'; } } ////////////////////////////////////////////////////////////////////////////// if (!function_exists('adshow_functions_exist')){ // Used to downgrade fatal errors to printed errors to make debugging easier // and so that a problem doesn't disable the whole website. // TODO can't just add new checks to here as Ad Injection might now get run before config // file is regenerated - e.g. if cached versions of pages are served function adshow_functions_exist(){ if (!defined('ADINJ_NO_CONFIG_FILE')){ if (!adshow_functions_exist_impl('adinj_config_allow_referrers')){ return false; } if (!adshow_functions_exist_impl('adinj_config_allowed_referrers_list')){ return false; } if (!adshow_functions_exist_impl('adinj_config_block_ips')){ return false; } if (!adshow_functions_exist_impl('adinj_config_blocked_ips_list')){ return false; } if (!adshow_functions_exist_impl('adinj_config_block_referrers')){ return false; } if (!adshow_functions_exist_impl('adinj_config_blocked_referrers_list')){ return false; } //if (!adshow_functions_exist_impl('adinj_config_block_hours')){ return false; } //if (!adshow_functions_exist_impl('adinj_config_block_after_ad_click')){ return false; } if (!adshow_functions_exist_impl('adinj_config_debug_mode')){ return false; } } return true; } function adshow_functions_exist_impl($function){ if (!function_exists($function)){ echo ""; return false; } return true; } } if (defined('ADINJ_NO_CONFIG_FILE')){ function adinj_config_allow_referrers() { return adinj_ticked('sevisitors_only'); } function adinj_config_allowed_referrers_list() { $list = adinj_quote_list('ad_referrers'); return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY); } function adinj_config_block_ips() { return adinj_ticked('block_ips'); } function adinj_config_blocked_ips_list() { $list = adinj_quote_list('blocked_ips'); return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY); } function adinj_config_block_referrers() { return adinj_ticked('block_keywords'); } function adinj_config_blocked_referrers_list() { $list = adinj_quote_list('blocked_keywords'); return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY); } function adinj_config_block_hours() { // if blocked by referrer $ops = adinj_options(); return $ops['block_ads_for_hours']; } function adinj_config_block_after_ad_click() { return false; //return adinj_ticked('block_after_ad_click'); //TODO maybe this should be checking something else } function adinj_config_debug_mode() { return adinj_ticked('debug_mode'); } } ////////////////////////////////////////////////////////////////////////////// if (!function_exists('adshow_display_ad_file_v2')){ function adshow_display_ad_file_v2($adfiles, $adfiles_frequency = array(), $options = array(), $altfiles = array(), $altfiles_frequency = array()){ if (!adshow_functions_exist()){ return false; } if (adinj_config_debug_mode()){ echo "\n"; } if (empty($adfiles) && empty($altfiles)){ echo "\n"; return false; } $adfile = ""; $showads = adshow_show_adverts(); if ($showads !== true){ if (adinj_config_debug_mode()){ echo "\n"; } $alt_content_file = adshow_pick_value($altfiles, $altfiles_frequency); if (!empty($alt_content_file)){ if (adinj_config_debug_mode()){ echo "\n"; } $adfile = $alt_content_file; } else { if (adinj_config_debug_mode()){ echo "\n"; } return false; } } if (empty($adfile)){ $adfile = adshow_pick_value($adfiles, $adfiles_frequency); } if (adinj_config_debug_mode()){ echo "\n"; } $plugin_dir = dirname(__FILE__); $ad_path = dirname($plugin_dir).'/ad-injection-data/'.$adfile; if (file_exists($ad_path)){ adshow_display_ad_full_path_v2($ad_path, $options); return; } echo " "; } } if (!function_exists('adshow_pick_value')){ function adshow_pick_value($values, $frequency){ if (empty($values)){ return ""; } if (!is_array($values)){ // single value passed in return $values; } $val = ""; // values is an array if (empty($frequency)){ // each value has an equal chance of being picked $val = array_rand(array_flip($values)); } else { // each value has its own probability of being picked $count = sizeof($values); if ($count != sizeof($frequency)){ echo "\n"; return ""; } $total = array_sum($frequency); $rand = rand(0, $total); $cumulative = 0; for ($i=0; $i<$count; ++$i){ $cumulative += $frequency[$i]; if ($rand <= $cumulative){ $val = $values[$i]; if (adinj_config_debug_mode()){ echo "\n"; } break; } } } return $val; } } if (!function_exists('adshow_display_ad_full_path_v2')){ function adshow_display_ad_full_path_v2($ad_path, $ops = array()){ if (!adshow_functions_exist()){ return false; } if (!file_exists($ad_path)){ echo "\n"; return false; } $ad = file_get_contents($ad_path); if ($ad === false) echo "\n"; $ad = adshow_eval_php($ad); echo adshow_add_formatting($ad, $ops); } } if (!function_exists('adshow_add_formatting')){ function adshow_add_formatting($ad, $ops = array()){ if (strlen($ops['align']) > 0 || strlen($ops['clear']) > 0 || strlen($ops['margin_top']) > 0 || strlen($ops['margin_bottom']) > 0 || strlen($ops['padding_top']) > 0 || strlen($ops['padding_bottom']) > 0) { $clear = ""; $mtop = ""; $mbottom = ""; $ptop = ""; $pbottom = ""; if (strlen($ops['clear']) > 0) $clear="clear:" . $ops['clear'] . ";"; if (strlen($ops['margin_top']) > 0) $mtop="margin-top:" . $ops['margin_top'] . "px;"; if (strlen($ops['margin_bottom']) > 0) $mbottom="margin-bottom:" . $ops['margin_bottom'] . "px;"; if (strlen($ops['padding_top']) > 0) $ptop="padding-top:" . $ops['padding_top'] . "px;"; if (strlen($ops['padding_bottom']) > 0) $pbottom="padding-bottom:" . $ops['padding_bottom'] . "px;"; $cssrules = $clear . $mtop . $mbottom . $ptop . $pbottom; if ($ops['align'] == 'rand lcr') $ops['align'] = array_rand(array_flip(array('left', 'center', 'right'))); if ($ops['align'] == 'rand float lr') $ops['align'] = array_rand(array_flip(array('float left', 'float right'))); if ($ops['align'] == 'rand all') $ops['align'] = array_rand(array_flip(array('left', 'center', 'right', 'float left', 'float right'))); if ($ops['align'] == 'left'){ $ad = "\n