ad_client.module in Advertisement 6.3
An advertising system for Drupal powered websites.
Client side module
Copyright (c) 2005-2009. Jeremy Andrews <jeremy@tag1consulting.com>.
Portions Copyright (c) 2010-2011. John Franklin <franklin@sentaidigital.com>
File
client/ad_client.moduleView source
<?php
/**
* @file
* An advertising system for Drupal powered websites.
*
* Client side module
*
* Copyright (c) 2005-2009.
* Jeremy Andrews <jeremy@tag1consulting.com>.
*
* Portions Copyright (c) 2010-2011.
* John Franklin <franklin@sentaidigital.com>
*/
/**
* Implementation of hook_init.
*/
function ad_client_init() {
// We do this in the init hook so that it doesn't get skipped when block
// caching is enabled.
$method = variable_get('ad_display', 'javascript');
if ($method == 'jquery') {
drupal_add_js('misc/jquery.js', 'core');
}
}
/*
* Implementation of hook_perm()
*/
function ad_client_perm() {
return array(
'exempt from advertising',
);
}
/**
* Implementation of hook_block().
*/
function ad_client_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks = array();
$groups = ad_groups_list();
foreach ($groups as $tid => $name) {
$blocks[$tid] = array(
'info' => t('ad group: @name', array(
'@name' => $name,
)),
'cache' => BLOCK_CACHE_PER_PAGE,
);
}
return $blocks;
case 'configure':
$form['ad_block_quantity_' . $delta] = array(
'#type' => 'select',
'#title' => t('Number of ads'),
'#default_value' => variable_get('ad_block_quantity_' . $delta, 1),
'#options' => drupal_map_assoc(array(
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
)),
'#description' => t('Select the maximum number of unique ads that should be displayed together in this block. If you specify a number larger than the maximum number of ads in this ad group, all ads will be displayed once.'),
);
return $form;
case 'save':
variable_set('ad_block_quantity_' . $delta, $edit['ad_block_quantity_' . $delta]);
break;
case 'view':
$block['content'] = ad($delta, variable_get('ad_block_quantity_' . $delta, 1));
return $block;
}
}
/**
* Implementation of hook_theme()
*/
function ad_client_theme() {
return array(
'ad_display' => array(
'file' => 'ad.module',
'arguments' => array(
'group' => NULL,
'display' => NULL,
'method' => 'javascript',
),
),
);
}
/**
* Function to display the actual advertisement to the screen. Wrap it in a
* theme function to make it possible to customize in your own theme.
*/
function theme_ad_display($group, $display, $method = 'javascript') {
static $id = -1;
// Increment counter for displaying multiple advertisements on the page.
$id++;
// The naming convention for the id attribute doesn't allow commas.
$group = preg_replace('/[,]/', '+', $group);
if ($method == 'jquery') {
return "\n<div class=\"advertisement group-{$group}\" id=\"group-id-{$group}-{$id}\">\n <script type=\"text/javascript\">\n//<![CDATA[\n \$(document).ready(function(){ jQuery(\"div#group-id-{$id}\").load(\"{$display}\"); });\n //]]>\n </script>\n</div>\n";
}
else {
if ($method == 'raw') {
return $display;
}
else {
return "\n<div class=\"advertisement group-{$group}\" id=\"group-id-{$group}-{$id}\">{$display}</div>\n";
}
}
}
/**
* Ad API Helper Function:
* Append all necessary attributes to <a> tags.
*/
function ad_client_link_attributes() {
return array_merge(ad_link_target(TRUE), ad_link_nofollow(TRUE));
}
/**
* Ad API Helper Function:
* Provide XHTML-strict-compatible target window onclick-handlers based on
* global configuration.
*/
function ad_client_link_target() {
switch (variable_get('ad_link_target', '_self')) {
case '_blank':
$target = array(
'onclick' => 'window.open(this.href); return false;',
);
break;
case '_parent':
$target = array(
'onclick' => 'window.parent.location = this.href; return false;',
);
break;
case '_top':
$target = array(
'onclick' => 'window.top.location = this.href; return false;',
);
break;
default:
$target = array();
break;
}
return $target;
}
/**
* Ad API Helper Function:
* Append rel="nofollow" if globally enabled.
*/
function ad_client_link_nofollow() {
if (variable_get('ad_link_nofollow', 0)) {
$nofollow = array(
'rel' => 'nofollow',
);
}
else {
$nofollow = array();
}
return $nofollow;
}
/**
* Add the noindex meta tag.
*/
function ad_client_noindex_meta() {
static $added = FALSE;
if (!$added) {
drupal_set_html_head('<meta name="robots" content="noindex" />');
$added = TRUE;
}
}
Functions
Name | Description |
---|---|
ad_client_block | Implementation of hook_block(). |
ad_client_init | Implementation of hook_init. |
ad_client_link_attributes | Ad API Helper Function: Append all necessary attributes to <a> tags. |
ad_client_link_nofollow | Ad API Helper Function: Append rel="nofollow" if globally enabled. |
ad_client_link_target | Ad API Helper Function: Provide XHTML-strict-compatible target window onclick-handlers based on global configuration. |
ad_client_noindex_meta | Add the noindex meta tag. |
ad_client_perm | |
ad_client_theme | Implementation of hook_theme() |
theme_ad_display | Function to display the actual advertisement to the screen. Wrap it in a theme function to make it possible to customize in your own theme. |