PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / trunk
JetBackup – Backup, Restore & Migrate vtrunk
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / Notification / Notification.php
backup / src / JetBackup / Notification Last commit date
.htaccess 1 year ago Email.php 1 year ago Notification.php 1 year ago index.html 1 year ago web.config 1 year ago
Notification.php
82 lines
1 <?php
2
3 namespace JetBackup\Notification;
4
5 use JetBackup\Data\ArrayData;
6 use JetBackup\Exception\NotificationException;
7 use JetBackup\Factory;
8 use JetBackup\JetBackup;
9 use JetBackup\Wordpress\Wordpress;
10
11 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
12
13 class Notification extends ArrayData {
14
15 const TEMPLATES_PATH = JetBackup::TEMPLATES_PATH . JetBackup::SEP . 'emails';
16
17 private array $_vars=[];
18
19 public static function message():Notification {
20 return (new Notification());
21 }
22
23 public function addParam($key, $value):Notification { $this->set($key, $value); return $this; }
24
25 /**
26 * @param $subject
27 * @param $message_name
28 *
29 * @return void
30 * @throws NotificationException
31 */
32 public function send($subject, $message_name) {
33
34 $recipient = Factory::getSettingsNotifications()->getAlternateEmail() ?: Wordpress::getBlogInfo('admin_email');
35
36 $message_file = self::TEMPLATES_PATH . JetBackup::SEP . $message_name . '.tpl';
37 if(!file_exists($message_file)) throw new NotificationException('Message file does not exist');
38
39 $main_file = self::TEMPLATES_PATH . JetBackup::SEP . 'main.tpl';
40 if(!file_exists($main_file)) throw new NotificationException('Main file does not exist');
41
42 $message = $this->_parse(file_get_contents($main_file), [
43 'content' => $this->_parse(file_get_contents($message_file), $this->getData()),
44 'year' => date('Y')
45 ]);
46
47 Email::send($recipient, $subject, $message);
48 }
49
50 private function _parse($content, $vars) {
51
52 $content = preg_replace("#{else}#", "<?php else: ?>", $content);
53 $content = preg_replace( "#{/if}#", "<?php endif; ?>", $content);
54 $content = preg_replace( "#{/foreach}#", "<?php endforeach; ?>", $content);
55
56 $content = preg_replace_callback("#{(if|elseif|foreach)\s+([^}]+)}#", function($matches) {
57 $condition = preg_replace_callback("#\\$([a-zA-Z0-9_]+)#", function($matches) {
58 return $this->_buildVar($matches[1]);
59 }, $matches[2]);
60
61 return "<?php $matches[1]($condition): ?>";
62
63 }, $content);
64
65 $content = preg_replace_callback("#{\\$([^}]+)}#", function($matches) {
66 return "<?php echo " . $this->_buildVar($matches[1]) . "; ?>";
67 }, $content);
68
69 $this->_vars = $vars;
70
71 ob_start();
72 eval('?>' . $content);
73 return ob_get_clean();
74 }
75
76 private function _buildVar($var) {
77 $parts = explode(".", $var);
78 $output = "\$this->_vars";
79 foreach ($parts as $part) $output .= "['$part']";
80 return $output;
81 }
82 }