-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.php
1772 lines (1437 loc) · 74.1 KB
/
init.php
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
// kleeja plugin
// developer: KLEEJA TEAM
// prevent illegal run
if (! defined('IN_PLUGINS_SYSTEM')) {
exit;
}
// plugin basic information
$kleeja_plugin['kleeja_payment']['information'] = [
// the casual name of this plugin, anything can a human being understands
'plugin_title' => [
'en' => 'Kleeja Payment',
'ar' => 'مدفوعات كليجا'
],
// who wrote this plugin?
'plugin_developer' => 'Kleeja Team',
// this plugin version
'plugin_version' => '1.3.0',
// explain what is this plugin, why should i use it?
'plugin_description' => [
'en' => 'Selling Files and Premium Groups',
'ar' => 'بيع الملفات والمجموعات المميزة'
],
// min version of kleeja that's required to run this plugin
'plugin_kleeja_version_min' => '3.1.5',
// max version of kleeja that support this plugin, use 0 for unlimited
'plugin_kleeja_version_max' => '3.9',
// should this plugin run before others?, 0 is normal, and higher number has high priority
'plugin_priority' => 10 , // only for define support_kjPay
// setting page to display in plugins page
'settings_page' => 'cp=options&smt=kleeja_payment'
];
//after installation message, you can remove it, it's not requiered
$kleeja_plugin['kleeja_payment']['first_run']['ar'] = "
باستخدام هذا البرنامج المساعد ، يمكنك تسعير الملفات والمجموعات لبيعها ، واستلام الدفعات إلى حساب paypal الخاص بك تلقائيًا <br>
قم يزيارة صفحة المساعدة للمزيد <br>
<a href='./index.php?cp=kj_payment_options&smt=help' >المساعدة</a>
";
$kleeja_plugin['kleeja_payment']['first_run']['en'] = "
With this plugin you can sell & purchases files and also join groups, and receive the payments to your paypal account automaticly
<br>
for more info visit help page <br>
<a href='./index.php?cp=kj_payment_options&smt=help' >Help</a>
";
// plugin installation function
$kleeja_plugin['kleeja_payment']['install'] = function ($plg_id) {
global $SQL , $dbprefix , $d_groups;
$InstallQuerys = [
"CREATE TABLE IF NOT EXISTS `{$dbprefix}payments` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`payment_state` text COLLATE utf8_bin NOT NULL,
`payment_method` VARCHAR(100) NULL DEFAULT NULL,
`payment_more_info` LONGTEXT DEFAULT NULL,
`payment_amount` float NOT NULL,
`payment_currency` VARCHAR(10) NOT NULL,
`payment_token` text COLLATE utf8_bin NOT NULL,
`payment_payer_ip` text COLLATE utf8_bin NOT NULL,
`payment_action` text COLLATE utf8_bin NOT NULL,
`item_id` int(11) NOT NULL,
`item_name` text COLLATE utf8_bin NOT NULL,
`user` int(11) NOT NULL,
`payment_year` int(11) NOT NULL,
`payment_month` int(11) NOT NULL,
`payment_day` int(11) NOT NULL,
`payment_time` text COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;" ,
"CREATE TABLE IF NOT EXISTS `{$dbprefix}payments_out` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user` int(11) NOT NULL,
`method` text COLLATE utf8_bin NOT NULL,
`amount` float NOT NULL,
`payment_more_info` text COLLATE utf8_bin NOT NULL,
`payout_year` int(11) NOT NULL,
`payout_month` int(11) NOT NULL,
`payout_day` int(11) NOT NULL,
`payout_time` text COLLATE utf8_bin NOT NULL,
`state` text COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;" ,
"CREATE TABLE IF NOT EXISTS `{$dbprefix}subscriptions` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8_bin NOT NULL,
`days` int(11) NOT NULL,
`price` float NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;" ,
"ALTER TABLE `{$dbprefix}files` ADD `price` FLOAT NOT NULL DEFAULT '0';" ,
"ALTER TABLE `{$dbprefix}users` ADD `package` INT NOT NULL DEFAULT '0';" ,
"ALTER TABLE `{$dbprefix}users` ADD `balance` FLOAT NOT NULL DEFAULT '0.00';" ,
"ALTER TABLE `{$dbprefix}users` ADD `subs_point` INT NOT NULL DEFAULT '0';" ,
"ALTER TABLE `{$dbprefix}users` ADD `package_expire` INT NOT NULL DEFAULT '0';" ,
"CREATE TABLE `{$dbprefix}subscription_point` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user` int(11) NOT NULL,
`file_id` int(11) NOT NULL,
`subscription_id` int(11) NOT NULL,
`subscripe_hash` text COLLATE utf8_bin NOT NULL,
`time` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"
];
foreach ($InstallQuerys as $query) {
$SQL->query($query);
}
// create group permission to access bought files
foreach ($d_groups as $group_id => $group_info) {
// guest & bought files => problems
// search for "expected_err" on this document Ctrl + F
// and u will know what i mean
if ($group_id == 2) {
continue;
}
// access_bought_files
$insert_acl = [
'INSERT' => 'acl_name, acl_can, group_id',
'INTO' => "{$dbprefix}groups_acl",
'VALUES' => "'access_bought_files', 0 , " . $group_id
];
$SQL->build($insert_acl);
// recaive_profits
$insert_acl['VALUES'] = "'recaive_profits', 0 , " . $group_id;
$SQL->build($insert_acl);
}
$options = [
'kjp_join_price' =>
[
'value' => '0',
'html' => configField('kjp_join_price'),
'plg_id' => $plg_id,
'type' => 'groups',
'order' => '0',
],
'kjp_min_payout_limit' =>
[
'value' => '0',
'html' => configField('kjp_min_payout_limit'),
'plg_id' => $plg_id,
'type' => 'groups',
'order' => '1',
],
'kjp_active_subscriptions' =>
[
'value' => '0',
'html' => configField('kjp_active_subscriptions', 'yesno'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '0',
],
'kjp_active_live_mode' =>
[
'value' => '0',
'html' => configField('kjp_active_live_mode', 'yesno'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '0',
],
'kjp_paypal_client_id' =>
[
'value' => '0',
'html' => configField('kjp_paypal_client_id'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '1',
],
'kjp_paypal_client_secret' =>
[
'value' => '0',
'html' => configField('kjp_paypal_client_secret'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '2',
],
'kjp_stripe_publishable_key' =>
[
'value' => '0',
'html' => configField('kjp_stripe_publishable_key'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '3',
],
'kjp_stripe_secret_key' =>
[
'value' => '0',
'html' => configField('kjp_stripe_secret_key'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '4',
],
'kjp_iso_currency_code' =>
[
'value' => 'USD',
'html' => configField('kjp_iso_currency_code'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '5',
],
'kjp_down_link_expire' =>
[
'value' => '1',
'html' => configField('kjp_down_link_expire'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '6',
],
'kjp_file_owner_profits' =>
[
'value' => '50',
'html' => configField('kjp_file_owner_profits'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '7',
],
'kjp_min_price_limit' =>
[
'value' => '1',
'html' => configField('kjp_min_price_limit'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '9',
],
'kjp_max_price_limit' =>
[
'value' => '5',
'html' => configField('kjp_max_price_limit'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '8',
]
];
// an example to add your method to kleeja payments
// be sure that the type is ('kj_pay_active_mthd') and the name is (active_{$your_method})
// check getPaymentMethods() function for more informations
$options['kjp_active_paypal'] = [
'value' => '1',
'html' => configField('kjp_active_paypal', 'yesno'),
'plg_id' => $plg_id,
'type' => 'kj_pay_active_mthd',
'order' => '1',
];
// $options['kjp_active_cards'] = [
// 'value' => '1',
// 'html' => configField('kjp_active_cards', 'yesno'),
// 'plg_id' => $plg_id,
// 'type' => 'kj_pay_active_mthd',
// 'order' => '2',
// ];
$options['kjp_active_balance'] = [
'value' => '1',
'html' => configField('kjp_active_balance', 'yesno'),
'plg_id' => $plg_id,
'type' => 'kj_pay_active_mthd',
'order' => '0',
];
add_config_r($options);
// extract libs
KJP::firstRun();
};
//plugin update function, called if plugin is already installed but version is different than current
$kleeja_plugin['kleeja_payment']['update'] = function ($old_version, $new_version) {
global $SQL , $dbprefix;
// extract Libs
KJP::firstRun();
if (version_compare($old_version, '1.2.4', '<')) {
// create subscription table
$SQL->query(
"CREATE TABLE IF NOT EXISTS `{$dbprefix}subscriptions` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8_bin NOT NULL,
`days` int(11) NOT NULL,
`price` float NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;"
);
$SQL->query(
"CREATE TABLE `{$dbprefix}subscription_point` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user` int(11) NOT NULL,
`file_id` int(11) NOT NULL,
`subscription_id` int(11) NOT NULL,
`subscripe_hash` text COLLATE utf8_bin NOT NULL,
`time` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"
);
// add package colum to users table
$SQL->query("ALTER TABLE `{$dbprefix}users` ADD `package` INT NOT NULL DEFAULT '0';");
$SQL->query("ALTER TABLE `{$dbprefix}users` ADD `package_expire` INT NOT NULL DEFAULT '0';");
$SQL->query("ALTER TABLE `{$dbprefix}users` ADD `subs_point` INT NOT NULL DEFAULT '0';");
$SQL->query("ALTER TABLE `{$dbprefix}payments` ALTER `payment_more_info` SET DEFAULT NULL;");
//we need the id of kleeja_payment plugin
$plg_id = KJP::info()['plugin_id'];
// Add new Config for Subscriptions and add prefix to plugins setting
add_config_r([
'kjp_join_price' =>
[
'value' => '0',
'html' => configField('kjp_join_price'),
'plg_id' => $plg_id,
'type' => 'groups',
'order' => '0',
],
'kjp_min_payout_limit' =>
[
'value' => '0',
'html' => configField('kjp_min_payout_limit'),
'plg_id' => $plg_id,
'type' => 'groups',
'order' => '1',
],
'kjp_active_live_mode' =>
[
'value' => '0',
'html' => configField('kjp_active_live_mode', 'yesno'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '0',
],
'kjp_paypal_client_id' =>
[
'value' => get_config('pp_client_id'),
'html' => configField('kjp_paypal_client_id'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '1',
],
'kjp_paypal_client_secret' =>
[
'value' => get_config('paypal_client_secret'),
'html' => configField('kjp_paypal_client_secret'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '2',
],
'kjp_stripe_publishable_key' =>
[
'value' => get_config('stripe_publishable_key'),
'html' => configField('kjp_stripe_publishable_key'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '3',
],
'kjp_stripe_secret_key' =>
[
'value' => get_config('stripe_secret_key'),
'html' => configField('kjp_stripe_secret_key'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '4',
],
'kjp_iso_currency_code' =>
[
'value' => get_config('iso_currency_code'),
'html' => configField('kjp_iso_currency_code'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '5',
],
'kjp_down_link_expire' =>
[
'value' => get_config('down_link_expire'),
'html' => configField('kjp_down_link_expire'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '6',
],
'kjp_file_owner_profits' =>
[
'value' => get_config('file_owner_profits'),
'html' => configField('kjp_file_owner_profits'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '7',
],
'kjp_min_price_limit' =>
[
'value' => get_config('min_price_limit'),
'html' => configField('kjp_min_price_limit'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '9',
],
'kjp_max_price_limit' =>
[
'value' => get_config('max_price_limit'),
'html' => configField('kjp_max_price_limit'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '8',
],
'kjp_active_subscriptions' =>
[
'value' => '0',
'html' => configField('kjp_active_subscriptions', 'yesno'),
'plg_id' => $plg_id,
'type' => 'kleeja_payment',
'order' => '0',
],
'kjp_active_balance'=>
[
'value' => get_config('active_balance'),
'html' => configField('kjp_active_balance', 'yesno'),
'plg_id' => $plg_id,
'type' => 'kj_pay_active_mthd',
'order' => '0',
],
'kjp_active_paypal'=>
[
'value' => get_config('active_paypal'),
'html' => configField('kjp_active_paypal', 'yesno'),
'plg_id' => $plg_id,
'type' => 'kj_pay_active_mthd',
'order' => '0',
],
'kjp_active_cards'=>
[
'value' => get_config('active_cards'),
'html' => configField('kjp_active_cards', 'yesno'),
'plg_id' => $plg_id,
'type' => 'kj_pay_active_mthd',
'order' => '0',
],
]);
// we will delete the old configs , becouse we will add prefix to it
delete_config([
'join_price',
'min_payout_limit',
'paypal_client_secret',
'pp_client_id',
'iso_currency_code',
'active_paypal',
'active_cards',
'active_balance',
'down_link_expire',
'stripe_publishable_key',
'stripe_secret_key',
'min_price_limit',
'max_price_limit' ,
'file_owner_profits' ,
]);
}
if (version_compare($old_version, '1.2.9', '<')) {
delete_config(['kjp_active_cards']);
}
//you could use update_config
};
// plugin uninstalling, function to be called at uninstalling
$kleeja_plugin['kleeja_payment']['uninstall'] = function ($plg_id) {
global $SQL , $dbprefix;
$SQL->query("DROP TABLE `{$dbprefix}subscription_point`");
$SQL->query("ALTER TABLE `{$dbprefix}files` DROP `price`;");
$SQL->query("ALTER TABLE `{$dbprefix}users` DROP `balance` , DROP `package` , DROP `package_expire` , DROP `subs_point`;");
// removed from db
//delete_olang(null, null , $plg_id);
delete_config([
'kjp_join_price',
'kjp_min_payout_limit',
'kjp_paypal_client_secret',
'kjp_paypal_client_id',
'kjp_iso_currency_code',
'kjp_payment_method',
'kjp_active_paypal',
'kjp_active_cards',
'kjp_active_balance',
'kjp_down_link_expire',
'kjp_stripe_publishable_key',
'kjp_stripe_secret_key',
'kjp_min_price_limit',
'kjp_max_price_limit' ,
'kjp_active_subscriptions',
'kjp_active_live_mode',
'kjp_file_owner_profits'
]);
// DELETE ACCESS BOUGHT FILES PERMISSIONS AND recaive profits
$SQL->query("DELETE FROM `{$dbprefix}groups_acl` WHERE acl_name = 'access_bought_files' OR acl_name = 'recaive_profits'");
// in the end , let's delete the olang , not our one , for other packages of this plugin
delete_olang(null, null, $plg_id);
};
// plugin functions
$kleeja_plugin['kleeja_payment']['functions'] = [
'qr_download_id_filename' => function ($args) {
global $SQL , $config , $usrcp , $subscription , $olang;
$query = $args['query'];
$query['SELECT'] .= ', f.price';
$result = $SQL->build($query);
if ($SQL->num_rows($result) > 0) {
$row = $SQL->fetch_array($result);
if ($config['kjp_active_subscriptions']) { // if the subscription is active
if ($row['price'] > 0 && ! $subscription->is_valid($usrcp->id())) { // subscripe is active but not valid & paid file
// wibsite founders and file Owner can download without pay
if ($usrcp->get_data('founder')['founder'] == 0 &&
($row['fuserid'] !== $usrcp->id() || $row['fusername'] !== $usrcp->name())) { // send to buy page && and display subscripes packs
redirect($config['siteurl'] . 'do.php?file=' . $row['id']);
$SQL->close();
exit;
}
} elseif ($row['price'] == 0 && ! $subscription->is_valid($usrcp->id())) { // subscripe is active but not valid & free file
// wibsite founders and file Owner can download without pay
if ($usrcp->get_data('founder')['founder'] == 0 &&
($row['fuserid'] !== $usrcp->id() || $row['fusername'] !== $usrcp->name())) { // display an msg to say that we are using subscripe system and redirect to subscripes page
kleeja_err($olang['KJP_WE_USE_SUBSCRIPE_SYS'], '', true, $config['siteurl'] . 'go.php?go=subscription');
$SQL->close();
exit;
}
} else {
/**
* if the code arrive here , that mean the user have valid subscripe , he is free to do what he want
* god bless hem
*/
}
} else { // the subscription is not active
if ($row['price'] > 0) { // if paid , send hem to buy page
// wibsite founders and file Owner can download without pay
if ($usrcp->get_data('founder')['founder'] == 0 &&
($row['fuserid'] !== $usrcp->id() || $row['fusername'] !== $usrcp->name())) {
redirect($config['siteurl'] . 'do.php?file=' . $row['id']);
$SQL->close();
exit;
}
} // subscription is not active and the file is free => do nothing , it's not our job
}
} // file not found -> kleeja will display an error msg
} ,
'err_navig_download_page' => function ($args) {
global $config, $SQL, $dbprefix, $olang, $lang , $tpl , $THIS_STYLE_PATH_ABS , $usrcp, $subscription;
if (ig('file') && (int) g('file')) {
// if we are using subscription system, and the user trying to buy a file, redirect hem to normal download page
if ($config['kjp_active_subscriptions'] && $subscription->is_valid($usrcp->id())) {
redirect($config['siteurl'] . 'do.php?id=' . g('file'));
exit;
}
// avilable Payment methods
$payment_methods = [];
foreach (getPaymentMethods() as $value) {
$value = trim($value);
$payment_methods[$value] = ['name' => $olang['KJP_MTHD_NAME_' . strtoupper($value)] , 'method' => $value];
}
if (ip('buy_file')) {
if (empty(p('method')) || empty(g('file'))) {
kleeja_err($lang['ERROR_NAVIGATATION']);
} else {
redirect(KJP::getPayURL('buy_file', (string) p('method'), (int) g('file')));
}
exit();
}
require_once dirname(__FILE__) . '/php/down_ui.php';
// add Vars to $GLOBAL
$error = false;
$tpl->assign('id', $id);
$tpl->assign('name', $name);
$tpl->assign('real_filename', $real_filename);
$tpl->assign('type', $type);
$tpl->assign('time', $time);
$tpl->assign('uploads', $uploads);
$tpl->assign('price', $price);
$tpl->assign('fusername', $fusername);
$tpl->assign('REPORT', $REPORT);
$tpl->assign('userfolder', $userfolder);
$tpl->assign('size', $size);
$tpl->assign('FormAction', $FormAction);
$tpl->assign('payment_methods', $payment_methods);
Saaheader($title);
echo $tpl->display($sty, $styPath);
Saafooter();
return compact('error');
$SQL->close();
}
} ,
'default_go_page' => function ($args) {
global $lang , $olang , $usrcp , $config , $THIS_STYLE_PATH_ABS ,$subscription;
// request Example : domain.io/kleeja/go.php?go=kj_payment&method=paypal&action=buy_file&id=1
// action = buy_file OR join_group or check
// id = the id of file or the id of group
// checking request Example : domain.io/kleeja/go.php?go=kj_payment&method=paypal&action=check&blablabla
// blablabla = it's optional for you to using sessions or anythink you want , anyway it will be global varibles
if (ig('go') && g('go') === 'kj_payment' && ig('method') && !empty(g('method')) && ig('action') && ! empty(g('action'))) {
require_once dirname(__FILE__) . '/php/kjPayment.php'; // require the payment interface
$PaymentMethodClass = dirname(__FILE__) . '/method/' . g('method') . '.php'; // default payment method
if (! file_exists($PaymentMethodClass)) {
$is_err = true;
is_array($plugin_run_result = Plugins::getInstance()->run('KjPay:set_payment_method', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
if ($is_err) {
kleeja_err('The class file of ' . g('method') . ' payment in not found');
exit;
}
}
require_once $PaymentMethodClass;
$PaymentMethod = 'kjPayMethod_' . basename($PaymentMethodClass, '.php');
// to be sure
if ($PaymentMethod !== 'kjPayMethod_' . g('method')) {
kleeja_err('Its not your method');
exit;
}
// check if the current payment class is implemented our interface or not
elseif (! (($PAY = new $PaymentMethod) instanceof KJPaymentMethod)) {
kleeja_err('<strong>' . $PaymentMethod . '</strong> class is not implementing (KJPaymentMethod) interface');
exit;
} elseif (! $PAY::permission('createPayment')) {
kleeja_err('This Method Dont support Creating Payments');
exit;
}
$PAY->paymentStart(); // Play some song to enjoy ;
$PAY->setCurrency(strtoupper($config['kjp_iso_currency_code']));
switch (g('action')) {
case 'buy_file':
if (! ig('id')) {
kleeja_err($lang['ERROR_NAVIGATATION']);
exit;
}
// user can't buy another file before receive the link of first file
// if the user do it , he will lost access to first bought file
if ($usrcp->kleeja_get_cookie('mailForDownFile')) {
// the user didn't download the file , becuse he did n't set his e-mail
redirect($config['siteurl'] . 'go.php?go=KJPaymentMailer');
exit;
}
$fileInfo = getFileInfo(g('id')); // get file information
if ($fileInfo['price'] <= 0) {
kleeja_err(' The File Is For Free ');
exit;
}
$PAY->CreatePayment('buy_file', $fileInfo);
// get some vars for kleeja # compact(':)')
foreach ($PAY->varsForCreatePayment() as $varName => $varValue) {
$GLOBALS[$varName] = $varValue;
}
break;
case 'join_group':
// Joining Group Steps
if (! ig('id')) {
kleeja_err($lang['ERROR_NAVIGATATION']);
exit;
}
$userIs = $usrcp->get_data('group_id');
if (! $usrcp->name()) { // the Guests have to signup befor join ..
/** $usrcp->id() == false && !$usrcp->id() this options does not work here */
kleeja_err($lang['USER_PLACE']);
exit;
} elseif ($userIs['group_id'] == g('id')) { // if the user is in this group .. note : $usrcp->group_id() also was making problems here , the user need to lougout
kleeja_err($olang['KJP_CNT_JOIN']);
exit;
} elseif ($userIs['group_id'] == 1 && ! defined('DEV_STAGE')) {
kleeja_err('YOU ARE ADMIN');
exit;
} else {
$groupInfo = getGroupInfo($args['d_groups'], g('id'));
if ($groupInfo) {
$PAY->CreatePayment('join_group', $groupInfo);
foreach ($PAY->varsForCreatePayment() as $varName => $varValue) {
$GLOBALS[$varName] = $varValue;
}
} else {
kleeja_err("It's not allowed to you to join this group");
exit;
}
}
break;
case 'subscripe':
if (! ig('id')) {
kleeja_err($lang['ERROR_NAVIGATATION']);
exit;
}
if (! $usrcp->name()) {
kleeja_err($lang['USER_PLACE'], '', true, $config['siteurl'] . 'go.php?go=subscription');
exit;
} elseif ($usrcp->group_id() == 1 && ! defined('DEV_STAGE')) {
kleeja_err('YOU ARE ADMIN');
exit;
} elseif ($subscription->is_valid($usrcp->id())) {
kleeja_err($olang['KJP_U_H_VALID_SUBSCRIPE']);
exit;
}
$subscripe_info = $subscription->get(g('id'));
if (! $subscripe_info) {
kleeja_err($lang['USER_PLACE'], '', true, $config['siteurl'] . 'go.php?go=subscription');
exit;
}
$PAY->CreatePayment('subscripe', $subscripe_info);
foreach ($PAY->varsForCreatePayment() as $varName => $varValue) {
$GLOBALS[$varName] = $varValue;
}
break;
case 'check':
// Checking Payments steps
// i don't want the user reset the cookie expire date
if ($usrcp->kleeja_get_cookie('mailForDownFile')) {
// the user didn't download the file , becuse he did n't set his e-mail
redirect($config['siteurl'] . 'go.php?go=KJPaymentMailer');
exit;
}
$PAY->checkPayment();
if ($PAY->isSuccess()) {
$GLOBALS['title'] = 'successful Payment ' . $_SESSION['kj_payment']['db_id'];
$GLOBALS['no_request'] = false;
$GLOBALS['stylee'] = 'pay_success';
$GLOBALS['FormAction'] = $config['siteurl'] . 'go.php?go=KJPaymentMailer';
// to allow the developers to including 'pay_success.html' with their styles .
$GLOBALS['styleePath'] = file_exists($THIS_STYLE_PATH_ABS . 'kj_payment/paypal.pay_success.html') ? $THIS_STYLE_PATH_ABS . 'kj_payment/' : dirname(__FILE__) . '/html/';
$global_vars = $PAY->getGlobalVars(); // compact(':)')
foreach ($global_vars as $varName => $varValue) {
$GLOBALS[$varName] = $varValue;
}
if ($_SESSION['kj_payment']['payment_action'] == 'buy_file') { // we send e-mail only when the user buying files , no e-mail for joining group
// "expected_err"
if (! $usrcp->name() || ! user_can('access_bought_files')) { // the user can find the file on bought files , don't need to send the download link
if ($PAY->linkMailer()) { // if the method support email
$mailTemplate = str_replace(['@fileName' , '@downLink' , '@linkExpire'], [$global_vars['file_name'] , $global_vars['down_link'] , date('Y-m-d / H:i:s', ($config['kjp_down_link_expire'] * 86400) + time())], $GLOBALS['olang']['KJP_MAIL_TPL']); // error here
$mailer = send_mail($PAY->linkMailer(), $mailTemplate, 'kleeja Payment Download Link', $config['sitemail'], $config['sitename']);
if ($mailer) { // mail is sent , don't need mail form & dispaly success msg
$GLOBALS['olang']['KJP_DOWN_INFO_2'] = str_replace(['@mail' , '@time'], [$PAY->linkMailer() , date('Y-m-d / H:i:s', ($config['kjp_down_link_expire'] * 86400) + time())], $GLOBALS['olang']['KJP_DOWN_INFO_2']);
$GLOBALS['showMailForm'] = false;
$usrcp->kleeja_set_cookie('downloadFile_' . $_SESSION['kj_payment']['item_id'], $_SESSION['kj_payment']['item_id'] . '_' . $_SESSION['kj_payment']['db_id'] . '_' . $_SESSION['kj_payment']['payment_token'], ($config['kjp_down_link_expire'] * 86400) + time());
} else { // we have to send mail again , i hope we never never arrive to this part :(
$GLOBALS['showMailForm'] = true;
$GLOBALS['olang']['KJP_DOWN_INFO_2'] = ''; // dont show this msg , we didn't send it yet
$usrcp->kleeja_set_cookie('mailForDownFile', $_SESSION['kj_payment']['item_id'] . '_' . $_SESSION['kj_payment']['db_id'] . '_' . $_SESSION['kj_payment']['payment_token'], time() + 86400);
}
} else { // method don't support email -> display email form & hide msg & set coockie to use mailform page
$GLOBALS['showMailForm'] = true;
$GLOBALS['olang']['KJP_DOWN_INFO_2'] = ''; // dont show this msg , we didn't send it yet
$usrcp->kleeja_set_cookie('mailForDownFile', $_SESSION['kj_payment']['item_id'] . '_' . $_SESSION['kj_payment']['db_id'] . '_' . $_SESSION['kj_payment']['payment_token'], time() + 86400);
}
} else {
$GLOBALS['olang']['KJP_DOWN_INFO_2'] = 'you can see the file and all bought files on <a href="./ucp.php?go=bought_files">Bought Files </a> Page';
$GLOBALS['showMailForm'] = false;
$usrcp->kleeja_set_cookie('downloadFile_' . $_SESSION['kj_payment']['item_id'], $_SESSION['kj_payment']['item_id'] . '_' . $_SESSION['kj_payment']['db_id'] . '_' . $_SESSION['kj_payment']['payment_token'], ($config['kjp_down_link_expire'] * 86400) + time());
}
}
}
unset($_SESSION['kj_payment']);
//else
//{
// Every method will do somthing , include it in $PAY->checkPayment()
//}
break;
default:
$request = false; // maybe we will need it later;
is_array($plugin_run_result = Plugins::getInstance()->run('KjPay:default_action', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
if (! $request) {
kleeja_err('Why i am here ??');
}
break;
}
} elseif (g('go') == 'paid_group') {
if (ip('join_grp')) {
// to be sure that no one playing with html file
if (in_array(p('method'), getPaymentMethods())) {
redirect(KJP::getPayURL('join_group', (string) p('method'), (int) g('group_id')));
exit();
}
}
$MethodOption = '';
foreach (getPaymentMethods() as $value) {
$value = trim($value);
$MethodOption .= "<option value='{$value}'>" . $olang['KJP_MTHD_NAME_' . strtoupper($value)] . "</option>\n";
// loop inside loop doesn't work in kleeja styles
}
$no_request = false;
$stylee = 'paid_group';
$titlee = $olang['KJP_PID_GRP'];
// to allow the developers to including 'paid_group.html' with their styles .
$styleePath = file_exists($THIS_STYLE_PATH_ABS . 'kj_payment/paid_group.html') ? $THIS_STYLE_PATH_ABS . 'kj_payment/' : dirname(__FILE__) . '/html/';
$PaidGroups = getGroupInfo($args['d_groups']);
return compact('no_request', 'titlee', 'stylee', 'styleePath', 'PaidGroups', 'MethodOption');
}
// Send Download Link
elseif (g('go') == 'KJPaymentMailer') {
$payCookieInfo = $usrcp->kleeja_get_cookie('mailForDownFile');
if (! $payCookieInfo) {
// ! from check payment page or the mail is sent
kleeja_err($lang['ERROR_NAVIGATATION']);
exit;
}
$payCookieInfoExplode = explode('_', $payCookieInfo);
$fileName = getFileInfo($payCookieInfoExplode[0])['name'];
if (ip('sendMail')) {
$mailAdress = p('buyerMail');
if (! filter_var($mailAdress, FILTER_VALIDATE_EMAIL)) {
kleeja_err($lang['WRONG_EMAIL'], '', true, $config['siteurl'] . 'go.php?go=KJPaymentMailer', 2);
exit; // again :)
}
$downloadLink = $config['siteurl'] . 'do.php?downPaidFile=' . $payCookieInfoExplode[0] . '_' . $payCookieInfoExplode[1] . '_' . $payCookieInfoExplode[2];
$mailTemplate = str_replace(['@fileName' , '@downLink' , '@linkExpire'], [$fileName , $downloadLink , date('Y-m-d / H:i:s', ($config['kjp_down_link_expire'] * 86400) + time())], $GLOBALS['olang']['KJP_MAIL_TPL']);
$mailer = send_mail($mailAdress, $mailTemplate, 'kleeja Payment Download Link', $config['sitemail'], $config['sitename']);
if (! $mailer) {
kleeja_err($olang['KJP_ERR_SND_MIL'], '', true, $config['siteurl'] . 'go.php?go=KJPaymentMailer', 3);
exit;
} else {
// set cookie for download file
$usrcp->kleeja_set_cookie('downloadFile_' . $payCookieInfoExplode[0], $payCookieInfo, ($config['kjp_down_link_expire'] * 86400) + time());
// delete cookie
$usrcp->kleeja_set_cookie('mailForDownFile', 'Finaly done , :)', time() - 86400); // *_*
// dispaly success msg || I HOPE WE DONE
kleeja_info(
str_replace(['@mail' , '@time'], [$mailAdress , date('Y-m-d / H:i:s', ($config['kjp_down_link_expire'] * 86400) + time())], $GLOBALS['olang']['KJP_DOWN_INFO_2'])
);