HEX
Server: Apache
System: Linux web15f74.uni5.net 5.4.282-1.el8.elrepo.x86_64 #1 SMP Mon Aug 19 18:33:22 EDT 2024 x86_64
User: lucendi (859622)
PHP: 7.4.33
Disabled: apache_child_terminate,c99_buff_prepare,c99_sess_put,dl,exec,leak,link,myshellexec,openlog,passthru,pclose,pcntl_exec,php_check_syntax,php_strip_whitespace,popen,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,symlink,system,socket_listen,socket_create_listen,putenv
Upload Files
File: /home/lucendi/www/wp-content/plugins/mesmerize-companion/src/Notify/Notification.php
<?php


namespace Mesmerize\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 mesmerize-notice 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(<?php echo wp_json_encode( '[data-cp-notification-name=' . $self->name . ']' ); ?>).on('click', '.notice-dismiss', function() {
							var data = {
								'action': 'cp_dismiss_notification',
								'notification': <?php echo wp_json_encode( $self->name ); ?>
							};
							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 );
	}
}