annotate html/ad_html.module @ 8:32c1a7d9e1fa ad tip

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