/
ignitiondeck.php
1846 lines (1639 loc) · 63 KB
/
ignitiondeck.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
/*
Plugin Name: IgnitionDeck Crowdfunding
URI: http://IgnitionDeck.com
Description: A custom crowdfunding platform for WordPress. IgnitionDeck allows you to create unlimited and dynamic fundraising campaigns for physical and/or digital goods, integrates with a variety of email and ecommerce platforms, and is compatible with all WordPress themes 3.1+.
Version: 1.5.7
Author: Virtuous Giant
Author URI: http://VirtuousGiant.com
License: GPL2
*/
/*
This sections handles the following:
1. IgnitionDeck Pro Activation
2. WordPress Multisite Activation
3. Standard WordPress Activation
*/
global $ign_db_version;
global $ign_installed_ver;
$ign_db_version = "1.5.7";
$ign_installed_ver = get_option( "ign_db_version" );
function is_id_network_activated() {
$active_plugins = get_site_option( 'active_sitewide_plugins');
if (isset($active_plugins['ignitiondeck-crowdfunding/ignitiondeck.php'])) {
if (is_multisite()) {
return true;
}
}
return false;
}
if (is_multisite() && is_id_pro()) {
// we only run this if we're network activating
if (is_network_admin()) {
register_activation_hook(__FILE__,'install_id_for_blogs');
}
// we are not in network admin, so we run regular activation script
else {
register_activation_hook(__FILE__,'ign_pre_install');
}
}
else {
register_activation_hook(__FILE__,'ign_pre_install');
register_activation_hook(__FILE__,'ign_set_defaults');
}
if (is_id_network_activated() && is_id_pro()) {
add_action('wpmu_new_blog', 'ign_pre_install', 1, 1);
add_action('wpmu_new_blog', 'ign_set_defaults');
}
function install_id_for_blogs() {
global $wpdb;
$sql = 'SELECT * FROM '.$wpdb->base_prefix.'blogs';
$res = $wpdb->get_results($sql);
foreach ($res as $blog) {
ign_pre_install($blog->blog_id);
}
}
function ign_pre_install ($blog_id = null) {
global $wpdb;
global $ign_db_version;
global $charset_collate;
if (!empty($blog_id) && is_id_network_activated() && is_id_pro()) {
if ($blog_id == 1) {
$wpdb->base_prefix = $wpdb->base_prefix;
}
else {
$wpdb->base_prefix = $wpdb->base_prefix.$blog_id.'_';
}
}
else if (!empty($blog_id) && is_id_pro()) {
if ($blog_id == 1) {
$wpdb->base_prefix = $wpdb->prefix;
}
else {
$wpdb->base_prefix = $wpdb->prefix.$blog_id.'_';
}
}
else {
$wpdb->base_prefix = $wpdb->prefix;
}
$table_name = $wpdb->base_prefix . "ign_settings";
$sql = "CREATE TABLE " . $table_name . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
theme_value VARCHAR( 250 ) NOT NULL DEFAULT 'style1',
theme_choices TEXT (65535),
prod_page_fb TINYINT( 1 ) NOT NULL,
prod_page_twitter TINYINT( 1 ) NOT NULL,
prod_page_linkedin TINYINT( 1 ) NOT NULL,
prod_page_google TINYINT( 1 ) NOT NULL,
prod_page_pinterest TINYINT( 1 ) NOT NULL,
id_widget_logo_on TINYINT( 1 ) NOT NULL DEFAULT '1',
id_widget_link VARCHAR( 200 ) NOT NULL DEFAULT 'http://ignitiondeck.com',
ask_a_question TINYINT( 1 ) NOT NULL,
ask_email VARCHAR( 100 ) NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
update_option("ign_db_version", $ign_db_version);
$table_name = $wpdb->base_prefix . "ign_products";
$sql = "CREATE TABLE " . $table_name . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
product_image VARCHAR( 250 ) NOT NULL ,
product_name VARCHAR( 250 ) NOT NULL ,
product_url VARCHAR( 250 ) NOT NULL ,
ign_product_title VARCHAR ( 250 ) NOT NULL,
ign_product_limit VARCHAR ( 250 ),
product_details TEXT NOT NULL ,
product_price DOUBLE NOT NULL ,
goal DOUBLE NOT NULL ,
created_at DATETIME,
UNIQUE KEY id (id)
) $charset_collate;";
dbDelta($sql);
$table_name = $wpdb->base_prefix . "ign_product_settings";
$sql = "CREATE TABLE " . $table_name . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
product_id VARCHAR( 250 ) NOT NULL,
mailchimp_api_key VARCHAR( 250 ) NOT NULL,
mailchimp_list_id VARCHAR( 250 ) NOT NULL,
aweber_email VARCHAR( 250 ) NOT NULL,
active_mailtype enum('mailchimp','aweber') NOT NULL,
form_settings TEXT NOT NULL,
paypal_email VARCHAR( 250 ) NOT NULL,
currency_code VARCHAR( 10 ) NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
dbDelta($sql);
$pay_info = $wpdb->base_prefix . "ign_pay_info";
$sql = "CREATE TABLE " . $pay_info . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
first_name VARCHAR( 250 ) NOT NULL ,
last_name VARCHAR( 250 ) NOT NULL ,
email VARCHAR( 250 ) NOT NULL ,
address VARCHAR( 250 ) NOT NULL ,
country VARCHAR( 250 ) NOT NULL ,
state VARCHAR( 250 ) NOT NULL ,
city VARCHAR( 250 ) NOT NULL ,
zip VARCHAR( 250 ) NOT NULL ,
product_id INT( 20 ) NOT NULL ,
transaction_id varchar( 250 ) NOT NULL,
preapproval_key varchar (250) NOT NULL,
product_level INT( 2 ) NOT NULL,
prod_price VARCHAR(200) NOT NULL,
status VARCHAR( 250 ) NOT NULL DEFAULT 'P',
created_at DATETIME,
UNIQUE KEY id (id)
) $charset_collate;";
dbDelta($sql);
// Payment selection settings
$pay_method_selection = $wpdb->base_prefix . "ign_pay_selection";
$sql_pay_sett = "CREATE TABLE " . $pay_method_selection . " (
id MEDIUMINT( 9 ) NOT NULL AUTO_INCREMENT,
payment_gateway VARCHAR( 100 ) NOT NULL,
modified_date DATETIME NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
dbDelta($sql_pay_sett);
// Standard Payment settings
$pay_settings = $wpdb->base_prefix . "ign_pay_settings";
$sql_pay_sett = "CREATE TABLE " . $pay_settings . " (
id MEDIUMINT( 9 ) NOT NULL AUTO_INCREMENT,
identity_token VARCHAR( 250 ) NOT NULL,
paypal_email VARCHAR( 250 ) NOT NULL,
paypal_override TINYINT( 1 ) NOT NULL,
paypal_mode ENUM('sandbox','production') NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
dbDelta($sql_pay_sett);
// Payment settings for Adaptive payments
$adaptive_pay_settings = $wpdb->base_prefix . "ign_adaptive_pay_settings";
$sql_pay_sett = "CREATE TABLE " . $adaptive_pay_settings . " (
id MEDIUMINT( 9 ) NOT NULL AUTO_INCREMENT,
paypal_email VARCHAR( 100 ) NOT NULL,
app_id VARCHAR( 100 ) NOT NULL,
api_username VARCHAR( 100 ) NOT NULL,
api_password VARCHAR( 100 ) NOT NULL,
api_signature VARCHAR( 200 ) NOT NULL,
pre_approval_key VARCHAR( 100 ) NOT NULL,
paypal_mode ENUM('sandbox','production') NOT NULL,
fund_type ENUM('standard', 'fixed') NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
dbDelta($sql_pay_sett);
// Aweber Options
$aweber_settings = $wpdb->base_prefix . "ign_aweber_settings";
$sql_aweber = "CREATE TABLE " . $aweber_settings . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
list_email VARCHAR( 100 ) NOT NULL,
is_active TINYINT( 2 ) NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
dbDelta($sql_aweber);
// Mailchimp
$mailchimp_subscription = $wpdb->base_prefix . "ign_mailchimp_subscription";
$sql_pay_sett = "CREATE TABLE " . $mailchimp_subscription . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
api_key VARCHAR( 250 ) NOT NULL ,
list_id VARCHAR( 250 ) NOT NULL,
region VARCHAR( 50 ) NOT NULL ,
is_active TINYINT( 2 ) NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
dbDelta($sql_pay_sett);
$form_settings = $wpdb->base_prefix . "ign_form";
$sql = "CREATE TABLE " . $form_settings . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
form_settings TEXT NOT NULL ,
UNIQUE KEY id (id)
) $charset_collate;";
dbDelta($sql);
$ign_form_settings = $wpdb->base_prefix . "ign_prod_default_settings";
$sql = "CREATE TABLE " . $ign_form_settings . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
form_settings TEXT NOT NULL,
currency_code VARCHAR( 10 ) NOT NULL DEFAULT 'USD',
UNIQUE KEY id (id)
) $charset_collate;";
dbDelta($sql);
$ign_deck_settings = $wpdb->base_prefix."ign_deck_settings";
$sql = "CREATE TABLE ".$ign_deck_settings." (
id mediumint(9) NOT NULL AUTO_INCREMENT,
attributes LONGTEXT NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
dbDelta($sql);
$url = dirname(dirname(dirname(dirname(__FILE__))));
if (file_exists($url.'/log.txt')) {
unlink($url.'/log.txt');
}
do_action('id_after_install');
}
function ign_set_defaults() {
global $wpdb;
global $ign_installed_ver;
$check_db = 'SELECT id_widget_logo_on FROM '.$wpdb->prefix.'ign_settings WHERE id="1"';
$return_check = $wpdb->get_row($check_db);
if( !isset($return_check) ) {
$sql = "INSERT INTO ".$wpdb->prefix."ign_settings (id_widget_logo_on) VALUES ('1')";
$update = $wpdb->query($sql);
}
update_option('id_email_inactive', 1);
do_action('id_set_defaults');
// convert image1 to featured image
$projects = ID_Project::get_project_posts();
if (!empty($projects)) {
global $wpdb;
foreach ($projects as $project) {
$post_id = $project->ID;
$thumb = get_the_post_thumbnail($post_id);
if (empty($thumb)) {
$image1 = get_post_meta($post_id, 'ign_product_image1', true);
$sql = $wpdb->prepare('SELECT ID FROM '.$wpdb->prefix.'posts WHERE guid = %s', $image1);
$res = $wpdb->get_row($sql);
if (!empty($res)) {
$attachment_id = $res->ID;
set_post_thumbnail($post_id, $attachment_id);
}
}
}
}
if (empty($ign_installed_ver)) {
update_option('idcf_auto_insert', 1);
}
}
//register_deactivation_hook( __FILE__, 'ignitiondeck_deactivate' );
function ignitiondeck_deactivate(){
global $wpdb;
$check = 'SELECT * FROM '.$wpdb->prefix.'ign_pay_settings WHERE id = 1';
$return_check = $wpdb->get_results($check);
if (isset($return_check->charge_mode)) {
$sql = 'ALTER TABLE '.$wpdb->prefix.'ign_pay_settings DROP COLUMN charge_mode';
$wpdb->query($sql);
}
$check2 = 'SELECT * FROM '.$wpdb->prefix.'ign_adaptive_pay_settings WHERE id = 1';
$return_check2 = $wpdb->get_results($check2);
if (isset($return_check2->charge_mode)) {
$sql2 = 'ALTER TABLE '.$wpdb->prefix.'ign_adaptive_pay_settings DROP COLUMN charge_mode';
$wpdb->query($sql2);
}
}
if (is_id_network_activated() && is_id_pro()) {
add_action('delete_blog', 'ignitiondeck_uninstall', 1, 1);
register_uninstall_hook(__FILE__,'id_remove_all_traces');
}
else {
register_uninstall_hook(__FILE__, 'ignitiondeck_uninstall');
}
function id_remove_all_traces() {
global $wpdb;
$sql = 'SELECT * FROM '.$wpdb->base_prefix.'blogs';
$res = $wpdb->get_results($sql);
foreach ($res as $blog) {
ignitiondeck_uninstall($blog->blog_id);
}
}
function ignitiondeck_uninstall($blog_id = null) {
global $wpdb;
if (!empty($blog_id) && is_id_network_activated() && is_id_pro()) {
if ($blog_id == 1) {
$wpdb->base_prefix = $wpdb->base_prefix;
}
else {
$wpdb->base_prefix = $wpdb->base_prefix.$blog_id.'_';
}
}
else if (!empty($blog_id) && is_id_pro()) {
if ($blog_id == 1) {
$wpdb->base_prefix = $wpdb->prefix;
}
else {
$wpdb->base_prefix = $wpdb->prefix.$blog_id.'_';
}
}
else {
$wpdb->base_prefix = $wpdb->prefix;
}
$sql = 'DROP TABLE IF EXISTS '.$wpdb->base_prefix.'ign_adaptive_pay_settings, '.$wpdb->base_prefix.'ign_aweber_settings, '.$wpdb->base_prefix
.'ign_customers, '.$wpdb->base_prefix.'ign_facebookapp_settings, '.$wpdb->base_prefix.'ign_form, '.$wpdb->base_prefix.'ign_mailchimp_subscription, '.
$wpdb->base_prefix.'ign_pay_info, '.$wpdb->base_prefix.'ign_pay_selection, '.$wpdb->base_prefix.'ign_pay_settings, '.$wpdb->base_prefix
.'ign_products, '.$wpdb->base_prefix.'ign_product_settings, '.$wpdb->base_prefix.'ign_prod_default_settings, '.$wpdb->base_prefix.'ign_questions, '.
$wpdb->base_prefix.'ign_settings, '.$wpdb->base_prefix.'ign_twitterapp_settings, '.$wpdb->base_prefix.'ign_deck_settings';
$res = $wpdb->query($sql);
$options = array(
'id_license_key',
'is_id_pro',
'is_id_basic',
'id_settings_option',
'id_defaults_notice',
'id_settings_notice',
'id_products_notice',
'id_purchase_default',
'id_ty_default',
'id_email_inactive',
'ign_db_version',
);
foreach ($options as $option) {
delete_option($option);
}
ID_Project::delete_project_posts();
}
/*
End Pro Activation, Multisite Activation, Standard Activation
*/
define( 'ID_PATH', plugin_dir_path(__FILE__) );
include_once 'classes/class-id_form.php';
include_once 'classes/class-project_widget.php';
include_once 'classes/class-id_project.php';
include_once 'classes/class-deck.php';
include_once 'classes/class-id_purchase_form.php';
if (is_id_pro()) {
include_once 'classes/class-id_fes.php';
}
include_once 'classes/class-id_order.php';
include_once 'ignitiondeck-functions.php';
include_once 'ignitiondeck-admin.php';
include_once 'ignitiondeck-postmeta.php';
include_once 'ignitiondeck-shortcodes.php';
//include_once 'ignitiondeck-globals.php';
if (is_id_pro()) {
include_once 'ignitiondeck-enterprise.php';
}
include_once 'ignitiondeck-update.php';
$active_plugins = get_option('active_plugins', true);
if (in_array('ignitiondeck/idf.php', $active_plugins) && is_id_licensed()) {
include_once plugin_dir_path(dirname(__FILE__)).'/ignitiondeck/idf.php';
}
else if (is_multisite() && is_id_network_activated() && file_exists(plugin_dir_path(dirname(__FILE__)).'/ignitiondeck/idf.php')) {
include_once plugin_dir_path(dirname(__FILE__)).'/ignitiondeck/idf.php';
}
if (idf_exists()) {
include_once 'idf/ignitiondeck-idf.php';
}
if (idf_exists() && idf_platform() == 'idc') {
include_once 'ignitiondeck-idc.php';
}
include_once 'ignitiondeck-api.php';
include_once 'ignitiondeck-filters.php';
/**
* Register ignitiondeck domain for translation texts
*/
add_action( 'init', 'languageLoad' );
function languageLoad() {
load_plugin_textdomain( 'ignitiondeck', false, dirname( plugin_basename( __FILE__ ) ).'/languages/' );
}
require ('languages/text_variables.php');
//Not currently in use
add_action( 'init', 'ignitiondeck_init' );
function ignitiondeck_init(){
}
// Deregister Woo Media Uploader on Project Pages
function disable_woo_media($hook) {
global $post_type;
if ($post_type == 'ignition_product') {
wp_dequeue_script('woo-medialibrary-uploader');
wp_deregister_script('woo-medialibrary-uploader');
}
}
add_action('wp_print_scripts', 'disable_woo_media', 20);
/**
* Include stylesheets
*/
function enqueue_front_css(){
$theme_name = getThemeFileName();
wp_register_style('ignitiondeck-base', plugins_url('/ignitiondeck-base.css', __FILE__));
if (file_exists(ID_PATH.'/ignitiondeck-custom.css')) {
wp_register_style('ignitiondeck-custom', plugins_url('/ignitiondeck-custom.css', __FILE__));
wp_enqueue_style('ignitiondeck-custom');
}
wp_register_style($theme_name, plugins_url('/skins/'.$theme_name.'.css', __FILE__));
wp_enqueue_style('ignitiondeck-base');
wp_enqueue_style($theme_name);
}
add_action('wp_enqueue_scripts', 'enqueue_front_css');
/**
* includeJavascript files
*/
function enqueue_front_js() {
wp_register_script( 'ignitiondeck', plugins_url('/js/ignitiondeck.js', __FILE__));
wp_register_script('idlightbox', plugins_url('/js/idlightbox.js', __FILE__));
wp_register_script( 'ddslick', plugins_url('/js/jquery.ddslick.min.js', __FILE__));
wp_enqueue_script('jquery');
wp_enqueue_script( 'ddslick');
wp_enqueue_script( 'ignitiondeck' );
wp_enqueue_script('idlightbox');
$settings = getSettings();
if ($settings->prod_page_fb == 1) {
global $post;
global $wpdb;
if (isset($post)) {
$post_name = $post->post_name;
$sql = $wpdb->prepare('SELECT * FROM '.$wpdb->prefix.'postmeta WHERE meta_key = %s AND meta_value=%s', 'ign_post_name', $post_name);
$res = $wpdb->get_results($sql);
if (isset($res) && !isset($_GET['purchaseform'])) {
wp_register_script( 'facebook', plugins_url('/js/facebook.js', __FILE__));
wp_enqueue_script( 'facebook');
}
else if (isset($post->post_type) && $post->post_type == 'ignition_product' && !isset($_GET['purchaseform'])) {
wp_register_script( 'facebook', plugins_url('/js/facebook.js', __FILE__));
wp_enqueue_script( 'facebook');
}
}
}
if (is_multisite() && is_id_network_activated()) {
$id_ajaxurl = network_home_url('/', 'relative').'wp-admin/admin-ajax.php';
}
else {
$id_ajaxurl = site_url('/', 'relative').'wp-admin/admin-ajax.php';
}
$id_siteurl = site_url('/');
wp_localize_script('ignitiondeck', 'id_ajaxurl', $id_ajaxurl);
wp_localize_script('ignitiondeck', 'id_siteurl', $id_siteurl);
}
add_action('wp_enqueue_scripts', 'enqueue_front_js');
// Initializing our widget in the admin area
add_action( 'widgets_init', 'showproduct_load_widgets' );
function showproduct_load_widgets() {
register_widget( 'Product_Widget' );
}
/**
* Proccess Product buyout
*/
function productBuyout(){
require ('languages/text_variables.php');
if(isset($_POST['submitPaymentPopup'])){
$first_name = '';
$last_name = '';
$email = '';
$address = '';
$country = '';
$state = '';
$city = '';
$zip = '';
$product_id = 0;
$level = 0;
$price = '0.00';
// Store all the required variables in SESSION to get them later
session_start();
if (isset($_POST['first_name'])) {
$first_name = esc_attr($_POST['first_name']);
}
if (isset($_POST['last_name'])) {
$last_name = esc_attr($_POST['last_name']);
}
if (isset($_POST['email'])) {
$email = esc_attr($_POST['email']);
}
if (isset($_POST['address'])) {
$address = esc_attr($_POST['address']);
}
if (isset($_POST['country'])) {
$country = esc_attr($_POST['country']);
}
if (isset($_POST['state'])) {
$state = esc_attr($_POST['state']);
}
if (isset($_POST['city'])) {
$city = esc_attr($_POST['city']);
}
if (isset($_POST['zip'])) {
$zip = esc_attr($_POST['zip']);
}
if (isset($_POST['project_id'])) {
$product_id = absint($_POST['project_id']);
}
if (isset($_POST['level'])) {
$level = absint($_POST['level']);
}
if (isset($_POST['price'])) {
$price = esc_attr(str_replace(',', '', $_POST['price']));
}
$payment_variables = array(
"first_name" => $first_name,
"last_name" => $last_name,
"email" => $email,
"address" => $address,
"country" => $country,
"state" => $state,
"city" => $city,
"zip" => $zip,
"product_id" => $product_id,
"level_select" => $level,
"price" => $price
);
$_SESSION['ig_payment_variables'] = serialize($payment_variables);
$project_id = $_POST['project_id'];
$project = new ID_Project($project_id);
$post_id = $project->get_project_postid();
$paymentSettings = getPaymentSettings();
// use this for default
$paypal_email = $paymentSettings->paypal_email;
$productDetails = $project->the_project();
//GETTING product default settings
$default_prod_settings = getProductDefaultSettings();
$prod_settings = $default_prod_settings;
// see if we have custom settings
$custom_settings = $project->get_project_settings();
if (!empty($custom_settings)) {
$prod_settings = $custom_settings;
if (!empty($custom_settings->paypal_email)) {
$paypal_email = $custom_settings->paypal_email;
}
}
if ($paymentSettings->paypal_mode == "sandbox")
$url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
else
$url = "https://www.paypal.com/cgi-bin/webscr";
$notifyURL = site_url(). "/?ipn_handler=1&payment_vars=".urlencode($_SESSION['ig_payment_variables']);
include_once 'templates/_paypalForm.php';
}
}
if (is_id_licensed()) {
add_action('init', 'productBuyout');
}
/*
* Function for catching the submission of popup, for using Paypal Adaptive Payments
*/
function projectPurchaseAdaptive() {
if (isset($_POST)) {
//exit;
}
if (isset($_POST['submitPaymentAdaptive'])) {
// Store all the required variables in SESSION to get them later
session_start();
$project_id = $_POST['project_id'];
$project = new ID_Project($project_id);
$payment_variables = array(
"fname" => (isset($_POST['first_name']) ? $_POST['first_name'] : ''),
"lname" => (isset($_POST['last_name']) ? $_POST['last_name'] : ''),
"email" => (isset($_POST['email']) ? $_POST['email'] : ''),
"address" => (isset($_POST['address']) ? $_POST['address'] : ''),
"country" => (isset($_POST['country']) ? $_POST['country'] : ''),
"state" => (isset($_POST['state']) ? $_POST['state'] : ''),
"city" => (isset($_POST['city']) ? $_POST['city'] : ''),
"zip" => (isset($_POST['zip']) ? $_POST['zip'] : ''),
"product_id" => (isset($_POST['project_id']) ? absint($_POST['project_id']) : ''),
"level" => (isset($_POST['level']) ? absint($_POST['level']) : ''),
"prod_price" => (isset($_POST['price']) ? str_replace(',', '', $_POST['price']) : '')
);
$_SESSION['ig_payment_variables'] = http_build_query($payment_variables);
//print_r($payment_variables);
//echo $_SESSION['ig_payment_variables'];
// Getting the Adaptive payment settings
$adaptive_pay_settings = getAdaptivePayPalSettings();
require_once 'paypal/lib/AdaptivePayments.php';
// GETTING product default settings
$default_prod_settings = getProductDefaultSettings();
// Getting product settings and if they are not present, set the default settings as product settings
$prod_settings = $project->get_project_settings();
if (empty($prod_settings))
$prod_settings = $default_prod_settings;
# Endpoint: this is the server URL which you have to connect for submitting your API request.
//Chanege to https://svcs.paypal.com/ to go live */
if ($adaptive_pay_settings->paypal_mode == "sandbox") {
define('API_BASE_ENDPOINT', 'https://svcs.sandbox.paypal.com/');
define('PAYPAL_REDIRECT_URL', 'https://www.sandbox.paypal.com/webscr&cmd=');
$app_id = "APP-80W284485P519543T";
}
else {
define('API_BASE_ENDPOINT', 'https://svcs.paypal.com/');
define('PAYPAL_REDIRECT_URL', 'https://www.paypal.com/webscr&cmd=');
$app_id = $adaptive_pay_settings->app_id;
}
/***** 3token API credentials *****************/
define('API_AUTHENTICATION_MODE','3token');
define('API_USERNAME', $adaptive_pay_settings->api_username);
define('API_PASSWORD', $adaptive_pay_settings->api_password);
define('API_SIGNATURE', $adaptive_pay_settings->api_signature);
define('X_PAYPAL_APPLICATION_ID', $app_id);
require_once 'paypal/lib/Config/paypal_sdk_clientproperties.php';
//print_r($adaptive_pay_settings);
// Setting the necessary variables for the payment
$returnURL = site_url()."/?payment_success=1&product_id=".$_POST['project_id'];
$cancelURL = site_url(). "/?payment_cancel=1" ;
$notifyURL = esc_url(site_url()). "/?ipn_handler=1&".$_SESSION['ig_payment_variables'];
$currencyCode = $prod_settings->currency_code;
$email = esc_attr($_POST['email']);
$preapprovalKey = "";
$requested = '';
$payRequest = new PayRequest();
$payRequest->actionType = "PAY";
$payRequest->cancelUrl = $cancelURL ;
$payRequest->returnUrl = $returnURL;
$payRequest->ipnNotificationUrl = $notifyURL;
$payRequest->clientDetails = new ClientDetailsType();
$payRequest->clientDetails->applicationId = $app_id; //"APP-1JE4291016473214C";
//$payRequest->clientDetails->deviceId = DEVICE_ID;
$payRequest->clientDetails->ipAddress = $_SERVER['REMOTE_ADDR'];
$payRequest->currencyCode = $currencyCode;
$payRequest->senderEmail = $email;
$payRequest->requestEnvelope = new RequestEnvelope();
$payRequest->requestEnvelope->errorLanguage = "en_US";
//$payRequest->preapprovalKey = "PA-16707604HP296522Y";
//print_r($payRequest);
if($preapprovalKey !== "")
{
$payRequest->preapprovalKey = $preapprovalKey ;
//echo $preapprovalKey."keyhere";
}
$receiver1 = new receiver();
$receiver1->email = $adaptive_pay_settings->paypal_email;
$receiver1->amount = esc_attr(str_replace(',', '', $_POST['price']));
$payRequest->receiverList = new ReceiverList();
$payRequest->receiverList = array($receiver1);
/* Make the call to PayPal to get the Pay token
* If the API call succeded, then redirect the buyer to PayPal
* to begin to authorize payment. If an error occured, show the
* resulting errors
*/
$ap = new AdaptivePayments();
//print_r($ap);
$response=$ap->Pay($payRequest);
//echo "end of line<br/>";
if(strtoupper($ap->isSuccess) == 'FAILURE')
{
//echo "inside failure<br/>";
$fault = $ap->getLastError();
if (isset($fault)) {
$errors = $fault->error;
}
if (count($errors) > 1) {
$errors_content = array();
foreach ($errors as $error) {
$errors_content[] = $error->message;
}
}
else {
$errors_content = $errors->message;
}
// For error handling
/*if (is_object($fault->error))
{
//$errors_content = '<table width =\"450px\" align=\"center\">';
$errors_content;
$errors_content = '';
foreach($fault->error as $err) {
//$errors_content .= '<tr>';
//$errors_content .= '<td>';
//$errors_content .= 'Error ID: ' . $err->errorId . '<br />';
//$errors_content .= 'Domain: ' . $err->domain . '<br />';
//$errors_content .= 'Severity: ' . $err->severity . '<br />';
//$errors_content .= 'Category: ' . $err->category . '<br />';
$errors_content .= $err . "<br />";
if(empty($err->parameter)) {
//$errors_content .= '<br />';
}
else {
//$errors_content .= 'Parameter: ' . $err->parameter . '<br /><br />';
}
//$errors_content .= '</td>';
//$errors_content .= '</tr>';
}
//$errors_content .= '</table>';
}
else
{
$errors_content = "";
//$errors_content .= 'Error ID: ' . $fault->error->errorId . '<br />';
//$errors_content .= 'Domain: ' . $fault->error->domain . '<br />';
//$errors_content .= 'Severity: ' . $fault->error->severity . '<br />';
//$errors_content .= 'Category: ' . $fault->error->category . '<br />';
$errors_content .= $fault->error->message . '<br />';
if(empty($fault->error->parameter)) {
//$errors_content .= '</br>';
}
else {
//$errors_content .= 'Parameter: ' . $fault->error->parameter . '<br /><br />';
}
}*/
if ($_POST['price'] > 0) {
$_SESSION['paypal_errors_content'] = $errors_content;
}
else {
$_SESSION['paypal_errors_content'] = "Please enter an amount greater than 0.00";
}
}
else
{
//echo "inside non-fail<br/>";
$_SESSION['payKey'] = $response->payKey;
if($response->paymentExecStatus == "COMPLETED")
{
//$location = "PaymentDetails.php";
$success_url = site_url()."/?payment_success=1&product_id=".$_POST['project_id'];
echo '<script type="text/javascript">window.location="'.$success_url.'";</script>';
}
else
{
$token = $response->payKey;
$payPalURL = PAYPAL_REDIRECT_URL.'_ap-payment&paykey='.$token;
echo '<script type="text/javascript">window.location="'.$payPalURL.'";</script>';
//header("Location: ".$payPalURL);
}
}
}
}
if (is_id_licensed()) {
add_action('init', 'projectPurchaseAdaptive');
}
function adaptivePreapproval() {
if (isset($_POST['btnSubmitPreapproval'])) {
global $wpdb;
$tz = get_option('timezone_string');
if (empty($tz)) {
$tz = 'UTC';
}
date_default_timezone_set($tz);
//print_r($_POST);
session_start();
$payment_variables = array(
"fname" => $_POST['first_name'],
"lname" => $_POST['last_name'],
"email" => $_POST['email'],
"address" => $_POST['address'],
"country" => $_POST['country'],
"state" => $_POST['state'],
"city" => $_POST['city'],
"zip" => $_POST['zip'],
"product_id" => absint($_POST['project_id']),
"level" => absint($_POST['level']),
"prod_price" => str_replace(',', '', $_POST['price'])
);
$preapproval_key = "";
$project = new ID_Project($variables['product_id']);
$post_id = $project->get_project_postid();
$product_name = get_the_title($post_id);
$_SESSION['ig_payment_variables'] = http_build_query($payment_variables);
// Getting the Adaptive payment settings
$adaptive_pay_settings = getAdaptivePayPalSettings();
require_once 'paypal/lib/AdaptivePayments.php';
// GETTING product default settings
$default_prod_settings = getProductDefaultSettings();
// Getting product settings and if they are not present, set the default settings as product settings
$prod_settings = getProductSettings(absint(esc_attr($_POST['project_id'])));
if (empty($prod_settings)) {
$prod_settings = $default_prod_settings;
}
# Endpoint: this is the server URL which you have to connect for submitting your API request.
//Chanege to https://svcs.paypal.com/ to go live */
if ($adaptive_pay_settings->paypal_mode == "sandbox") {
define('API_BASE_ENDPOINT', 'https://svcs.sandbox.paypal.com/AdaptivePayments/Preapproval/');
define('PAYPAL_REDIRECT_URL', 'https://www.sandbox.paypal.com/webscr&cmd=_ap-preapproval&preapprovalkey='.$preapproval_key);
$app_id = "APP-80W284485P519543T";
}
else {
define('API_BASE_ENDPOINT', 'https://svcs.paypal.com/AdaptivePayments/Preapproval/');
define('PAYPAL_REDIRECT_URL', 'https://www.paypal.com/webscr&cmd=_ap-preapproval&preapprovalkey='.$preapproval_key);
$app_id = $adaptive_pay_settings->app_id;
}
/***** 3token API credentials *****************/
define('API_AUTHENTICATION_MODE','3token');
define('API_USERNAME', $adaptive_pay_settings->api_username);
define('API_PASSWORD', $adaptive_pay_settings->api_password);
define('API_SIGNATURE', $adaptive_pay_settings->api_signature);
define('X_PAYPAL_APPLICATION_ID', $app_id);
require_once 'paypal/lib/Config/paypal_sdk_clientproperties.php';
$returnURL = site_url()."/?payment_success=1&product_id=".absint(esc_attr($_POST['project_id']));
$cancelURL = site_url(). "/?payment_cancel=1" ;
$notifyURL = esc_url(site_url()). "/?ipn_handler=1&type=paypal_preauth&".$_SESSION['ig_payment_variables'];
$currencyCode = $prod_settings->currency_code;
$senderEmail = esc_attr($_POST['email']);
$preauth = new PreapprovalRequest();
$preauth->cancelUrl = $cancelURL;
$preauth->ipnNotificationUrl = $notifyURL;
$preauth->returnUrl = $returnURL;
$preauth->currencyCode = $currencyCode;
$preauth->maxNumberOfPayments = "1";
$preauth->maxNumberofPaymentsPerPeriod = 1;
$preauth->endingDate = date("Y-m-d\Z", strtotime("+ 364 day"));
$preauth->startingDate = date('Y-m-d\Z');
$preauth->maxTotalAmountOfAllPayments = esc_attr(str_replace(',', '', $_POST['price']));
$preauth->memo = $product_name.' pledge of '.number_format($_POST['price'], 2, '.', ',').' '.$currencyCode;
$preauth->clientDetails = new ClientDetailsType();
$preauth->clientDetails->applicationId = $app_id;
//$preauth->clientDetails->deviceId = DEVICE_ID;
//$preauth->clientDetails->ipAddress = "127.0.0.1";
//$preapprovalRequest->maxNumberOfPayments = $maxNumberOfPayments;
//$preapprovalRequest->maxTotalAmountOfAllPayments = $maxTotalAmountOfAllPayments;
$preauth->requestEnvelope = new RequestEnvelope();
$preauth->requestEnvelope->errorLanguage = "en_US";
$preauth->senderEmail = $senderEmail;
$ap = new AdaptivePayments();
$response=$ap->Preapproval($preauth);
//print_r($preauth);
//print_r($response);
//print_r($ap);
if(strtoupper($ap->isSuccess) == 'FAILURE')
{
$fault = $ap->getLastError();
// For error handling
if(is_array($fault->error))
{
$errors_content = '<table width =\"450px\" align=\"center\">';
foreach($fault->error as $err) {
$errors_content .= '<tr>';
$errors_content .= '<td>';
$errors_content .= 'Error ID: ' . $err->errorId . '<br />';
$errors_content .= 'Domain: ' . $err->domain . '<br />';
$errors_content .= 'Severity: ' . $err->severity . '<br />';
$errors_content .= 'Category: ' . $err->category . '<br />';
$errors_content .= 'Message: ' . $err->message . '<br />';
if(empty($err->parameter)) {
$errors_content .= '<br />';
}
else {
$errors_content .= 'Parameter: ' . $err->parameter . '<br /><br />';
}
$errors_content .= '</td>';
$errors_content .= '</tr>';
}
$errors_content .= '</table>';
}
else
{
$errors_content = 'Error ID: ' . $fault->error->errorId . '<br />';
$errors_content .= 'Domain: ' . $fault->error->domain . '<br />';
$errors_content .= 'Severity: ' . $fault->error->severity . '<br />';
$errors_content .= 'Category: ' . $fault->error->category . '<br />';
$errors_content .= 'Message: ' . $fault->error->message . '<br />';
if(empty($fault->error->parameter)) {
$errors_content .= '</br>';
}
else {
$errors_content .= 'Parameter: ' . $fault->error->parameter . '<br /><br />';
}
}
$_SESSION['paypal_errors_content'] = $errors_content;
}
else
{
// Redirect to paypal.com here
$_SESSION['preapprovalKey'] = $response->preapprovalKey;
$token = $response->preapprovalKey;
$payPalURL = PAYPAL_REDIRECT_URL.'_ap-preapproval&preapprovalkey='.$token;
echo '<script type="text/javascript">window.location="'.$payPalURL.'";</script>';
}
}
}
if (is_id_licensed()) {
add_action('init', 'adaptivePreapproval');
}
/*
* Function for adding the Order if the payment is made successfully
*/
function paymentSuccess() {
if (isset($_GET['payment_success']) || isset($_GET['merchant_return_link'])) {
do_action('id_payment_return');
$prod_id = esc_attr($_GET['product_id']);
$ty_url = getThankYouURLfromType($prod_id, "thank_you_url");
echo '<script type="text/javascript">window.location="'.$ty_url.'";</script>';