PluginProbe
Email Log / trunk
Email Log vtrunk
2.63 2.4.8 2.4.9 2.6 2.61 2.62 trunk 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.8.1 0.9 0.9.1 0.9.2 1.1 1.5 1.5.1 1.5.2 1.5.3 1.5.4 All 61 releases
email-log / include / Core / EmailLog.php

EmailLog.php in Email Log trunk, at include/Core/EmailLog.php

665 lines 18.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace EmailLog\Core;
4
5 use EmailLog\Core\DB\TableManager;
6 use EmailLog\EmailLogAutoloader;
7
8 /**
9 * The main plugin class.
10 *
11 * @since Genesis
12 */
13 class EmailLog
14 {
15 /**
16 * Flag to track if the plugin is loaded.
17 *
18 * @since 2.0
19 * @access private
20 *
21 * @var bool
22 */
23 private $loaded = false;
24
25 /**
26 * Flag to override plugin API.
27 *
28 * @since 2.4.5
29 * @access private
30 *
31 * @var bool
32 */
33 private $plugins_api_overridden = false;
34
35 /**
36 * Plugin file path.
37 *
38 * @since 2.0
39 * @access private
40 *
41 * @var string
42 */
43 private $plugin_file;
44
45 /**
46 * Filesystem directory path where translations are stored.
47 *
48 * @since 2.0
49 *
50 * @var string
51 */
52 public $translations_path;
53
54 /**
55 * Auto loader.
56 *
57 * @var \EmailLog\EmailLogAutoloader
58 */
59 public $loader;
60
61 /**
62 * Database Table Manager.
63 *
64 * @since 2.0
65 *
66 * @var \EmailLog\Core\DB\TableManager
67 */
68 public $table_manager;
69
70 /**
71 * List of loadies.
72 *
73 * @var Loadie[]
74 */
75 private $loadies = array();
76 private $loadies_init = array();
77 /**
78 * Initialize the plugin.
79 *
80 * @param string $file Plugin file.
81 * @param EmailLogAutoloader $loader EmailLog Autoloader.
82 * @param TableManager $table_manager Table Manager.
83 */
84 public function __construct($file, $loader, $table_manager)
85 {
86 $this->plugin_file = $file;
87 $this->loader = $loader;
88 $this->table_manager = $table_manager;
89
90 $this->add_loadie($table_manager);
91
92 $this->translations_path = dirname(plugin_basename($this->plugin_file)) . '/languages/';
93 }
94
95 /**
96 * Add an Email Log Loadie.
97 * The `load()` method of the Loadies will be called when Email Log is loaded.
98 *
99 * @param \EmailLog\Core\Loadie $loadie Loadie to be loaded.
100 *
101 * @return bool False if Email Log is already loaded or if $loadie is not of `Loadie` type. True otherwise.
102 */
103 public function add_loadie($loadie, $loadie_init = false)
104 {
105 if ($this->loaded) {
106 return false;
107 }
108
109 if (! $loadie instanceof Loadie) {
110 return false;
111 }
112
113 if ($loadie_init === true) {
114 $this->loadies_init[] = $loadie;
115 } else {
116 $this->loadies[] = $loadie;
117 }
118
119 return true;
120 }
121
122 /**
123 * Load the plugin.
124 */
125 public function load()
126 {
127 if ($this->loaded) {
128 return;
129 }
130
131 load_plugin_textdomain('email-log', false, $this->translations_path);
132
133 $this->table_manager->load();
134
135 foreach ($this->loadies as $loadie) {
136 $loadie->load();
137 }
138
139 foreach ($this->loadies_init as $loadie_init) {
140 add_action('init', array($loadie_init, 'load'));
141 }
142
143 $this->loaded = true;
144
145 $options = get_option('email-log-core');
146
147 /**
148 * Email Log plugin loaded.
149 *
150 * @since 2.0
151 */
152 do_action('el_loaded');
153
154 add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
155 add_action('admin_action_emaillog_install_wp301', array($this, 'install_wp301'));
156 }
157
158 function admin_enqueue_scripts()
159 {
160 $js_localize = array(
161 'undocumented_error' => __('An undocumented error has occurred. Please refresh the page and try again.', 'email-log'),
162 'documented_error' => __('An error has occurred.', 'email-log'),
163 'plugin_name' => 'Email Log PRO',
164 'url' => EMAIL_LOG_URL,
165 'icon_url' => EMAIL_LOG_URI . 'assets/img/loader-icon.png',
166 'settings_url' => admin_url('admin.php?page=email-log'),
167 'is_plugin_page' => $this->is_plugin_page(),
168 'home_url' => get_home_url(),
169 'loading_icon_url' => EMAIL_LOG_URI . 'assets/img/loading-icon.png',
170 'email_test_url' => EMAIL_LOG_URI . 'assets/img/emaillog-test.gif',
171 'el_nonce' => wp_create_nonce('el-email-test'),
172 'wp301_install_url' => add_query_arg(array('action' => 'emaillog_install_wp301', '_wpnonce' => wp_create_nonce('install_wp301'), 'rnd' => wp_rand()), admin_url('admin.php')),
173 );
174
175 if ($this->is_plugin_page()) {
176 wp_enqueue_style('wp-jquery-ui-dialog');
177
178 wp_enqueue_script('jquery-ui-position');
179 wp_enqueue_script("jquery-effects-core");
180 wp_enqueue_script("jquery-effects-blind");
181 wp_enqueue_script('jquery-ui-accordion');
182 wp_enqueue_script('jquery-ui-dialog');
183
184 wp_enqueue_script('email-log', EMAIL_LOG_URL . 'assets/js/email-log-admin.js', array('jquery'), $this->get_version(), true);
185 wp_enqueue_style('email-log', EMAIL_LOG_URL . 'assets/css/email-log-admin.css', array(), $this->get_version());
186 wp_localize_script('email-log', 'wp_email_log', $js_localize);
187 }
188 }
189
190 // auto download / install / activate WP 301 Redirects plugin
191 public function install_wp301()
192 {
193 check_ajax_referer('install_wp301');
194
195 if (false === current_user_can('manage_options')) {
196 wp_die('Sorry, you have to be an admin to run this action.');
197 }
198
199 $plugin_slug = 'eps-301-redirects/eps-301-redirects.php';
200 $plugin_zip = 'https://downloads.wordpress.org/plugin/eps-301-redirects.latest-stable.zip';
201
202 @include_once ABSPATH . 'wp-admin/includes/plugin.php';
203 @include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
204 @include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
205 @include_once ABSPATH . 'wp-admin/includes/file.php';
206 @include_once ABSPATH . 'wp-admin/includes/misc.php';
207 echo '<style>
208 body{
209 font-family: sans-serif;
210 font-size: 14px;
211 line-height: 1.5;
212 color: #444;
213 }
214 </style>';
215
216 echo '<div style="margin: 20px; color:#444;">';
217 echo 'If things are not done in a minute <a target="_parent" href="' . esc_url(admin_url('plugin-install.php?s=301%20redirects%20webfactory&tab=search&type=term')) . '">install the plugin manually via Plugins page</a><br><br>';
218 echo 'Starting ...<br><br>';
219
220 wp_cache_flush();
221 $upgrader = new \Plugin_Upgrader();
222 echo 'Check if WP 301 Redirects is already installed ... <br />';
223 if ($this->is_plugin_installed($plugin_slug)) {
224 echo 'WP 301 Redirects is already installed! <br /><br />Making sure it\'s the latest version.<br />';
225 $upgrader->upgrade($plugin_slug);
226 $installed = true;
227 } else {
228 echo 'Installing WP 301 Redirects.<br />';
229 $installed = $upgrader->install($plugin_zip);
230 }
231 wp_cache_flush();
232
233 if (!is_wp_error($installed) && $installed) {
234 echo 'Activating WP 301 Redirects.<br />';
235 $activate = activate_plugin($plugin_slug);
236
237 if (is_null($activate)) {
238 echo 'WP 301 Redirects Activated.<br />';
239
240 echo '<script>setTimeout(function() { top.location = "' . esc_url(admin_url('options-general.php?page=eps_redirects')) . '"; }, 1000);</script>';
241 echo '<br>If you are not redirected in a few seconds - <a href="' . esc_url(admin_url('options-general.php?page=eps_redirects')) . '" target="_parent">click here</a>.';
242 }
243 } else {
244 echo 'Could not install WP 301 Redirects. You\'ll have to <a target="_parent" href="' . esc_url(admin_url('plugin-install.php?s=301%20redirects%20webfactory&tab=search&type=term')) . '">download and install manually</a>.';
245 }
246
247 echo '</div>';
248 } // install_wp301
249
250 /**
251 * Check if given plugin is installed
252 *
253 * @param [string] $slug Plugin slug
254 * @return boolean
255 */
256 static function is_plugin_installed($slug)
257 {
258 if (!function_exists('get_plugins')) {
259 require_once ABSPATH . 'wp-admin/includes/plugin.php';
260 }
261 $all_plugins = get_plugins();
262
263 if (!empty($all_plugins[$slug])) {
264 return true;
265 } else {
266 return false;
267 }
268 } // is_plugin_installed
269
270 public function is_plugin_page()
271 {
272 if (!function_exists('get_current_screen')) {
273 return false;
274 }
275
276 $current_screen = get_current_screen();
277 if (!empty($current_screen) && in_array($current_screen->id, array('toplevel_page_email-log', 'toplevel_page_email-log-license', 'email-log_page_email-log-settings', 'email-log_page_email-log-license', 'email-log_page_email-log-monitor'))) {
278 return true;
279 } else {
280 return false;
281 }
282 } // is_plugin_page
283
284 /**
285 * Plugin API has been overridden.
286 *
287 * @since 2.4.5
288 */
289 public function plugin_api_overridden()
290 {
291 $this->plugins_api_overridden = true;
292 }
293
294 /**
295 * Has the plugin API have been overridden?
296 *
297 * @since 2.4.5
298 *
299 * @return bool True if overridden, False otherwise.
300 */
301 public function is_plugin_api_overridden()
302 {
303 return $this->plugins_api_overridden;
304 }
305
306 /**
307 * Return Email Log version.
308 *
309 * @return string Email Log Version.
310 */
311 public function get_version()
312 {
313 return email_log_plugin_version();
314 }
315
316 /**
317 * Return the Email Log plugin directory path.
318 *
319 * @return string Plugin directory path.
320 */
321 public function get_plugin_path()
322 {
323 return plugin_dir_path($this->plugin_file);
324 }
325
326 /**
327 * Return the Email Log plugin file.
328 *
329 * @since 2.0.0
330 *
331 * @return string Plugin directory path.
332 */
333 public function get_plugin_file()
334 {
335 return $this->plugin_file;
336 }
337
338 public static function wp_kses_wf($html)
339 {
340 add_filter('safe_style_css', function ($styles) {
341 $styles_wf = array(
342 'text-align',
343 'margin',
344 'color',
345 'float',
346 'border',
347 'background',
348 'background-color',
349 'border-bottom',
350 'border-bottom-color',
351 'border-bottom-style',
352 'border-bottom-width',
353 'border-collapse',
354 'border-color',
355 'border-left',
356 'border-left-color',
357 'border-left-style',
358 'border-left-width',
359 'border-right',
360 'border-right-color',
361 'border-right-style',
362 'border-right-width',
363 'border-spacing',
364 'border-style',
365 'border-top',
366 'border-top-color',
367 'border-top-style',
368 'border-top-width',
369 'border-width',
370 'caption-side',
371 'clear',
372 'cursor',
373 'direction',
374 'font',
375 'font-family',
376 'font-size',
377 'font-style',
378 'font-variant',
379 'font-weight',
380 'height',
381 'letter-spacing',
382 'line-height',
383 'margin-bottom',
384 'margin-left',
385 'margin-right',
386 'margin-top',
387 'overflow',
388 'padding',
389 'padding-bottom',
390 'padding-left',
391 'padding-right',
392 'padding-top',
393 'text-decoration',
394 'text-indent',
395 'vertical-align',
396 'width',
397 'display',
398 );
399
400 foreach ($styles_wf as $style_wf) {
401 $styles[] = $style_wf;
402 }
403 return $styles;
404 });
405
406 $allowed_tags = wp_kses_allowed_html('post');
407 $allowed_tags['input'] = array(
408 'type' => true,
409 'style' => true,
410 'class' => true,
411 'id' => true,
412 'checked' => true,
413 'disabled' => true,
414 'name' => true,
415 'size' => true,
416 'placeholder' => true,
417 'value' => true,
418 'data-*' => true,
419 'size' => true,
420 'disabled' => true
421 );
422
423 $allowed_tags['textarea'] = array(
424 'type' => true,
425 'style' => true,
426 'class' => true,
427 'id' => true,
428 'checked' => true,
429 'disabled' => true,
430 'name' => true,
431 'size' => true,
432 'placeholder' => true,
433 'value' => true,
434 'data-*' => true,
435 'cols' => true,
436 'rows' => true,
437 'disabled' => true,
438 'autocomplete' => true
439 );
440
441 $allowed_tags['select'] = array(
442 'type' => true,
443 'style' => true,
444 'class' => true,
445 'id' => true,
446 'checked' => true,
447 'disabled' => true,
448 'name' => true,
449 'size' => true,
450 'placeholder' => true,
451 'value' => true,
452 'data-*' => true,
453 'multiple' => true,
454 'disabled' => true
455 );
456
457 $allowed_tags['option'] = array(
458 'type' => true,
459 'style' => true,
460 'class' => true,
461 'id' => true,
462 'checked' => true,
463 'disabled' => true,
464 'name' => true,
465 'size' => true,
466 'placeholder' => true,
467 'value' => true,
468 'selected' => true,
469 'data-*' => true
470 );
471 $allowed_tags['optgroup'] = array(
472 'type' => true,
473 'style' => true,
474 'class' => true,
475 'id' => true,
476 'checked' => true,
477 'disabled' => true,
478 'name' => true,
479 'size' => true,
480 'placeholder' => true,
481 'value' => true,
482 'selected' => true,
483 'data-*' => true,
484 'label' => true
485 );
486
487 $allowed_tags['a'] = array(
488 'href' => true,
489 'data-*' => true,
490 'class' => true,
491 'style' => true,
492 'id' => true,
493 'target' => true,
494 'data-*' => true,
495 'role' => true,
496 'aria-controls' => true,
497 'aria-selected' => true,
498 'disabled' => true
499 );
500
501 $allowed_tags['div'] = array(
502 'style' => true,
503 'class' => true,
504 'id' => true,
505 'data-*' => true,
506 'role' => true,
507 'aria-labelledby' => true,
508 'value' => true,
509 'aria-modal' => true,
510 'tabindex' => true
511 );
512
513 $allowed_tags['li'] = array(
514 'style' => true,
515 'class' => true,
516 'id' => true,
517 'data-*' => true,
518 'role' => true,
519 'aria-labelledby' => true,
520 'value' => true,
521 'aria-modal' => true,
522 'tabindex' => true
523 );
524
525 $allowed_tags['span'] = array(
526 'style' => true,
527 'class' => true,
528 'id' => true,
529 'data-*' => true,
530 'aria-hidden' => true
531 );
532
533 $allowed_tags['style'] = array(
534 'class' => true,
535 'id' => true,
536 'type' => true,
537 'style' => true
538 );
539
540 $allowed_tags['fieldset'] = array(
541 'class' => true,
542 'id' => true,
543 'type' => true,
544 'style' => true
545 );
546
547 $allowed_tags['link'] = array(
548 'class' => true,
549 'id' => true,
550 'type' => true,
551 'rel' => true,
552 'href' => true,
553 'media' => true,
554 'style' => true
555 );
556
557 $allowed_tags['form'] = array(
558 'style' => true,
559 'class' => true,
560 'id' => true,
561 'method' => true,
562 'action' => true,
563 'data-*' => true,
564 'style' => true
565 );
566
567 $allowed_tags['script'] = array(
568 'class' => true,
569 'id' => true,
570 'type' => true,
571 'src' => true,
572 'style' => true
573 );
574
575 $allowed_tags['table'] = array(
576 'class' => true,
577 'id' => true,
578 'type' => true,
579 'cellpadding' => true,
580 'cellspacing' => true,
581 'border' => true,
582 'style' => true
583 );
584
585 $allowed_tags['canvas'] = array(
586 'class' => true,
587 'id' => true,
588 'style' => true
589 );
590
591 if(empty($html)){
592 echo '';
593 } else {
594 echo wp_kses($html, $allowed_tags);
595 }
596
597 add_filter('safe_style_css', function ($styles) {
598 $styles_wf = array(
599 'text-align',
600 'margin',
601 'color',
602 'float',
603 'border',
604 'background',
605 'background-color',
606 'border-bottom',
607 'border-bottom-color',
608 'border-bottom-style',
609 'border-bottom-width',
610 'border-collapse',
611 'border-color',
612 'border-left',
613 'border-left-color',
614 'border-left-style',
615 'border-left-width',
616 'border-right',
617 'border-right-color',
618 'border-right-style',
619 'border-right-width',
620 'border-spacing',
621 'border-style',
622 'border-top',
623 'border-top-color',
624 'border-top-style',
625 'border-top-width',
626 'border-width',
627 'caption-side',
628 'clear',
629 'cursor',
630 'direction',
631 'font',
632 'font-family',
633 'font-size',
634 'font-style',
635 'font-variant',
636 'font-weight',
637 'height',
638 'letter-spacing',
639 'line-height',
640 'margin-bottom',
641 'margin-left',
642 'margin-right',
643 'margin-top',
644 'overflow',
645 'padding',
646 'padding-bottom',
647 'padding-left',
648 'padding-right',
649 'padding-top',
650 'text-decoration',
651 'text-indent',
652 'vertical-align',
653 'width'
654 );
655
656 foreach ($styles_wf as $style_wf) {
657 if (($key = array_search($style_wf, $styles)) !== false) {
658 unset($styles[$key]);
659 }
660 }
661 return $styles;
662 });
663 }
664 }
665