-
Notifications
You must be signed in to change notification settings - Fork 24
/
sendpress.php
1908 lines (1485 loc) · 58.3 KB
/
sendpress.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: SendPress Newsletters
Version: 1.24.8.19
Plugin URI: https://sendpress.com
Description: Easy to manage Newsletters for WordPress.
Author: SendPress
Author URI: https://sendpress.com/
Text Domain: sendpress
Domain Path: /languages/
*/
if ( ! defined( 'DB_NAME' ) ) {
header( 'HTTP/1.0 403 Forbidden' );
die;
}
global $blog_id;
defined( 'SENDPRESS_API_BASE' ) or define( 'SENDPRESS_API_BASE', 'http://api.sendpress.com' );
define( 'SENDPRESS_API_VERSION', 1 );
define( 'SENDPRESS_MINIMUM_WP_VERSION', '3.6' );
define( 'SENDPRESS_VERSION', '1.24.8.19' );
define( 'SENDPRESS_URL', plugin_dir_url( __FILE__ ) );
define( 'SENDPRESS_PATH', plugin_dir_path( __FILE__ ) );
define( 'SENDPRESS_BASENAME', plugin_basename( __FILE__ ) );
define( 'SENDPRESS_IRON', 'http://sendpress.com/iron' );
define( 'SENDPRESS_SENDER_KEY', md5( __FILE__ . $blog_id ) );
define( 'SENDPRESS_CRON', md5( __FILE__ . $blog_id ) );
if ( ! defined( 'SENDPRESS_FILE' ) ) {
define( 'SENDPRESS_FILE', __FILE__ );
}
if ( ! defined( 'SENDPRESS_STORE_URL' ) ) {
define( 'SENDPRESS_STORE_URL', 'https://store.sendpress.com' );
}
if ( ! defined( 'SENDPRESS_PRO_NAME' ) ) {
define( 'SENDPRESS_PRO_NAME', 'SendPress Pro' );
}
global $pro_names;
$pro_names = array( 256, 806, 807,30800 ); //pro1, pro3, pro20, Sp Pro
/*
*
* Supporting Classes they build out the WordPress table views.
*
*/
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
/*
*
* Supporting Classes they build out the WordPress table views.
*
*/
if ( ! class_exists( 'SendPress_Pro_Updater' ) ) {
require_once( SENDPRESS_PATH . 'classes/class-sendpress-pro-updater.php' );
}
// AutoLoad Classes
spl_autoload_register( array( 'SendPress', 'autoload' ) );
require_once( SENDPRESS_PATH . 'inc/functions.php' );
/*
require_once( SENDPRESS_PATH . 'classes/class-file-loader.php' );
$sp_loader = new File_Loader('SendPress Required Class');
*/
//require_once( SENDPRESS_PATH . 'classes/selective-loader.php' );
if ( ! defined( 'SENDPRESS_TRANSIENT_LENGTH' ) ) {
define( 'SENDPRESS_TRANSIENT_LENGTH', 7 * 86400 );
}
/**
* The Main Brain.
*
* @package SendPress
* @subpackage
* @since thedawnoftime
*/
class SendPress {
var $prefix = 'sendpress_';
var $ready = false;
var $_nonce_value = 'sendpress-is-awesome';
var $_current_action = '';
var $_current_view = '';
var $_email_post_type = 'sp_newsletters';
var $_report_post_type = 'sp_report';
var $adminpages = array(
'sp',
'sp-overview',
'sp-reports',
'sp-emails',
'sp-templates',
'sp-subscribers',
'sp-settings',
'sp-queue',
'sp-pro',
'sp-help'
);
var $_templates = array();
var $_messages = array();
var $_page = '';
var $testmode = false;
var $_posthelper = '';
var $_debugAddress = '[email protected]';
var $_debugMode = false;
public $email_tags;
public $log;
public $db;
public $api;
public $validate;
public $customizer;
public $loader;
private static $instance;
function nonce_value() {
return 'sendpress-is-awesome';
}
function __construct() {
//add_action( 'admin_init' , array( 'SendPress' , 'wp' ) );
add_action( 'init', array( $this, 'init' ) );
add_action( 'widgets_init', array( $this , 'load_widgets' ) );
/*
add_action( 'widgets_init',
create_function( '', 'return register_widget("SendPress_Widget_Forms");' )
);
add_action( 'widgets_init',
create_function( '', 'return register_widget("SendPress_Widget_Signup");' )
);
*/
add_action( 'plugins_loaded', array( $this, 'load_plugin_language' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'wp_enqueue_script' ) );
add_action( 'init', array( 'SendPress_Shortcode_Loader', 'init' ) );
do_action( 'sendpress_loaded' );
}
public static function autoload( $className ) {
if ( strpos( $className, 'SendPress' ) !== 0 ) {
return;
}
// Convert Classname to filename
$cls = str_replace( '_', '-', strtolower( $className ) );
if ( substr( $cls, - 1 ) == '-' ) {
//AutoLoad seems to get odd clasname sometimes that ends with _
return;
}
if ( class_exists( $className ) ) {
return;
}
if ( strpos( $className, '_SC_' ) != false ) {
if ( defined( 'SENDPRESS_PRO_PATH' ) ) {
$pro_file = SENDPRESS_PRO_PATH . "classes/sc/class-" . $cls . ".php";
if ( file_exists( $pro_file ) ) {
include SENDPRESS_PRO_PATH . "classes/sc/class-" . $cls . ".php";
return;
}
}
include SENDPRESS_PATH . "classes/sc/class-" . $cls . ".php";
return;
}
if ( strpos( $className, '_Tag_' ) != false ) {
include SENDPRESS_PATH . "classes/tag/class-" . $cls . ".php";
return;
}
if ( strpos( $className, '_DB' ) != false ) {
include SENDPRESS_PATH . "classes/db/class-" . $cls . ".php";
return;
}
if ( strpos( $className, '_REST' ) != false ) {
include SENDPRESS_PATH . "classes/api/v1/class-" . $cls . ".php";
return;
}
if ( strpos( $className, 'Public_View' ) != false ) {
if ( defined( 'SENDPRESS_PRO_PATH' ) ) {
$pro_file = SENDPRESS_PRO_PATH . "classes/public-views/class-" . $cls . ".php";
if ( file_exists( $pro_file ) ) {
include SENDPRESS_PRO_PATH . "classes/public-views/class-" . $cls . ".php";
return;
}
}
if ( file_exists( SENDPRESS_PATH . "classes/public-views/class-" . $cls . ".php" ) ) {
include SENDPRESS_PATH . "classes/public-views/class-" . $cls . ".php";
}
return;
}
if ( strpos( $className, 'View' ) != false ) {
if ( defined( 'SENDPRESS_PRO_PATH' ) ) {
$pro_file = SENDPRESS_PRO_PATH . "classes/views/class-" . $cls . ".php";
if ( file_exists( $pro_file ) ) {
include SENDPRESS_PRO_PATH . "classes/views/class-" . $cls . ".php";
return;
}
}
include SENDPRESS_PATH . "classes/views/class-" . $cls . ".php";
return;
}
if ( strpos( $className, 'Module' ) != false ) {
if ( defined( 'SENDPRESS_PRO_PATH' ) ) {
$pro_file = SENDPRESS_PRO_PATH . "classes/modules/class-" . $cls . ".php";
if ( file_exists( $pro_file ) ) {
include SENDPRESS_PRO_PATH . "classes/modules/class-" . $cls . ".php";
return;
}
}
include SENDPRESS_PATH . "classes/modules/class-" . $cls . ".php";
return;
}
if ( defined( 'SENDPRESS_PRO_PATH' ) ) {
$pro_file = SENDPRESS_PRO_PATH . "classes/class-" . $cls . ".php";
if ( file_exists( $pro_file ) ) {
include SENDPRESS_PRO_PATH . "classes/class-" . $cls . ".php";
return;
}
}
if ( file_exists( SENDPRESS_PATH . "classes/class-" . $cls . ".php" ) ) {
include SENDPRESS_PATH . "classes/class-" . $cls . ".php";
}
return;
}
static $array_of_db_objects;
public function load( $object ){
$class_name = "SendPress_DB_" . $object;
if(isset(self::$array_of_db_objects[$object])) {
return self::$array_of_db_objects[$object];
}
if(class_exists($class_name)){
$class = new $class_name();
self::$array_of_db_objects[$object] = $class;
} else {
$class = new WP_Error();
}
return $class;
}
public static function get_instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof SendPress ) ) {
self::$instance = new SendPress;
self::$instance->template_tags = new SendPress_Template_Tags();
self::$instance->api = new SendPress_API();
self::$instance->rest_api = new SendPress_Api_Loader();
self::$instance->validate = new SendPress_Security();
self::$instance->log = new SendPress_Logging();
self::$instance->db = new stdClass();
self::$instance->db->subscribers_tracker = new SendPress_DB_Subscribers_Tracker();
self::$instance->db->url = new SendPress_DB_Url();
self::$instance->db->subscribers_url = new SendPress_DB_Subscribers_Url();
self::$instance->db->suppression = new SendPress_DB_Suppression();
self::$instance->loader = new SendPress_Loader();
}
return self::$instance;
}
/**
* Create the wp-admin menu link
*/
public function add_menu_link() {
$link = $this->get_customizer_link();
add_submenu_page( 'themes.php', 'Email Templates', 'Email Templates', apply_filters( 'mailtpl/roles', 'edit_theme_options'), $link , null );
}
/**
* Simple function to generate link for customizer
* @return string
*/
public function get_customizer_link( $email = 0 , $return = false) {
if($return == false){
$return = admin_url();
}
$link = add_query_arg(
array(
'url' => urlencode( site_url( '/?sendpress_display=true&spemail='.$email ) ),
'return' => urlencode( $return ),
'sendpress_display' => 'true',
'spemail' => $email
),
'customize.php'
);
return $link;
}
static function update_templates() {
sendpress_register_template(
array(
'slug' => 'original',
'path' => SENDPRESS_PATH . 'templates/original.html',
'name' => 'SendPress Original'
)
);
sendpress_register_template(
array(
'slug' => '1column',
'path' => SENDPRESS_PATH . 'templates/1column.html',
'name' => 'Responsive 1 Column'
)
);
sendpress_register_template(
array(
'slug' => '2columns-to-rows',
'path' => SENDPRESS_PATH . 'templates/2columns-to-rows.html',
'name' => '2 Column Top - Wide Bottom - Responsive'
)
);
}
function init() {
add_action('sendpress_template_loaded', array('SendPress_Videos', 'add_video_filter') );
//add_action('register_form',array( $this , 'add_registration_fields'));
if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
{
SendPress_Ajax_Loader::init();
} else {
SendPress_Pro_Manager::init();
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'admin_notices', array( $this, 'admin_notice' ) );
if ( defined( 'WP_ADMIN' ) && WP_ADMIN == true ) {
$sendpress_screen_options = new SendPress_Screen_Options();
}
//add_filter( 'cron_schedules', array($this,'cron_schedule' ));
//add_action( 'wp_loaded', array( $this, 'add_cron' ) );
if ( SendPress_Option::get( 'sp_widget_shortdoces' ) ) {
add_filter( 'widget_text', 'do_shortcode' );
}
add_image_size( 'sendpress-max', 600, 600 );
add_filter( 'template_include', array( $this, 'template_include' ), 1 );
add_action( 'sendpress_cron_action', array( $this, 'sendpress_cron_action_run' ) );
//using this for now, might find a different way to include things later
// global $load_signup_js;
// $load_signup_js = false;
add_action( 'wp_enqueue_scripts', array( $this, 'add_front_end_scripts' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'add_front_end_styles' ) );
add_action( 'wp_loaded', array( 'SendPress_Cron' , 'auto_cron' ) );
add_filter( 'cron_schedules', array( 'SendPress_Cron', 'cron_schedules' ) );
}
if( !defined('SPNL_DISABLE_SENDING_WP_MAIL') && apply_filters('spnl_wpmail_sending', true ) ){
sendpress_register_sender( 'SendPress_Sender_Website' );
}
if( !defined('SPNL_DISABLE_SENDING_GMAIL') && apply_filters('spnl_gmail_sending', true ) ){
sendpress_register_sender( 'SendPress_Sender_Gmail' );
}
if( !defined('SPNL_DISABLE_SENDING_DELIVERY') && apply_filters('spnl_delivery_sending', true ) ){
sendpress_register_sender( 'SendPress_Sender_SPNL' );
}
do_action( 'sendpress_init' );
SendPress_Admin::add_cap( 'Emails_Send', 'sendpress_email_send' );
$indexer = "";
$permalinks = get_option( 'permalink_structure' );
if ( $permalinks ) {
$pos = strpos( $permalinks, "index.php" );
if ( $pos > 0 ) { // note: three equal signs
$indexer = "index.php/";
}
}
add_rewrite_rule(
"^{$indexer}sendpress/([^/]+)/?",
'index.php?sendpress=$matches[1]',
"top" );
$this->add_custom_post();
/*
if( defined( 'DOING_AJAX' ) || ( isset( $_GET['sendpress_display'] ) && 'true' == $_GET['sendpress_display'] ) ) {
$this->loader->add_action( 'customize_register', $this->customizer, 'register_customize_sections' );
$this->loader->add_action( 'customize_section_active', $this->customizer, 'remove_other_sections', 10, 2 );
$this->loader->add_action( 'customize_panel_active', $this->customizer, 'remove_other_panels', 10, 2 );
$this->loader->add_action( 'template_include', $this->customizer, 'capture_customizer_page' );
}
if( isset( $_GET['sendpress_display'] ) ) {
$this->loader->add_action( 'customize_controls_enqueue_scripts', $this->customizer, 'enqueue_scripts' );
$this->loader->add_action( 'customize_preview_init', $this->customizer, 'enqueue_template_scripts', 99 );
//$this->loader->add_action( 'init', $this->customizer, 'remove_all_actions', 99 );
$this->customizer->remove_all_actions();
}
*/
$this->loader->run();
}
function add_registration_fields() {
//Get and set any values already sent
$user_extra = SPNL()->validate->_isset('user_extra') ? SPNL()->validate->_string('user_extra') : '';
?>
<p>
<label for="user_extra">
<input type="checkbox" name="user_extra" id="user_extra"
value="<?php echo esc_attr( stripslashes( $user_extra ) ); ?>"/> <?php _e( 'Join our mailing List.', 'sendpress' ); ?>
</label><br>
</p><br>
<?php
}
static function add_cron() {
if ( SendPress_Option::get( 'autocron', 'no' ) == 'yes' && wp_next_scheduled( 'sendpress_cron_action' ) ) {
wp_clear_scheduled_hook( 'sendpress_cron_action' );
} else {
if ( ! wp_next_scheduled( 'sendpress_cron_action' ) ) {
wp_schedule_event( time(), 'hourly', 'sendpress_cron_action' );
}
}
}
function user_has_cap( $all, $caps, $args ) {
if ( isset( $args[2] ) ) {
$post = get_post( $args[2] );
if ( $post !== null && $post->post_type == 'sp_newsletters' ) {
if ( current_user_can( 'sendpress_email' ) ) {
foreach ( $caps as $cap ) {
$all[ $cap ] = 1;
}
}
}
}
return $all;
}
function load_plugin_language() {
//load_plugin_textdomain( 'sendpress', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
// Set filter for plugin's languages directory
$sendpress_lang_dir = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
$sendpress_lang_dir = apply_filters( 'sendpress_languages_directory', $sendpress_lang_dir );
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), 'sendpress' );
$mofile = sprintf( '%1$s-%2$s.mo', 'sendpress', $locale );
// Setup paths to current locale file
$mofile_local = $sendpress_lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/sendpress/' . $mofile;
if ( file_exists( $mofile_global ) ) {
// Look in global /wp-content/languages/sendpress folder
load_textdomain( 'sendpress', $mofile_global );
} elseif ( file_exists( $mofile_local ) ) {
// Look in local /wp-content/plugins/easy-digital-downloads/languages/ folder
load_textdomain( 'sendpress', $mofile_local );
} else {
// Load the default language files
load_plugin_textdomain( 'sendpress', false, $sendpress_lang_dir );
}
}
/**
* Register our widget.
* 'SendPress_Signup_Widget' is the widget class used below.
*
* @since 1.0
*/
function load_widgets() {
register_widget( 'SendPress_Widget_Signup' );
register_widget( 'SendPress_Widget_Forms' );
}
function admin_notice() {
//This is the WordPress one shows above menu area.
//echo 'wtf';
}
function sendpress_notices() {
if ( in_array( 'settings', $this->_messages ) ) {
echo '<div class="error"><p>';
echo "<strong>";
_e( 'Warning!', 'sendpress' );
echo "</strong> ";
printf( __( ' Before sending any emails please setup your <a href="%1s">information</a>.', 'sendpress' ), SendPress_Admin::link( 'Settings_Account' ) );
echo '</p></div>';
}
$pause_sending = SendPress_Option::get( 'pause-sending', 'no' );
//Stop Sending for now
if ( $pause_sending == 'yes' ) {
echo '<div class="error"><p>';
echo "<strong>";
_e( 'Warning!', 'sendpress' );
echo "</strong> ";
printf( __( ' Sending has been paused. You can resume sending on the <a href="%1s">Queue</a> page.', 'sendpress' ), SendPress_Admin::link( 'Queue' ) );
echo '</p></div>';
}
}
/**
* ready_for_sending
*
* @access public
*
* @return mixed Value.
*/
function ready_for_sending() {
$ready = true;
$message = '';
$from = SendPress_Option::get( 'fromname' );
if ( $from == false || $from == '' ) {
$ready = false;
$this->show_message( 'settings' );
}
$fromemail = SendPress_Option::get( 'fromemail' );
if ( ( $from == false || $from == '' ) && ! is_email( $fromemail ) ) {
$ready = false;
$this->show_message( 'settings' );
}
/*
$canspam = SendPress_Option::get('canspam');
if($canspam == false || $canspam == ''){
$ready = false;
$this->show_message('settings');
}
*/
$this->ready = $ready;
}
function show_message( $item ) {
if ( ! in_array( $item, $this->_messages ) ) {
array_push( $this->_messages, $item );
}
}
// Hook into that action that'll fire weekly
function sendpress_cron_action_run() {
if ( SendPress_Option::get( 'autocron', 'no' ) == 'yes' ) {
return;
}
$cron_url = site_url( 'wp-cron.php' ) . '?&action=sendpress&silent=1&t=' . time();
$cron_request = apply_filters( 'cron_request', array(
'url' => $cron_url,
'args' => array(
'timeout' => 0.01,
'blocking' => false,
'sslverify' => apply_filters( 'https_local_ssl_verify', true )
)
) );
wp_remote_post( $cron_url, $cron_request['args'] );
}
function cron_schedule( $schedules ) {
$schedules['tenminutes'] = array(
'interval' => 300, // 1 week in seconds
'display' => __( 'Once Every Minute' ),
);
return $schedules;
}
function template_include( $template ) {
global $post;
if ( ( get_query_var( 'sendpress' ) ) || SPNL()->validate->_isset('sendpress') ) {
add_filter( 'do_rocket_lazyload', '__return_false' );
$action = SPNL()->validate->_isset('sendpress') ? SPNL()->validate->_string('sendpress'): get_query_var( 'sendpress' ) ;
//Look for encrypted data
$data = SendPress_Data::decrypt( $action );
$view = false;
if ( is_object( $data ) ) {
$view = isset( $data->view ) ? $data->view : false;
} else {
$view = $action;
}
$view_class = SendPress_Data::get_public_view_class( $view );
if ( class_exists( $view_class ) ) {
$view_class = NEW $view_class;
$view_class->data( $data );
if ( isset( $_POST['sp'] ) && wp_verify_nonce( $_POST['sp'], 'sendpress-form-post' ) && method_exists( $view_class, 'save' ) ) {
$view_class->save();
}
$view_class->prerender();
$view_class->render();
}
//$this->load_default_screen($action);
die();
}
if ( isset( $post ) ) {
if ( $post->post_type == $this->_email_post_type || $post->post_type == $this->_report_post_type ) {
$inline = false;
if ( SPNL()->validate->_isset('inline') ) {
$inline = true;
}
SendPress_Email_Cache::build_cache_for_email( $post->ID );
$message = new SendPress_Email();
$message->id( $post->ID );
$message->subscriber_id( 0 );
$message->list_id( 0 );
$body = $message->html();
//print_r( $body );
unset( $message );
echo $body;
die();
//SendPress_Template::get_instance()->render_html(false, true, $inline );
//return SENDPRESS_PATH. '/template-loader.php';
//return dirname(__FILE__) . '/my_special_template.php';
}
/**
*
* if($post->post_type == 'sp-standard' ){
* return 'You Bet';
* }
**/
}
return $template;
}
static function add_vars( $public_query_vars ) {
$public_query_vars[] = 'sendpress';
$public_query_vars[] = 'spmanage';
$public_query_vars[] = 'splist';
$public_query_vars[] = 'spreport';
$public_query_vars[] = 'spurl';
$public_query_vars[] = 'spemail';
$public_query_vars[] = 'spms';
return $public_query_vars;
}
function add_custom_post() {
SendPress_Posts::email_post_type( $this->_email_post_type );
SendPress_Posts::report_post_type( $this->_report_post_type );
SendPress_Posts::template_post_type();
SendPress_Posts::list_post_type();
do_action( 'sendpress_custom_post_types_created', $this );
}
function create_color_picker( $value ) { ?>
<input class="cpcontroller " data-id="<?php echo $value['id']; ?>" css-id="<?php echo $value['css']; ?>"
link-id="<?php echo $value['link']; ?>" name="<?php echo $value['id']; ?>"
id="<?php echo $value['id']; ?>" type="text"
value="<?php echo isset( $value['value'] ) ? $value['value'] : $value['std']; ?>"/>
<input type='hidden' value='<?php echo $value['std']; ?>' id='default_<?php echo $value['id']; ?>'/>
<a href="#" class="btn btn-default btn-xs reset-line" data-type="cp"
data-id="<?php echo $value['id']; ?>">Reset</a>
<div id="pickholder_<?php echo $value['id']; ?>" class="colorpick clearfix" style="display:none;">
<a class="close-picker">x</a>
<div id="<?php echo $value['id']; ?>_colorpicker" class="colorpicker_space"></div>
</div>
<?php
}
function create_color_picker_iframe( $value ) { ?>
<input class="cpcontroller" iframe="true" data-id="<?php echo $value['id']; ?>"
css-id="<?php echo $value['css']; ?>" target="<?php echo $value['iframe']; ?>"
link-id="<?php echo $value['link']; ?>" name="<?php echo $value['id']; ?>"
id="<?php echo $value['id']; ?>" type="text"
value="<?php echo isset( $value['value'] ) ? $value['value'] : $value['std']; ?>"/>
<input type='hidden' value='<?php echo $value['std']; ?>' id='default_<?php echo $value['id']; ?>'/>
<a href="#" class="btn btn-default btn-xs reset-line" data-type="cp"
data-id="<?php echo $value['id']; ?>">Reset</a>
<div id="pickholder_<?php echo $value['id']; ?>" class="colorpick clearfix" style="display:none;">
<a class="close-picker">x</a>
<div id="<?php echo $value['id']; ?>_colorpicker" class="colorpicker_space"></div>
</div>
<?php
}
function plugin_mce_css( $mce_css ) {
if ( ! empty( $mce_css ) ) {
$mce_css .= ',';
}
$mce_css .= plugins_url( '/templates/simple.css', __FILE__ );
$mce_css .= ',';
$mce_css .= plugins_url( '/css/editor.css', __FILE__ );
return $mce_css;
}
/* Display a notice that can be dismissed */
function sendpress_ignore_087() {
/* Check that the user hasn't already clicked to ignore the message */
if ( ! SendPress_Option::get( 'sendpress_ignore_087' ) ) {
echo '<div class="updated"><p>';
printf( __( '<b>SendPress</b>: We have upgraded your lists to a new format. Please check your <a href="%1$s">widget settings</a> to re-enable your list(s). | <a href="%2$s">Hide Notice</a>' ), admin_url( 'widgets.php' ), admin_url( 'widgets.php?sendpress_ignore_087=0' ) );
echo "</p></div>";
}
}
function myformatTinyMCE( $in ) {
if ( isset( $in['plugins'] ) ) {
$in['plugins'] = str_replace( 'wpeditimage,', '', $in['plugins'] );
}
return $in;
}
function admin_init() {
;
$this->maybe_upgrade();
if ( ! empty( $_GET['_wp_http_referer'] ) && ( isset( $_GET['page'] ) && in_array( SPNL()->validate->page(), $this->adminpages ) ) ) {
//safe redirect with esc_url 4/20
wp_safe_redirect( esc_url_raw( remove_query_arg( array(
'_wp_http_referer',
'_wpnonce'
), stripslashes( $_SERVER['REQUEST_URI'] ) ) ) );
exit;
}
if ( isset( $_REQUEST['post_id'] ) ) {
$p = get_post( $_REQUEST['post_id'] );
if ( $p !== null && $p->post_type == 'sp_newsletters' ) {
add_filter( 'disable_captions', '__return_true' );
}
}
//Removed in 0.9.2
//$this->create_initial_list();
/*
if( SendPress_Option::get('emails-today') == false ){
$emails_today = array( date("z") => '0' );
SendPress_Option::set('emails-today', $emails_today);
}
$emails_today = SendPress_Option::get('emails-today');
$emails_today[date("z") + 1 ] = '0';
SendPress_Option::set('emails-today', $emails_today);
*/
//SendPress_Option::set('emails-today', '');
//SendPress_Option::set('allow_tracking', '');
//wp_clear_scheduled_hook( 'sendpress_cron_action' );
// Schedule an action if it's not already scheduled
/*
if ( ! wp_next_scheduled( 'sendpress_cron_action' ) ) {
wp_schedule_event( time(), 'tenminutes', 'sendpress_cron_action' );
}
*/
//wp_clear_scheduled_hook( 'sendpress_cron_action' );
/*
add_meta_box( 'email-status', __( 'Email Status', 'sendpress' ), array( $this, 'email_meta_box' ), $this->_email_post_type, 'side', 'low' );
*/
//MAKE SURE WE ARE ON AN ADMIN PAGE
if ( SPNL()->validate->page() !== false ) {
$this->_page = SPNL()->validate->page();
$this->_current_view = isset( $_GET['view'] ) ? sanitize_text_field( $_GET['view'] ) : '';
//echo $this->_page;
$view_class = $this->get_view_class( $this->_page, $this->_current_view );
//Securiry check for view
if( !is_user_logged_in() ){
wp_die('Cheating I see..');
};
//SendPress_Tracking::init();
SendPress_Notifications_Manager::init();
if ( isset( $_GET['spv'] ) ) {
SendPress_Option::set( 'version', $_GET['spv'] );
}
if ( isset( $_GET['sp-admin-code'] ) && current_user_can( 'manage_options' ) ) {
switch ( $_GET['sp-admin-code'] ) {
case 'install-tables':
$this->install_tables();
break;
case 'remove-key':
SendPress_Option::set( 'api_key', '' );
SendPress_Pro_Manager::set_pro_state( false ); //this will delete the transient
break;
default:
# code...
break;
}
}
$this->ready_for_sending();
add_action( 'admin_print_scripts', array( $this, 'editor_insidepopup' ) );
add_filter( 'gettext', array( $this, 'change_button_text' ), null, 2 );
add_action( 'sendpress_notices', array( $this, 'sendpress_notices' ) );
add_filter( 'user_has_cap', array( $this, 'user_has_cap' ), 10, 3 );
//SendPress_Option::set('default-signup-widget-settings',false);
remove_action( 'admin_init', 'Zotpress_add_meta_box', 1 );
remove_filter( 'mce_external_plugins', 'cforms_plugin' );
remove_filter( 'mce_buttons', 'cforms_button' );
remove_filter( "mce_plugins", "cforms_plugin" );
remove_filter( 'mce_buttons', 'cforms_button' );
remove_filter( 'tinymce_before_init', 'cforms_button_script' );
if ( SPNL()->validate->page() == 'sp-templates' || ( isset( $_GET['view'] ) && $_GET['view'] == 'style-email' ) ) {
wp_register_script( 'sendpress_js_styler', SENDPRESS_URL . 'js/styler.js', '', SENDPRESS_VERSION );
}
if ( defined( 'WPE_PLUGIN_BASE' ) ) {
add_action( 'admin_print_styles', array( $this, 'remove_wpengine_style' ) );
}
add_filter( 'tiny_mce_before_init', array( $this, 'myformatTinyMCE' ) );
if ( isset( $_GET['beta'] ) ) {
SendPress_Option::set( 'beta', absint( $_GET['beta'] ) );
}
if ( isset( $_GET['trackeroff'] ) ) {
SendPress_Option::set( 'tracker_off', $_GET['trackeroff'] );
}
remove_editor_styles();
add_filter( 'mce_css', array( $this, 'plugin_mce_css' ) );
//Stop Facebook Plugin from posting emails to Facebook.
remove_action( 'transition_post_status', 'fb_publish_later', 10, 3 );
$tiny = new SendPress_TinyMCE();
//Securiry check for view
$view_class = NEW $view_class;
$view_class->admin_init();
add_action( 'sendpress_admin_scripts', array( $view_class, 'admin_scripts_load' ) );
$this->_current_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : '';
$this->_current_action = isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : $this->_current_action;
$this->_current_action = isset( $_POST['action2'] ) ? sanitize_text_field( $_POST['action2'] ) : $this->_current_action;
$this->_current_action = isset( $_POST['action'] ) && sanitize_text_field( $_POST['action'] ) !== '-1' ? sanitize_text_field( $_POST['action'] ) : $this->_current_action;
$method = str_replace( "-", "_", $this->_current_action );
$method = str_replace( " ", "_", $method );
if ( method_exists( $view_class, 'security_check' ) ) {
call_user_func( array( $view_class, 'security_check' ) );
}
if ( ! empty( $_POST ) && ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], $this->_nonce_value ) ) ) {
if ( method_exists( $view_class, $method ) ) {
//view_class$save_class = new $view_class;
$view_class->$method();
//print_r($save_class);
} elseif ( method_exists( $view_class, 'save' ) ) {
//$view_class::save($this);
//$save_class = new $view_class;
$view_class->save( );
} else {
require_once( SENDPRESS_PATH . 'inc/helpers/sendpress-post-actions.php' );
}
} else if ( isset( $_GET['action'] ) || isset( $_GET['action2'] ) ) {
$this->_current_action = sanitize_text_field( $_GET['action'] );
$this->_current_action = ( isset( $_GET['action2'] ) && sanitize_text_field( $_GET['action2'] ) !== '-1' ) ? sanitize_text_field( $_GET['action2'] ) : $this->_current_action;
$method = str_replace( "-", "_", $this->_current_action );
$method = str_replace( " ", "_", $method );
if ( method_exists( $view_class, $method ) ) {
call_user_func( array( $view_class, $method ) );
die();
}
require_once( SENDPRESS_PATH . 'inc/helpers/sendpress-get-actions.php' );
}
}
}
function wp_enqueue_script() {
global $pagenow;
wp_register_script( 'sendpress-widget-js', SENDPRESS_URL . 'js/sendpress.widget.js', '', SENDPRESS_VERSION );
if ( $pagenow === 'widgets.php' ) {
wp_enqueue_script( 'sendpress-widget-js' );
}
//MAKE SURE WE ARE ON AN ADMIN PAGE