1<?php
2/*
3 * DokuWiki paypal plugin
4 * Author : Zahno Silvan
5 * Usage:
6 * {{paypal>encrypted_value}}
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the LGNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * LGNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the LGNU Lesser General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 */
22
23
24if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
25if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
26require_once(DOKU_PLUGIN.'syntax.php');
27
28/**
29 * All DokuWiki plugins to extend the parser/rendering mechanism
30 * need to inherit from this class
31 */
32class syntax_plugin_paypal extends DokuWiki_Syntax_Plugin {
33
34    /**
35     * return some info
36     */
37    function getInfo(){
38        return array(
39            'author' => 'Zahno Silvan',
40            'email'  => 'zaswiki@gmail.com',
41            'date'   => '2011-02-17',
42            'name'   => 'Paypal Plugin',
43            'desc'   => 'Embedding PayPal Donation Button',
44            'url'    => 'http://zawiki.zapto.org/doku.php/tschinz:dw_paypal',
45        );
46    }
47
48    /**
49     * What kind of syntax are we?
50     */
51    function getType(){
52        return 'substition';
53    }
54
55    /**
56     * Where to sort in?
57     */
58    function getSort(){
59        return 299;
60    }
61
62
63    /**
64     * Connect pattern to lexer
65     */
66    function connectTo($mode) {
67      $this->Lexer->addSpecialPattern('\{\{paypal>.*?\}\}',$mode,'plugin_paypal');
68    }
69
70    /**
71     * Handle the match
72     */
73    function handle($match, $state, $pos, &$handler){
74        switch ($state) {
75          case DOKU_LEXER_ENTER :
76            break;
77          case DOKU_LEXER_MATCHED :
78            break;
79          case DOKU_LEXER_UNMATCHED :
80            break;
81          case DOKU_LEXER_EXIT :
82            break;
83          case DOKU_LEXER_SPECIAL :
84            return $match;
85            break;
86        }
87        return array();
88    }
89
90    /**
91     * Create output
92     */
93    function render($mode, &$renderer, $data) {
94        if($mode == 'xhtml'){
95			// strip {{paypal> from start
96			$data = substr($data,9);
97            // strip }} from end
98			$data = substr($data,0,-2);
99			$encrypted_value = $data;
100
101			if (empty($encrypted_value))
102			{
103				$renderer->doc .= 'No encrypted value given';
104				return true;
105			}
106
107			$renderer->doc .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">';
108			$renderer->doc .= '<input type="hidden" name="cmd" value="_s-xclick">';
109			$renderer->doc .= '<input type="hidden" name="encrypted" value="'.$encrypted_value.'">';
110			$renderer->doc .= '<input type="image" src="https://www.paypal.com/en_US/CH/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">';
111			$renderer->doc .= '<img alt="" border="0" src="https://www.paypal.com/de_DE/i/scr/pixel.gif" width="1" height="1">';
112			$renderer->doc .= '</form>';
113
114            return true;
115        }
116        return false;
117    }
118}
119