/****************************************************************
  Docking Boxes core CSS: YOU MUST NOT CHANGE OR OVERRIDE THESE 
*****************************************************************/
.dbx-clone {
	position:absolute;
	visibility:hidden;
	}
.dbx-clone, .dbx-clone .dbx-handle-cursor {
	cursor:move !important;
	}
.dbx-dummy {
	display:block;
	width:0;
	height:0;
	overflow:hidden;
	}
.dbx-group, .dbx-box, .dbx-handle {
	position:relative;
	display:block;
	}
/****************************************************************
  avoid padding, margins or borders on dbx-box, 
  to reduce visual discrepancies between it and the clone.  
  overall, dbx-box is best left as visually unstyled as possible 
*****************************************************************/
.dbx-box {
	margin:0;
	padding:0;
	border:none;
	clear: both;
	}
/****************************************************************
  otherwise, do what you like :) 
*****************************************************************/
/* group container(s) */
.dbx-group {
	width:210px;
	padding:0 0px 10px;
}
* html .dbx-group {
	width: 210px;
	padding-bottom:0;
}

/* handles */
.dbx-handle {
	position:relative;
	margin:0;
	padding: 16px 24px 7px 10px;
	background:url(images/sidep-handle.png) no-repeat 0 0; 
}
* html .dbx-handle { 
	width: 176px; 
}
/* handle cursors are in a class of their own
   so they only get applied if the script is supported */
.dbx-handle-cursor {
	cursor:move;
}

/* toggle images */
a.dbx-toggle, a.dbx-toggle:visited {
	display:block;
	width:20px;
	height:20px;
	overflow:hidden;
	background:url(images/sidep-toggle.png) no-repeat;
	position:absolute;
	top:12px;
	right:3px;
	text-indent:-50px;
	text-decoration:none;
}
a.dbx-toggle-open, a.dbx-toggle-open:visited {
	background-position:0 0;
}
a.dbx-toggle-closed, a.dbx-toggle-closed:visited {
	background-position:0 -20px;
}
a.dbx-toggle-hilite-open, a.dbx-toggle-hilite-open:visited {
	background-position:-20px 0;
}
a.dbx-toggle-hilite-closed, a.dbx-toggle-hilite-closed:visited {
	background-position:-20px -20px;
}

/* keyboard navigation tooltip */
.dbx-tooltip {
	display:block;
	position:absolute;
	margin:36px 0 0 125px;
	width:185px;
	border:1px solid #000;
	background:#ffd;
	color:#000;
	font:normal normal normal 0.85em tahoma, arial, sans-serif;
	padding:2px 4px 3px 5px;
	text-align:left;
}
* html .dbx-tooltip { width:210px; }

/* use CSS2 system colors in CSS2 browsers 
   but not safari, which doesn't support them */
*[class="dbx-tooltip"]:lang(en) {
	border-color:InfoText;
	background:InfoBackground;
	color:InfoText;
	font:small-caption;
	font-weight:normal;
	}
/* inner content area */	
.dbx-content {
	margin: 0;
	padding: 5px 10px 9px 10px;
	background: url(images/sidep-bottom.png) no-repeat 0 100%;
	overflow: hidden;
}
/* toggle state of inner content area */
.dbx-box-closed .dbx-content {
	display:block;
	height:4px;
	padding:0;
	overflow:hidden;
}
.dbx-box-closed .dbx-content * {
	display:none;
}

/* additional clone styles */
.dbx-clone {
	opacity:0.8;
	-moz-opacity:0.8;
	-khtml-opacity:0.8;
	filter:alpha(opacity=80);
}
<?php
/*
Plugin Name: Author Adsense
Plugin URI: http://www.kinkydress.com/php-scripts/author-adsense/
Description: Allows authors to specify their own Google Adsense Publisher ID and share in your blog's ad revenue.
Version: 3.0
Author: Lisa-Marie Welsh (Harley)
Author URI: http://www.kinkydress.com
*/

/*  Copyright 2006  Lisa-Marie Welsh  (email : lisa.welsh@gmail.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 2 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, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
function kd_install(){
   global $table_prefix, $wpdb, $user_level;

   $table_name = $table_prefix . "author_adsense";

   if($wpdb->get_var("show tables like '$table_name'") != $table_name){

   $sql = "CREATE TABLE ".$table_name." (
   id mediumint(9) NOT NULL auto_increment,
   author_id int(11) NOT NULL default '0',
   author_adsense text NOT NULL,
   PRIMARY KEY  (`id`)
   );";

   require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
   dbDelta($sql);

   $google_values[0] = "";
   $google_values[1] = "50";
   $google_values[2] = "50";
   $google_values[3] = "edit_posts";

   update_option("kd_author_adsense", $google_values);

   }
}

function kd_get_google_id($user_id){
   global $table_prefix, $wpdb, $user_ID;
   $table_name = $table_prefix . "author_adsense";
   $google_values = get_option('kd_author_adsense');

      $google_id = $wpdb->get_var("SELECT author_adsense FROM $table_name WHERE author_id='$user_id'");
      $google_values = get_option('kd_author_adsense');
      $admin_id = $google_values[0];
      if(!$google_id){ $google_id = $admin_id; }

   srand(time());
   $random = (rand()%101);
   if($random <= $google_values[1]){ return $admin_id; }
   else { return $google_id; }
}
function kd_authoredit(){
   global $table_prefix, $wpdb, $user_ID;
   
   $table_name = $table_prefix . "author_adsense";
   
   if(isset($_POST['update_kd_googleauthor'])) {
      $user_adsense = $_POST['user_google'];
      $google_id = $wpdb->get_var("SELECT author_adsense FROM $table_name WHERE author_id=$user_ID");
              if(!$google_id) { $wpdb->query("INSERT INTO $table_name (author_id, author_adsense) VALUES ('$user_ID', '$user_adsense')"); }

         if($google_id) { $wpdb->query("UPDATE $table_name SET author_adsense='$user_adsense' WHERE author_id='$user_ID'"); }
   }
   $google_id = $wpdb->get_var("SELECT author_adsense FROM $table_name WHERE author_id='$user_ID'");
   ?>
   <div class=wrap>
   <form method="post">
      <h2>Update Your Adsense ID</h2>
      <p><b>Warning:</b> Repeatedly clicking on your own ads will lead to a suspension of your adsense account by the friendly people at Google. For more information about Google's terms, take a look <a href="https://www.google.com/support/adsense/bin/answer.py?answer=23921&topic=8426" target="_blank">at what you should do to prevent suspension</a>.</p>
      <p>Insert your Google Adsense publishers ID below. If you don't have one you can get one <a href="http://www.google.com/adsense/" target="_blank">here</a>.</p>

   <fieldset name="set1">
   <legend>Adsense ID</legend>
   <input type="text" name="user_google" value="<? echo $google_id; ?>">
   </fieldset>
   <div class="submit">
   <input type="hidden" name="update_kd_googleauthor" value="1">
   <input type="submit" name="info_update" value="Update Options &raquo;" /></div>
   </form>

<p align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-0171234649422987";
google_ad_width = 120;
google_ad_height = 60;
google_ad_format = "120x60_as_rimg";
google_cpa_choice = "CAAQsYXuiwIaCHNv7ZBFBHrZKOvB93M";
google_ad_channel = "2268339227";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

   </div>
<?php
}

function kd_admin_menu() {
   $google_values = get_option('kd_author_adsense');
   $lowest_user = $google_values[3];
   add_submenu_page('plugins.php', 'Author Adsense Config', 'Author Adsense Config', 'manage_options', 'author-adsense-admin', 'kd_admin_options');
   add_submenu_page('index.php', 'My Adsense', 'My Adsense', $lowest_user, 'author-adsense', 'kd_authoredit');
   }

function kd_admin_options(){
   global $table_prefix, $wpdb;
   $table_name = $table_prefix . "author_adsense";
   $google_current = "3.0";


   if(isset($_POST['update_kd_google'])) {
   $google_values[0] = $_POST['user_google'];
   $google_values[1] = $_POST['admin_show'];
   $google_values[2] = 100 - $google_values[1];
   $google_values[3] = $_POST['level_google'];

   update_option("kd_author_adsense", $google_values);
   }

   if($wpdb->get_var("show tables like '$table_name'") != $table_name){
         echo "<div class='wrap'><p><b>The database table is not installed, check your db permissions and activate the plugin again or run the following code in phpMyAdmin</b></p>";
   $sql = "CREATE TABLE ".$table_name." (
   id mediumint(9) NOT NULL auto_increment,
   author_id int(11) NOT NULL default '0',
   author_adsense text NOT NULL,
   PRIMARY KEY  (`id`)
   );";
   echo "<p><code>" . $sql . "</code></p></div>";
         }

   $google_values = get_option('kd_author_adsense');
   ?>
   <div class=wrap>
   <form method="post">
      <h2>Update Author Adsense Options</h2>
      <br/>Your Version: <?php echo $google_current; ?>
      <script type="text/javascript" src="http://www.kinkydress.com/downloads/authoradsense.js"></script>
      <p>At the moment your ads are showing at a ratio of (Admin) <?php echo $google_values[1] . ":" . $google_values[2]; ?> (User).</p>
      <p>Enter your admin Google Adsense ID. If the author hasn't specified an adsense publisher, the admin id will be shown instead.</p>
      <fieldset name="set1">
   <legend>Admin Google ID</legend>
   <input type="text" name="user_google" value="<?php echo $google_values[0]; ?>">
      </fieldset>
   <p>Put in the percentage you want the above admin ID to show for example if you want your ads to show half of the time enter 50, if you want them to show three quarters of the time enter 75.</p>
   <fieldset name="set2">
   <legend>Admin Percentage</legend>
   <input type="text" name="admin_show" value="<?php echo $google_values[1]; ?>" size="2">%
   </fieldset>
   <p>Enter the lowest user level that are allowed to add their adsense ID.</p>
   <fieldset name="set3">
   <legend>User Level</legend>
   <select name="level_google" size="1">
<option <?php if($google_values[3]=="manage_options") echo "selected "; ?>value="manage_options">Administrator</option>
<option <?php if($google_values[3]=="moderate_comments") echo "selected "; ?>value="moderate_comments">Editor</option>
<option <?php if($google_values[3]=="publish_posts") echo "selected "; ?>value="publish_posts">Author</option>
<option <?php if($google_values[3]=="edit_posts") echo "selected "; ?>value="edit_posts">Contributer</option>
</select>
</fieldset>
   <div class="submit">
   <input type="hidden" name="update_kd_google" value="1">
   <input type="submit" name="info_update" value="Update Options &raquo;" /></div>
   </form>
   </div>
   <div class="wrap">
   <p><b>Usage:</b></p>
   <p>In your theme file, for example single.php enter your usual adsense code. In the line that says google_ad_client = "yourid" enter this code &lt;&#63;php $kd_user_id=$post->post_author; echo kd_get_google_id($kd_user_id);  &#63;&#62; overwriting the yourid bit. This will insert the appropriate google publisher id in the right place.</p>
   <p>For help/suggestions/bug reports please visit the <a href="http://www.kinkydress.com/php-scripts/author-adsense/" target="_blank">author adsense page</a> or feel free to email harleyquine@gmail.com.</p>
<?php
}
add_action('admin_menu', 'kd_admin_menu');
add_action('activate_author-adsense.php','kd_install');
