| 1 |
<?php
|
| 2 |
// $Id: advert.module,v 1.5 2009/01/26 19:14:02 goba Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Prefix for variable names used to store advertisements.
|
| 6 |
*/
|
| 7 |
define('ADVERT_BLOCK_BODY', 'advert_block_body_');
|
| 8 |
|
| 9 |
/**
|
| 10 |
* List of all ad blocks. This is the only place to add blocks to if you need more.
|
| 11 |
*/
|
| 12 |
function _advert_list_blocks() {
|
| 13 |
$list = array();
|
| 14 |
|
| 15 |
$list[0]['forum'] = 51;
|
| 16 |
$list[0]['title'] = t('Paid services forum ad');
|
| 17 |
|
| 18 |
$list[1]['forum'] = 34;
|
| 19 |
$list[1]['title'] = t('Affiliate hosting header ad');
|
| 20 |
|
| 21 |
$list[2]['forum'] = 51;
|
| 22 |
$list[2]['title'] = t('Affiliate paid-services Ad with Google Ad Manager');
|
| 23 |
|
| 24 |
return $list;
|
| 25 |
}
|
| 26 |
|
| 27 |
/**
|
| 28 |
* Get master data for a particular block, by delta.
|
| 29 |
*/
|
| 30 |
function _advert_get_block($delta) {
|
| 31 |
$list = _advert_list_blocks();
|
| 32 |
return $list[$delta];
|
| 33 |
}
|
| 34 |
|
| 35 |
/**
|
| 36 |
* Implementation of hook_block().
|
| 37 |
*/
|
| 38 |
function advert_block($op = 'list', $delta = 0, $edit = array()) {
|
| 39 |
switch ($op) {
|
| 40 |
case 'list':
|
| 41 |
$blocks = array();
|
| 42 |
foreach(_advert_list_blocks() as $block_delta => $block_data) {
|
| 43 |
$blocks[$block_delta]['info'] = $block_data['title'];
|
| 44 |
}
|
| 45 |
return $blocks;
|
| 46 |
|
| 47 |
case 'configure':
|
| 48 |
$form = array();
|
| 49 |
|
| 50 |
// Provide form to enter ad details.
|
| 51 |
$form[ADVERT_BLOCK_BODY . $delta] = array(
|
| 52 |
'#type' => 'textarea',
|
| 53 |
'#title' => t('HTML and/or Javascript'),
|
| 54 |
'#description' => t('Enter HTML and/or Javascript to display in this block'),
|
| 55 |
'#default_value' => variable_get(ADVERT_BLOCK_BODY . $delta, ''),
|
| 56 |
);
|
| 57 |
return $form;
|
| 58 |
|
| 59 |
case 'save':
|
| 60 |
variable_set(ADVERT_BLOCK_BODY . $delta, $edit[ADVERT_BLOCK_BODY . $delta]);
|
| 61 |
return;
|
| 62 |
|
| 63 |
case 'view':
|
| 64 |
$block_data = _advert_get_block($delta);
|
| 65 |
$forum = $block_data['forum'];
|
| 66 |
if (advert_is_in_forum($forum)) {
|
| 67 |
$block['subject'] = $block_data['title'];
|
| 68 |
$block['content'] = variable_get(ADVERT_BLOCK_BODY . $delta, '');
|
| 69 |
return $block;
|
| 70 |
}
|
| 71 |
}
|
| 72 |
}
|
| 73 |
|
| 74 |
/**
|
| 75 |
* Are we in the appropriate forum to display that ad?
|
| 76 |
*/
|
| 77 |
function advert_is_in_forum($forum_id) {
|
| 78 |
return ((arg(0) == 'forum') && (arg(1) == $forum_id)) ||
|
| 79 |
((arg(0) == 'node') && is_numeric(arg(1)) && ($node = menu_get_object()) && (($node->type == 'forum') && ($node->tid == $forum_id)));
|
| 80 |
}
|