-
Notifications
You must be signed in to change notification settings - Fork 4
/
jaiminho.php
1804 lines (1537 loc) · 64.3 KB
/
jaiminho.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: Jaiminho Newsletters
Version: 2.1
Plugin URI: https://jaiminho.redelivre.org.br
Description: Plugin que atualiza o Seedpress em tempo de execução com algumas personalizações para a Rede Livre.
Author: RedeLivre
Author URI: https://redelivre.org.br
Developer: https://github.com/cabelotaina
Developer: https://github.com/jacsonp
Text Domain: jaiminho
Domain Path: /languages/
*/
define( 'JAIMINHO_URL', plugin_dir_url( __FILE__ ) );
define( 'JAIMINHO_VERSION', 0.0 );
define( 'JAIMINHO_PATH', plugin_dir_path( __FILE__ ) );
define( 'SPNL_DISABLE_SENDING_DELIVERY',false);
define( 'SPNL_DISABLE_SENDING_GMAIL',false);
define( 'SPNL_DISABLE_SENDING_WP_MAIL',false);
// sendpress classes
require_once( ABSPATH . '/wp-content/plugins/sendpress/sendpress.php' );
require_once( ABSPATH . '/wp-content/plugins/sendpress/classes/class-sendpress-option.php' );
// divi classes
require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'wp-divi'. DIRECTORY_SEPARATOR .'modules.php';
// jaiminho classes
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-send.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/plugins/mce-table-buttons/mce_table_buttons.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/class-jaiminho-signup-shortcode-old.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-overview.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-queue-all.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-queue.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-settings.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-queue-errors.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-templates.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-temp.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-social.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-systememail.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-tempstyle.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-systememailcreate.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-systememailedit.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-create.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-edit.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-send.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-send-confirm.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-send-queue.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-send-tempdelete.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-send-tempclone.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-settings-account.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-reports.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-subscribers.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-subscribers-csvimport.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-subscribers-add.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/views/class-jaiminho-view-emails-list-filter.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/class-jaiminho-sender-redelivre.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/class-jaiminho-sender-network.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/class-jaiminho-sender-gmail.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/class-tgm-plugin-activation.php' );
require_once( ABSPATH . '/wp-content/plugins/jaiminho/classes/class-jaiminho-widget-signup.php' );
class Jaiminho extends SendPress
{
protected $plugin_name;
protected $sendpress_name;
public function __construct()
{
add_action('init', array( $this , 'Init' ) );
add_action('widgets_init', create_function( '' , 'return register_widget("Jaiminho_Widget_Signup");'));
//spl_autoload_register( array( 'Jaiminho', 'autoload' ) );
Jaiminho_Signup_Shortcode::init();
}
public function Init()
{
$sendpress_name = __( 'SendPress', 'sendpress' );
add_action( 'init' , array( $this , 'jaiminho_check_rewrite' ) );
add_action( 'init' , array( $this , 'run_script' ) );
sendpress_register_sender( 'Jaiminho_Sender_RedeLivre' );
sendpress_register_sender( 'Jaiminho_Sender_Gmail' );
remove_action( 'in_admin_footer',array(SendPress_View::get_instance(),'footer'),10);
wp_register_script('jaiminho_disable', JAIMINHO_URL .'js/disable.js' ,'',JAIMINHO_VERSION);
add_action( 'admin_menu', array($this,'remove_menu'));
add_action( 'admin_menu', array($this,'admin_menu'));
add_action( 'toplevel_page_sp-overview', array($this,'render_view_jaiminho'));
add_action( 'jaiminho_page_sp-settings', array($this,'render_view_jaiminho'));
add_filter( 'admin_footer_text', '__return_empty_string', 11 );
add_filter( 'update_footer', '__return_empty_string', 11 );
add_action( 'admin_print_styles' , array( $this , 'jaiminho_admin_footer_css_hide' ) );
add_filter( 'tiny_mce_before_init', array( $this, 'myformatTinyMCE' ) );
if (is_multisite())
{
add_action( 'network_admin_menu' , array( $this , 'jaiminho_network_settings' ) );
sendpress_register_sender( 'Jaiminho_Sender_NetWork' );
add_action( 'wpmu_new_blog', array( $this , 'jaiminho_set_settings_for_new_site' ) );
}
add_action( 'tgmpa_register', array( $this , 'jaiminho_register_required_plugins' ) );
remove_action( 'init' , array( SPNL() , 'toplevel_page_sp-overview' ) );
add_action( 'sendpress_notices', array( $this, 'jaiminho_notices' ) );
add_action( 'init', array( $this, 'frame_it_up' ), 20 );
add_action( 'admin_enqueue_scripts', array( $this, 'load_admin_script') );
add_action( 'admin_action_export', array($this,'export_report') );
add_action( 'admin_action_exportsenderrors', array($this,'exportsenderrors') );
add_action( 'admin_action_send_message', array($this,'send_message') );
add_action( 'admin_action_export_all_lists', array($this,'export_all_lists') );
add_action( 'admin_action_remove_hard_bounces', array($this,'remove_hard_bounces') );
add_action( 'admin_action_import', array($this,'save_import') );
add_filter( 'mce_buttons_2', array($this,'mce_buttons') );
add_action( 'admin_action_addsubscriber', array($this,'addsubscriber') );
add_action( 'admin_action_createsubscriber', array($this,'create_subscriber') );
add_action( 'admin_action_createsubscribers', array($this,'create_subscribers') );
add_action( 'admin_action_sendemails', array($this,'send_emails') );
add_action( 'admin_action_saveemail', array($this,'save_email') );
add_action( 'admin_action_createlist', array($this,'create_list') );
add_action( 'admin_action_gethtml', array($this,'get_link_html_callback') );
add_action( 'admin_init', array($this,'my_tinymce_button') );
add_action( 'wp_ajax_get_link_html', array($this,'get_link_html_callback') );
add_action( 'wp_ajax_nopriv_get_link_html', array($this,'get_link_html_callback' ));
// docs to understand this see: https://codex.wordpress.org/Plugin_API/Admin_Screen_Reference
add_action( "admin_head-toplevel_page_sp-emails", array($this,'my_admin_head') );
}
public function remove_hard_bounces(){
$email = SendPress_Option::get("bounce_email");
$password = get_option("bounce_email_password");
$server = get_option("bounce_email_server");
$port = get_option("bounce_email_port");
require_once("includes/php-bounce-handler/bounce_driver.class.php");
$bouncehandler = new Bouncehandler();
/* connect to gmail */
//$hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$hostname = '{'.$server.':'.$port.'/imap/ssl/novalidate-cert}INBOX';
$username = $email;
$password = $password;
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
$emails = imap_search($inbox,'UNANSWERED');
if($emails) {
rsort($emails);
set_time_limit(0);
foreach( $emails as $email ) {
$overview = imap_fetch_overview($inbox,$email,0);
$bounce = imap_fetchheader($inbox, $email).imap_body($inbox, $email);
$multiArray = $bouncehandler->get_the_facts($bounce);
//var_dump($multiArray);
if($multiArray != array()){
if($multiArray[0]["recipient"] == "failed"){
$subscriberID = SendPress_Data::get_subscriber_by_email($multiArray[0]["recipient"]);
SendPress_Data::delete_subscriber($subscriberID);
}
}
}
}
/* close the connection */
imap_close($inbox);
SendPress_Admin::redirect( 'Subscribers' );
}
/**
* Localize Script
*/
function my_admin_head() {
$plugin_url = plugins_url( '/', __FILE__ );
?>
<!-- TinyMCE Shortcode Plugin -->
<script type='text/javascript'>
var my_plugin = {
'url': '<?php echo admin_url('admin.php'); ?>',
};
</script>
<!-- TinyMCE Shortcode Plugin -->
<?php
}
function get_link_html_callback(){
if($_GET["url"] != ""){
$url = $_GET["url"];
if(filter_var($url, FILTER_VALIDATE_URL)){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$content_old = curl_exec($ch);
curl_close($ch);
$content_old = preg_replace('/<script\b[^>]*>(.*?)<\/script>/is', "", $content_old);
$content = wp_kses($content_old,
array(
'head' => array(
'meta' => array(),
'title' => array(),
),
'a' => array(
'href' => array(
),
'title' => array(),
'style' => array(),
),
'br' => array(),
'em' => array(),
'p' => array(
'stylle' => array(),
),
'img' => array(
'src' => array(),
'style' => array(),
),
'strong' => array(),
'center' => array(),
'table' => array(
'tr' => array(
'style' => array()
),
'td' => array(
'style' => array()
),
'style' => array(),
),
'div' => array(
'style' => array(),
),
'style' => array(
'type' => array(
'text/css'
),
),
), array("http","https","ftp", "irc", "mailto"));
echo $content;
}
}
die();
}
function my_tinymce_button() {
if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
add_filter( 'mce_buttons', array($this,'my_register_tinymce_button') );
add_filter( 'mce_external_plugins', array($this,'my_add_tinymce_button') );
}
}
function my_register_tinymce_button( $buttons ) {
array_push( $buttons, "button_addlink" );
return $buttons;
}
function my_add_tinymce_button( $plugin_array ) {
$plugin_array['my_button_script'] = plugins_url( '/mybuttons.js', __FILE__ ) ;
return $plugin_array;
}
function create_list(){
$vars = $_GET;
if(count($vars) == 4){
SendPress_Admin::redirect('Emails_Send', array('emailID'=> SPNL()->validate->_int('emailID') ) );
}
global $wpdb;
$meta_table = SendPress_Data::subscriber_meta_table();
$query = "select distinct subscriberID from $meta_table where";
$name = "";
if (isset($vars["states"])) {
foreach ($vars["states"] as $state) {
$name .= "_" . $state;
$query .= $wpdb->prepare( " meta_value=%s or ", $state);
}
}
if (isset($vars['cities'])) {
foreach ($vars["cities"] as $city) {
$name .= "_" . $city;
$query .= $wpdb->prepare( " meta_value=%s or ", $city);
}
}
if (isset($vars['genres'])) {
foreach ($vars["genres"] as $genre) {
$name .= "_" . $genre;
$query .= $wpdb->prepare( " meta_value=%s or ", $genre);
}
}
if (isset($vars['categories'])) {
$last_value = end(array_values($vars["categories"]));
foreach ($vars["categories"] as $category) {
$name .= "_" . $category;
}
}
$public = 0;
$query = substr($query, 0, -3);
$list = SendPress_Data::create_list( array('name'=> $name, 'public'=>$public ) );
$subscribers = $wpdb->get_results($query);
//addsubscriber
foreach ($subscribers as $key => $subscriber) {
$subscriber = $subscriber->subscriberID;
$list_values['listID'] = $list;
$list_values['subscriberID'] = $subscriber;
$list_values['status'] = 2;
$list_values['updated'] = date('Y-m-d H:i:s');
$table = SendPress_Data::list_subcribers_table();
$result = $wpdb->insert($table,$list_values);
}
SendPress_Admin::redirect('Emails_Send', array('emailID'=> SPNL()->validate->_int('emailID') ) );
}
function send_emails(){
$saveid = SPNL()->validate->_int('post_ID');
update_post_meta( $saveid, 'send_date', date('Y-m-d H:i:s') );
$email_post = get_post( $saveid );
$subject = SendPress_Option::get('current_send_subject_'. $saveid);
$info = SendPress_Option::get('current_send_'.$saveid);
$slug = SendPress_Data::random_code();
$new_id = SendPress_Posts::copy($email_post, $subject, $slug, SPNL()->_report_post_type );
SendPress_Posts::copy_meta_info($new_id, $saveid);
$lists = implode(',', $info['listIDS']);
update_post_meta($new_id,'_send_time', $info['send_at'] );
update_post_meta($new_id,'_send_lists', $lists );
update_post_meta($new_id,'_stat_type', 'new' );
$count = 0;
if(get_post_meta($saveid ,'istest',true) == true ){
update_post_meta($new_id,'_report_type', 'test' );
}
update_post_meta($new_id ,'_sendpress_subject', $subject );
if(isset($info['testemails']) && $info['testemails'] != false ){
foreach($info['testemails'] as $email){
$go = array(
'from_name' => 'Josh',
'from_email' => 'joshlyford@gmail.com',
'to_email' => $email['email'],
'emailID'=> $new_id,
'subscriberID'=> 0,
'subject' => $subject,
'listID' => 0
);
SPNL()->add_email_to_queue($go);
$count++;
}
}
update_post_meta($new_id,'_send_count', $count );
SendPress_Admin::redirect('Emails_Send_Queue',array('emailID'=> $new_id));
}
function save_email(){
$post_id = SPNL()->validate->_int('post_ID');
if($post_id > 0){
$html = SPNL()->validate->_html('content_area_one_edit');
$post_update = array(
'ID' => $post_id,
'post_content' => $html
);
update_post_meta( $post_id, '_sendpress_template', SPNL()->validate->_int('template') );
update_post_meta( $post_id, '_sendpress_subject', sanitize_text_field(SPNL()->validate->_string('post_subject' )) );
if( SPNL()->validate->_isset('header_content_edit')){
update_post_meta( $post_id, '_header_content', SPNL()->validate->_html('header_content_edit') );
}
if( SPNL()->validate->_isset('footer_content_edit')){
update_post_meta( $post_id, '_footer_content', SPNL()->validate->_html('footer_content_edit') );
}
remove_filter('content_save_pre', 'wp_filter_post_kses');
remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');
wp_update_post( $post_update );
add_filter('content_save_pre', 'wp_filter_post_kses');
add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
}
if( SPNL()->validate->_string('submit') == 'save-next'){
SendPress_Admin::redirect('Emails_List_Filter', array('emailID'=> SPNL()->validate->_int('post_ID') ) );
} else if (SPNL()->validate->_string('submit') == 'send-test'){
$email = new stdClass;
$email->emailID = SPNL()->validate->_int('post_ID');
$email->subscriberID = 0;
$email->listID = 0;
$email->to_email = SPNL()->validate->_email('test-email');
$d =SendPress_Manager::send_test_email( $email );
//print_r($d);
SendPress_Admin::redirect('Emails_Edit', array('emailID'=>SPNL()->validate->_int('emailID') ));
} else {
SendPress_Admin::redirect('Emails_Edit', array('emailID'=>SPNL()->validate->_int('emailID') ));
}
}
function create_subscriber(){
$email = SPNL()->validate->_email('email');
$fname = SPNL()->validate->_string('firstname');
$lname = SPNL()->validate->_string('lastname');
$phonenumber = SPNL()->validate->_string('phonenumber');
$salutation = SPNL()->validate->_string('salutation');
$listID = SPNL()->validate->_int('listID');
$status = SPNL()->validate->_string('status');
$subscriber_id = "";
if( is_email($email) ){
$result = SendPress_Data::add_subscriber( array('firstname'=> $fname ,'email'=> $email,'lastname'=>$lname, 'phonenumber'=>$phonenumber, 'salutation'=>$salutation) );
SendPress_Data::update_subscriber_status($listID, $result, $status ,false);
$subscriber_id = $result;
}
$state = SPNL()->validate->_string('state');
$city = SPNL()->validate->_string('city');
$genre = SPNL()->validate->_string('genre');
$category = SPNL()->validate->_string('category');
SendPress_Data::update_subscriber_meta($subscriber_id,'state',$state, $listID);
SendPress_Data::update_subscriber_meta($subscriber_id,'city',$city, $listID);
SendPress_Data::update_subscriber_meta($subscriber_id,'genre',$genre, $listID);
SendPress_Data::update_subscriber_meta($subscriber_id,'category',$category, $listID);
SendPress_Admin::redirect( 'Subscribers_Subscribers' , array( 'listID' => $listID ) );
}
function create_subscribers(){
//$this->security_check();
$csvadd = "email,firstname,lastname\n" . trim( SPNL()->validate->_string('csv-add') );
$listID = SPNL()->validate->_int('listID');
if($listID > 0 ){
$newsubscribers = SendPress_Data::subscriber_csv_post_to_array( $csvadd );
foreach( $newsubscribers as $subscriberx){
if( is_email( trim( $subscriberx['email'] ) ) ){
$result = SendPress_Data::add_subscriber( array('firstname'=> trim($subscriberx['firstname']) ,'email'=> trim($subscriberx['email']),'lastname'=> trim($subscriberx['lastname']) ) );
SendPress_Data::update_subscriber_status($listID, $result, 2, false);
}
}
}
SendPress_Admin::redirect( 'Subscribers_Subscribers' , array( 'listID' => $listID ) );
}
function addsubscriber(){
if (isset($_POST)) {
$values = array();
$values['email'] = $_POST['email'] ? $_POST['email']:"";
$values['firstname'] = $_POST['firstname'] ? $_POST['firstname']:"";
$values['lastname'] = $_POST['lastname'] ? $_POST['lastname']:"";
$values['phonenumber'] = $_POST['phonenumber'] ? $_POST['phonenumber']:"";
$user = SendPress_Data::add_subscriber($values);
$list_values = array();
$listID = $_POST['list'] ? $_POST['list']:"";
$list_values['listID'] = $listID;
$list_values['subscriberID'] = $user;
$list_values['status'] = 2;
$list_values['updated'] = date('Y-m-d H:i:s');
$table = SendPress_Data::list_subcribers_table();
global $wpdb;
$result = $wpdb->insert($table,$list_values);
if (!$result) {
$id = $wpdb->get_var( 'select * from wp_sendpress_list_subscribers where listID = '.$list_values['listID'].' and subscriberID = '.$list_values['subscriberID']);
$wpdb->update($table,$list_values, array('id' => $id));
}
$link = isset($_POST['link'])?$_POST['link']:"";
if (isset($link)) {
wp_redirect($link."?result=1");
}
}
}
function send_message(){
$result = wp_mail( get_option('admin_email'), "Créditos no blog ".get_bloginfo(), 'O blog ' . network_site_url( '/' ) . ' - ' . get_bloginfo() . " necessita de mais créditos.");
SendPress_Admin::redirect('Queue', array('result' => $result));
}
function save_import(){
$uploadfiles = $_FILES['uploadfiles'];
if (is_array($uploadfiles)) {
if ( $uploadfiles['error'] == 0 ) {
$filetmp = $uploadfiles['tmp_name'];
$filename = $uploadfiles['name'];
$filetype = wp_check_filetype( $filename, array('csv' => 'text/csv') );
$filetitle = preg_replace('/\.[^.]+$/', '', basename( $filename ) );
$filename = $filetitle . '.' . $filetype['ext'];
$upload_dir = wp_upload_dir();
if( $filetype['ext'] != 'csv' || $filetype['type'] != 'text/csv'){
SendPress_Admin::redirect('Subscribers_Csvimport',array('listID'=> SPNL()->validate->_int( 'listID' )));
}
// $i = 0;
// while ( file_exists( $upload_dir['path'] .'/' . $filename ) ) {
// $filename = $filetitle . '_' . $i . '.' . $filetype['ext'];
// var_dump($filename);
// $i++;
// }
$filedest = $upload_dir['path'] . '/' . $filename;
$filedest = str_replace('\\','/', $filedest);
if ( !is_writeable( $upload_dir['path'] ) ) {
SendPress_Option::set('import_error', true);
}
if ( !@move_uploaded_file($filetmp, $filedest) ){
SendPress_Option::set('import_error', true);
}
update_post_meta(SPNL()->validate->_int( 'listID' ),'csv_import',$filedest);
//if( SendPress_Option::get('import_error', false) == 1 ){
SendPress_Admin::redirect('Subscribers_Csvprep',array('listID'=> SPNL()->validate->_int( 'listID' )));
//}
}
}
}
function mce_buttons( $buttons ) {
array_unshift( $buttons, 'fontselect' );
array_unshift( $buttons, 'fontsizeselect' );
return $buttons;
}
function export_all_lists(){
$query = SendPress_Data::get_lists();
header("Content-type:text/octect-stream");
header("Content-Disposition:attachment;filename=sendpress.csv");
echo "email, firstname, lastname, status, phone, list \n";
while($query->have_posts()){
$query->the_post();
$item = get_post();
$subscribers = SendPress_Data::export_subscirbers($item->ID);
foreach($subscribers as $sb){
echo $sb->email . "," .
$sb->firstname . "," .
$sb->lastname . "," .
$sb->status . "," .
$sb->phonenumber . "," .
$item->post_title . "\n";
}
}
}
public function exportsenderrors()
{
header("Content-type:text/octect-stream");
header("Content-Disposition:attachment;filename=sendpress_errors.csv");
echo "Email,Tipo de Erro \n";
$errors = SPNL()->log->get_logs(0,'sending');
foreach ($errors as $error) {
$error_description = $error->post_title;
$email = strip_tags ( $error->post_content );
$error_email = explode ( " " , $email )[count($email)];
echo $error_email.",".$error_description."\n";
}
}
function export_report(){
$args = array(
'post_type' => 'sp_report' ,
'post_status' => array('publish','draft'),
'posts_per_page' => -1,
'fields' => 'ids',
'meta_query' => array(
array(
'key' => '_report_type',
'compare' => 'not exists',
),
),
);
$query = new WP_Query( $args );
if($query->have_posts()){
header("Content-type:text/octect-stream");
header("Content-Disposition:attachment;filename=sendpress.csv");
print "Titulo,Destinatarios,Enviados,Na Fila,Lista,Unique,Total,Inscritos via URL Unique,Inscritos via URL Total,Desinscritos,Data \n";
while($query->have_posts()){
$query->the_post();
$item = get_post();
$stat_type = get_post_meta($item->ID, '_stat_type', true);
$rec = get_post_meta($item->ID, '_send_count', true) + get_post_meta($item->ID, '_send_last_count', true) . '';
$sentold = get_post_meta($item->ID, '_sent_total', true);
$queue = 0;
$sent = get_post_meta($item->ID, '_send_total', true);
$inqueue = get_post_meta($item->ID, '_in_queue', true);
if($inqueue !== 'none'){
$queue = SendPress_Data::emails_in_queue($item->ID);
$sentindb = SendPress_Data::emails_sent_in_queue_for_report($item->ID);
if($sentindb > $sent){
update_post_meta($item->ID, '_send_total', $sentindb);
$sent = $sentindb;
}
if($queue == 0){
update_post_meta($item->ID, '_in_queue', 'none');
}
}
$display = '';
$info = get_post_meta($item->ID, '_send_data', true);
if(!empty($info['listIDS']) ){
foreach($info['listIDS'] as $list_id){
$list = get_post( $list_id );
if($list && $list->post_type == 'sendpress_list'){
$display .= $list->post_title.'<br>';
}
}
} else {
$lists = get_post_meta($item->ID,'_send_lists', true);
$list = explode(",",$lists );
foreach($list as $list_id){
$list = get_post( $list_id );
if($list && $list->post_type == 'sendpress_list'){
$display .= $list->post_title.'<br>';
}
}
}
$opens = SPNL()->load("Subscribers_Tracker")->get_opens( $item->ID );
$opens_total = SPNL()->load("Subscribers_Tracker")->get_opens_total( $item->ID );
$opens = $opens == 0 ? '-' : $opens;
$opens_total = $opens_total == 0 ? '-' : $opens_total;
$clicks = SPNL()->load("Subscribers_Url")->clicks_email_id( $item->ID );
$clicks_total = SPNL()->load("Subscribers_Url")->clicks_total_email_id( $item->ID );
$clicks = $clicks == 0 ? '-' : $clicks;
$clicks_total = $clicks_total == 0 ? '-' : $clicks_total;
$unsubscribers = SPNL()->load("Subscribers_Tracker")->get_unsubs( $item->ID );
$unsubscribert = $unsubscribers == 0 ? '-' : $clicks;
$date = get_post_meta($item->ID, "send_date", true);
$date_final = !empty( $date )? date_i18n(get_option('date_format') ,strtotime($date) ) : 'sem data';
print get_the_title() . "," .$rec .",". $sent .",". $queue ."," . strip_tags($display) . "," . $opens .",". $opens_total . "," . $clicks . "," . $clicks_total . "," . $clicks . "," . $date_final."\n";
}
}
}
function frame_it_up( $init_array ){
global $allowedtags, $allowedposttags;
$allowedposttags['iframe'] = $allowedtags['iframe'] = array(
'name' => true,
'id' => true,
'class' => true,
'style' => true,
'src' => true,
'width' => true,
'height' => true,
'allowtransparency' => true,
'frameborder' => true,
);
}
function jaiminho_notices() {
$registered = strtotime(get_blog_details()->registered);
$now = new DateTime();
$now = strtotime($now->format('Y-m-d H:i:s'));
$secs = $now - $registered;
$days = $secs / 86400;
if (!get_option('emails-credits') && $days > 100 && SendPress_Option::get( 'sendmethod' ) === 'Jaiminho_Sender_NetWork' )
{
echo '<div class="notice notice-info is-dismissible"><p>';
echo "<strong>";
_e( 'Olá!', 'sendpress' );
echo "</strong> ";
printf( __( ' Seus créditos acabaram, entre em contato para pedir mais créditos', 'jaiminho' ));
echo '</p></div>';
}
if (get_option('emails-credits') == "5000" && $days <10 )
{
echo '<div class="notice notice-success is-dismissible"><p>';
echo "<strong>";
_e( 'Olá!', 'sendpress' );
echo "</strong> ";
printf( __( ' Bem vindo a plataforma, nós colocamos 5000 créditos, ou seja você pode enviar 5k emails a partir de agora, se precisar de mais entre em contato com a gente', 'jaiminho' ));
echo '</p></div>';
}
}
function jaiminho_set_settings_for_new_site($blog_id){
switch_to_blog( $blog_id );
activate_plugin('sendpress/sendpress.php');
//activate_plugin('jaiminho/jaiminho.php');
SendPress_Option::set( 'wpcron-per-call' , 5000 );
SendPress_Option::set( 'emails-per-day' , 5000);
SendPress_Option::set( 'emails-per-hour' , 2500 );
switch_to_blog( 1 );
$args = array (
'networkuser' => get_option('networkuser'),
'networkpass' => get_option('networkpass'),
'networkserver' => get_option('networkserver'),
'networkport' => get_option('networkport'),
'bounce_email' => get_option('bounce_email'),
'sendmethod' => 'Jaiminho_Sender_NetWork',
);
switch_to_blog( $blog_id );
foreach( $args as $key => $value )
{
$method = SendPress_Option::set($key,$value);
}
$jaiminho = new Jaiminho();
$jaiminho->jaiminho_define_opt_in_email();
$jaiminho->create_templates();
restore_current_blog();
}
public static function jaiminho_define_opt_in_email(){
$optin = SendPress_Data::get_template_id_by_slug('double-optin');
$my_post = array(
'ID' => $optin,
'post_title' => "Por favor responda para entrar na lista de emails da *|SITE:TITLE|*",
'post_content' => "Olá!
Falta pouco para podermos enviar para você e-mail do site *|SITE:TITLE|*, mas antes disto precisamos que você confirme que você realmente quer receber nossas informações.
Se você quer receber informações do *|SITE:TITLE|* no seu e-mail, você só precisa clicar no linque abaixo. Muito obrigado!
———————————————————————————————————
CONFIRME UTILIZANDO O LINQUE ABAIXO:
*|SP:CONFIRMLINK|*
Clique no linque acima para nos dar permissão de te enviar
informações. É rápido e fácil! Se você não conseguir clicar,
copie e cole o linque o seu navegador.
———————————————————————————————————
Se você não quiser receber e-mails, simplesmente ignore esta mensagem."
);
wp_update_post($my_post);
}
public function jaiminho_register_required_plugins(){
$plugins = array(
array(
'name' => 'sendpress',
'slug' => 'sendpress',
'required' => true
),
);
$config = array(
'id' => 'jaiminho', // Unique ID for hashing notices for multiple instances of TGMPA.
'default_path' => '', // Default absolute path to bundled plugins.
'menu' => 'tgmpa-install-plugins', // Menu slug.
'parent_slug' => 'plugins.php', // Parent menu slug.
'capability' => 'manage_options', // Capability needed to view plugin install page, should be a capability associated with the parent menu used.
'has_notices' => false, // Show admin notices or not.
'dismissable' => true, // If false, a user cannot dismiss the nag message.
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
'is_automatic' => false, // Automatically activate plugins after installation or not.
'message' => '', // Message to output right before the plugins table.
);
tgmpa( $plugins, $config );
}
public function jaiminho_check_rewrite(){
global $wp_rewrite;
$rules = $wp_rewrite->extra_rules_top;
$found = false;
if(is_array($rules))
{
foreach ($rules as $rule)
{
if(strpos($rule, 'sendpress') !== false)
{
$found = true;
break;
}
}
if ( ! $found )
{
$wp_rewrite->flush_rules();
}
}
}
public function jaiminho_network_settings(){
$basename = 'jaiminho-network-settings';
add_menu_page( __('Jaiminho','jaiminho'), __('Jaiminho','jaiminho'), 'manage_network_options', $basename, array( $this , 'jaiminho_settings_network_html' ), JAIMINHO_URL . 'img/jaiminho-bg-16.png' );
add_submenu_page(
$basename,
__('Configurar Contas','jaiminho'),
__('Configurar Contas','jaiminho'),
'manage_network_options',
$basename,
array( $this , 'jaiminho_settings_network_html' )
);
add_submenu_page(
$basename,
__('Configurar Créditos','jaiminho'),
__('Configurar Créditos','jaiminho'),
'manage_network_options',
'jaiminho-network-credits-settings',
array( $this , 'jaiminho_settings_network_html_credits' )
);
add_submenu_page(
$basename,
__('Configurar Limite de Envio','jaiminho'),
__('Configurar Limite de Envio','jaiminho'),
'manage_network_options',
'jaiminho-emails-limits-settings',
array( $this , 'jaiminho_emails_limits_html' )
);
add_submenu_page(
$basename,
__('Corrigir tabelas','jaiminho'),
__('Corrigir tabelas','jaiminho'),
'manage_network_options',
'jaiminho-fix-tables--settings',
array( $this , 'jaiminho_fix_tables_html' )
);
}
public function jaiminho_fix_tables_html(){
global $wpdb;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
$collate = '';
if ( $wpdb->has_cap( 'collation' ) ) {
if( ! empty($wpdb->charset ) ){
$collate .= "DEFAULT CHARACTER SET $wpdb->charset";
}
if( ! empty($wpdb->collate ) ){
$collate .= " COLLATE $wpdb->collate";
}
}
?>
<form method="post">
<input type="hidden" name="fix_tables" value="true" />
<?php submit_button(__( 'Corrigir Tabelas' , 'jaiminho' )); ?>
</form>
<?php
$args = array(
'network_id' => null,
'public' => null,
'archived' => null,
'mature' => null,
'spam' => null,
'deleted' => null,
'limit' => null,
'offset' => 0,
);
//TODO: this function is deprecated for wp 4.6.0
$blogs = wp_get_sites( $args );
// debug info
// echo '<pre>';
// var_dump($blogs);
// echo '</pre>';
foreach( $blogs as $blog ){
switch_to_blog( $blog['blog_id'] );
echo '<br>';
echo get_bloginfo( 'name' );
echo '<br>';
echo "<b>Database Tables</b>: <br>";
// primera tabela
$subscriber_events_table = new SendPress_DB_Subscribers_Tracker();
$subscriber_events_table = $subscriber_events_table->table_name;
if($wpdb->get_var("show tables like '$subscriber_events_table'") != $subscriber_events_table) {
echo $subscriber_events_table . " Not Installed<br>";
if(isset($_POST['fix_tables'])){
$command = " CREATE TABLE $subscriber_events_table (
subscriberID int(11) unsigned NOT NULL,
emailID int(11) unsigned NOT NULL,
sent_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
opened_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
status tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (subscriberID,emailID)
) $collate;\n";
$return = dbDelta($command);
echo $return["wp_sendpress_report_url"];
}
}
else {
echo $subscriber_events_table . " OK<br>";
}
// XXX Terminar indentação do jaiminho
// segunda tabela
$subscriber_events_table = new SendPress_DB_Subscribers_Url();
$subscriber_events_table = $subscriber_events_table->table_name;
if($wpdb->get_var("show tables like '$subscriber_events_table'") != $subscriber_events_table) {
echo $subscriber_events_table . " Not Installed<br>";
if(isset($_POST['fix_tables']))
{
$command = " CREATE TABLE $subscriber_events_table (
subscriberID int(11) unsigned NOT NULL,
emailID int(11) unsigned NOT NULL,
urlID int(11) unsigned NOT NULL,
clicked_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
click_count int(11) unsigned NOT NULL,
PRIMARY KEY ( subscriberID , emailID , urlID )
) $collate;\n";
$return = dbDelta($command);
echo $return["wp_sendpress_report_url"];
}
} else {
echo $subscriber_events_table . " OK<br>";
}
//terceira tabela
$subscriber_events_table = new SendPress_DB_Url();
$subscriber_events_table = $subscriber_events_table->table_name;
if($wpdb->get_var("show tables like '$subscriber_events_table'") != $subscriber_events_table) {
echo $subscriber_events_table . " Not Installed<br>";
if(isset($_POST['fix_tables']))
{
$command = " CREATE TABLE $subscriber_events_table (urlID int(11) unsigned NOT NULL AUTO_INCREMENT, url text,hash varchar(255) DEFAULT NULL, PRIMARY KEY (urlID), KEY hash (hash)) $collate;\n";
$return = dbDelta($command);
echo $return["wp_sendpress_report_url"];
}
} else {
echo $subscriber_events_table . " OK<br>";
}
// quarta tabela
$report_url_table = SendPress_DB_Tables::report_url_table();
if($wpdb->get_var("show tables like '$report_url_table'") != $report_url_table) {
echo $report_url_table . " Not Installed<br>";