![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartinsight.co/wp-content/plugins/colibri-page-builder/src/Notify/ |
<?php namespace ColibriWP\PageBuilder\Notify; use DateTime; class Notification { const NOTIFICATION_ACTION_PREFIX = "cp_notification_notice_"; private $name; private $start = '*'; private $end = '*'; private $after = null; private $dismissible = true; private $type = "info"; private $active_callback = null; private $handle = null; private $priority = 0; private $data; public function __construct($data) { $this->data = $data; foreach ($data as $key => $value) { if (property_exists($this, $key)) { if ($key === 'after') { if (intval($value)) { $this->$key = intval($value); } } else { $this->$key = $value; } } } if ($this->canShow()) { $this->addNotificationView(); } } // php 5.3 compatibility public function __get($name) { if (property_exists($this, $name)) { return $this->$name; } else { //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped throw new \Exception("Property {$name} does not exists in class Notification", 1); } } public function addNotificationView() { $self = $this; add_action('admin_notices', function () use ($self) { ?> <div data-cp-notification-name="<?php echo esc_attr($self->name); ?>" class="cp-notification notice notice-<?php echo esc_attr($self->type); ?> <?php echo($self->dismissible ? 'is-dismissible' : '') ?>"> <?php if ($self->handle) { call_user_func($self->handle, $self->data); } else { do_action(\Mesmerize\Notify\Notification::NOTIFICATION_ACTION_PREFIX . $self->name, $self->data); } ?> <?php if ($self->dismissible): ?> <script type="text/javascript"> jQuery('[data-cp-notification-name="<?php echo esc_attr($self->name) ?>"]').on('click', '.notice-dismiss', function () { var data = { 'action': 'cp_dismiss_notification', 'notification': <?php echo wp_json_encode($self->name); ?>, _wpnonce: '<?php echo wp_create_nonce('cp_dismiss_notification_nonce'); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped?>' }; jQuery.post(ajaxurl, data).done(function (response) { }); }) </script> <?php endif; ?> </div> <?php }, 0); } public function canShow() { $canShow = ( $this->isActive() && ! $this->isDismissed() && $this->inTimeBoundaries() ); return $canShow; } public function isActive() { if ( ! $this->active_callback) { return true; } else { return call_user_func($this->active_callback); } } public function inTimeBoundaries() { $time = new DateTime("now"); if ($this->after) { $installTime = intval(NotificationsManager::initializationTS()); $showAfter = strtotime('+' . $this->after . ' days', $installTime); if ($showAfter <= $time->getTimeStamp()) { return true; } } else { if ($this->start === "*") { return true; } else { $start = \DateTime::createFromFormat('d-m-Y', $this->start); if ($start && $start <= $time) { if ($this->end === "*") { return true; } else { $end = \DateTime::createFromFormat('d-m-Y', $this->end); if ($end && $time <= $end) { return true; } } } } } return false; } public function isDismissed() { if ( ! $this->dismissible) { return false; } $notifications = get_option(NotificationsManager::DISMISSED_NOTIFICATIONS_OPTION, array()); return in_array($this->name, $notifications); } }