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