View Single Post
  #2 (permalink)  
Old 11-30-2006, 02:42 AM
Dravis Dravis is offline
Casual Pligger
 
Join Date: Jun 2006
Location: Dover, NH
Posts: 62
Thanks: 3
Thanked 42 Times in 16 Posts
Continued from previous post...
libs\lang.conf: add the following code snip to the very end of the file:
Code:
//***** PlugIM.com mod: Adsense Revenue Sharing
//<SECTION>GOOGLE ADSENSE REVENUE SHARING</SECTION><ADDED></ADDED>
PLIGG_Visual_Google_Adsense_ID = "Google Adsense ID"
PLIGG_Visual_Google_Adsense_ID_Explain = "(begins with: pub-)"
PLIGG_Visual_Google_Adsense_Channel = "Adsense Channel (optional)"
PLIGG_Visual_Google_Adsense_Channel_Explain = "(numerical value)"
PLIGG_Visual_Google_Adsense_Only_Admins = "Only admins can see Google Adsense settings."
//***** End PlugIM.com mod 

4.) New File:
plugins\function.adsense.php: save this code as a new file named function.adsense.php and upload it to the plugins directory:
Code:
<?php
 /******************************************************************
* template_lite Adsense Plugin for Pligg
*
* Name: adsense
* Type: function
* Purpose: use the authors adsense ID or not?
* Author: Ryan 'Dravis' Knowles http://www.PlugIM.com
* Parameters:
*	params: parameters array
*	tpl: template_lite instance
* Returns: nothing, assigns new value to a template_lite variable
******************************************************************/
function tpl_function_adsense($params, &$tpl)
{
	// check to make sure this is a full story
	if (strcasecmp($tpl->get_template_vars("viewtype"), "full") != 0){
		// not a full story, no adsense sharing
		$tpl->assign($params['assign'], 0);
		return;
	}
	
	// check to see if the author has an adsense id on their profile
	if ($tpl->get_template_vars("google_adsense_id") == ""){
		// this author hasn't provided their adsense id, no sharing
		$tpl->assign($params['assign'], 0);
		return;
	}
	
	// make sure the logged in user isn't the same user who submitted the story
	// using a case insensitive compare because the user name isn't case sensitive
	if (strcasecmp($tpl->get_template_vars("user_logged_in"), $tpl->get_template_vars("link_submitter")) == 0){
		// the user viewing the story is also the author, can't show them their own ads, no sharing
		$tpl->assign($params['assign'], 0);
		return;
	}

	// generate a random number between 1 and 100
	srand((float) microtime() * 10000000);
	$random = rand(1, 100);

	// check the random number against their adsense percent (defaults to 50% but can be adjusted)	
	if ($random > $tpl->get_template_vars("google_adsense_percent")){
		// if the random number is higher than their percent of revenue sharing, no sharing this time
		$tpl->assign($params['assign'], 0);
		return;
	}

	// passed all checks, use the users adsense ID for this page	
	$tpl->assign($params['assign'], 1);
	return;
}
?>

5.) Template files:
mollio-beat\profile_center.tpl: add the following code snip to approximately line 59:
Code:
<input type="text" name="msn" id="msn" tabindex="4" value="{$user_msn}">
</p></td>
</tr>
<!-- ***** PlugIM.com mod: Adsense Revenue Sharing -->
<tr>
<td><p class="l-mid"><label for="name" accesskey="1">{#PLIGG_Visual_Google_Adsense_ID#}:</label>
{if #PLIGG_Visual_Google_Adsense_ID_Explain# neq ""}
	<em>{#PLIGG_Visual_Google_Adsense_ID_Explain#}</em><br />
{/if}
<input type="text" name="google_adsense_id" id="google_adsense_id" tabindex="5" value="{$google_adsense_id}">
</p></td>
<td><p class="l-mid"><label for="name" accesskey="1">{#PLIGG_Visual_Google_Adsense_Channel#}:</label>
{if #PLIGG_Visual_Google_Adsense_Channel_Explain# neq ""}
	<em>{#PLIGG_Visual_Google_Adsense_Channel_Explain#}</em><br />
{/if}
<input type="text" name="google_adsense_channel" id="google_adsense_channel" tabindex="6" value="{$google_adsense_channel}">
</p></td>
</tr>
<tr><td style="background:#FFFFFF" colspan="2"><em>{#PLIGG_Visual_Google_Adsense_Only_Admins#}</em></td></tr>
<!-- ***** End PlugIM.com mod -->			
<tr>
<td><p class="l-mid"><label for="name" accesskey="1">{#PLIGG_Visual_Profile_PublicEmail#}:</label>
*Note: Don’t forget to update all the tabindex values the rest of the way down the template.
admin_templates\user_edit_center.tpl: add the following code snip to approximately line 16:
Code:
<form id="form1" name="form1" method="get" action="">
<input type=hidden name=user value="{$userdata[nr].user_login}">
<table style="border:none">
	<tr><td width="35%">Login:</td><td width="65%"><input name="login" value="{$userdata[nr].user_login}"></td></tr>
	{if $amIgod eq 1}
<tr><td>Level:</td><td>
<SELECT NAME="level">
	{html_options values=$levels output=$levels selected=$userdata[nr].user_level}
</SELECT>
	{/if}
	</td></tr>
	<tr><td>Email:</td><td><input name="email" value="{$userdata[nr].user_email}"></td></tr>
	<!-- ***** PlugIM.com mod: Adsense Revenue Sharing -->
	<tr><td>Adsense Revenue Share:</td><td><input size="1" name="google_adsense_percent" value="{$userdata[nr].google_adsense_percent}">%</td></tr>	
	<!-- ***** End PlugIM.com mod -->
	<tr><td colspan="2"><input type=submit name=mode value="save" class="log2"> <input type=button onclick="window.history.go(-1)" value="cancel" class="log2"></td></tr>
	<tr><td colspan="2"></td></tr>
*Note: I changed the way the table was being displayed in this template file, so I included the whole form instead of just the mod change
admin_templates\user_show_center.tpl: add the following code snip to approximately line 8:
Code:
<tr><td><b>Email: </b></td><td>{$userdata[nr].user_email}</td></tr>
<!-- ***** PlugIM.com mod: Adsense Revenue Sharing -->
<tr><td><b>Adsense Revenue Share: </b></td><td>{$userdata[nr].google_adsense_percent}%</td></tr>
<!-- ***** End PlugIM.com mod -->
<tr><td><strong>Last Login Date/Time:</strong> </td><td>{$userdata[nr].user_lastlogin}</td></tr>

6.) The Final Step:
WARNING: Messing this part up could seriously get your Adsense account banned.

Google's ONLY Adsense Revenue Sharing Rule to date: If you choose to display multiple Adsense blocks on the same page, EVERY block MUST reference the same Adsense ID number.

Fortunately this mod handles Google's requirement as long as one simple step is followed. See Displaying Multiple Adsense Blocks below:

mollio-beat\link_summary.tpl: add the following code snip wherever you want your first Google Adsense block to be displayed:
Code:
{adsense assign=users_adsense}
{if $users_adsense}
	<script type="text/javascript"><!--
		google_ad_client = "{$google_adsense_id}";
		google_alternate_ad_url = "";
		google_ad_width = 468;
		google_ad_height = 60;
		google_ad_format = "468x60_as";
		google_ad_type = "text";
		google_ad_channel ="{$google_adsense_channel}";
		google_color_border = "f6f6f6";
		google_color_bg = "f6f6f6";
		google_color_link = "330066";
		google_color_text = "000000";
		google_color_url = "330066";
		//-->
	</script>
	<script type="text/javascript"
	  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
	</script>
{else}				
	<script type="text/javascript"><!--
		google_ad_client = "Your Adsense ID number";
		google_alternate_ad_url = "";
		google_ad_width = 468;
		google_ad_height = 60;
		google_ad_format = "468x60_as";
		google_ad_type = "text";
		google_ad_channel ="Your Channel number";
		google_color_border = "f6f6f6";
		google_color_bg = "f6f6f6";
		google_color_link = "330066";
		google_color_text = "000000";
		google_color_url = "330066";
		//-->
	</script>
	<script type="text/javascript"
	  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
	</script>
{/if}
*VERY IMPORTANT: Make sure to fill in your Adsense ID number and optional Channel number where denoted in the code above.
**Note: You can change the color and google_ad_format variables above to whatever you want using the ad designer in your Adsense account.
Displaying Multiple Adsense Blocks:
Use the same code from the section above for your second and third Adsense blocks, just delete the first line of code: {adsense assign=users_adsense}

That line should only be in link_summary.tpl once for the very first Adsense block and that's it. As long as you follow this step, all of your Adsense blocks will always use the same Adsense ID number whether it's yours, or the author of the story.

That's it! Let the questions roll… I’ll check in a couple times a day to answer any questions and PM’s enquiring about availability and pricing to have me do the install for you. Enjoy!
__________________
Ryan 'Dravis' Knowles

RAGING DEBATE & PlugIM
Reply With Quote
The Following 13 Users Say Thank You to Dravis For This Useful Post: