-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
1396 lines (1127 loc) · 47.7 KB
/
plugin.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: Frontpage
Plugin URI: http://mecus.es
Description: Frontpage is a cool plugin to view your own front page before to publish it. <strong>Before update give a look to <a href="http://mecus.es">this page</a> to know what's changed.</strong> Based on Satollo newsletter.
Version: 1.0
Author: _DorsVenabili
Author URI: http://mecus.es
*/
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
define('frontpage', '1.0');
$frontpage_options_main = get_option('frontpage_main', array());
// Labels loading, after that $frontpage_labels is filled
$frontpage_labels = null;
@include_once(dirname(__FILE__) . '/languages/es_ES.php');
if (WPLANG != '') @include_once(dirname(__FILE__) . '/languages/' . WPLANG . '.php');
//@include_once(ABSPATH . 'wp-content/plugins/frontpage-custom/languages/es_ES.php');
//if (WPLANG != '') @include_once(ABSPATH . 'wp-content/plugins/frontpage-custom/languages/' . WPLANG . '.php');
// Don't try to hack that, frontpage will badly fail
//@include(ABSPATH . 'wp-content/plugins/frontpage-extras/frontpage-extras.php');
$frontpage_step = 'subscription';
$frontpage_subscriber;
function frontpage_init_labels() {
}
function frontpage_label($name, $default='') {
global $frontpage_labels;
if (isset($frontpage_labels[$name]))
return $frontpage_labels[$name];
return $default;
}
function frontpage_echo($name, $default) {
echo frontpage_label($name, $default);
}
function frontpage_request($name, $default=null ) {
if (!isset($_REQUEST[$name])) return $default;
return stripslashes_deep($_REQUEST[$name]);
}
function frontpage_subscribers_count() {
global $wpdb;
return $wpdb->get_var("select count(*) from " . $wpdb->prefix . "frontpage where status='C'");
}
//Shows two selects boxes to choose year and month
function frontpage_get_year_and_month() {
global $wpdb, $m, $monthnum, $year, $wp_locale;
$options_search = get_option('frontpage_search');
if ( isset($_GET['w']) )
$w = ''.intval($_GET['w']);
// Let's figure out when we are
if ( !empty($monthnum) && !empty($year) ) {
$thismonth = ''.zeroise(intval($monthnum), 2);
$thisyear = ''.intval($year);
} elseif ( !empty($w) ) {
// We need to get the month from MySQL
$thisyear = ''.intval(substr($m, 0, 4));
$d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
$thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
} elseif ( !empty($m) ) {
$thisyear = ''.intval(substr($m, 0, 4));
if ( strlen($m) < 6 )
$thismonth = '01';
else
$thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
} else {
$thisyear = gmdate('Y', current_time('timestamp'));
$thismonth = gmdate('m', current_time('timestamp'));
}
$unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
$anyo = $thisyear;
$mes = 1;
?>
<select id="options[frontpage_year]" name="options[frontpage_year]">
<option <?php if ($_POST['a'] != 'search' && check_admin_referer()) echo 'selected'; ?> value=""><?php echo __('Select a year','frontpage'); ?></option>
<?php while($anyo >= 2007): ?>
<option <?php if ($_POST['a'] == 'search' && check_admin_referer() && $anyo == $options_search['frontpage_year']){
echo 'selected';
}
else{
echo '';
}; ?> value="<?php echo $anyo; ?>" onclick="frontpage_select_year(<?php echo $anyo; ?>)"><?php echo $anyo; ?></option>
<?php $anyo--;
endwhile; ?>
</select>
<select id="options[frontpage_month]" name="options[frontpage_month]" <?php if ($_POST['a'] != 'search' && check_admin_referer()) echo 'disabled="disabled"'; ?>>
<option <?php if ($_POST['a'] != 'search' && check_admin_referer()) echo 'selected'; ?> value=""><?php echo __('Select a month','frontpage'); ?></option>
<?php while($mes <= 12):
$month_name = month_name($mes); ?>
<option <?php if ($_POST['a'] == 'search' && check_admin_referer() && $mes == $options_search['frontpage_month']){
echo 'selected';
}
else{
echo '';
}; ?> value="<?php echo $mes; ?>" onclick="frontpage_select_month(<?php echo $mes; ?>)"><?php echo $month_name; ?></option>
<?php $mes++;
endwhile; ?>
</select>
<?php
}
//Shows a select box with the frontpages for the selected year and month
function frontpage_get_frontpages_for_date(){
global $wpdb;
$options_search = get_option('frontpage_search');
$y = $options_search['frontpage_year'];
$m = $options_search['frontpage_month'];
$frontpages = $wpdb->get_results("SELECT * FROM wp_frontpage WHERE YEAR(fecha) = '$y' AND MONTH(fecha) = '$m' ORDER BY fecha DESC");
$id_last_frontpage = 0;
?>
<select id="options[id_frontpage]" name="options[id_frontpage]" style="width:200px;" <?php if ($_POST['a'] != 'search' && check_admin_referer()) echo 'disabled="disabled"';?>>
<option <?php if ($_POST['a'] == 'search' && check_admin_referer()) echo 'selected';; ?> value=""><?php echo __('Select a day','frontpage'); ?></option>
<?php foreach($frontpages as $frontpage):
$id_frontpage = $frontpage->idPortada;
if($id_last_frontpage != $id_frontpage): ?>
<option <?php if ($_POST['f'] == 'id_frontpage' && check_admin_referer() && $id_frontpage == $options_search['id_frontpage']) echo 'selected'; ?> value="<?php echo $id_frontpage; ?>" onclick="frontpage_select_id(<?php echo $id_frontpage; ?>)"><?php echo $frontpage->fecha; ?></option>
<?php endif;
$id_last_frontpage = $id_frontpage;
endforeach; ?>
</select>
<?php
}
function month_name($en_month){
switch($en_month){
case 1:
$es_month = __('January','frontpage');
break;
case 2:
$es_month = __('February','frontpage');
break;
case 3:
$es_month = __('March','frontpage');
break;
case 4:
$es_month = __('April','frontpage');
break;
case 5:
$es_month = __('May','frontpage');
break;
case 6:
$es_month = __('June','frontpage');
break;
case 7:
$es_month = __('July','frontpage');
break;
case 8:
$es_month = __('August','frontpage');
break;
case 9:
$es_month = __('September','frontpage');
break;
case 10:
$es_month = __('October','frontpage');
break;
case 11:
$es_month = __('November','frontpage');
break;
case 12:
$es_month = __('December','frontpage');
break;
}
return $es_month;
}
/* Modificaci—n Mecus
function frontpage_embed_form($form=0) {
$options = get_option('frontpage');
if (frontpage_has_extras('1.0.2') && $form>0) {
echo str_replace('{frontpage_url}', $options['url'], frontpage_extras_get_form($form));
}
else {
echo '<div class="frontpage-embed-form">';
if (isset($options['noname'])) {
echo str_replace('{frontpage_url}', $options['url'], frontpage_label('embedded_form_noname'));
}
else {
echo str_replace('{frontpage_url}', $options['url'], frontpage_label('embedded_form'));
}
echo '</div>';
}
}*/
/* Modificaci—n Mecus
if (!is_admin()) {
add_shortcode('frontpage', 'frontpage_call');
add_shortcode('frontpage_form', 'frontpage_form_call');
}
function frontpage_form_call($attrs, $content=null) {
$options = get_option('frontpage');
if (frontpage_has_extras('1.0.2') && isset($attrs['form'])) {
$buffer = str_replace('{frontpage_url}', $options['url'], frontpage_extras_get_form($attrs['form']));
}
else {
$buffer = '<div class="frontpage-embed-form">';
if (!isset($options['noname'])) {
$buffer .= str_replace('{frontpage_url}', $options['url'], frontpage_label('embedded_form'));
}
else {
$buffer .= str_replace('{frontpage_url}', $options['url'], frontpage_label('embedded_form_noname'));
}
$buffer .= '</div>';
}
return $buffer;
}
/* Modificaci—n Mecus
function frontpage_call($attrs, $content=null) {
global $frontpage_step, $frontpage_subscriber;
$options = get_option('frontpage');
$buffer = '';
// When a user is starting the subscription process
if ($frontpage_step == 'subscription') {
$buffer .= $options['subscription_text'];
if (frontpage_has_extras('1.0.2') && isset($attrs['form'])) {
$buffer .= str_replace('{frontpage_url}', $options['url'], frontpage_extras_get_form($attrs['form']));
}
else {
if (isset($options['noname'])) {
$buffer .= frontpage_label('subscription_form_noname');
}
else {
$buffer .= frontpage_label('subscription_form');
}
//if (!defined('frontpage_EXTRAS'))
// $buffer .= '<div style="text-align:right;padding:0 10px;margin:0;"><a style="font-size:9px;color:#bbb;text-decoration:none" href="http://mecus.es">by satollo.net</a></div>';
}
}
// When a user asked to subscribe and the connfirmation request has been sent
if ($frontpage_step == 'subscribed') {
$text = frontpage_replace($options['subscribed_text'], $frontpage_subscriber);
$buffer .= $text;
}
if ($frontpage_step == 'confirmed') {
$text = frontpage_replace($options['confirmed_text'], $frontpage_subscriber);
$buffer .= $text;
if (isset($options['confirmed_tracking'])) {
ob_start();
eval('?>' . $options['confirmed_tracking']);
$buffer .= ob_get_clean();
}
}
// Here we are when an unsubscription is requested. There are two kind of unsubscription: the
// ones with email and token, so the user has only to confire and the ones without
// data, so the user is requested to insert his email. In the latter case an email
// will be sent to the user with alink to confirm the email removal.
if ($frontpage_step == 'unsubscription' || $frontpage_step == 'unsubscription_error') {
$frontpage_subscriber = frontpage_get_subscriber($_REQUEST['ni']);
$buffer = frontpage_replace($options['unsubscription_text'], $frontpage_subscriber);
$url = frontpage_add_qs($options['url'], 'na=uc&ni=' . $frontpage_subscriber->id .
'&nt=' . $_REQUEST['nt']);
$buffer = frontpage_replace_url($buffer, 'UNSUBSCRIPTION_CONFIRM_URL', $url);
}
// Last message shown to user to say good bye
if ($frontpage_step == 'unsubscribed') {
$text = $options['unsubscribed_text'];
$text = frontpage_replace($text, $frontpage_subscriber);
$buffer .= $text;
}
return '<div class="frontpage">' . $buffer . '</div>';
}
/* Modificaci—n Mecus
function frontpage_phpmailer_init($phpmailer) {
$options_email = get_option('frontpage_view');
$phpmailer->Sender = $options_email['return_path'];
}
/**
* Sends out frontpages.
*
* I recipients is an array of subscribers, other parameters are ignored and a test
* batch is started. This parameter has priority over all.
*
* If continue is true, the system try to continue a previous batch keeping its
* configuration (eg. if it was a simulation or not).
*
* If continue is false, simulate indicates if the batch is a simulation and forces
* the subscriber's email to a test one, as specified in the configuration.
*
* Return true if the batch is completed.
*//* Modificaci—n Mecus
function frontpage_send_batch() {
global $wpdb;
frontpage_info(__FUNCTION__, 'Start');
$options = get_option('frontpage');
$options_email = get_option('frontpage_view');
$batch = get_option('frontpage_batch');
if ($batch == null || !is_array($batch)) {
frontpage_error(__FUNCTION__, 'No batch found');
return;
}
frontpage_debug(__FUNCTION__, "Batch:\n" . print_r($last, true));
// Batch have to contain 'id' which is the starting id, 'simulate' boolean
// to indicate if is a simulation or not, 'scheduled' if it's a scheduled
// sending process. 'list' is the list number, required.
// If 'id' = 0 it's a new seding process.
if (!isset($batch['id'])) {
frontpage_error(__FUNCTION__, 'Batch "id" parameter not present');
return false;
}
if (!isset($batch['list'])) {
frontpage_error(__FUNCTION__, 'Batch "list" parameter not present');
return false;
}
if (!isset($batch['simulate'])) {
frontpage_error(__FUNCTION__, 'Batch "simulate" parameter not present');
return false;
}
if (!isset($batch['scheduled'])) {
frontpage_error(__FUNCTION__, 'Batch "scheduled" parameter not present');
return false;
}
$id = (int)$batch['id'];
$list = (int)$batch['list'];
$simulate = (bool)$batch['simulate'];
$scheduled = (bool)$batch['scheduled']; // Used to avoid echo
if ($scheduled) {
$max = $options_email['scheduler_max'];
if (!is_numeric($max)) $max = 10;
}
else {
$max = $options_email['max'];
if (!is_numeric($max)) $max = 0;
}
$query = "select * from " . $wpdb->prefix . "frontpage where status='C' and list=" . $list .
" and id>" . $id . " order by id";
if ($max > 0) {
$query .= " limit " . $max;
}
$recipients = $wpdb->get_results($query);
// For a new batch save some info
if ($id == 0) {
frontpage_delete_batch_file();
wp_clear_scheduled_hook('frontpage_cron_hook');
$batch['total'] = $wpdb->get_var("select count(*) from " . $wpdb->prefix . "frontpage where status='C' and list=" . $list);
$batch['sent'] = 0;
$batch['completed'] = false;
$batch['message'] = '';
}
// Not all hosting provider allow this...
@set_time_limit(100000);
$start_time = time();
$max_time = (int)(ini_get('max_execution_time') * 0.8);
$db_time = time();
if (!$scheduled) {
echo 'Sending to: <br />';
}
if (isset($options_email['novisual'])) {
$message = $options_email['message'];
}
else {
$message = '<html><head><style type="text/css">' . frontpage_get_theme_css($options_email['theme']) .
'</style></head><body>' . $options_email['message'] . '</body></html>';
}
$idx = 0;
add_action('phpmailer_init','frontpage_phpmailer_init');
if (frontpage_has_extras('1.0.4')) frontpage_init_mail();
foreach ($recipients as $r) {
$url = frontpage_add_qs($options['url'],
'na=u&ni=' . $r->id . '&nt=' . $r->token);
$m = frontpage_replace_url($message, 'UNSUBSCRIPTION_URL', $url);
$m = frontpage_replace($m, $r);
if (defined('frontpage_EXTRAS') && isset($options_email['track']))
$m = frontpage_relink($m, $r->id, $options_email['name']);
$s = $options_email['subject'];
$s = frontpage_replace($s, $r);
if ($simulate) {
$x = frontpage_mail($options_email['simulate_email'], $s, $m, true);
}
else {
$x = frontpage_mail($r->email, $s, $m, true);
}
if (!$scheduled) {
echo htmlspecialchars($r->name) . ' (' . $r->email . ') ';
if ($x) {
echo '[OK] - ';
frontpage_debug(__FUNCTION__, 'Sent to ' . $r->id . ' success');
} else {
echo '[KO] - ';
frontpage_debug(__FUNCTION__, 'Sent to ' . $r->id . ' failed');
}
flush();
}
$idx++;
$batch['sent']++;
$batch['id'] = $r->id;
// Try to avoid database timeout
if (time()-$db_time > 15) {
//frontpage_debug(__FUNCTION__, 'Batch saving to avoid database timeout');
$db_time = time();
$batch['message'] = 'Temporary saved batch to avoid database timeout';
if (!update_option('frontpage_batch', $batch)) {
frontpage_error(__FUNCTION__, 'Unable to save to database, saving on file system');
frontpage_error(__FUNCTION__, "Batch:\n" . print_r($batch, true));
frontpage_save_batch_file($batch);
remove_action('phpmailer_init','frontpage_phpmailer_init');
if (frontpage_has_extras('1.0.4')) frontpage_close_mail();
return false;
}
}
// Check for the max emails per batch
if ($max != 0 && $idx >= $max) {
frontpage_info(__FUNCTION__, 'Batch saving due to max emails limit reached');
$batch['message'] = 'Batch max emails limit reached (it is ok)';
if (!update_option('frontpage_batch', $batch)) {
frontpage_error(__FUNCTION__, 'Unable to save to database, saving on file system');
frontpage_error(__FUNCTION__, "Batch:\n" . print_r($batch, true));
frontpage_save_batch_file($batch);
remove_action('phpmailer_init','frontpage_phpmailer_init');
if (frontpage_has_extras('1.0.4')) frontpage_close_mail();
return false;
}
remove_action('phpmailer_init','frontpage_phpmailer_init');
if (frontpage_has_extras('1.0.4')) frontpage_close_mail();
return true;
}
// Timeout check, max time is zero if set_time_limit works
if (($max_time != 0 && (time()-$start_time) > $max_time)) {
frontpage_info(__FUNCTION__, 'Batch saving due to max time limit reached');
$batch['message'] = 'Batch max time limit reached (it is ok)';
if (!update_option('frontpage_batch', $batch)) {
frontpage_error(__FUNCTION__, 'Unable to save to database, saving on file system');
frontpage_error(__FUNCTION__, "Batch:\n" . print_r($last, true));
frontpage_save_batch_file($batch);
remove_action('phpmailer_init','frontpage_phpmailer_init');
if (frontpage_has_extras('1.0.4')) frontpage_close_mail();
return false;
}
remove_action('phpmailer_init','frontpage_phpmailer_init');
if (frontpage_has_extras('1.0.4')) frontpage_close_mail();
return true;
}
}
// All right (incredible!)
frontpage_info(__FUNCTION__, 'Sending completed!');
$batch['completed'] = true;
$batch['message'] = '';
if (!update_option('frontpage_batch', $batch)) {
frontpage_error(__FUNCTION__, 'Unable to save to database, saving on file system');
frontpage_error(__FUNCTION__, "Batch:\n" . print_r($last, true));
frontpage_save_batch_file($batch);
remove_action('phpmailer_init','frontpage_phpmailer_init');
if (frontpage_has_extras('1.0.4')) frontpage_close_mail();
return false;
}
remove_action('phpmailer_init','frontpage_phpmailer_init');
if (frontpage_has_extras('1.0.4')) frontpage_close_mail();
return true;
}
/**
* Send a set of test emails to a list of recipents. The recipients are created
* in the composer page using the test addresses.
*//* Modificaci—n Mecus
function frontpage_send_test($recipients) {
global $wpdb;
//frontpage_info(__FUNCTION__, 'Start');
$options = get_option('frontpage');
$options_email = get_option('frontpage_view');
@set_time_limit(100000);
echo 'Sending to: <br />';
if (isset($options_email['novisual'])) {
$message = $options_email['message'];
}
else {
$message = '<html><head><style type="text/css">' . frontpage_get_theme_css($options_email['theme']) .
'</style></head><body>' . $options_email['message'] . '</body></html>';
}
//if (frontpage_has_extras('1.0.4')) frontpage_init_mail();
foreach ($recipients as $r) {
$url = frontpage_add_qs($options['url'],
'na=u&ni=' . $r->id . '&nt=' . $r->token);
$m = frontpage_replace_url($message, 'UNSUBSCRIPTION_URL', $url);
$m = frontpage_replace($m, $r);
if (defined('frontpage_EXTRAS') && isset($options_email['track']))
$m = frontpage_relink($m, $r->id, $options_email['name']);
$s = $options_email['subject'];
$s = frontpage_replace($s, $r);
$x = frontpage_mail($r->email, $s, $m, true);
echo htmlspecialchars($r->name) . ' (' . $r->email . ') ';
flush();
if ($x) {
echo '[OK] -- ';
frontpage_debug(__FUNCTION__, 'Sent to ' . $r->id . ' success');
} else {
echo '[KO] -- ';
frontpage_debug(__FUNCTION__, 'Sent to ' . $r->id . ' failed');
}
}
//if (frontpage_has_extras('1.0.4')) frontpage_close_mail();
}*/
/*
function frontpage_add_qs($url, $qs, $amp=true) {
if (strpos($url, '?') !== false) {
if ($amp) return $url . '&' . $qs;
else return $url . '&' . $qs;
}
else return $url . '?' . $qs;
}*/
/**
* Add a request of frontpage subscription into the database with status "S" (waiting
* confirmation) and sends out the confirmation request email to the subscriber.
* The email will contain an URL (or link) the user has to follow to complete the
* subscription (double opt-in).
*//* Modificaci—n Mecus
function frontpage_subscribe($email, $name='', $profile=null) {
global $wpdb, $frontpage_subscriber;
$options = get_option('frontpage');
$email = frontpage_normalize_email($email);
$name = frontpage_normalize_name($name);
$list = 0;
if ($profile == null) $profile = array();
// Check if this email is already in our database: if so, just resend the
// confirmation email.
$frontpage_subscriber = frontpage_get_subscriber_by_email($email, $list);
if (!$frontpage_subscriber) {
$token = md5(rand());
if (isset($options['noconfirmation'])) {
$status = 'C';
}
else {
$status = 'S';
}
@$wpdb->insert($wpdb->prefix . 'frontpage', array(
'email'=>$email,
'name'=>$name,
'token'=>$token,
'list'=>$list,
'status'=>$status
//'profile'=>serialize($profile)
));
$id = $wpdb->insert_id;
$frontpage_subscriber = frontpage_get_subscriber($id);
// Profile saving
foreach ($profile as $key=>$value) {
@$wpdb->insert($wpdb->prefix . 'frontpage_profiles', array(
'frontpage_id'=>$id,
'name'=>$key,
'value'=>$value));
}
}
if (isset($options['noconfirmation'])) {
frontpage_send_welcome($frontpage_subscriber);
}
else {
frontpage_send_confirmation($frontpage_subscriber);
}
$message = 'There is a new subscriber to ' . get_option('blogname') . ' frontpage:' . "\n\n" .
$name . ' <' . $email . '>' . "\n\n" .
'Have a nice day,' . "\n" . 'your frontpage plugin.';
$subject = '[' . get_option('blogname') . '] New subscription';
frontpage_notify_admin($subject, $message);
}
/* Modificaci—n Mecus
function frontpage_frontpage_save($subscriber) {
global $wpdb;
$email = frontpage_normalize_email($email);
$name = frontpage_normalize_name($name);
$wpdb->query($wpdb->prepare("update " . $wpdb->prefix . "frontpage set email=%s, name=%s where id=%d",
$subscriber['email'], $subscriber['name'], $subscriber['id']));
}
/**
* Resends the confirmation message when asked by user manager panel.
*//* Modificaci—n Mecus
function frontpage_send_confirmation($subscriber) {
$options = get_option('frontpage');
frontpage_debug(__FUNCTION__, "Confirmation request to:\n" . print_r($subscriber, true));
$message = $options['confirmation_message'];
$html = frontpage_get_theme_html($options['theme']);
if ($html == null) $html = '{message}';
$message = str_replace('{message}', $message, $html);
// The full URL to the confirmation page
$url = frontpage_add_qs($options['url'], 'na=c&ni=' . $subscriber->id .
'&nt=' . $subscriber->token);
$message = frontpage_replace_url($message, 'SUBSCRIPTION_CONFIRM_URL', $url);
// URL to the unsubscription page (for test purpose)
$url = frontpage_add_qs($options['url'], 'na=u&ni=' . $subscriber->id .
'&nt=' . $subscriber->token);
$message = frontpage_replace_url($message, 'UNSUBSCRIPTION_URL', $url);
$message = frontpage_replace($message, $subscriber);
$subject = frontpage_replace($options['confirmation_subject'], $subscriber);
if (frontpage_has_extras('1.0.4')) frontpage_init_mail();
frontpage_mail($subscriber->email, $subject, $message);
if (frontpage_has_extras('1.0.4')) frontpage_close_mail();
}
/**
* Return a subscriber by his email. The email will be sanitized and normalized
* before issuing the query to the database.
*//* Modificaci—n Mecus
function frontpage_get_subscriber($id) {
global $wpdb;
$recipients = $wpdb->get_results($wpdb->prepare("select * from " . $wpdb->prefix .
"frontpage where id=%d", $id));
if (!$recipients) return null;
return $recipients[0];
}
function frontpage_get_subscriber_by_email($email, $list=0) {
global $wpdb;
$recipients = $wpdb->get_results($wpdb->prepare("select * from " . $wpdb->prefix .
"frontpage where email=%s and list=%d", $email, $list));
if (!$recipients) return null;
return $recipients[0];
}*/
/*
function frontpage_get_all() {
global $wpdb;
$recipients = $wpdb->get_results("select * from " . $wpdb->prefix . "frontpage order by email");
return $recipients;
}*/
/*
function frontpage_search($text, $status=null, $order='email') {
global $wpdb;
if ($order == 'id') $order = 'id desc';
$query = "select * from " . $wpdb->prefix . "frontpage where 1=1";
if ($status != null) {
$query .= " and status='" . $wpdb->escape($status) . "'";
}
if ($text == '') {
$recipients = $wpdb->get_results($query . " order by " . $order . ' limit 100');
}
else {
$recipients = $wpdb->get_results($query . " and email like '%" .
$wpdb->escape($text) . "%' or name like '%" . $wpdb->escape($text) . "%' order by " . $order . ' limit 100');
}
if (!$recipients) return null;
return $recipients;
}*/
/* Modificaci—n Mecus
function frontpage_get_unconfirmed() {
global $wpdb;
$recipients = $wpdb->get_results("select * from " . $wpdb->prefix . "frontpage where status='S' order by email");
return $recipients;
}
/**
* Normalize an email address,making it lowercase and trimming spaces.
*//* Modificaci—n Mecus
function frontpage_normalize_email($email) {
return strtolower(trim($email));
}
function frontpage_normalize_name($name) {
$name = str_replace(';', ' ', $name);
$name = strip_tags($name);
return $name;
}
add_action('init', 'frontpage_init');
/**
* Intercept the request parameters which drive the subscription and unsubscription
* process.
*/
/*
function frontpage_init() {
global $frontpage_step, $wpdb, $frontpage_subscriber;
global $hyper_cache_stop;
// "na" always is the action to be performed - stands for "frontpage action"
$action = $_REQUEST['na'];
if (!$action) return;
$hyper_cache_stop = true;
//if (defined('frontpage_EXTRAS')) frontpage_extra_init($action);
$options = get_option('frontpage');
/* Modificaci—n Mecus
// Subscription request from a subscription form (in page), can be
// a direct subscription with no confirmation
if ($action == 's') {
if (!frontpage_is_email($_REQUEST['ne'])) {
die(frontpage_label('error_email'));
}
// If not set, the subscription form is not requesting the name, so we do not
// raise errors.
if (isset($_REQUEST['nn'])) {
if (trim($_REQUEST['nn']) == '') {
die(frontpage_label('error_name'));
}
}
else {
$_REQUEST['nn'] = '';
}
$profile1 = $_REQUEST['np'];
if (!isset($profile1) || !is_array($profile1)) $profile1 = array();
// keys starting with "_" are removed because used internally
$profile = array();
foreach ($profile1 as $k=>$v) {
if ($k[0] == '_') continue;
$profile[$k] = $v;
}
$profile['_ip'] = $_SERVER['REMOTE_ADDR'];
$profile['_referrer'] = $_SERVER['HTTP_REFERER'];
// Check if the group is good
frontpage_subscribe($_REQUEST['ne'], $_REQUEST['nn'], $profile);
if (isset($options['noconfirmation'])) {
$frontpage_step = 'confirmed';
}
else {
$frontpage_step = 'subscribed';
}
return;
}
// A request to confirm a subscription
if ($action == 'c') {
$id = $_REQUEST['ni'];
frontpage_confirm($id, $_REQUEST['nt']);
header('Location: ' . frontpage_add_qs($options['url'], 'na=cs&ni=' . $id . '&nt=' . $_REQUEST['nt'], false));
die();
}
// Show the confirmed message after a redirection (to avoid mutiple email sending).
// Redirect is sent by action "c".
if ($action == 'cs') {
$frontpage_subscriber = frontpage_get_subscriber($_REQUEST['ni']);
if ($frontpage_subscriber->token != $_REQUEST['nt']) die('Ivalid token');
$frontpage_step = 'confirmed';
}
// Unsubscription process has 2 options: if email and token are specified the user
// will only be asked to confirm. If there is no infos of who remove (when
// mass mail mode is used) the user will be asked to type the emailto be removed.
if ($action == 'u') {
$frontpage_step = 'unsubscription';
}
// User confirmed he want to unsubscribe clicking the link on unsubscription
// page
if ($action == 'uc') {
frontpage_unsubscribe($_REQUEST['ni'], $_REQUEST['nt']);
$frontpage_step = 'unsubscribed';
}
}*/
/**
* Deletes a subscription (no way back). Fills the global $frontpage_subscriber
* with subscriber data to be used to build up messages.
*//* Modificaci—n Mecus
function frontpage_unsubscribe($id, $token) {
global $frontpage_subscriber, $wpdb;
// Save the subscriber for good bye page
$frontpage_subscriber = frontpage_get_subscriber($id);
$wpdb->query($wpdb->prepare("delete from " . $wpdb->prefix . "frontpage where id=%d" .
" and token=%s", $id, $token));
$options = get_option('frontpage');
$html = frontpage_get_theme_html($options['theme']);
if ($html == null) $html = '{message}';
$message = str_replace('{message}', $options['unsubscribed_message'], $html);
$message = frontpage_replace($message, $frontpage_subscriber);
// URL to the unsubscription page (for test purpose)
// $url = frontpage_add_qs($options['url'], 'na=u&ni=' . $frontpage_subscriber->id .
// '&nt=' . $frontpage_subscriber->token);
// $message = frontpage_replace_url($message, 'UNSUBSCRIPTION_URL', $url);
$subject = frontpage_replace($options['unsubscribed_subject'], $frontpage_subscriber);
if (frontpage_has_extras('1.0.4')) frontpage_init_mail();
frontpage_mail($frontpage_subscriber->email, $subject, $message);
if (frontpage_has_extras('1.0.4')) frontpage_close_mail();
// Admin notification
$message = 'There is an unsubscription to ' . get_option('blogname') . ' frontpage:' . "\n\n" .
$frontpage_subscriber->name . ' <' . $frontpage_subscriber->email . '>' . "\n\n" .
'Have a nice day,' . "\n" . 'your frontpage plugin.';
$subject = '[' . get_option('blogname') . '] Unsubscription';
frontpage_notify_admin($subject, $message);
}*/
/*
* Deletes a specific subscription. Called only from the admin panel.
*//* Modificaci—n Mecus
function frontpage_delete($id) {
global $wpdb;
$wpdb->query($wpdb->prepare("delete from " . $wpdb->prefix . "frontpage where id=%d", $id));
}
function frontpage_delete_all($status=null) {
global $wpdb;
if ($status == null) {
$wpdb->query("delete from " . $wpdb->prefix . "frontpage");
}
else {
$wpdb->query("delete from " . $wpdb->prefix . "frontpage where status='" . $wpdb->escape($status) . "'");
}
}*/
/**
* Confirms a subscription identified by id and token, changing it's status on
* database. Fill the global $frontpage_subscriber with user data.
* If the subscription id already confirmed, the welcome email is still sent to
* the subscriber (the welcome email can contains somthing reserved to the user
* and he may has lost it).
* If id and token do not match, the function does nothing.
*//* Modificaci—n Mecus
function frontpage_confirm($id, $token) {
global $wpdb, $frontpage_subscriber;
$options = get_option('frontpage');
$frontpage_subscriber = frontpage_get_subscriber($id);
frontpage_info(__FUNCTION__, "Starting confirmation of subscriber " . $id);
if ($frontpage_subscriber == null) {
frontpage_error(__FUNCTION__, "Subscriber not found");
return;
}
if ($frontpage_subscriber->token != $token) {
frontpage_error(__FUNCTION__, "Token not matching");
return;
}
frontpage_debug(__FUNCTION__, "Confirming subscriber:\n" . print_r($frontpage_subscriber, true));
$count = $wpdb->query($wpdb->prepare("update " . $wpdb->prefix . "frontpage set status='C' where id=%d", $id));
frontpage_send_welcome($frontpage_subscriber);
}
function frontpage_send_welcome($subscriber) {
$options = get_option('frontpage');
frontpage_debug(__FUNCTION__, "Welcome message to:\n" . print_r($subscriber, true));