-
Notifications
You must be signed in to change notification settings - Fork 0
/
retainly.php
4885 lines (4205 loc) · 197 KB
/
retainly.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: Retainly Plugin
* Plugin URI: https://retainly.co
* Version: 1.1
* Description: This plugin helps capture subscribers from your wordpress to your list in retainly.
* Author: Retainly
* Author URI: https://retainly.co
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
define( 'RAD_RAPIDOLOGY_PLUGIN_DIR', trailingslashit( dirname( __FILE__ ) ) );
define( 'RAD_RAPIDOLOGY_PLUGIN_URI', plugins_url( '', __FILE__ ) );
if ( ! class_exists( 'RAD_Dashboard' ) ) {
require_once( RAD_RAPIDOLOGY_PLUGIN_DIR . 'dashboard/dashboard.php' );
}
if ( ! class_exists( 'rapidology_rapidbar' ) ) {
require_once( RAD_RAPIDOLOGY_PLUGIN_DIR . 'includes/ext/rapidology_rapidbar/class.rapidology_rapidbar.php' );
}
require_once('includes/updater.php');
require_once('includes/rapidology_functions.php');
class RAD_Rapidology extends RAD_Dashboard {
var $plugin_version = '1.1';
var $db_version = '1.0';
var $_options_pagename = 'rad_rapidology_options';
var $menu_page;
var $protocol;
var $privacy_url = 'http://www.rapidology.com/privacy';
var $tou_url = 'http://www.rapidology.com/tou';
private static $_this;
function __construct() {
// Don't allow more than one instance of the class
/*if ( isset( self::$_this ) ) {
wp_die( sprintf( __( '%s is a singleton class and you cannot create a second instance.', 'rapidology' ),
get_class( $this ) )
);
}*/
global $pagenow;
self::$_this = $this;
$this->protocol = is_ssl() ? 'https' : 'http';
add_action( 'admin_menu', array( $this, 'add_menu_link' ) );
add_action( 'plugins_loaded', array( $this, 'add_localization' ) );
add_action( 'admin_init', array( $this, 'execute_footer_text' ) );
add_action('admin_init', array( $this,'rapidologly_update' ) );
add_filter( 'rad_rapidology_import_sub_array', array( $this, 'import_settings' ) );
add_filter( 'rad_rapidology_import_array', array( $this, 'import_filter' ) );
add_filter( 'rad_rapidology_export_exclude', array( $this, 'filter_export_settings' ) );
add_filter( 'rad_rapidology_save_button_class', array( $this, 'save_btn_class' ) );
// generate home tab in dashboard
add_action( 'rad_rapidology_after_header_options', array( $this, 'generate_home_tab' ) );
add_action( 'rad_rapidology_after_main_options', array( $this, 'generate_premade_templates' ) );
add_action( 'rad_rapidology_after_save_button', array( $this, 'add_next_button' ) );
do_action('rapidology_ext_init');
$plugin_file = plugin_basename( __FILE__ );
add_filter( "plugin_action_links_{$plugin_file}", array( $this, 'add_settings_link' ) );
$dashboard_args = array(
'rad_dashboard_options_pagename' => $this->_options_pagename,
'rad_dashboard_plugin_name' => 'rapidology',
'rad_dashboard_save_button_text' => __( 'Save & Exit', 'rapidology' ),
'rad_dashboard_plugin_class_name' => 'rad_rapidology',
'rad_dashboard_options_path' => RAD_RAPIDOLOGY_PLUGIN_DIR . 'dashboard/includes/options.php',
'rad_dashboard_options_page' => 'toplevel_page',
);
parent::__construct( $dashboard_args );
// Register save settings function for ajax request
add_action( 'wp_ajax_rad_rapidology_save_settings', array( $this, 'rapidology_save_settings' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts_styles' ) );
add_action( 'wp_ajax_rapidology_reset_options_page', array( $this, 'rapidology_reset_options_page' ) );
add_action( 'wp_ajax_rapidology_remove_optin', array( $this, 'remove_optin' ) );
add_action( 'wp_ajax_rapidology_duplicate_optin', array( $this, 'duplicate_optin' ) );
add_action( 'wp_ajax_rapidology_add_variant', array( $this, 'add_variant' ) );
add_action( 'wp_ajax_rapidology_home_tab_tables', array( $this, 'home_tab_tables' ) );
add_action( 'wp_ajax_rapidology_toggle_optin_status', array( $this, 'toggle_optin_status' ) );
add_action( 'wp_ajax_rapidology_authorize_account', array( $this, 'authorize_account' ) );
add_action( 'wp_ajax_rapidology_reset_accounts_table', array( $this, 'reset_accounts_table' ) );
add_action( 'wp_ajax_rapidology_generate_mailing_lists', array( $this, 'generate_mailing_lists' ) );
add_action( 'wp_ajax_rapidology_generate_new_account_fields', array( $this, 'generate_new_account_fields' ) );
add_action( 'wp_ajax_rapidology_generate_accounts_list', array( $this, 'generate_accounts_list' ) );
add_action( 'wp_ajax_rapidology_generate_current_lists', array( $this, 'generate_current_lists' ) );
add_action( 'wp_ajax_rapidology_generate_edit_account_page', array( $this, 'generate_edit_account_page' ) );
add_action( 'wp_ajax_rapidology_save_account_tab', array( $this, 'save_account_tab' ) );
add_action( 'wp_ajax_rapidology_ab_test_actions', array( $this, 'ab_test_actions' ) );
add_action( 'wp_ajax_rapidology_get_stats_graph_ajax', array( $this, 'get_stats_graph_ajax' ) );
add_action( 'wp_ajax_rapidology_refresh_optins_stats_table', array( $this, 'refresh_optins_stats_table' ) );
add_action( 'wp_ajax_rapidology_reset_stats', array( $this, 'reset_stats' ) );
add_action( 'wp_ajax_rapidology_pick_winner_optin', array( $this, 'pick_winner_optin' ) );
add_action( 'wp_ajax_rapidology_clear_stats', array( $this, 'clear_stats' ) );
add_action( 'wp_ajax_rapidology_clear_stats_single_optin', array( $this, 'clear_stats_single_optin' ) );
add_action( 'wp_ajax_rapidology_get_premade_values', array( $this, 'get_premade_values' ) );
add_action( 'wp_ajax_rapidology_generate_template_filter', array( $this, 'generate_template_filter' ) );
add_action( 'wp_ajax_rapidology_generate_premade_grid', array( $this, 'generate_premade_grid' ) );
add_action( 'wp_ajax_rapidology_display_preview', array( $this, 'display_preview' ) );
add_action( 'wp_ajax_rapidology_handle_stats_adding', array( $this, 'handle_stats_adding' ) );
add_action( 'wp_ajax_nopriv_rapidology_handle_stats_adding', array( $this, 'handle_stats_adding' ) );
add_action( 'wp_ajax_rapidology_subscribe', array( $this, 'subscribe' ) );
add_action( 'wp_ajax_nopriv_rapidology_subscribe', array( $this, 'subscribe' ) );
add_action( 'wp_ajax_rapidology_center_webhooks', array( $this, 'CenterWebHookSubmit' ) );
add_action( 'wp_ajax_nopriv_rapidology_center_webhooks', array( $this, 'CenterWebHookSubmit' ) );
add_action( 'widgets_init', array( $this, 'register_widget' ) );
add_action( 'after_setup_theme', array( $this, 'register_image_sizes' ) );
add_shortcode( 'rad_rapidology_inline', array( $this, 'display_inline_shortcode' ) );
add_shortcode( 'rad_rapidology_locked', array( $this, 'display_locked_shortcode' ) );
add_filter( 'body_class', array( $this, 'add_body_class' ) );
register_activation_hook( __FILE__, 'rapid_version_check' );
if($pagenow == 'plugins.php' || isset($_GET['page']) && $_GET['page']=='rad_rapidology_options'){
add_action( 'admin_notices', 'rapid_version_check' );
}
if ( ! wp_next_scheduled( 'rapidology_update_source_check' ) ) {
wp_schedule_event( time(), 'daily', 'rapidology_update_source_check' );
}
register_activation_hook( __FILE__, array( $this, 'activate_plugin' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate_plugin' ) );
add_action( 'rapidology_lists_auto_refresh', array( $this, 'perform_auto_refresh' ) );
add_action( 'rapidology_stats_auto_refresh', array( $this, 'perform_stats_refresh' ) );
add_action( 'rapidology_update_source_check', array($this, 'rapidology_update_source' ));
$this->frontend_register_locations();
foreach ( array( 'post.php', 'post-new.php' ) as $hook ) {
add_action( "admin_head-$hook", array( $this, 'tiny_mce_vars' ) );
add_action( "admin_head-$hook", array( $this, 'add_mce_button_filters' ) );
}
}
function activate_plugin() {
// schedule lists auto update daily
//wp_schedule_event( time(), 'daily', 'rapidology_lists_auto_refresh' );
//wp_schedule_event( time(), 'daily', 'rapidology_update_source_check' );
//install the db for stats
$this->db_install();
}
function deactivate_plugin() {
// remove lists auto updates from wp cron if plugin deactivated
//wp_clear_scheduled_hook( 'rapidology_lists_auto_refresh' );
//wp_clear_scheduled_hook( 'rapidology_stats_auto_refresh' );
}
function define_page_name() {
return $this->_options_pagename;
}
function rapidology_update_source() {
//$update = wp_remote_get('https://rapidology.com/download/wp_update.json?version=413');
//$update = json_decode($update['body']);
//update_option( 'rapidology_update_source', $update->wordpress_update );
update_option( 'rapidology_update_source', true );
}
function rapidologly_update( )
{
$plugin_name = plugin_basename(dirname(dirname(__FILE__)));
//check if we are updating from github or wordpress
$update = get_option( 'rapidology_update_source', false );
if (is_admin()) { // note the use of is_admin() to double check that this is happening in the admin
if ($update == false) {
$config = array(
'slug' => plugin_basename(__FILE__), // this is the slug of your plugin
'proper_folder_name' => dirname(plugin_basename(__FILE__)), // this is the name of the folder your plugin lives in
'zip_url' => 'https://rapidology.com/download/rapidology.zip', // the zip url of the github repo
'release_url' => 'https://api.github.com/repos/leadpages/rapidology-plugin/releases',
'api_url' => 'https://api.github.com/repos/leadpages/rapidology-plugin', // the github API url of your github repo
'raw_url' => 'https://raw.github.com/leadpages/rapidology-plugin/master', // the github raw url of your github repo
'github_url' => 'https://github.com/leadpages/rapidology-plugin', // the github url of your github repo
'sslverify' => true, // wether WP should check the validity of the SSL cert when getting an update, see https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/2 and https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/4 for details
'requires' => '3.5', // which version of WordPress does your plugin require?
'tested' => '4.5', // which version of WordPress is your plugin tested up to?
'readme' => 'README.md' // which file to use as the readme for the version number
);
new Rapidology_GitHub_Updater($config);
}
}
}
/**
* Returns an instance of the object
*
* @return object
*/
static function get_this() {
return self::$_this;
}
function add_menu_link() {
$menu_page = add_menu_page(
__( 'Retainly', 'rapidology' ),
__( 'Retainly', 'rapidology' ),
'manage_options',
'rad_rapidology_options',
array( $this, 'options_page' )
);
add_submenu_page( 'rad_rapidology_options', __( 'Retainly', 'rapidology' ), __( 'Resources', 'rapidology' ), 'manage_options', 'rad_rapidology_options' );
add_submenu_page( 'rad_rapidology_options', __( 'Optin Forms', 'rapidology' ), __( 'Optin Forms', 'rapidology' ), 'manage_options', 'admin.php?page=rad_rapidology_options#tab_rad_dashboard_tab_content_header_home' );
add_submenu_page( 'rad_rapidology_options', __( 'Email Accounts', 'rapidology' ), __( 'Email Accounts', 'rapidology' ), 'manage_options', 'admin.php?page=rad_rapidology_options#tab_rad_dashboard_tab_content_header_accounts' );
add_submenu_page( 'rad_rapidology_options', __( 'Statistics', 'rapidology' ), __( 'Statistics', 'rapidology' ), 'manage_options', 'admin.php?page=rad_rapidology_options#tab_rad_dashboard_tab_content_header_stats' );
/*add_submenu_page( 'rad_rapidology_options', __( 'Import & Export', 'rapidology' ), __( 'Import & Export', 'rapidology' ), 'manage_options', 'admin.php?page=rad_rapidology_options#tab_rad_dashboard_tab_content_header_importexport' );*/
}
function add_body_class( $body_class ) {
$body_class[] = 'rad_rapidology';
return $body_class;
}
function save_btn_class() {
return 'rad_dashboard_custom_save';
}
/**
* Adds plugin localization
* Domain: rapidology
*
* @return void
*/
function add_localization() {
load_plugin_textdomain( 'rapidology', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
// Add settings link on plugin page
function add_settings_link( $links ) {
$settings_link = sprintf( '<a href="admin.php?page=rad_rapidology_options">%1$s</a>', __( 'Settings', 'rapidology' ) );
array_unshift( $links, $settings_link );
return $links;
}
function options_page() {
RAD_Rapidology::generate_options_page( $this->generate_optin_id() );
}
function import_settings() {
return true;
}
function rapidology_save_settings() {
RAD_Rapidology::dashboard_save_settings();
}
function filter_export_settings( $options ) {
$updated_array = array_merge( $options, array( 'accounts' ) );
return $updated_array;
}
/**
*
* Adds the "Next" button into the Rapidology dashboard via RAD_Dashboard action.
* @return prints the data on screen
*
*/
function add_next_button() {
printf( '
<div class="rad_dashboard_row rad_dashboard_next_design">
<button class="rad_dashboard_icon">%1$s</button>
</div>',
__( 'Next: Design', 'rapidology' )
);
printf( '
<div class="rad_dashboard_row rad_dashboard_next_display">
<button class="rad_dashboard_icon">%1$s</button>
</div>',
__( 'Next: Display Settings', 'rapidology' )
);
printf( '
<div class="rad_dashboard_row rad_dashboard_next_customize">
<button class="rad_dashboard_icon" data-selected_layout="layout_1">%1$s</button>
</div>',
__( 'Next: Customize', 'rapidology' )
);
printf( '
<div class="rad_dashboard_row rad_dashboard_next_shortcode">
<button class="rad_dashboard_icon">%1$s</button>
</div>',
__( 'Generate Shortcode', 'rapidology' )
);
}
/**
* Retrieves the Rapidology options from DB and makes it available outside the class
* @return array
*/
public static function get_rapidology_options() {
return get_option( 'rad_rapidology_options' ) ? get_option( 'rad_rapidology_options' ) : array();
}
/**
* Updates the Rapidology options outside the class
* @return void
*/
public static function update_rapidology_options( $update_array ) {
$dashboard_options = RAD_Rapidology::get_rapidology_options();
$updated_options = array_merge( $dashboard_options, $update_array );
update_option( 'rad_rapidology_options', $updated_options );
}
/**
* Filters the options_array before importing data. Function generates new IDs for imported options to avoid replacement of existing ones.
* Filter is used in RAD_Dashboard class
* @return array
*/
function import_filter( $options_array ) {
$updated_array = array();
$new_id = $this->generate_optin_id( false );
foreach ( $options_array as $key => $value ) {
$updated_array[ 'optin_' . $new_id ] = $options_array[ $key ];
//reset accounts settings and make all new optins inactive
$updated_array[ 'optin_' . $new_id ]['email_provider'] = 'empty';
$updated_array[ 'optin_' . $new_id ]['account_name'] = 'empty';
$updated_array[ 'optin_' . $new_id ]['email_list'] = 'empty';
$updated_array[ 'optin_' . $new_id ]['optin_status'] = 'inactive';
$new_id ++;
}
return $updated_array;
}
function add_mce_button_filters() {
add_filter( 'mce_external_plugins', array( $this, 'add_mce_button' ) );
add_filter( 'mce_buttons', array( $this, 'register_mce_button' ) );
}
function add_mce_button( $plugin_array ) {
global $typenow;
wp_enqueue_style( 'rapidology-shortcodes', RAD_RAPIDOLOGY_PLUGIN_URI . '/css/tinymcebutton.css', array(), $this->plugin_version );
$plugin_array['rapidology'] = RAD_RAPIDOLOGY_PLUGIN_URI . '/js/rapidology-mce-buttons.js';
return $plugin_array;
}
function register_mce_button( $buttons ) {
global $typenow;
array_push( $buttons, 'rapidology_button' );
return $buttons;
}
/**
* Pass locked_optins and inline_optins lists to tiny-MCE script
*/
function tiny_mce_vars() {
$options_array = RAD_Rapidology::get_rapidology_options();
$locked_array = array();
$inline_array = array();
$onclick_array = array();
if ( ! empty( $options_array ) ) {
foreach ( $options_array as $optin_id => $details ) {
if ( 'accounts' !== $optin_id ) {
if ( isset( $details['optin_status'] ) && 'active' === $details['optin_status'] && empty( $details['child_of'] ) ) {
if ( '1' == $details['click_trigger'] ) {
$onclick_array = array_merge( $onclick_array, array( $optin_id => preg_replace( '/[^A-Za-z0-9 _-]/', '', $details['optin_name'] ) ) );
}
if ( 'inline' == $details['optin_type'] ) {
$inline_array = array_merge( $inline_array, array( $optin_id => $details['optin_name'] ) );
}
if ( 'locked' == $details['optin_type'] ) {
$locked_array = array_merge( $locked_array, array( $optin_id => $details['optin_name'] ) );
}
}
}
}
}
if ( empty( $locked_array ) ) {
$locked_array = array(
'empty' => __( 'No optins available', 'rapidology' ),
);
}
if ( empty( $inline_array ) ) {
$inline_array = array(
'empty' => __( 'No optins available', 'rapidology' ),
);
}
if ( empty( $onclick_array ) ) {
$onclick_array = array(
'empty' => __( 'No optins available', 'rapidology' ),
);
}
?>
<!-- TinyMCE Shortcode Plugin -->
<script type='text/javascript'>
var rapidology = {
'onclick_optins' : '<?php echo json_encode( $onclick_array ); ?>',
'locked_optins': '<?php echo json_encode( $locked_array ); ?>',
'inline_optins': '<?php echo json_encode( $inline_array ); ?>',
'rapidology_tooltip': '<?php _e( "insert rapidology Opt-In", "rapidology" ); ?>',
'inline_text': '<?php _e( "Inline Opt-In", "rapidology" ); ?>',
'locked_text': '<?php _e( "Locked Content Opt-In", "rapidology" ); ?>'
}
</script>
<!-- TinyMCE Shortcode Plugin -->
<?php
}
function db_install() {
global $wpdb;
$table_name = $wpdb->prefix . 'rad_rapidology_stats';
/*
* We'll set the default character set and collation for this table.
* If we don't do this, some characters could end up being converted
* to just ?'s when saved in our table.
*/
$charset_collate = '';
if ( ! empty( $wpdb->charset ) ) {
$charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
}
if ( ! empty( $wpdb->collate ) ) {
$charset_collate .= " COLLATE {$wpdb->collate}";
}
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
record_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
record_type varchar(3) NOT NULL,
optin_id varchar(20) NOT NULL,
list_id varchar(100) NOT NULL,
ip_address varchar(45) NOT NULL,
page_id varchar(20) NOT NULL,
removed_flag boolean NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
$db_version = array(
'db_version' => $this->db_version,
);
RAD_Rapidology::update_option( $db_version );
update_option('rad_rapidology_activated', 'rapidology_activated');
}
function register_image_sizes() {
add_image_size( 'rapidology_image', 610 );
}
/**
* Generates the Rapidology's Home, Stats, Accounts tabs. Hooked to Dashboard class
*/
function generate_home_tab( $option, $dashboard_settings = array() ) {
switch ( $option['type'] ) {
case 'home' :
printf( '
<div class="rad_dashboard_row rad_dashboard_new_optin">
<h1>%2$s</h1>
<button class="rad_dashboard_icon">%1$s</button>
<input type="hidden" name="action" value="new_optin" />
</div>',
esc_html__( 'new optin', 'rapidology' ),
esc_html__( 'Active Opt-Ins', 'rapidology' )
);
printf( '
<div class="rad_dashboard_row rad_dashboard_optin_select">
<h3>%1$s</h3>
<span class="rad_dashboard_icon rad_dashboard_close_button"></span>
<ul>
<li class="rad_dashboard_optin_type rad_dashboard_optin_add rad_dashboard_optin_type_popup" data-type="pop_up">
<h6>%2$s</h6>
<div class="optin_select_grey">
<div class="optin_select_light_grey">
</div>
</div>
</li>
<li class="rad_dashboard_optin_type rad_dashboard_optin_add rad_dashboard_optin_type_flyin" data-type="flyin">
<h6>%3$s</h6>
<div class="optin_select_grey"></div>
<div class="optin_select_light_grey"></div>
</li>
<li class="rad_dashboard_optin_type rad_dashboard_optin_add rad_dashboard_optin_type_below" data-type="below_post">
<h6>%4$s</h6>
<div class="optin_select_grey"></div>
<div class="optin_select_light_grey"></div>
</li>
<li class="rad_dashboard_optin_type rad_dashboard_optin_add rad_dashboard_optin_type_inline" data-type="inline">
<h6>%5$s</h6>
<div class="optin_select_grey"></div>
<div class="optin_select_light_grey"></div>
<div class="optin_select_grey"></div>
</li>
</ul>
<ul>
<li class="rad_dashboard_optin_type rad_dashboard_optin_add rad_dashboard_optin_type_locked" data-type="locked">
<h6>%6$s</h6>
<div class="optin_select_grey"></div>
<div class="optin_select_light_grey"></div>
<div class="optin_select_grey"></div>
</li>
<li class="rad_dashboard_optin_type rad_dashboard_optin_add rad_dashboard_optin_type_widget" data-type="widget">
<h6>%7$s</h6>
<div class="optin_select_grey"></div>
<div class="optin_select_light_grey"></div>
<div class="optin_select_grey_small"></div>
<div class="optin_select_grey_small last"></div>
</li>
<li class="rad_dashboard_optin_type rad_dashboard_optin_add rad_dashboard_optin_type_rapidbar" data-type="rapidbar">
<h6>%8$s</h6>
<div class="optin_select_light_grey"></div>
<div class="optin_select_grey"></div>
</li>
</ul>
</div>',
esc_html__( 'select optin type to begin', 'rapidology' ),
esc_html__( 'pop up', 'rapidology' ),
esc_html__( 'fly in', 'rapidology' ),
esc_html__( 'below post', 'rapidology' ),
esc_html__( 'inline', 'rapidology' ),
esc_html__( 'locked content', 'rapidology' ),
esc_html__( 'widget', 'rapidology' ),
esc_html__( 'bar', 'rapidology' )
);
$this->display_home_tab_tables();
break;
case 'account' :
printf( '
<div class="rad_dashboard_row rad_dashboard_new_account_row">
<h1>%2$s</h1>
<button class="rad_dashboard_icon">%1$s</button>
<input type="hidden" name="action" value="new_account" />
</div>',
esc_html__( 'new account', 'rapidology' ),
esc_html__( 'My Accounts', 'rapidology' )
);
$this->display_accounts_table();
break;
case 'edit_account' :
echo '<div id="rad_dashboard_edit_account_tab"></div>';
break;
case 'stats' :
printf( '
<div class="rad_dashboard_row rad_dashboard_stats_row">
<h1>%1$s</h1>
<div class="rad_rapidology_stats_controls">
<button class="rad_dashboard_icon rad_rapidology_clear_stats">%2$s</button>
<span class="rad_dashboard_confirmation">%4$s</span>
<button class="rad_dashboard_icon rad_rapidology_refresh_stats">%3$s</button>
</div>
</div>
<span class="rad_rapidology_stats_spinner"></span>
<div class="rad_dashboard_stats_contents"></div>',
esc_html( $option['title'] ),
esc_html__( 'Clear Stats', 'rapidology' ),
esc_html__( 'Refresh Stats', 'rapidology' ),
sprintf(
'%1$s<span class="rad_dashboard_confirm_stats">%2$s</span><span class="rad_dashboard_cancel_delete">%3$s</span>',
esc_html__( 'Remove all the stats data?', 'rapidology' ),
esc_html__( 'Yes', 'rapidology' ),
esc_html__( 'No', 'rapidology' )
)
);
break;
case 'support' :
include_once(RAD_RAPIDOLOGY_PLUGIN_DIR.'includes/static_content/marketing.php');
break;
}
}
/**
* Generates tab for the premade layouts selection
*/
function generate_premade_templates( $option ) {
switch ( $option['type'] ) {
case 'premade_templates' :
echo '<div class="rad_rapidology_premade_grid"><span class="spinner rad_rapidology_premade_spinner"></span></div>';
break;
case 'preview_optin' :
printf( '
<div class="rad_dashboard_row rad_dashboard_preview">
<button class="rad_dashboard_icon">%1$s</button>
</div>',
esc_html__( 'Preview', 'rapidology' )
);
break;
}
}
function generate_template_filter(){
if(! wp_verify_nonce( $_POST['rapidology_premade_nonce'], 'rapidology_premade' )){
die(-1);
}
$filter_path = RAD_RAPIDOLOGY_PLUGIN_URI.'/images';
$isRapidBar = '';
$isRedirect = '';
$isRapidBar = $_POST['isRapidBar'];
$isRedirect = $_POST['isRedirect'];
if($isRapidBar == 'true'){
$this->generate_premade_grid();
die();
}
$output = '';
$output .= <<<SOL
<div class="layout_filter_wrapper">
<p>Filter by Layout</p>
<div class="layout_filter">
<img src="$filter_path/layout_bottomform_sidepic.svg" data-form="bottom" data-img="left"/>
<img src="$filter_path/layout_bottomform_toppic.svg" data-form="bottom" data-img="above"/>
<img src="$filter_path/layout_sideform.svg" data-form="right" data-img="side"/>
</div>
</div>
<div class="templates_loading">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-5 -15 120 120" width="150" height="150" fill="#14283a">
<circle transform="translate(14 0)" cx="0" cy="14" r="0">
<animate attributeName="r" values="0; 20; 0; 0" dur="1.2s" repeatCount="indefinite" begin="0"
keytimes="0;0.2;0.7;1" keySplines="0.2 0.2 0.4 0.8;0.2 0.6 0.4 0.8;0.2 0.6 0.4 0.8" calcMode="spline" />
</circle>
<circle transform="translate(50 0)" cx="0" cy="14" r="0">
<animate attributeName="r" values="0; 20; 0; 0" dur="1.2s" repeatCount="indefinite" begin="0.3"
keytimes="0;0.2;0.7;1" keySplines="0.2 0.2 0.4 0.8;0.2 0.6 0.4 0.8;0.2 0.6 0.4 0.8" calcMode="spline" />
</circle>
<circle transform="translate(80 0)" cx="0" cy="14" r="0">
<animate attributeName="r" values="0; 20; 0; 0" dur="1.2s" repeatCount="indefinite" begin="0.6"
keytimes="0;0.2;0.7;1" keySplines="0.2 0.2 0.4 0.8;0.2 0.6 0.4 0.8;0.2 0.6 0.4 0.8" calcMode="spline" />
</circle>
</svg>
</div>
<div class="rad_rapidology_premade_grid"></div>
SOL;
die($output);
}
function generate_premade_grid() {
$isRapidBar = '';
$isRedirect = '';
$formLocation = '';
$imgLocation = '';
$rapidBarClass = '';
if (! wp_verify_nonce( $_POST['rapidology_premade_nonce'], 'rapidology_premade' )){
die(-1);
}
$isRapidBar = $_POST['isRapidBar'];
$isRedirect = $_POST['isRedirect'];
$formLocation = ($_POST['formLocation'] != '' ? $_POST['formLocation'] : '');
$imgLocation = $_POST['imgLocation'];
$layoutFolder = $isRedirect == 'true' ? 'redirect' : 'form';
$filter_path = RAD_RAPIDOLOGY_PLUGIN_URI.'/images';
if($isRapidBar == 'true'){
require_once(RAD_RAPIDOLOGY_PLUGIN_DIR . 'includes/ext/rapidology_rapidbar/layouts/'.$layoutFolder.'/premade-layouts.php');
$imgpath = RAD_RAPIDOLOGY_PLUGIN_URI . '/includes/ext/rapidology_rapidbar/layouts/'.$layoutFolder.'/images/thumb_';
$rapidBarClass = ' rapidbar_layouts';
}else {
require_once(RAD_RAPIDOLOGY_PLUGIN_DIR . 'includes/premade-layouts.php');
$imgpath = RAD_RAPIDOLOGY_PLUGIN_URI . '/images/thumb_';
}
$select_layouts = array();
if($isRapidBar == 'true'){
$select_layouts = $all_layouts;
}else {
if ( isset( $all_layouts ) ) {
foreach ( $all_layouts as $id => $array ) {
foreach ( $array as $key => $value ) {
if ( $key == 'rad_dashboard_form_orientation' ) {
if ( $value == $formLocation ) {
$select_layouts[ $id ] = $array;
}
}
}
}
}
//now filter based on img location
if ( $formLocation != 'right' ) {
if ( isset( $select_layouts ) ) {
foreach ( $select_layouts as $id => $array ) {
foreach ( $array as $key => $value ) {
if ( $key == 'rad_dashboard_image_orientation' ) {
if ( $value != $imgLocation ) {
unset( $select_layouts[ $id ] );
}
}
}
}
}
}
}
$output = '';
if ( isset( $select_layouts ) ) {
$i = 0;
$output .= '<div class="rad_rapidology_premade_grid'.$rapidBarClass.'">';
foreach ( $select_layouts as $layout_id => $layout_options ) {
$output .= sprintf( '
<div class="rad_rapidology_premade_item%2$s rad_rapidology_premade_id_%1$s" data-layout="%1$s">
<div class="rad_rapidology_premade_item_inner">
<img src="%3$s" alt="" />
</div>
</div>',
esc_attr( $layout_id ),
0 == $i ? ' rad_rapidology_layout_selected' : '',
esc_attr( $imgpath . $layout_id . '.svg' )
);
$i ++;
}
$output .= '</div>';
}
die( $output );
}
/**
* Gets the layouts data, converts it to json string and passes back to js script to fill the form with predefined values
*/
function get_premade_values() {
$this->permissionsCheck();
$isRapidBar = '';
$isRedirect = '';
if(! wp_verify_nonce( $_POST['rapidology_premade_nonce'], 'rapidology_premade' )){
die(-1);
}
$premade_data_json = str_replace( '\\', '', $_POST['premade_data_array'] );
$premade_data = json_decode( $premade_data_json, true );
$layout_id = $premade_data['id'];
$isRapidBar = $_POST['isRapidBar'];
$isRedirect = $_POST['isRedirect'];
$layoutFolder = $isRedirect == 'true' ? 'redirect' : 'form';
if($isRapidBar == 'true'){
require_once(RAD_RAPIDOLOGY_PLUGIN_DIR . 'includes/ext/rapidology_rapidbar/layouts/'.$layoutFolder.'/premade-layouts.php');
}else {
require_once(RAD_RAPIDOLOGY_PLUGIN_DIR . 'includes/premade-layouts.php');
}
if ( isset( $all_layouts[ $layout_id ] ) ) {
$options_set = json_encode( $all_layouts[ $layout_id ] );
}
die( $options_set );
}
/**
* Generates output for the Stats tab
*/
function generate_stats_tab() {
$this->permissionsCheck();
$options_array = RAD_Rapidology::get_rapidology_options();
$output = sprintf( '
<div class="rad_dashboard_stats_contents rad_dashboard_stats_ready">
<div class="rad_dashboard_all_time_stats">
<h3>%1$s</h3>
%2$s
</div>
<div class="rad_dashboard_optins_stats rad_dashboard_lists_stats_graph">
<div class="rad_rapidology_graph_header">
<h3>%6$s</h3>
<div class="rad_rapidology_graph_controls">
<a href="#" class="rad_rapidology_graph_button rad_rapidology_active_button" data-period="30">%7$s</a>
<a href="#" class="rad_rapidology_graph_button" data-period="12">%8$s</a>
<select class="rad_rapidology_graph_select_list">%9$s</select>
</div>
</div>
%5$s
</div>
<div class="rad_dashboard_optins_stats rad_dashboard_optins_all_table">
<div class="stats-collapse"><h2 style="display:inline">View Opt-In Stats</h2><span class="dashicons dashicons-arrow-down-alt2 rad_dashboard_show_hide show-hide-icon"></span></div>
<div class="rad_dashboard_optins_list">
%3$s
</div>
</div>
<div class="stats-collapse list-stats"><h2 style="display:inline">View List Stats</h2><span class="dashicons dashicons-arrow-down-alt2 rad_dashboard_show_hide show-hide-icon"></span></div>
<div class="rad_dashboard_optins_stats rad_dashboard_lists_stats">
%4$s
</div>
<div class="stats-collapse page-stats"><h2 style="display:inline">View Page Stats</h2><span class="dashicons dashicons-arrow-down-alt2 rad_dashboard_show_hide show-hide-icon"></span></div>
%10$s
</div>',
esc_html__( 'Overview', 'rapidology' ),
$this->generate_all_time_stats(),
$this->generate_optins_stats_table( 'conversion_rate', true ),
( ! empty( $options_array['accounts'] ) )
? sprintf(
'<div class="rad_dashboard_optins_list">
%1$s
</div>',
$this->generate_lists_stats_table( 'count', true )
)
: '',
$this->generate_lists_stats_graph( 30, 'day', '' ), // #5
esc_html__( 'New sign ups', 'rapidology' ),
esc_html__( 'Last 30 days', 'rapidology' ),
esc_html__( 'Last 12 month', 'rapidology' ),
$this->generate_all_lists_select(),
$this->generate_pages_stats() // #10
);
return $output;
}
/**
* Generates the stats tab and passes it to jQuery
* @return string
*/
function reset_stats() {
$this->permissionsCheck();
if(! check_ajax_referer('rapidology_stats_nonce', 'rapidology_stats_nonce')){
die(-1);
}
$output = $this->generate_stats_tab();
update_option( 'rad_rapidology_stats_cache', $output );
if ( ! wp_get_schedule( 'rapidology_stats_auto_refresh' ) ) {
wp_schedule_event( time(), 'daily', 'rapidology_stats_auto_refresh' );
}
die( $output );
}
/**
* Update Stats and save it into WP DB
* @return void
*/
function perform_stats_refresh() {
$fresh_stats = $output = $this->generate_stats_tab();
update_option( 'rad_rapidology_stats_cache', $fresh_stats );
}
/**
* Removes all the stats data from DB
* @return void
*/
function clear_stats() {
$this->permissionsCheck();
if(! check_ajax_referer('rapidology_stats_nonce', 'rapidology_stats_nonce')){
die(-1);
}
global $wpdb;
$table_name = $wpdb->prefix . 'rad_rapidology_stats';
// construct sql query to mark removed options as removed in stats DB
$sql = "TRUNCATE TABLE $table_name";
$wpdb->query( $sql );
}
/**
* Removes stats data from DB for single optin
* @return void
*/
function clear_stats_single_optin() {
if(! check_ajax_referer('rapidology_stats_nonce', 'rapidology_stats_nonce')){
die(-1);
}
delete_option( 'rad_rapidology_stats_cache' );
global $wpdb;
$optin_id = sanitize_text_field($_POST['optin_id']);
$table_name = $wpdb->prefix . 'rad_rapidology_stats';
// construct sql query to mark removed options as removed in stats DB
$sql = "DELETE FROM $table_name WHERE optin_id = '$optin_id'";
$wpdb->query( $sql );
}
/**
* Generates the Lists menu for Lists stats graph
* @return string
*/
function generate_all_lists_select() {
$options_array = RAD_Rapidology::get_rapidology_options();
$output = sprintf( '<option value="all">%1$s</option>', __( 'All lists', 'rapidology' ) );
if ( ! empty( $options_array['accounts'] ) ) {
foreach ( $options_array['accounts'] as $service => $accounts ) {
foreach ( $accounts as $name => $details ) {
if ( ! empty( $details['lists'] ) ) {
foreach ( $details['lists'] as $id => $list_data ) {
$output .= sprintf(
'<option value="%2$s">%1$s</option>',
esc_html( $service . ' - ' . $list_data['name'] ),
esc_attr( $service . '_' . $id )
);
}
}
}
}
}
return $output;
}
/**
* Generates the Overview part of stats page
* @return string
*/
function generate_all_time_stats( $empty_stats = false ) {
$conversion_rate = $this->conversion_rate( 'all' );
$all_subscribers = $this->calculate_subscribers( 'all' );
$growth_rate = $this->calculate_growth_rate( 'all' );
$ouptut = sprintf(
'<div class="rad_dashboard_stats_container">
<div class="all_stats_column conversion_rate">
<span class="value">%1$s</span>
<span class="caption">%2$s</span>
</div>
<div class="all_stats_column subscribers">
<span class="value">%3$s</span>