-
Notifications
You must be signed in to change notification settings - Fork 58
/
ManageMaillist.php
1564 lines (1399 loc) · 51.1 KB
/
ManageMaillist.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
/**
* @name ElkArte Forum
* @copyright ElkArte Forum contributors
* @license BSD http://opensource.org/licenses/BSD-3-Clause
*
* @version 1.0 Alpha
*
* This file contains maillist functions that are specifically done by administrators
* and those with approve email permission
*
*/
if (!defined('ELK'))
die('No access...');
/**
* This class is the administration maillist controller.
* - handles maillist configuration
* - handles the showing, repairing, deleting and bouncing failed emails
* - handles the adding / editing / removing of both filters and parsers
*
*/
class ManageMaillist_Controller extends Action_Controller
{
/**
* Basic feature settings form
* @var Settings_Form
*/
protected $_maillistSettings;
/**
* Main dispatcher.
* This function checks permissions and passes control
* to the sub action.
* @see Action_Controller::action_index()
*/
public function action_index()
{
global $context, $txt;
// All the functions available
$subActions = array(
'emaillist' => array($this, 'action_unapproved_email', 'permission' => 'approve_emails'),
'approve' => array($this, 'action_approve_email', 'permission' => 'approve_emails'),
'delete' => array($this, 'action_delete_email', 'permission' => 'approve_emails'),
'bounce' => array($this, 'action_bounce_email', 'permission' => 'approve_emails'),
'emailtemplates' => array($this, 'action_view_bounce_templates', 'permission' => 'approve_emails'),
'view' => array($this, 'action_view_email', 'permission' => 'approve_emails'),
'emailsettings' => array($this, 'action_settings', 'permission' => 'admin_forum'),
'emailfilters' => array($this, 'action_list_filters', 'permission' => 'admin_forum'),
'editfilter' => array($this, 'action_edit_filters', 'permission' => 'admin_forum'),
'deletefilter' => array($this, 'action_delete_filters', 'permission' => 'admin_forum'),
'emailparser' => array($this, 'action_list_parsers', 'permission' => 'admin_forum'),
'editparser' => array($this, 'action_edit_parsers', 'permission' => 'admin_forum'),
'deleteparser' => array($this, 'action_delete_parsers', 'permission' => 'admin_forum'),
);
// Set up the action class
$action = new Action();
$action->initialize($subActions, 'emaillist');
// Default to sub action 'emaillist' if none was given
$subAction = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) && (empty($subActions[$_REQUEST['sa']][1]) || allowedTo($subActions[$_REQUEST['sa']][1])) ? $_REQUEST['sa'] : 'emaillist';
// Template & language
loadTemplate('Maillist');
loadLanguage('Maillist');
// Create the title area for the template.
$context[$context['admin_menu_name']]['tab_data'] = array(
'title' => $txt['ml_admin_configuration'],
'help' => $txt['maillist_help_short'],
'description' => $txt['ml_configuration_desc'],
);
// If you have the permissions, then go Play
$action->dispatch($subAction);
}
/**
* Main listing of failed emails.
* - shows the sender, key and subject of the email
* - Will show the found key if it was missing or possible sender if it was wrong
* - icons to view, bounce, delete or approve a failure
*/
public function action_unapproved_email()
{
global $context, $scripturl, $modSettings, $txt, $settings;
// Set an id if none was supplied
$id = (isset($_REQUEST['e_id']) ? (int) $_REQUEST['e_id'] : 0);
if (empty($id) || $id <= 0)
$id = 0;
require_once(SUBSDIR . '/Maillist.subs.php');
createToken('admin-ml', 'get');
// Build the list option array to display the email data
$listOptions = array(
'id' => 'view_email_errors',
'title' => $txt['ml_emailerror'],
'items_per_page' => $modSettings['defaultMaxMessages'],
'no_items_label' => $txt['ml_emailerror_none'],
'base_href' => $scripturl . '?action=admin;area=maillist',
'default_sort_col' => 'id_email',
'get_items' => array(
'function' => 'list_maillist_unapproved',
'params' => array(
$id,
),
),
'get_count' => array(
'function' => 'list_maillist_count_unapproved',
'params' => array(
$id,
),
),
'columns' => array(
'id_email' => array(
'header' => array(
'value' => $txt['id'],
),
'data' => array(
'db' => 'id_email',
'style' => 'width: 2.2em;',
),
'sort' => array(
'default' => 'id_email ',
'reverse' => 'id_email DESC',
),
),
'error' => array(
'header' => array(
'value' => $txt['error'],
),
'data' => array(
'db' => 'error',
),
'sort' => array(
'default' => 'error ',
'reverse' => 'error DESC',
),
),
'subject' => array(
'header' => array(
'value' => $txt['subject'],
),
'data' => array(
'db' => 'subject',
),
'sort' => array(
'default' => 'subject',
'reverse' => 'subject DESC',
),
),
'key' => array(
'header' => array(
'value' => $txt['key'],
),
'data' => array(
'db' => 'key',
),
'sort' => array(
'default' => 'data_id',
'reverse' => 'data_id DESC',
),
),
'message' => array(
'header' => array(
'value' => $txt['message_id'],
),
'data' => array(
'sprintf' => array(
'format' => '<a href="%1$s">%2$s</a>',
'params' => array(
'link' => true,
'message' => true,
),
),
),
'sort' => array(
'default' => 'message_id',
'reverse' => 'message_id DESC',
),
),
'from' => array(
'header' => array(
'value' => $txt['from'],
),
'data' => array(
'db' => 'from',
),
'sort' => array(
'default' => 'email_from',
'reverse' => 'email_from DESC',
),
),
'type' => array(
'header' => array(
'value' => $txt['message_type'],
),
'data' => array(
'function' => create_function('$rowData', '
global $txt;
// Do we have a type?
if (empty($rowData[\'type\']))
return $txt[\'not_applicable\'];
// Personal?
elseif ($rowData[\'type\'] === \'p\')
return $txt[\'personal_message\'];
// New Topic?
elseif ($rowData[\'type\'] === \'x\')
return $txt[\'new_topic\'];
// Ah a Reply then
else
return $txt[\'topic\'] . \' \' . $txt[\'reply\'];
'),
),
'sort' => array(
'default' => 'message_type',
'reverse' => 'message_type DESC',
),
),
'action' => array(
'header' => array(
'value' => $txt['message_action'],
),
'data' => array(
'sprintf' => array(
'format' => '<a href="?action=admin;area=maillist;sa=approve;item=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-ml_token_var'] . '=' . $context['admin-ml_token'] . '"><img style="width:16px;height:16px" title="' . $txt['approve'] . '" src="' . $settings['images_url'] . '/icons/field_valid.png" alt="*" /></a>
<a href="?action=admin;area=maillist;sa=delete;item=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-ml_token_var'] . '=' . $context['admin-ml_token'] . '" onclick="return confirm(' . JavaScriptEscape($txt['delete_warning']) . ') && submitThisOnce(this);" accesskey="d"><img style="width:16px;height:16px" title="' . $txt['delete'] . '" src="' . $settings['images_url'] . '/icons/quick_remove.png" alt="*" /></a><br />
<a href="?action=admin;area=maillist;sa=bounce;item=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-ml_token_var'] . '=' . $context['admin-ml_token'] . '"><img style="width:16px;height:16px" title="' . $txt['bounce'] . '" src="' . $settings['images_url'] . '/icons/pm_replied.png" alt="*" /></a>
<a href="?action=admin;area=maillist;sa=view;item=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-ml_token_var'] . '=' . $context['admin-ml_token'] . '"><img style="width:16px;height:16px" title="' . $txt['view'] . '" src="' . $settings['images_url'] . '/icons/pm_read.png" alt="*" /></a>',
'params' => array(
'id_email' => true,
),
),
'class' => 'centertext',
),
),
),
'form' => array(
'href' => $scripturl . '?action=admin;area=maillist;sa=emaillist',
'include_sort' => true,
'include_start' => true,
),
'additional_rows' => array(
array(
'position' => 'top_of_list',
'value' => isset($_SESSION['email_error']) ? '<div class="' . (isset($_SESSION['email_error_type']) ? 'infobox' : 'errorbox') . '">' . $_SESSION['email_error'] . '</div>' : $txt['heading'],
'class' => 'windowbg2',
),
),
);
// Clear any errors
unset($_SESSION['email_error'], $_SESSION['email_error_type']);
// Set the context values for the template
$context['page_title'] = $txt['emailerror_title'];
$context['sub_template'] = 'show_list';
$context['default_list'] = 'view_email_errors';
// Create the list.
require_once(SUBSDIR . '/List.subs.php');
createList($listOptions);
}
/**
* Show a failed email for review by the moderation team
* - Will not show a PM if it has been identified as such
*/
public function action_view_email()
{
global $txt, $context;
allowedTo('approve_emails');
checkSession('get');
validateToken('admin-ml', 'get');
$id = (int) $_GET['item'];
if (!empty($id))
{
require_once(SUBSDIR . '/Maillist.subs.php');
// load up the email details, no funny biz ;)
$temp_email = list_maillist_unapproved('', '', '', $id);
if (!empty($temp_email))
{
if ($temp_email[0]['type'] !== 'p' && allowedTo('approve_emails'))
{
$data = (int) $temp_email[0]['body'];
// Read/parse this message for viewing
require_once(CONTROLLERDIR . '/Emailpost.controller.php');
$controller = Emailpost_Controller();
$result = $controller->action_pbe_preview($data);
$text = isset($result['body']) ? $result['body'] : '';
$email_to = isset($result['to']) ? $result['to'] : '';
}
else
{
// PM's mean just that ...
$text = $txt['noaccess'];
$email_to = $txt['private'];
}
}
else
$text = $txt['badid'];
}
else
$text = $txt['badid'];
// prep and show the template with what we found
$context['body'] = parse_bbc($text);
$context['to'] = $txt['to'] . ' ' . (isset($email_to) ? $email_to : '');
$context['notice_subject'] = (isset($temp_email[0]['subject']) ? $txt['subject'] . ': ' . $temp_email[0]['subject'] : '');
$context['notice_from'] = (isset($temp_email[0]['from']) ? $txt['from'] . ': ' . $temp_email[0]['from'] : '');
$context['page_title'] = $txt['show_notice'];
$context['error_code'] = $txt[$temp_email[0]['error_code']];
$context['sub_template'] = 'show_email';
}
/**
* Deletes an entry from the database
* - Flushes the moderator menu todo numbers so the menu numbers update
*/
public function action_delete_email()
{
allowedTo('approve_emails');
checkSession('get');
validateToken('admin-ml', 'get');
$id = (int) $_GET['item'];
if (!empty($id))
{
// remove this entry
require_once(SUBSDIR . '/Maillist.subs.php');
maillist_delete_entry($id);
}
// Flush the cache
cache_put_data('num_menu_errors', null, 900);
// Back to the failed list we go
redirectexit('action=admin;area=maillist;sa=emaillist');
}
/**
* Attempts to approve and post a failed email
* - Reviews the data to see if the email error function fixed typical issues like key and wrong id
* - Submits the fixed email to the main function which will post it or fail it again
* - If successful will remove the entry from the failed log
*/
public function action_approve_email()
{
global $txt;
allowedTo('approve_emails');
checkSession('get');
validateToken('admin-ml', 'get');
// Get the id to approve
$id = (int) $_GET['item'];
if (!empty($id) && $id !== -1)
{
// Load up the email data
require_once(SUBSDIR . '/Maillist.subs.php');
$temp_email = list_maillist_unapproved('', '', '', $id);
if (!empty($temp_email))
{
// Do we have the needed data to approve this, after all it failed for a reason yes?
if (!empty($temp_email[0]['key']) && (!in_array($temp_email[0]['error_code'], array('error_pm_not_found', 'error_no_message', 'error_not_find_board', 'error_topic_gone'))))
{
// Set up the details needed to get this posted
$force = true;
$key = $temp_email[0]['key'] . $temp_email[0]['type'] . $temp_email[0]['message'];
$data = $temp_email[0]['body'];
// Unknown from email? Update the message ONLY if we found an appropriate one during the error checking process
if (in_array($temp_email[0]['error_code'], array('error_not_find_member', 'error_key_sender_match')))
{
// did we actually find a potential correct name, if so we post from the valid member
$check_emails = explode('=>', $temp_email[0]['from']);
if (isset($check_emails[1]))
$data = str_ireplace('From: ' . trim($check_emails[0]), 'From: ' . trim($check_emails[1]), $data);
}
// Lets TRY AGAIN to make a post!
include_once(CONTROLLERDIR . '/Emailpost.controller.php');
$controller = new Emailpost_Controller();
$text = $controller->action_pbe_post($data, $force, $key);
// Assuming all went well, remove this entry and file since we are done.
if ($text === true)
{
maillist_delete_entry($id);
// Flush the menu count cache
cache_put_data('num_menu_errors', null, 900);
$_SESSION['email_error'] = $txt['approved'];
$_SESSION['email_error_type'] = 1;
}
else
$_SESSION['email_error'] = $txt['error_approved'];
}
else
$_SESSION['email_error'] = $txt['cant_approve'];
}
else
$_SESSION['email_error'] = $txt['badid'];
}
else
$_SESSION['email_error'] = $txt['badid'];
// back to the list we go
redirectexit('action=admin;area=maillist;sa=emaillist');
}
/**
* Allows the admin to choose from predefined and custom templates
* - Uses the selected template to send a bounce notification with
* details as specified by the template
*/
public function action_bounce_email()
{
global $context, $txt, $modSettings, $scripturl, $mbname;
if (!isset($_REQUEST['bounce']))
{
checkSession('get');
validateToken('admin-ml', 'get');
}
require_once(SUBSDIR . '/Mail.subs.php');
require_once(SUBSDIR . '/Maillist.subs.php');
// We should have been sent an email ID
if (isset($_REQUEST['item']))
{
// Needs to be an int!
$id = (int) $_REQUEST['item'];
// Load up the email details, no funny biz yall ;)
$temp_email = list_maillist_unapproved(null, null, null, $id);
if (!empty($temp_email))
{
// set the options
$_POST['item'] = (int) $temp_email[0]['id_email'];
$fullerrortext = $txt[$temp_email[0]['error_code']];
$shorterrortext = $temp_email[0]['error'];
// Build the template selection area, first the standard ones
$bounce = array('bounce', 'inform');
foreach ($bounce as $k => $type)
{
$context['bounce_templates'][$k]['body'] = $txt['ml_' . $type . '_body'];
$context['bounce_templates'][$k]['subject'] = $txt['ml_' . $type . '_subject'];
$context['bounce_templates'][$k]['title'] = $txt['ml_' . $type . '_title'];
}
// And now any custom ones available for this moderator
$context['bounce_templates'] += array_merge($context['bounce_templates'], maillist_templates());
// Replace all the variables in the templates
foreach ($context['bounce_templates'] as $k => $name)
{
$context['bounce_templates'][$k]['body'] = strtr($name['body'], array(
'{MEMBER}' => un_htmlspecialchars($temp_email[0]['name']),
'{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname,
'{REGARDS}' => $txt['regards_team'],
'{SUBJECT}' => $temp_email[0]['subject'],
'{ERROR}' => $fullerrortext,
'{FORUMNAME}' => $mbname,
'{FORUMNAMESHORT}' => (!empty($modSettings['maillist_sitename']) ? $modSettings['maillist_sitename'] : $mbname),
'{EMAILREGARDS}' => (!empty($modSettings['maillist_sitename_regards']) ? $modSettings['maillist_sitename_regards'] : ''),
'{REGARDS}' => $txt['regards_team'],
));
}
}
else
$context['settings_message'] = $txt['badid'];
}
else
$context['settings_message'] = $txt['badid'];
// Check if they are sending the notice
if (isset($_REQUEST['bounce']))
{
checkSession('post');
validateToken('admin-ml');
// They did check the box, how else could they have posted
if (isset($_POST['warn_notify']))
{
// lets make sure we have the items to send it
$check_emails = explode('=>', $temp_email[0]['from']);
$to = trim($check_emails[0]);
$subject = trim($_POST['warn_sub']);
$body = trim($_POST['warn_body']);
if (empty($body) || empty($subject))
$context['settings_message'] = $txt['bad_bounce'];
else
{
// Time for someone to get a we're so sorry message!
sendmail($to, $subject, $body, null, null, false, 5);
redirectexit('action=admin;area=maillist;bounced');
}
}
}
// Prep and show the template
createToken('admin-ml');
$context['warning_data'] = array('notify' => '', 'notify_subject' => '', 'notify_body' => '');
$context['body'] = parse_bbc($fullerrortext);
$context['item'] = isset($_POST['item']) ? $_POST['item'] : '';
$context['notice_to'] = $txt['to'] . ' ' . $temp_email[0]['from'];
$context['page_title'] = $txt['bounce_title'];
$context['sub_template'] = 'bounce_email';
}
/**
* List all the filters in the system
* - Allows to add/edit or delete filters
* - Filters are used to alter text in a post, to remove crud that comes with emails
* - Filters can be defined as regex, the system will check it for valid syntax
* - Uses list_get_filter_parser for the data and list_count_filter_parser for the number
*/
public function action_list_filters()
{
global $context, $scripturl, $txt, $settings, $modSettings;
$id = 0;
require_once(SUBSDIR . '/Maillist.subs.php');
// build the listoption array to display the filters
$listOptions = array(
'id' => 'email_filter',
'title' => $txt['filters'],
'items_per_page' => $modSettings['defaultMaxMessages'],
'no_items_label' => $txt['no_filters'],
'base_href' => $scripturl . '?action=admin;area=maillist;sa=emailfilters',
'default_sort_col' => 'name',
'get_items' => array(
'function' => 'list_get_filter_parser',
'params' => array(
$id,
'filter'
),
),
'get_count' => array(
'function' => 'list_count_filter_parser',
'params' => array(
$id,
'filter'
),
),
'columns' => array(
'name' => array(
'header' => array(
'value' => $txt['filter_name'],
),
'data' => array(
'db' => 'filter_name',
),
'sort' => array(
'default' => 'filter_name, id_filter',
'reverse' => 'filter_name DESC, id_filter DESC',
),
),
'from' => array(
'header' => array(
'value' => $txt['filter_from'],
),
'data' => array(
'db' => 'filter_from',
),
'sort' => array(
'default' => 'filter_from, id_filter',
'reverse' => 'filter_from DESC, id_filter DESC',
),
),
'to' => array(
'header' => array(
'value' => $txt['filter_to'],
'style' => 'width:10em;',
),
'data' => array(
'db' => 'filter_to',
),
'sort' => array(
'default' => 'filter_to, id_filter',
'reverse' => 'filter_to DESC, id_filter DESC',
),
),
'type' => array(
'header' => array(
'value' => $txt['filter_type'],
),
'data' => array(
'db' => 'filter_type',
),
'sort' => array(
'default' => 'filter_type, id_filter',
'reverse' => 'filter_type DESC, id_filter DESC',
),
),
'action' => array(
'header' => array(
'value' => $txt['message_action'],
),
'data' => array(
'sprintf' => array(
'format' => '<a href="?action=admin;area=maillist;sa=editfilter;f_id=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . '">
<img title="' . $txt['modify'] . '" src="' . $settings['images_url'] . '/buttons/modify.png" alt="*" />
</a>
<a href="?action=admin;area=maillist;sa=deletefilter;f_id=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . '" onclick="return confirm(' . JavaScriptEscape($txt['filter_delete_warning']) . ') && submitThisOnce(this);" accesskey="d">
<img title="' . $txt['delete'] . '" src="' . $settings['images_url'] . '/buttons/delete.png" alt="*" />
</a>',
'params' => array(
'id_filter' => true,
),
),
'class' => 'centertext',
'style' => 'white-space:nowrap;',
),
),
),
'form' => array(
'href' => $scripturl . '?action=admin;area=maillist;sa=editfilter;',
'include_sort' => true,
'include_start' => true,
'hidden_fields' => array(
$context['session_var'] => $context['session_id'],
),
),
'additional_rows' => array(
array(
'position' => isset($_GET['saved']) ? 'top_of_list' : 'after_title',
'value' => isset($_GET['saved']) ? '<div class="infobox">' . $txt['saved'] . '</div>' : $txt['filters_title'],
'class' => 'windowbg2',
),
array(
'position' => 'below_table_data',
'value' => '<input type="submit" name="addfilter" value="' . $txt['add_filter'] . '" class="button_submit" />',
),
),
);
// Set the context values
$context['page_title'] = $txt['filters'];
$context['sub_template'] = 'show_list';
$context['default_list'] = 'email_filter';
// Create the list.
require_once(SUBSDIR . '/List.subs.php');
createList($listOptions);
}
/**
* Edit or Add a filter
* - If regex will check for proper syntax before saving to the database
*/
public function action_edit_filters()
{
global $context, $scripturl, $txt, $modSettings;
// Editing an existing filter?
if (isset($_REQUEST['f_id']))
{
// Needs to be an int!
$id = (int) $_REQUEST['f_id'];
if (empty($id) || $id <= 0)
fatal_lang_error('error_no_id_filter');
// Load it up and set it as the current values
require_once(SUBSDIR . '/Maillist.subs.php');
$row = maillist_load_filter_parser($id, 'filter');
$modSettings['id_filter'] = $row['id_filter'];
$modSettings['filter_type'] = $row['filter_type'];
$modSettings['filter_to'] = $row['filter_to'];
$modSettings['filter_from'] = $row['filter_from'];
$modSettings['filter_name'] = $row['filter_name'];
// Some items for the form
$context['page_title'] = $txt['edit_filter'];
$context['editing'] = true;
$context['settings_message'] = array();
}
else
{
// Setup place holders for adding a new one instead
$modSettings['filter_type'] = '';
$modSettings['filter_to'] = '';
$modSettings['filter_from'] = '';
$modSettings['filter_name'] = '';
$context['page_title'] = $txt['add_filter'];
$context['editing'] = false;
$context['settings_message'] = array();
}
// Initialize the filer settings form
$this->_initFiltersSettingsForm();
$config_vars = $this->_filtersSettings->settings();
// Saving the new or edited entry?
if (isset($_GET['save']))
{
checkSession();
// Editing an entry?
$editid = (isset($_GET['edit'])) ? (int) $_GET['edit'] : -1;
$editname = (isset($_GET['edit'])) ? 'id_filter' : '';
// If its regex we do a quick check to see if its valid or not
if ($_POST['filter_type'] === 'regex')
{
$valid = (@preg_replace($_POST['filter_from'], $_POST['filter_to'], 'ElkArte') === null) ? false : true;
if (!$valid)
{
// Seems to be bad ... reload the form, set the message
$context['error_type'] = 'notice';
$context['settings_message'][] = $txt['regex_invalid'];
$modSettings['filter_type'] = $_POST['filter_type'];
$modSettings['filter_to'] = $_POST['filter_to'];
$modSettings['filter_from'] = $_POST['filter_from'];
$modSettings['filter_name'] = $_POST['filter_name'];
}
}
if (empty($_POST['filter_type']) || empty($_POST['filter_from']))
{
$context['error_type'] = 'notice';
$context['settings_message'][] = $txt['filter_invalid'];
}
// if we are good to save, so save it ;)
if (empty($context['settings_message']))
{
// And ... its a filter
$config_vars[] = array('text', 'filter_style');
$_POST['filter_style'] = 'filter';
require_once(SUBSDIR . '/Maillist.subs.php');
MaillistSettingsClass::saveTableSettings($config_vars, 'postby_emails_filters', array(), $editid, $editname);
writeLog();
redirectexit('action=admin;area=maillist;sa=emailfilters;saved');
}
}
// Prepare some final context for the template
$title = !empty($_GET['saved']) ? 'saved_filter' : ($context['editing'] == true ? 'edit_filter' : 'add_filter');
$context['post_url'] = $scripturl . '?action=admin;area=maillist;sa=editfilter' . ($context['editing'] ? ';edit=' . $modSettings['id_filter'] : ';new') . ';save';
$context['settings_title'] = $txt[$title];
$context['linktree'][] = array(
'url' => $scripturl . '?action=admin;area=maillist;sa=editfilter',
'name' => ($context['editing']) ? $txt['edit_filter'] : $txt['add_filter'],
);
$context[$context['admin_menu_name']]['tab_data'] = array(
'title' => $txt[$title],
'description' => $txt['filters_title'],
);
$context[$context['admin_menu_name']]['current_subsection'] = 'emailfilters';
// Load and show
MaillistSettingsClass::prepare_db($config_vars);
loadTemplate('Admin', 'admin');
$context['sub_template'] = 'show_settings';
}
/**
* Initialize Mailist settings form.
*/
private function _initFiltersSettingsForm()
{
global $txt;
// We need some setting options for our maillist
require_once(SUBSDIR . '/Settings.class.php');
// We don't save values in settings but in our filters table so we extend the class with our jazz
require_once(SUBSDIR . '/EmailSettings.class.php');
// Instantiate the extended parser form
$this->_filtersSettings = new MaillistSettingsClass();
// Set up the config_vars for the form
$config_vars = array(
array('text', 'filter_name', 25, 'subtext' => $txt['filter_name_desc']),
array('select', 'filter_type',
array(
'standard' => $txt['option_standard'],
'regex' => $txt['option_regex'],
),
),
array('large_text', 'filter_from', 4, 'subtext' => $txt['filter_from_desc']),
array('text', 'filter_to', 25, 'subtext' => $txt['filter_to_desc']),
);
return $this->_filtersSettings->settings($config_vars);
}
/**
* Deletes a filter from the system / database
*/
public function action_delete_filters()
{
// Removing the filter?
if (isset($_GET['f_id']))
{
checkSession('get');
$id = (int) $_GET['f_id'];
require_once(SUBSDIR . '/Maillist.subs.php');
maillist_delete_filter_parser($id);
redirectexit('action=admin;area=maillist;sa=emailfilters;deleted');
}
}
/**
* Show a list of all the parsers in the system
* - Allows to add/edit or delete parsers
* - Parsers are used to split a message at a line of text
* - Parsers can only be defined as regex, the system will check it for valid syntax
* - Uses list_get_filter_parser for the data and list_count_filter_parser for the number
*/
public function action_list_parsers()
{
global $context, $scripturl, $txt, $settings, $modSettings;
$id = 0;
require_once(SUBSDIR . '/Maillist.subs.php');
// build the listoption array to display the data
$listOptions = array(
'id' => 'email_parser',
'title' => $txt['parsers'],
'items_per_page' => $modSettings['defaultMaxMessages'],
'no_items_label' => $txt['no_parsers'],
'base_href' => $scripturl . '?action=admin;area=maillist;sa=emailparser',
'default_sort_col' => 'name',
'get_items' => array(
'function' => 'list_get_filter_parser',
'params' => array(
$id,
'parser'
),
),
'get_count' => array(
'function' => 'list_count_filter_parser',
'params' => array(
$id,
'parser'
),
),
'columns' => array(
'name' => array(
'header' => array(
'value' => $txt['parser_name'],
),
'data' => array(
'db' => 'filter_name',
),
'sort' => array(
'default' => 'filter_name',
'reverse' => 'filter_name DESC',
),
),
'from' => array(
'header' => array(
'value' => $txt['parser_from'],
),
'data' => array(
'db' => 'filter_from',
),
'sort' => array(
'default' => 'filter_from',
'reverse' => 'filter_from DESC',
),
),
'type' => array(
'header' => array(
'value' => $txt['parser_type'],
),
'data' => array(
'db' => 'filter_type',
),
'sort' => array(
'default' => 'filter_type',
'reverse' => 'filter_type DESC',
),
),
'action' => array(
'header' => array(
'value' => $txt['message_action'],
),
'data' => array(
'sprintf' => array(
'format' => '<a href="?action=admin;area=maillist;sa=editparser;f_id=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . '">
<img title="' . $txt['modify'] . '"src="' . $settings['images_url'] . '/buttons/modify.png" alt="*" />
</a>
<a href="?action=admin;area=maillist;sa=deleteparser;f_id=%1$s;' . $context['session_var'] . '=' . $context['session_id'] . '" onclick="return confirm(' . JavaScriptEscape($txt['parser_delete_warning']) . ') && submitThisOnce(this);" accesskey="d">
<img title="' . $txt['delete'] . '" src="' . $settings['images_url'] . '/buttons/delete.png" alt="*" />
</a>',
'params' => array(
'id_filter' => true,
),
),
'class' => 'centertext',
'style' => 'white-space:nowrap;',
),
),
),
'form' => array(
'href' => $scripturl . '?action=admin;area=maillist;sa=editparser',
'include_sort' => true,
'include_start' => true,
'hidden_fields' => array(
$context['session_var'] => $context['session_id'],
),
),
'additional_rows' => array(
array(
'position' => isset($_GET['saved']) ? 'top_of_list' : 'after_title',
'value' => isset($_GET['saved']) ? '<div class="infobox">' . $txt['saved'] . '</div>' : $txt['parsers_title'],
'class' => 'windowbg2',
),
array(
'position' => 'below_table_data',
'value' => '<input type="submit" name="addfilter" value="' . $txt['add_parser'] . '" class="button_submit" />',
'class' => 'righttext',
),
),
);
// Set the context values
$context['page_title'] = $txt['parsers'];
$context['sub_template'] = 'show_list';
$context['default_list'] = 'email_parser';
// Create the list.
require_once(SUBSDIR . '/List.subs.php');
createList($listOptions);
}
/**
* Adds or Edits an existing parser
* - All parsers are assumed regex
*/
public function action_edit_parsers()
{
global $context, $scripturl, $txt, $modSettings;
// Editing an existing filter?
if (isset($_REQUEST['f_id']))
{
// Needs to be an int!
$id = (int) $_REQUEST['f_id'];
if (empty($id) || $id < 0)
fatal_lang_error('error_no_id_filter');
// load this filter so we can edit it
require_once(SUBSDIR . '/Maillist.subs.php');
$row = maillist_load_filter_parser($id, 'parser');
$modSettings['id_filter'] = $row['id_filter'];
$modSettings['filter_type'] = $row['filter_type'];
$modSettings['filter_from'] = $row['filter_from'];
$modSettings['filter_name'] = $row['filter_name'];
$context['page_title'] = $txt['edit_parser'];
$context['editing'] = true;
}
else
{
// Setup place holders for adding a new one instead
$modSettings['filter_type'] = '';
$modSettings['filter_name'] = '';
$modSettings['filter_from'] = '';
// To the template we go
$context['page_title'] = $txt['add_parser'];
$context['editing'] = false;
}
// Initialize the mailparser settings form
$this->_initParsersSettingsForm();
$config_vars = $this->_parsersSettings->settings();
// Check if they are saving the changes
if (isset($_GET['save']))