| 1 |
<?php
|
| 2 |
// $Id: adsense.install,v 1.16 2008/12/13 23:11:14 jcnventura Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Install file of the adsense module
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_install().
|
| 11 |
*/
|
| 12 |
function adsense_install() {
|
| 13 |
drupal_set_message(st("AdSense settings are available under !link",
|
| 14 |
array( '!link' => l(st('Administer > Site configuration > AdSense'), 'admin/settings/adsense' ) )
|
| 15 |
));
|
| 16 |
}
|
| 17 |
|
| 18 |
/**
|
| 19 |
* Implementation of hook_uninstall().
|
| 20 |
*/
|
| 21 |
function adsense_uninstall() {
|
| 22 |
variable_del('adsense_access_pages');
|
| 23 |
variable_del('adsense_basic_id');
|
| 24 |
variable_del('adsense_disable');
|
| 25 |
variable_del('adsense_id_module');
|
| 26 |
variable_del('adsense_placeholder');
|
| 27 |
variable_del('adsense_placeholder_text');
|
| 28 |
variable_del('adsense_section_targeting');
|
| 29 |
variable_del('adsense_test_mode');
|
| 30 |
variable_del('adsense_visibility');
|
| 31 |
|
| 32 |
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'adsense\_ad\_channel\_%'");
|
| 33 |
while ($variable = db_fetch_object($settings)) {
|
| 34 |
variable_del($variable->name);
|
| 35 |
}
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Drupal 5.x to 6.x update.
|
| 40 |
*/
|
| 41 |
function adsense_update_6000() {
|
| 42 |
// Convert old ad blocks to the new per-ad-gen blocks
|
| 43 |
// New block will have the original number as the name, so that the block input tag works
|
| 44 |
$oldsearch = 0;
|
| 45 |
$managed = 0;
|
| 46 |
$oldcode = 0;
|
| 47 |
$pos = drupal_strlen('adsense_ad_block_');
|
| 48 |
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'adsense\_ad\_block\_%'");
|
| 49 |
while ($variable = db_fetch_object($settings)) {
|
| 50 |
$data = explode(':', variable_get($variable->name, ''));
|
| 51 |
if ($data[0] == 'Search Box') {
|
| 52 |
// Block is an old search block
|
| 53 |
// Store the name and the channel in the new block
|
| 54 |
$newdata = implode(':', array(drupal_substr($variable->name, $pos), $data[2]));
|
| 55 |
variable_set('adsense_search_ad_block_'. $oldsearch++, $newdata);
|
| 56 |
}
|
| 57 |
elseif (!empty($data[3])) {
|
| 58 |
// Slot is defined, so it is a managed ad
|
| 59 |
// Store the name, format and slot in the new block
|
| 60 |
$newdata = implode(':', array(drupal_substr($variable->name, $pos), $data[0], $data[3]));
|
| 61 |
variable_set('adsense_managed_ad_block_'. $managed++, $newdata);
|
| 62 |
}
|
| 63 |
else {
|
| 64 |
// Slot is an old code ad
|
| 65 |
// Store the name, format, group and channel in the new block
|
| 66 |
$newdata = implode(':', array(drupal_substr($variable->name, $pos), $data[0], $data[1], $data[2]));
|
| 67 |
variable_set('adsense_oldcode_ad_block_'. $oldcode++, $newdata);
|
| 68 |
}
|
| 69 |
// Raise the number of blocks in a type, if necessary
|
| 70 |
variable_set('adsense_search_number_blocks', max(variable_get('adsense_search_number_blocks', 2), $oldsearch));
|
| 71 |
variable_set('adsense_managed_number_blocks', max(variable_get('adsense_managed_number_blocks', 3), $managed));
|
| 72 |
variable_set('adsense_oldcode_number_blocks', max(variable_get('adsense_oldcode_number_blocks', 3), $oldcode));
|
| 73 |
|
| 74 |
variable_del($variable->name);
|
| 75 |
}
|
| 76 |
|
| 77 |
$ret = array();
|
| 78 |
return $ret;
|
| 79 |
}
|