-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsharer_toolbar.module
More file actions
166 lines (139 loc) · 4.34 KB
/
sharer_toolbar.module
File metadata and controls
166 lines (139 loc) · 4.34 KB
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
<?php
/**
* @file sharer_toolbar.module
* Hooks implementations and code logic related to Sharer Toolbar module
*/
/**
* Implements hook_permission().
*/
function sharer_toolbar_permission() {
return array(
'access sharer toolbar' => array(
'title' => t('Access sharer toolbar'),
'description' => t('Choose who can acces sharers on front.'),
),
'admin sharer toolbar' => array(
'title' => t('Administer sharer toolbar'),
'description' => t('Choose which social sharer to be displayed and other stuffs.'),
),
);
}
/**
* Implements hook_menu().
*/
function sharer_toolbar_menu() {
return array(
'admin/config/services/social-sharer-toolbar' => array(
'title' => 'Sharer toolbar configuration',
'description' => 'Configure sharer toolbar.',
'page callback' => 'drupal_get_form',
'page arguments' => array('sharer_toolbar_config_form'),
'access arguments' => array('admin sharer toolbar'),
'file' => 'sharer_toolbar.forms.inc',
)
);
}
/**
* Implements hook_theme().
*/
function sharer_toolbar_theme($existing, $type, $theme, $path) {
return array(
// Sharer toolbar config form
'sharer_toolbar_config_form' => array(
'render element' => 'form',
'file' => 'sharer_toolbar.theme.inc',
),
// Sharer toolbar template
'sharer_toolbar' => array(
'variables' => array(
'sharers' => array(),
),
'template' => 'sharer-toolbar',
// 'path' => 'templates',
),
);
}
/**
* Implements hook_sharer_toolbar_available_sharer().
*/
function sharer_toolbar_sharer_toolbar_available_sharer() {
// Define default sharers
return array(
// Facebook sharer
'facebook' => array(
'sid' => 'facebook',
'name' => 'Facebook',
'icon_class' => 'icon-facebook',
'url' => 'https://www.facebook.com/sharer/sharer.php?u=[:shared_url:]',
'label' => 'Share on Facebook',
),
// Twitter sharer
'twitter' => array(
'sid' => 'twitter',
'name' => 'Twitter',
'icon_class' => 'icon-twitter',
'url' => 'https://twitter.com/home?status=[:shared_summary:] [:shared_url:]',
'label' => 'Share on Twitter',
),
// Google Plus sharer
'googleplus' => array(
'sid' => 'googleplus',
'name' => 'Google +',
'icon_class' => 'icon-googleplus',
'url' => 'https://plus.google.com/share?url=[:shared_url:]',
'label' => 'Share on Google +',
),
// Twitter sharer
'linkedin' => array(
'sid' => 'linkedin',
'name' => 'LinkedIn',
'icon_class' => 'icon-linkedin',
'url' => 'https://www.linkedin.com/shareArticle?mini=true&url=[:shared_url:]&title=[:shared_title:]&summary=[:shared_summary:]&source=[:shared_source:]',
'label' => 'Share on LinkedIn',
),
// Email sharer
'email' => array(
'sid' => 'email',
'name' => 'Email',
'icon_class' => 'icon-email',
'url' => 'mailto:?subject=[:shared_title:]&body=[:shared_url:]',
'label' => 'Share by email',
),
);
}
/**
* Implements hook_process_node().
*/
function sharer_toolbar_process_node(&$variables) {
// Default value for sharer toolbar
$variables['sharer_toolbar'] = NULL;
// Generate only if user can access it
if (user_access('access sharer toolbar')) {
module_load_include('inc', 'sharer_toolbar');
$sharing_buttons = array();
// Get all active and available sharers
$ordered_sharers = _sharer_toolbar_get_ordered_available_sharers();
$active_sharers = variable_get('sharer_toolbar_sharers_configuration', array());
// Generate button if sharer is active
foreach ($ordered_sharers as $delta => &$sharer) {
$sid = $sharer['sid'];
if ($active_sharers[$sid]['status']) {
// Transform URL
_sharer_toolbar_generate_sharer_url($sharer['url'], $variables);
}
// or unset before sending array to template
else {
unset($ordered_sharers[$delta]);
}
}
// Add javascript feature
drupal_add_js(drupal_get_path('module', 'sharer_toolbar') . '/js/sharer-opener.js');
// Render HTML for sharer toolbar
if (!empty($ordered_sharers)) {
$variables['sharer_toolbar'] = theme('sharer_toolbar', array(
'title' => variable_get('sharer_toolbar_title', 'Share'),
'sharers' => $ordered_sharers,
));
}
}
}