| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: adsense.install,v 1.11 2008/08/10 20:20:20 jcnventura Exp $ |
| 3 |
// |
|
| 4 |
// Copyright 2005-2008 Khalid Baheyeldin http://2bits.com |
/** |
| 5 |
|
* @file |
| 6 |
function adsense_install() { |
* Install file of the adsense module |
| 7 |
switch ($GLOBALS['db_type']) { |
*/ |
| 8 |
case 'mysql': |
|
| 9 |
case 'mysqli': |
/** |
| 10 |
$success = db_query("CREATE TABLE IF NOT EXISTS {adsense_clicks} ( |
* Implementation of hook_install(). |
| 11 |
aid INT(10) NOT NULL AUTO_INCREMENT, |
*/ |
| 12 |
ip VARCHAR(15) DEFAULT '0', |
function adsense_install() { |
| 13 |
timestamp INT(11) unsigned NOT NULL DEFAULT '0', |
drupal_set_message(t("AdSense settings are available under !link", |
| 14 |
path VARCHAR(255) NOT NULL DEFAULT '', |
array( '!link' => l('Administer > Site configuration > AdSense ', 'admin/settings/adsense' ) ) |
| 15 |
PRIMARY KEY (aid), |
)); |
| 16 |
KEY (timestamp) |
} |
| 17 |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
|
| 18 |
break; |
/** |
| 19 |
case 'pgsql': |
* Implementation of hook_uninstall(). |
| 20 |
$success = db_query("CREATE TABLE {adsense_clicks} ( |
*/ |
| 21 |
aid SERIAL, |
function adsense_uninstall() { |
| 22 |
ip VARCHAR(15) DEFAULT '0', |
variable_del('adsense_access_pages'); |
| 23 |
timestamp INTEGER NOT NULL DEFAULT '0', |
variable_del('adsense_basic_id'); |
| 24 |
path VARCHAR(255) DEFAULT '', |
variable_del('adsense_disable'); |
| 25 |
PRIMARY KEY (aid));"); |
variable_del('adsense_id_module'); |
| 26 |
$success = db_query("CREATE INDEX {timestamp} ON {adsense_clicks} (timestamp);"); |
variable_del('adsense_placeholder'); |
| 27 |
break; |
variable_del('adsense_placeholder_text'); |
| 28 |
} |
variable_del('adsense_section_targeting'); |
| 29 |
|
variable_del('adsense_test_mode'); |
| 30 |
if ($success) { |
variable_del('adsense_visibility'); |
| 31 |
drupal_set_message(t('Adsense module table creation successful.')); |
|
| 32 |
} |
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'adsense\_ad\_channel\_%'"); |
| 33 |
else { |
while ($variable = db_fetch_object($settings)) { |
| 34 |
drupal_set_message(t('Adsense module table creation was unsuccessful.'), 'error'); |
variable_del($variable->name); |
| 35 |
} |
} |
| 36 |
} |
} |
| 37 |
|
|
| 38 |
/** |
/** |
| 39 |
* Implementation of hook_uninstall(). |
* Drupal 5.x to 6.x update. |
| 40 |
*/ |
*/ |
| 41 |
function adsense_uninstall() { |
function adsense_update_6000() { |
| 42 |
db_query('DROP TABLE {adsense_clicks}'); |
variable_del('adsense_click_tracking'); |
| 43 |
db_query("DELETE FROM {variable} WHERE name LIKE 'adsense_%'"); |
variable_del('adsense_click_tracking_name_resolve'); |
| 44 |
} |
|
| 45 |
|
// Convert old ad blocks to the new per-ad-gen blocks |
| 46 |
function adsense_update_1() { |
// New block will have the original number as the name, so that the block input tag works |
| 47 |
adsense_install(); |
$oldsearch = 0; |
| 48 |
} |
$managed = 0; |
| 49 |
|
$oldcode = 0; |
| 50 |
function adsense_update_2() { |
$pos = strlen('adsense_ad_block_'); |
| 51 |
switch ($GLOBALS['db_type']) { |
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'adsense\_ad\_block\_%'"); |
| 52 |
case 'mysql': |
while ($variable = db_fetch_object($settings)) { |
| 53 |
case 'mysqli': |
$data = explode(':', variable_get($variable->name, '')); |
| 54 |
db_query("ALTER TABLE {adsense_clicks} ADD `path` varchar(255) default ''"); |
if ($data[0] == 'Search Box') { |
| 55 |
break; |
// Block is an old search block |
| 56 |
} |
// Store the name and the channel in the new block |
| 57 |
} |
$newdata = implode(':', array(substr($variable->name, $pos), $data[2])); |
| 58 |
|
variable_set('adsense_search_ad_block_'. $oldsearch++, $newdata); |
| 59 |
|
} |
| 60 |
|
elseif (!empty($data[3])) { |
| 61 |
|
// Slot is defined, so it is a managed ad |
| 62 |
|
// Store the name, format and slot in the new block |
| 63 |
|
$newdata = implode(':', array(substr($variable->name, $pos), $data[0], $data[3])); |
| 64 |
|
variable_set('adsense_managed_ad_block_'. $managed++, $newdata); |
| 65 |
|
} |
| 66 |
|
else { |
| 67 |
|
// Slot is an old code ad |
| 68 |
|
// Store the name, format, group and channel in the new block |
| 69 |
|
$newdata = implode(':', array(substr($variable->name, $pos), $data[0], $data[1], $data[2])); |
| 70 |
|
variable_set('adsense_oldcode_ad_block_'. $oldcode++, $newdata); |
| 71 |
|
} |
| 72 |
|
// Raise the number of blocks in a type, if necessary |
| 73 |
|
variable_set('adsense_search_number_blocks', max(variable_get('adsense_search_number_blocks', 2), $oldsearch)); |
| 74 |
|
variable_set('adsense_managed_number_blocks', max(variable_get('adsense_managed_number_blocks', 3), $managed)); |
| 75 |
|
variable_set('adsense_oldcode_number_blocks', max(variable_get('adsense_oldcode_number_blocks', 3), $oldcode)); |
| 76 |
|
|
| 77 |
|
variable_del($variable->name); |
| 78 |
|
} |
| 79 |
|
|
| 80 |
|
$ret[] = update_sql("DROP TABLE {adsense_clicks}"); |
| 81 |
|
return $ret; |
| 82 |
|
} |