PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 1.0.14
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v1.0.14
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
firebox / Inc / Framework / Inc / Base / Assignments / Datetimebase.php

Datetimebase.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 1.0.14, at Inc/Framework/Inc/Base/Assignments/Datetimebase.php

125 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FirePlugins Framework
4 * @version 1.0.27
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2022 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FPFramework\Base\Assignments;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 use FPFramework\Base\Assignment;
20
21 class Datetimebase extends Assignment
22 {
23 /**
24 * Server's Timezone
25 *
26 * @var DateTimeZone
27 */
28 protected $tz;
29
30 /**
31 * If set to True, dates will be constructed with modified offset based on the passed timezone
32 *
33 * @var Boolean
34 */
35 protected $modify_offset = true;
36
37 /**
38 * Class constructor
39 *
40 * @param object $assignment
41 */
42 public function __construct($assignment, $factory)
43 {
44 parent::__construct($assignment, $factory);
45
46 // Set timezone
47 if (property_exists($assignment->params, 'timezone') && !empty($assignment->params->timezone))
48 {
49 $this->tz = new \DateTimeZone($assignment->params->timezone);
50 }
51 else
52 {
53 $offset = \FPFramework\Base\Factory::getConfig()->get('offset');
54 $this->tz = new \DateTimeZone($offset);
55 }
56
57 // Set modify offset switch
58 if (property_exists($this->params, 'modify_offset'))
59 {
60 $this->modify_offset = (bool) $this->params->modify_offset;
61 }
62
63 // Set now date
64 $now = property_exists($assignment->params, 'now') ? $assignment->params->now : 'now';
65 $this->date = $this->getDate($now);
66 }
67
68 /**
69 * Checks if the current datetime is between the specified range
70 *
71 * @param JDate &$up_date
72 * @param JDate &$down_date
73 *
74 * @return bool
75 */
76 protected function checkRange(&$up_date, &$down_date)
77 {
78 if (!$up_date && !$down_date)
79 {
80 return false;
81 }
82
83 // Set down date's hours to 23:59:59
84 if ($down_date && property_exists($this->params, 'publish_down_end_date') && $this->params->publish_down_end_date)
85 {
86 $down_date->setTime(23, 59, 59);
87 }
88
89 $now = $this->date->getTimestamp();
90
91 if (((bool)$up_date && $up_date->getTimestamp() > $now) ||
92 ((bool)$down_date && $down_date->getTimestamp() < $now))
93 {
94 return false;
95 }
96
97 return true;
98 }
99
100 /**
101 * Create a date object based on the given string and apply timezone.
102 *
103 * @param String $date
104 *
105 * @return void
106 */
107 protected function getDate($date = 'now')
108 {
109 // Fix the date string
110 \FPFramework\Libs\Functions::fixDate($date);
111
112 if ($this->modify_offset)
113 {
114 // Create date, set timezone and modify offset
115 $date = $this->factory->getDate($date)->setTimeZone($this->tz);
116 } else
117 {
118 // Create date and set timezone without modifyig offset
119 $date = $this->factory->getDate($date, $this->tz);
120 }
121
122 return $date;
123 }
124 }
125