forked from leegarner-glfusion/paypal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.inc
1804 lines (1524 loc) · 51.8 KB
/
functions.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* glFusion API functions for the Paypal plugin.
* Based on the gl-paypal Plugin for Geeklog CMS by Vincent Furia.
*
* @author Lee Garner <lee@leegarner.com>
* @author Vincent Furia <vinny01@users.sourceforge.net
* @copyright Copyright (c) 2009-2016 Lee Garner
* @copyright Copyright (c) 2005-2006 Vincent Furia
* @package paypal
* @version 0.5.7
* @license http://opensource.org/licenses/gpl-2.0.php
* GNU Public License v2 or later
* @filesource
*/
// this file can't be used on its own
if (!defined ('GVERSION')) {
die ('This file can not be used on its own.');
}
/** Include the system configuration class */
require_once $_CONF['path_system'] . 'classes/config.class.php';
$pp_config = config::get_instance();
$_PP_CONF= $pp_config->get_config('paypal');
/** Include paypal config file */
require_once dirname(__FILE__) . '/paypal.php';
$_PP_CONF['datetime_fmt'] = 'Y-m-d H:i:s T';
/** Define base path to plugin */
define('PAYPAL_PI_PATH', "{$_CONF['path']}plugins/{$_PP_CONF['pi_name']}");
/** Define base URL to plugin */
define('PAYPAL_URL', "{$_CONF['site_url']}/{$_PP_CONF['pi_name']}");
/** Define URL to plugin admin interface */
define('PAYPAL_ADMIN_URL',
"{$_CONF['site_admin_url']}/plugins/{$_PP_CONF['pi_name']}");
// Define product types
define('PP_PROD_PHYSICAL', 1);
define('PP_PROD_DOWNLOAD', 2);
define('PP_PROD_VIRTUAL', 4);
// Define comment status
define('PP_COMMENTS_ENABLED', 0);
define('PP_COMMENTS_CLOSED' , 1);
define('PP_COMMENTS_DISABLED', 2);
// Order status codes
define('PP_STATUS_OPEN', 0);
define('PP_STATUS_PAID', 1);
/** Define the main $_SESSION variable name. We store things like the
* shopping cart ID and previous/next page views here. */
define('PP_CART_VAR', 'glPPcart');
if (file_exists(PAYPAL_PI_PATH . '/config.php')) {
/** Include local configuration overrides */
include_once PAYPAL_PI_PATH . '/config.php';
}
// Load the site's language file, falling back to English.
$langpath = PAYPAL_PI_PATH . '/language';
$langfile = "{$_CONF['language']}.php";
if (!is_file("$langpath/$langfile")) {
$langfile = 'english.php';
}
/** Include the proper language file */
require_once "$langpath/$langfile";
if (is_file("$langpath/custom/$langfile")) {
/** Include the custom language file, if any */
include_once "$langpath/custom/$langfile";
}
// Set user ID = 1 for anonymous users.
if (empty($_USER['uid']) || $_USER['uid'] < 2) {
$_USER['uid'] = 1;
$_USER['username'] = 'anonymous';
$_USER['fullname'] = 'Anonymous';
}
/** Import plugin-specific functions */
function USES_paypal_functions()
{ require_once PAYPAL_PI_PATH . '/paypal_functions.inc.php'; }
/** Import product class */
function USES_paypal_class_product()
{ require_once PAYPAL_PI_PATH . '/classes/product.class.php'; }
/** Import category class */
function USES_paypal_class_category()
{ require_once PAYPAL_PI_PATH . '/classes/category.class.php'; }
/** Import CSS-based menu */
function USES_paypal_class_menu()
{ require_once PAYPAL_PI_PATH . '/classes/menu.class.php'; }
/** Import IPN handler class.
* Imports only the required IPN class.
*
* @param string $gateway Gateway being used.
*/
function USES_paypal_class_ipn($gateway='paypal')
{
$filename = PAYPAL_PI_PATH . '/classes/ipn/' . $gateway . '_ipn.class.php';
if (is_file($filename))
require_once $filename;
}
/** Import image handling class for products */
function USES_paypal_class_productimage()
{ require_once PAYPAL_PI_PATH . '/classes/ProductImage.class.php'; }
/** Import image handling class for categories */
function USES_paypal_class_categoryimage()
{ require_once PAYPAL_PI_PATH . '/classes/CategoryImage.class.php'; }
/** Import image handling class for categories */
function USES_paypal_class_attribute()
{ require_once PAYPAL_PI_PATH . '/classes/attribute.class.php'; }
/** Import file upload handling class */
function USES_paypal_class_ppFile()
{ require_once PAYPAL_PI_PATH . '/classes/ppFile.class.php'; }
/** Import shopping cart class */
function USES_paypal_class_cart()
{ require_once PAYPAL_PI_PATH . '/classes/cart.class.php'; }
/** Import user information class */
function USES_paypal_class_userinfo()
{ require_once PAYPAL_PI_PATH . '/classes/UserInfo.class.php'; }
/** Import order class */
function USES_paypal_class_order()
{ require_once PAYPAL_PI_PATH . '/classes/order.class.php'; }
/** Upgrade functions */
function USES_paypal_upgrade()
{ require_once PAYPAL_PI_PATH . '/upgrade.inc.php'; }
/** Import workflow handling */
function USES_paypal_class_workflow()
{ require_once PAYPAL_PI_PATH . '/classes/workflow.class.php'; }
/** Import order status workflow handling */
function USES_paypal_class_orderstatus()
{ require_once PAYPAL_PI_PATH . '/classes/orderstatus.class.php'; }
/** Import currency class */
function USES_paypal_class_currency()
{ require_once PAYPAL_PI_PATH . '/classes/currency.class.php'; }
/** Define global configuration variable to hold payment gateways */
$_PP_CONF['gateways'] = array();
/** Store the current SQL-formatted timestamp since it's used often */
USES_class_date();
$_PP_CONF['now'] = new Date('now', $_CONF['timezone']);
global $ppGCart;
$ppGCart = NULL;
function PAYPAL_setCart()
{
global $ppGCart;
if ($ppGCart === NULL) {
USES_paypal_class_cart();
$ppGCart = new ppCart();
}
}
/**
* Import a single payment gateway.
* This function imports the requested gateway, regardless of whether
* it's enabled in the configuration.
* If the gateway name is omitted, then only the base class is imported.
*
* @param string $gw_name Name of gateway (class file) to import
* @return boolean True on success, False on failure
*/
function USES_paypal_gateway($gw_name='')
{
if ($gw_name == '') {
$classfile = PAYPAL_PI_PATH . '/classes/paymentgw.class.php';
} else {
$classfile = PAYPAL_PI_PATH . '/classes/gateways/' .
$gw_name . '.class.php';
}
if (is_file($classfile)) {
require_once $classfile;
return true;
} else {
return false;
}
}
/**
* Import the payment gateways.
*
* All installed gateways can be loaded (for administration), or only
* the enabled gateways can be loaded (the default).
*
* @param boolean $all True to get all gateways, False for only enabled
*/
function PAYPAL_loadGateways($all = false)
{
global $_PP_CONF, $_TABLES;
// Might be called multiple times, only needs to populate the array once.
if (!empty($_PP_CONF['gateways'])) {
return;
}
// Include the base gateway class
require_once PAYPAL_PI_PATH . '/classes/paymentgw.class.php';
// Load the enabled gateways
$sql = "SELECT id, enabled, services
FROM {$_TABLES['paypal.gateways']}";
// If not loading all gateways, get just then enabled ones
if (!$all) $sql .= ' WHERE enabled=1';
$sql .= ' ORDER BY orderby';
$res = DB_query($sql, 1);
while ($A = DB_fetchArray($res, false)) {
// For each available gateway, load its class file and add it
// to the global array
if (USES_paypal_gateway($A['id'])) {
$A['services'] = @unserialize($A['services']);
$_PP_CONF['gateways'][] = $A;
}
}
}
/**
* Show the product catalog in the centerblock.
*
* @param integer $where Where to show the block (only after featured story)
* @param integer $page Which page (Home page only)
* @param string $topic Which topics to show with (All)
* @return string HTML code for submission form
*/
function plugin_centerblock_paypal($where = 1, $page = 1, $topic = '')
{
global $_PP_CONF, $ppGCart;
$display = '';
// Only show if no topic is requested
if ($_PP_CONF['centerblock'] == 1 && $topic == '') {
USES_paypal_functions();
USES_paypal_class_cart();
$ppGCart = new ppCart();
$display = PAYPAL_siteHeader();
$T = new Template(PAYPAL_PI_PATH . '/templates');
$T->set_file('title', 'paypal_title.thtml');
$T->set_var('title', $LANG_PP['main_title']);
$display .= $T->parse('', 'title');
$display .= PAYPAL_userMenu('');
$display .= PAYPAL_ProductList();
$display .= PAYPAL_siteFooter();
}
return $display;
}
/**
* Upgrade the plugin to the currently-installed version.
*
* @return mixed True if successful, error message number otherwise
*/
function plugin_upgrade_paypal()
{
global $_TABLES, $_PP_CONF;
$pi_name = $_PP_CONF['pi_name'];
// Get the current version, compare to the version in the plugin code
$current_ver = DB_getItem($_TABLES['plugins'], 'pi_version',
"pi_name = '$pi_name'");
if (!$current_ver) {
COM_errorLog("Error getting the $pi_name Plugin version",1);
return '03';
}
// if we're at the current version, what are we doing here?
if ($current_ver >= $_PP_CONF['pi_version']) {
COM_errorLog("Current version $current_ver is already up to date");
return '06';
}
// If we're still here, perform the upgrade functions.
USES_paypal_upgrade();
$error = PAYPAL_do_upgrade($current_ver);
if ($error) {
COM_errorLog("Error updating the $pi_name Plugin version",1);
return '04';
}
// now update the current version number.
DB_query("UPDATE {$_TABLES['plugins']} SET
pi_version = '{$_PP_CONF['pi_version']}',
pi_gl_version = '{$_PP_CONF['gl_version']}',
pi_homepage = '{$_PP_CONF['pi_url']}'
WHERE pi_name = '$pi_name'");
if (DB_error()) {
COM_errorLog("Error updating the $pi_name Plugin version",1);
return '05';
}
CTL_clearCache($_PP_CONF['pi_name']);
COM_errorLog("Succesfully updated the $pi_name Plugin!",1);
return true;
}
/**
* Returns the main menu items for the plugin.
*
* @return array Associative array of menu items to be added to menu
*/
function plugin_getmenuitems_paypal() {
global $_CONF, $_PP_CONF, $LANG_PP;
$menuitems = array();
if (SEC_hasRights('paypal.user,paypal.admin,paypal.view', 'OR') &&
$_PP_CONF['menuitem']) {
$menuitems[$LANG_PP['mnu_paypal']] = PAYPAL_URL . '/index.php';
}
return $menuitems;
}
/**
* Check to see if this plugin supports comments.
*
* @return boolean True if comments supported, false otherwise
*/
function plugin_commentsupport_paypal()
{
global $_PP_CONF;
return $_PP_CONF['ena_comments'] == 0 ? false : true;
}
/**
* Save a comment
*
* @param string $type Plugin to save comment
* @param string $title Comment title
* @param string $comment Comment text
* @param string $id Item id to which $cid belongs
* @param integer $pid Comment parent
* @param string $postmode 'html' or 'text'
* @return mixed false for failure, HTML string (redirect?) for success
*/
function plugin_savecomment_paypal($title,$comment,$id,$pid,$postmode)
{
global $_CONF, $LANG03, $_TABLES;
// Without comment support, we shouldn't get here unless something
// nefarious is going on, but just in case...
if (!plugin_commentsupport_paypal())
return;
$id = (int)$id;
$title = strip_tags($title); // No HTML in the comment title
$pid = COM_applyFilter($pid, true);
$postmode = COM_applyFilter ($postmode);
// Actually save the comment
$ret = CMT_saveComment($title, $comment, $id, $pid, 'paypal', $postmode);
if ($ret > 0) { // failure
return COM_siteHeader()
. CMT_commentform ($title, $comment, $id, $pid,
'paypal', $LANG03[14], $postmode)
. COM_siteFooter();
} else { // success - update the comment counter for this item
$comments = (int)DB_count($_TABLES['comments'],
array('type', 'sid'),
array('paypal', $id));
DB_query("UPDATE {$_TABLES['paypal.products']}
SET comments = $comments
WHERE id = $id", 1);
return COM_refresh(COM_buildUrl(PAYPAL_URL . "/detail.php?id=$id"));
}
}
/**
* How the plugin will display specific comments.
*
* @param string $id Unique idenifier for item comment belongs to
* @param int $cid Comment id to display
* @param string $title Page/comment title
* @param string $order 'ASC' or 'DSC' or blank
* @param string $format 'threaded', 'nested', or 'flat'
* @param int $page Page number of comments to display
* @param boolean $view True to view comment (by cid), false to display (by $pid)
* @return mixed results of calling the plugin_displaycomment_ function
*/
function plugin_displaycomment_paypal(
$id, $cid, $title, $order,
$format, $page, $view)
{
global $_TABLES, $LANG_ACCESS;
$retval = '';
// Without comment support, we shouldn't get here unless something
// nefarious is going on, but just in case...
if (!plugin_commentsupport_paypal())
return $retval;
$allowed = 1;
if ($allowed == 1) {
$delete_option = (SEC_hasRights('paypal.admin'));
$retval .= CMT_userComments($id, $title, 'paypal', $order, $format,
$cid, $page, $view, $delete_option,
plugin_commentsupport_paypal());
} else {
$retval .= COM_startBlock($LANG_ACCESS['accessdenied'], '',
COM_getBlockTemplate ('_msg_block', 'header'))
. $LANG_ACCESS['storydenialmsg']
. COM_endBlock(COM_getBlockTemplate ('_msg_block', 'footer'));
}
return $retval;
}
/**
* Delete a single comment.
*
* @param int $cid Comment to be deleted
* @param string $id Item id to which $cid belongs
* @return mixed false for failure, HTML string (redirect?) for success
*/
function plugin_deletecomment_paypal($cid, $id)
{
global $_CONF,$_FM_TABLES, $_TABLES;
if (SEC_hasRights('paypal.admin')) {
if (CMT_deleteComment($cid, $id, 'paypal') == 0) {
$count = DB_count($_TABLES['comments'],
array('sid', 'type'),
array($id, 'paypal'));
$count--;
if ($count < 0) $count = 0;
DB_query("UPDATE {$_TABLES['paypal.products']}
SET comments=$count
WHERE id='$id'");
// Redirect back to the product detail page
return COM_refresh(PAYPAL_URL . '/detail.php?id=' . $id);
}
}
// Default return if anything fails
return false;
}
/**
* Handle any post-processing for an edited comment.
* Just redirects back to the product detail page. The comment is actually
* saved in comment.php.
*
* @param integer $cid Comment ID
* @param mixed $id Item ID
*/
function plugin_editcomment_paypal($cid, $id)
{
echo COM_refresh(PAYPAL_URL . '/detail.php?id=' . $id);
exit;
}
/**
* Returns the URL of the plugin's icon.
*
* @return string URL of the icon
*/
function plugin_geticon_paypal()
{
return PAYPAL_URL . '/images/paypal.png';
}
/**
* Add an option for the plugin in the command and control area.
*
* @return array Array containing (pi_name, admin_url, icon_url)
*/
function plugin_cclabel_paypal()
{
global $_PP_CONF;
if (SEC_hasRights('paypal.admin')) {
return array($_PP_CONF['pi_display_name'],
PAYPAL_ADMIN_URL . '/index.php',
plugin_geticon_paypal());
}
}
/**
* Adds the paypal plugin to the Admin menu.
*
* @return array Array containing (pi_name, pi_admin_url, # of items or '')
*/
function plugin_getadminoption_paypal()
{
global $_TABLES, $_PP_CONF;
if (SEC_hasRights('paypal.admin')) {
return array($_PP_CONF['pi_display_name'],
PAYPAL_ADMIN_URL . '/index.php',
DB_count($_TABLES['paypal.products']));
}
}
/**
* Returns the user option for this plugin
* Adds the plugin to the user menu
*
* @return array Array containing (plugin name, plugin user url, 0)
*/
function plugin_getuseroption_paypal()
{
global $LANG_PP, $_TABLES, $ppGCart, $_USER;
$retval = array();
if (!COM_isAnonUser() &&
DB_count($_TABLES['paypal.orders'], 'uid', $_USER['uid']) > 0) {
$retval[] = array($LANG_PP['purchase_history'],
PAYPAL_URL . '/index.php?view=history');
}
PAYPAL_setCart();
if ($ppGCart->hasItems()) {
$retval[] = array($LANG_PP['viewcart'],
PAYPAL_URL . '/index.php?view=cart');
}
return $retval;
}
/**
* Returns the current version of the paypal plugin.
*
* @return string Plugin version
*/
function plugin_chkVersion_paypal()
{
global $_PP_CONF;
return $_PP_CONF['pi_version'];
}
/**
* Performs operations when a user (or admin) deletes an account
*
* Remove purchases from the paypal purchases table.
*
* @TODO Rather than drop rows, archive them
* @param int $uid User ID that is being deleted
*/
function plugin_user_delete_paypal($uid) {
global $_TABLES;
$sql = "DELETE FROM {$_TABLES['paypal.purchases']} WHERE user_id = $uid";
DB_query($sql);
}
/**
* Support merging local accounts into remote accounts
*
* @param integer $origUID Original (remote) user ID
* @param integer $destUID Merged (local) user ID
*/
function plugin_user_move_paypal($origUID, $destUID)
{
global $_TABLES;
$origUID = (int)$origUID;
$destUID = (int)$destUID;
DB_query("UPDATE {$_TABLES['paypal.purchases']}
SET user_id = $destUID WHERE user_id = $origUID", 1);
DB_query("UPDATE {$_TABLES['paypal.address']}
SET uid = $destUID WHERE uid = $origUID", 1);
DB_query("UPDATE {$_TABLES['paypal.orders']}
SET uid = $destUID WHERE uid = $origUID", 1);
DB_query("UPDATE {$_TABLES['paypal.userinfo']}
SET uid = $destUID WHERE uid = $origUID", 1);
DB_query("UPDATE {$_TABLES['paypal.cart']}
SET cart_uid = $destUID WHERE cart_uid = $origUID", 1);
}
/**
* Implements the [paypal:] autotag.
*
* Currently only allows for a single product ID, which will generate
* a link to that product's detail page.
*
* @since version 0.4.0
* @param string $op Operation to perform (tagname or parse)
* @param string $content Content in which to replace autotag
* @param array $autotag Autotag details
* @return string Updated $content
*/
function plugin_autotags_paypal ($op, $content = '', $autotag = '') {
global $_CONF, $_TABLES;
if ($op == 'tagname' ) {
return array('paypal','paypal_cat');
} else if ($op == 'parse') {
switch ($autotag['tag']) {
case 'paypal':
$id = COM_applyFilter($autotag['parm1'], true);
$url = COM_buildUrl(PAYPAL_URL . '/detail.php?id=' . $id);
// Allow the author to use different text for the link. Default
// is the stored product name.
if (empty($autotag['parm2'])) {
$linktext = DB_getItem($_TABLES['paypal.products'],
'name', "id = '$id'");
} else {
$linktext = $autotag['parm2'];
}
$link = '<a href="' . $url . '">' . $linktext . '</a>';
$content = str_replace ($autotag['tagstr'], $link, $content);
break;
case 'paypal_cat':
$id = COM_applyFilter($autotag['parm1'], true);
$url = COM_buildUrl(PAYPAL_URL.'/index.php?category='.$id);
if (empty($autotag['parm2'])) {
$linktext = DB_getItem($_TABLES['paypal.categories'],
'cat_name', "cat_id = '$id'");
} else {
$linktext = $autotag['parm2'];
}
$link = '<a href="' . $url . '">' . $linktext . '</a>';
$content = str_replace ($autotag['tagstr'], $link, $content);
break;
}
return $content;
}
}
/**
* Checks to see if the user has sufficient rights to view the page.
*
* Check if the current user has rights (at least one of) specified by
* $rights. If not log the error, display a generic access denied message
* and exit.
*
* @param string $rights Comma-separated list of allowable rights
*/
function PAYPAL_access_check($rights = 'paypal.user,paypal.admin,paypal.view')
{
global $_USER, $_SERVER, $LANG_PP, $_PLUGINS;
// If this plugin or a required plugin isn't available, abort gracefully
if (!in_array('paypal', $_PLUGINS) ||
!in_array('lglib', $_PLUGINS) ||
!SEC_hasRights($rights, 'OR')) {
COM_404();
exit;
}
}
/**
* Generate a single buy-now button for the first enabled payment gateway.
* This function is deprecated, but is kept to avoid completely breaking
* if some plugin that calls this function is still in place.
*
* Plugins should call PLG_invokeService('paypal, 'genButton'...) instead.
*
* Provided $vars should include:
* 'item_number', 'item_name', 'amount', and optionally 'item_type'
*
* @deprecated version 0.5.0
* @uses PaymentGw::ExternalButton()
* @param string $btn_type Type of button (buy_now, add_to_cart, etc.)
* @param array $vars Associative array of input variables
* @param string $item_type Optional type indicator (physical, virtual)
* @return string HTML of requested button
*/
function PAYPAL_genButton($btn_type, $vars, $item_type=0)
{
global $_CONF, $_PP_CONF, $_USER, $LANG_configselects;
$retval = '';
// must be an expected type
if (!in_array($btn_type,
array('buy_now', 'add_cart', 'pay_now', 'subscribe', 'donation'))) {
return $retval;
}
if ($btn_type == 'add_cart') {
if ($_PP_CONF['ena_cart'] == 1) {
$tpl_add_cart = 'btn_add_cart.thtml';
if ($item_type == 0) $item_type = PP_PROD_VIRTUAL;
$T = new Template(PAYPAL_PI_PATH . '/templates');
$T->set_file('cart', 'buttons/btn_add_cart.thtml');
$T->set_var(array(
'item_name' => $vars['item_name'],
'item_number' => $vars['item_number'],
'amount' => $vars['amount'],
'pi_url' => PAYPAL_URL,
'item_type' => $item_type,
) );
$retval = $T->parse('', 'cart');
}
} else {
PAYPAL_loadGateways();
$gw_id = '';
if (!empty($_PP_CONF['gateways'])) {
// Get the first gateway that supports the button type
foreach ($_PP_CONF['gateways'] as $gw_info) {
if ($gw_info[$btn_type] == 1 && class_exists($gw_info['id'])) {
$gw = new $gw_info['id'];
$retval = $gw->ExternalButton($vars, $btn_type);
break;
}
}
}
}
return $retval;
}
/**
* Return the types to list in the search types selection.
*
* @return array Associative array (typename => title)
*/
function plugin_searchtypes_paypal()
{
global $_PP_CONF, $LANG_PP;
return array($_PP_CONF['pi_name'] => $LANG_PP['srchtitle']);
}
/**
* Create a plugin search object to search this plugin
*
* @param string $query Search query string
* @param string $datestart Starting date for search
* @param string $dateend Ending date for search
* @param string $topic Topic selected for search
* @param string $type Type selected during search
* @param string $author Limit results to this author (not used)
* @return object Search object to be processed by Search class
*/
function plugin_dopluginsearch_paypal(
$query, $datestart, $dateend, $topic, $keyType, $author
)
{
global $_CONF, $_TABLES, $_PP_CONF, $LANG_PP;
// Products aren't "auhored", so return null if searching by author
if (!empty($author) ||
!SEC_hasRights('paypal.user,paypal.admin,paypal.view', 'OR')) {
return NULL;
}
if (empty($keyType)) {
$type = 'all';
}
// Encode query for inclusion in result's url
$htmlquery = urlencode($query);
$query = trim(DB_escapeString(htmlspecialchars($query), ENT_QUOTES, COM_getEncodingt()));
$sql = "SELECT
p.id, p.name as title, p.description as description,
dt_add as date, views as hits,
CONCAT('/{$_PP_CONF['pi_name']}/detail.php?id=',p.id,'&query=$htmlquery') as url
FROM {$_TABLES['paypal.products']} p
LEFT JOIN {$_TABLES['paypal.categories']} c
ON p.cat_id=c.cat_id
WHERE p.enabled = 1
AND (c.enabled=1 OR c.enabled IS NULL)";
$search = new SearchCriteria($_PP_CONF['pi_name'], $LANG_PP['blocktitle']);
$columns = array('p.name', 'p.short_description', 'p.description',
'p.keywords', 'c.cat_name', 'c.description');
list($sql, $ftsql) =
$search->buildSearchSQL($keyType, $query, $columns, $sql);
$search->setSQL($sql);
return $search;
}
/**
* Get additional Javascript files to import in the header
*
* @return array Array of filenames to import
*/
function plugin_getheaderjs_paypal()
{
$files = array(
PAYPAL_PI_PATH . '/js/toggleEnabled.js',
);
return $files;
}
/**
* Get additional CSS into the site header.
* Checks first for layout-specific version, gets the plugin default if none.
*
* @return array List of paths to CSS files
*/
function plugin_getheadercss_paypal()
{
global $_CONF, $_PP_CONF;
$styles = array();
$pi_css = PAYPAL_PI_PATH . '/css/';
$layout_css = "{$_CONF['path_layout']}plugins/{$_PP_CONF['pi_name']}/";
$files = array('style.css');
foreach ($files as $file) {
$styles[] = $pi_css . $file;
if (@file_exists($pi_css . 'custom/' . $file)) {
$styles[] = $pi_css . 'custom/' . $file;
}
if (@file_exists($layout_css . $file)) {
$styles[] = $layout_css . $file;
}
}
return $styles;
}
/**
* Get the URL to the localized configuration help file.
*
* @uses PAYPAL_getDocURL()
* @param string $option Configuration option to display
* @param string $doclang Documentation language requested
* @return array Array of (url, window_type)
*/
function plugin_getconfigelementhelp_paypal($option, $doclang='english')
{
$doc_url = PAYPAL_getDocURL('config.html', $doclang);
if (empty($doc_url))
return false;
if (!empty($option)) {
$file .= '#desc_' . $option;
}
return array($doc_url . $file, 0);
}
/**
* Get the link to a documentation file.
*
* Returns the URL to the file, or to the directory if no file requested.
*
* @see plugin_getconfigelementhelp_paypal()
* @see Product::showForm()
* @param string $file HTML file
* @param string $doclang Documentation language
* @return string URL to document directory or file
*/
function PAYPAL_getDocURL($file='', $doclang='english')
{
$doc_path = PAYPAL_PI_PATH . "/docs/$doclang/";
$doc_url = '';
if ($file != '') {
if (!file_exists($doc_path . $file)) {
$doclang = 'english';
}
$doc_url = PAYPAL_URL . "/docs/$doclang/$file";
} else {
if (!is_dir($doc_path)) {
$doclang = 'english';
}
$doc_url = PAYPAL_URL . "/docs/$doclang/";
}
return $doc_url;
}
/**
* Return the items that should be removed with the plugin.
*
* @return array Array of items to be removed.
*/
function plugin_autouninstall_paypal ()
{
$out = array (
// Give the name of the tables, without $_TABLES[]
'tables' => array(
'paypal.address',
'paypal.buttons',
'paypal.cart',
'paypal.categories',
'paypal.currency',
'paypal.gateways',
'paypal.images',
'paypal.ipnlog',
'paypal.order_items',
'paypal.order_log',
'paypal.orderstatus',
'paypal.orders',
'paypal.prod_attr',
'paypal.products',
'paypal.purchases',
'paypal.specials',
'paypal.userinfo',
'paypal.workflows',
),
// Give the full name of the group, as in the db
'groups' => array('paypal Admin'),
// Give the full name of the feature, as in the db
'features' => array(
'paypal.admin',
'paypal.user',
'paypal.view'
),
// Give the full name of the block, including 'phpblock_', etc
'php_blocks' => array(
'phpblock_paypal_random',
'phpblock_paypal_featured',
'phpblock_paypal_categories',
'phpblock_paypal_popular',
'phpblock_paypal_cart',
'phpblock_paypal_recent',
),
// List all vars by name
'vars'=> array('paypal_gid'),
);
return $out;
}
/**
* Disable this plugin's blocks when the plugin is changed.
*
* Acts on all blocks with a phpblock function similar to the specified
* functions. Blocks are not enabled automatically when enabling the plugin.
*
* @param boolean $enabled Plugin's new "enabled" state
*/
function plugin_enablestatechange_paypal($enabled)
{
global $_TABLES;
$enabled = $enabled == true ? 1 : 0;
if ($enabled == 0) {
$blockfns = array('phpblock_paypal_');
foreach ($blockfns as $blockfn) {
DB_query("UPDATE {$_TABLES['blocks']}
SET is_enabled=$enabled
WHERE phpblockfn like '{$blockfn}%'"
);
}
}
}
/**
* Get comment url and unique id fieldname.
*