pierre@0: > Content management >> pierre@0: * Ads >> Settings >> Global settings >> Display type" to "Raw". pierre@0: * If you configure the "Display type" to IFrame, you will be serving IFrames pierre@0: * within IFrames. pierre@0: * pierre@0: * Copyright (c) 2005-2009. pierre@0: * Jeremy Andrews . pierre@0: */ pierre@0: pierre@0: /** pierre@0: * Function used to display the selected ad. pierre@0: */ pierre@0: function ad_external_display_ad($ad) { pierre@0: return theme('ad_external_ad', $ad); pierre@0: } pierre@0: pierre@0: /** pierre@0: * Return a themed ad of type ad_remote. 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_external_ad($ad) { pierre@0: global $base_url; pierre@0: pierre@0: if (isset($ad->aid)) { pierre@0: $output = '
'; pierre@0: // For now, we hard code this to only support caching with the file cache. pierre@0: // As more cache types are introduced, we'll expand this. Ideally it should pierre@0: // be cache type agnostic, but that seems to be unrealistic. pierre@0: if (variable_get('ad_cache', 'none') == 'file') { pierre@0: $adserve = variable_get('adserve', ''); pierre@0: $display_variables = '&c=file'. module_invoke('ad_cache_file', 'adcacheapi', 'display_variables', array()); pierre@0: $external = url("$base_url/$adserve?o=external&n=$ad->aid&$display_variables"); pierre@0: } pierre@0: else { pierre@0: $external = db_result(db_query('SELECT url FROM {ad_external} WHERE aid = %d', $ad->aid)); pierre@0: } pierre@0: $append = 'frameborder="'. variable_get('ad_iframe_frameborder', 0) .'" '; pierre@0: $append .= 'scrolling="'. variable_get('ad_iframe_scroll', 'auto') .'" '; pierre@0: if ($height = variable_get('ad_iframe_height', '')) { pierre@0: $append .= "height=\"$height\" "; pierre@0: } pierre@0: if ($width = variable_get('ad_iframe_width', '')) { pierre@0: $append .= "width=\"$width\" "; pierre@0: } pierre@0: $output .= ""; 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_external_theme() { pierre@0: return array( pierre@0: 'ad_external_ad' => array( pierre@0: 'file' => 'ad_external.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_external_help($path, $arg) { pierre@0: $output = ''; pierre@0: switch ($path) { pierre@0: case 'node/add/ad#external': pierre@0: $output = t('An external advertisement, displayed in an IFrame.'); 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_external_access($op, $node, $account) { pierre@0: return ad_access($op, $node, $account); pierre@0: } pierre@0: pierre@0: /** pierre@0: * Implementation of hook_adapi(). pierre@0: */ pierre@0: function ad_external_adapi($op, &$node) { pierre@0: switch ($op) { pierre@0: case 'load': pierre@0: return db_fetch_array(db_query('SELECT * FROM {ad_external} WHERE aid = %d', $node['aid'])); pierre@0: pierre@0: case 'insert': pierre@0: db_query("INSERT INTO {ad_external} (aid, url) VALUES(%d, '%s')", $node->nid, $node->url); pierre@0: break; pierre@0: pierre@0: case 'update': pierre@0: db_query("UPDATE {ad_external} SET url = '%s' WHERE aid = %d", $node->url, $node->nid); pierre@0: break; pierre@0: pierre@0: case 'delete': pierre@0: db_query('DELETE FROM {ad_external} WHERE aid = %d', $node->nid); pierre@0: break; pierre@0: pierre@0: case 'form': pierre@0: return ad_external_node_form($node); pierre@0: pierre@0: case 'view': pierre@0: return ad_external_node_view($node); pierre@0: pierre@0: case 'redirect': pierre@0: // TODO: Would it ever make sense to have redirects for this ad type? pierre@0: watchdog('ad', 'Unexpected redirect attempt in external ad type.'); pierre@0: return; pierre@0: pierre@0: case 'type': pierre@0: return array( pierre@0: 'external' => array( pierre@0: 'name' => t('External ad'), pierre@0: 'module' => 'ad_external', pierre@0: 'description' => t('An external advertisement, displayed in an IFrame.'), pierre@0: 'help' => t('An external advertisement, displayed in an IFrame.'), pierre@0: ), 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_external_node_form(&$node) { pierre@0: $form = array(); pierre@0: pierre@0: $form['ad_external'] = array( pierre@0: '#type' => 'fieldset', pierre@0: '#title' => t('External'), pierre@0: '#collapsible' => TRUE, pierre@0: ); pierre@0: pierre@0: $form['ad_external']['preview'] = array( pierre@0: '#type' => 'markup', pierre@0: '#value' => ad_external_display_ad($node), pierre@0: ); pierre@0: pierre@0: if ((arg(1) == 'add' || arg(2) == 'edit') && pierre@0: user_access('create advertisements')) { pierre@0: $form['ad_external']['url'] = array( pierre@0: '#type' => 'textfield', pierre@0: '#title' => t('External Source URL'), pierre@0: '#required' => TRUE, pierre@0: '#default_value' => isset($node->url) ? $node->url : '', pierre@0: '#description' => t('Enter the complete URL where your external ad his hosted. The URL must begin with http:// or https://. For example, %url.', array('%url' => t('http://www.sample.org/external/ad.php'))), pierre@0: ); pierre@0: pierre@0: } pierre@0: pierre@0: return $form; pierre@0: } pierre@0: pierre@0: /** pierre@0: * Adapi helper function for displaying ad itself. pierre@0: */ pierre@0: function ad_external_node_view(&$node) { pierre@0: $node->content['ad'] = array( pierre@0: '#value' => theme('box', '', stripslashes(ad_external_display_ad($node))), pierre@0: '#weight' => -1, pierre@0: ); pierre@0: $link = t('Links to !url.', array('!url' => $node->url)); pierre@0: if (variable_get('ad_filter', 0)) { pierre@0: $link = check_markup($link, $node->format, FALSE); pierre@0: } pierre@0: $node->content['ad-link'] = array( pierre@0: '#value' => "