This repository has been archived by the owner on Mar 3, 2022. It is now read-only.
forked from bryanbraun/social_share
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsocial_share.install
250 lines (231 loc) · 7.35 KB
/
social_share.install
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
<?php
/**
* @file social_share.install
*/
/**
* Implements hook_schema().
*/
function social_share_schema() {
$schema = array();
$schema['social_share_networks'] = array(
'fields' => array(
'machine_name' => array(
'type' => 'varchar',
'length' => 255,
),
'human_name' => array(
'type' => 'varchar',
'length' => 255,
),
'url' => array(
'type' => 'blob',
),
'weight' => array(
'type' => 'int',
'length' => 4,
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 0,
),
'locked' => array(
'type' => 'int',
'length' => 1,
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('machine_name'),
);
return $schema;
}
/**
* Implements hook_install().
*/
function social_share_install() {
// Everything that needs to happen on first install is the same as
// what happens during update 7200.
social_share_update_7200();
}
/**
* Implements hook_uninstall().
*/
function social_share_uninstall() {
// Remove all social share configuration from the database.
db_delete('variable')
->condition('name', 'social_share_%', 'LIKE')
->execute();
}
/**
* Install DB Schema,
* Populate Default Social Networks
*/
function social_share_update_7200() {
if (!db_table_exists('social_share_networks')) {
drupal_install_schema('social_share');
}
else {
db_truncate('social_share_networks')->execute();
}
$networks = array(
array(
'machine_name' => 'delicious',
'human_name' => t('Delicious'),
'url' => 'http://www.delicious.com/save?v=5&noui&jump=close&url=%URL%&title=%TITLE%',
'locked' => TRUE,
),
array(
'machine_name' => 'digg',
'human_name' => t('Digg'),
'url' => 'http://digg.com/share?url=%URL%&title=%TITLE%',
'locked' => TRUE,
),
array(
'machine_name' => 'facebook',
'human_name' => t('Facebook'),
'url' => 'http://facebook.com/sharer.php?u=%URL%&t=%TITLE%',
'locked' => TRUE,
),
array(
'machine_name' => 'googleplus',
'human_name' => t('Google Plus'),
'url' => 'https://plus.google.com/share?url=%URL%',
'locked' => TRUE,
),
array(
'machine_name' => 'hyves',
'human_name' => t('Hyves'),
'url' => 'http://www.hyves-share.nl/button/tip/?tipcategoryid=12&rating=5&title=%TITLE%&body=%DESC%Bron: [url=%URL%]%URL%[/url]',
'locked' => TRUE,
),
array(
'machine_name' => 'linkedin',
'human_name' => t('LinkedIn'),
'url' => 'http://www.linkedin.com/shareArticle?url=%URL%&mini=true&title=%TITLE%&ro=false&summary=%DESC%&source=',
'locked' => TRUE,
),
array(
'machine_name' => 'msnlive',
'human_name' => t('MSN Live'),
'url' => 'http://profile.live.com/badge/?url=%URL%&title=%TITLE%&description=%DESC%',
'locked' => TRUE,
),
array(
'machine_name' => 'myspace',
'human_name' => t('Myspace'),
'url' => 'http://www.myspace.com/Modules/PostTo/Pages/default.aspx?u=%URL%&c=%TITLE%',
'locked' => TRUE,
),
array(
'machine_name' => 'orkut',
'human_name' => t('Orkut'),
'url' => 'http://promote.orkut.com/preview?nt=orkut.com&tt=%TITLE%&du=%URL%&cn=%DESC%',
'locked' => TRUE,
),
array(
'machine_name' => 'pinterest',
'human_name' => t('Pinterest'),
'url' => 'http://pinterest.com/pin/create/button/?url=%URL%&media=%IMAGE%&description=%DESC%',
'locked' => TRUE,
),
array(
'machine_name' => 'reddit',
'human_name' => t('Reddit'),
'url' => 'http://reddit.com/submit?url=%URL%&title=%TITLE%',
'locked' => TRUE,
),
array(
'machine_name' => 'stumbleupon',
'human_name' => t('StumbleUpon'),
'url' => 'http://stumbleupon.com/submit?url=%URL%&title=%TITLE%',
'locked' => TRUE,
),
array(
'machine_name' => 'twitter',
'human_name' => t('Twitter'),
'url' => 'http://twitter.com/intent/tweet?url=%URL%&text=%TITLE%',
'locked' => TRUE,
),
array(
'machine_name' => 'yahoo',
'human_name' => t('Yahoo'),
'url' => 'http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&u=%URL%&t=%TITLE%&d=%DESC%',
'locked' => TRUE,
),
);
foreach ($networks as $network) {
db_insert('social_share_networks')
->fields($network)
->execute();
}
}
/**
* Migrate from 7.x-1.x to 7.x-2.x
*/
function social_share_update_7201() {
// Update label variable from string to array:
$default_language = language_default();
$label = variable_get('social_share_label', t('Share to'));
if (is_array($label)) {
variable_set('social_share_label', $label);
}
else {
variable_set('social_share_label', array($default_language->language => $label));
}
// Gather list of enabled networks:
$available_networks = social_share_available_networks();
$networks = variable_get('social_share_sites', array());
$enabled_networks = array();
foreach ($networks as $network => $enabled) {
if (!$enabled) {
unset($networks[$network]);
}
}
foreach ($available_networks as $available_network) {
if (isset($networks[$available_network['machine_name']])) {
$enabled_networks[] = $available_network['machine_name'];
}
}
// Set up enabled networks for each enabled node type.
$node_types = variable_get('social_share_node_types', array());
foreach($node_types as $type => $enabled) {
if ($enabled) {
variable_set('social_share_enabled_' . $type, 1);
variable_set('social_share_networks_' . $type, $enabled_networks);
variable_set('social_share_title_' . $type, '[node:title]');
variable_set('social_share_description_' . $type, '[node:body]');
variable_set('social_share_url_' . $type, '[node:url:absolute]');
variable_set('social_share_image_' . $type, '');
variable_set('social_share_theme_' . $type, 'social_share_link');
variable_set('social_share_show_label_' . $type, 1);
}
}
// Set up enabled networks for block (if block is enabled):
if (variable_get('social_share_block', 0)) {
$block_enabled_networks = array();
foreach ($available_networks as $available_network) {
$block_enabled_networks[$available_network['machine_name']] = (in_array($enabled_networks, $available_network['machine_name'])) ? 1 : 0;
}
$block_settings = array(
'social_share_show_label' => 1,
'social_share_title' => '[current-page:title]',
'social_share_description' => '',
'social_share_url' => '[current-page:url:absolute]',
'social_share_image' => '',
'social_share_theme' => 'social_share_link',
'social_share_networks' => $block_enabled_networks,
);
variable_set('social_share_block_settings', $block_settings);
}
// Clean up no longer needed variables
$vars = array(
'social_share_node_types',
'social_share_sites',
'social_share_teaser',
'social_share_weight',
);
foreach ($vars as $var) {
variable_del($var);
}
drupal_flush_all_caches();
}