Commit e28ac5f2 authored by João Ventura's avatar João Ventura
Browse files

Moved the module configuration path from "System" to "Web services"

Synced the generated ad javascript with the current output from Google
Synced the CSE watermark javascript with the one from Google
Ported the "old" modules to D7 (necessary for revenue sharing)
Started work on porting the revenue sharing to D7.
parent 377eeda8
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -30,13 +30,13 @@ directory.

Configuration
-------------
To enable this module, visit Administer -> Site building -> Modules, and
enable adsense, and one of the other modules in the Adsense group. The modules
marked as '(old)' are not using the new 'Managed Ads' feature of Google
AdSense, so you should only use them if you have ads in the old format or if
you know what you're doing.
To enable this module, visit Administration -> Modules, and enable adsense,
and one of the other modules in the Adsense group.  The modules marked as
'(old)' are not using the new 'Managed Ads' feature of Google AdSense, so
you should only use them if you have ads in the old format or if you know
what you're doing.

To configure it, go to Administer -> Site configuration -> AdSense.
To configure it, go to Administration > Configuration > Web services > AdSense

Follow the online instructions on that page on how to display ads and the
various ways to do so.
@@ -86,7 +86,7 @@ function your_module_adsense($op, $args = array()) {
}

Your module's settings form must be of type MENU_LOCAL_TASK and located in
'admin/settings/adsense/publisher/your_module'.
'admin/config/services/adsense/publisher/your_module'.

After you install the module, it should appear on the adsense module settings
page, along with other modules. You should be able to select it, and configure
@@ -103,7 +103,7 @@ http://drupal.org/project/adsense
Authors
-------
Khalid Baheyeldin (http://baheyeldin.com/khalid and http://2bits.com)
Joao Ventura      (http://www.venturas.org)
Joao Ventura      (http://venturas.org)

If you use this module, find it useful, and want to send the authors a thank
you note, then use the Feedback/Contact page at the URLs above.
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ description = Displays Google AdSense ads on your site to earn revenue. Requires
package = Adsense
core = 7.x

configure = admin/config/system/adsense
configure = admin/config/services/adsense

files[] = adsense.module
files[] = adsense.install
+13 −3
Original line number Diff line number Diff line
@@ -5,6 +5,15 @@
 * Install file of the adsense module
 */

/**
 * Implements of hook_install().
 */
function adsense_install() {
  drupal_set_message(st("AdSense settings are available under !link",
    array( '!link' => l(st('Administration > Configuration > Web services > AdSense'),  'admin/config/services/adsense' ) )
  ));
}

/**
 * Implements hook_uninstall().
 */
@@ -19,7 +28,8 @@ function adsense_uninstall() {
  variable_del('adsense_test_mode');
  variable_del('adsense_visibility');

  // 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');
  $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'adsense\_ad\_channel\_%'");
  foreach ($settings as $variable) {
    variable_del($variable->name);
  }
}
+44 −34
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ function adsense_theme() {
function adsense_menu() {
  $items = array();

  $items['admin/config/system/adsense'] = array(
  $items['admin/config/services/adsense'] = array(
    'title' => 'AdSense',
    'description' => 'Configure Google AdSense Ads.',
    'page callback' => 'drupal_get_form',
@@ -135,12 +135,12 @@ function adsense_menu() {
    'access arguments'  => array('administer adsense'),
    'file' => 'adsense.admin.inc',
  );
  $items['admin/config/system/adsense/main'] = array(
  $items['admin/config/services/adsense/main'] = array(
    'title' => 'Settings',
    'weight' => 10,
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );
  $items['admin/config/system/adsense/publisher'] = array(
  $items['admin/config/services/adsense/publisher'] = array(
    'title' => 'Publisher ID',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('adsense_id_settings'),
@@ -149,7 +149,7 @@ function adsense_menu() {
    'type' => MENU_LOCAL_TASK,
    'file' => 'adsense.admin.inc',
  );
  $items['admin/config/system/adsense/publisher/site'] = array(
  $items['admin/config/services/adsense/publisher/site'] = array(
    'title' => 'Site ID',
    'weight' => -1,
    'type' => MENU_DEFAULT_LOCAL_TASK,
@@ -172,7 +172,7 @@ function adsense_requirements($phase) {
        $requirements['adsense_basic_id'] = array(
          'title' => $t('AdSense'),
          'value' => $t('Publisher ID is not set.'),
          'description' => $t('Please configure it in the <a href="@url">AdSense Publisher ID settings page</a>.', array('@url' => url('admin/config/system/adsense/publisher'))),
          'description' => $t('Please configure it in the <a href="@url">AdSense Publisher ID settings page</a>.', array('@url' => url('admin/config/services/adsense/publisher'))),
          'severity' => REQUIREMENT_ERROR,
        );
      }
@@ -181,6 +181,17 @@ function adsense_requirements($phase) {
  return $requirements;
}

/**
 * Implements hook_help().
 */
function adsense_help($path, $arg) {
  switch ($path) {
    case 'admin/help#adsense':
      include_once(drupal_get_path('module', 'adsense') . '/help/adsense.help.inc');
      return adsense_help_text();
  }
}

/**
 * Implements hook_filter_info().
 */
@@ -197,12 +208,19 @@ function adsense_filter_info() {
}

/**
 * Helper function to process the adsense input filter.
 * 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.');
}

/**
 * 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.
 *   modified text with the adsense tags replaced by Google AdSense ads
 *
 * @see adsense_filter_info()
 * @see adsense_display()
@@ -230,7 +248,7 @@ function _adsense_process_tags($text, $filter) {
              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.
                    // Found the block with the same name as the passed arg
                    $block = module_invoke($module, 'block_view', $delta);
                    $ad = $block['content'];
                  }
@@ -275,13 +293,6 @@ function _adsense_process_tags($text, $filter) {
  return $text;
}

/**
 * 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().
 */
@@ -300,23 +311,23 @@ function adsense_node_view($node, $view_mode, $langcode) {
}

/**
 * Provides the Google AdSense Publisher ID / slot ID to be used in the ad.
 * 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) {
@@ -359,7 +370,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';
@@ -387,13 +398,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;
@@ -414,21 +425,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')) {
@@ -460,7 +471,7 @@ function adsense_display() {

        break;
    }
    // Remove empty lines.
    // Remove empty lines
    $ad = str_replace("\n\n", "\n", $ad);
  }

@@ -484,14 +495,14 @@ function theme_adsense_ad($vars) {
}

/**
 * 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)) {
@@ -563,8 +574,7 @@ function _adsense_page_match() {
    if ($visibility == 2) {
      return php_eval($pages);
    }
    $pages = drupal_strtolower($pages);
    $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
    $path = 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);
+5 −3
Original line number Diff line number Diff line
@@ -7,7 +7,9 @@ dependencies[] = adsense
package = Adsense
core = 7.x

files[] = adsense_cse.module
files[] = adsense_cse.install
files[] = adsense_cse.admin.inc
configure = admin/config/services/adsense/click

files[] = adsense_click.module
files[] = adsense_click.install
files[] = adsense_click.admin.inc
files[] = adsense_click.logs.inc
Loading