Plugin Directory

source: newsletter/tags/9.0.8/main/main.php

Last change on this file was 3379215, checked in by satollo, 6 weeks ago

Version 9.0.4

File size: 22.3 KB
Line 
1<?php
2/** @var NewsletterMainAdmin $this */
3/** @var NewsletterControls $controls */
4/** @var NewsletterLogger $logger */
5/** @var wpdb $wpdb */
6/** @var string $language */
7
8use Newsletter\License;
9
10defined('ABSPATH') || exit;
11
12if (!$controls->is_action()) {
13    $controls->data = $this->get_options('', $language);
14} else {
15
16    if ($controls->is_action('save')) {
17
18        if (!$language) {
19
20            $css = $controls->data['css'] ?? '';
21
22            if (!$this->is_html_allowed()) {
23                $controls->data = wp_kses_post_deep($controls->data);
24                // CSS must not be filtered!
25                $controls->data['css'] = $css;
26            }
27
28            if (preg_match('#</?\w+#', $css)) {
29                $controls->errors .= __('Invalid CSS', 'newsletter') . '<br>';
30            }
31
32            if (!$this->is_email($controls->data['sender_email'])) {
33                $controls->errors .= __('The sender email address is not correct.', 'newsletter') . '<br>';
34            } else {
35                $controls->data['sender_email'] = $this->normalize_email($controls->data['sender_email']);
36            }
37
38            if (!$this->is_email($controls->data['return_path'], true)) {
39                $controls->errors .= __('Return path email is not correct.', 'newsletter') . '<br>';
40            } else {
41                $controls->data['return_path'] = $this->normalize_email($controls->data['return_path']);
42            }
43
44            $controls->data['scheduler_max'] = (int) $controls->data['scheduler_max'];
45            if ($controls->data['scheduler_max'] < 12) {
46                $controls->data['scheduler_max'] = 12;
47            }
48
49            if (defined('NEWSLETTER_SEND_DELAY')) {
50                $controls->data['max_per_second'] = (float) $controls->data['max_per_second'];
51            } else {
52                $controls->data['max_per_second'] = (float) $controls->data['max_per_second'];
53                if ($controls->data['max_per_second'] <= 0) {
54                    $controls->data['max_per_second'] = 0;
55                }
56            }
57
58            if (!$this->is_email($controls->data['reply_to'], true)) {
59                $controls->errors .= __('Reply to email is not correct.', 'newsletter') . '<br>';
60            } else {
61                $controls->data['reply_to'] = $this->normalize_email($controls->data['reply_to']);
62            }
63
64            if (!empty($controls->data['contract_key'])) {
65                $controls->data['contract_key'] = trim($controls->data['contract_key']);
66            }
67
68            update_option('newsletter_log_level', $controls->data['log_level']);
69        }
70
71        if (empty($controls->errors)) {
72            $this->save_options($controls->data, '', $language);
73            $controls->add_toast_saved();
74            if (!$language) {
75                $this->logger->debug('Main options saved');
76                NewsletterMainAdmin::instance()->set_completed_step('sender');
77                if ($controls->data['scheduler_max'] != 100) {
78                    NewsletterMainAdmin::instance()->set_completed_step('delivery-speed');
79                }
80            }
81        }
82
83        Newsletter\Addons::clear();
84        Newsletter\News::clear();
85        update_option('newsletter_public_page_check', 0, false);
86
87        License::update();
88    }
89
90    if ($controls->is_action('create')) {
91        $page = [];
92        $page['post_title'] = 'Newsletter';
93        $page['post_content'] = '[newsletter]';
94        $page['post_status'] = 'publish';
95        $page['post_type'] = 'page';
96        $page['comment_status'] = 'closed';
97        $page['ping_status'] = 'closed';
98        $page['post_category'] = [1];
99
100        $current_language = $this->get_current_language();
101        $this->switch_language('');
102        // Insert the post into the database
103        $page_id = wp_insert_post($page);
104        $this->switch_language($language);
105
106        $controls->data['page'] = $page_id;
107        $this->save_options($controls->data);
108
109        $controls->messages = 'A new page has been created';
110    }
111}
112
113if (!$language) {
114    $return_path = $controls->data['return_path'] ?? '';
115
116    if (!empty($return_path)) {
117        list($return_path_local, $return_path_domain) = explode('@', $return_path);
118
119        $sender = $this->get_option('sender_email');
120        list($sender_local, $sender_domain) = explode('@', $sender);
121
122        if ($sender_domain != $return_path_domain) {
123            $controls->warnings[] = __('Your Return Path domain is different from your Sender domain. Providers may require them to match.', 'newsletter');
124        }
125    }
126}
127
128$license_data = License::get_data();
129
130if (is_wp_error($license_data)) {
131    $controls->errors .= esc_html($license_data->get_error_message());
132}
133
134$mailer = Newsletter::instance()->get_mailer();
135$mailer_speed = $mailer->get_speed();
136
137// Public page type check
138$front_page_id = (int) get_option('page_on_front');
139$blog_page_id = (int) get_option('page_for_posts');
140
141if (!empty($controls->data['page'])) {
142    if ($controls->data['page'] == $front_page_id) {
143        $controls->warnings[] = 'The blog front page has been set as the Newsletter public page, that is not recommended. Please create a dedicated page.';
144    } elseif ($controls->data['page'] == $blog_page_id) {
145        $controls->warnings[] = 'The blog post list page has been set as the Newsletter public page, that is not recommended. Please create a dedicated page.';
146    }
147}
148?>
149
150<?php include NEWSLETTER_INCLUDES_DIR . '/codemirror.php'; ?>
151<style>
152    .CodeMirror {
153        border: 1px solid #ddd;
154    }
155</style>
156
157<script>
158    jQuery(function () {
159        var editor = CodeMirror.fromTextArea(document.getElementById("options-css"), {
160            lineNumbers: true,
161            mode: 'css',
162            extraKeys: {"Ctrl-Space": "autocomplete"}
163        });
164    });
165</script>
166
167<div class="wrap" id="tnp-wrap">
168
169    <?php include NEWSLETTER_ADMIN_HEADER; ?>
170
171    <div id="tnp-heading">
172        <?php $controls->title_help('https://www.thenewsletterplugin.com/plugins/newsletter/newsletter-configuration') ?>
173
174<!--        <h2><?php esc_html_e('Settings', 'newsletter'); ?></h2>-->
175        <?php include __DIR__ . '/nav.php' ?>
176
177    </div>
178    <div id="tnp-body" class="tnp-main-main">
179
180        <?php $controls->show() ?>
181
182        <?php if (!empty($controls->data['contract_key']) && !class_exists('NewsletterExtensions')) { ?>
183            <div class="tnp-notice">
184                Please, install the <a href="?page=newsletter_main_extensions">Addons Manager</a> to access all professional addons and features.
185            </div>
186        <?php } ?>
187
188
189        <form method="post" action="">
190            <?php $controls->init(); ?>
191
192            <div id="tabs">
193
194                <ul>
195                    <li><a href="#tabs-basic"><?php esc_html_e('Settings', 'newsletter') ?></a></li>
196                    <li><a href="#tabs-speed"><?php esc_html_e('Sending', 'newsletter') ?></a></li>
197                    <li class="tnp-tabs-advanced"><a href="#tabs-advanced"><?php esc_html_e('Advanced', 'newsletter') ?></a></li>
198                    <?php if (NEWSLETTER_DEBUG) { ?>
199                        <li><a href="#tabs-debug">Debug</a></li>
200                    <?php } ?>
201                </ul>
202
203                <div id="tabs-basic">
204                    <?php $controls->language_notice(); ?>
205                    <table class="form-table">
206                        <?php if (!$language) { ?>
207                            <tr>
208                                <th>
209                                    <?php esc_html_e('Sender email', 'newsletter') ?>
210                                    <?php $controls->field_help('https://www.thenewsletterplugin.com/documentation/installation/newsletter-configuration/#sender') ?>
211                                </th>
212                                <td>
213                                    <?php $controls->text_email('sender_email', 40); ?>
214                                    <span class="description">
215                                        Emails delivered with a <a href="https://www.thenewsletterplugin.com/documentation/installation/newsletter-configuration/#sender" target="_blank">different address</a>?
216                                    </span>
217                                </td>
218                            </tr>
219                            <tr>
220                                <th>
221                                    <?php esc_html_e('Sender name', 'newsletter') ?>
222                                </th>
223                                <td>
224                                    <?php $controls->text('sender_name', 40); ?>
225                                </td>
226                            </tr>
227
228                            <tr>
229                                <th><?php esc_html_e('License key', 'newsletter') ?></th>
230                                <td>
231
232                                    <?php if (defined('NEWSLETTER_LICENSE_KEY')) { ?>
233                                        <?php esc_html_e('A license key is set', 'newsletter') ?>
234                                    <?php } else { ?>
235                                        <?php $controls->text('contract_key', 40); ?>
236                                        <span class="description">
237                                            <?php printf(__('Find it in <a href="%s" target="_blank">your account</a> page', 'newsletter'), "https://www.thenewsletterplugin.com/account") ?>
238                                        </span>
239                                    <?php } ?>
240                                </td>
241                            </tr>
242
243
244                            <tr>
245                                <th>
246                                    <?php esc_html_e('Return path', 'newsletter') ?>
247                                    <?php $controls->field_help('/installation/newsletter-configuration/#return-path') ?>
248                                </th>
249                                <td>
250                                    <?php $controls->text_email('return_path', 40); ?>
251                                    <span class="description">Some providers ignore it or <strong>block all emails</strong> if set</span>
252                                </td>
253                            </tr>
254                            <tr>
255                                <th>
256                                    <?php esc_html_e('Reply to', 'newsletter') ?>
257                                    <?php $controls->field_help('/installation/newsletter-configuration/#reply-to') ?>
258                                </th>
259                                <td>
260                                    <?php $controls->text_email('reply_to', 40); ?>
261
262                                </td>
263                            </tr>
264                        <?php } ?>
265                        <tr>
266                            <th>
267                                <?php esc_html_e('Public page', 'newsletter') ?>
268                                <?php $controls->field_help('/installation/newsletter-configuration/#dedicated-page') ?>
269                            </th>
270                            <td>
271
272                                <?php $controls->page('page', NEWSLETTER_DEBUG ? 'None (for debug)' : null, '', true); ?>
273
274                                <?php
275                                if (!$this->is_multilanguage() && empty($controls->data['page'])) {
276                                    $controls->button('create', __('Create the page', 'newsletter'));
277                                }
278                                ?>
279
280                                <p class="description">
281                                    <?php esc_html_e('The page content must be only the shortcode [newsletter]', 'newsletter') ?>.
282                                    <br>
283                                    <?php esc_html_e('Do not choose the "front page" or "post list page"', 'newsletter') ?>.
284                                </p>
285
286                                <?php if ($this->is_multilanguage()) { ?>
287                                    <p class="description">
288                                        <?php esc_html_e('To be set for every language', 'newsletter'); ?>
289                                    </p>
290                                <?php } ?>
291
292                            </td>
293                        </tr>
294
295                    </table>
296                </div>
297
298                <div id="tabs-speed">
299                    <?php $controls->language_notice(); ?>
300                    <?php if (!$language) { ?>
301                        <table class="form-table">
302                            <tr>
303                                <th>
304                                    <?php esc_html_e('Max emails per hour', 'newsletter') ?>
305                                    <?php $controls->field_help('/installation/newsletter-configuration/#speed') ?>
306                                </th>
307                                <td>
308                                    <?php $controls->text('scheduler_max', 5); ?> (min. 12)
309                                    <p class="description">
310                                        <a href="?page=newsletter_system_delivery#tnp-speed">See the collected statistics</a>
311
312                                        <?php $batch_max = floor($controls->data['scheduler_max'] / 12); ?>
313                                        <?php if ($batch_max < 5) { ?>
314                                            <br>
315                                            The delivery engines runs every 5 minutes (12 runs per hour). With that setting you'll have:
316                                            <br>
317                                            <?php echo $batch_max; ?> max emails every 5 minutes,
318                                            <?php echo $batch_max * 12; ?> max emails per hour,
319                                            <?php echo $batch_max * 12 * 24; ?> max emails per day
320                                        <?php } ?>
321
322                                        <?php if ($mailer_speed && $mailer_speed != $controls->data['scheduler_max']) { ?>
323                                            <br><br>
324                                            <strong>The maximum speed is overridden by the delivery addon "<?php echo esc_html($mailer->get_description()); ?>"</strong>
325                                        <?php } ?>
326                                    </p>
327
328
329                                </td>
330                            </tr>
331
332                            <tr>
333                                <th>
334                                    <?php esc_html_e('Max emails per second', 'newsletter') ?>
335                                    <?php $controls->field_help('/installation/newsletter-configuration/#speed') ?>
336                                </th>
337                                <td>
338                                    <?php if (defined('NEWSLETTER_SEND_DELAY')) { ?>
339                                        Delay set to <?php echo esc_html(NEWSLETTER_SEND_DELAY); ?> in <code>wp-config.php</code>
340                                    <?php } else { ?>
341                                        <?php $controls->text('max_per_second', 5); ?>
342                                        <span class="description"><?php esc_html_e('0 for unlimited', 'newsletter') ?></span>
343                                    <?php } ?>
344                                </td>
345                            </tr>
346
347                            <tr valign="top">
348                                <th>Sending time window</th>
349                                <td>
350                                    <?php $controls->enabled('schedule'); ?>
351
352                                    <span data-tnpshow="schedule=1">
353                                        from <?php $controls->hours('schedule_start'); ?> to <?php $controls->hours('schedule_end'); ?>
354                                    </span>
355
356                                    <p class="description">
357                                        Out of this time window the newsletter sending is suspended. Does not apply to email series.
358                                    </p>
359                                </td>
360                            </tr>
361
362                        </table>
363
364                        <?php do_action('newsletter_panel_main_speed', $controls) ?>
365                    <?php } ?>
366                </div>
367
368
369                <div id="tabs-advanced">
370                    <?php $controls->language_notice(); ?>
371                    <?php if (!$language) { ?>
372                        <table class="form-table">
373                            <tr>
374                                <th><?php esc_html_e('Allowed roles', 'newsletter') ?></th>
375                                <td>
376                                    <?php
377                                    $wp_roles = get_editable_roles();
378                                    $roles = array();
379                                    foreach ($wp_roles as $key => $wp_role) {
380                                        if ($key == 'administrator')
381                                            continue;
382                                        if ($key == 'subscriber')
383                                            continue;
384                                        $roles[$key] = $wp_role['name'];
385                                    }
386                                    $controls->checkboxes('roles', $roles);
387                                    ?>
388
389                                </td>
390                            </tr>
391
392                            <tr>
393                                <th>
394                                    <?php $controls->label(__('Tracking default', 'newsletter'), '/installation/newsletter-configuration/#tracking') ?>
395                                </th>
396                                <td>
397                                    <?php $controls->enabled('track'); ?>
398                                    <span class="description">
399                                        Applied only to new newsletters.
400                                    </span>
401                                </td>
402                            </tr>
403
404                            <tr>
405                                <th>
406                                    <?php $controls->label(__('Log level', 'newsletter'), '/newsletter-configuration#log') ?>
407                                </th>
408                                <td>
409                                    <?php $controls->log_level('log_level'); ?>
410                                </td>
411                            </tr>
412
413                            <tr>
414                                <th><?php esc_html_e('Standard styles', 'newsletter') ?></th>
415                                <td>
416                                    <?php $controls->disabled('css_disabled'); ?>
417                                </td>
418                            </tr>
419
420                            <tr>
421                                <th><?php esc_html_e('Custom styles', 'newsletter') ?></th>
422                                <td>
423                                    <p class="description">
424                                        Styles added to the site for the subscription and profile editing forms.
425                                    </p>
426                                    <?php if (apply_filters('newsletter_enqueue_style', true) === false) { ?>
427                                        <p><strong>Warning: Newsletter styles and custom styles are disable by your theme or a plugin.</strong></p>
428                                    <?php } ?>
429                                    <?php $controls->textarea('css'); ?>
430
431                                </td>
432                            </tr>
433
434                            <tr>
435                                <th><?php esc_html_e('IP addresses', 'newsletter') ?></th>
436                                <td>
437                                    <?php $controls->select('ip', array('' => __('Store', 'newsletter'), 'anonymize' => __('Anonymize', 'newsletter'), 'skip' => __('Do not store', 'newsletter'))); ?>
438                                </td>
439                            </tr>
440
441                            <tr>
442                                <th>
443                                    <?php $controls->label(__('Debug mode', 'newsletter'), '/newsletter-configuration#debug') ?>
444                                </th>
445                                <td>
446                                    <?php $controls->yesno('debug', 40); ?>
447                                    <span class="description">
448                                        If PHP errors are intercepted they are logged <a href="?page=newsletter_system_logs">here</a>.
449                                    </span>
450                                </td>
451                            </tr>
452
453                            <tr>
454                                <th>
455                                    <?php $controls->label(__('Tracking and action links', 'newsletter'), '') ?>
456                                </th>
457                                <td>
458                                    <?php $controls->select('links', ['' => 'Standard', 'ajax' => 'Alternative']); ?>
459                                    <span class="description">
460                                        Select "alternative" if confirmation/unsubscription/tracking links seems to not work. Resend a test nessletter
461                                        to check the effect, old newsletters are not affacted.
462                                    </span>
463                                </td>
464                            </tr>
465
466                            <tr>
467                                <th>
468                                    <?php $controls->label(__('Email encoding', 'newsletter'), '/newsletter-configuration#encoding') ?>
469                                </th>
470                                <td>
471                                    <?php $controls->select('content_transfer_encoding', array('' => 'Default', '8bit' => '8 bit', 'base64' => 'Base 64', 'binary' => 'Binary', 'quoted-printable' => 'Quoted printable', '7bit' => '7 bit')); ?>
472                                </td>
473                            </tr>
474
475
476                        </table>
477                    <?php } ?>
478                </div>
479
480                <?php if (NEWSLETTER_DEBUG) { ?>
481                    <div id="tabs-debug">
482                        <pre><?php echo esc_html(wp_json_encode($this->get_db_options('', $language), JSON_PRETTY_PRINT)) ?></pre>
483                    </div>
484                <?php } ?>
485
486
487            </div> <!-- tabs -->
488
489            <div class="tnp-buttons">
490                <?php $controls->button_save(); ?>
491            </div>
492
493        </form>
494
495    </div>
496
497    <?php include NEWSLETTER_ADMIN_FOOTER; ?>
498
499</div>
500
Note: See TracBrowser for help on using the repository browser.