getSetting('enable-adjs')) { wp_enqueue_script('adjs', '//cdn.adjs.net/publisher.ad.min.js'); } } function advman_run() { global $advman_engine; // An ad is being requested by its name if (!empty($_REQUEST['advman-ad-name'])) { $name = OX_Tools::sanitize($_REQUEST['advman-ad-name'], 'key'); $ad = $advman_engine->selectAd($name); if (!empty($ad)) { echo $ad->display(); $advman_engine->incrementStats($ad); } die(0); } // An ad is being requested by its id if (!empty($_REQUEST['advman-ad-id'])) { $id = OX_Tools::sanitize($_REQUEST['advman-ad-id'], 'number'); $ad = $advman_engine->getAd($id); if (!empty($ad)) { echo $ad->display(); $advman_engine->incrementStats($ad); } die(0); } // Add a filter for displaying an ad in the content // DEPRECATED - will be using shortcodes going forward add_filter('the_content', 'advman_filter_content'); add_shortcode('ad', 'advman_shortcode'); // Add an action when the wordpress footer displays add_action('wp_footer', 'advman_footer'); // If admin, initialise the Admin functionality if (is_admin()) { add_action('admin_menu', array('Advman_Admin','init')); } } /* This filter parses post content and replaces markup with the correct ad, for named ad or for default */ function advman_filter_content($content) { $patterns = array( '//', '//', '//', '//', '/\[ad#(.*?)\]/', ); return preg_replace_callback($patterns, 'advman_filter_content_callback', html_entity_decode($content)); } // Ad Shortcode function advman_shortcode( $atts ) { global $advman_engine; $name = !empty($atts['name']) ? $atts['name'] : null; $ad = $advman_engine->selectAd($name); if (!empty($ad)) { $adHtml = $ad->display(); $advman_engine->incrementStats($ad); return $adHtml; } return ''; } function advman_filter_content_callback($matches) { } // Backwards compatibility with adsense-manager if (!function_exists('adsensem_ad')) { function adsensem_ad($name = false) { return advman_ad($name); } } function advman_ad($name = false) { global $advman_engine; $ad = $advman_engine->selectAd($name); if (!empty($ad)) { echo $ad->display(); $advman_engine->incrementStats($ad); } } /** * Called when the Wordpress footer displays, and adds a comment in the HTML for debugging purposes */ function advman_footer() { ?>