/** * init ad object * * @param int $id id of the ad (= post id) * @param arr $args additional arguments */ public function __construct($id, $args = array()) { $id = absint($id); $this->id = $id; $this->args = is_array($args) ? $args : array(); if (!empty($id)) { $this->load($id); } // dynamically add sanitize filters for condition types $_types = array(); // -TODO use model $advanced_ads_ad_conditions = Advanced_Ads::get_ad_conditions(); foreach ($advanced_ads_ad_conditions as $_condition) { // add unique $_types[$_condition['type']] = false; } // iterate types foreach (array_keys($_types) as $_type) { // -TODO might be faster to use __call() method or isset()-test class method array $method_name = 'sanitize_condition_' . $_type; if (method_exists($this, $method_name)) { add_filter('advanced-ads-sanitize-condition-' . $_type, array($this, $method_name), 10, 1); } elseif (function_exists('advads_sanitize_condition_' . $_type)) { // check for public function to sanitize this add_filter('advanced-ads-sanitize-condition-' . $_type, 'advads_sanitize_condition_' . $_type, 10, 1); } } }
<li><?php _e('If you want to display the ad everywhere, don\'t do anything here. ', 'advanced-ads'); ?> </li> <li><?php _e('The fewer conditions you enter, the better the performance will be.', 'advanced-ads'); ?> </li> <li><?php printf(__('Learn more about display conditions from the <a href="%s" target="_blank">manual</a>.', 'advanced-ads'), ADVADS_URL . 'manual/display-conditions/#utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-display'); ?> </li> </ul> <?php // -TODO use model $advanced_ads_ad_conditions = Advanced_Ads::get_ad_conditions(); if (is_array($advanced_ads_ad_conditions)) { foreach ($advanced_ads_ad_conditions as $_key => $_condition) { if (!isset($_condition['callback'])) { continue; } ?> <div class="advanced-ad-display-condition"> <?php if (is_array($_condition['callback']) && method_exists($_condition['callback'][0], $_condition['callback'][1])) { call_user_func(array($_condition['callback'][0], $_condition['callback'][1]), $ad); // works also in php below 5.3 // $_condition['callback'][0]::$_condition['callback'][1]($ad); // works only in php 5.3 and above } ?> </div><?php