1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: PayPal Shopping Cart |
---|
4 | Version: auto |
---|
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 | 1.0.7 26/03/2011 |
---|
54 | Add hu_HU language (Hungarian) thanks to samli |
---|
55 | |
---|
56 | */ |
---|
57 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
58 | |
---|
59 | global $prefixeTable; |
---|
60 | |
---|
61 | // +-----------------------------------------------------------------------+ |
---|
62 | // | Define plugin constants | |
---|
63 | // +-----------------------------------------------------------------------+ |
---|
64 | |
---|
65 | defined('PPPPP_ID') or define('PPPPP_ID', basename(dirname(__FILE__))); |
---|
66 | define('PPPPP_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
67 | define('PPPPP_SIZE_TABLE', $prefixeTable.'ppppp_size'); |
---|
68 | |
---|
69 | function ppppp_append_form($tpl_source, &$smarty){ |
---|
70 | $pattern = '#<.*\"infoTable\".*>#'; |
---|
71 | $replacement = ' |
---|
72 | <tr> |
---|
73 | <td class="label">{\'Buy this picture\'|@translate}</td> |
---|
74 | <td> |
---|
75 | <form name="ppppp_form" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" onSubmit="javascript:pppppValid()"> |
---|
76 | <input type="hidden" name="add" value="1"> |
---|
77 | <input type="hidden" name="cmd" value="_cart"> |
---|
78 | <input type="hidden" name="business" value="{$ppppp_e_mail}"> |
---|
79 | <input type="hidden" name="item_name"> |
---|
80 | <input type="hidden" name="no_shipping" value="2"><!-- shipping address mandatory --> |
---|
81 | <input type="hidden" name="handling_cart" value="{$ppppp_fixed_shipping}"> |
---|
82 | <input type="hidden" name="currency_code" value="{$ppppp_currency}"> |
---|
83 | <select name="amount"> |
---|
84 | {foreach from=$ppppp_array_size item=ppppp_row_size} |
---|
85 | <option value="{$ppppp_row_size.price}">{$ppppp_row_size.size} : {$ppppp_row_size.price} {$ppppp_currency}</option> |
---|
86 | {/foreach} |
---|
87 | <input type="submit" value="{\'Add to cart\'|@translate}"> |
---|
88 | </form> |
---|
89 | </td> |
---|
90 | <td> |
---|
91 | <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> |
---|
92 | <input type="hidden" name="cmd" value="_cart"> |
---|
93 | <input type="hidden" name="business" value="{$ppppp_e_mail}"> |
---|
94 | <input type="hidden" name="display" value="1"> |
---|
95 | <input type="hidden" name="no_shipping" value="2"> |
---|
96 | <input type=submit value="{\'View Shopping Cart\'|@translate}"> |
---|
97 | </form> |
---|
98 | </td> |
---|
99 | </tr> |
---|
100 | |
---|
101 | {literal} |
---|
102 | <script type="text/javascript"> |
---|
103 | function pppppValid(){ |
---|
104 | var amount=document.ppppp_form.amount; |
---|
105 | var selectedAmount=amount[amount.selectedIndex]; |
---|
106 | document.ppppp_form.item_name.value="Photo \"{/literal}{$current.TITLE}\", Ref {$INFO_FILE}, {\'Size\'|@translate} : {literal} "+selectedAmount.text; |
---|
107 | } |
---|
108 | </script> |
---|
109 | {/literal} |
---|
110 | '; |
---|
111 | if(!preg_match($pattern,$tpl_source)) { |
---|
112 | $pattern='#{if isset\(\$COMMENT_IMG\)}#'; |
---|
113 | $replacement='<table>'.$replacement.'</table>'; |
---|
114 | $replacement=$replacement.'$0'; |
---|
115 | } |
---|
116 | else |
---|
117 | $replacement='$0'.$replacement; |
---|
118 | return preg_replace($pattern, $replacement, $tpl_source,1); |
---|
119 | } |
---|
120 | |
---|
121 | function ppppp_picture_handler() |
---|
122 | { |
---|
123 | global $template, $conf, $page; |
---|
124 | |
---|
125 | if ($conf['PayPalShoppingCart']['apply_to_albums'] == 'list') |
---|
126 | { |
---|
127 | if (!isset($page['category'])) |
---|
128 | { |
---|
129 | return; |
---|
130 | } |
---|
131 | |
---|
132 | $query = ' |
---|
133 | SELECT |
---|
134 | paypal_active |
---|
135 | FROM '.CATEGORIES_TABLE.' |
---|
136 | WHERE id = '.$page['category']['id'].' |
---|
137 | ;'; |
---|
138 | list($paypal_active) = pwg_db_fetch_row(pwg_query($query)); |
---|
139 | |
---|
140 | if ('false' == $paypal_active) |
---|
141 | { |
---|
142 | return; |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | $template->set_prefilter('picture', 'ppppp_append_form'); |
---|
147 | load_language('plugin.lang', PPPPP_PATH); |
---|
148 | |
---|
149 | $query='SELECT * FROM '.PPPPP_SIZE_TABLE.' '.@$conf['PayPalShoppingCart_sizes_order_by'].';'; |
---|
150 | $result = pwg_query($query); |
---|
151 | while($row = pwg_db_fetch_assoc($result)) |
---|
152 | { |
---|
153 | $template->append('ppppp_array_size',$row); |
---|
154 | } |
---|
155 | |
---|
156 | $template->assign( |
---|
157 | array( |
---|
158 | 'ppppp_fixed_shipping' => $conf['PayPalShoppingCart']['fixed_shipping'], |
---|
159 | 'ppppp_currency' => $conf['PayPalShoppingCart']['currency'], |
---|
160 | 'ppppp_e_mail' => get_webmaster_mail_address(), |
---|
161 | ) |
---|
162 | ); |
---|
163 | } |
---|
164 | |
---|
165 | add_event_handler('loc_begin_picture', 'ppppp_picture_handler'); |
---|
166 | |
---|
167 | function ppppp_append_js($tpl_source, &$smarty){ |
---|
168 | load_language('plugin.lang', PPPPP_PATH); |
---|
169 | if(strstr($tpl_source,"{'Menu'|@translate}")==false) |
---|
170 | return $tpl_source; |
---|
171 | $pattern = '#{/foreach}#'; |
---|
172 | $replacement = '{/foreach} |
---|
173 | <li><a href="" title="'.l10n('View my PayPal Shopping Cart').'" onclick="document.forms[\'ppppp_form_view_cart\'].submit()">'.l10n('View Shopping Cart').'</a></li> |
---|
174 | <form name="ppppp_form_view_cart" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> |
---|
175 | <input type="hidden" name="cmd" value="_cart"> |
---|
176 | <input type="hidden" name="business" value="{$ppppp_e_mail}"> |
---|
177 | <input type="hidden" name="display" value="1"> |
---|
178 | <input type="hidden" name="no_shipping" value="2"> |
---|
179 | </form> |
---|
180 | '; |
---|
181 | return preg_replace($pattern, $replacement, $tpl_source); |
---|
182 | } |
---|
183 | |
---|
184 | function ppppp_index_handler(){ |
---|
185 | global $template; |
---|
186 | $template->set_prefilter('menubar', 'ppppp_append_js'); |
---|
187 | $template->assign('ppppp_e_mail',get_webmaster_mail_address()); |
---|
188 | } |
---|
189 | |
---|
190 | add_event_handler('loc_begin_index', 'ppppp_index_handler'); |
---|
191 | |
---|
192 | function ppppp_admin_menu($menu){ |
---|
193 | load_language('plugin.lang', PPPPP_PATH); |
---|
194 | array_push($menu, array( |
---|
195 | 'NAME' => l10n('PayPal Shopping Cart'), |
---|
196 | 'URL' => get_admin_plugin_menu_link(PPPPP_PATH . 'admin.php'))); |
---|
197 | return $menu; |
---|
198 | } |
---|
199 | |
---|
200 | add_event_handler('get_admin_plugin_menu_links', 'ppppp_admin_menu'); |
---|
201 | |
---|
202 | add_event_handler('init', 'ppppp_init'); |
---|
203 | /** |
---|
204 | * plugin initialization |
---|
205 | * - unserialize configuration |
---|
206 | * - load language |
---|
207 | */ |
---|
208 | function ppppp_init() |
---|
209 | { |
---|
210 | global $conf; |
---|
211 | |
---|
212 | // load plugin language file |
---|
213 | load_language('plugin.lang', PPPPP_PATH); |
---|
214 | |
---|
215 | // prepare plugin configuration |
---|
216 | $conf['PayPalShoppingCart'] = safe_unserialize($conf['PayPalShoppingCart']); |
---|
217 | } |
---|
218 | ?> |
---|