annotate html/ad_html.module @ 0:d8a3998dac8e ad

ajout module ad
author pierre
date Fri, 20 Feb 2009 14:04:09 +0000
parents
children 948362c2a207
rev   line source
pierre@0 1 <?php
pierre@0 2 // $Id: ad_html.module,v 1.1.2.5.2.8 2009/02/17 18:56:26 jeremy Exp $
pierre@0 3
pierre@0 4 /**
pierre@0 5 * @file
pierre@0 6 * Enhances the ad module to support html ads.
pierre@0 7 *
pierre@0 8 * Copyright (c) 2005-2009.
pierre@0 9 * Jeremy Andrews <jeremy@tag1consulting.com>.
pierre@0 10 */
pierre@0 11
pierre@0 12
pierre@0 13 /**
pierre@0 14 * Function used to display the selected ad.
pierre@0 15 */
pierre@0 16 function ad_html_display_ad($ad) {
pierre@0 17 return theme('ad_html_ad', $ad);
pierre@0 18 }
pierre@0 19
pierre@0 20 /**
pierre@0 21 * Return a themed ad of type ad_html.
pierre@0 22 *
pierre@0 23 * @param @ad
pierre@0 24 * The ad object.
pierre@0 25 * @return
pierre@0 26 * A string containing the ad markup.
pierre@0 27 */
pierre@0 28 function theme_ad_html_ad($ad) {
pierre@0 29 if (isset($ad->aid)) {
pierre@0 30 $output = '<div class="html-advertisement" id="ad-'. $ad->aid .'">';
pierre@0 31 $output .= check_markup($ad->html, $ad->format, FALSE);
pierre@0 32 $output .= '</div>';
pierre@0 33 return $output;
pierre@0 34 }
pierre@0 35 }
pierre@0 36
pierre@0 37 /**
pierre@0 38 * Implementation of hook_theme().
pierre@0 39 */
pierre@0 40 function ad_html_theme() {
pierre@0 41 return array(
pierre@0 42 'ad_html_ad' => array(
pierre@0 43 'file' => 'ad_html.module',
pierre@0 44 'arguments' => array(
pierre@0 45 'ad' => NULL,
pierre@0 46 ),
pierre@0 47 ),
pierre@0 48 );
pierre@0 49 }
pierre@0 50
pierre@0 51 /**
pierre@0 52 * Implementation of hook_help().
pierre@0 53 */
pierre@0 54 function ad_html_help($path, $arg) {
pierre@0 55 $output = '';
pierre@0 56 switch ($path) {
pierre@0 57 case 'node/add/ad#html':
pierre@0 58 $output = t('A html advertisement.');
pierre@0 59 break;
pierre@0 60 }
pierre@0 61 return $output;
pierre@0 62 }
pierre@0 63
pierre@0 64 /**
pierre@0 65 * Implementation of hook_access().
pierre@0 66 */
pierre@0 67 function ad_html_access($op, $node, $account) {
pierre@0 68 return ad_access($op, $node, $account);
pierre@0 69 }
pierre@0 70
pierre@0 71 /**
pierre@0 72 * Implementation of the ad module's _adapi hook.
pierre@0 73 */
pierre@0 74 function ad_html_adapi($op, &$node) {
pierre@0 75 switch ($op) {
pierre@0 76 case 'load':
pierre@0 77 $return = db_fetch_array(db_query('SELECT html FROM {ad_html} WHERE aid = %d', $node['aid']));
pierre@0 78 $return['ad'] = check_markup($return['html'], $node['format'], FALSE);
pierre@0 79 return $return;
pierre@0 80
pierre@0 81 case 'insert':
pierre@0 82 db_query("INSERT INTO {ad_html} (aid, html) VALUES(%d, '%s')", $node->nid, $node->html);
pierre@0 83 break;
pierre@0 84
pierre@0 85 case 'update':
pierre@0 86 db_query("UPDATE {ad_html} SET html = '%s' WHERE aid = %d", $node->html, $node->nid);
pierre@0 87 break;
pierre@0 88
pierre@0 89 case 'delete':
pierre@0 90 db_query('DELETE FROM {ad_html} WHERE aid = %d', $node->nid);
pierre@0 91 break;
pierre@0 92
pierre@0 93 case 'form':
pierre@0 94 return ad_html_node_form($node);
pierre@0 95
pierre@0 96 case 'view':
pierre@0 97 return ad_html_node_view($node);
pierre@0 98
pierre@0 99 case 'type':
pierre@0 100 return array(
pierre@0 101 'html' => array(
pierre@0 102 'name' => t('HTML ad'),
pierre@0 103 'module' => 'ad_html',
pierre@0 104 'description' => t('A html advertisement.'),
pierre@0 105 'help' => t('A html advertisement.'),
pierre@0 106 ),
pierre@0 107 );
pierre@0 108 case 'permissions':
pierre@0 109 if (!isset($node->adtype) || $node->adtype == 'html') {
pierre@0 110 return array('manage ad html');
pierre@0 111 }
pierre@0 112 }
pierre@0 113 }
pierre@0 114
pierre@0 115 /**
pierre@0 116 * Adapi helper function for displaying a node form.
pierre@0 117 */
pierre@0 118 function ad_html_node_form(&$node) {
pierre@0 119 $form = array();
pierre@0 120
pierre@0 121 $form['ad_html'] = array(
pierre@0 122 '#type' => 'fieldset',
pierre@0 123 '#title' => t('HTML'),
pierre@0 124 '#collapsible' => TRUE,
pierre@0 125 );
pierre@0 126
pierre@0 127 $form['ad_html']['display'] = array(
pierre@0 128 '#type' => 'markup',
pierre@0 129 '#value' => ad_html_display_ad($node),
pierre@0 130 );
pierre@0 131
pierre@0 132 if (ad_adaccess($node, 'manage ad html') || arg(1) == 'add' && user_access('create advertisements')) {
pierre@0 133 $form['ad_html']['html'] = array(
pierre@0 134 '#type' => 'textarea',
pierre@0 135 '#title' => t('Ad HTML'),
pierre@0 136 '#required' => TRUE,
pierre@0 137 '#default_value' => isset($node->html) ? $node->html : '',
pierre@0 138 '#description' => t('Paste the complete HTML provided by your advertising affiliate.'),
pierre@0 139 );
pierre@0 140 }
pierre@0 141
pierre@0 142 return $form;
pierre@0 143 }
pierre@0 144
pierre@0 145 /**
pierre@0 146 * Helper function, display the html ad as a node.
pierre@0 147 */
pierre@0 148 function ad_html_node_view(&$node) {
pierre@0 149 $node->content['ad'] = array(
pierre@0 150 '#value' => theme('box', '', stripslashes(ad_html_display_ad($node))),
pierre@0 151 '#weight' => -1,
pierre@0 152 );
pierre@0 153 }
pierre@0 154