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 add_filter('the_content', 'advman_filter_content'); // 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')); } }
function OX_Swifty($dalClass = null) { // Functions here are initialisation only - plugins have not been loaded (so we cannot initialise data) $this->counter = array(); $this->ad_networks = array(); $this->actions = array(); // Load all Swifty plugins OX_Tools::load_plugins(OX_LIB . '/Plugins', $this); // Load the data access layer $this->dal = is_null($dalClass) ? new OX_Dal() : new $dalClass(); }
static function init() { global $advman_engine, $advman_list; $advman_list = new Advman_Template_Table_List(); //Detect when a bulk action is being triggered... $action = OX_Tools::sanitize_request_var('action'); // Perform actions if ($action) { $ads = Advman_Tools::get_current_ads(); if ($ads) { if (count($ads) == 1) { // If there is a single ad selected, then perform the action on that ad. Notice messages and workflow are different in this case foreach ($ads as $ad) { Advman_Admin::ad_action($action, $ad); } } else { // These are bulk actions switch ($action) { case 'copy': foreach ($ads as $ad) { if ($ad) { $advman_engine->copyAd($ad->id); } } Advman_Admin::add_notice('advman-notice-once', __("Ads copied"), false); break; case 'delete': foreach ($ads as $ad) { if ($ad) { $advman_engine->deleteAd($ad->id); } } Advman_Admin::add_notice('advman-notice-once', __("Ads deleted"), false); break; } } } else { $ad = Advman_Tools::get_current_ad(); if ($ad) { Advman_Admin::ad_action($action, $ad); } } $url = remove_query_arg(array('action', 'ad', 'network', '_wpnonce')); wp_redirect($url); } }
static function sanitize($field, $type = null) { if (is_array($field)) { $a = array(); foreach ($field as $name => $value) { $n = OX_Tools::sanitize($name, 'key'); $v = OX_Tools::sanitize($value, $type); $a[$n] = $v; } return $a; } switch ($type) { case 'n': case 'number': case 'int': return preg_replace('#[^0-9\\.\\-]#i', '', $field); break; case 'format': return $field == 'custom' ? $field : preg_replace('#[^0-9x]#i', '', $field); break; case 'key': return preg_replace('#[^a-z0-9-_]#i', '', $field); default: return stripslashes(str_replace("", '', $field)); break; } }
function save_settings() { // Save settings to parent first! parent::save_settings(); //Override adformat saving already switch ($this->get_property('adtype')) { case 'slot': case 'ad': $this->set_property('adformat', OX_Tools::sanitize($_POST['advman-adformat'], 'format')); break; case 'link': $this->set_property('adformat', OX_Tools::sanitize($_POST['advman-linkformat'], 'format')); break; case 'ref_image': $this->set_property('adformat', OX_Tools::sanitize($_POST['advman-referralformat'], 'format')); break; default: $this->set_property('adformat', ''); } list($width, $height, $null) = split('[x]', $this->get_property('adformat')); $this->set_property('width', $width); $this->set_property('height', $height); }
/** * This function is called from the Wordpress Settings menu */ function settings() { // Get our options and see if we're handling a form submission. $action = OX_Tools::sanitize_post_var('advman-action'); if ($action == 'save') { global $advman_engine; $settings = array('openx-market', 'openx-market-cpm', 'openx-sync', 'enable-php', 'stats', 'purge-stats-days'); foreach ($settings as $setting) { $value = isset($_POST["advman-{$setting}"]) ? OX_Tools::sanitize($_POST["advman-{$setting}"]) : false; $advman_engine->setSetting($setting, $value); } } $template = Advman_Tools::get_template('Settings'); $template->display(); }
static function display_format($ad, $nw = false) { $properties = $ad->get_network_property_defaults(); if (isset($properties['adtype'])) { $adtype = $nw ? $ad->get_network_property('adtype') : $ad->get_property('adtype'); } else { $adtype = null; } $adformat = $nw ? $ad->get_network_property('adformat') : $ad->get_property('adformat'); $width = $nw ? $ad->get_network_property('width') : $ad->get_property('width'); $height = $nw ? $ad->get_network_property('height') : $ad->get_property('height'); $formats = Advman_Tools::organize_formats($ad->get_ad_formats()); ?> <table class="form-table" id="advman-settings-ad_format"> <?php if (!is_null($adtype)) { if (sizeof($formats['data']) == 1) { foreach ($formats['data'] as $t => $sectionFormat) { ?> ?><input type="hidden" name="advman-adtype" value="<?php echo $t; ?> "> <?php } } else { ?> <tr id="advman-form-adtype"> <td class="advman_label"><label for="advman-adtype"><?php _e('Ad Type:'); ?> </label></td> <td> <select name="advman-adtype" id="advman-adtype" onchange="advman_form_update(this);"> <option value=""> <?php _e('Use Default', 'advman'); ?> </option> <?php foreach ($formats['data'] as $t => $sectionFormat) { ?> <option<?php echo $adtype == $t ? ' selected="selected"' : ''; ?> value="<?php echo $t; ?> "> <?php echo $formats['types'][$t]; ?> </option> <?php } ?> </select> <img class="default_note" title="<?php echo __('[Default]', 'advman') . ' ' . $ad->get_network_property('adtype'); ?> "> </td> </tr> <?php } } foreach ($formats['data'] as $t => $sectionFormats) { ?> <tr id="advman-form-adformat-<?php echo $t; ?> "<?php echo $t == $adtype || is_null($adtype) ? '' : ' style="display:none"'; ?> > <td class="advman_label"><label for="advman-adformat"><?php _e('Format:', 'advman'); ?> </label></td> <td> <select name="advman-adformat<?php echo is_null($adtype) ? '' : '-' . $t; ?> " id="advman-adformat" onchange="advman_form_update(this);"> <?php if (!$nw) { ?> <optgroup id="advman-optgroup-default" label="<?php _e('Default', 'advman'); ?> "> <option value=""> <?php _e('Use Default', 'advman'); ?> </option> </optgroup> <?php } foreach ($sectionFormats as $section => $sformats) { ?> <optgroup id="advman-optgroup-<?php echo $section; ?> " label="<?php echo $formats['sections'][$section]; ?> "> <?php foreach ($sformats as $sformat) { list($w, $h, $l) = OX_Tools::explode_format($sformat); ?> <option<?php echo $adformat == $sformat ? ' selected="selected"' : ''; ?> value="<?php echo $sformat; ?> "> <?php printf($formats['formats'][$sformat], $w, $h, $l); ?> </option> <?php } ?> </optgroup> <?php } ?> </select> <img class="default_note" title="<?php echo __('[Default]', 'advman') . ' ' . $ad->get_network_property('adformat'); ?> "> </td> </tr> <?php } if (!empty($formats['sections']['custom'])) { ?> <tr id="advman-settings-custom"> <td class="advman_label"><label for="advman-width"><?php _e('Dimensions:'); ?> </label></td> <td> <input name="advman-width" size="5" title="<?php _e('Custom width for this unit.', 'advman'); ?> " value="<?php echo $width; ?> " /> x <input name="advman-height" size="5" title="<?php _e('Custom height for this unit.', 'advman'); ?> " value="<?php echo $height; ?> " /> px </td> </tr> <?php } ?> </table> <br /> <span style="font-size:x-small;color:gray;"><?php _e('Select one of the supported ad format sizes.', 'advman'); ?> <?php if (!empty($formats['sections']['custom'])) { _e('If your ad size is not one of the standard sizes, select Custom and fill in your size.', 'advman'); } ?> </span> <?php }
function display($target = null) { global $advman_engine; $action = isset($_POST['advman-action']) ? OX_Tools::sanitize($_POST['advman-action'], 'key') : ''; $oxMarket = $advman_engine->getSetting('openx-market'); if (is_null($oxMarket)) { $oxMarket = false; } $oxUpdates = $advman_engine->getSetting('openx-sync'); if (is_null($oxUpdates)) { $oxUpdates = false; } $oxCpm = $advman_engine->getSetting('openx-market-cpm'); if (is_null($oxCpm)) { $oxCpm = '0.20'; } $oxEnablePhp = $advman_engine->getSetting('enable-php'); if (is_null($oxEnablePhp)) { $oxEnablePhp = false; } $oxStats = $advman_engine->getSetting('stats'); if (is_null($oxStats)) { $oxStats = true; } $oxPurgeStatsDays = $advman_engine->getSetting('purge-stats-days'); if (is_null($oxPurgeStatsDays)) { $oxPurgeStatsDays = 30; } ?> <div class="wrap"> <div id="icon-options-general" class="icon32"><br /></div> <h2><?php _e('Ad Settings', 'advman'); ?> </h2> <?php if ($action == 'save') { ?> <div id="message" class="updated fade"><p><strong><?php _e('Settings saved.'); ?> </strong></p></div> <?php } ?> <form action="" method="post" id="advman-form" enctype="multipart/form-data"> <input type="hidden" name="advman-mode" id="advman-mode" value="settings" /> <input type="hidden" name="advman-action" id="advman-action" value="save" /> <input type="hidden" name="advman-target" id="advman-target" /> <table class="form-table"> <tbody> <tr valign="top"> <th scope="row"> <label for="advman-openx-market"><?php _e('Optimization', 'advman'); ?> </label> </th> <td> <fieldset> <legend class="hidden"><?php _e('Optimization', 'advman'); ?> </legend> <label for="advman-openx-market"><input name="advman-openx-market" type="checkbox" id="advman-openx-market" value="1"<?php echo $oxMarket ? ' checked="checked"' : ''; ?> /> <?php _e('Optimize ads on OpenX Market by default', 'advman'); ?> </label> </fieldset> <?php _e('Default floor price:', 'advman'); ?> <input type="text" name="advman-openx-market-cpm" value="<?php echo $oxCpm; ?> " class="small-text" /><br /> <span class="setting-description"><?php _e('By enabling the OpenX Market, an alternative ad may show if it will make you more money than the existing ad. The floor price is the eCPM (revenue per 1000 ads) that your ad network pays.', 'advman'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Updates', 'advman'); ?> </th> <td> <fieldset> <legend class="hidden"><?php _e('Updates', 'advman'); ?> </legend> <label for="advman-openx-sync"><input name="advman-openx-sync" type="checkbox" id="advman-openx-sync" value="1"<?php echo $oxUpdates ? ' checked="checked"' : ''; ?> /> <?php _e('Check for updates', 'advman'); ?> </label> </fieldset> <span class="setting-description"><?php _e('Checking for updates will keep you informed of not only updates, but of any offers from advertisers who want to buy your ad space.', 'advman'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"> <label for="advman-stats"><?php _e('Statistics', 'advman'); ?> </label> </th> <td> <fieldset> <legend class="hidden"><?php _e('Statistics', 'advman'); ?> </legend> <label for="advman-stats"><input name="advman-stats" type="checkbox" id="advman-stats" value="1"<?php echo $oxStats ? ' checked="checked"' : ''; ?> /> <?php _e('Collect statistics about the number of ads served', 'advman'); ?> </label> </fieldset> <?php _e('Purge after:', 'advman'); ?> <input type="text" name="advman-purge-stats-days" value="<?php echo $oxPurgeStatsDays; ?> " class="small-text" /> <?php _e('days', 'advman'); ?> <br /> <span class="setting-description"><?php _e('Collecting statistics about your ad serving will give you insight on how many ads have been viewed by your users. It is a good idea to purge these stats after 30 days so that your database does not get too full.', 'advman'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Other Settings', 'advman'); ?> </th> <td> <fieldset> <legend class="hidden"><?php _e('Other Settings', 'advman'); ?> </legend> <label for="advman-enable-php"><input name="advman-enable-php" type="checkbox" id="advman-enable-php" value="1"<?php echo $oxEnablePhp ? ' checked="checked"' : ''; ?> /> <?php _e('Allow PHP Code in Ads (BETA)', 'advman'); ?> </label> </fieldset> <span class="setting-description"><?php _e('Allowing PHP code in ads will execute any PHP code when delivering an ad. Be careful - only enable if you know what you are doing.', 'advman'); ?> </span> </td> </tr> </tbody> </table> <p class="submit"> <input type="submit" name="Submit" class="button-primary" value="<?php _e('Save Changes', 'advman'); ?> " /> </p> </form> </div> <?php }
static function admin_footer_text($default_text) { $addition = ''; $page = OX_Tools::sanitize_request_var('page'); if (stristr($page, 'advman-') !== false) { $addition = " | <span id='footer-thankyou'>" . __("Ads by <a href='http://wordpress.org/plugins/advertising-manager/'>Advertising Manager</a>", "advman") . " </span><span style='font-size:x-small;color:silver'>v" . ADVMAN_VERSION . "</span>"; } return $default_text . $addition; }
function insert_ad($ad) { $id = $this->data['settings']['next_ad_id']; $this->data['settings']['next_ad_id'] = $id + 1; $ad->id = $id; $this->data['ads'][$id] = $ad; OX_Tools::sort($this->data['ads']); $this->_update_data('settings'); $this->_update_data('ads'); return $ad; }
public function testGetIntMax() { $i = OX_Tools::get_int_max(); $this->assertEquals($i, 9.223372036854776E+18); }
function display($target = null) { global $advman_engine; $action = isset($_POST['advman-action']) ? OX_Tools::sanitize($_POST['advman-action'], 'key') : ''; $oxEnableAdjs = $advman_engine->getSetting('enable-adjs'); if (is_null($oxEnableAdjs)) { $oxEnableAdjs = false; } $oxEnablePhp = $advman_engine->getSetting('enable-php'); if (is_null($oxEnablePhp)) { $oxEnablePhp = false; } $oxStats = $advman_engine->getSetting('stats'); if (is_null($oxStats)) { $oxStats = true; } $oxPurgeStatsDays = $advman_engine->getSetting('purge-stats-days'); if (is_null($oxPurgeStatsDays)) { $oxPurgeStatsDays = 30; } ?> <div class="wrap"> <div id="icon-options-general" class="icon32"><br /></div> <h2><?php _e('Ad Settings', 'advman'); ?> </h2> <?php if ($action == 'save') { ?> <div id="message" class="updated fade"><p><strong><?php _e('Settings saved.'); ?> </strong></p></div> <?php } ?> <form action="" method="post" id="advman-form" enctype="multipart/form-data"> <input type="hidden" name="advman-action" id="advman-action" value="save" /> <table class="form-table"> <tbody> <tr valign="top"> <th scope="row"><?php _e('Ad Quality', 'advman'); ?> </th> <td> <span class="setting-description"><?php _e('Ad quality tools help small and medium sized publishers (like many Wordpress bloggers) learn more about their traffic quality, and get access to larger advertisers with bigger budgets. These tools are installed automatically.', 'advman'); ?> </span><br><br> <fieldset> <legend class="hidden"><?php _e('Ad Quality', 'advman'); ?> </legend> <label for="advman-enable-adjs"><input name="advman-enable-adjs" type="checkbox" id="advman-enable-adjs" value="1"<?php echo $oxEnableAdjs ? ' checked="checked"' : ''; ?> /> <?php _e('Allow ad quality measurement (Beta)', 'advman'); ?> </label> </fieldset><br> <span class="setting-description"><?php _e("By turning on ad quality measurement, your blog which will use javascript from Ad.js to measure the quality of your visitors, and report the results to you in the analytics screen. Installation is automatic.<br><br><strong>Please Note: The automatic installation will send your blog domain and admin email address to Ad.js to obtain a client ID.</strong>", 'advman'); ?> </span><br><br> </td> </tr> <tr valign="top"> <th scope="row"> <label for="advman-stats"><?php _e('Statistics', 'advman'); ?> </label> </th> <td> <fieldset> <legend class="hidden"><?php _e('Statistics', 'advman'); ?> </legend> <label for="advman-stats"><input name="advman-stats" type="checkbox" id="advman-stats" value="1"<?php echo $oxStats ? ' checked="checked"' : ''; ?> /> <?php _e('Collect statistics about the number of ads served', 'advman'); ?> </label> </fieldset> <?php _e('Purge after:', 'advman'); ?> <input type="text" name="advman-purge-stats-days" value="<?php echo $oxPurgeStatsDays; ?> " class="small-text" /> <?php _e('days', 'advman'); ?> <br /> <span class="setting-description"><?php _e('Collecting statistics about your ad serving will give you insight on how many ads have been viewed by your users. It is a good idea to purge these stats after maximum 100 days so that your database does not get too full.', 'advman'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Other Settings', 'advman'); ?> </th> <td> <fieldset> <legend class="hidden"><?php _e('Other Settings', 'advman'); ?> </legend> <label for="advman-enable-php"><input name="advman-enable-php" type="checkbox" id="advman-enable-php" value="1"<?php echo $oxEnablePhp ? ' checked="checked"' : ''; ?> /> <?php _e('Allow PHP Code in Ads', 'advman'); ?> </label> </fieldset> <span class="setting-description"><?php _e('Allowing PHP code in ads will execute any PHP code when delivering an ad. Be careful - only enable if you know what you are doing.', 'advman'); ?> </span> </td> </tr> </tbody> </table> <p class="submit"> <input type="submit" name="Submit" class="button-primary" value="<?php _e('Save Changes', 'advman'); ?> " /> </p> </form> </div> <?php }
static function get_current_ads() { global $advman_engine; $ads = false; $targets = OX_Tools::sanitize_request_var('ad'); if (is_array($targets)) { $ads = array(); foreach ($targets as $target) { $ads[$target] = $advman_engine->getAd($target); } } return $ads; }
function adsensem_upgrade_ad_settings(&$data) { $ads = array(); foreach ($data['ads'] as $id => $ad) { $ad['id'] = $id; if (!isset($ad['name'])) { $base = 'ad'; if (!empty($ad['class'])) { $class = $ad['class']; $tmp = new $class(); $base = $tmp->network_name; } $ad['name'] = OX_Tools::generate_name($base); } // add active if (!isset($ad['active'])) { $ad['active'] = true; } // remove title if (isset($ad['title'])) { unset($ad['title']); } // Make sure that any settings under 'color-url' are now under 'color-link' if (!empty($ad['color-url']) && empty($ad['color-link'])) { $ad['color-link'] = $ad['color-url']; } unset($ad['color-url']); // Set the OpenX Market if (!isset($ad['openx-market'])) { $ad['openx-market'] = false; } // Set the OpenX Market CPM if (!isset($ad['openx-market-cpm'])) { $ad['openx-market-cpm'] = '0.20'; } // Set the Weight if (!isset($ad['weight'])) { $ad['weight'] = '1'; } // Changed the 'hide link url' field to 'status' (for cj ads) if (isset($ad['hide-link-url'])) { $ad['status'] = $ad['hide-link-url']; unset($ad['hide-link-url']); } // Make sure width and height are correct if (empty($ad['width']) || empty($ad['height'])) { $format = $ad['adformat']; if (!empty($format) && $format != 'custom') { list($width, $height, $null) = split('[x]', $format); $ad['width'] = $width; $ad['height'] = $height; } } // Make sure that there is ad code if (empty($ad['code'])) { Advman_Upgrade::_get_code($ad); } // remove some variables... $aVars = array('codemethod', 'networkName', 'shortName', 'url'); foreach ($aVars as $var) { if (isset($ad[$var])) { unset($ad[$var]); } } $ads[$id] = $ad; } $data['ads'] = $ads; }