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 | define('PPPPP_CONFIG_TABLE', $prefixeTable.'ppppp_config'); |
---|
69 | define('PPPPP_VERSION', 'auto'); |
---|
70 | |
---|
71 | |
---|
72 | function ppppp_append_form($tpl_source, &$smarty){ |
---|
73 | $pattern = '#<.*\"infoTable\".*>#'; |
---|
74 | $replacement = ' |
---|
75 | <tr> |
---|
76 | <td class="label">{\'Buy this picture\'|@translate}</td> |
---|
77 | <td> |
---|
78 | <form name="ppppp_form" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" onSubmit="javascript:pppppValid()"> |
---|
79 | <input type="hidden" name="add" value="1"> |
---|
80 | <input type="hidden" name="cmd" value="_cart"> |
---|
81 | <input type="hidden" name="business" value="{$ppppp_e_mail}"> |
---|
82 | <input type="hidden" name="item_name"> |
---|
83 | <input type="hidden" name="no_shipping" value="2"><!-- shipping address mandatory --> |
---|
84 | <input type="hidden" name="handling_cart" value="{$ppppp_fixed_shipping}"> |
---|
85 | <input type="hidden" name="currency_code" value="{$ppppp_currency}"> |
---|
86 | <select name="amount"> |
---|
87 | {foreach from=$ppppp_array_size item=ppppp_row_size} |
---|
88 | <option value="{$ppppp_row_size.price}">{$ppppp_row_size.size} : {$ppppp_row_size.price} {$ppppp_currency}</option> |
---|
89 | {/foreach} |
---|
90 | <input type="submit" value="{\'Add to cart\'|@translate}"> |
---|
91 | </form> |
---|
92 | </td> |
---|
93 | <td> |
---|
94 | <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> |
---|
95 | <input type="hidden" name="cmd" value="_cart"> |
---|
96 | <input type="hidden" name="business" value="{$ppppp_e_mail}"> |
---|
97 | <input type="hidden" name="display" value="1"> |
---|
98 | <input type="hidden" name="no_shipping" value="2"> |
---|
99 | <input type=submit value="{\'View Shopping Cart\'|@translate}"> |
---|
100 | </form> |
---|
101 | </td> |
---|
102 | </tr> |
---|
103 | |
---|
104 | {literal} |
---|
105 | <script type="text/javascript"> |
---|
106 | function pppppValid(){ |
---|
107 | var amount=document.ppppp_form.amount; |
---|
108 | var selectedAmount=amount[amount.selectedIndex]; |
---|
109 | document.ppppp_form.item_name.value="Photo \"{/literal}{$current.TITLE}\", Ref {$INFO_FILE}, {\'Size\'|@translate} : {literal} "+selectedAmount.text; |
---|
110 | } |
---|
111 | </script> |
---|
112 | {/literal} |
---|
113 | '; |
---|
114 | if(!preg_match($pattern,$tpl_source)) { |
---|
115 | $pattern='#{if isset\(\$COMMENT_IMG\)}#'; |
---|
116 | $replacement='<table>'.$replacement.'</table>'; |
---|
117 | $replacement=$replacement.'$0'; |
---|
118 | } |
---|
119 | else |
---|
120 | $replacement='$0'.$replacement; |
---|
121 | return preg_replace($pattern, $replacement, $tpl_source,1); |
---|
122 | } |
---|
123 | |
---|
124 | function ppppp_picture_handler(){ |
---|
125 | global $template, $conf, $page; |
---|
126 | |
---|
127 | if ($conf['PayPalShoppingCart']['apply_to_albums'] == 'list') |
---|
128 | { |
---|
129 | if (!isset($page['category'])) |
---|
130 | { |
---|
131 | return; |
---|
132 | } |
---|
133 | |
---|
134 | $query = ' |
---|
135 | SELECT |
---|
136 | paypal_active |
---|
137 | FROM '.CATEGORIES_TABLE.' |
---|
138 | WHERE id = '.$page['category']['id'].' |
---|
139 | ;'; |
---|
140 | list($paypal_active) = pwg_db_fetch_row(pwg_query($query)); |
---|
141 | |
---|
142 | if ('false' == $paypal_active) |
---|
143 | { |
---|
144 | return; |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | $template->set_prefilter('picture', 'ppppp_append_form'); |
---|
149 | load_language('plugin.lang', PPPPP_PATH); |
---|
150 | $query='SELECT * FROM '.PPPPP_SIZE_TABLE.' '.@$conf['PayPalShoppingCart_sizes_order_by'].';'; |
---|
151 | $result = pwg_query($query); |
---|
152 | while($row = pwg_db_fetch_assoc($result)){ |
---|
153 | $template->append('ppppp_array_size',$row); |
---|
154 | } |
---|
155 | $query='SELECT value FROM '.PPPPP_CONFIG_TABLE.' WHERE param = \'fixed_shipping\';'; |
---|
156 | $result = pwg_query($query); |
---|
157 | $row = pwg_db_fetch_row($result); |
---|
158 | $template->assign('ppppp_fixed_shipping',$row[0]); |
---|
159 | $query='SELECT value FROM '.PPPPP_CONFIG_TABLE.' WHERE param = \'currency\';'; |
---|
160 | $result = pwg_query($query); |
---|
161 | $row = pwg_db_fetch_row($result); |
---|
162 | $template->assign('ppppp_currency',$row[0]); |
---|
163 | |
---|
164 | $template->assign('ppppp_e_mail',get_webmaster_mail_address()); |
---|
165 | } |
---|
166 | |
---|
167 | add_event_handler('loc_begin_picture', 'ppppp_picture_handler'); |
---|
168 | |
---|
169 | function ppppp_append_js($tpl_source, &$smarty){ |
---|
170 | load_language('plugin.lang', PPPPP_PATH); |
---|
171 | if(strstr($tpl_source,"{'Menu'|@translate}")==false) |
---|
172 | return $tpl_source; |
---|
173 | $pattern = '#{/foreach}#'; |
---|
174 | $replacement = '{/foreach} |
---|
175 | <li><a href="" title="'.l10n('View my PayPal Shopping Cart').'" onclick="document.forms[\'ppppp_form_view_cart\'].submit()">'.l10n('View Shopping Cart').'</a></li> |
---|
176 | <form name="ppppp_form_view_cart" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> |
---|
177 | <input type="hidden" name="cmd" value="_cart"> |
---|
178 | <input type="hidden" name="business" value="{$ppppp_e_mail}"> |
---|
179 | <input type="hidden" name="display" value="1"> |
---|
180 | <input type="hidden" name="no_shipping" value="2"> |
---|
181 | </form> |
---|
182 | '; |
---|
183 | return preg_replace($pattern, $replacement, $tpl_source); |
---|
184 | } |
---|
185 | |
---|
186 | function ppppp_index_handler(){ |
---|
187 | global $template; |
---|
188 | $template->set_prefilter('menubar', 'ppppp_append_js'); |
---|
189 | $template->assign('ppppp_e_mail',get_webmaster_mail_address()); |
---|
190 | } |
---|
191 | |
---|
192 | add_event_handler('loc_begin_index', 'ppppp_index_handler'); |
---|
193 | |
---|
194 | function ppppp_admin_menu($menu){ |
---|
195 | load_language('plugin.lang', PPPPP_PATH); |
---|
196 | array_push($menu, array( |
---|
197 | 'NAME' => l10n('PayPal Shopping Cart'), |
---|
198 | 'URL' => get_admin_plugin_menu_link(PPPPP_PATH . 'admin.php'))); |
---|
199 | return $menu; |
---|
200 | } |
---|
201 | |
---|
202 | add_event_handler('get_admin_plugin_menu_links', 'ppppp_admin_menu'); |
---|
203 | |
---|
204 | add_event_handler('init', 'ppppp_init'); |
---|
205 | /** |
---|
206 | * plugin initialization |
---|
207 | * - check for upgrades |
---|
208 | * - unserialize configuration |
---|
209 | * - load language |
---|
210 | */ |
---|
211 | function ppppp_init() |
---|
212 | { |
---|
213 | global $conf, $pwg_loaded_plugins; |
---|
214 | |
---|
215 | // apply upgrade if needed |
---|
216 | if ( |
---|
217 | PPPPP_VERSION == 'auto' or |
---|
218 | $pwg_loaded_plugins[PPPPP_ID]['version'] == 'auto' or |
---|
219 | version_compare($pwg_loaded_plugins[PPPPP_ID]['version'], PPPPP_VERSION, '<') |
---|
220 | ) |
---|
221 | { |
---|
222 | // call install function |
---|
223 | include_once(PPPPP_PATH.'include/install.inc.php'); |
---|
224 | ppppp_install(); |
---|
225 | |
---|
226 | // update plugin version in database |
---|
227 | if ( $pwg_loaded_plugins[PPPPP_ID]['version'] != 'auto' and PPPPP_VERSION != 'auto' ) |
---|
228 | { |
---|
229 | $query = ' |
---|
230 | UPDATE '. PLUGINS_TABLE .' |
---|
231 | SET version = "'. PPPPP_VERSION .'" |
---|
232 | WHERE id = "'. PPPPP_ID .'"'; |
---|
233 | pwg_query($query); |
---|
234 | |
---|
235 | $pwg_loaded_plugins[PPPPP_ID]['version'] = PPPPP_VERSION; |
---|
236 | |
---|
237 | if (defined('IN_ADMIN')) |
---|
238 | { |
---|
239 | $_SESSION['page_infos'][] = 'PayPalShoppingCart plugin updated to version '. PPPPP_VERSION; |
---|
240 | } |
---|
241 | } |
---|
242 | } |
---|
243 | |
---|
244 | // load plugin language file |
---|
245 | load_language('plugin.lang', PPPPP_PATH); |
---|
246 | |
---|
247 | // prepare plugin configuration |
---|
248 | $conf['PayPalShoppingCart'] = unserialize($conf['PayPalShoppingCart']); |
---|
249 | } |
---|
250 | ?> |
---|