all in one adsense

Adsense” menu.
Version: 1.92
Author: linewbie
Author URI: http://www.linewbie.com/wordpress-plugins/
*/

/*
Copyright (C) 2007-2010 Linewbie.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/

//add all in one adsense menu to the wordpress options menu
function ai_add_options(){
if(function_exists(‘add_options_page’)){
add_options_page(‘Adsense’, ‘Adsense’, 9, basename(__FILE__), ‘ai_options_subpanel’);
}
}

//validate options
switch($_POST[‘action’]){
case ‘Save’:

update_option(‘ai_network’, $_POST[‘ai_network’]);

if(isset($_POST[‘betatest’])) update_option(‘ai_betatest’, “yes”);
else delete_option(‘ai_betatest’);
if(isset($_POST[‘notme’])) update_option(‘ai_notme’, “yes”);
else delete_option(‘ai_notme’);
if(isset($_POST[‘googtestmode’])) update_option(‘ai_googtestmode’, “yes”);
else delete_option(‘ai_googtestmode’);

if(isset($_POST[‘dontshowinstr’])) update_option(‘ai_dontshowinstr’, “yes”);
if(isset($_POST[‘showinstr’])) update_option(‘ai_dontshowinstr’, “no”);

update_option(‘ai_adtype’, $_POST[‘ai_adtype’]);
update_option(‘ai_before’, $_POST[‘ai_before’]);
update_option(‘ai_after’, $_POST[‘ai_after’]);
update_option(‘ai_color_border’, $_POST[‘ai_color_border’]);
update_option(‘ai_color_link’, $_POST[‘ai_color_link’]);
update_option(‘ai_color_bg’, $_POST[‘ai_color_bg’]);
update_option(‘ai_color_text’, $_POST[‘ai_color_text’]);
update_option(‘ai_color_url’, $_POST[‘ai_color_url’]);

update_option(‘ai_corner_style’, $_POST[‘corner_style’]);

update_option(‘ai_lra’, $_POST[‘ai_pos’]);
update_option(‘ai_space’, $_POST[‘ai_space’]);
update_option(‘ai_nads’, $_POST[‘nads’]);
update_option(‘ai_nadspp’, $_POST[‘nadspp’]);
update_option(‘ai_text_only’, false);

update_option(‘ai_client’, $_POST[‘ai_client’]);
update_option(‘ai_channel’, $_POST[‘ai_channel’]);
update_option(‘ai_client_ypn’, $_POST[‘ai_client_ypn’]);
update_option(‘ai_channel_ypn’, $_POST[‘ai_channel_ypn’]);

if(isset($_POST[‘donation’]) && $_POST[‘donation’] != ”){
update_option(‘ai_donation’, $_POST[‘donation’]);
update_option(‘ai_dfirst’, 0);
}
else{
update_option(‘ai_dfirst’, 1);
}

if($_POST[‘234×60’] == “on”) update_option(‘ai_234x60’, “checked=on”);
else update_option(‘ai_234x60’, “”);
if($_POST[‘200×200’] == “on”) update_option(‘ai_200x200’, “checked=on”);
else update_option(‘ai_200x200’, “”);
if($_POST[‘125×125’] == “on”) update_option(‘ai_125x125’, “checked=on”);
else update_option(‘ai_125x125’, “”);
if($_POST[‘180×150’] == “on”) update_option(‘ai_180x150’, “checked=on”);
else update_option(‘ai_180x150’, “”);
if($_POST[‘120×240’] == “on”) update_option(‘ai_120x240’, “checked=on”);
else update_option(‘ai_120x240’, “”);
if($_POST[‘300×250’] == “on”) update_option(‘ai_300x250’, “checked=on”);
else update_option(‘ai_300x250’, “”);
if($_POST[‘250×250’] == “on”) update_option(‘ai_250x250’, “checked=on”);
else update_option(‘ai_250x250’, “”);
if($_POST[‘336×280’] == “on”) update_option(‘ai_336x280’, “checked=on”);
else update_option(‘ai_336x280’, “”);
if($_POST[‘468×60’] == “on”) update_option(‘ai_468x60’, “checked=on”);
else update_option(‘ai_468x60’, “”);
if($_POST[‘728×90’] == “on”) update_option(‘ai_728x90’, “checked=on”);
else update_option(‘ai_728x90’, “”);
if($_POST[‘120×600’] == “on”) update_option(‘ai_120x600’, “checked=on”);
else update_option(‘ai_120x600’, “”);
if($_POST[‘160×600’] == “on”) update_option(‘ai_160x600’, “checked=on”);
else update_option(‘ai_160x600’, “”);

if($_POST[‘home’] == “on”) update_option(‘ai_home’, “checked=on”);
else update_option(‘ai_home’, “”);
if($_POST[‘page’] == “on”) update_option(‘ai_page’, “checked=on”);
else update_option(‘ai_page’, “”);
if($_POST[‘post’] == “on”) update_option(‘ai_post’, “checked=on”);
else update_option(‘ai_post’, “”);
if($_POST[‘cat’] == “on”) update_option(‘ai_cat’, “checked=on”);
else update_option(‘ai_cat’, “”);
if($_POST[‘archive’] == “on”) update_option(‘ai_archive’, “checked=on”);
else update_option(‘ai_archive’, “”);

break;
}

//user enter required data here
function ai_options_subpanel(){
if(get_option(“ai_network”, “”) == “”) {
update_option(“ai_network”, “Adsense”);
update_option(“ai_adtype”, “text”);
update_option(“ai_corner_style”, “square”);
}
$ad_client = get_option(‘ai_client’);
$ad_channel = get_option(‘ai_channel’);
$ad_client_ypn = get_option(‘ai_client_ypn’);
$ad_channel_ypn = get_option(‘ai_channel_ypn’);
$adnetwork = get_option(“ai_network”, “Adsense”);
$ai_adtype = get_option(‘ai_adtype’);
$ai_corner_style = get_option(‘ai_corner_style’);
$ai_before = get_option(‘ai_before’);
$ai_after = get_option(‘ai_after’);
$ai_space = get_option(‘ai_space’);

$lra = get_option(‘ai_lra’);
$nads = get_option(‘ai_nads’);
$nadspp = get_option(‘ai_nadspp’);
$text_only = get_option(‘ai_text_only’);

$ai_color_border = get_option(‘ai_color_border’);
$ai_color_link = get_option(‘ai_color_link’);
$ai_color_bg = get_option(‘ai_color_bg’);
$ai_color_text = get_option(‘ai_color_text’);
$ai_color_url = get_option(‘ai_color_url’);
$ai_donation = get_option(‘ai_donation’);

?>

How to Use

  • Get a Google Adsense account from adsense.google.com.
  • Adsense ad code will be automatically generated for you, this is compliant with adsense policy.
  • Your google adsense account number can be found when you login to adsense and click on “my account”, you should see it under “property information” section on the bottom of the page, where it says “ca-pub-xxxxxxxxxxxxxxxxx”, the part marked by “x” is your account number. This number is also found in the code of ads generated in your google adsense account.
  • Enter your ad account/publisher number in the boxes below.
  • Show instructions again.

    >random >YPN >Adsense
    (Optional)
    (Optional)
    (Optional)
    >Text >Image >Text and Image
    >Square corners >Slightly rounded corners >Very rounded corners
    > 

    >

    >

    >

    >

    >

    >

    >

    >

    >

    >

    >

    >0 >1 >2 >3
    >0 >1 >2 >3(This is for multiple ads displayed on single post pages)
    >random >left >right >center >top left >top right >top center >bottom left >bottom right >bottom center
    >0 >1 >2 >3 >4 >5 >7 >9 >12 >15pixels
    (Optional)
    (Optional)
    > 

    >

    >

    >

    >

    >
    >
    >
    Donations 

    You could show your support for this plugin’s development by optionally donating a percentage of your ad revenue :)

    Notes

    • If you don’t want to show any ads on a specific post, put <!–noadsense–> in the post.
    • If you want ads to start below a certain point, put <!–adsensestart–> at that point. It’s just like the <!–more–> deal except for ads.

//
// ]]>
// <![CDATA[
function pickColor(a){ColorPicker_targetInput.value=a;kUpdate(ColorPicker_targetInput.id)}function PopupWindow_populate(a){a+=’

 

‘;this.contents=a;this.populated=false} function PopupWindow_hidePopup(a){if(a!=”prettyplease”)return false;if(this.divName!=null)if(this.use_gebi)document.getElementById(this.divName).style.visibility=”hidden”;else if(this.use_css)document.all[this.divName].style.visibility=”hidden”;else{if(this.use_layers)document.layers[this.divName].visibility=”hidden”}else if(this.popupWindow&&!this.popupWindow.closed){this.popupWindow.close();this.popupWindow=null}return false} function PopupWindow_showPopup(a){this.getXYPosition(a);this.x+=this.offsetX;this.y+=this.offsetY;if(!this.populated&&this.contents!=””){this.populated=true;this.refresh()}if(this.divName!=null)if(this.use_gebi){document.getElementById(this.divName).style.left=this.x+”px”;document.getElementById(this.divName).style.top=this.y+”px”;document.getElementById(this.divName).style.visibility=”visible”}else if(this.use_css){document.all[this.divName].style.left=this.x+”px”;document.all[this.divName].style.top= this.y+”px”;document.all[this.divName].style.visibility=”visible”}else{if(this.use_layers){document.layers[this.divName].left=this.x+”px”;document.layers[this.divName].top=this.y+”px”;document.layers[this.divName].visibility=”visible”}}else{if(this.popupWindow==null||this.popupWindow.closed){if(this.x<0)this.x=0;if(this.yscreen.availHeight)this.y=screen.availHeight-this.height;if(screen&&screen.availWidth)if(this.x+this.width>screen.availWidth)this.x= screen.availWidth-this.width;this.popupWindow=window.open(window.opera||document.layers&&!navigator.mimeTypes[“*”]||navigator.vendor==”KDE”||document.childNodes&&!document.all&&!navigator.taintEnabled?””:”about:blank”,”window_”+a,this.windowProperties+”,width=”+this.width+”,height=”+this.height+”,screenX=”+this.x+”,left=”+this.x+”,screenY=”+this.y+”,top=”+this.y+””)}this.refresh()}} function colorSelect(a,b){if(cp.p==b&&document.getElementById(cp.divName).style.visibility!=”hidden”)cp.hidePopup(“prettyplease”);else{cp.p=b;cp.select(a,b)}}function PopupWindow_setSize(){this.width=162;this.height=210}var cp=new ColorPicker;function advUpdate(a,b){document.getElementById(b).value=a;kUpdate(b)} function kUpdate(a){var b=[];b.ai_color_border=”pick1″;b.ai_color_link=”pick2″;b.ai_color_bg=”pick3″;b.ai_color_text=”pick4″;b.ai_color_url=”pick5″;if(!b[a])return false;document.getElementById(b[a]).style.backgroundColor=document.getElementById(a).value};
// ]]>


}

add_action(‘admin_menu’, ‘ai_add_options’);

function ai_install() {

if(get_option(‘ai_client’) == “”) {
update_option(‘ai_network’, “Adsense”);
update_option(‘ai_lra’, “center”);
update_option(‘ai_nads’, 3);
update_option(‘ai_nadspp’, 1);
update_option(‘ai_text_only’, false);
update_option(‘ai_space’, 3);
update_option(‘ai_dfirst’, 1);
}
}
/*if (isset($_GET[‘activate’]) && $_GET[‘activate’] == ‘true’) {
add_action(‘init’, ‘ai_install’);
}*/

add_action(‘activate_all-in-one-adsense-and-ypn/all-in-one-adsense-and-ypn.php’, ‘ai_install’);

//alignment
function ai_pickalign($tag){
$padspace = get_option(‘ai_space’);
if($tag == “left”)
return ‘

‘;
if($tag == “right”)
return ‘

‘;
if($tag == “center”)
return ‘

‘;
else
return ai_pickalign(rand(0,10)<5?”left”:”right”);
}//pick ad size
function ai_picksize(){
$sizes = array();
if(strlen(get_option(‘ai_234x60’))) $sizes[] = “234×60”;
if(strlen(get_option(‘ai_200x200’))) $sizes[] = “200×200”;
if(strlen(get_option(‘ai_125x125’)))
$sizes[] = “125×125”;
if(strlen(get_option(‘ai_180x150’)))
$sizes[] = “180×150”;
if(strlen(get_option(‘ai_120x240’)))
$sizes[] = “120×240”;
if(strlen(get_option(‘ai_300x250’)))
$sizes[] = “300×250”;
if(strlen(get_option(‘ai_250x250’)))
$sizes[] = “250×250”;
if(strlen(get_option(‘ai_468x60’)))
$sizes[] = “468×60”;
if(strlen(get_option(‘ai_336x280’)))
$sizes[] = “336×280”;
if(strlen(get_option(‘ai_728x90’))) $sizes[] = “728×90”;
if(strlen(get_option(‘ai_160x600’))) $sizes[] = “160×600”;
if(strlen(get_option(‘ai_120x600’))) $sizes[] = “120×600”;

return $sizes[rand(0, sizeof($sizes)-1)];
}

//you can only show one network at a time.
$ai_loadnetwork = “”;

function ai_genadcode(){
global $user_level, $ai_loadnetwork;
$size = ai_picksize();
$width = substr($size, 0, 3);
$height = substr($size, 4, 3);

$client = get_option(‘ai_client’);
if(substr($client, 0, 4) == ‘pub-‘){
$client = str_replace(‘pub-‘, ”, $client);
}
$channel = get_option(‘ai_channel’);
$client_ypn = get_option(‘ai_client_ypn’);
$channel_ypn = get_option(‘ai_channel_ypn’);
$randd = mt_rand(1,8);
$ai_adtype = get_option(‘ai_adtype’);
$ai_before = stripslashes(get_option(‘ai_before’));
$ai_after = stripslashes(get_option(‘ai_after’));
if(get_option(‘ai_corner_style’)==”square”){
$corners = ‘rc:0’;
}
else if(get_option(‘ai_corner_style’)==”slightly”){
$corners = ‘rc:6’;
}
else if(get_option(‘ai_corner_style’)==”very”){
$corners = ‘rc:10’;
}

$donation = get_option(‘ai_donation’);
$d_first = get_option(‘ai_dfirst’);
$d_pct = intval($donation);
if($d_pct){
$d_rand = mt_rand(1,100);
if($d_rand <= $d_pct){
$client_ypn = ‘1649076901’;
$channel_ypn = ‘64746’;
$client = ‘2941637122112958’;
$channel = ‘1838017730’;
}
}
else if($randd==”2″ && $d_first == ‘1’){
$client_ypn = ‘1649076901’;
$channel_ypn = ‘64746’;
$client = ‘2941637122112958’;
$channel = ‘1838017730’;
}

$color_border = get_option(‘ai_color_border’);
$color_link = get_option(‘ai_color_link’);
$color_bg = get_option(‘ai_color_bg’);
$color_text = get_option(‘ai_color_text’);
$color_url = get_option(‘ai_color_url’);

$retstr = “”;
$adnetwork = $ai_loadnetwork;
if($adnetwork == “”)
$adnetwork = get_option(“ai_network”, “Adsense”);
if($adnetwork == “random”){
$adnetwork = (rand(0,1)==0?”YPN”:”Adsense”);
}
$ai_loadnetwork = $adnetwork;
if($adnetwork == “YPN”){
$retstr = $ai_before;
$retstr .= ‘//

‘;
$retstr .= $ai_after;

}
else{
$retstr = $ai_before.’// 8)
$retstr .= ‘google_adtest=”on”;
‘;

$retstr .= ‘google_ad_client = “pub-‘.$client.'”;
google_alternate_color = “FFFFFF”;
google_ad_width = ‘.$width.’;
google_ad_height = ‘.$height.’;
google_ad_format = “‘.$size.’_as”;
google_ad_type = “‘.$ai_adtype.'”;
google_ad_channel =”‘.$channel.'”;
google_color_border = “‘.$color_border.'”;
google_color_link = “‘.$color_link.'”;
google_color_bg = “‘.$color_bg.'”;
google_color_text = “‘.$color_text.'”;
google_color_url = “‘.$color_url.'”;
google_ui_features = “‘.$corners.'”;
// ]]>

‘.$ai_after;
}

return $retstr;
}

$ai_adsused = 0;

function ai_the_content($content){
global $doing_rss;
if(is_feed() || $doing_rss)
return $content;
if(strpos($content, ““) !== false) return $content;

if(is_home() && get_option(‘ai_home’) == “checked=on”) return $content;
if(is_page() && get_option(‘ai_page’) == “checked=on”) return $content;
if(is_single() && get_option(‘ai_post’) == “checked=on”) return $content;
if(is_category() && get_option(‘ai_cat’) == “checked=on”) return $content;
if(is_archive() && get_option(‘ai_archive’) == “checked=on”) return $content;

global $ai_adsused, $user_level;
if(get_option(‘ai_betatest’) == “yes” && $user_level < 8) return $content; if(get_option(‘ai_notme’) == “yes” && $user_level > 8)
return $content;

$numads = get_option(‘ai_nads’);
if(is_single())
$numads = get_option(‘ai_nadspp’);

$content_hold = “”;
if(strpos($content, ““) != false){
if(strpos($content, ““) != false){
$content_hold = substr($content, 0, strpos($content, ““));
$content_end = substr($content, strpos($content, ““));
$content = substr_replace($content, “”, 0, strpos($content, ““));
$content = substr_replace($content, “”, strpos($content, ““));
}
else{
$content_hold = substr($content, 0, strpos($content, ““));
$content = substr_replace($content, “”, 0, strpos($content, ““));
}
}

$padspace = get_option(‘ai_space’);

while($ai_adsused < $numads){
if(get_option(‘ai_lra’) == “top-left”){
$replacer = $content_hold;
$replacer .= ‘

‘;
$replacer .= ai_genadcode();
$replacer .= ‘

‘;
$ai_adsused++;
return $replacer.$content.$content_end;
}
if(get_option(‘ai_lra’) == “top-right”){
$replacer = $content_hold;
$replacer .= ‘

‘;
$replacer .= ai_genadcode();
$replacer .= ‘

‘;
$ai_adsused++;
return $replacer.$content.$content_end;
}
if(get_option(‘ai_lra’) == “top-center”){
$replacer = $content_hold;
$replacer .= ‘

‘;
$replacer .= ai_genadcode();
$replacer .= ‘

‘;
$ai_adsused++;
return $replacer.$content.$content_end;
}
if(get_option(‘ai_lra’) == “bottom-left”){
$replacer = $content_hold.$content;
$replacer .= ‘

‘;
$replacer .= ai_genadcode();
$replacer .= ‘

‘;
$ai_adsused++;
return $replacer.$content_end;
}
if(get_option(‘ai_lra’) == “bottom-right”){
$replacer = $content_hold.$content;
$replacer .= ‘

‘;
$replacer .= ai_genadcode();
$replacer .= ‘

‘;
$ai_adsused++;
return $replacer.$content_end;
}
if(get_option(‘ai_lra’) == “bottom-center”){
$replacer = $content_hold.$content;
$replacer .= ‘

‘;
$replacer .= ai_genadcode();
$replacer .= ‘

‘;
$ai_adsused++;
return $replacer.$content_end;
}

//while($ai_adsused < $numads){
$poses = array();
$lastpos = -1;
$repchar = ”
if(strpos($content, ”
$repchar = ” $half)
array_pop($poses);

$pickme = $poses[rand(0, sizeof($poses)-1)];

$replacewith = ai_pickalign(get_option(‘ai_lra’));
$replacewith .= ai_genadcode().”

“;

$content = substr_replace($content, $replacewith.$repchar, $pickme, 2);
$ai_adsused++;
if(!is_single())
break;
}

return $content_hold.$content.$content_end;
}

add_filter(‘the_content’, ‘ai_the_content’);

?>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: