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