forked from Ontraport/PilotPress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpilotpress.php
executable file
·3603 lines (3040 loc) · 115 KB
/
pilotpress.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: PilotPress
Plugin URI: http://ontraport.com/
Description: ONTRAPORT WordPress integration plugin.
Version: 1.9.8
Author: ONTRAPORT Inc.
Author URI: http://ontraport.com/
Text Domain: pilotpress
Copyright: 2017, Ontraport
*/
if(defined("ABSPATH")) {
include_once(ABSPATH.WPINC.'/class-http.php');
global $wp_version;
if (version_compare($wp_version,"3.1","<"))
{
include_once(ABSPATH.WPINC.'/registration.php');
}
register_activation_hook(__FILE__, "enable_pilotpress");
register_deactivation_hook(__FILE__, "disable_pilotpress");
$pilotpress = new PilotPress;
//create and load up the PilotPress Text Widget statically
add_action( 'widgets_init',array( 'PilotPress_Widget', 'register' ) );
//Hook into the admin footer so as to load this JS
add_action( 'admin_footer-widgets.php' , "pilotpress_widget_js" );
}
class PilotPress {
const VERSION = "1.9.8";
const WP_MIN = "3.6";
const NSPACE = "_pilotpress_";
const URL_JQCSS = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/smoothness/jquery-ui.css";
const AUTH_SALT = "M!E%VxpKvuQHn!PTPOTohtLbnOl&)5&0mb(Uj^c#Zz!-0898yfS#7^xttNW(x1ia";
public $system_pages = array();
public static $brand = "OfficeAutoPilot";
public static $brand_url = "OfficeAutoPilot.com";
public static $url_api = "https://www1.moon-ray.com/api.php";
public static $backup_url_api = "https://web.moon-ray.com/api.php";
public static $url_tjs = "https://www1.moon-ray.com/tracking.js";
public static $url_jswpcss = "https://forms.moon-ray.com/v2.4/include/scripts/moonrayJS/moonrayJS-only-wp-forms.css";
public static $url_mrcss = "https://forms.moon-ray.com/v2.4/include/minify/?g=moonrayCSS";
/* Various runtime, shared variables */
private $uri;
private $metaboxes;
private $settings;
private $status = 0;
private $do_login = false;
private $homepage_url;
private $incrementalnumber = 1;
private $tagsSequences;
//Global ppprotect-category reference
private $ppp;
function __construct() {
// Includes new ppprotect class that has enhanced protections for things like categories etc.
require_once( plugin_dir_path( __FILE__ ) . 'ppprotect-categories.php');
$this->ppp = new PPProtect();
$this->bind_hooks(); /* hook into WP */
$this->start_session(); /* use sessions, controversial but easy */
$this->ppp->ppprotectHooks();
/* Used for keeping a record of the current shortcodes to be merged */
$this->shortcodeFields = array();
/* use this var, it's handy */
$this->uri = get_option('siteurl').'/wp-content/plugins/'.dirname(plugin_basename(__FILE__));
/* the various Centers */
$this->centers = array(
"customer_center" => array(
"title" => "Customer Center",
"slug" => "customer-center",
"content" => "This content will be replaced by the Customer Center"
),
"affiliate_center" => array(
"title" => "Partner Center",
"slug" => "affiliate-center",
"content" => "This content will be replaced by the Partner Center"
),
);
}
/* this function loads up runtime settings from API or transient caches for both plugin and user (if logged in) */
function load_settings() {
global $wpdb;
$this->system_pages = $this->get_system_pages();
if($this->get_setting("disablecaching") && get_transient('pilotpress_cache') && !isset($_SESSION["rehash"])) {
$this->settings = get_transient('pilotpress_cache');
if(get_transient("usertags_".$this->get_setting("contact_id", "user"))) {
$tags = get_transient("usertags_".$this->get_setting("contact_id", "user"));
if(is_array($tags["tags"])) {
$this->settings["user"]["tags"] = $tags["tags"];
}
}
$this->status = 1;
} else {
if(isset($_SESSION["rehash"])) {
unset($_SESSION["rehash"]);
}
$this->settings["wp"] = array();
$this->settings["wp"]["post_types"] = array();
$this->settings["wp"]["permalink"] = get_option('permalink_structure');
$this->settings["wp"]["template"] = get_option('template');
$this->settings["wp"]["plugins"] = get_option('active_plugins');
$this->settings["wp"]["post_types"] = get_post_types();
$this->settings["pilotpress"] = get_option("pilotpress-settings");
$this->api_version = get_option("pilotpress_api_version");
if($this->get_setting("usehome")) {
$this->homepage_url = home_url();
} else {
$this->homepage_url = site_url();
}
$this->settings["pilotpress"]["error_redirect_field"] = 'select-keyvalue';
$this->settings["pilotpress"]["error_redirect_message"] = "Redirect to THIS page on error.";
$results = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pilotpress_show_in_nav'", ARRAY_A);
foreach($results as $index => $page) {
$this->settings["pilotpress"]["show_in_nav"][] = $page["post_id"];
}
if($this->get_setting("api_key") && $this->get_setting("app_id")) {
$app_id = explode("_", $this->get_setting("app_id"));
if(count($app_id) == 3) {
if($app_id[1] > 20000 || $this->api_version ) {
self::$brand = "ONTRAPORT";
self::$brand_url = "ontraport.com";
self::$url_api = "https://api.ontraport.com/pilotpress.php";
self::$backup_url_api = "https://api.ontraport.com/pilotpress.php";
self::$url_tjs = "https://optassets.ontraport.com/tracking.js";
self::$url_jswpcss = "https://forms.ontraport.com/v2.4/include/scripts/moonrayJS/moonrayJS-only-wp-forms.css";
self::$url_mrcss = "https://forms.ontraport.com/v2.4/include/minify/?g=moonrayCSS";
}
// for debugging
if(is_file(ABSPATH . "/pp_debug_include.php"))
{
include_once(ABSPATH . "/pp_debug_include.php");
}
}
//check if these are stored in the cache first
$pilotPressTrackingURL = get_transient("pilotpress_tracking_url");
$pilotPressTracking = get_transient("pilotpress_tracking");
$getSiteSettings = true;
if ($pilotPressTrackingURL !== false && $pilotPressTracking !== false)
{
$this->settings["oap"]["tracking_url"] = $pilotPressTrackingURL;
$this->settings["oap"]["tracking"] = $pilotPressTracking;
$getSiteSettings = false;
}
//Check to make sure we really need to even make this API call...
if (is_user_logged_in() || $getSiteSettings )
{
//Only make use of cookie if not an admin user.
if(isset($_COOKIE["contact_id"]) && !current_user_can('manage_options')) {
global $current_user;
get_currentuserinfo();
$username = $current_user->user_login;
$api_result = $this->api_call("get_site_settings", array("site" => site_url(), "contact_id" => $_COOKIE["contact_id"], "username" => $username , "version"=>self::VERSION ));
}
else {
$api_result = $this->api_call("get_site_settings", array("site" => site_url() , "version"=>self::VERSION ));
}
if(is_array($api_result)) {
$this->settings["oap"] = $api_result;
if(isset($this->settings["user"])) {
unset($this->settings["user"]);
}
$this->ppp->ppprotectSetPPMemLevels($api_result["membership_levels"]);
if(!$this->get_setting("disablecaching")) {
set_transient('pilotpress_cache', $this->settings, 60 * 60 * 12);
}
$_SESSION["default_fields"] = $this->settings["oap"]["default_fields"];
if(isset($api_result["membership_level"])) {
$_SESSION["user_levels"] = $api_result["membership_level"];
if(!empty($username))
{
$_SESSION["user_name"] = $username;
}
}
$this->status = 1;
//Lets store the API version into their options table if available
if (isset($api_result["pilotpress_api_version"]))
{
update_option("pilotpress_api_version" , $api_result["pilotpress_api_version"]);
}
//Cache the tracking link and custom domain so we can avoid calling this every page load
if (isset($api_result["tracking_url"]))
{
set_transient('pilotpress_tracking_url', $api_result["tracking_url"],60 * 60 * 24);
}
if (isset($api_result["tracking_url"]))
{
set_transient('pilotpress_tracking', $api_result["tracking"],60 * 60 * 24);
}
}
}
} else {
$this->status = 0;
}
$this->settings["user"] = $this->get_user_settings();
if($this->get_setting("contact_id", "user")) {
if(get_transient("usertags_".$this->get_setting("contact_id", "user"))) {
$tags = get_transient("usertags_".$this->get_setting("contact_id", "user"));
} else {
$tags = $this->api_call("get_contact_tags", array("contact_id" => $this->get_setting("contact_id", "user")));
if(!$this->get_setting("disablecaching")) {
set_transient('usertags_'.$this->get_setting("contact_id", "user"), $tags, 60 * 60 * 12);
}
}
if(is_array($tags["tags"])) {
$this->settings["user"]["tags"] = $tags["tags"];
}
}
}
}
/* what protocol? */
static function get_protocol() {
if(isset($_SERVER["HTTPS"])) {
if(!empty($_SERVER["HTTPS"])) {
return "https://";
}
}
return "http://";
}
/* add metaboxes to said post types */
function update_post_types() {
$exclude = array("attachment","revision","nav_menu_item");
$array = $this->get_setting("post_types","wp");
$post_types = get_post_types('','names');
foreach($post_types as $post_type) {
if(!in_array($post_type, $array) && !in_array($post_type, $exclude)) {
$array[] = $post_type;
}
}
$this->settings["wp"]["post_types"] = $array;
}
function get_setting($key, $type = "pilotpress", $array = false) {
if(isset($this->settings[$type][$key])) {
if(!is_array($this->settings[$type][$key]) && $array) {
return array($this->settings[$type][$key]);
} else {
return $this->settings[$type][$key];
}
} else {
if($array) {
return array();
} else {
return false;
}
}
}
/* ditto getter is also handy */
function get_field($key) {
foreach($this->get_setting("fields", "user", true) as $group => $fields) {
if(isset($fields[$key]))
{
return $fields[$key];
}
else if (isset($fields[html_entity_decode($key)]))
{
return $fields[html_entity_decode($key)];
}
}
foreach($this->get_setting("default_fields", "oap", true) as $group => $fields) {
if(isset($fields[$key]))
{
return $fields[$key];
}
else if (isset($fields[html_entity_decode($key)]))
{
return $fields[html_entity_decode($key)];
}
}
return "";
}
function is_setup() {
if($this->status != 0) {
return true;
} else {
return false;
}
}
/* this is a fancy getter, for user settings */
function get_user_settings() {
$return = array();
if (isset($_SESSION['contact_id'])) {
$return["contact_id"] = $_SESSION["contact_id"];
}
if(isset($_SESSION["user_levels"])) {
$return["name"] = $_SESSION["user_name"];
$return["username"] = $_SESSION["user_name"];
$return["nickname"] = $_SESSION["nickname"];
$return["levels"] = $_SESSION["user_levels"];
}
return $return;
}
/* finally some fun: this sets up the admin edit page! */
function settings_init() {
$_SESSION["rehash"] = 1;
add_options_page('PilotPress Settings' , 'PilotPress', 'manage_options', 'pilotpress-settings', array(&$this, 'settings_page'));
register_setting('pilotpress-settings', 'pilotpress-settings', array(&$this, 'settings_validate'));
add_settings_section('pilotpress-settings-general', __('General Settings', 'pilotpress'), array(&$this, 'settings_section_general'), 'pilotpress-settings');
add_settings_field('pilotpress_app_id', __('Application ID', 'pilotpress'), array(&$this, 'display_settings_app_id'), 'pilotpress-settings', 'pilotpress-settings-general');
add_settings_field('pilotpress_api_key', __('API Key', 'pilotpress'), array(&$this, 'display_settings_api_key'), 'pilotpress-settings', 'pilotpress-settings-general');
add_settings_field('wp_userlockout', __('Lock all users without Admin role out of profile editor', 'pilotpress'), array(&$this, 'display_settings_userlockout'), 'pilotpress-settings', 'pilotpress-settings-general');
add_settings_section('settings_section_oap', __(self::$brand . ' Integration Settings', 'pilotpress'), array(&$this, 'settings_section_oap'), 'pilotpress-settings');
add_settings_field('customer_center', __('Enable Customer Center', 'pilotpress'), array(&$this, 'display_settings_cc'), 'pilotpress-settings', 'settings_section_oap');
add_settings_field('affiliate_center', __('Enable Partner Center', 'pilotpress'), array(&$this, 'display_settings_ac'), 'pilotpress-settings', 'settings_section_oap');
add_settings_section('pilotpress-redirect-display', __('Post Login Redirect Settings', 'pilotpress'), array(&$this, 'settings_section_redirect'), 'pilotpress-settings');
add_settings_field('pilotpress_customer_plr', __('Customers Redirect To', 'pilotpress'), array(&$this, 'display_settings_customer_plr'), 'pilotpress-settings', 'pilotpress-redirect-display');
add_settings_field('pilotpress_affiliate_plr', __('Partners Redirect To', 'pilotpress'), array(&$this, 'display_settings_affiliate_plr'), 'pilotpress-settings', 'pilotpress-redirect-display');
//Add the Customer Center Settings
add_settings_section('pilotpress-customer-center-display', __('Customer Center Settings', 'pilotpress'), array(&$this, 'settings_section_customer_settings'), 'pilotpress-settings');
add_settings_field('pilotpress_customer_center_header_image', __('Custom Header Image', 'pilotpress'), array(&$this, 'display_settings_customer_center_header_image'), 'pilotpress-settings', 'pilotpress-customer-center-display');
add_settings_field('pilotpress_customer_center_primary_color', __('Primary Color', 'pilotpress'), array(&$this, 'display_settings_customer_center_primary_color'), 'pilotpress-settings', 'pilotpress-customer-center-display');
add_settings_field('pilotpress_customer_center_secondary_color', __('Secondary (Background) Color', 'pilotpress'), array(&$this, 'display_settings_customer_center_secondary_color'), 'pilotpress-settings', 'pilotpress-customer-center-display');
//Add the New User Register Settings
add_settings_section('pilotpress-new-user-display', __('New User Register Settings', 'pilotpress'), array(&$this, 'settings_section_new_user_settings'), 'pilotpress-settings');
add_settings_field('pilotpress_add_newly_registered_users', __('Add newly registered WordPress users to your ONTRAPORT contacts', 'pilotpress'), array(&$this, 'display_settings_add_newly_registered_users'), 'pilotpress-settings', 'pilotpress-new-user-display');
add_settings_field('pilotpress_newly_registered_tags', __('What tags should they have?', 'pilotpress'), array(&$this, 'display_settings_newly_registered_tags'), 'pilotpress-settings', 'pilotpress-new-user-display');
add_settings_field('pilotpress_newly_registered_sequences', __('What sequences should they be on?', 'pilotpress'), array(&$this, 'display_settings_newly_registered_sequences'), 'pilotpress-settings', 'pilotpress-new-user-display');
//Add the Logout Settings
add_settings_section('pilotpress-logout-users-display', __('Logout Settings', 'pilotpress'), array(&$this, 'settings_section_logout_settings'), 'pilotpress-settings');
add_settings_field('pilotpress_logout_users', __('Would you like to keep user\'s logged into your site longer than normal? <br /> <br /> <i>(*Please note that if the browser is closed for a long period the user will have to log in again.</i>) ', 'pilotpress'), array(&$this, 'display_settings_logout_users'), 'pilotpress-settings', 'pilotpress-logout-users-display');
add_settings_section('pilotpress-settings-advanced', __('Advanced Settings', 'pilotpress'), array(&$this, 'settings_section_advanced'), 'pilotpress-settings');
add_settings_field('pp_use_cache', __('Disable API Caching', 'pilotpress'), array(&$this, 'display_settings_disablecaching'), 'pilotpress-settings', 'pilotpress-settings-advanced');
add_settings_field('pp_sslverify', __('Disable Verify Host SSL', 'pilotpress'), array(&$this, 'display_settings_disablesslverify'), 'pilotpress-settings', 'pilotpress-settings-advanced');
add_settings_field('pp_use_home', __('Use WordPress URL instead of Site URL', 'pilotpress'), array(&$this, 'display_settings_usehome'), 'pilotpress-settings', 'pilotpress-settings-advanced');
}
/* WP is sometimes silly, this is a function to echo a checkbox and have it registered.. annoying but easy */
function display_settings_cc() {
echo "<input type='checkbox' name='pilotpress-settings[customer_center]'";
if($this->get_setting("customer_center")) {
echo " checked";
}
echo ">";
}
/* ditto */
function display_settings_ac() {
echo "<input type='checkbox' name='pilotpress-settings[affiliate_center]'";
if($this->get_setting("affiliate_center")) {
echo " checked";
}
echo ">";
}
/* customer center settings */
function display_settings_customer_plr() {
$setting = $this->get_setting("pilotpress_customer_plr");
if(!$setting) {
$setting = "-1";
}
$pages = $this->get_routeable_pages(array("-2"));
echo "<select name='pilotpress-settings[pilotpress_customer_plr]'>";
foreach($pages as $id => $title) {
echo "<option value='{$id}'";
if($id == $setting) {
echo " selected";
}
echo ">{$title}</option>";
}
echo "</select>";
}
/* ditto, but for affil center */
function display_settings_affiliate_plr() {
$setting = $this->get_setting("pilotpress_affiliate_plr");
if(!$setting) {
$setting = "-1";
}
$pages = $this->get_routeable_pages(array("-2"));
echo "<select name='pilotpress-settings[pilotpress_affiliate_plr]'>";
foreach($pages as $id => $title) {
echo "<option value='{$id}'";
if($id == $setting) {
echo " selected";
}
echo ">{$title}</option>";
}
echo "</select>";
}
/** @brief settings hook for showing the customer center header image */
function display_settings_customer_center_header_image()
{
$setting = $this->get_setting("pilotpress_customer_center_header_image");
if (!$setting){
$setting = "";
}
$output = "<input name='pilotpress-settings[pilotpress_customer_center_header_image]' class='pilotpress_customer_center_header_image_url' type='text' name='header_logo' size='60' value='$setting'>
<a href='#' class='button pilotpress_header_logo_upload'>Upload</a>";
echo $output;
}
/** @brief settings hook for showing the customer center primary color */
function display_settings_customer_center_primary_color()
{
$setting = $this->get_setting("pilotpress_customer_center_primary_color");
if (!$setting){
$setting = "";
}
$output = "<input type='text' name='pilotpress-settings[pilotpress_customer_center_primary_color]' id='primary-color' value='".$setting."' data-default-color='#ffffff' class='pilotpress-color-picker' />";
echo $output;
}
/** @brief settings hook for showing the customer center secondary (background) color */
function display_settings_customer_center_secondary_color()
{
$setting = $this->get_setting("pilotpress_customer_center_secondary_color");
if (!$setting){
$setting = "";
}
$output = "<input type='text' name='pilotpress-settings[pilotpress_customer_center_secondary_color]' id='secondary-color' value='".$setting."' data-default-color='#ffffff' class='pilotpress-color-picker' />";
echo $output;
}
/** @brief displays the setting for the option to add new registered users to ONTRAPORT */
function display_settings_add_newly_registered_users()
{
$setting = $this->get_setting("pilotpress_add_newly_registered_users");
if (!$setting){
$setting = "-1";
}
echo "<select name=pilotpress-settings[pilotpress_add_newly_registered_users]>";
echo "<option value='0' ".selected( $setting, 0 ).">No</option>";
echo "<option value='1' ".selected( $setting, 1 ).">Yes</option>";
echo "</select>";
}
/** @brief displays the setting for the sequences that should be added to the new user */
function display_settings_newly_registered_sequences()
{
$setting = $this->get_setting("pilotpress_newly_registered_sequences");
if (!$setting){
$setting = "-1";
}
$output = "<select multiple name=pilotpress-settings[pilotpress_newly_registered_sequences][]>";
$sequences = json_decode($this->tagsSequences["sequences"] ,true );
foreach($sequences as $sequence)
{
$selected = "";
if(is_array($setting))
{
if (in_array($sequence["drip_id"] , $setting))
{
$selected = "selected='selected'";
}
}
$output .= "<option value='".$sequence["drip_id"]."' ".$selected . ">".$sequence["name"]."</option>";
}
$output .= "</select>";
echo $output;
}
/** @brief displays the setting for the tags to be added to new users */
function display_settings_newly_registered_tags()
{
$setting = $this->get_setting("pilotpress_newly_registered_tags");
if (!$setting){
$setting = "";
}
$output = "<select multiple name=pilotpress-settings[pilotpress_newly_registered_tags][]>";
$tags = json_decode($this->tagsSequences["tags"] , true );
foreach($tags as $tag)
{
$selected = "";
if(is_array($setting))
{
if (in_array($tag["tag_name"] , $setting))
{
$selected = "selected='selected'";
}
}
$output .= "<option value='".$tag["tag_name"]."' ".$selected.">".$tag["tag_name"]."</option>";
}
$output .= "</select>";
echo $output;
}
/** @brief displays the setting for enabling or disabling logout duration settings */
function display_settings_logout_users()
{
$setting = $this->get_setting("pilotpress_logout_users");
if (!$setting){
$setting = "-1";
}
echo "<select name=pilotpress-settings[pilotpress_logout_users]>";
echo "<option value='0' ".selected( $setting, 0 ).">No</option>";
echo "<option value='1' ".selected( $setting, 1 ).">Yes</option>";
echo "</select>";
}
/* section output, blank for austerity */
function settings_section_customer_settings() {}
function settings_section_new_user_settings() {}
function settings_section_logout_settings() {}
function settings_section_general() {}
function settings_section_oap() {}
function settings_section_redirect() {}
function settings_section_advanced() {
echo "<span class='pilotpress-advanced-warning'><b>WARNING:</b> these settings affect the core functionality of the PilotPress plugin, proceed with caution.</span>";
}
/* notices! this is where the magic nags happen */
function display_notice() {
global $post, $wp_version;
if(basename($_SERVER["SCRIPT_NAME"]) == "post.php" && $_GET["action"] == "edit" && in_array($post->ID, $this->system_pages)) {
echo '<div class="updated"><p>This page is used by the <b>PilotPress</b> plugin. You can edit the content but not delete the page itself.</p></div>';
}
if($wp_version < self::WP_MIN) {
echo '<div class="error" style="padding-top: 5px; padding-bottom: 5px;">';
_e('PilotPress requires WordPress '.self::WP_MIN.' or higher. Please de-activate the PilotPress plugin, upgrade to WordPress '.self::WP_MIN.' or higher then activate PilotPress again.', 'pilotpress');
echo '</div>';
}
if (!$this->get_setting('api_key') || !$this->get_setting('app_id')) {
echo '<div class="error" style="padding-top: 5px; padding-bottom: 5px;">';
_e('PilotPress must be configured with an ' . self::$brand . ' API Key and App ID.', 'pilotpress');
if($_GET['page'] != 'pilotpress-settings') {
_e(sprintf('Go to the <a href="%s" title="PilotPress Admin Page">PilotPress Admin Page</a> to finish setting up your site!', 'options-general.php?page=pilotpress-settings'), 'pilotpress');
echo ' ' ;
_e(sprintf('You need an <a href="%s" title="Visit '. self::$brand_url .'">' . self::$brand . '</a> account to use this plugin.', 'http://' . self::$brand_url));
echo ' ';
_e('Don\'t have one yet?', 'pilotpress');
echo ' ';
_e(sprintf('<a href="%s" title="' . self::$brand . ' SignUp">Sign up</a> now!', 'http://' . self::$brand_url, 'pilotpress'));
}
echo '</div>';
}
if(!$this->is_setup() && $this->get_setting('api_key') && $this->get_setting('app_id')) {
echo '<div class="error" style="padding-top: 5px; padding-bottom: 5px;">';
_e('Either this site <b>'.str_replace("http://","",(string)site_url()).'</b> is not configured in ' . self::$brand . ' or the <a href="options-general.php?page=pilotpress-settings">API Key / App Id settings</a> are incorrect. ', 'pilotpress');
_e('Most PilotPress features are disabled until this is configured. Please <a href="'.$this->get_setting("setup_url", "oap").'">click here</a> to set it up or visit the <a href="'.$this->get_setting("help_url", "oap").'">online help</a> for more information.', 'pilotpress');
echo '</div>';
}
}
function display_settings_api_key() {
?>
<input size="50" name="pilotpress-settings[api_key]" id="pilotpress_api_key" type="text" class="code" value="<?php echo $this->get_setting('api_key'); ?>" />
<?php
}
function display_settings_app_id() {
?>
<input size="50" name="pilotpress-settings[app_id]" id="pilotpress_app_id" type="text" class="code" value="<?php echo $this->get_setting('app_id'); ?>" />
<?php
}
function display_settings_userlockout() {
echo "<input type='checkbox' name='pilotpress-settings[wp_userlockout]'";
if($this->get_setting("wp_userlockout")) {
echo " checked";
}
echo ">";
}
function display_settings_disablecaching() {
echo "<input type='checkbox' name='pilotpress-settings[disablecaching]'";
if($this->get_setting("disablecaching")) {
echo " checked";
}
echo ">";
}
function display_settings_disablesslverify() {
echo "<input type='checkbox' name='pilotpress-settings[disablesslverify]'";
if($this->get_setting("disablesslverify")) {
echo " checked";
}
echo ">";
}
function display_settings_disableprotected() {
echo "<input type='checkbox' name='pilotpress-settings[disableprotected]'";
if($this->get_setting("disableprotected")) {
echo " checked";
}
echo ">";
}
function display_settings_usehome() {
echo "<input type='checkbox' name='pilotpress-settings[usehome]'";
if($this->get_setting("usehome")) {
echo " checked";
}
echo ">";
}
/* finally, we register the settings page itself. */
function settings_page() {
//get the sequences and tags...
$this->tagsSequences = $this->api_call("get_tags_sequences", array("site" => site_url()));
?>
<div class="wrap"><h2><?php _e('PilotPress Settings', 'pilotpress'); ?></h2><?php
?><form name="pilotpress-settings" method="post" action="options.php"><?php
settings_fields('pilotpress-settings');
do_settings_sections('pilotpress-settings');
?>
<p class="submit"><input type="submit" class="button-primary" name="save" value="<?php _e('Save Changes', 'pilotpress'); ?>" /> <input type="button" class="button-secondary" name="advanced" value="<?php _e('Advanced Settings', 'pilotpress'); ?>"></p></form></div>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(document).find("[name=pilotpress-settings] h3:eq(6)").toggle();
jQuery(document).find(".pilotpress-advanced-warning").toggle();
jQuery(document).find("[name=pilotpress-settings] table:eq(6)").toggle();
jQuery(document).find("[name=advanced]").click(function() {
jQuery(document).find("[name=pilotpress-settings] h3:eq(6)").toggle();
jQuery(document).find(".pilotpress-advanced-warning").toggle();
jQuery(document).find("[name=pilotpress-settings] table:eq(6)").toggle();
});
//media uploader
jQuery('.pilotpress_header_logo_upload').click(function(e) {
e.preventDefault();
var custom_uploader = wp.media({
title: 'Customer Center Header Image',
button: {
text: 'Upload Image'
},
multiple: false // Set this to true to allow multiple files to be selected
})
.on('select', function() {
var attachment = custom_uploader.state().get('selection').first().toJSON();
jQuery('.pilotpress_customer_center_header_image').attr('src', attachment.url);
jQuery('.pilotpress_customer_center_header_image_url').val(attachment.url);
})
.open();
});
//primary color picker init
jQuery('#primary-color.pilotpress-color-picker').iris();
jQuery('#primary-color.pilotpress-color-picker').iris({ change: function(event, ui)
{
var colorpickervar = jQuery("#primary-color.pilotpress-color-picker").val()
jQuery("#primary-color.pilotpress-color-picker").siblings('.iris-border').css('background-color', colorpickervar);
}
});
//secondary color picker init
jQuery('#secondary-color.pilotpress-color-picker').iris();
jQuery('#secondary-color.pilotpress-color-picker').iris({ change: function(event, ui)
{
var colorpickervar = jQuery("#secondary-color.pilotpress-color-picker").val()
jQuery("#secondary-color.pilotpress-color-picker").siblings('.iris-border').css('background-color', colorpickervar);
}
});
});
</script>
<?php
}
/* use this to validate input, for now it simply creates the pages and/or resets cache */
function settings_validate($input) {
if(isset($input["customer_center"])) {
$this->create_system_page("customer_center");
} else {
$this->delete_system_page("customer_center");
}
if(isset($input["affiliate_center"])) {
$this->create_system_page("affiliate_center");
} else {
$this->delete_system_page("affiliate_center");
}
$_SESSION["rehash"] = 1;
return $input;
}
/* OH YEAH! this is the API call method, wraps the static function as some other plugins may call via their own behalf */
function api_call($method, $data) {
return self::api_call_static($method, $data, $this->get_setting("app_id"), $this->get_setting("api_key"), $this->get_setting("disablesslverify"));
}
/* this is the real function of the above, for errors... try dumping $post */
static function api_call_static($method, $data, $app_id, $api_key, $ssl_verify = false) {
$post = array('body' => array("app_id" => $app_id,
"api_key" => $api_key,
"data" => json_encode($data)), 'timeout' => 500);
if($ssl_verify) {
$post["sslverify"] = 0;
}
$endpoint = sprintf(self::$url_api.'/%s/%s/%s', "json", "pilotpress", $method);
$response = wp_remote_post($endpoint, $post);
if(is_object($response))
{
if ($response->errors['http_request_failed']){
$endpoint = sprintf(self::$backup_url_api.'/%s/%s/%s', "json", "pilotpress", $method);
$response = wp_remote_post($endpoint, $post);
}
}
if(is_wp_error($response) || $response['response']['code'] == 500) {
return false;
} else {
$body = json_decode(trim($response['body']), true);
}
if(isset($body["type"]) && $body["type"] == "error") {
return false;
} else {
return $body["pilotpress"];
}
}
/* all WP binding happens here, mostly. consolidated for your pleasure */
private function bind_hooks() {
/* hitup the API or grab transient */
add_action("init", array(&$this, "load_settings") , 1);
add_action("init", array(&$this, "load_scripts") , 10);
add_action('init', array(&$this,'sessionslap_ping'));
add_action('wp_print_styles', array(&$this, 'stylesheets'));
add_action('wp_print_footer_scripts', array(&$this, 'tracking'));
add_action('retrieve_password', array(&$this, 'retrieve_password'));
add_action('profile_update', array(&$this, 'profile_update'));
add_action("wp_ajax_pp_update_aff_details", array(&$this, 'update_aff_details'));
add_action("wp_ajax_pp_update_cc_details", array(&$this, 'update_cc_details'));
if(is_admin()) {
add_action('admin_menu', array(&$this, 'settings_init'));
add_filter('admin_init', array(&$this, 'clean_meta'));
add_filter('admin_init', array(&$this, 'flush_rewrite_rules'));
add_filter('admin_init', array(&$this, 'user_lockout'));
add_action('admin_enqueue_scripts', array(&$this, 'admin_load_scripts'));
add_action('admin_notices', array(&$this, 'display_notice'));
add_action('admin_menu', array(&$this, 'metabox_add'));
add_action('pre_post_update', array(&$this, 'metabox_save'));
add_action('media_buttons', array(&$this, 'media_button_add'), 20);
add_action('media_upload_forms', array(&$this, 'media_upload_forms'));
add_action('media_upload_images', array(&$this, 'media_upload_images'));
add_action('media_upload_videos', array(&$this, 'media_upload_videos'));
add_action('media_upload_fields', array(&$this, 'media_upload_fields'));
add_action('wp_ajax_pp_insert_form', array(&$this, 'get_insert_form_html'));
add_action('wp_ajax_pp_insert_video', array(&$this, 'get_insert_video_html'));
add_action("wp_ajax_pp_get_aff_report", array(&$this, 'get_aff_report'));
add_filter('tiny_mce_before_init', array(&$this, 'mce_valid_elements'));
add_filter('tiny_mce_version', array(&$this, 'tiny_mce_version') );
add_filter("mce_external_plugins", array(&$this, "mce_external_plugins"));
add_filter('mce_buttons_3', array(&$this, 'mce_buttons'));
add_filter('manage_posts_columns', array(&$this, 'page_list_col'));
add_action('manage_posts_custom_column', array(&$this, 'page_list_col_value'), 10, 2);
add_filter('manage_pages_columns', array(&$this, 'page_list_col'));
add_action('manage_pages_custom_column', array(&$this, 'page_list_col_value'), 10, 2);
add_filter('user_has_cap', array(&$this, 'lock_delete'), 0, 3);
add_filter('media_upload_tabs', array(&$this, 'modify_media_tab'));
add_action('wp_loaded', array(&$this, 'update_post_types'));
// For login_form
add_action('admin_head', array(&$this, 'include_form_admin_options'));
//add_action('admin_print_footer_scripts', array(&$this, 'tinymce_autop'), 50);
} else {
add_filter('rewrite_rules_array', array(&$this, 'filter_rewrite_rules'));
add_action('wp', array(&$this, 'post_process'));
add_filter('get_pages', array(&$this, 'get_pages'));
add_filter("wp_nav_menu", array(&$this, 'get_nav_menus'));
add_filter("wp_nav_menu_objects", array(&$this, 'get_nav_menu_objects'));
add_filter('posts_where', array(&$this, 'posts_where'));
add_filter('query_vars', array(&$this, 'filter_query_vars'));
add_filter('the_content', array(&$this, 'content_process'));
add_filter('login_message', array(&$this, 'content_process'));
add_shortcode('protected', array(&$this, 'shortcode_show_if'));
add_shortcode('show_if', array(&$this, 'shortcode_show_if'));
add_shortcode('login_page', array(&$this, 'login_page'));
add_shortcode('field', array(&$this, 'shortcode_field'));
add_shortcode('pilotpress_protected', array(&$this, 'shortcode_show_if'));
add_shortcode('pilotpress_show_if', array(&$this, 'shortcode_show_if'));
add_shortcode('pilotpress_login_page', array(&$this, 'login_page'));
add_shortcode('pilotpress_field', array(&$this, 'shortcode_field'));
}
add_action('wp_authenticate', array(&$this, 'user_login'), 1, 2);
add_action("wp_login_failed", array(&$this, 'user_login_failed'));
add_action("lostpassword_post", array(&$this, 'user_lostpassword'));
add_action('wp_logout', array(&$this, 'user_logout'));
add_action('init', array(&$this, 'pp_login_button'));
add_action('user_register', array(&$this, 'add_new_register_user_to_ONTRAPORT') , 10, 1);
}
function retrieve_password($name) {
$return = $this->api_call("retrieve_password", array("site" => site_url(), "username" => $name));
}
/* update a persons profile */
function profile_update($user_id) {
if(isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['nickname']) && isset($_POST['pass1'])) {
$user = get_userdata($user_id);
$details = array();
$details["site"] = site_url();
$details["username"] = $user->user_login;
$details["firstname"] = $_POST['first_name'];
$details["lastname"] = $_POST['last_name'];
$details["nickname"] = $_POST['nickname'];
$details["password"] = $_POST["pass1"];
$return = $this->api_call("profile_update", $details);
}
}
function user_lockout() {
global $current_user;
if(!current_user_can('manage_options') && $this->get_setting("wp_userlockout") && !isset($_POST["action"])) {
$customer = $this->get_setting("pilotpress_customer_plr");
if(!empty($customer) && $customer != "-1") {
self::redirect(get_permalink($customer));
} else {
self::redirect($this->homepage_url);
}
die;
}
}
/* please load scripts here vs. printing. it's so much healthier */
function load_scripts() {
wp_enqueue_script("jquery");
wp_register_script("mr_tracking", self::$url_tjs, array(), false, true);
wp_enqueue_script("mr_tracking");
}
/*
@brief only load these scripts if in the admin dashboard
*/
function admin_load_scripts()
{
// Here to determine if the automattic color picker 'iris' is included with wordpress... if not, include and use it
$version = get_bloginfo('version');
if ($version < 3.5)
{
wp_register_style('irisstyle', plugins_url( '/js/iris.css' , __FILE__ ));
wp_enqueue_style('irisstyle');
wp_register_style('jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css');
wp_enqueue_style('jquery-ui');
wp_deregister_script('jquery-color');
wp_register_script('jquery-color', plugins_url( 'color.js' , __FILE__ ));
wp_enqueue_script('jquery-color');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-draggable');
wp_enqueue_script('jquery-ui-slider');
wp_enqueue_script('jquery-ui-widget');
wp_enqueue_script('jquery-ui-mouse');
wp_enqueue_script('jquery-ui-tabs');
wp_register_script('iris', plugins_url( '/js/iris.js' , __FILE__ ), array( 'jquery', 'jquery-color', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-ui-mouse', 'jquery-ui-tabs' ));
wp_enqueue_script('iris');
}
else
{
wp_register_style('jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css');
wp_enqueue_style('jquery-ui');
wp_enqueue_script('jquery-ui-tabs');
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script('iris');
}
if(function_exists( 'wp_enqueue_media' )){
wp_enqueue_media();
}else{
wp_enqueue_style('thickbox');
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
}
}
function stylesheets() {
wp_register_style("mrjswp", self::$url_jswpcss);
wp_enqueue_style("mrjswp");
wp_register_style("mrcss", self::$url_mrcss);
wp_enqueue_style("mrcss");
wp_register_style("jqcss", self::URL_JQCSS);
wp_enqueue_style("jqcss");
}
/* except this one. */
function tracking() {
echo "<script>_mri = \"".$this->get_setting('tracking','oap')."\";_mr_domain = \"" . $this->get_setting('tracking_url', 'oap') . "\"; mrtracking();</script>";