diff -rup adsense.admin.inc adsense.admin.inc
--- adsense.admin.inc	2010-01-11 13:20:48.000000000 +0100
+++ adsense.admin.inc	2011-01-07 11:26:58.877435000 +0100
@@ -16,7 +16,7 @@
  */
 function adsense_main_settings() {
   include_once(drupal_get_path('module', 'adsense') .'/help/adsense.help.inc');
-  require_once(drupal_get_path('module', 'adsense') .'/includes/adsense.search_options.inc');
+  include_once(drupal_get_path('module', 'adsense') .'/includes/adsense.search_options.inc');
 
   $form['help'] = array(
     '#type'        => 'fieldset',
@@ -26,8 +26,7 @@ function adsense_main_settings() {
   );
 
   $form['help']['help'] = array(
-    '#type'  => 'markup',
-    '#value' => adsense_help_text(),
+    '#markup' => adsense_help_text(),
   );
 
   $form['visibility'] = array(
@@ -154,8 +153,7 @@ function adsense_id_settings() {
   );
 
   $form['help']['help'] = array(
-    '#type'  => 'markup',
-    '#value' => adsense_id_help_text(),
+    '#markup' => adsense_id_help_text(),
   );
 
   $form['adsense_basic_id'] = array(
@@ -178,7 +176,7 @@ function adsense_id_settings() {
   else {
     $form['adsense_id_module'] = array(
       '#type'  => 'hidden',
-      '#value' => $options[0],
+      '#value' => $options['adsense_basic'],
     );
   }
 
@@ -191,7 +189,13 @@ function adsense_id_settings() {
  * Validate adsense_id_settings form.
  */
 function _adsense_id_settings_validate($form, &$form_state) {
+  // Trim remaning whitespace.
   $form_state['values']['adsense_basic_id'] = trim($form_state['values']['adsense_basic_id']);
+	
+  // Verify it's a valid Adsense publisher ID.
+  if (!preg_match('/^pub-[0-9]+$/', $form_state['values']['adsense_basic_id'])) {
+    form_set_error('adsense_basic_id', t('A valid Google AdSense Publisher ID is case sensitive and formatted like %id.', array('%id' => 'pub-9999999999999')));
+  }
 }
 
 /**
@@ -201,7 +205,7 @@ function _adsense_id_settings_validate($
  *   array of selectable Publisher ID functions
  */
 function _adsense_id_settings_client_id_mods() {
-  $ret['adsense_basic'] = 'Use the site Publisher ID always';
+  $ret['adsense_basic'] = 'Always use the site Publisher ID.';
 
   $funcs = get_defined_functions();
   foreach ($funcs['user'] as $func) {
diff -rup adsense.info adsense.info
--- adsense.info	2010-08-21 01:01:58.000000000 +0200
+++ adsense.info	2011-01-07 11:26:58.903436500 +0100
@@ -5,11 +5,11 @@
 name = AdSense core
 description = Displays Google AdSense ads on your site to earn revenue. Requires at least one additional ad unit generator module.
 package = Adsense
-core = 6.x
+core = 7.x
+version = 7.x-1-dev
 
-; Information added by drupal.org packaging script on 2010-08-21
-version = "6.x-1.x-dev"
-core = "6.x"
-project = "adsense"
-datestamp = "1282348918"
+files[] = adsense.module
+files[] = adsense.install
+files[] = adsense.admin.inc
 
+configure = admin/config/adsense/main
diff -rup adsense.install adsense.install
--- adsense.install	2009-03-31 15:41:02.000000000 +0200
+++ adsense.install	2011-01-07 11:26:58.981441000 +0100
@@ -7,16 +7,16 @@
  */
 
 /**
- * Implementation of hook_install().
+ * Implements hook_install().
  */
 function adsense_install() {
   drupal_set_message(st("AdSense settings are available under !link",
-    array( '!link' => l(st('Administer > Site configuration > AdSense'),  'admin/settings/adsense' ) )
+    array( '!link' => l(st('Administer > Configuration > AdSense'),  'admin/config/adsense' ) )
   ));
 }
 
 /**
- * Implementation of hook_uninstall().
+ * Implements hook_uninstall().
  */
 function adsense_uninstall() {
   variable_del('adsense_access_pages');
@@ -29,51 +29,7 @@ function adsense_uninstall() {
   variable_del('adsense_test_mode');
   variable_del('adsense_visibility');
 
-  $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'adsense\_ad\_channel\_%'");
-  while ($variable = db_fetch_object($settings)) {
-    variable_del($variable->name);
-  }
-}
-
-/**
- * Drupal 5.x to 6.x update.
- */
-function adsense_update_6000() {
-  // Convert old ad blocks to the new per-ad-gen blocks
-  // New block will have the original number as the name, so that the block input tag works
-  $oldsearch = 0;
-  $managed = 0;
-  $oldcode = 0;
-  $pos = drupal_strlen('adsense_ad_block_');
-  $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'adsense\_ad\_block\_%'");
-  while ($variable = db_fetch_object($settings)) {
-    $data = explode(':', variable_get($variable->name, ''));
-    if ($data[0] == 'Search Box') {
-      // Block is an old search block
-      // Store the name and the channel in the new block
-      $newdata = implode(':', array(drupal_substr($variable->name, $pos), $data[2]));
-      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(drupal_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(drupal_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 = array();
-  return $ret;
+  // Delete all the AdSense channel variables and then clear the variable cache.
+  db_query("DELETE FROM {variable} WHERE name LIKE 'adsense\_ad\_channel\_%'");
+  cache_clear_all('variables', 'cache');
 }
diff -rup adsense.module adsense.module
--- adsense.module	2009-09-01 17:30:20.000000000 +0200
+++ adsense.module	2011-01-07 11:35:29.301629600 +0100
@@ -93,30 +93,42 @@ function adsense_ad_formats($key = NULL)
 }
 
 /**
- * Implementation of hook_perm().
+ * Implements hook_permission().
  */
-function adsense_perm() {
-  return array('administer adsense', 'hide adsense', 'use PHP for ad visibility');
+function adsense_permission() {
+  return array(
+    'administer adsense' => array(
+      'title' => t('Administer AdSense settings'),
+      'description' => t('Perform administration tasks for AdSense.'),
+    ),
+    'hide adsense' => array(
+      'title' => t('Hide AdSense'),
+      'description' => t('Hide AdSense ads for this role.'),
+    ),
+    'use PHP for ad visibility' => array(
+      'title' => t('Can use PHP for AdSense visibility'),
+    ),
+  );
 }
 
 /**
- * Implementation of hook_theme().
+ * Implements hook_theme().
  */
 function adsense_theme() {
   return array(
     'adsense_ad' => array(
-      'arguments' => array('ad' => NULL, 'module' => NULL),
+      'variables' => array('ad' => NULL, 'module' => NULL),
     ),
   );
 }
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function adsense_menu() {
   $items = array();
 
-  $items['admin/settings/adsense'] = array(
+  $items['admin/config/adsense'] = array(
     'title' => 'AdSense',
     'description' => 'Configure Google AdSense Ads.',
     'page callback' => 'drupal_get_form',
@@ -124,12 +136,12 @@ function adsense_menu() {
     'access arguments'  => array('administer adsense'),
     'file' => 'adsense.admin.inc',
   );
-  $items['admin/settings/adsense/main'] = array(
+  $items['admin/config/adsense/main'] = array(
     'title' => 'Settings',
     'weight' => 10,
     'type' => MENU_DEFAULT_LOCAL_TASK,
   );
-  $items['admin/settings/adsense/publisher'] = array(
+  $items['admin/config/adsense/publisher'] = array(
     'title' => 'Publisher ID',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('adsense_id_settings'),
@@ -138,7 +150,7 @@ function adsense_menu() {
     'type' => MENU_LOCAL_TASK,
     'file' => 'adsense.admin.inc',
   );
-  $items['admin/settings/adsense/publisher/site'] = array(
+  $items['admin/config/adsense/publisher/site'] = array(
     'title' => 'Site ID',
     'weight' => -1,
     'type' => MENU_DEFAULT_LOCAL_TASK,
@@ -148,7 +160,7 @@ function adsense_menu() {
 }
 
 /**
- * Implementation of hook_requirements().
+ * Implements hook_requirements().
  */
 function adsense_requirements($phase) {
   $requirements = array();
@@ -171,74 +183,32 @@ function adsense_requirements($phase) {
 }
 
 /**
- * Implementation of hook_filter().
- */
-function adsense_filter($op, $delta = 0, $format = -1, $text = '') {
-  switch ($op) {
-    case 'list':
-      return array(0 => t('AdSense tag'));
-    case 'no cache':
-      return TRUE;
-    case 'description':
-      return t('Substitutes an AdSense special tag with an ad.');
-    case 'process':
-      return _adsense_process_tags($text);
-    default:
-      return $text;
-  }
-}
-
-/**
- * Implementation of hook_nodeapi().
- */
-function adsense_nodeapi(&$node, $op = 'view', $teaser, $page) {
-  switch ($op) {
-    case 'view':
-      if (variable_get('adsense_section_targeting', ADSENSE_SECTION_TARGETING_DEFAULT)) {
-        $node->content['adsense_start'] = array(
-          '#value' => '<!-- google_ad_section_start -->',
-          '#weight' => -5,
-          );
-        $node->content['adsense_end'] = array(
-          '#value' => '<!-- google_ad_section_end -->',
-          '#weight' => 5,
-          );
-      }
-  }
-}
-
-/**
- * Implementation of hook_form_filter_admin_format_form_alter().
- */
-function adsense_form_filter_admin_format_form_alter(&$form, $form_state) {
-  // In Drupal <= 6.9 (or later) the HTML corrector has a bug that causes problems with the use of the AdSense tag filter
-  sscanf(VERSION, "%d.%d", $major, $minor);
-  if (($major == 6) && ($minor <= 99)) {
-    if ((empty($form_state['post']) && $form['filters']['adsense/0']['#default_value'] && $form['filters']['filter/3']['#default_value']) ||
-        ((!empty($form_state['post'])) && ($form_state['post']['filters']['adsense/0'] == '1') && ($form_state['post']['filters']['filter/3'] == '1'))) {
-      drupal_set_message(t('The HTML corrector filter has a bug that causes problems with the use of the AdSense tag. Disabling the HTML corrector filter is recommended.'), 'warning', TRUE);
-    }
-  }
-}
-
-/**
- * Implementation of hook_filter_tips().
+ * Implements hook_filter_info(). 
  */
-function adsense_filter_tips($delta, $format, $long = FALSE) {
-  return t('Use the special tag [adsense:<em>format</em>:<em>slot</em>] or [adsense:<em>format</em>:<em>[group]</em>:<em>[channel]</em><em>[:slot]</em>] or [adsense:block:<em>location</em>] to display Google AdSense ads.');
+function adsense_filter_info() {
+  $filters['adsense'] = array(
+    'title' => t('AdSense tag'), 
+    'description' => t('Substitutes an AdSense special tag with an ad. Add this below "Limit allowed HTML tags".'), 
+    'process callback' => '_adsense_process_tags',
+    'tips callback' => '_adsense_filter_tips',
+    'cache' => FALSE,
+  );
+  
+  return $filters;
 }
 
 /**
- * Helper function to process the adsense input filter
- *
+ * Helper function to process the adsense input filter.
+ * 
  * @param $text
- *   text of the node being processed
+ *   text of the node being processed.
  * @return
- *   modified text with the adsense tags replaced by Google AdSense ads
- * @see adsense_filter()
+ *   modified text with the adsense tags replaced by Google AdSense ads.
+ *   
+ * @see adsense_filter_info()
  * @see adsense_display()
  */
-function _adsense_process_tags($text) {
+function _adsense_process_tags($text, $filter) {
   $patterns = array(
     'block'  => '/\[adsense:block:([^\]]+)\]/x',
     'oldtag' => '/\[adsense:([^:]+):(\d*):(\d*):?(\w*)\]/x',
@@ -257,12 +227,12 @@ function _adsense_process_tags($text) {
               'adsense_search',
             );
             foreach ($mods as $module) {
-              $module_blocks = module_invoke($module, 'block', 'list');
+              $module_blocks = module_invoke($module, 'block_info');
               if ($module_blocks) {
                 foreach ($module_blocks as $delta => $block) {
                   if ($block['info'] == $match[1]) {
-                    // Found the block with the same name as the passed arg
-                    $block = module_invoke($module, 'block', 'view', $delta);
+                    // Found the block with the same name as the passed arg.
+                    $block = module_invoke($module, 'block_view', $delta);
                     $ad = $block['content'];
                   }
                 }
@@ -307,23 +277,47 @@ function _adsense_process_tags($text) {
 }
 
 /**
- * Provides the Google AdSense Publisher ID / slot ID to be used in the ad
+ * Callback to display our filter tips. 
+ */
+function _adsense_filter_tips($filter, $format, $long = FALSE) {
+  return t('Use the special tag [adsense:<em>format</em>:<em>slot</em>] or [adsense:<em>format</em>:<em>[group]</em>:<em>[channel]</em><em>[:slot]</em>] or [adsense:block:<em>location</em>] to display Google AdSense ads.');
+}
+
+/**
+ * Implements hook_node_view(). 
+ */
+function adsense_node_view($node, $view_mode, $langcode) {
+  if (variable_get('adsense_section_targeting', ADSENSE_SECTION_TARGETING_DEFAULT)) {
+    $node->content['adsense_start'] = array(
+      '#markup' => '<!-- google_ad_section_start -->',
+      '#weight' => -5,
+    );
+    
+    $node->content['adsense_end'] = array(
+      '#markup' => '<!-- google_ad_section_end -->',
+      '#weight' => 5,
+    );
+  }
+}
+
+/**
+ * Provides the Google AdSense Publisher ID / slot ID to be used in the ad.
  *
  * If revenue sharing modules are installed, this function will call the
  * appropriate function in those modules.
  *
  * @param $format
- *   format of the ad being generated (optional)
+ *   format of the ad being generated (optional).
  * @return
  *   If the format parameter is supplied, array with 'client' and 'slot'
- *   fields, otherwise just the Publisher ID string is returned
+ *   fields, otherwise just the Publisher ID string is returned.
  */
 function adsense_get_client_slot_id($format = NULL) {
-  // Get the configured function
+  // Get the configured function.
   $function = variable_get('adsense_id_module', ADSENSE_ID_MODULE_DEFAULT);
 
   if ($function != ADSENSE_ID_MODULE_DEFAULT) {
-    // Call the function
+    // Call the function.
     if (function_exists($function)) {
       $client_id = $function('client_id', $format);
       if ($client_id) {
@@ -366,7 +360,7 @@ function adsense_display() {
     $args = func_get_arg(0);
   }
   else {
-    // handle the 'old' method of calling this function
+    // handle the 'old' method of calling this function.
     // adsense_display($format = '160x600', $group = 1, $channel = 1, $slot = '', $referral = 0, $cpa = '')
 
     $args['format'] = '160x600';
@@ -394,13 +388,13 @@ function adsense_display() {
     $ad = '<!--adsense: invalid format: '. $args['format'] .'-->';
   }
   elseif (!_adsense_page_match()) {
-    // Check first if disabled or if we are at adsense limit or if this page doesn't allow adsense
+    // Check first if disabled or if we are at adsense limit or if this page doesn't allow adsense.
     $ad = '<!--adsense: page not in match list-->';
   }
   elseif (!_adsense_check_if_enabled()) {
     global $user;
 
-    // Ads are disabled
+    // Ads are disabled.
     if (variable_get('adsense_placeholder', ADSENSE_PLACEHOLDER_DEFAULT) || ($user->uid == 1)) {
       $width = array_key_exists('width', $ad) ? $ad['width'] : 0;
       $height = array_key_exists('height', $ad) ? $ad['height'] : 0;
@@ -421,21 +415,21 @@ function adsense_display() {
   else {
     // If site Slot ID for this ad was passed, pass the format as argument
     // in case Publisher ID modules are enabled that can return different
-    // Slot IDs per ad format
+    // Slot IDs per ad format.
     $client_id_arg = !empty($args['slot']) ? $args['format'] : NULL;
     $client = adsense_get_client_slot_id($client_id_arg);
 
     if (is_array($client)) {
-      // An array was received, use that Slot ID
+      // An array was received, use that Slot ID.
       $slot = $client['slot'];
       $client = $client['client'];
     }
     elseif (isset($args['slot'])) {
-      // Use the original site Slot ID
+      // Use the original site Slot ID.
       $slot = $args['slot'];
     }
 
-    // Ad should be displayed
+    // Ad should be displayed.
     switch ($args['format']) {
       case 'Search Box':
         if (!empty($slot) && module_exists('adsense_cse')) {
@@ -463,11 +457,11 @@ function adsense_display() {
           $ad = '<!--adsense: no AdSense for Content module found-->';
         }
 
-        $ad = theme('adsense_ad', $ad, $module);
+        $ad = theme('adsense_ad', array('ad' => $ad, 'module' => $module));
 
         break;
     }
-    // Remove empty lines
+    // Remove empty lines.
     $ad = str_replace("\n\n", "\n", $ad);
   }
 
@@ -486,19 +480,19 @@ function adsense_display() {
  *   string with the modified ad unit
  * @ingroup themeable
  */
-function theme_adsense_ad($ad, $module) {
-  return "<div class='adsense $module'>\n$ad\n</div>";
+function theme_adsense_ad($vars) {
+  return "<div class='adsense ". $vars['module'] ."'>\n" . $vars['ad'] . "\n</div>";
 }
 
 /**
- * Helper function to verify if ads are currently enabled
+ * Helper function to verify if ads are currently enabled.
  *
  * @return
- *   TRUE if ad display is enabled, FALSE otherwise
+ *   TRUE if ad display is enabled, FALSE otherwise.
  */
 function _adsense_check_if_enabled() {
   if (!variable_get('adsense_basic_id', ADSENSE_BASIC_ID_DEFAULT)) {
-    // Google AdSense Publisher ID is not configured
+    // Google AdSense Publisher ID is not configured.
     return FALSE;
   }
   if (variable_get('adsense_disable', ADSENSE_DISABLE_DEFAULT)) {
@@ -568,9 +562,10 @@ function _adsense_page_match() {
 
   if ($pages) {
     if ($visibility == 2) {
-      return drupal_eval($pages);
+      return php_eval($pages);
     }
-    $path = drupal_get_path_alias($_GET['q']);
+    $pages = drupal_strtolower($pages);
+    $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
     $page_match = drupal_match_path($path, $pages);
     if ($path != $_GET['q']) {
       $page_match = $page_match || drupal_match_path($_GET['q'], $pages);
diff -rup contrib/adsense_click/adsense_click.info contrib/adsense_click/adsense_click.info
--- contrib/adsense_click/adsense_click.info	2010-08-21 01:01:58.000000000 +0200
+++ contrib/adsense_click/adsense_click.info	2011-01-07 11:26:59.040444400 +0100
@@ -4,13 +4,14 @@
 
 name = AdSense Click Tracking
 description = Tracks clicks to Google Adsense
-dependencies[] = adsense
 package = Adsense
-core = 6.x
+dependencies[] = adsense
+core = 7.x
+version = 7.x-1-dev
 
-; Information added by drupal.org packaging script on 2010-08-21
-version = "6.x-1.x-dev"
-core = "6.x"
-project = "adsense"
-datestamp = "1282348918"
+files[] = adsense_cse.module
+files[] = adsense_cse.install
+files[] = adsense_cse.admin.inc
+files[] = adsense_click.logs.inc
 
+configure = admin/config/adsense/click
diff -rup contrib/adsense_click/adsense_click.install contrib/adsense_click/adsense_click.install
--- contrib/adsense_click/adsense_click.install	2008-12-19 01:32:38.000000000 +0100
+++ contrib/adsense_click/adsense_click.install	2011-01-07 11:26:59.051445000 +0100
@@ -6,21 +6,8 @@
  * Install file of the adsense_click module
  */
 
-function adsense_click_install() {
-  // Create tables.
-  drupal_install_schema('adsense_click');
-}
-
-/**
- * Implementation of hook_uninstall().
- */
-function adsense_click_uninstall() {
-  // Remove tables.
-  drupal_uninstall_schema('adsense_click');
-}
-
 /**
- * Implementation of hook_schema().
+ * Implements hook_schema().
  */
 function adsense_click_schema() {
   $schema['adsense_clicks'] = array(
@@ -28,7 +15,6 @@ function adsense_click_schema() {
       'aid' => array(
         'type' => 'serial',
         'not null' => TRUE,
-        'disp-width' => '10',
       ),
       'ip' => array(
         'type' => 'varchar',
@@ -41,7 +27,6 @@ function adsense_click_schema() {
         'unsigned' => TRUE,
         'not null' => TRUE,
         'default' => 0,
-        'disp-width' => '11',
       ),
       'path' => array(
         'type' => 'varchar',
@@ -71,58 +56,3 @@ function adsense_click_schema() {
 
   return $schema;
 }
-
-function adsense_click_update_1() {
-  $schema['adsense_clicks'] = array(
-    'fields' => array(
-      'aid' => array(
-        'type' => 'serial',
-        'not null' => TRUE,
-        'disp-width' => '10',
-      ),
-      'ip' => array(
-        'type' => 'varchar',
-        'length' => '15',
-        'not null' => FALSE,
-        'default' => '0',
-      ),
-      'timestamp' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-        'default' => 0,
-        'disp-width' => '11',
-      ),
-      'path' => array(
-        'type' => 'varchar',
-        'length' => '255',
-        'not null' => TRUE,
-        'default' => '',
-      ),
-    ),
-    'primary key' => array('aid'),
-    'indexes' => array(
-      'timestamp' => array('timestamp'),
-    ),
-  );
-
-  $ret = array();
-  db_create_table($ret, 'adsense_clicks', $schema['adsense_clicks']);
-  return $ret;
-}
-
-function adsense_click_update_2() {
-  $ret = array();
-  db_add_field($ret, 'adsense_clicks', 'title', array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''));
-  db_add_field($ret, 'adsense_clicks', 'referrer', array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''));
-  return $ret;
-}
-
-function adsense_click_update_3() {
-  $ret = array();
-  db_change_field($ret, 'adsense_clicks', 'path', 'path', array('type' => 'varchar', 'length' => '255', 'not null' => FALSE, 'default' => ''));
-  db_change_field($ret, 'adsense_clicks', 'title', 'title', array('type' => 'varchar', 'length' => '255', 'not null' => FALSE, 'default' => ''));
-  db_change_field($ret, 'adsense_clicks', 'referrer', 'referrer', array('type' => 'varchar', 'length' => '255', 'not null' => FALSE, 'default' => ''));
-  db_add_index($ret, 'adsense_clicks', 'path', array('path'));
-  return $ret;
-}
diff -rup contrib/adsense_click/adsense_click.logs.inc contrib/adsense_click/adsense_click.logs.inc
--- contrib/adsense_click/adsense_click.logs.inc	2008-12-19 01:32:38.000000000 +0100
+++ contrib/adsense_click/adsense_click.logs.inc	2011-01-07 11:26:59.091447300 +0100
@@ -1,4 +1,4 @@
-<?php
+<td></td><?php
 // $Id: adsense_click.logs.inc,v 1.1.4.2 2008/12/19 01:32:37 jcnventura Exp $
 
 /**
@@ -11,86 +11,128 @@
 
 function adsense_click_log() {
   $header = array(
-    array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'),
-    array('data' => t('Path'),      'field' => 'path'),
-    array('data' => t('IP/Host'),   'field' => 'ip'),
-    array('data' => t('Referrer'),  'field' => 'referrer'),
+    array('data' => t('Timestamp'), 'field' => 'ads.timestamp', 'sort' => 'desc'),
+    array('data' => t('Path'),      'field' => 'ads.path'),
+    array('data' => t('IP/Host'),   'field' => 'ads.ip'),
+    array('data' => t('Referrer'),  'field' => 'ads.referrer'),
   );
+	$rows = array();
 
   $name_resolve = variable_get('adsense_click_tracking_name_resolve', ADSENSE_CLICK_TRACKING_NAME_RESOLVE_DEFAULT);
-
-  $sql = 'SELECT * FROM {adsense_clicks} '. tablesort_sql($header);
-
-  $result = pager_query($sql, 50);
-  while ($log = db_fetch_object($result)) {
+	
+  // Create our base query.
+  $query = db_select('adsense_clicks', 'ads');
+  $query = $query->extend('PagerDefault')->extend('TableSort');
+	
+  $query
+    ->fields('ads', array('ip', 'timestamp', 'path', 'title', 'referrer'))
+    ->limit(50)
+    ->orderByHeader($header);
+		
+  $result = $query->execute();
+	
+  foreach ($result as $log) {
     if ($name_resolve) {
       $host = gethostbyaddr($log->ip);
     }
     else {
       $host = $log->ip;
     }
-
-    $rows[] = array(
+		
+		$rows[] = array(
       array('data' => format_date($log->timestamp, 'small'), 'nowrap' => 'nowrap'),
       _adsense_click_format_path($log->path, $log->title),
       l($host, 'http://whois.domaintools.com/'. $log->ip),
       _adsense_click_format_path($log->referrer),
     );
   }
-
-  return theme('table', $header, $rows) . theme('pager', NULL, 50, 0);
+	
+  return theme('table', array('header' => $header, 'rows' => $rows)) . theme('pager');
 }
 
 function adsense_click_top_pages() {
   $header = array(
-    array('data' => t('Path'),   'field' => 'path'),
+    array('data' => t('Path'),   'field' => 'ads.path'),
     array('data' => t('Clicks'), 'field' => 'count', 'sort' => 'desc'),
     array('data' => t('Last'),   'field' => 'last'),
   );
-
-  $sql = 'SELECT path, COUNT(*) AS count, MAX(timestamp) AS last FROM {adsense_clicks} GROUP BY path'. tablesort_sql($header);
-
-  $result = pager_query($sql, 50);
-  while ($log = db_fetch_object($result)) {
-    $title = db_result(db_query("SELECT title FROM {adsense_clicks} WHERE path = '%s'", $path));
-    $rows[] = array(
-      array('data' => _adsense_click_format_path($log->path, $title)),
+	$rows = array();
+  
+  // Create our base query.
+  $query = db_select('adsense_clicks', 'ads');
+  $query = $query->extend('PagerDefault')->extend('TableSort');
+	
+  $query
+    ->fields('ads', array('path', 'title'))
+    ->groupBy('path')
+    ->limit(50)
+    ->orderByHeader($header);
+		
+  $count = $query->addExpression('COUNT(*)', 'count');
+  $max = $query->addExpression('MAX(timestamp)', 'last');
+	
+  $result = $query->execute();
+	
+  foreach ($result as $log) {
+		$rows[] = array(
+      array('data' => _adsense_click_format_path($log->path, $log->title)),
       array('data' => $log->count, 'align' => 'right'),
       array('data' => format_date($log->last, 'small'), 'nowrap' => 'nowrap'),
     );
   }
-
-  return theme('table', $header, $rows) . theme('pager', NULL, 50, 0);
+	
+  return theme('table', array('header' => $header, 'rows' => $rows)) . theme('pager');
 }
 
 function adsense_click_by_day() {
-  global $db_type;
   $header = array(
     array('data' => t('Day'),    'field' => 'day', 'sort' => 'desc'),
     array('data' => t('Clicks'), 'field' => 'count'),
   );
-
-  switch ($db_type) {
+  $rows = array();
+	
+  $query = db_select('adsense_clicks', 'ads');
+  $count_query = clone $query;
+  $query = $query->extend('PagerDefault')->extend('TableSort');
+	
+  /**
+   * @TODO Must be an easier and prettier way of doing this.
+   */
+  $database_driver = db_driver();
+	
+  switch ($database_driver) {
     case 'mysql':
-    case 'mysqli':
-      $sql_count = "SELECT COUNT(DISTINCT(FROM_UNIXTIME(timestamp, '%y-%m-%%d'))) FROM {adsense_clicks}";
-      $sql = "SELECT FROM_UNIXTIME(timestamp, '%Y-%m-%%d') AS day, COUNT(*) AS count FROM {adsense_clicks} GROUP BY day" . tablesort_sql($header);
+      $count_query->addExpression("COUNT(DISTINCT(FROM_UNIXTIME(timestamp, '%y-%m-%d')))");
+      $day = $query->addExpression("FROM_UNIXTIME(timestamp, '%Y-%m-%d')", 'day');
       break;
     case 'pgsql':
-      $sql_count = "SELECT COUNT(DISTINCT(TO_CHAR(timestamp, 'YYYY-MM-DD'))) FROM {adsense_clicks}";
-      $sql = "SELECT TO_CHAR(timestamp, 'YYYY-MM-DD') AS day, COUNT(*) AS count FROM {adsense_clicks} GROUP BY day" . tablesort_sql($header);
+      $count_query->addExpression("COUNT(DISTINCT(TO_CHAR(timestamp, 'YYYY-MM-DD')))");
+      $day = $query->addExpression("TO_CHAR(timestamp, 'YYYY-MM-DD')", 'day');
       break;
-  }
-
-  $result = pager_query($sql, 50, 0, $sql_count);
-  while ($log = db_fetch_object($result)) {
-    $rows[] = array(
+    case 'sqlite':
+      $count_query->addExpression("COUNT(DISTINCT(datetime(timestamp, 'unixepoch', 'localtime')))");
+      $day = $query->addExpression("datetime(timestamp, 'unixepoch', 'localtime')", 'day');
+      break;
+	}
+	
+	// Extend our query and add our count expression.
+	$count = $query->addExpression('COUNT(*)', 'count');
+	
+	$query->groupBy('day')
+	  ->limit(50)
+    ->orderByHeader($header)
+	  ->setCountQuery($count_query);
+	
+	$result = $query->execute();
+	
+	foreach ($result as $log) {
+		$rows[] = array(
       $log->day,
       array('data' => $log->count, 'align' => 'right'),
     );
-  }
-
-  return theme('table', $header, $rows) . theme('pager', NULL, 50, 0);
+	}
+	
+  return theme('table', array('header' => $header, 'rows' => $rows)) . theme('pager');
 }
 
 function _adsense_click_format_path($path, $title = '', $width = 32) {
diff -rup contrib/adsense_click/adsense_click.module contrib/adsense_click/adsense_click.module
--- contrib/adsense_click/adsense_click.module	2010-01-11 12:29:36.000000000 +0100
+++ contrib/adsense_click/adsense_click.module	2011-01-07 11:26:59.111448400 +0100
@@ -13,12 +13,12 @@ define('ADSENSE_CLICK_TRACKING_DEFAULT',
 define('ADSENSE_CLICK_TRACKING_NAME_RESOLVE_DEFAULT', 0);
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function adsense_click_menu() {
   $items = array();
 
-  $items['admin/settings/adsense/click'] = array(
+  $items['admin/config/adsense/click'] = array(
     'title'            => 'Clicks',
     'description'      => 'Track the clicks on Adsense ads.',
     'page callback'    => 'drupal_get_form',
@@ -60,14 +60,18 @@ function adsense_click_menu() {
 }
 
 /**
- * Implementation of hook_perm().
+ * Implements hook_permission().
  */
 function adsense_click_perm() {
-  return array('view clicks');
+  return array(
+    'view clicks' => array(
+      'title' => 'View AdSense clicks',
+    )
+  );
 }
 
 /**
- * Implementation of hook_init().
+ * Implements hook_init().
  */
 function adsense_click_init() {
   if (variable_get('adsense_click_tracking', ADSENSE_CLICK_TRACKING_DEFAULT)) {
@@ -77,7 +81,14 @@ function adsense_click_init() {
 
 function adsense_click_register() {
   if (variable_get('adsense_click_tracking', ADSENSE_CLICK_TRACKING_DEFAULT)) {
-    db_query("INSERT INTO {adsense_clicks} (ip, timestamp, path, title, referrer) values('%s', %d, '%s', '%s', '%s')",
-      ip_address(), time(), $_GET['u'], $_GET['t'], $_GET['r']);
+    db_insert('adsense_clicks')
+      ->fields(array(
+        'ip' => ip_address(),
+        'timestamp' => REQUEST_TIME,
+        'path' => $_GET['u'],
+        'title' => $_GET['t'],
+        'referrer' => $_GET['r']
+      ))
+      ->execute();
   }
 }
diff -rup cse/adsense_cse.admin.inc cse/adsense_cse.admin.inc
--- cse/adsense_cse.admin.inc	2009-05-13 01:04:20.000000000 +0200
+++ cse/adsense_cse.admin.inc	2011-01-07 11:26:59.198453400 +0100
@@ -27,8 +27,7 @@ function adsense_cse_settings() {
   );
 
   $form['help']['help'] = array(
-    '#type'  => 'markup',
-    '#value' => adsense_cse_help_text(),
+    '#markup' => adsense_cse_help_text(),
   );
 
   $form['searchbox'] = array(
diff -rup cse/adsense_cse.info cse/adsense_cse.info
--- cse/adsense_cse.info	2010-08-21 01:01:58.000000000 +0200
+++ cse/adsense_cse.info	2011-01-07 11:26:59.207453900 +0100
@@ -6,11 +6,11 @@ name = CSE Search
 description = AdSense for Search generator module. This module uses the new Custom Search Engine code created via the Adsense interface.
 dependencies[] = adsense
 package = Adsense
-core = 6.x
+core = 7.x
+version = 7.x-1-dev
 
-; Information added by drupal.org packaging script on 2010-08-21
-version = "6.x-1.x-dev"
-core = "6.x"
-project = "adsense"
-datestamp = "1282348918"
+files[] = adsense_cse.module
+files[] = adsense_cse.install
+files[] = adsense_cse.admin.inc
 
+configure = admin/config/adsense/cse
diff -rup cse/adsense_cse.install cse/adsense_cse.install
--- cse/adsense_cse.install	2009-02-10 01:35:20.000000000 +0100
+++ cse/adsense_cse.install	2011-01-07 11:26:59.237455600 +0100
@@ -10,17 +10,7 @@
  * Implementation of hook_uninstall().
  */
 function adsense_cse_uninstall() {
-  variable_del('adsense_cse_ad_location');
-  variable_del('adsense_cse_color_box_background');
-  variable_del('adsense_cse_country');
-  variable_del('adsense_cse_encoding');
-  variable_del('adsense_cse_frame_width');
-  variable_del('adsense_cse_logo');
-  variable_del('adsense_cse_number_blocks');
-  variable_del('adsense_cse_textbox_length');
-  variable_del('adsense_cse_language');
-  $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'adsense\_cse\_ad\_block\_%'");
-  while ($variable = db_fetch_object($settings)) {
-    variable_del($variable->name);
-  }
+  // Delete all the AdSense variables and then clear the variable cache.
+  db_query("DELETE FROM {variable} WHERE name LIKE 'adsense\_cse\_%'");
+  cache_clear_all('variables', 'cache');
 }
diff -rup cse/adsense_cse.module cse/adsense_cse.module
--- cse/adsense_cse.module	2010-01-11 12:20:30.000000000 +0100
+++ cse/adsense_cse.module	2011-01-07 11:26:59.247456200 +0100
@@ -23,14 +23,14 @@ define('ADSENSE_CSE_TEXTBOX_LENGTH_DEFAU
 define('ADSENSE_CSE_LANGUAGE_DEFAULT', 'en');
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function adsense_cse_menu() {
   $items = array();
 
   $results_path = variable_get('clean_url', 0) ? ADSENSE_CSE_RESULTS_PATH : '.';
 
-  $items['admin/settings/adsense/cse'] = array(
+  $items['admin/config/adsense/cse'] = array(
     'title' => 'Custom Search',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('adsense_cse_settings'),
@@ -51,61 +51,72 @@ function adsense_cse_menu() {
 }
 
 /**
- * Implementation of hook_block().
+ * Implements hook_block_info().
  */
-function adsense_cse_block($op = 'list', $delta = 0, $edit = array()) {
-  $block = NULL;
+function adsense_cse_block_info() {
+  $blocks = array();
+  $max = variable_get('adsense_cse_number_blocks', ADSENSE_CSE_NUMBER_BLOCKS_DEFAULT);
+  
+  for ($count=0 ; $count < $max ; $count++) {
+    if ($ad = _adsense_cse_get_block_config($count)) {
+      $title = $ad[0];
+    }
+    else {
+      $title = t('AdSense CSE: unconfigured ') . $count;
+    }
+    $blocks[$count] = array(
+      'info' => $title,
+      'cache' => DRUPAL_NO_CACHE,
+    );
+  }
+  
+  return $blocks;
+}
 
-  switch ($op) {
-    case 'list':
-      $max = variable_get('adsense_cse_number_blocks', ADSENSE_CSE_NUMBER_BLOCKS_DEFAULT);
-      for ($count=0; $count < $max ; $count++) {
-        if ($ad = _adsense_cse_get_block_config($count)) {
-          $title = $ad[0];
-        }
-        else {
-          $title = t('AdSense CSE: unconfigured ') . $count;
-        }
-        $block[$count]['info'] = $title;
-        $block[$count]['cache'] = BLOCK_NO_CACHE;
-      }
-      break;
+/**
+ * Implements hook_block_configure().
+ */
+function adsense_cse_block_configure($delta = '') {
+  $ad = _adsense_cse_get_block_config($delta);
+  
+  $form['info'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Block description'),
+    '#default_value' => ($ad) ? $ad[0] : '',
+    '#maxlength' => 64,
+    '#description' => t('A brief description of your block. Used on the <a href="@overview">block overview page</a>.', array('@overview' => url('admin/structure/block'))),
+    '#required' => TRUE,
+    '#weight' => -19,
+  );
+
+  $form['ad_slot'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Ad Slot ID'),
+    '#default_value' => ($ad) ? $ad[1] : '',
+    '#description' => t('This is the provided by the AdSense site in the Search Box Code "cx" field. This is usually provided in the form partner-<em>Publisher ID</em>:<em>Slot Id</em>. If the code provided is, for example, partner-pub-0123456789:<strong>abcdef-ghij</strong>, then insert only <strong>abcdef-ghij</strong> here.'),
+    '#required' => TRUE,
+  );
+      
+  return $form;
+}
 
-    case 'configure':
-      $ad = _adsense_cse_get_block_config($delta);
+/**
+ * Implements hook_block_save().
+ */
+function adsense_cse_block_save($delta = '', $edit = array()) {
+  $data = implode(':', array(urlencode($edit['info']), $edit['ad_slot']));
+  variable_set('adsense_cse_ad_block_'. $delta, $data);
+}
 
-      $form['info'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Block description'),
-        '#default_value' => ($ad) ? $ad[0] : '',
-        '#maxlength' => 64,
-        '#description' => t('A brief description of your block. Used on the <a href="@overview">block overview page</a>.', array('@overview' => url('admin/build/block'))),
-        '#required' => TRUE,
-        '#weight' => -19,
-      );
-
-      $form['ad_slot'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Ad Slot ID'),
-        '#default_value' => ($ad) ? $ad[1] : '',
-        '#description' => t('This is the provided by the AdSense site in the Search Box Code "cx" field. This is usually provided in the form partner-<em>Publisher ID</em>:<em>Slot Id</em>. If the code provided is, for example, partner-pub-0123456789:<strong>abcdef-ghij</strong>, then insert only <strong>abcdef-ghij</strong> here.'),
-        '#required' => TRUE,
-      );
-      return $form;
-
-    case 'save':
-      $data = implode(':', array(urlencode($edit['info']), $edit['ad_slot']));
-      variable_set('adsense_cse_ad_block_'. $delta, $data);
-      return;
-
-    case 'view':
-      if (_adsense_page_match()) {
-        $ad = _adsense_cse_get_block_config($delta);
-        $block['content'] = ($ad) ? adsense_display(array('format' => 'Search Box', 'slot' => $ad[1])) : t('AdSense unconfigured block. <a href=!url>Click to configure.</a>', array('!url' => url('admin/build/block/configure/adsense_cse/'. $delta)));
-      }
-      break;
-    }
-  return $block;
+/**
+ * Implements hook_block_view().
+ */
+function adsense_cse_block_view($delta = '') {
+  if (_adsense_page_match()) {
+    $ad = _adsense_cse_get_block_config($delta);
+    $block['content'] = ($ad) ? adsense_display(array('format' => 'Search Box', 'slot' => $ad[1])) : t('AdSense unconfigured block. <a href=!url>Click to configure.</a>', array('!url' => url('admin/structure/block/manage/adsense_cse/'. $delta)));
+    return $block;
+  }
 }
 
 /**
diff -rup cse/adsense_cse.results.inc cse/adsense_cse.results.inc
--- cse/adsense_cse.results.inc	2009-08-05 22:08:10.000000000 +0200
+++ cse/adsense_cse.results.inc	2011-01-07 11:26:59.263457100 +0100
@@ -24,9 +24,8 @@ function _adsense_cse_results() {
     $output = _adsense_format_box("Results<br />width = ${width}<br />country = ${country}", $width, 100);
   }
   else {
-    if (variable_get('adsense_secret_adtest', ADSENSE_SECRET_ADTEST_DEFAULT)) {
-      $secret = '  var googleAdtest = "on";';
-    }
+  	
+    $secret = variable_get('adsense_secret_adtest', ADSENSE_SECRET_ADTEST_DEFAULT) ? '  var googleAdtest = "on";' : '';
 
     $output = <<<CSE_RESULTS_TXT
 <div id="cse-search-results"></div>
diff -rup help/adsense.help.inc help/adsense.help.inc
--- help/adsense.help.inc	2009-09-01 17:28:18.000000000 +0200
+++ help/adsense.help.inc	2011-01-07 11:26:59.309459700 +0100
@@ -20,22 +20,25 @@ function adsense_help_text() {
   // Get the ad formats
   $ads = adsense_ad_formats();
   $ads['Search Box'] = adsense_ad_formats('Search Box');
+	
+	// Create the ad format table.
   $headers = array(t('Format'), t('Description'), t('Width'), t('Height'));
   $rows = array();
   foreach ($ads as $format => $data) {
     $width = isset($data['width']) ? $data['width'] : '';
     $height = isset($data['height']) ? $data['height'] : '';
-    $rows[] = array($format, $data['desc'], $width, $height);
+    $rows[] = array(
+      'data' => array($format, $data['desc'], $width, $height),
+    );
   }
 
-  // Create the ad format text
-  $ad_formats_text = theme('table', $headers, $rows);
+  $ad_formats_text = theme('table', array('header' => $headers, 'rows' => $rows));
 
   if (module_exists('adsense_cse')) {
-    $custom_search_link = l(t('Custom search help'), 'admin/settings/adsense/cse');
+    $custom_search_link = l(t('Custom search help'), 'admin/config/adsense/cse');
   }
   else {
-    $custom_search_link = t('Adsense CSE module (which must be enabled; !link) and refer to its help', array('!link' => l(t('modules'), 'admin/build/modules')));
+    $custom_search_link = t('Adsense CSE module (which must be enabled; !link) and refer to its help', array('!link' => l(t('modules'), 'admin/modules')));
   }
 
   $output = <<<EOF
diff -rup managed/adsense_managed.admin.inc managed/adsense_managed.admin.inc
--- managed/adsense_managed.admin.inc	2008-09-11 23:52:00.000000000 +0200
+++ managed/adsense_managed.admin.inc	2011-01-07 11:26:59.344461700 +0100
@@ -25,8 +25,7 @@ function adsense_managed_settings() {
   );
 
   $form['help']['help'] = array(
-    '#type'  => 'markup',
-    '#value' => adsense_managed_help_text(),
+    '#markup' => adsense_managed_help_text(),
   );
 
   $form['blocks'] = array(
diff -rup managed/adsense_managed.info managed/adsense_managed.info
--- managed/adsense_managed.info	2010-08-21 01:01:58.000000000 +0200
+++ managed/adsense_managed.info	2011-01-07 11:26:59.352462200 +0100
@@ -6,11 +6,11 @@ name = Managed ads
 description = Ad unit generator module using the new managed ads feature available in the Google AdSense site.
 dependencies[] = adsense
 package = Adsense
-core = 6.x
+core = 7.x
+version = 7.x-2-dev
 
-; Information added by drupal.org packaging script on 2010-08-21
-version = "6.x-1.x-dev"
-core = "6.x"
-project = "adsense"
-datestamp = "1282348918"
+files[] = adsense_managed.module
+files[] = adsense_managed.install
+files[] = adsense_managed.admin.inc
 
+configure = admin/config/adsense/managed
diff -rup managed/adsense_managed.install managed/adsense_managed.install
--- managed/adsense_managed.install	2008-07-21 01:21:34.000000000 +0200
+++ managed/adsense_managed.install	2011-01-07 11:26:59.370463200 +0100
@@ -7,12 +7,10 @@
  */
 
 /**
- * Implementation of hook_uninstall().
+ * Implements hook_uninstall().
  */
 function adsense_managed_uninstall() {
-  variable_del('adsense_managed_number_blocks');
-  $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'adsense\_managed\_ad\_block\_%'");
-  while ($variable = db_fetch_object($settings)) {
-    variable_del($variable->name);
-  }
+  // Delete all the AdSense variables and then clear the variable cache.
+  db_query("DELETE FROM {variable} WHERE name LIKE 'adsense\_managed\_%'");
+  cache_clear_all('variables', 'cache');
 }
diff -rup managed/adsense_managed.module managed/adsense_managed.module
--- managed/adsense_managed.module	2010-01-11 12:20:30.000000000 +0100
+++ managed/adsense_managed.module	2011-01-07 11:26:59.398464800 +0100
@@ -13,12 +13,12 @@ define('ADSENSE_MANAGED_AD_BLOCK_DEFAULT
 define('ADSENSE_MANAGED_NUMBER_BLOCKS_DEFAULT', 3);
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function adsense_managed_menu() {
   $items = array();
 
-  $items['admin/settings/adsense/managed'] = array(
+  $items['admin/config/adsense/managed'] = array(
     'title' => 'Managed Ads',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('adsense_managed_settings'),
@@ -32,91 +32,98 @@ function adsense_managed_menu() {
 }
 
 /**
- * Implementation of hook_block().
+ * Implements hook_block_info().
  */
-function adsense_managed_block($op = 'list', $delta = 0, $edit = array()) {
-  $block = NULL;
+function adsense_managed_block_info() {
+  $blocks = array();
+  $max = variable_get('adsense_managed_number_blocks', ADSENSE_MANAGED_NUMBER_BLOCKS_DEFAULT);
+  
+  for ($count=0 ; $count < $max ; $count++) {
+    if ($ad = _adsense_managed_get_block_config($count)) {
+      $title = $ad[0];
+    }
+    else {
+      $title = t('AdSense: unconfigured ') . $count;
+    }
+    $blocks[$count] = array(
+      'info' => $title,
+      'cache' => DRUPAL_NO_CACHE,
+    );
+  }
+  
+  return $blocks;
+}
+
+/**
+ * Implements hook_block_configure().
+ */
+function adsense_managed_block_configure($delta = '') {
+  $ad = _adsense_managed_get_block_config($delta);
+  foreach (adsense_ad_formats() as $format => $data) {
+    $ad_list[$format] = $format .' : '. $data['desc'];
+  }
+  
+  $form['info'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Block description'),
+    '#default_value' => ($ad) ? $ad[0] : '',
+    '#maxlength' => 64,
+    '#description' => t('A brief description of your block. Used on the <a href="@overview">block overview page</a>.', array('@overview' => url('admin/structure/block'))),
+    '#required' => TRUE,
+    '#weight' => -19,
+  );
+  $form['ad_format'] = array(
+    '#type' => 'select',
+    '#title' => t('Ad format'),
+    '#default_value' => ($ad) ? $ad[1] : '250x250',
+    '#options' => $ad_list,
+    '#description' => t('Select the ad dimensions you want for this block.'),
+    '#required' => TRUE,
+  );
+  $form['ad_slot'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Ad Slot ID'),
+    '#default_value' => ($ad) ? $ad[2] : '',
+    '#description' => t('This is the Ad Slot ID from your Google Adsense account, such as 0123456789.'),
+    '#required' => TRUE,
+  );
+  $form['ad_align'] = array(
+    '#type' => 'select',
+    '#title' => t('Ad alignment'),
+    '#default_value' => ($ad) ? $ad[3] : 'center',
+    '#options' => array(
+      '' => t('None'),
+      'left' => t('Left'),
+      'center' => t('Centered'),
+      'right' => t('Right')
+    ),
+    '#description' => t('Select the horizontal alignment of the ad within the block.'),
+  );
+  
+  return $form;
+}
+
+/**
+ * Implements hook_block_save().
+ */
+function adsense_managed_block_save($delta = '', $edit = array()) {
+  $data = implode(':', array(urlencode($edit['info']), $edit['ad_format'], $edit['ad_slot'], $edit['ad_align']));
+  variable_set('adsense_managed_ad_block_'. $delta, $data);
+}
 
-  switch ($op) {
-    case 'list':
-      $max = variable_get('adsense_managed_number_blocks', ADSENSE_MANAGED_NUMBER_BLOCKS_DEFAULT);
-      for ($count=0 ; $count < $max ; $count++) {
-        if ($ad = _adsense_managed_get_block_config($count)) {
-          $title = $ad[0];
-        }
-        else {
-          $title = t('AdSense: unconfigured ') . $count;
-        }
-        $block[$count]['info'] = $title;
-        $block[$count]['cache'] = BLOCK_NO_CACHE;
-      }
-      break;
-
-    case 'configure':
-      $ad = _adsense_managed_get_block_config($delta);
-
-      foreach (adsense_ad_formats() as $format => $data) {
-        $ad_list[$format] = $format .' : '. $data['desc'];
-      }
-
-      $form['info'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Block description'),
-        '#default_value' => ($ad) ? $ad[0] : '',
-        '#maxlength' => 64,
-        '#description' => t('A brief description of your block. Used on the <a href="@overview">block overview page</a>.', array('@overview' => url('admin/build/block'))),
-        '#required' => TRUE,
-        '#weight' => -19,
-      );
-
-      $form['ad_format'] = array(
-        '#type' => 'select',
-        '#title' => t('Ad format'),
-        '#default_value' => ($ad) ? $ad[1] : '250x250',
-        '#options' => $ad_list,
-        '#description' => t('Select the ad dimensions you want for this block.'),
-        '#required' => TRUE,
-      );
-
-      $form['ad_slot'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Ad Slot ID'),
-        '#default_value' => ($ad) ? $ad[2] : '',
-        '#description' => t('This is the Ad Slot ID from your Google Adsense account, such as 0123456789.'),
-        '#required' => TRUE,
-      );
-
-      $form['ad_align'] = array(
-        '#type' => 'select',
-        '#title' => t('Ad alignment'),
-        '#default_value' => ($ad) ? $ad[3] : 'center',
-        '#options' => array(
-          '' => t('None'),
-          'left' => t('Left'),
-          'center' => t('Centered'),
-          'right' => t('Right')
-        ),
-        '#description' => t('Select the horizontal alignment of the ad within the block.'),
-      );
-
-      return $form;
-
-    case 'save':
-      $data = implode(':', array(urlencode($edit['info']), $edit['ad_format'], $edit['ad_slot'], $edit['ad_align']));
-      variable_set('adsense_managed_ad_block_'. $delta, $data);
-      return;
-
-    case 'view':
-      if (_adsense_page_match()) {
-        $ad = _adsense_managed_get_block_config($delta);
-        $block['content'] = ($ad) ? adsense_display(array('format' => $ad[1], 'slot' => $ad[2])) : t('AdSense unconfigured block. <a href=!url>Click to configure.</a>', array('!url' => url('admin/build/block/configure/adsense_managed/'. $delta)));
-        if (!empty($ad[3])) {
-          $block['content'] = "<div style='text-align:${ad[3]}'>${block['content']}</div>";
-        }
-      }
-      break;
+/**
+ * Implements hook_block_view().
+ */
+function adsense_managed_block_view($delta = '') {
+  if (_adsense_page_match()) {
+    $ad = _adsense_managed_get_block_config($delta);
+    $block['content'] = ($ad) ? adsense_display(array('format' => $ad[1], 'slot' => $ad[2])) : t('AdSense unconfigured block. <a href=!url>Click to configure.</a>', array('!url' => url('admin/structure/block/manage/adsense_managed/'. $delta)));
+    if (!empty($ad[3])) {
+      $block['content'] = "<div style='text-align:${ad[3]}'>${block['content']}</div>";
     }
-  return $block;
+    
+    return $block;
+  }
 }
 