Script and Google AdSense Extension

From Zedomax Wiki

Jump to: navigation, search

This extension allow you to add Google AdSense ads or any other scripts.


Usage

Let's say you have this code from Google AdSense:

<script type="text/javascript"><!--
google_ad_client = "pub-3379402347635671";
//728x90, created 12/2/07
google_ad_slot = "6488952503";
google_ad_width = 728;
google_ad_height = 90;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
  1. Replace <script type="text/javascript"> with <myscript>.
  2. Replace </script> with </myscript>.
  3. Replace <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> with <myscript src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></myscript>. 

You should get something like this after the conversion:

<myscript><!--
google_ad_client = "pub-3379402347635671";
//728x90, created 12/2/07
google_ad_slot = "6488952503";
google_ad_width = 728;
google_ad_height = 90;
//--></myscript>
<myscript src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</myscript>

Code


<?php
$wgExtensionCredits['parserhook'][] = array(
'name' => 'Script and Google AdSense Extension - 11/16/2007',
'author' => 'Max Lee http://zedomax.net',
'url' => 'http://zedomax.net',
'version' => 'v.0.1',
'description' => 'Add Google AdSense and other scripts for your pages',
);

# MyScript extension

# Usage:
/*
<myscript><!--
google_ad_client = "pub-3379402347635671";
//728x90, created 12/2/07
google_ad_slot = "6488952503";
google_ad_width = 728;
google_ad_height = 90;
//--></myscript>
<myscript src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

*/

# To install it put this file in the extensions directory
# To activate the extension, include it from your LocalSettings.php
# with: require("extensions/wikiscript.php");

$wgExtensionFunctions[] = "wfMyScript";

function wfMyScript() {
    global $wgParser;
    # registers the <myscript> extension with the WikiText parser
    $wgParser->setHook( "myscript", "renderMyScript" );
}

# The callback function for converting the input text to HTML output
function renderMyScript( $input, $argv ) {
    if ($argv["src"]=='')
        $output = '<script type="text/javascript">';
    else
        $output = '<script src="'.$argv["src"].'" type="text/javascript">';
    $output .= $input;
    $output .= '</script>';
    return $output;
}
?>
Personal tools