-
Notifications
You must be signed in to change notification settings - Fork 1
/
shared_count.module
179 lines (166 loc) · 5.93 KB
/
shared_count.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
<?php
/**
* @file
* ShareCount Integration
*/
/**
* Implements hook_help().
*/
function shared_count_help($path, $arg) {
switch ($path) {
case 'admin/help#shared_count':
return '<p>' . t('This module provides a Shared count service integration') . '</p>';
}
}
/**
* Implements hook_menu().
*/
function shared_count_menu() {
$items = array();
$items['admin/config/services/shared-count-config'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array('shared_count_config_form'),
'access arguments' => array('configure shared count'),
'title' => 'Shared count configuration',
);
return $items;
}
/**
* Implements hook_permission().
*/
function shared_count_permission() {
$permissions['configure shared count'] = array(
'title' => t('Configure Settings for Shared Count'),
'description' => t('Access to Shared Count configuration'),
);
return $permissions;
}
/**
* Shared Count Configuration form.
*/
function shared_count_config_form($form, $form_state) {
$social_networks = array(
'facebook' => t('Facebook'),
'google_plus' => t('Google plus'),
'twitter' => t('Twitter'),
'linkedin' => t('Linkedin'),
'stumbleupon' => t('Stumbleupon'),
'pinterest' => t('Pinterest'),
);
$columns = array(
'disabled' => t('Disabled'),
'pinned' => t('Pinned'),
'hidden' => t('Hidden')
);
$shared_count_plans = array(
'https://free.sharedcount.com/' => t('Free'),
'https://plus.sharedcount.com/' => t('Plus'),
'https://business.sharedcount.com/' => t('Business'),
);
$form['shared_count_api_key'] = array(
'#type' => 'textfield',
'#title' => t('Shared count API key'),
'#default_value' => variable_get('shared_count_api_key', ''),
'#required' => TRUE,
);
$form['shared_count_plan'] = array(
'#type' => 'radios',
'#title' => t('Shared Count Plans'),
'#default_value' => variable_get('shared_count_plan','https://free.sharedcount.com/'),
'#options' => $shared_count_plans,
'#description' => t('Select your shared count plan'),
);
$form['shared_count_social_networks'] = array(
'#title' => t('Sortable Lists Element'),
'#type' => 'sortable_lists',
'#options' => $social_networks,
'#columns' => $columns,
'#default_value' => variable_get('shared_count_social_networks', array()),
);
return system_settings_form($form);
}
/**
* Implements hook_block_info().
*/
function shared_count_block_info() {
$blocks = array();
$blocks['share_count_block'] = array(
'info' => t('Shared Count'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function shared_count_block_view($delta = '') {
$block = array();
switch($delta) {
case 'share_count_block':
$block['subject'] = '';
$block['content'] = shared_count_block_markup();
break;
}
return $block;
}
/**
* Implements hook_theme().
*/
function shared_count_theme($existing, $type, $theme, $path) {
return array(
'shared_count_share_links' => array(
'variables' => array(
'primary_items' => '',
'secondary_items' => '',
'caption_text' => '',
'more_text' => '',
),
'template' => 'shared-count-share-links',
'path' => drupal_get_path('module', 'shared_count') . '/templates',
),
);
}
/**
* Generete the markup for the share buttons.
*/
function shared_count_block_markup() {
$settings = array(
'shared_count_api_key' => variable_get('shared_count_api_key',''),
'shared_count_request_domain' => variable_get('shared_count_plan', 'https://free.sharedcount.com/'),
);
drupal_add_js(array('setting' => $settings), array('type' => 'setting'));
$items = shared_count_get_items(variable_get('shared_count_social_networks', array()));
$variables = array(
'primary_items' => $items['primary'],
'secondary_items' => $items['secondary'],
'more_text' => t('more'),
'caption_text' => t('Shares'),
);
$markup = theme('shared_count_share_links', $variables);
return $markup;
}
/**
* Get all items
*/
function shared_count_get_items($shared_count_social_networks) {
global $base_url;
$path_alias = drupal_get_path_alias();
$social_networks = array(
'facebook' => l(t('Share on Facebook'), 'https://www.facebook.com/sharer/sharer.php', array('external' => TRUE,'query' => array('u' => $base_url . '/' . $path_alias), 'attributes' => array('class' => array('shared-count-facebook')))),
'google_plus' => l(t('g+'), 'https://plus.google.com/share', array('external' => TRUE,'query' => array('url' => $base_url . '/' . $path_alias), 'attributes' => array('class' => array('shared-count-googleplus')))),
'twitter' => l(t('Share on Twitter'), 'https://twitter.com/home', array('external' => TRUE,'query' => array('status' => $base_url . '/' . $path_alias), 'attributes' => array('class' => array('shared-count-twitter')))),
'linkedin' => l(t('Linkedin'),'https://www.linkedin.com/shareArticle', array('external' => TRUE, 'query' => array('url' => $base_url . '/' . $path_alias, 'title' => drupal_get_title(), 'mini' => TRUE), 'attributes' => array('class' => array('shared-count-linkedin')))),
'stumbleupon' => l(t('Stumbleupon'),'https://www.stumbleupon.com/submit', array('external' => TRUE, 'query' => array('url' => $base_url . '/' . $path_alias, 'title' => drupal_get_title()), 'attributes' => array('class' => array('shared-count-stumbleupon')))),
'pinterest' => l(t('Pinterest'),'https://pinterest.com/pin/create/button/', array('external' => TRUE, 'query' => array('url' => $base_url . '/' . $path_alias), 'attributes' => array('class' => array('shared-count-pinterest')))),
);
$pinned = '';
$hidden = '';
foreach($shared_count_social_networks['sortable_lists']['pinned'] as $network) {
$pinned .= $social_networks[$network];
}
foreach($shared_count_social_networks['sortable_lists']['hidden'] as $network) {
$hidden .= $social_networks[$network];
}
$items['primary'] = $pinned;
$items['secondary'] = $hidden;
return $items;
}