-
Notifications
You must be signed in to change notification settings - Fork 1
/
easy_social.module
410 lines (352 loc) · 12.3 KB
/
easy_social.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<?php
/**
* @file
* This is the file description for Easy Social module.
*
*/
/**
* Implements hook_permission().
*/
function easy_social_permission() {
return array(
'administer easy social' => array(
'title' => t('Administer Easy Social'),
'description' => t('Manage Easy Social permissions.'),
),
);
}
/**
* Implements hook_menu().
*/
function easy_social_menu() {
$items = array();
$items['admin/config/content/easysocial'] = array(
'title' => 'Easy Social Settings',
'description' => 'Configure the social buttons and node types',
'page callback' => 'drupal_get_form',
'page arguments' => array('admin_config_easy_social'),
'access arguments' => array('administer easy social'),
);
return $items;
}
/**
* Implements hook_variable_info().
*/
function easy_social_variable_info() {
$variables['easysocial_global_typebtn'] = array(
'title' => t('Easy Social Global Type of Buttons'),
'default' => 0,
'group' => 'easysocial',
'token' => FALSE,
);
$variables['easysocial_global_social_buttons'] = array(
'title' => t('Easy Social Global Type of Network Buttons'),
'default' => array('twitter', 'facebook', 'googleplus','linkedin'),
'group' => 'easysocial',
'token' => FALSE,
);
$variables['easysocial_tt_global_account_via'] = array(
'title' => t('Easy Social Global Mention Account'),
'default' => '',
'group' => 'easysocial',
'token' => FALSE,
);
$variables['easysocial_tt_global_account_related'] = array(
'title' => t('Easy Social Global Related Account'),
'default' => '',
'group' => 'easysocial',
'token' => FALSE,
);
$variables['easysocial_tt_global_account_description'] = array(
'title' => t('Easy Social Global Twitter Description'),
'default' => 'Check it out: !title',
'group' => 'easysocial',
'token' => FALSE,
);
$node_types = node_type_get_types();
foreach ($node_types as $type => $typeobj) {
$variables['easysocial_' . $type . '_override'] = array(
'title' => t('Easy Social Override Option for type %type', array('%type' => $typeobj->name)),
'default' => -1,
'group' => 'easysocial',
'token' => FALSE,
);
$variables['easysocial_' . $type . '_typebtn'] = array(
'title' => t('Easy Social Type of Buttons for %type', array('%type' => $typeobj->name)),
'default' => -1,
'group' => 'easysocial',
'token' => FALSE,
);
$variables['easysocial_' . $type . '_social_buttons'] = array(
'title' => t('Easy Social Network Buttons for %type', array('%type' => $typeobj->name)),
'default' => array(),
'group' => 'easysocial',
'token' => FALSE,
);
}
return $variables;
}
function admin_config_easy_social(){
$form = array();
$form['global_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Global Settings'),
'#description' => t('Settings available for all content types'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['global_settings']['easysocial_global_typebtn'] = array(
'#type' => 'radios',
'#title' => t('Type of buttons'),
'#options' => array(t('Horizontal'), t('Vertical')),
'#default_value' => variable_get_value('easysocial_global_typebtn'),
);
$form['global_settings']['easysocial_global_social_buttons'] = array(
'#type' => 'checkboxes',
'#title' => t('Social Buttons'),
'#options' => array('twitter' => 'Twitter', 'facebook' => 'Facebook','googleplus' => 'Google Plus','linkedin' => 'Linked In'),
'#default_value' => variable_get_value('easysocial_global_social_buttons'),
);
$form['global_settings']['twitter_global_data'] = array(
'#type' => 'fieldset',
'#title' => t('Twitter Info'),
'#collapsible' => FALSE,
'#collapsed' => TRUE,
);
$form['global_settings']['twitter_global_data']['easysocial_tt_global_account_via'] = array(
'#type' => 'textfield',
'#title' => t('Mention account'),
'#size' => 40,
'#maxlength' => 255,
'#default_value' => variable_get_value('easysocial_tt_global_account_via'),
);
$form['global_settings']['twitter_global_data']['easysocial_tt_global_account_related'] = array(
'#type' => 'textfield',
'#title' => t('Related account'),
'#size' => 40,
'#maxlength' => 255,
'#default_value' => variable_get_value('easysocial_tt_global_account_related'),
);
$form['global_settings']['twitter_global_data']['easysocial_tt_global_account_description'] = array(
'#type' => 'textfield',
'#title' => t('Related account description'),
'#size' => 120,
'#maxlength' => 120,
'#default_value' => variable_get_value('easysocial_tt_global_account_description'),
'#description' => 'Use !title for the current page title'
);
$form['override_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Override Settings by Type'),
'#description' => t('Settings by content type'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$node_types = node_type_get_types();
foreach ($node_types as $type => $typeobj) {
$form['override_settings']['easysocial_settings_type_' . $type] = array(
'#type' => 'fieldset',
'#title' => t('Custom Settings for %type', array('%type' => $typeobj->name)),
'#collapsible' => FALSE,
'#collapsed' => TRUE,
);
$form['override_settings']['easysocial_settings_type_' . $type]['easysocial_' . $type . '_override'] = array(
'#type' => 'checkbox',
'#title' => t('Override'),
'#description' => t('Check this option to override the global settings for this type'),
'#default_value' => variable_get_value('easysocial_' . $type . '_override'),
);
$form['override_settings']['easysocial_settings_type_' . $type]['easysocial_' . $type . '_typebtn'] = array(
'#type' => 'radios',
'#title' => t('Type of buttons'),
// '#description' => t('Type of buttons, horizontal or vertical.'),
'#options' => array(t('Horizontal'), t('Vertical')),
'#default_value' => variable_get_value('easysocial_' . $type . '_typebtn')
);
$form['override_settings']['easysocial_settings_type_' . $type]['easysocial_' . $type . '_social_buttons'] = array(
'#type' => 'checkboxes',
'#title' => t('Social Buttons'),
'#options' => array('twitter' => 'Twitter', 'facebook' => 'Facebook','googleplus' => 'Google Plus','linkedin' => 'Linked In'),
'#default_value' => variable_get_value('easysocial_' . $type . '_social_buttons'),
);
}
$form = system_settings_form($form);
return $form;
}
/**
* Implements hook_theme().
*/
function easy_social_theme() {
$theme = array(
'easy_social_links' => array(
'template' => 'easy-social-links',
'variables' => array('social_links' => NULL),
),
);
return $theme;
}
/**
* Implements hook_field_extra_fields().
* The Easy Social available in Manage display page in the content types
*/
function easy_social_field_extra_fields() {
$extra = array();
$node_types = node_type_get_types();
foreach ($node_types as $type => $typeobj){
$extra['node'][$type] = array(
'display' => array(
'easy_social' => array(
'label' => t('Easy Social'),
'weight' => 100,
),
),
);
}
return $extra;
}
/**
* Implements hook_node_view().
* Certify to load the buttons in the moment I want
*/
function easy_social_node_view($node, $view_mode, $langcode) {
//Check if this type has a custom setting
if(variable_get_value('easysocial_' . $node->type . '_override') == 1){
$type = variable_get_value('easysocial_' . $node->type . '_typebtn');
$buttons = variable_get_value('easysocial_' . $node->type . '_social_buttons');
}
//Global settings
else {
$type = variable_get_value('easysocial_global_typebtn');
$buttons = variable_get_value('easysocial_global_social_buttons');
}
//Url to be shared
$url = url('node/'.$node->nid, array('absolute' => TRUE));
$social_links = array();
//Load Js files and generate respective markups
foreach ($buttons as $service) {
if(is_string($service)){
$data = array(
'nid' => $node->nid,
'title' => $node->title
);
eval("_easysocial_js_add_{$service}();");
eval("\$social_links[\$service] = _easysocial_button_{$service}_markup(\$url, \$type, \$data);");
}
}
//If at least one button is selected, go on
if(count($social_links) > 0){
$node->content['easy_social'] = array(
'#theme' => 'easy_social_links',
'#social_links' => $social_links,
'#weight' => 999
);
}
}
/**
* Add external facebook js
*/
function _easysocial_js_add_facebook(){
drupal_add_js('http://static.ak.fbcdn.net/connect.php/js/FB.Share', 'external');
}
/**
* Add external twitter js
*/
function _easysocial_js_add_twitter(){
drupal_add_js('http://platform.twitter.com/widgets.js', 'external');
}
/**
* Add external googleplus js
*/
function _easysocial_js_add_googleplus(){
drupal_add_js('https://apis.google.com/js/plusone.js', 'external');
}
/**
* Add external linkedin js
*/
function _easysocial_js_add_linkedin(){
drupal_add_js('http://platform.linkedin.com/in.js', 'external');
}
/**
* Generate the needed markup for the facebook share link
* @param $url The url to be shared
* @param $type Generate horizontal or vertical widgets
* @param $data Actually not used
* @return the html markup
*/
function _easysocial_button_facebook_markup($url, $type, $data = NULL, $lang = 'en_US'){
if($type == 0){
$type_box = 'button_count';
$markup = <<<FB
<iframe class="fb-widget"
src="http://www.facebook.com/plugins/like.php?href={$url}&locale={$lang}&layout={$type_box}&show_faces=false&width=86&action=like&font=trebuchet+ms&colorscheme=light&height=21"
scrolling="no"
frameborder="0"
style="border:none; overflow:hidden; width:87px; height:21px;"
allowTransparency="true"></iframe>
FB;
} else {
$type_box = 'box_count';
$markup = <<<FB
<iframe class="fb-widget"
src="http://www.facebook.com/plugins/like.php?href={$url}&locale={$lang}&layout={$type_box}&show_faces=false&width=450&action=like&font=trebuchet+ms&colorscheme=light&height=21"
scrolling="no"
frameborder="0"
style="border:none; overflow:hidden; width:48px; height:60px;"
allowTransparency="true"></iframe>
FB;
}
return $markup;
}
/**
* Generate the needed markup for the twitter share link
* @param $url The url to be shared
* @param $type Generate horizontal or vertical widgets
* @param $data Assoc array with info for the tweet
* @return the html markup
*/
function _easysocial_button_twitter_markup($url, $type, $data = NULL, $lang = 'en'){
$type = ($type == 0) ? 'horizontal' : 'vertical';
$account_via = variable_get_value('easysocial_tt_global_account_via');
$account_related = variable_get_value('easysocial_tt_global_account_related');
$description = variable_get_value('easysocial_tt_global_account_description');
$description = str_replace('!title', $data['title'], $description);
$markup = <<<TT
<a href="http://twitter.com/share"
class="twitter-share-button"
data-url="{$url}"
data-count="{$type}"
data-lang = "{$lang}"
data-via="{$account_via}"
data-related="{$account_related}"
data-text="{$description}">Tweet</a>
TT;
return $markup;
}
/**
* Generate the needed markeup for the googleplus share link
* @param $url The url to be shared
* @param $type Generate horizontal or vertical widgets
* @param $data Actually not used
* @return the html markup
*/
function _easysocial_button_googleplus_markup($url, $type, $data = NULL, $lang = 'en_US'){
$type = ($type == 0) ? 'medium' : 'tall';
$markup = <<<GP
<g:plusone size="{$type}" href="{$url}"></g:plusone>
GP;
return $markup;
}
/**
* Generate the needed markeup for the linkedin share link
* @param $url The url to be shared
* @param $type Generate horizontal or vertical widgets
* @param $data Actually not used
* @return the html markup
*/
function _easysocial_button_linkedin_markup($url, $type, $data = NULL, $lang = 'en_US'){
$type = ($type == 0) ? 'right' : 'top';
$markup = <<<LI
<script type="in/share" data-url="{$url}" data-counter="{$type}"></script>
LI;
return $markup;
}