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'));
    }
}
Exemple #2
0
 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;
     }
 }
Exemple #3
0
 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);
 }
Exemple #4
0
 /**
  * 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();
 }
Exemple #5
0
    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>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?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>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?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 
    }
Exemple #6
0
 /**
  * This function is called from the Wordpress Settings menu
  */
 static function settings()
 {
     global $advman_engine;
     // 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;
         // We need to know if we are changing the adjs settings
         $adjs_pre = $advman_engine->getSetting('enable-adjs');
         $settings = array('enable-php', 'stats', 'purge-stats-days', 'enable-adjs');
         foreach ($settings as $setting) {
             $value = isset($_POST["advman-{$setting}"]) ? OX_Tools::sanitize($_POST["advman-{$setting}"]) : false;
             $advman_engine->setSetting($setting, $value);
         }
         $adjs_post = $advman_engine->getSetting('enable-adjs');
         // If a user is turning on adjs
         // This generates a client ID given the admin email address and the domain.  Note:  user has given consent in settings if we have made it this far.
         if (!$adjs_pre && $adjs_post) {
             $url = 'http://adjs.io/beta_signups';
             $params = array('headers' => array("Accept" => 'application/json'), 'body' => array('beta_signup' => array("email" => get_option('admin_email'), "url" => get_option('siteurl'))));
             //                print_r($params);
             //                exit;
             $response = wp_remote_post($url, $params);
             if (is_array($response) && $response['body']) {
                 $clientId = json_decode($response['body'])->client_id;
                 $advman_engine->setSetting('adjs-clientid', $clientId);
             } else {
                 // Fail silently!
                 //                    print_r($response);
                 //                    exit;
             }
         }
         // If a user is turning off adjs
         // This generates a client ID given the admin email address and the domain.  Note:  user has given consent in settings if we have made it this far.
         if ($adjs_pre && !$adjs_post) {
             $clientId = $advman_engine->getSetting('adjs-clientid');
             if ($clientId) {
                 $url = "http://adjs.io/beta_signups/{$clientId}";
                 $params = array('method' => 'DELETE', 'headers' => array("Accept" => 'application/json'));
                 $response = wp_remote_request($url, $params);
                 if ($response['response'] && $response['response']['code'] == 204) {
                     $advman_engine->setSetting('adjs-clientid', '');
                 }
             }
         }
     }
     $template = Advman_Tools::get_template('Settings');
     $template->display();
 }
Exemple #7
0
    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>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?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 
    }
Exemple #8
0
 static function get_search_query()
 {
     $q = false;
     if (isset($_GET['s'])) {
         $q = OX_Tools::sanitize($_GET['s']);
     }
     return $q;
 }