1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: PayPal Shopping Cart |
---|
4 | Version: 1.0.7 |
---|
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 | define('PPPPP_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
59 | include_once (PPPPP_PATH.'/constants.php'); |
---|
60 | |
---|
61 | function ppppp_append_form($tpl_source, &$smarty){ |
---|
62 | $pattern = '#<.*\"infoTable\".*>#'; |
---|
63 | $replacement = ' |
---|
64 | <tr> |
---|
65 | <td class="label">{\'Buy this picture\'|@translate}</td> |
---|
66 | <td> |
---|
67 | <form name="ppppp_form" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" onSubmit="javascript:pppppValid()"> |
---|
68 | <input type="hidden" name="add" value="1"> |
---|
69 | <input type="hidden" name="cmd" value="_cart"> |
---|
70 | <input type="hidden" name="business" value="{$ppppp_e_mail}"> |
---|
71 | <input type="hidden" name="item_name"> |
---|
72 | <input type="hidden" name="no_shipping" value="2"><!-- shipping address mandatory --> |
---|
73 | <input type="hidden" name="handling_cart" value="{$ppppp_fixed_shipping}"> |
---|
74 | <input type="hidden" name="currency_code" value="{$ppppp_currency}"> |
---|
75 | <select name="amount"> |
---|
76 | {foreach from=$ppppp_array_size item=ppppp_row_size} |
---|
77 | <option value="{$ppppp_row_size.price}">{$ppppp_row_size.size} : {$ppppp_row_size.price} {$ppppp_currency}</option> |
---|
78 | {/foreach} |
---|
79 | <input type="submit" value="{\'Add to cart\'|@translate}"> |
---|
80 | </form> |
---|
81 | </td> |
---|
82 | <td> |
---|
83 | <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> |
---|
84 | <input type="hidden" name="cmd" value="_cart"> |
---|
85 | <input type="hidden" name="business" value="{$ppppp_e_mail}"> |
---|
86 | <input type="hidden" name="display" value="1"> |
---|
87 | <input type="hidden" name="no_shipping" value="2"> |
---|
88 | <input type=submit value="{\'View Shopping Cart\'|@translate}"> |
---|
89 | </form> |
---|
90 | </td> |
---|
91 | </tr> |
---|
92 | |
---|
93 | {literal} |
---|
94 | <script type="text/javascript"> |
---|
95 | function pppppValid(){ |
---|
96 | var amount=document.ppppp_form.amount; |
---|
97 | var selectedAmount=amount[amount.selectedIndex]; |
---|
98 | document.ppppp_form.item_name.value="Photo \"{/literal}{$current.TITLE}\", Ref {$INFO_FILE}, {\'Size\'|@translate} : {literal} "+selectedAmount.text; |
---|
99 | } |
---|
100 | </script> |
---|
101 | {/literal} |
---|
102 | '; |
---|
103 | if(!preg_match($pattern,$tpl_source)) { |
---|
104 | $pattern='#{if isset\(\$COMMENT_IMG\)}#'; |
---|
105 | $replacement='<table>'.$replacement.'</table>'; |
---|
106 | $replacement=$replacement.'$0'; |
---|
107 | } |
---|
108 | else |
---|
109 | $replacement='$0'.$replacement; |
---|
110 | return preg_replace($pattern, $replacement, $tpl_source,1); |
---|
111 | } |
---|
112 | |
---|
113 | function ppppp_picture_handler(){ |
---|
114 | global $template; |
---|
115 | $template->set_prefilter('picture', 'ppppp_append_form'); |
---|
116 | load_language('plugin.lang', PPPPP_PATH); |
---|
117 | $query='SELECT * FROM '.PPPPP_SIZE_TABLE.';'; |
---|
118 | $result = pwg_query($query); |
---|
119 | while($row = mysql_fetch_array($result)){ |
---|
120 | $template->append('ppppp_array_size',$row); |
---|
121 | } |
---|
122 | $query='SELECT value FROM '.PPPPP_CONFIG_TABLE.' WHERE param = \'fixed_shipping\';'; |
---|
123 | $result = pwg_query($query); |
---|
124 | $row = mysql_fetch_array($result); |
---|
125 | $template->assign('ppppp_fixed_shipping',$row[0]); |
---|
126 | $query='SELECT value FROM '.PPPPP_CONFIG_TABLE.' WHERE param = \'currency\';'; |
---|
127 | $result = pwg_query($query); |
---|
128 | $row = mysql_fetch_array($result); |
---|
129 | $template->assign('ppppp_currency',$row[0]); |
---|
130 | |
---|
131 | $template->assign('ppppp_e_mail',get_webmaster_mail_address()); |
---|
132 | $template->append('footer_elements',' - PayPal plugin by <a href=http://www.queguineur.fr>queguineur.fr</a>'); |
---|
133 | } |
---|
134 | |
---|
135 | add_event_handler('loc_begin_picture', 'ppppp_picture_handler'); |
---|
136 | |
---|
137 | function ppppp_append_js($tpl_source, &$smarty){ |
---|
138 | load_language('plugin.lang', PPPPP_PATH); |
---|
139 | if(strstr($tpl_source,"{'Menu'|@translate}")==false) |
---|
140 | return $tpl_source; |
---|
141 | $pattern = '#{/foreach}#'; |
---|
142 | $replacement = '{/foreach} |
---|
143 | <li><a href="" title="'.l10n('View my PayPal Shopping Cart').'" onclick="document.forms[\'ppppp_form_view_cart\'].submit()">'.l10n('View Shopping Cart').'</a></li> |
---|
144 | <form name="ppppp_form_view_cart" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> |
---|
145 | <input type="hidden" name="cmd" value="_cart"> |
---|
146 | <input type="hidden" name="business" value="{$ppppp_e_mail}"> |
---|
147 | <input type="hidden" name="display" value="1"> |
---|
148 | <input type="hidden" name="no_shipping" value="2"> |
---|
149 | </form> |
---|
150 | '; |
---|
151 | return preg_replace($pattern, $replacement, $tpl_source); |
---|
152 | } |
---|
153 | |
---|
154 | function ppppp_index_handler(){ |
---|
155 | global $template; |
---|
156 | $template->set_prefilter('menubar', 'ppppp_append_js'); |
---|
157 | $template->assign('ppppp_e_mail',get_webmaster_mail_address()); |
---|
158 | } |
---|
159 | |
---|
160 | add_event_handler('loc_begin_index', 'ppppp_index_handler'); |
---|
161 | |
---|
162 | function ppppp_admin_menu($menu){ |
---|
163 | load_language('plugin.lang', PPPPP_PATH); |
---|
164 | array_push($menu, array( |
---|
165 | 'NAME' => l10n('PayPal Shopping Cart'), |
---|
166 | 'URL' => get_admin_plugin_menu_link(PPPPP_PATH . 'admin.php'))); |
---|
167 | return $menu; |
---|
168 | } |
---|
169 | |
---|
170 | add_event_handler('get_admin_plugin_menu_links', 'ppppp_admin_menu'); |
---|
171 | ?> |
---|