ad_html.module in Advertisement 7
Same filename and directory in other branches
Enhances the ad module to support html ads.
Copyright (c) 2005-2009. Jeremy Andrews <jeremy@tag1consulting.com>.
File
html/ad_html.moduleView source
<?php
/**
* @file
* Enhances the ad module to support html ads.
*
* Copyright (c) 2005-2009.
* Jeremy Andrews <jeremy@tag1consulting.com>.
*/
/**
* Function used to display the selected ad.
*/
function ad_html_display_ad($ad) {
return theme('ad_html_ad', array(
'ad' => $ad,
));
}
/**
* Return a themed ad of type ad_html.
*
* @param @ad
* The ad object.
* @return
* A string containing the ad markup.
*/
function theme_ad_html_ad($variables) {
$ad = $variables['ad'];
if (isset($ad->aid)) {
$output = '<div class="html-advertisement" id="ad-' . $ad->aid . '">';
if (isset($ad->html)) {
$output .= check_markup($ad->html, 'full_html');
}
$output .= '</div>';
return $output;
}
}
/**
* Implementation of hook_theme().
*/
function ad_html_theme() {
return array(
'ad_html_ad' => array(
'file' => 'ad_html.module',
'variables' => array(
'ad' => NULL,
),
),
);
}
/**
* Implementation of hook_help().
*/
function ad_html_help($path, $arg) {
$output = '';
switch ($path) {
case 'node/add/ad#html':
$output = t('A html advertisement.');
break;
}
return $output;
}
/**
* Implementation of the ad module's _adapi hook.
*/
function ad_html_adapi($op, $node) {
switch ($op) {
case 'load':
$return = db_query('SELECT html FROM {ad_html} WHERE aid = :aid', array(
':aid' => $node->aid,
))
->fetchAssoc();
$return['ad'] = check_markup($return['html'], 'full_html');
return $return;
case 'insert':
db_query("INSERT INTO {ad_html} (aid, html) VALUES(:aid, :html)", array(
':aid' => $node->nid,
':html' => $node->html,
));
break;
case 'update':
db_query("UPDATE {ad_html} SET html = :html WHERE aid = :aid", array(
':html' => $node->html,
':aid' => $node->nid,
));
break;
case 'delete':
db_query('DELETE FROM {ad_html} WHERE aid = :aid', array(
':aid' => $node->nid,
));
break;
case 'form':
return _ad_html_node_form($node);
case 'view':
return _ad_html_node_view($node);
case 'type':
return array(
'html' => array(
'name' => t('HTML ad'),
'module' => 'ad_html',
'description' => t('A html advertisement.'),
'help' => t('A html advertisement.'),
),
);
case 'permissions':
if (!isset($node->adtype) || $node->adtype == 'html') {
return array(
'manage ad html' => TRUE,
);
}
}
}
/**
* Adapi helper function for displaying a node form.
*/
function _ad_html_node_form(&$node) {
$form = array();
$form['ad_html'] = array(
'#type' => 'fieldset',
'#title' => t('HTML'),
'#collapsible' => TRUE,
);
$form['ad_html']['display'] = array(
'#type' => 'markup',
'#value' => ad_html_display_ad($node),
);
if (isset($node->nid) && ad_check_permission($node->nid, 'manage ad html') || arg(1) == 'add' && user_access('create advertisements')) {
$form['ad_html']['html'] = array(
'#type' => 'textarea',
'#title' => t('Ad HTML'),
'#required' => TRUE,
'#default_value' => isset($node->html) ? $node->html : '',
'#description' => t('Paste the complete HTML provided by your advertising affiliate.'),
);
}
return $form;
}
/**
* Helper function, display the html ad as a node.
*/
function _ad_html_node_view(&$node) {
$node->content['ad'] = array(
'#value' => theme('ad_box', array(
'title' => '',
'content' => stripslashes(ad_html_display_ad($node)),
)),
'#weight' => -1,
);
}
Functions
Name | Description |
---|---|
ad_html_adapi | Implementation of the ad module's _adapi hook. |
ad_html_display_ad | Function used to display the selected ad. |
ad_html_help | Implementation of hook_help(). |
ad_html_theme | Implementation of hook_theme(). |
theme_ad_html_ad | Return a themed ad of type ad_html. |
_ad_html_node_form | Adapi helper function for displaying a node form. |
_ad_html_node_view | Helper function, display the html ad as a node. |