View Single Post
  #1 (permalink)  
Old 11-30-2006, 02:41 AM
Dravis Dravis is offline
Casual Pligger
 
Join Date: Jun 2006
Location: Dover, NH
Posts: 62
Thanks: 3
Thanked 42 Times in 16 Posts
Lightbulb Adsense Revenue Sharing Mod for 8.2

Here it is, the mod you’ve all been waiting for, and if it looks intimidating… that’s because it is. Before we get started, here’s some key information:
  • WARNING: You should not attempt to implement this mod on your own unless you are very comfortable with the Pligg source and know how to make database modifications with phpMyAdmin.
  • This write up is for version 8.2 beta, do not try to implement this mod if you have an older version of Pligg, it won’t work.
  • The line numbers for the code snippets are approximations and may not match your files exactly. I’ve included a line or two of code above and below each snip to help make sure you’re adding the code to the right spot in the file.
  • If you’re uncomfortable implementing this mod, but you really want it, I can install it on your site for you. If you’re interested, PM me for pricing information and please take me up on this. In fact I’m counting on a couple of installs to help me recover from the insane amount of time it took to type this up.
Once implemented, here’s how this mod works:
Users may add an Adsense ID and Adsense Channel (optional) to their account settings. If they set they’re Adsense ID, from that point forward, every time a story they posted is viewed, there’s a chance their ads are displayed. The optional Adsense Channel allows the user to track how many impressions and clicks their ads are getting through their Adsense account. You set the default revenue share percent for all users while implementing the mod, but after that, you may adjust any user’s revenue sharing percent through the user administration menu. So for example if you want to reward one particular member for their recent participation, you can bump just that one user’s revenue share from 50% to 80%. The way this mod is set up, there is no revenue sharing for ads on the front page summary, or any other pages on the site, just the full story pages where you can submit comments. As a safety precaution to protect your users, as long as they’re logged into their user account, they’ll never be shown their own ads in an attempt to help prevent them from accidentally clicking them and getting banned from Google.
On to the changes…

1.) Database Changes:
Using phpMyAdmin, login to your Pligg database and add the following fields to the end of the users table:
google_adsense_id VARCHAR(64) not null
google_adsense_channel VARCHAR(64) not null
google_adsense_percent TINYINT(3) UNSIGNED not null 50*
*Default Value: This is the default percent revenue sharing value you want to automatically assign all new and current users of your site. I don’t recommend changing this once you’ve set it, so think long and hard on what you want it to be. In this example, when the author’s stories are viewed, their ads are shown 50% of the time. You can set it anywhere between 0-100.

2.) Root files:
admin_users.php: add the following code snip to approximately line 101:
Code:
$userdata->email=trim($_GET["email"]);
//***** PlugIM.com mod: Adsense Revenue Sharing
$userdata->google_adsense_percent=trim($_GET["google_adsense_percent"]);
//***** End PlugIM.com mod
$userdata->store();
profile.php: add the following 2 code snips:
Approximately line 129 (in the show_profile() function):
Code:
$main_smarty->assign('user_email', $user->email);
//***** PlugIM.com mod: Adsense Revenue Sharing
$main_smarty->assign('google_adsense_id', $user->google_adsense_id);
$main_smarty->assign('google_adsense_channel', $user->google_adsense_channel);
//***** End PlugIM.com mod
$main_smarty->assign('user_login', $user->username);
Approximately line 182 (in the save_profile() function):
Code:
	$user->email=cleanit($_POST['email']);
}
//***** PlugIM.com mod: Adsense Revenue Sharing
$user->google_adsense_id=cleanit($_POST['google_adsense_id']);
$user->google_adsense_channel=cleanit($_POST['google_adsense_channel']);
//***** End PlugIM.com mod	
$user->url=cleanit($_POST['url']);
user.php: search for $link->print_summary(); It's in 4 different places in the file: approximately lines 196, 211, 226, and 241.
Replace all 4 of those lines with the following:
Code:
//***** PlugIM.com mod: Adsense Revenue Sharing
//$link->print_summary();			
$link->print_summary('summary');
//***** End PlugIM.com mod 

3.) Lib Files:
libs\link.php: add the following 3 code snips:
Approximately line 14 (in the Link class):
Code:
var $username = false;
//***** PlugIM.com mod: Adsense Revenue Sharing
var $google_adsense_id = '';
var $google_adsense_channel = '';
var $google_adsense_percent = '';
//***** End PlugIM.com mod	
var $randkey = 0;
Approximately line 192 (in the read() function):
Code:
$id = $this->id;
//***** PlugIM.com mod: Adsense Revenue Sharing
//if(($link = $db->get_row("SELECT links.*, users.user_login, users.user_email FROM links, users WHERE link_id = $id AND user_id=link_author"))) {
if(($link = $db->get_row("SELECT links.*, users.user_login, users.user_email, users.google_adsense_id, users.google_adsense_channel, users.google_adsense_percent FROM links, users WHERE link_id = $id AND user_id=link_author"))) {
//***** End PlugIM.com mod
	$this->author=$link->link_author;
	$this->author_email=$link->user_email;
	//***** PlugIM.com mod: Adsense Revenue Sharing
	$this->google_adsense_id = $link->google_adsense_id;
	$this->google_adsense_channel = $link->google_adsense_channel;
	$this->google_adsense_percent = $link->google_adsense_percent;
	//***** End PlugIM.com mod				
	$this->username=$link->user_login;
Approximately line 471 (in the fill_smarty($smarty, $type='full') function):
Code:
$smarty->assign('Avatar_ImgSrc', get_avatar('large', "", $this->username(), $this->author_email));
		
//***** PlugIM.com mod: Adsense Revenue Sharing
$smarty->assign('google_adsense_id', $this->google_adsense_id);
$smarty->assign('google_adsense_channel', $this->google_adsense_channel);
$smarty->assign('google_adsense_percent', $this->google_adsense_percent);
//***** End PlugIM.com mod	

$canIhaveAccess = 0;
libs\user.php: add the following 4 code snips:
Approximately line 18 (in the User class):
Code:
var $email = '';
//***** PlugIM.com mod: Adsense Revenue Sharing
var $google_adsense_id = '';
var $google_adsense_channel = '';
var $google_adsense_percent = 50;	// default to 50%*
//***** End PlugIM.com mod	
var $names = '';
*VERY IMPORTANT: This value MUST match the default value you assigned to google_adsense_percent in the Users table of the Pligg database!

Approximately line 62 (in the store() function):
Code:
$user_email = $db->escape($this->email);
//***** PlugIM.com mod: Adsense Revenue Sharing
$user_google_adsense_id = $db->escape($this->google_adsense_id);
$user_google_adsense_channel = $db->escape($this->google_adsense_channel);
$user_google_adsense_percent = $db->escape($this->google_adsense_percent);
//***** End PlugIM.com mod			
$user_names = $db->escape($this->names);
Approximately line 88 (also in the store() function):
Code:
} else {
	// Username is never updated
	//***** PlugIM.com mod: Adsense Revenue Sharing
	//$sql = "UPDATE users set user_avatar_source='$user_avatar_source', user_login='$user_login', user_occupation='$user_occupation', user_location='$user_location', public_email='$user_public_email', user_level='$user_level', user_karma=$user_karma, user_date=FROM_UNIXTIME($user_date), user_pass='$saltedpass', user_lang=$user_lang, user_email='$user_email', user_names='$user_names', user_url='$user_url', user_aim='$user_aim', user_msn='$user_msn', user_yahoo='$user_yahoo', user_gtalk='$user_gtalk', user_skype='$user_skype', user_irc='$user_irc' WHERE user_id=$this->id";
	$sql = "UPDATE users set user_avatar_source='$user_avatar_source', user_login='$user_login', google_adsense_id='$user_google_adsense_id', google_adsense_channel='$user_google_adsense_channel', google_adsense_percent='$user_google_adsense_percent', user_occupation='$user_occupation', user_location='$user_location', public_email='$user_public_email', user_level='$user_level', user_karma=$user_karma, user_date=FROM_UNIXTIME($user_date), user_pass='$saltedpass', user_lang=$user_lang, user_email='$user_email', user_names='$user_names', user_url='$user_url', user_aim='$user_aim', user_msn='$user_msn', user_yahoo='$user_yahoo', user_gtalk='$user_gtalk', user_skype='$user_skype', user_irc='$user_irc' WHERE user_id=$this->id";
	//***** End PlugIM.com mod
	//die($sql);
	$db->query($sql);
}
Approximately line 111 (in the read() function):
Code:
$this->pass = $user->user_pass;
//***** PlugIM.com mod: Adsense Revenue Sharing
$this->google_adsense_id = $user->google_adsense_id;
$this->google_adsense_channel = $user->google_adsense_channel;
$this->google_adsense_percent = $user->google_adsense_percent;
//***** End PlugIM.com mod				
$this->email = $user->user_email;
Continued in next post...

Last edited by Dravis; 12-15-2006 at 01:19 AM.
Reply With Quote
The Following 2 Users Say Thank You to Dravis For This Useful Post: