1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: PayPal Shopping Cart |
---|
4 | Version: 1.0.6 |
---|
5 | Description: Append PayPal Shopping Cart on Piwigo to sell photos |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=499 |
---|
7 | Author: queguineur.fr |
---|
8 | Author URI: http://www.queguineur.fr |
---|
9 | */ |
---|
10 | /* |
---|
11 | Plugin Panier PayPal Pour Piwigo |
---|
12 | Copyright (C) 2011 www.queguineur.fr Tous droits réservés. |
---|
13 | |
---|
14 | Ce programme est un logiciel libre ; vous pouvez le redistribuer ou le |
---|
15 | modifier suivant les termes de la GNU General Public License telle que |
---|
16 | publiée par la Free Software Foundation : soit la version 3 de cette |
---|
17 | licence, soit (à votre gré) toute version ultérieure. |
---|
18 | |
---|
19 | Ce programme est distribué dans lespoir quil vous sera utile, mais SANS |
---|
20 | AUCUNE GARANTIE : sans même la garantie implicite de COMMERCIALISABILITÉ |
---|
21 | ni dADÉQUATION À UN OBJECTIF PARTICULIER. Consultez la Licence Générale |
---|
22 | Publique GNU pour plus de détails. |
---|
23 | |
---|
24 | Vous devriez avoir reçu une copie de la Licence Générale Publique GNU avec |
---|
25 | ce programme ; si ce nest pas le cas, consultez : |
---|
26 | <http://www.gnu.org/licenses/>. |
---|
27 | */ |
---|
28 | /* |
---|
29 | Historique |
---|
30 | 1.0.0 10/02/2011 |
---|
31 | Version initiale |
---|
32 | |
---|
33 | 1.0.1 10/02/2011 |
---|
34 | Ajout du Plugin URI pour permettre les mises à jours |
---|
35 | Traduction en Anglais du Plugin Name et du nom du répertoire |
---|
36 | |
---|
37 | 1.0.2 10/02/2011 |
---|
38 | Correction du problème de compatibilité avec exif view (double affichage des boutons) |
---|
39 | |
---|
40 | 1.0.3 15/02/2011 |
---|
41 | Add lv_LV (Latvian) thanks to Aivars Baldone |
---|
42 | |
---|
43 | 1.0.4 17/02/2011 |
---|
44 | Add de_DE and it_IT (par Sugar888) |
---|
45 | |
---|
46 | 1.0.5 27/02/2011 |
---|
47 | Correction pb compatibilité avec certains thèmes |
---|
48 | Déplacement des boutons PayPal en début de table info |
---|
49 | |
---|
50 | 1.0.6 05/03/2011 |
---|
51 | Add sk_SK (by dodo) |
---|
52 | |
---|
53 | */ |
---|
54 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
55 | define('PPPPP_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
56 | include_once (PPPPP_PATH.'/constants.php'); |
---|
57 | |
---|
58 | function ppppp_append_form($tpl_source, &$smarty){ |
---|
59 | $pattern = '#<.*\"infoTable\".*>#'; |
---|
60 | $replacement = ' |
---|
61 | <tr> |
---|
62 | <td class="label">{\'Buy this picture\'|@translate}</td> |
---|
63 | <td> |
---|
64 | <form name="ppppp_form" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" onSubmit="javascript:pppppValid()"> |
---|
65 | <input type="hidden" name="add" value="1"> |
---|
66 | <input type="hidden" name="cmd" value="_cart"> |
---|
67 | <input type="hidden" name="business" value="{$ppppp_e_mail}"> |
---|
68 | <input type="hidden" name="item_name"> |
---|
69 | <input type="hidden" name="no_shipping" value="2"><!-- shipping address mandatory --> |
---|
70 | <input type="hidden" name="handling_cart" value="{$ppppp_fixed_shipping}"> |
---|
71 | <input type="hidden" name="currency_code" value="{$ppppp_currency}"> |
---|
72 | <select name="amount"> |
---|
73 | {foreach from=$ppppp_array_size item=ppppp_row_size} |
---|
74 | <option value="{$ppppp_row_size.price}">{$ppppp_row_size.size} : {$ppppp_row_size.price} {$ppppp_currency}</option> |
---|
75 | {/foreach} |
---|
76 | <input type="submit" value="{\'Add to cart\'|@translate}"> |
---|
77 | </form> |
---|
78 | </td> |
---|
79 | <td> |
---|
80 | <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> |
---|
81 | <input type="hidden" name="cmd" value="_cart"> |
---|
82 | <input type="hidden" name="business" value="{$ppppp_e_mail}"> |
---|
83 | <input type="hidden" name="display" value="1"> |
---|
84 | <input type="hidden" name="no_shipping" value="2"> |
---|
85 | <input type=submit value="{\'View Shopping Cart\'|@translate}"> |
---|
86 | </form> |
---|
87 | </td> |
---|
88 | </tr> |
---|
89 | |
---|
90 | {literal} |
---|
91 | <script type="text/javascript"> |
---|
92 | function pppppValid(){ |
---|
93 | var amount=document.ppppp_form.amount; |
---|
94 | var selectedAmount=amount[amount.selectedIndex]; |
---|
95 | document.ppppp_form.item_name.value="Photo \"{/literal}{$current.TITLE}\", Ref {$INFO_FILE}, {\'Size\'|@translate} : {literal} "+selectedAmount.text; |
---|
96 | } |
---|
97 | </script> |
---|
98 | {/literal} |
---|
99 | '; |
---|
100 | if(!preg_match($pattern,$tpl_source)) { |
---|
101 | $pattern='#{if isset\(\$COMMENT_IMG\)}#'; |
---|
102 | $replacement='<table>'.$replacement.'</table>'; |
---|
103 | $replacement=$replacement.'$0'; |
---|
104 | } |
---|
105 | else |
---|
106 | $replacement='$0'.$replacement; |
---|
107 | return preg_replace($pattern, $replacement, $tpl_source,1); |
---|
108 | } |
---|
109 | |
---|
110 | function ppppp_picture_handler(){ |
---|
111 | global $template; |
---|
112 | $template->set_prefilter('picture', 'ppppp_append_form'); |
---|
113 | load_language('plugin.lang', PPPPP_PATH); |
---|
114 | $query='SELECT * FROM '.PPPPP_SIZE_TABLE.';'; |
---|
115 | $result = pwg_query($query); |
---|
116 | while($row = mysql_fetch_array($result)){ |
---|
117 | $template->append('ppppp_array_size',$row); |
---|
118 | } |
---|
119 | $query='SELECT value FROM '.PPPPP_CONFIG_TABLE.' WHERE param = \'fixed_shipping\';'; |
---|
120 | $result = pwg_query($query); |
---|
121 | $row = mysql_fetch_array($result); |
---|
122 | $template->assign('ppppp_fixed_shipping',$row[0]); |
---|
123 | $query='SELECT value FROM '.PPPPP_CONFIG_TABLE.' WHERE param = \'currency\';'; |
---|
124 | $result = pwg_query($query); |
---|
125 | $row = mysql_fetch_array($result); |
---|
126 | $template->assign('ppppp_currency',$row[0]); |
---|
127 | |
---|
128 | $template->assign('ppppp_e_mail',get_webmaster_mail_address()); |
---|
129 | $template->append('footer_elements',' - PayPal plugin by <a href=http://www.queguineur.fr>queguineur.fr</a>'); |
---|
130 | } |
---|
131 | |
---|
132 | add_event_handler('loc_begin_picture', 'ppppp_picture_handler'); |
---|
133 | |
---|
134 | function ppppp_append_js($tpl_source, &$smarty){ |
---|
135 | load_language('plugin.lang', PPPPP_PATH); |
---|
136 | if(strstr($tpl_source,"{'Menu'|@translate}")==false) |
---|
137 | return $tpl_source; |
---|
138 | $pattern = '#{/foreach}#'; |
---|
139 | $replacement = '{/foreach} |
---|
140 | <li><a href="" title="'.l10n('View my PayPal Shopping Cart').'" onclick="document.forms[\'ppppp_form_view_cart\'].submit()">'.l10n('View Shopping Cart').'</a></li> |
---|
141 | <form name="ppppp_form_view_cart" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> |
---|
142 | <input type="hidden" name="cmd" value="_cart"> |
---|
143 | <input type="hidden" name="business" value="{$ppppp_e_mail}"> |
---|
144 | <input type="hidden" name="display" value="1"> |
---|
145 | <input type="hidden" name="no_shipping" value="2"> |
---|
146 | </form> |
---|
147 | '; |
---|
148 | return preg_replace($pattern, $replacement, $tpl_source); |
---|
149 | } |
---|
150 | |
---|
151 | function ppppp_index_handler(){ |
---|
152 | global $template; |
---|
153 | $template->set_prefilter('menubar', 'ppppp_append_js'); |
---|
154 | $template->assign('ppppp_e_mail',get_webmaster_mail_address()); |
---|
155 | } |
---|
156 | |
---|
157 | add_event_handler('loc_begin_index', 'ppppp_index_handler'); |
---|
158 | |
---|
159 | function ppppp_admin_menu($menu){ |
---|
160 | load_language('plugin.lang', PPPPP_PATH); |
---|
161 | array_push($menu, array( |
---|
162 | 'NAME' => l10n('PayPal Shopping Cart'), |
---|
163 | 'URL' => get_admin_plugin_menu_link(PPPPP_PATH . 'admin.php'))); |
---|
164 | return $menu; |
---|
165 | } |
---|
166 | |
---|
167 | add_event_handler('get_admin_plugin_menu_links', 'ppppp_admin_menu'); |
---|
168 | ?> |
---|