You are here

simple_adsense.module in Simple AdSense 7

Same filename and directory in other branches
  1. 8.0 simple_adsense.module
  2. 1.0.x simple_adsense.module

Module file for Simple AdSense.

File

simple_adsense.module
View source
<?php

/**
 * @file
 * Module file for Simple AdSense.
 */

/**
 * Implements hook_help().
 */
function simple_adsense_help($path, $arg) {
  switch ($path) {
    case "admin/help#simple_adsense":
      return check_markup(file_get_contents(dirname(__FILE__) . "/README.txt"));
    case 'admin/config/content/simple_adsense':
      $link = array(
        "!google" => l(t("Google Adsense"), "https://www.google.com/adsense/app", array(
          'attributes' => array(
            'target' => '_blank',
          ),
        )),
      );
      return '<p>' . t("Input here client and slot(s) got from !google Custom Ad unit(s).", $link) . '</p>';
    case 'admin/structure/block':
      return '<p>' . t("Blocks blow which title starts with Simpel Adsense are Simple Adsense blocks.") . '</p>';
  }
}

/**
 * Implements hook_menu().
 */
function simple_adsense_menu() {
  $items['admin/config/content/simple_adsense'] = array(
    'title' => 'Simple Adsense',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'simple_adsense_settings',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'description' => 'configure adsense info',
    'file' => 'simple_adsense.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_block_info().
 */
function simple_adsense_block_info() {
  $blocks = array();
  $client = variable_get("simple_adsense_client", NULL);
  $slots = variable_get("simple_adsense_slots", NULL);
  if (isset($client) && isset($slots)) {
    foreach ($slots as $key => $value) {
      $blocks["simple_adsense_slot" . $key] = array(
        'info' => t('Simple Adsense (@val)', array(
          "@val" => $value,
        )),
        'cache' => DRUPAL_NO_CACHE,
      );
    }
  }
  return $blocks;
}

/**
 * Implements hook_block_view().
 *
 * @delta.
 */
function simple_adsense_block_view($delta = '') {
  $block = array();
  $client = variable_get("simple_adsense_client", NULL);
  $slots = variable_get("simple_adsense_slots", NULL);
  if (isset($client) && isset($slots)) {
    foreach ($slots as $key => $value) {
      if ($delta == "simple_adsense_slot" . $key) {
        $block['subject'] = '<none>';
        $block['content'] = array(
          '#theme' => 'ad_unit',
          '#slot' => $value,
          '#client' => "ca-" . $client,
        );
      }
    }
  }
  return $block;
}

/**
 * Implements hook_theme().
 */
function simple_adsense_theme($existing, $type, $theme, $path) {
  return array(
    'ad_unit' => array(
      'template' => 'ad_unit',
      'variables' => array(
        'slot' => NULL,
        'client' => NULL,
      ),
    ),
  );
}

/**
 * Implements template_preprocess_block().
 *
 * Add a custom class to our blocks.
 */
function simple_adsense_preprocess_block(&$variables) {
  $delta = $variables['block']->delta;
  if (preg_match('/^simple_adsense_slot\\d+$/', $delta)) {
    $variables["classes_array"] = array_merge($variables["classes_array"], array(
      "simple-adsense",
    ));
  }
}