https://opentutorial.com/api.php?action=feedcontributions&user=Hurfblurf&feedformat=atomOpenTutorial - User contributions [en]2024-03-29T08:39:53ZUser contributionsMediaWiki 1.32.0https://opentutorial.com/index.php?title=Create_adsense_ads_for_mediawiki&diff=2890Create adsense ads for mediawiki2007-01-05T09:59:34Z<p>Hurfblurf: /* The Code */</p>
<hr />
<div>'''How to Create a Google Adsense Extension for Mediawiki''' - kdm adsense is a Mediawiki Extension which adds a new <nowiki><adsense></nowiki> tag which allows you to add an adsense button to your wiki pages.<br />
<br />
== The Code ==<br />
<pre><nowiki><br />
<?php<br />
/* kdm adsense WikiMedia extension<br />
** kdm (c) 2006<br />
** Add the following line to LocalSettings.php<br />
** require_once('extensions/kdm/kdm_adsense.php'); // kdm adsense Extension<br />
*/<br />
<br />
$wgExtensionFunctions[] = "wfadsenseExtension";<br />
<br />
function wfadsenseExtension() {<br />
global $wgParser;<br />
global $kdm_adsense;<br />
# register the extension with the WikiText parser<br />
$wgParser->setHook( "adsense", "renderadsense" );<br />
<br />
$kdm_adsense = array();<br />
# CHANGE THE LINES BELOW TO REFLECT TO YOUR ADSENSE ADS!!! (there's no limit on the number of ads you define)<br />
$kdm_adsense[1] = '<br />
<script type="text/javascript"><br />
<!--<br />
google_ad_client = "pub-1702912899203427";<br />
google_ad_width = 468;<br />
google_ad_height = 15;<br />
google_ad_format = "468x15_0ads_al";<br />
google_ad_channel ="3636989479";<br />
google_color_border = "FFFFCC";<br />
google_color_bg = "FFFFFF";<br />
google_color_link = "000000";<br />
google_color_url = "336699";<br />
google_color_text = "333333";<br />
//--></script><br />
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><br />
';<br />
<br />
<br />
$kdm_adsense[2] = '<br />
<script type="text/javascript"><!--<br />
google_ad_client = "pub-4452383759975954";<br />
google_ad_width = 468;<br />
google_ad_height = 60;<br />
google_ad_format = "468x60_as";<br />
google_ad_type = "text_image";<br />
google_ad_channel ="1172885669";<br />
google_color_border = "C3D9FF";<br />
google_color_bg = "FFFFFF";<br />
google_color_link = "0000FF";<br />
google_color_url = "008000";<br />
google_color_text = "000000";<br />
//--></script><br />
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><br />
';<br />
}<br />
<br />
# The callback function for converting the input text to HTML output<br />
function renderadsense( $input, $argv ) {<br />
global $kdm_adsense;<br />
global $wgAuth;<br />
$pos_space=strpos($input,' ');<br />
if (!$pos_space) {<br />
if (is_numeric($input)) { // format <adsense>number</adsense><br />
$part1 = $input;<br />
$part2 = '';<br />
if (!$kdm_adsense[$part1]) {<br />
print_r ('warning, specified adsense ad not found, defaulting to button 1');<br />
$part1 = 1;<br />
$part2 = $input;<br />
}<br />
} else { // format <adsense>text</adsense> & format <adsense></adsense><br />
$part1 = 1;<br />
$part2 = $input;<br />
}<br />
} else { // format <adsense>number text</adsense><br />
$part1=substr($input,0,$pos_space);<br />
$part2=substr($input,$pos_space+1);<br />
if (is_numeric($part1)) {<br />
if (!$kdm_adsense[$part1]) {<br />
print_r ('warning, specified adsense ad not found, defaulting to button 1');<br />
$part1 = 1;<br />
}<br />
} else { // format <adsense>text</adsense><br />
$part1 = 1;<br />
$part2 = $input;<br />
}<br />
}<br />
$form=$kdm_adsense[$part1];<br />
// if the kdm interface is available, then use the clean function which is defined there, <br />
// otherwise just clean the necessities...<br />
if (class_exists ('kdm')) {<br />
$input = $wgAuth->kdm->kdm->clean_value ($part2);<br />
} else {<br />
$part2 = str_replace( ">" , ">" , $part2 );<br />
$part2 = str_replace( "<" , "<" , $part2 );<br />
$part2 = str_replace( "\"" , """ , $part2 );<br />
$part2 = str_replace( "!" , "!" , $part2 );<br />
$part2 = str_replace( "'" , "'" , $part2 );<br />
$input = $part2;<br />
}<br />
$output = '<table border=0><tr><td>'.$form.'</td><td valign=center>'.$input.'</td></tr></table>';<br />
return $output;<br />
}<br />
?><br />
</nowiki></pre><br />
<br />
== !!WARNING!! ==<br />
If the text that you place between the single quotes in the $kdm_adsense[1] variable has any single quotes in it then you must escape them otherwise IT WILL NOT WORK.<br />
<br />
You will get an error like similar to '''"Parse error: parse error, unexpected '}' in /home/content/O/p/e/OpenTutorial/html/extensions/kdm/kdm_adsense.php on line 21"'''<br />
<br />
Example:<br />
*<pre>$kdm_adsense[2] = '<form action="https://... - it\'s fast, free and secure!"></form>'</pre><br />
** works just fine<br />
*<pre>$kdm_adsense[2] = '<form action="https://... - it's fast, free and secure!"></form>'</pre><br />
** will crash your wiki<br />
<br />
<br />
== Installation ==<br />
* create a directory kdm in the extensions directory<br />
* place kdm_adsense.php in the extensions/kdm directory (see code below)<br />
* open the file LocalSettings.php, search for:<br />
?><br />
and change this to:<br />
require_once('extensions/kdm/kdm_adsense.php'); // kdm adsense Extension<br><br />
?><br />
* in the function wfadsenseExtension, place the code for your adsense-buttons in the variable $kdm_adsense.<br />
<br />
<br />
== Usage ==<br />
* the tag <nowiki><adsense></nowiki> is translated to the button defined in $kdm_adsense[1].<br />
* the tag <nowiki><adsense>2</adsense></nowiki> is translated to the button defined in $kdm_adsense[2].<br />
* the tag <nowiki><adsense>2 description</adsense></nowiki> is translated to the button defined in $kdm_adsense[2], additionaly the text 'description' is placed next to the adsense button.<br />
* the tag <nowiki><adsense>description</adsense></nowiki> is translated to the button defined in $kdm_adsense[1], additionaly the text 'description' is placed next to the adsense button.<br />
<br />
<br />
== Donate ==<br />
If you find this extension usefull, then perhaps you can donate a few bucks? ;)<br />
<br />
<paypal></paypal><br />
<br />
<br />
== Example ==<br />
<nowiki><adsense></adsense></nowiki> Produces (Note: Sometimes this doesn't always how up, I don't know why)<br><adsense></adsense> <br />
<br />
<nowiki><adsense>2</adsense></nowiki> Produces <br><adsense>2</adsense><br />
<br />
<br />
<br />
== Inspiration ==<br />
This extension was inspired by the [http://www.ipbwiki.com/index.php/IpbWiki_Paypal_Extension IpbWiki Paypal Extension]<br />
<br />
<br />
== See also ==<br />
* [[Create paypal buttons for mediawiki]]<br />
* [[Hack mediawiki isbn for affiliates]]<br />
<br />
<br />
<br />
== Bibliography ==<br />
<br />
* (ISBN 0470043997) "Wikis For Dummies (For Dummies (Computer/Tech))" by Dan Woods <br />
* (ISBN 020171499X) "The Wiki Way: Quick Collaboration on the Web" by Bo Leuf, Ward Cunningham <br />
* (ISBN 3540259953) "Wiki : Web Collaboration" by Anja Ebersbach, Markus Glaser, Richard Heigl, G. Dueck (Foreword), Andrea Adelung (Translator)<br />
<br />
<br />
<br />
[[category:software]]<br />
[[category:mediawiki]]</div>Hurfblurf