Difference between revisions of "Create paypal buttons for mediawiki"

From OpenTutorial
Jump to navigation Jump to search
m
Line 1: Line 1:
= How to Create a PayPal Buttons Extension for Mediawiki =  
+
= How to Create an adsense Buttons Extension for Mediawiki =  
  
IpbWiki Paypal is a Mediawiki Extension which adds a new <nowiki><paypal></nowiki> tag which allows you to add a paypal button to your wiki pages.
+
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.
  
= Download Extension =
 
  
[http://www.ipbwiki.com/forums/index.php?download=1 Download the file IpbWiki_Paypal.php] (Click on the download button on the bottom of the next screen)
+
= Code for file kdm_adsense.php =
  
= Code for file IpbWiki_Paypal.php =
+
Copy and paste the below code and place it in a file named "kdm_adsense.php".
  
If you have problems downloading the above file, then alternatively you can just copy and paste the below code and place it in a file named "IpbWiki_Paypal.php".
 
 
<pre>
 
<pre>
 
<nowiki>
 
<nowiki>
 
<?php
 
<?php
/* IpbWiki Paypal WikiMedia extension  
+
/* kdm adsense WikiMedia extension
** IpbWiki (c) 2006
+
** kdm (c) 2006
** Installation Instructions: http://www.ipbwiki.com/index.php/IpbWiki_Paypal_Extension
+
** Add the following line to LocalSettings.php
 +
** require_once('extensions/kdm/kdm_adsense.php');  // kdm adsense Extension
 
*/
 
*/
  
$wgExtensionFunctions[] = "wfPayPalExtension";
+
$wgExtensionFunctions[] = "wfadsenseExtension";
  
function wfPayPalExtension() {
+
function wfadsenseExtension() {
    global $wgParser;
+
  global $wgParser;
    global $ipbwiki_paypal;
+
  global $kdm_adsense;
    # register the extension with the WikiText parser
+
  # register the extension with the WikiText parser
    $wgParser->setHook( "paypal", "renderPayPal" );
+
  $wgParser->setHook( "adsense", "renderadsense" );
  
    $ipbwiki_paypal = array();
+
  $kdm_adsense = array();
    # CHANGE THE LINES BELOW TO REFLECT TO YOUR PAYPAL BUTTONS!!! (there's no limit on the number of buttons you define)
+
  # CHANGE THE LINES BELOW TO REFLECT TO YOUR ADSENSE ADS!!! (there's no limit on the number of ads you define)
    $ipbwiki_paypal[1] = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_xclick"><input type="hidden" name="business" value="ipbwiki@gmail.com"><input type="hidden" name="item_name" value="IpbWiki PayPal"><input type="hidden" name="no_shipping" value="1"><input type="hidden" name="cn" value="Optional Comments"><input type="hidden" name="currency_code" value="EUR"><input type="hidden" name="tax" value="0"><input type="hidden" name="bn" value="PP-DonationsBF"><input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but04.gif" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!"></form>';
+
  $kdm_adsense[1] = '
    $ipbwiki_paypal[2] = '<form action="https://... - it\'s fast, free and secure!"></form>'
+
<script type="text/javascript">
 +
<!-- google_ad_client = "pub-4452383759975954";
 +
google_ad_width = 468;
 +
google_ad_height = 15;
 +
google_ad_format = "468x15_0ads_al";
 +
google_ad_channel ="6604887705";
 +
google_color_border = "FFFFCC";
 +
google_color_bg = "FFFFFF";
 +
google_color_link = "000000";
 +
google_color_url = "336699";
 +
google_color_text = "333333";
 +
//--></script>
 +
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
 +
';
 +
 
 +
 
 +
  $kdm_adsense[2] = '
 +
<script type="text/javascript"><!--
 +
google_ad_client = "pub-4452383759975954";
 +
google_ad_width = 468;
 +
google_ad_height = 60;
 +
google_ad_format = "468x60_as";
 +
google_ad_type = "text_image";
 +
google_ad_channel ="1172885669";
 +
google_color_border = "C3D9FF";
 +
google_color_bg = "FFFFFF";
 +
google_color_link = "0000FF";
 +
google_color_url = "008000";
 +
google_color_text = "000000";
 +
//--></script>
 +
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
 +
';
 
}
 
}
  
 
# The callback function for converting the input text to HTML output
 
# The callback function for converting the input text to HTML output
function renderPayPal( $input, $argv ) {
+
function renderadsense( $input, $argv ) {
    global $ipbwiki_paypal;
+
  global $kdm_adsense;
    global $wgAuth;
+
  global $wgAuth;
    $pos_space=strpos($input,' ');
+
  $pos_space=strpos($input,' ');
    if (!$pos_space) {
+
  if (!$pos_space) {
        if (is_numeric($input)) {  // format <paypal>number</paypal>
+
      if (is_numeric($input)) {  // format <adsense>number</adsense>
            $part1 = $input;
+
          $part1 = $input;
            $part2 = '';
+
          $part2 = '';
            if (!$ipbwiki_paypal[$part1]) {
+
          if (!$kdm_adsense[$part1]) {
                print_r ('warning, specified paypal button not found, defaulting to button 1');
+
              print_r ('warning, specified adsense button not found, defaulting to button 1');
                $part1 = 1;
+
              $part1 = 1;
                $part2 = $input;
+
              $part2 = $input;
            }
+
          }
        } else {                  // format <paypal>text</paypal> & format <paypal></paypal>
+
      } else {                  // format <adsense>text</adsense> & format <adsense></adsense>
            $part1 = 1;
+
          $part1 = 1;
            $part2 = $input;
+
          $part2 = $input;
        }
+
      }
    } else {                      // format <paypal>number text</paypal>
+
  } else {                      // format <adsense>number text</adsense>
        $part1=substr($input,0,$pos_space);
+
      $part1=substr($input,0,$pos_space);
        $part2=substr($input,$pos_space+1);
+
      $part2=substr($input,$pos_space+1);
        if (is_numeric($part1)) {
+
      if (is_numeric($part1)) {
            if (!$ipbwiki_paypal[$part1]) {
+
          if (!$kdm_adsense[$part1]) {
                print_r ('warning, specified paypal button not found, defaulting to button 1');
+
              print_r ('warning, specified adsense button not found, defaulting to button 1');
                $part1 = 1;
+
              $part1 = 1;
            }
+
          }
        } else {                // format <paypal>text</paypal>
+
      } else {                // format <adsense>text</adsense>
            $part1 = 1;
+
          $part1 = 1;
            $part2 = $input;
+
          $part2 = $input;
        }
+
      }
    }
+
  }
    $form=$ipbwiki_paypal[$part1];
+
  $form=$kdm_adsense[$part1];
    // if the ipbwiki interface is available, then use the clean function which is defined there, otherwise just clean the necessities...
+
  // if the kdm interface is available, then use the clean function which is defined there, otherwise just clean the necessities...
    if (class_exists ('ipbwiki')) {
+
  if (class_exists ('kdm')) {
        $input = $wgAuth->ipbwiki->ipbwiki->clean_value ($part2);
+
      $input = $wgAuth->kdm->kdm->clean_value ($part2);
    } else {  
+
  } else {
        $part2 = str_replace( ">"            , "&gt;"          , $part2 );
+
      $part2 = str_replace( ">"            , "&gt;"          , $part2 );
        $part2 = str_replace( "<"            , "&lt;"          , $part2 );
+
      $part2 = str_replace( "<"            , "&lt;"          , $part2 );
        $part2 = str_replace( "\""          , "&quot;"        , $part2 );
+
      $part2 = str_replace( "\""          , "&quot;"        , $part2 );
        $part2 = str_replace( "!"            , "&#33;"        , $part2 );
+
      $part2 = str_replace( "!"            , "&#33;"        , $part2 );
        $part2 = str_replace( "'"            , "&#39;"        , $part2 );  
+
      $part2 = str_replace( "'"            , "&#39;"        , $part2 );
        $input = $part2;
+
      $input = $part2;
    }
+
  }
    $output = '<table border=0><tr><td>'.$form.'</td><td valign=center>'.$input.'</td></tr></table>';
+
  $output = '<table border=0><tr><td>'.$form.'</td><td valign=center>'.$input.'</td></tr></table>';
    return $output;
+
  return $output;
 
}
 
}
 
?>
 
?>
Line 84: Line 114:
  
 
= !!WARNING!! =
 
= !!WARNING!! =
If the text that you place between the single quotes in the $ipbwiki_paypal[1] variable has any single quotes in it then you mist escape them otherwise IT WILL NOT WORK.
+
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.
 +
 
 +
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"'''
  
 
Example:
 
Example:
*<pre>$ipbwiki_paypal[2] = '<form action="https://... - it\'s fast, free and secure!"></form>'</pre>
+
*<pre>$kdm_adsense[2] = '<form action="https://... - it\'s fast, free and secure!"></form>'</pre>
 
** works just fine
 
** works just fine
*<pre>$ipbwiki_paypal[2] = '<form action="https://... - it's fast, free and secure!"></form>'</pre>
+
*<pre>$kdm_adsense[2] = '<form action="https://... - it's fast, free and secure!"></form>'</pre>
 
** will crash your wiki
 
** will crash your wiki
  
Line 95: Line 127:
  
 
= Installation =
 
= Installation =
* create a directory ipbwiki in the extensions directory
+
* create a directory kdm in the extensions directory
* place IpbWiki_PayPal.php in the extensions/ipbwiki directory (see code below)
+
* place kdm_adsense.php in the extensions/kdm directory (see code below)
 
* open the file LocalSettings.php, search for:
 
* open the file LocalSettings.php, search for:
 
  ?>
 
  ?>
 
and change this to:
 
and change this to:
     require_once('extensions/ipbwiki/IpbWiki_PayPal.php');  // IpbWiki PayPal Extension<br>
+
     require_once('extensions/kdm/kdm_adsense.php');  // kdm adsense Extension<br>
 
  ?>
 
  ?>
* in the function wfPayPalExtension, place the code for your paypal-buttons in the variable $ipbwiki_paypal.
+
* in the function wfadsenseExtension, place the code for your adsense-buttons in the variable $kdm_adsense.
  
 
= Usage =
 
= Usage =
* the tag <nowiki><paypal></nowiki> is translated to the button defined in $ipbwiki_paypal[1].
+
* the tag <nowiki><adsense></nowiki> is translated to the button defined in $kdm_adsense[1].
* the tag <nowiki><paypal>2</paypal></nowiki> is translated to the button defined in $ipbwiki_paypal[2].
+
* the tag <nowiki><adsense>2</adsense></nowiki> is translated to the button defined in $kdm_adsense[2].
* the tag <nowiki><paypal>2 description</paypal></nowiki> is translated to the button defined in $ipbwiki_paypal[2], additionaly the text 'description' is placed next to the paypal button.
+
* 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.
* the tag <nowiki><paypal>description</paypal></nowiki> is translated to the button defined in $ipbwiki_paypal[1], additionaly the text 'description' is placed next to the paypal button.
+
* 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.
  
 
= Donate =
 
= Donate =
Line 114: Line 146:
 
<tr>
 
<tr>
 
   <td>If you find this extension usefull, then perhaps you can donate a few bucks? ;)</td>
 
   <td>If you find this extension usefull, then perhaps you can donate a few bucks? ;)</td>
   <td>Donate to the original author [http://www.ipbwiki.com/index.php/IpbWiki_Paypal_Extension here]</td>
+
   <td><paypal></paypal></td>
 
</tr>
 
</tr>
 
</table>
 
</table>
  
  
{{origin|originurl=http://www.ipbwiki.com/index.php/IpbWiki_Paypal_Extension}}
+
= Inspiration =
 +
This extension was inspired by the [http://www.ipbwiki.com/index.php/IpbWiki_Paypal_Extension IpbWiki Paypal Extension]
  
 +
{{incomplete}}
 
[[category:software]]
 
[[category:software]]
 
[[category:mediawiki]]
 
[[category:mediawiki]]

Revision as of 19:01, 9 April 2006

How to Create an adsense Buttons Extension for Mediawiki

kdm adsense is a Mediawiki Extension which adds a new <adsense> tag which allows you to add an adsense button to your wiki pages.


Code for file kdm_adsense.php

Copy and paste the below code and place it in a file named "kdm_adsense.php".


<?php
/* kdm adsense WikiMedia extension
** kdm (c) 2006
** Add the following line to LocalSettings.php
** require_once('extensions/kdm/kdm_adsense.php');  // kdm adsense Extension
*/

$wgExtensionFunctions[] = "wfadsenseExtension";

function wfadsenseExtension() {
   global $wgParser;
   global $kdm_adsense;
   # register the extension with the WikiText parser
   $wgParser->setHook( "adsense", "renderadsense" );

   $kdm_adsense = array();
   # CHANGE THE LINES BELOW TO REFLECT TO YOUR ADSENSE ADS!!! (there's no limit on the number of ads you define)
   $kdm_adsense[1] = '
<script type="text/javascript">
<!-- google_ad_client = "pub-4452383759975954";
google_ad_width = 468;
google_ad_height = 15;
google_ad_format = "468x15_0ads_al";
google_ad_channel ="6604887705";
google_color_border = "FFFFCC";
google_color_bg = "FFFFFF";
google_color_link = "000000";
google_color_url = "336699";
google_color_text = "333333";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
';


   $kdm_adsense[2] = '
<script type="text/javascript"><!--
google_ad_client = "pub-4452383759975954";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="1172885669";
google_color_border = "C3D9FF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
';
}

# The callback function for converting the input text to HTML output
function renderadsense( $input, $argv ) {
   global $kdm_adsense;
   global $wgAuth;
   $pos_space=strpos($input,' ');
   if (!$pos_space) {
       if (is_numeric($input)) {  // format <adsense>number</adsense>
           $part1 = $input;
           $part2 = '';
           if (!$kdm_adsense[$part1]) {
               print_r ('warning, specified adsense button not found, defaulting to button 1');
               $part1 = 1;
               $part2 = $input;
           }
       } else {                   // format <adsense>text</adsense> & format <adsense></adsense>
           $part1 = 1;
           $part2 = $input;
       }
   } else {                       // format <adsense>number text</adsense>
       $part1=substr($input,0,$pos_space);
       $part2=substr($input,$pos_space+1);
       if (is_numeric($part1)) {
           if (!$kdm_adsense[$part1]) {
               print_r ('warning, specified adsense button not found, defaulting to button 1');
               $part1 = 1;
           }
       } else {                 // format <adsense>text</adsense>
           $part1 = 1;
           $part2 = $input;
       }
   }
   $form=$kdm_adsense[$part1];
   // if the kdm interface is available, then use the clean function which is defined there, otherwise just clean the necessities...
   if (class_exists ('kdm')) {
       $input = $wgAuth->kdm->kdm->clean_value ($part2);
   } else {
       $part2 = str_replace( ">"            , ">"          , $part2 );
       $part2 = str_replace( "<"            , "<"          , $part2 );
       $part2 = str_replace( "\""           , """        , $part2 );
       $part2 = str_replace( "!"            , "!"         , $part2 );
       $part2 = str_replace( "'"            , "'"         , $part2 );
       $input = $part2;
   }
   $output = '<table border=0><tr><td>'.$form.'</td><td valign=center>'.$input.'</td></tr></table>';
   return $output;
}
?>


!!WARNING!!

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.

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"

Example:

  • $kdm_adsense[2] = '<form action="https://... - it\'s fast, free and secure!"></form>'
    • works just fine
  • $kdm_adsense[2] = '<form action="https://... - it's fast, free and secure!"></form>'
    • will crash your wiki


Installation

  • create a directory kdm in the extensions directory
  • place kdm_adsense.php in the extensions/kdm directory (see code below)
  • open the file LocalSettings.php, search for:
?>

and change this to:

    require_once('extensions/kdm/kdm_adsense.php');  // kdm adsense Extension
?>
  • in the function wfadsenseExtension, place the code for your adsense-buttons in the variable $kdm_adsense.

Usage

  • the tag <adsense> is translated to the button defined in $kdm_adsense[1].
  • the tag <adsense>2</adsense> is translated to the button defined in $kdm_adsense[2].
  • the tag <adsense>2 description</adsense> is translated to the button defined in $kdm_adsense[2], additionaly the text 'description' is placed next to the adsense button.
  • the tag <adsense>description</adsense> is translated to the button defined in $kdm_adsense[1], additionaly the text 'description' is placed next to the adsense button.

If you find this extension usefull, then perhaps you can donate a few bucks? ;) <paypal></paypal>


Inspiration

This extension was inspired by the IpbWiki Paypal Extension

This Tutorial in incomplete and is a work in progress
Please be patient as the author will resume work on it shortly

Or...
If you have the knowledge Be bold in updating pages and finish it yourself.
It's very rewarding and a lot of fun too.