pierre@0: . pierre@0: */ pierre@0: pierre@0: pierre@0: /** pierre@0: * Function used to display the selected ad. pierre@0: */ pierre@0: function ad_html_display_ad($ad) { pierre@0: return theme('ad_html_ad', $ad); pierre@0: } pierre@0: pierre@0: /** pierre@0: * Return a themed ad of type ad_html. pierre@0: * pierre@0: * @param @ad pierre@0: * The ad object. pierre@0: * @return pierre@0: * A string containing the ad markup. pierre@0: */ pierre@0: function theme_ad_html_ad($ad) { pierre@0: if (isset($ad->aid)) { pierre@0: $output = '
'; pierre@0: $output .= check_markup($ad->html, $ad->format, FALSE); pierre@0: $output .= '
'; pierre@0: return $output; pierre@0: } pierre@0: } pierre@0: pierre@0: /** pierre@0: * Implementation of hook_theme(). pierre@0: */ pierre@0: function ad_html_theme() { pierre@0: return array( pierre@0: 'ad_html_ad' => array( pierre@0: 'file' => 'ad_html.module', pierre@0: 'arguments' => array( pierre@0: 'ad' => NULL, pierre@0: ), pierre@0: ), pierre@0: ); pierre@0: } pierre@0: pierre@0: /** pierre@0: * Implementation of hook_help(). pierre@0: */ pierre@0: function ad_html_help($path, $arg) { pierre@0: $output = ''; pierre@0: switch ($path) { pierre@0: case 'node/add/ad#html': pierre@0: $output = t('A html advertisement.'); pierre@0: break; pierre@0: } pierre@0: return $output; pierre@0: } pierre@0: pierre@0: /** pierre@0: * Implementation of hook_access(). pierre@0: */ pierre@0: function ad_html_access($op, $node, $account) { pierre@0: return ad_access($op, $node, $account); pierre@0: } pierre@0: pierre@0: /** pierre@0: * Implementation of the ad module's _adapi hook. pierre@0: */ pierre@0: function ad_html_adapi($op, &$node) { pierre@0: switch ($op) { pierre@0: case 'load': pierre@0: $return = db_fetch_array(db_query('SELECT html FROM {ad_html} WHERE aid = %d', $node['aid'])); pierre@0: $return['ad'] = check_markup($return['html'], $node['format'], FALSE); pierre@0: return $return; pierre@0: pierre@0: case 'insert': pierre@0: db_query("INSERT INTO {ad_html} (aid, html) VALUES(%d, '%s')", $node->nid, $node->html); pierre@0: break; pierre@0: pierre@0: case 'update': pierre@0: db_query("UPDATE {ad_html} SET html = '%s' WHERE aid = %d", $node->html, $node->nid); pierre@0: break; pierre@0: pierre@0: case 'delete': pierre@0: db_query('DELETE FROM {ad_html} WHERE aid = %d', $node->nid); pierre@0: break; pierre@0: pierre@0: case 'form': pierre@0: return ad_html_node_form($node); pierre@0: pierre@0: case 'view': pierre@0: return ad_html_node_view($node); pierre@0: pierre@0: case 'type': pierre@0: return array( pierre@0: 'html' => array( pierre@0: 'name' => t('HTML ad'), pierre@0: 'module' => 'ad_html', pierre@0: 'description' => t('A html advertisement.'), pierre@0: 'help' => t('A html advertisement.'), pierre@0: ), pierre@0: ); pierre@0: case 'permissions': pierre@0: if (!isset($node->adtype) || $node->adtype == 'html') { pierre@0: return array('manage ad html'); pierre@0: } pierre@0: } pierre@0: } pierre@0: pierre@0: /** pierre@0: * Adapi helper function for displaying a node form. pierre@0: */ pierre@0: function ad_html_node_form(&$node) { pierre@0: $form = array(); pierre@0: pierre@0: $form['ad_html'] = array( pierre@0: '#type' => 'fieldset', pierre@0: '#title' => t('HTML'), pierre@0: '#collapsible' => TRUE, pierre@0: ); pierre@0: pierre@0: $form['ad_html']['display'] = array( pierre@0: '#type' => 'markup', pierre@0: '#value' => ad_html_display_ad($node), pierre@0: ); pierre@0: pierre@0: if (ad_adaccess($node, 'manage ad html') || arg(1) == 'add' && user_access('create advertisements')) { pierre@0: $form['ad_html']['html'] = array( pierre@0: '#type' => 'textarea', pierre@0: '#title' => t('Ad HTML'), pierre@0: '#required' => TRUE, pierre@0: '#default_value' => isset($node->html) ? $node->html : '', pierre@0: '#description' => t('Paste the complete HTML provided by your advertising affiliate.'), pierre@0: ); pierre@0: } pierre@0: pierre@0: return $form; pierre@0: } pierre@0: pierre@0: /** pierre@0: * Helper function, display the html ad as a node. pierre@0: */ pierre@0: function ad_html_node_view(&$node) { pierre@0: $node->content['ad'] = array( pierre@0: '#value' => theme('box', '', stripslashes(ad_html_display_ad($node))), pierre@0: '#weight' => -1, pierre@0: ); pierre@0: } pierre@0: