simple_adsense.module in Simple AdSense 7
Same filename and directory in other branches
Module file for Simple AdSense.
File
simple_adsense.moduleView 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",
));
}
}
Functions
Name | Description |
---|---|
simple_adsense_block_info | Implements hook_block_info(). |
simple_adsense_block_view | Implements hook_block_view(). |
simple_adsense_help | Implements hook_help(). |
simple_adsense_menu | Implements hook_menu(). |
simple_adsense_preprocess_block | Implements template_preprocess_block(). |
simple_adsense_theme | Implements hook_theme(). |