Difference between revisions of "Create paypal buttons for mediawiki"
Jump to navigation
Jump to search
(Reformatted to make it look better) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | = How to Create | + | = How to Create a PayPal 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. | |
− | = | + | = 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 IpbWiki_Paypal.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 |
− | ** | + | ** IpbWiki (c) 2006 |
− | ** | + | ** Installation Instructions: http://www.ipbwiki.com/IpbWiki_Paypal_Extension |
− | |||
*/ | */ | ||
− | $wgExtensionFunctions[] = " | + | $wgExtensionFunctions[] = "wfPayPalExtension"; |
− | function | + | function wfPayPalExtension() { |
− | + | global $wgParser; | |
− | + | global $ipbwiki_paypal; | |
− | + | # register the extension with the WikiText parser | |
− | + | $wgParser->setHook( "paypal", "renderPayPal" ); | |
− | + | $ipbwiki_paypal = array(); | |
− | + | # CHANGE THE LINES BELOW TO REFLECT TO YOUR PAYPAL BUTTONS!!! (there's no limit on the number of buttons 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>'; | |
− | < | + | $ipbwiki_paypal[2] = '<form action="https://... - it\'s fast, free and secure!"></form>' |
− | < | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | < | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | //--></ | ||
− | < | ||
− | ' | ||
} | } | ||
# The callback function for converting the input text to HTML output | # The callback function for converting the input text to HTML output | ||
− | function | + | function renderPayPal( $input, $argv ) { |
− | + | global $ipbwiki_paypal; | |
− | + | global $wgAuth; | |
− | + | $pos_space=strpos($input,' '); | |
− | + | if (!$pos_space) { | |
− | + | if (is_numeric($input)) { // format <paypal>number</paypal> | |
− | + | $part1 = $input; | |
− | + | $part2 = ''; | |
− | + | if (!$ipbwiki_paypal[$part1]) { | |
− | + | print_r ('warning, specified paypal button not found, defaulting to button 1'); | |
− | + | $part1 = 1; | |
− | + | $part2 = $input; | |
− | + | } | |
− | + | } else { // format <paypal>text</paypal> & format <paypal></paypal> | |
− | + | $part1 = 1; | |
− | + | $part2 = $input; | |
− | + | } | |
− | + | } else { // format <paypal>number text</paypal> | |
− | + | $part1=substr($input,0,$pos_space); | |
− | + | $part2=substr($input,$pos_space+1); | |
− | + | if (is_numeric($part1)) { | |
− | + | if (!$ipbwiki_paypal[$part1]) { | |
− | + | print_r ('warning, specified paypal button not found, defaulting to button 1'); | |
− | + | $part1 = 1; | |
− | + | } | |
− | + | } else { // format <paypal>text</paypal> | |
− | + | $part1 = 1; | |
− | + | $part2 = $input; | |
− | + | } | |
− | + | } | |
− | + | $form=$ipbwiki_paypal[$part1]; | |
− | + | // if the ipbwiki interface is available, then use the clean function which is defined there, otherwise just clean the necessities... | |
− | + | if (class_exists ('ipbwiki')) { | |
− | + | $input = $wgAuth->ipbwiki->ipbwiki->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; | |
} | } | ||
?> | ?> | ||
Line 112: | Line 82: | ||
</nowiki> | </nowiki> | ||
</pre> | </pre> | ||
+ | |||
+ | {{adsense2}} | ||
+ | |||
= !!WARNING!! = | = !!WARNING!! = | ||
− | If the text that you place between the single quotes in the $ | + | 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. |
− | |||
− | |||
Example: | Example: | ||
− | *<pre>$ | + | *<pre>$ipbwiki_paypal[2] = '<form action="https://... - it\'s fast, free and secure!"></form>'</pre> |
** works just fine | ** works just fine | ||
− | *<pre>$ | + | *<pre>$ipbwiki_paypal[2] = '<form action="https://... - it's fast, free and secure!"></form>'</pre> |
** will crash your wiki | ** will crash your wiki | ||
− | |||
= Installation = | = Installation = | ||
− | * create a directory | + | * create a directory ipbwiki in the extensions directory |
− | * place | + | * place IpbWiki_PayPal.php in the extensions/ipbwiki 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/ | + | require_once('extensions/ipbwiki/IpbWiki_PayPal.php'); // IpbWiki PayPal Extension<br> |
?> | ?> | ||
− | * in the function | + | * in the function wfPayPalExtension, place the code for your paypal-buttons in the variable $ipbwiki_paypal. |
+ | |||
= Usage = | = Usage = | ||
− | * the tag <nowiki>< | + | * the tag <nowiki><paypal></nowiki> is translated to the button defined in $ipbwiki_paypal[1]. |
− | * the tag <nowiki>< | + | * the tag <nowiki><paypal>2</paypal></nowiki> is translated to the button defined in $ipbwiki_paypal[2]. |
− | * the tag <nowiki>< | + | * 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>< | + | * 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. |
+ | |||
= Donate = | = Donate = | ||
Line 146: | Line 118: | ||
<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> | + | <td>Donate to the original author [http://www.ipbwiki.com/IpbWiki_Paypal_Extension here]</td> |
</tr> | </tr> | ||
</table> | </table> | ||
− | |||
− | |||
− | + | ||
[[category:software]] | [[category:software]] | ||
[[category:mediawiki]] | [[category:mediawiki]] |
Latest revision as of 00:08, 2 October 2007
Contents
How to Create a PayPal Buttons Extension for Mediawiki
IpbWiki Paypal is a Mediawiki Extension which adds a new <paypal> tag which allows you to add a paypal button to your wiki pages.
Download Extension
Download the file IpbWiki_Paypal.php (Click on the download button on the bottom of the next screen)
Code for file IpbWiki_Paypal.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".
<?php /* IpbWiki Paypal WikiMedia extension ** IpbWiki (c) 2006 ** Installation Instructions: http://www.ipbwiki.com/IpbWiki_Paypal_Extension */ $wgExtensionFunctions[] = "wfPayPalExtension"; function wfPayPalExtension() { global $wgParser; global $ipbwiki_paypal; # register the extension with the WikiText parser $wgParser->setHook( "paypal", "renderPayPal" ); $ipbwiki_paypal = array(); # CHANGE THE LINES BELOW TO REFLECT TO YOUR PAYPAL BUTTONS!!! (there's no limit on the number of buttons 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>'; $ipbwiki_paypal[2] = '<form action="https://... - it\'s fast, free and secure!"></form>' } # The callback function for converting the input text to HTML output function renderPayPal( $input, $argv ) { global $ipbwiki_paypal; global $wgAuth; $pos_space=strpos($input,' '); if (!$pos_space) { if (is_numeric($input)) { // format <paypal>number</paypal> $part1 = $input; $part2 = ''; if (!$ipbwiki_paypal[$part1]) { print_r ('warning, specified paypal button not found, defaulting to button 1'); $part1 = 1; $part2 = $input; } } else { // format <paypal>text</paypal> & format <paypal></paypal> $part1 = 1; $part2 = $input; } } else { // format <paypal>number text</paypal> $part1=substr($input,0,$pos_space); $part2=substr($input,$pos_space+1); if (is_numeric($part1)) { if (!$ipbwiki_paypal[$part1]) { print_r ('warning, specified paypal button not found, defaulting to button 1'); $part1 = 1; } } else { // format <paypal>text</paypal> $part1 = 1; $part2 = $input; } } $form=$ipbwiki_paypal[$part1]; // if the ipbwiki interface is available, then use the clean function which is defined there, otherwise just clean the necessities... if (class_exists ('ipbwiki')) { $input = $wgAuth->ipbwiki->ipbwiki->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 $ipbwiki_paypal[1] variable has any single quotes in it then you mist escape them otherwise IT WILL NOT WORK.
Example:
$ipbwiki_paypal[2] = '<form action="https://... - it\'s fast, free and secure!"></form>'
- works just fine
$ipbwiki_paypal[2] = '<form action="https://... - it's fast, free and secure!"></form>'
- will crash your wiki
Installation
- create a directory ipbwiki in the extensions directory
- place IpbWiki_PayPal.php in the extensions/ipbwiki directory (see code below)
- open the file LocalSettings.php, search for:
?>
and change this to:
require_once('extensions/ipbwiki/IpbWiki_PayPal.php'); // IpbWiki PayPal Extension
?>
- in the function wfPayPalExtension, place the code for your paypal-buttons in the variable $ipbwiki_paypal.
Usage
- the tag <paypal> is translated to the button defined in $ipbwiki_paypal[1].
- the tag <paypal>2</paypal> is translated to the button defined in $ipbwiki_paypal[2].
- the tag <paypal>2 description</paypal> is translated to the button defined in $ipbwiki_paypal[2], additionaly the text 'description' is placed next to the paypal button.
- the tag <paypal>description</paypal> is translated to the button defined in $ipbwiki_paypal[1], additionaly the text 'description' is placed next to the paypal button.
Donate
If you find this extension usefull, then perhaps you can donate a few bucks? ;) | Donate to the original author here |