HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.2.34
System: Linux atalantini.com 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64
User: root (0)
PHP: 7.2.34
Disabled: NONE
Upload Files
File: //opt/plugins/countdown-builder/classes/countdown/StickyCountdown.php
<?php
namespace ycd;

class StickyCountdown extends Countdown {

	public function __construct() {
		parent::__construct();
		add_action('add_meta_boxes', array($this, 'mainOptions'));
		add_filter('ycdCountdownDefaultOptions', array($this, 'defaultOptions'), 1, 1);
		add_action('ycdGeneralMetaboxes', array($this, 'metaboxes'), 10, 1);
	}

	public function metaboxes($metaboxes) {
		$metaboxes[YCD_PROGRESS_METABOX_KEY] = array('title' => YCD_PROGRESS_METABOX_TITLE, 'position' => 'normal', 'prioritet' => 'high');
	   
		return $metaboxes;
	}

	public function defaultOptions($options) {

		return $options;
	}

	public function includeStyles() {
		$this->includeGeneralScripts();
		$data = array(
			'days' => $this->getOptionValue('ycd-sticky-countdown-days'),
			'hours' => $this->getOptionValue('ycd-sticky-countdown-hours'),
			'minutes' => $this->getOptionValue('ycd-sticky-countdown-minutes'),
			'seconds' => $this->getOptionValue('ycd-sticky-countdown-seconds')
		);
		ScriptsIncluder::registerScript('Sticky.js', array('dirUrl' => YCD_COUNTDOWN_JS_URL, 'dep' => array('jquery')));
		ScriptsIncluder::localizeScript('Sticky.js', 'YCD_STICKY_ARGS', $data);
		ScriptsIncluder::enqueueScript('Sticky.js');
	}

	public function mainOptions(){
		parent::mainOptions();
		add_meta_box('ycdMainOptions', __('Sticky countdown options', YCD_TEXT_DOMAIN), array($this, 'mainView'), YCD_COUNTDOWN_POST_TYPE, 'normal', 'high');
	}

	public function mainView() {
		$typeObj = $this;
		require_once YCD_VIEWS_MAIN_PATH.'stickyMainView.php';
	}

	public function renderLivePreview() {
		$typeObj = $this;
		require_once YCD_PREVIEW_VIEWS_PATH.'circlePreview.php';
	}

	private function renderStyles() {
		$id = $this->getId();
		$important = ' !important';
		
		if(is_admin()) {
			$important = '';
		}
		$paddingEnable = $this->getOptionValue('ycd-sticky-button-padding-enable');
		$buttonPadding = $this->getOptionValue('ycd-sticky-button-padding');
		$inputBgColor = $this->getOptionValue('ycd-sticky-bg-color');
		$inputColor = $this->getOptionValue('ycd-sticky-button-color');
		$stickyTextColor = $this->getOptionValue('ycd-sticky-text-color');
		$stickyBgColor = $this->getOptionValue('ycd-sticky-text-background-color');
		$stickyCountdownColor = $this->getOptionValue('ycd-sticky-countdown-text-color');
		$countdownSize = (int)$this->getOptionValue('ycd-stick-countdown-font-size');
		$countdownWeight = $this->getOptionValue('ycd-stick-countdown-font-weight');
		
		$enableBorder = $this->getOptionValue('ycd-sticky-button-border-enable');
		$borderWidth = $this->getOptionValue('ycd-sticky-button-border-width');
		$borderRadius = $this->getOptionValue('ycd-sticky-button-border-radius');
		$borderColor = $this->getOptionValue('ycd-sticky-button-border-color');
		
		ob_start();
		?>
		<style type="text/css">
			.ycd-sticky-header-countdown {
				color: <?php echo $stickyCountdownColor; ?>;
				font-size: <?php echo $countdownSize; ?>px;
				font-weight: <?php echo $countdownWeight; ?>;
			}
			/* Style the header */
			.ycd-sticky-header {
				padding: 10px 16px;
				background: <?php echo esc_attr($stickyBgColor); ?>;
				color: <?php echo $stickyTextColor; ?>;
			}
			
			.ycd-sticky-header-child {
				width: 33%;
				display: inline-block;
				text-align: center;
				vertical-align: middle;
			}

			/* Page content */
			.ycd-sticky-content {
				padding: 16px;
			}

			/* The sticky class is added to the header with JS when it reaches its scroll position */
			.ycd-sticky {
				position: fixed;
				top: 0;
				width: 100%;
				z-index: 9999999999999999999999999999999999999999;
			}

			/* Add some top padding to the page content to prevent sudden quick movement (as the header gets a new position at the top of the page (position:fixed and top:0) */
			.ycd-sticky + .ycd-sticky-content {
				padding-top: 102px;
			}
			.ycd-sticky-button {
				background-color: <?php echo $inputBgColor.$important; ?>;
				color: <?php echo $inputColor.$important; ?>;
			}
			<?php if (!empty($paddingEnable)): ?>
				.ycd-sticky-button {
					padding: <?php echo $buttonPadding.' '.$important; ?>;
				}
			<?php endif; ?>
			<?php if (!empty($enableBorder)): ?>
				.ycd-sticky-button {
					border: <?php echo $borderWidth.'  solid '.$borderColor.' '.$important; ?>;
					border-radius: <?php echo $borderRadius.' '.$important; ?>;
			<?php endif; ?>
		</style>
		<?php
		$styles = ob_get_contents();
		ob_get_clean();

		echo $styles;
	}

	private function renderCountdown() {
		$type = $this->getOptionValue('ycd-sticky-countdown-mode');

		if ($type == 'stickyCountdownDefault') {
			return '<div class="ycd-sticky-clock"></div>';
		}
		$id = $this->getOptionValue('ycd-sticky-countdown');
		$content = do_shortcode('[ycd_countdown id='.$id.']');

		return $content;
	}
	
	private function getStickyContent() {
		$id = $this->getId();
		
		// time setting
		$settings = array();
		$endDate = $this->getOptionValue('ycd-date-time-picker');
		$timeZone = $this->getOptionValue('ycd-circle-time-zone');
		$settings['endDate'] = $endDate;
		$settings['timeZone'] = $timeZone;
		$settings['ycd-countdown-end-sound'] = $this->getOptionValue('ycd-countdown-end-sound');
		$settings['ycd-countdown-end-sound-url'] = $this->getOptionValue('ycd-countdown-end-sound-url');
		$settings['ycd-sticky-button-redirect-new-tab'] = $this->getOptionValue('ycd-sticky-button-redirect-new-tab');
		$settings['ycd-countdown-expire-behavior'] = $this->getOptionValue('ycd-countdown-expire-behavior');
		$settings['ycd-expire-text'] = $this->getOptionValue('ycd-expire-text');
		$settings['ycd-expire-url'] = $this->getOptionValue('ycd-expire-url');
		$settings['id'] = $id;
		$settings['ycd-countdown-date-type'] = $this->getOptionValue('ycd-countdown-date-type');
		$settings += $this->generalOptionsData();
	  
		$settings = json_encode($settings);

		$stickyUrl = $this->getOptionValue('ycd-sticky-url');
		$actionUrl = "window.location.href = '$stickyUrl'";
		
		if (!empty($settings['ycd-sticky-button-redirect-new-tab'])) {
			$actionUrl = "window.open('$stickyUrl')";
		}
		
		$textContent = $this->getOptionValue('ycd-sticky-text');
		$buttonText = $this->getOptionValue('ycd-sticky-button-text');
		
		ob_start();
		?>
			<div class="ycd-sticky-header ycd-sticky-header-<?php echo esc_attr($id); ?>" data-id="<?php echo esc_attr($id); ?>" data-settings="<?php echo esc_attr($settings); ?>">
				<div class="ycd-sticky-header-child ycd-sticky-header-text">
					<?php echo $textContent; ?>
				</div>
				<div class="ycd-sticky-header-child ycd-sticky-header-countdown">
					<?php echo $this->renderCountdown(); ?>
					<?php echo $this->renderProgressBar(); ?>
				</div>
				<div class="ycd-sticky-header-child ycd-sticky-header-button">
					<input type="button" class="ycd-sticky-button" onclick="<?php echo $actionUrl; ?>" value="<?php echo  esc_attr($buttonText); ?>">
				</div>
				<div>
					<?php echo $this->renderSubscriptionForm(); ?>
				</div>
			</div>
		<?php
		$content = ob_get_contents();
		ob_end_clean();
		$content .= $this->renderStyles();
		
		return $content;
	}

	public function addToContent() {
		return $this->getViewContent();
	}

	public function getViewContent() {
		$this->includeStyles();
		$content = $this->getStickyContent();
		
		return $content;
	}
}