-
Notifications
You must be signed in to change notification settings - Fork 0
/
sharethis.install
69 lines (64 loc) · 2.03 KB
/
sharethis.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
<?php
/**
* @file
* This file holds the install information for the ShareThis Module.
*/
/**
* Implements hook_install().
*/
function sharethis_install() {
variable_set('sharethis_publisherID', sharethis_create_publisher_key());
}
/**
* Creates a publisher key for use with the ShareThis API.
*/
function sharethis_create_publisher_key() {
$pubkey = "dr-";
$pubkey .= dechex(mt_rand( 0, 0xffff ));
$pubkey .= dechex(mt_rand( 0, 0xffff )) . "-";
$pubkey .= dechex(mt_rand( 0, 0xffff )) . "-";
$pubkey .= dechex(mt_rand( 0, 0xffff )) . "-";
$pubkey .= dechex(mt_rand( 0, 0xffff )) . "-";
$pubkey .= dechex(mt_rand( 0, 0xffff ));
$pubkey .= dechex(mt_rand( 0, 0xffff ));
$pubkey .= dechex(mt_rand( 0, 0xffff ));
return $pubkey;
}
/**
* Remove the custom ShareThis table.
*/
function sharethis_update_7001() {
// Move from the st_table to the variables table.
if (db_table_exists('st_table')) {
// Select all options in the ShareThis table.
$result = db_select('st_table', 's')
->fields('s', array('st_option', 'st_value'))
->execute();
while ($record = $result->fetchAssoc()) {
// Variable name switches. publisherID stays the same.
switch ($record['st_option']) {
case 'buttons':
$record['st_option'] = 'button_option';
break;
case 'nodeType':
$record['st_option'] = 'node_option';
break;
case 'services':
$record['st_option'] = 'service_option';
break;
case 'viewMode':
$record['st_option'] = 'teaser_option';
break;
case 'widget':
$record['st_option'] = 'widget_option';
break;
}
// Prefix the option with a "sharethis_" namespace.
variable_set('sharethis_' . $record['st_option'], $record['st_value']);
}
// Now that our settings are in the variables table, safely drop the table.
db_drop_table('st_table');
// Return a success message.
return t('Switched from the custom ShareThis table to the Variables table.');
}
}