@@ -34,7 +34,7 @@ |
||
34 | 34 | */ |
35 | 35 | public function __construct($alias, $fqcn) |
36 | 36 | { |
37 | - if (! is_subclass_of($fqcn, $alias)) { |
|
37 | + if ( ! is_subclass_of($fqcn, $alias)) { |
|
38 | 38 | throw new InvalidAliasException($fqcn, $alias); |
39 | 39 | } |
40 | 40 | $this->alias = $alias; |
@@ -17,46 +17,46 @@ |
||
17 | 17 | class ClassAlias |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string $alias an interface or base class representing what object |
|
22 | - * can be utilized by another object and/or function |
|
23 | - */ |
|
24 | - private $alias; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var string $fqcn the actual class that should be substituted for the alias above |
|
28 | - */ |
|
29 | - private $fqcn; |
|
30 | - |
|
31 | - /** |
|
32 | - * ClassAlias constructor. |
|
33 | - * |
|
34 | - * @param string $alias Interface specified by implementing class |
|
35 | - * @param string $fqcn Concrete class that satisfies interface |
|
36 | - * @throws InvalidAliasException |
|
37 | - */ |
|
38 | - public function __construct($alias, $fqcn) |
|
39 | - { |
|
40 | - if (! is_subclass_of($fqcn, $alias)) { |
|
41 | - throw new InvalidAliasException($fqcn, $alias); |
|
42 | - } |
|
43 | - $this->alias = $alias; |
|
44 | - $this->fqcn = $fqcn; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function alias() |
|
51 | - { |
|
52 | - return $this->alias; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function fqcn() |
|
59 | - { |
|
60 | - return $this->fqcn; |
|
61 | - } |
|
20 | + /** |
|
21 | + * @var string $alias an interface or base class representing what object |
|
22 | + * can be utilized by another object and/or function |
|
23 | + */ |
|
24 | + private $alias; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var string $fqcn the actual class that should be substituted for the alias above |
|
28 | + */ |
|
29 | + private $fqcn; |
|
30 | + |
|
31 | + /** |
|
32 | + * ClassAlias constructor. |
|
33 | + * |
|
34 | + * @param string $alias Interface specified by implementing class |
|
35 | + * @param string $fqcn Concrete class that satisfies interface |
|
36 | + * @throws InvalidAliasException |
|
37 | + */ |
|
38 | + public function __construct($alias, $fqcn) |
|
39 | + { |
|
40 | + if (! is_subclass_of($fqcn, $alias)) { |
|
41 | + throw new InvalidAliasException($fqcn, $alias); |
|
42 | + } |
|
43 | + $this->alias = $alias; |
|
44 | + $this->fqcn = $fqcn; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function alias() |
|
51 | + { |
|
52 | + return $this->alias; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function fqcn() |
|
59 | + { |
|
60 | + return $this->fqcn; |
|
61 | + } |
|
62 | 62 | } |
@@ -18,41 +18,41 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class FactoryWithDependencyResolver implements FactoryInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * @var DependencyResolverInterface $dependency_resolver |
|
23 | - */ |
|
24 | - private $dependency_resolver; |
|
21 | + /** |
|
22 | + * @var DependencyResolverInterface $dependency_resolver |
|
23 | + */ |
|
24 | + private $dependency_resolver; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var LoaderInterface $loader |
|
28 | - */ |
|
29 | - private $loader; |
|
26 | + /** |
|
27 | + * @var LoaderInterface $loader |
|
28 | + */ |
|
29 | + private $loader; |
|
30 | 30 | |
31 | - /** |
|
32 | - * FactoryWithDependencyResolver constructor. |
|
33 | - * |
|
34 | - * @param DependencyResolverInterface $dependency_resolver |
|
35 | - * @param LoaderInterface $loader |
|
36 | - */ |
|
37 | - public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader) |
|
38 | - { |
|
39 | - $this->dependency_resolver = $dependency_resolver; |
|
40 | - $this->loader = $loader; |
|
41 | - } |
|
31 | + /** |
|
32 | + * FactoryWithDependencyResolver constructor. |
|
33 | + * |
|
34 | + * @param DependencyResolverInterface $dependency_resolver |
|
35 | + * @param LoaderInterface $loader |
|
36 | + */ |
|
37 | + public function __construct(DependencyResolverInterface $dependency_resolver, LoaderInterface $loader) |
|
38 | + { |
|
39 | + $this->dependency_resolver = $dependency_resolver; |
|
40 | + $this->loader = $loader; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return DependencyResolverInterface |
|
45 | - */ |
|
46 | - public function dependencyResolver() |
|
47 | - { |
|
48 | - return $this->dependency_resolver; |
|
49 | - } |
|
43 | + /** |
|
44 | + * @return DependencyResolverInterface |
|
45 | + */ |
|
46 | + public function dependencyResolver() |
|
47 | + { |
|
48 | + return $this->dependency_resolver; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return LoaderInterface |
|
53 | - */ |
|
54 | - public function loader() |
|
55 | - { |
|
56 | - return $this->loader; |
|
57 | - } |
|
51 | + /** |
|
52 | + * @return LoaderInterface |
|
53 | + */ |
|
54 | + public function loader() |
|
55 | + { |
|
56 | + return $this->loader; |
|
57 | + } |
|
58 | 58 | } |
@@ -11,10 +11,10 @@ |
||
11 | 11 | interface FactoryInterface |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param mixed $arguments Either a Fully Qualified Class Name |
|
16 | - * or array of data required for construction |
|
17 | - * @return mixed |
|
18 | - */ |
|
19 | - public static function create($arguments); |
|
14 | + /** |
|
15 | + * @param mixed $arguments Either a Fully Qualified Class Name |
|
16 | + * or array of data required for construction |
|
17 | + * @return mixed |
|
18 | + */ |
|
19 | + public static function create($arguments); |
|
20 | 20 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | foreach ($this->blocks as $block) { |
146 | 146 | $block->initialize(); |
147 | 147 | $this->trackAssetManagersForBlocks($block); |
148 | - if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
148 | + if ( ! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
149 | 149 | $this->block_asset_manager_collection->add($block->assetManager()); |
150 | 150 | $block->assetManager()->setAssetHandles(); |
151 | 151 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | $supported_routes = $block->supportedRoutes(); |
168 | 168 | foreach ($supported_routes as $supported_route) { |
169 | 169 | if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
170 | - $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
170 | + $this->block_asset_managers[$block->blockType()] = $block->assetManager()->assetNamespace(); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | } |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function matchesRoute(BlockInterface $block) |
185 | 185 | { |
186 | - if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
186 | + if (isset($this->block_asset_managers[$block->blockType()])) { |
|
187 | 187 | return true; |
188 | 188 | } |
189 | - unset($this->block_asset_managers[ $block->blockType() ]); |
|
189 | + unset($this->block_asset_managers[$block->blockType()]); |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | |
@@ -202,12 +202,12 @@ discard block |
||
202 | 202 | try { |
203 | 203 | // cycle thru block loader folders |
204 | 204 | foreach ($this->blocks as $block) { |
205 | - if (! $this->matchesRoute($block)) { |
|
205 | + if ( ! $this->matchesRoute($block)) { |
|
206 | 206 | continue; |
207 | 207 | } |
208 | 208 | // perform any setup required for the block |
209 | 209 | $block_type = $block->registerBlock(); |
210 | - if (! $block_type instanceof WP_Block_Type) { |
|
210 | + if ( ! $block_type instanceof WP_Block_Type) { |
|
211 | 211 | throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
212 | 212 | } |
213 | 213 | do_action( |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $assets = array_flip($this->block_asset_managers); |
227 | 227 | foreach ($this->block_asset_manager_collection as $asset_manager) { |
228 | 228 | // if there are no longer any blocks that require these assets, |
229 | - if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
229 | + if ( ! isset($assets[$asset_manager->assetNamespace()])) { |
|
230 | 230 | // then unset asset enqueueing and bail |
231 | 231 | remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
232 | 232 | remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
@@ -32,223 +32,223 @@ |
||
32 | 32 | class BlockRegistrationManager extends BlockManager |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @var BlockAssetManagerCollection $block_asset_manager_collection |
|
37 | - */ |
|
38 | - protected $block_asset_manager_collection; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var RouteMatchSpecificationManager $route_manager |
|
42 | - */ |
|
43 | - protected $route_manager; |
|
44 | - |
|
45 | - /** |
|
46 | - * array for tracking asset managers required by blocks for the current route |
|
47 | - * |
|
48 | - * @var array $block_asset_managers |
|
49 | - */ |
|
50 | - protected $block_asset_managers = array(); |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * BlockRegistrationManager constructor. |
|
55 | - * |
|
56 | - * @param BlockAssetManagerCollection $block_asset_manager_collection |
|
57 | - * @param BlockCollection $blocks |
|
58 | - * @param RouteMatchSpecificationManager $route_manager |
|
59 | - * @param RequestInterface $request |
|
60 | - */ |
|
61 | - public function __construct( |
|
62 | - BlockAssetManagerCollection $block_asset_manager_collection, |
|
63 | - BlockCollection $blocks, |
|
64 | - RouteMatchSpecificationManager $route_manager, |
|
65 | - RequestInterface $request |
|
66 | - ) { |
|
67 | - $this->block_asset_manager_collection = $block_asset_manager_collection; |
|
68 | - $this->route_manager = $route_manager; |
|
69 | - parent::__construct($blocks, $request); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Returns the name of a hookpoint to be used to call initialize() |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function initHook() |
|
79 | - { |
|
80 | - return 'AHEE__EE_System__initialize'; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Perform any early setup required for block editors to functions |
|
86 | - * |
|
87 | - * @return void |
|
88 | - * @throws Exception |
|
89 | - */ |
|
90 | - public function initialize() |
|
91 | - { |
|
92 | - $this->initializeBlocks(); |
|
93 | - add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks')); |
|
94 | - add_action('wp_loaded', array($this, 'unloadAssets')); |
|
95 | - add_filter('block_categories', array($this, 'addEspressoBlockCategories')); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @param array $categories |
|
101 | - * @since 4.9.71.p |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - public function addEspressoBlockCategories(array $categories) |
|
105 | - { |
|
106 | - return array_merge( |
|
107 | - $categories, |
|
108 | - array( |
|
109 | - array( |
|
110 | - 'slug' => 'event-espresso', |
|
111 | - 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
112 | - ), |
|
113 | - ) |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @return CollectionInterface|BlockInterface[] |
|
120 | - * @throws CollectionLoaderException |
|
121 | - * @throws CollectionDetailsException |
|
122 | - */ |
|
123 | - protected function populateBlockCollection() |
|
124 | - { |
|
125 | - $loader = new CollectionLoader( |
|
126 | - new CollectionDetails( |
|
127 | - // collection name |
|
128 | - 'editor_blocks', |
|
129 | - // collection interface |
|
130 | - 'EventEspresso\core\domain\entities\editor\BlockInterface', |
|
131 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
132 | - apply_filters( |
|
133 | - 'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs', |
|
134 | - array('EventEspresso\core\domain\entities\editor\blocks') |
|
135 | - ), |
|
136 | - // filepaths to classes to add |
|
137 | - array(), |
|
138 | - // file mask to use if parsing folder for files to add |
|
139 | - '', |
|
140 | - // what to use as identifier for collection entities |
|
141 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
142 | - CollectionDetails::ID_CLASS_NAME |
|
143 | - ), |
|
144 | - $this->blocks |
|
145 | - ); |
|
146 | - return $loader->getCollection(); |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * populates the BlockCollection and calls initialize() on all installed blocks |
|
152 | - * |
|
153 | - * @return void |
|
154 | - * @throws Exception |
|
155 | - */ |
|
156 | - public function initializeBlocks() |
|
157 | - { |
|
158 | - try { |
|
159 | - $this->populateBlockCollection(); |
|
160 | - // cycle thru block loaders and initialize each loader |
|
161 | - foreach ($this->blocks as $block) { |
|
162 | - $block->initialize(); |
|
163 | - $this->trackAssetManagersForBlocks($block); |
|
164 | - if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
165 | - $this->block_asset_manager_collection->add($block->assetManager()); |
|
166 | - $block->assetManager()->setAssetHandles(); |
|
167 | - } |
|
168 | - } |
|
169 | - } catch (Exception $exception) { |
|
170 | - new ExceptionStackTraceDisplay($exception); |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * track blocks with routes that match the current request |
|
177 | - * |
|
178 | - * @param BlockInterface $block |
|
179 | - * @throws InvalidClassException |
|
180 | - */ |
|
181 | - private function trackAssetManagersForBlocks(BlockInterface $block) |
|
182 | - { |
|
183 | - $supported_routes = $block->supportedRoutes(); |
|
184 | - foreach ($supported_routes as $supported_route) { |
|
185 | - if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
|
186 | - $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
187 | - } |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * returns true if the block should be registered for the current request |
|
194 | - * else removes block from block_routes array and returns false |
|
195 | - * |
|
196 | - * @param BlockInterface $block |
|
197 | - * @return boolean |
|
198 | - * @throws InvalidClassException |
|
199 | - */ |
|
200 | - public function matchesRoute(BlockInterface $block) |
|
201 | - { |
|
202 | - if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
203 | - return true; |
|
204 | - } |
|
205 | - unset($this->block_asset_managers[ $block->blockType() ]); |
|
206 | - return false; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * calls registerBlock() and load assets for all installed blocks |
|
212 | - * |
|
213 | - * @return void |
|
214 | - * @throws Exception |
|
215 | - */ |
|
216 | - public function registerBlocks() |
|
217 | - { |
|
218 | - try { |
|
219 | - // cycle thru block loader folders |
|
220 | - foreach ($this->blocks as $block) { |
|
221 | - if (! $this->matchesRoute($block)) { |
|
222 | - continue; |
|
223 | - } |
|
224 | - // perform any setup required for the block |
|
225 | - $block_type = $block->registerBlock(); |
|
226 | - if (! $block_type instanceof WP_Block_Type) { |
|
227 | - throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
228 | - } |
|
229 | - do_action( |
|
230 | - 'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered', |
|
231 | - $block, |
|
232 | - $block_type |
|
233 | - ); |
|
234 | - } |
|
235 | - } catch (Exception $exception) { |
|
236 | - new ExceptionStackTraceDisplay($exception); |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - public function unloadAssets() |
|
241 | - { |
|
242 | - $assets = array_flip($this->block_asset_managers); |
|
243 | - foreach ($this->block_asset_manager_collection as $asset_manager) { |
|
244 | - // if there are no longer any blocks that require these assets, |
|
245 | - if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
246 | - // then unset asset enqueueing and bail |
|
247 | - remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
248 | - remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
249 | - remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
250 | - remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
251 | - } |
|
252 | - } |
|
253 | - } |
|
35 | + /** |
|
36 | + * @var BlockAssetManagerCollection $block_asset_manager_collection |
|
37 | + */ |
|
38 | + protected $block_asset_manager_collection; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var RouteMatchSpecificationManager $route_manager |
|
42 | + */ |
|
43 | + protected $route_manager; |
|
44 | + |
|
45 | + /** |
|
46 | + * array for tracking asset managers required by blocks for the current route |
|
47 | + * |
|
48 | + * @var array $block_asset_managers |
|
49 | + */ |
|
50 | + protected $block_asset_managers = array(); |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * BlockRegistrationManager constructor. |
|
55 | + * |
|
56 | + * @param BlockAssetManagerCollection $block_asset_manager_collection |
|
57 | + * @param BlockCollection $blocks |
|
58 | + * @param RouteMatchSpecificationManager $route_manager |
|
59 | + * @param RequestInterface $request |
|
60 | + */ |
|
61 | + public function __construct( |
|
62 | + BlockAssetManagerCollection $block_asset_manager_collection, |
|
63 | + BlockCollection $blocks, |
|
64 | + RouteMatchSpecificationManager $route_manager, |
|
65 | + RequestInterface $request |
|
66 | + ) { |
|
67 | + $this->block_asset_manager_collection = $block_asset_manager_collection; |
|
68 | + $this->route_manager = $route_manager; |
|
69 | + parent::__construct($blocks, $request); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Returns the name of a hookpoint to be used to call initialize() |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function initHook() |
|
79 | + { |
|
80 | + return 'AHEE__EE_System__initialize'; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Perform any early setup required for block editors to functions |
|
86 | + * |
|
87 | + * @return void |
|
88 | + * @throws Exception |
|
89 | + */ |
|
90 | + public function initialize() |
|
91 | + { |
|
92 | + $this->initializeBlocks(); |
|
93 | + add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks')); |
|
94 | + add_action('wp_loaded', array($this, 'unloadAssets')); |
|
95 | + add_filter('block_categories', array($this, 'addEspressoBlockCategories')); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @param array $categories |
|
101 | + * @since 4.9.71.p |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + public function addEspressoBlockCategories(array $categories) |
|
105 | + { |
|
106 | + return array_merge( |
|
107 | + $categories, |
|
108 | + array( |
|
109 | + array( |
|
110 | + 'slug' => 'event-espresso', |
|
111 | + 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
112 | + ), |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @return CollectionInterface|BlockInterface[] |
|
120 | + * @throws CollectionLoaderException |
|
121 | + * @throws CollectionDetailsException |
|
122 | + */ |
|
123 | + protected function populateBlockCollection() |
|
124 | + { |
|
125 | + $loader = new CollectionLoader( |
|
126 | + new CollectionDetails( |
|
127 | + // collection name |
|
128 | + 'editor_blocks', |
|
129 | + // collection interface |
|
130 | + 'EventEspresso\core\domain\entities\editor\BlockInterface', |
|
131 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
132 | + apply_filters( |
|
133 | + 'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs', |
|
134 | + array('EventEspresso\core\domain\entities\editor\blocks') |
|
135 | + ), |
|
136 | + // filepaths to classes to add |
|
137 | + array(), |
|
138 | + // file mask to use if parsing folder for files to add |
|
139 | + '', |
|
140 | + // what to use as identifier for collection entities |
|
141 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
142 | + CollectionDetails::ID_CLASS_NAME |
|
143 | + ), |
|
144 | + $this->blocks |
|
145 | + ); |
|
146 | + return $loader->getCollection(); |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * populates the BlockCollection and calls initialize() on all installed blocks |
|
152 | + * |
|
153 | + * @return void |
|
154 | + * @throws Exception |
|
155 | + */ |
|
156 | + public function initializeBlocks() |
|
157 | + { |
|
158 | + try { |
|
159 | + $this->populateBlockCollection(); |
|
160 | + // cycle thru block loaders and initialize each loader |
|
161 | + foreach ($this->blocks as $block) { |
|
162 | + $block->initialize(); |
|
163 | + $this->trackAssetManagersForBlocks($block); |
|
164 | + if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
165 | + $this->block_asset_manager_collection->add($block->assetManager()); |
|
166 | + $block->assetManager()->setAssetHandles(); |
|
167 | + } |
|
168 | + } |
|
169 | + } catch (Exception $exception) { |
|
170 | + new ExceptionStackTraceDisplay($exception); |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * track blocks with routes that match the current request |
|
177 | + * |
|
178 | + * @param BlockInterface $block |
|
179 | + * @throws InvalidClassException |
|
180 | + */ |
|
181 | + private function trackAssetManagersForBlocks(BlockInterface $block) |
|
182 | + { |
|
183 | + $supported_routes = $block->supportedRoutes(); |
|
184 | + foreach ($supported_routes as $supported_route) { |
|
185 | + if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
|
186 | + $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
187 | + } |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * returns true if the block should be registered for the current request |
|
194 | + * else removes block from block_routes array and returns false |
|
195 | + * |
|
196 | + * @param BlockInterface $block |
|
197 | + * @return boolean |
|
198 | + * @throws InvalidClassException |
|
199 | + */ |
|
200 | + public function matchesRoute(BlockInterface $block) |
|
201 | + { |
|
202 | + if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
203 | + return true; |
|
204 | + } |
|
205 | + unset($this->block_asset_managers[ $block->blockType() ]); |
|
206 | + return false; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * calls registerBlock() and load assets for all installed blocks |
|
212 | + * |
|
213 | + * @return void |
|
214 | + * @throws Exception |
|
215 | + */ |
|
216 | + public function registerBlocks() |
|
217 | + { |
|
218 | + try { |
|
219 | + // cycle thru block loader folders |
|
220 | + foreach ($this->blocks as $block) { |
|
221 | + if (! $this->matchesRoute($block)) { |
|
222 | + continue; |
|
223 | + } |
|
224 | + // perform any setup required for the block |
|
225 | + $block_type = $block->registerBlock(); |
|
226 | + if (! $block_type instanceof WP_Block_Type) { |
|
227 | + throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
228 | + } |
|
229 | + do_action( |
|
230 | + 'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered', |
|
231 | + $block, |
|
232 | + $block_type |
|
233 | + ); |
|
234 | + } |
|
235 | + } catch (Exception $exception) { |
|
236 | + new ExceptionStackTraceDisplay($exception); |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + public function unloadAssets() |
|
241 | + { |
|
242 | + $assets = array_flip($this->block_asset_managers); |
|
243 | + foreach ($this->block_asset_manager_collection as $asset_manager) { |
|
244 | + // if there are no longer any blocks that require these assets, |
|
245 | + if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
246 | + // then unset asset enqueueing and bail |
|
247 | + remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
248 | + remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
249 | + remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
250 | + remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
251 | + } |
|
252 | + } |
|
253 | + } |
|
254 | 254 | } |
@@ -25,105 +25,102 @@ |
||
25 | 25 | |
26 | 26 | ) |
27 | 27 | ); |
28 | - |
|
29 | - |
|
30 | - |
|
31 | 28 | * |
32 | 29 | */ |
33 | 30 | class EE_DMS_4_1_0_event_venue extends EE_Data_Migration_Script_Stage |
34 | 31 | { |
35 | - private $_old_table; |
|
36 | - private $_new_table; |
|
37 | - public function _migration_step($num_items = 50) |
|
38 | - { |
|
32 | + private $_old_table; |
|
33 | + private $_new_table; |
|
34 | + public function _migration_step($num_items = 50) |
|
35 | + { |
|
39 | 36 | |
40 | - global $wpdb; |
|
41 | - $start_at_record = $this->count_records_migrated(); |
|
42 | - $rows = $wpdb->get_results( |
|
43 | - $wpdb->prepare( |
|
44 | - "SELECT * FROM $this->_old_table AS ev |
|
37 | + global $wpdb; |
|
38 | + $start_at_record = $this->count_records_migrated(); |
|
39 | + $rows = $wpdb->get_results( |
|
40 | + $wpdb->prepare( |
|
41 | + "SELECT * FROM $this->_old_table AS ev |
|
45 | 42 | INNER JOIN " . $wpdb->prefix . "events_detail AS e ON ev.event_id=e.id |
46 | 43 | WHERE e.event_status!='D' LIMIT %d,%d", |
47 | - $start_at_record, |
|
48 | - $num_items |
|
49 | - ), |
|
50 | - ARRAY_A |
|
51 | - ); |
|
52 | - $items_actually_migrated = 0; |
|
53 | - foreach ($rows as $event_venue_rel) { |
|
54 | - $this->_insert_new_event_to_venue_rel($event_venue_rel); |
|
55 | - $items_actually_migrated++; |
|
56 | - } |
|
57 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
58 | - $this->set_completed(); |
|
59 | - } |
|
60 | - return $items_actually_migrated; |
|
61 | - } |
|
62 | - public function _count_records_to_migrate() |
|
63 | - { |
|
64 | - global $wpdb; |
|
65 | - $count = $wpdb->get_var( |
|
66 | - "SELECT COUNT(ev.id) FROM ".$this->_old_table . " AS ev |
|
44 | + $start_at_record, |
|
45 | + $num_items |
|
46 | + ), |
|
47 | + ARRAY_A |
|
48 | + ); |
|
49 | + $items_actually_migrated = 0; |
|
50 | + foreach ($rows as $event_venue_rel) { |
|
51 | + $this->_insert_new_event_to_venue_rel($event_venue_rel); |
|
52 | + $items_actually_migrated++; |
|
53 | + } |
|
54 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
55 | + $this->set_completed(); |
|
56 | + } |
|
57 | + return $items_actually_migrated; |
|
58 | + } |
|
59 | + public function _count_records_to_migrate() |
|
60 | + { |
|
61 | + global $wpdb; |
|
62 | + $count = $wpdb->get_var( |
|
63 | + "SELECT COUNT(ev.id) FROM ".$this->_old_table . " AS ev |
|
67 | 64 | INNER JOIN " . $wpdb->prefix . 'events_detail AS e ON ev.event_id=e.id |
68 | 65 | WHERE e.event_status!="D"' |
69 | - ); |
|
70 | - return $count; |
|
71 | - } |
|
72 | - public function __construct() |
|
73 | - { |
|
74 | - global $wpdb; |
|
75 | - $this->_old_table = $wpdb->prefix."events_venue_rel"; |
|
76 | - $this->_new_table = $wpdb->prefix."esp_event_venue"; |
|
77 | - $this->_pretty_name = __("Event to Venue Relations", "event_espresso"); |
|
78 | - parent::__construct(); |
|
79 | - } |
|
66 | + ); |
|
67 | + return $count; |
|
68 | + } |
|
69 | + public function __construct() |
|
70 | + { |
|
71 | + global $wpdb; |
|
72 | + $this->_old_table = $wpdb->prefix."events_venue_rel"; |
|
73 | + $this->_new_table = $wpdb->prefix."esp_event_venue"; |
|
74 | + $this->_pretty_name = __("Event to Venue Relations", "event_espresso"); |
|
75 | + parent::__construct(); |
|
76 | + } |
|
80 | 77 | |
81 | - /** |
|
82 | - * Attempts to insert a new question group inthe new format given an old one |
|
83 | - * @global type $wpdb |
|
84 | - * @param array $old_event_venue_rel |
|
85 | - * @return int |
|
86 | - */ |
|
87 | - private function _insert_new_event_to_venue_rel($old_event_venue_rel) |
|
88 | - { |
|
89 | - global $wpdb; |
|
90 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_venue_rel['event_id'], $wpdb->prefix."posts"); |
|
91 | - $new_venue_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_venue", $old_event_venue_rel['venue_id'], $wpdb->prefix."posts"); |
|
92 | - if (! $new_event_id) { |
|
93 | - $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_venue_rel['event_id'])); |
|
94 | - return 0; |
|
95 | - } |
|
96 | - if (! $new_venue_id) { |
|
97 | - $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $old_event_venue_rel['venue_id'])); |
|
98 | - return 0; |
|
99 | - } |
|
100 | - // first ensure there are no other relation entries for this event |
|
101 | - // because although EE4 supports it, EE3 didn't really |
|
102 | - $wpdb->delete( |
|
103 | - $this->_new_table, |
|
104 | - array( |
|
105 | - 'EVT_ID' => $new_event_id, |
|
106 | - ), |
|
107 | - array( |
|
108 | - '%d',// EVT_ID |
|
109 | - ) |
|
110 | - ); |
|
78 | + /** |
|
79 | + * Attempts to insert a new question group inthe new format given an old one |
|
80 | + * @global type $wpdb |
|
81 | + * @param array $old_event_venue_rel |
|
82 | + * @return int |
|
83 | + */ |
|
84 | + private function _insert_new_event_to_venue_rel($old_event_venue_rel) |
|
85 | + { |
|
86 | + global $wpdb; |
|
87 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_venue_rel['event_id'], $wpdb->prefix."posts"); |
|
88 | + $new_venue_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_venue", $old_event_venue_rel['venue_id'], $wpdb->prefix."posts"); |
|
89 | + if (! $new_event_id) { |
|
90 | + $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_venue_rel['event_id'])); |
|
91 | + return 0; |
|
92 | + } |
|
93 | + if (! $new_venue_id) { |
|
94 | + $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $old_event_venue_rel['venue_id'])); |
|
95 | + return 0; |
|
96 | + } |
|
97 | + // first ensure there are no other relation entries for this event |
|
98 | + // because although EE4 supports it, EE3 didn't really |
|
99 | + $wpdb->delete( |
|
100 | + $this->_new_table, |
|
101 | + array( |
|
102 | + 'EVT_ID' => $new_event_id, |
|
103 | + ), |
|
104 | + array( |
|
105 | + '%d',// EVT_ID |
|
106 | + ) |
|
107 | + ); |
|
111 | 108 | // echo "last query". $wpdb->last_query;die; |
112 | - $cols_n_values = array( |
|
113 | - 'EVT_ID'=>$new_event_id, |
|
114 | - 'VNU_ID'=>$new_venue_id, |
|
115 | - 'EVV_primary'=>true |
|
116 | - ); |
|
117 | - $datatypes = array( |
|
118 | - '%d',// EVT_ID |
|
119 | - '%d',// VNU_ID |
|
120 | - '%d',// EVT_primary |
|
121 | - ); |
|
122 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
123 | - if (! $success) { |
|
124 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_venue_rel, $this->_new_table, $cols_n_values, $datatypes)); |
|
125 | - return 0; |
|
126 | - } |
|
127 | - return $wpdb->insert_id; |
|
128 | - } |
|
109 | + $cols_n_values = array( |
|
110 | + 'EVT_ID'=>$new_event_id, |
|
111 | + 'VNU_ID'=>$new_venue_id, |
|
112 | + 'EVV_primary'=>true |
|
113 | + ); |
|
114 | + $datatypes = array( |
|
115 | + '%d',// EVT_ID |
|
116 | + '%d',// VNU_ID |
|
117 | + '%d',// EVT_primary |
|
118 | + ); |
|
119 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
120 | + if (! $success) { |
|
121 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_venue_rel, $this->_new_table, $cols_n_values, $datatypes)); |
|
122 | + return 0; |
|
123 | + } |
|
124 | + return $wpdb->insert_id; |
|
125 | + } |
|
129 | 126 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $rows = $wpdb->get_results( |
43 | 43 | $wpdb->prepare( |
44 | 44 | "SELECT * FROM $this->_old_table AS ev |
45 | - INNER JOIN " . $wpdb->prefix . "events_detail AS e ON ev.event_id=e.id |
|
45 | + INNER JOIN ".$wpdb->prefix."events_detail AS e ON ev.event_id=e.id |
|
46 | 46 | WHERE e.event_status!='D' LIMIT %d,%d", |
47 | 47 | $start_at_record, |
48 | 48 | $num_items |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | { |
64 | 64 | global $wpdb; |
65 | 65 | $count = $wpdb->get_var( |
66 | - "SELECT COUNT(ev.id) FROM ".$this->_old_table . " AS ev |
|
67 | - INNER JOIN " . $wpdb->prefix . 'events_detail AS e ON ev.event_id=e.id |
|
66 | + "SELECT COUNT(ev.id) FROM ".$this->_old_table." AS ev |
|
67 | + INNER JOIN " . $wpdb->prefix.'events_detail AS e ON ev.event_id=e.id |
|
68 | 68 | WHERE e.event_status!="D"' |
69 | 69 | ); |
70 | 70 | return $count; |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | global $wpdb; |
90 | 90 | $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_venue_rel['event_id'], $wpdb->prefix."posts"); |
91 | 91 | $new_venue_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_venue", $old_event_venue_rel['venue_id'], $wpdb->prefix."posts"); |
92 | - if (! $new_event_id) { |
|
92 | + if ( ! $new_event_id) { |
|
93 | 93 | $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_venue_rel['event_id'])); |
94 | 94 | return 0; |
95 | 95 | } |
96 | - if (! $new_venue_id) { |
|
96 | + if ( ! $new_venue_id) { |
|
97 | 97 | $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $old_event_venue_rel['venue_id'])); |
98 | 98 | return 0; |
99 | 99 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | 'EVT_ID' => $new_event_id, |
106 | 106 | ), |
107 | 107 | array( |
108 | - '%d',// EVT_ID |
|
108 | + '%d', // EVT_ID |
|
109 | 109 | ) |
110 | 110 | ); |
111 | 111 | // echo "last query". $wpdb->last_query;die; |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | 'EVV_primary'=>true |
116 | 116 | ); |
117 | 117 | $datatypes = array( |
118 | - '%d',// EVT_ID |
|
119 | - '%d',// VNU_ID |
|
120 | - '%d',// EVT_primary |
|
118 | + '%d', // EVT_ID |
|
119 | + '%d', // VNU_ID |
|
120 | + '%d', // EVT_primary |
|
121 | 121 | ); |
122 | 122 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
123 | - if (! $success) { |
|
123 | + if ( ! $success) { |
|
124 | 124 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_venue_rel, $this->_new_table, $cols_n_values, $datatypes)); |
125 | 125 | return 0; |
126 | 126 | } |
@@ -16,131 +16,131 @@ |
||
16 | 16 | */ |
17 | 17 | class Config |
18 | 18 | { |
19 | - /** |
|
20 | - * @var EE_Network_Config |
|
21 | - */ |
|
22 | - private $network_config; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * @var EE_Config |
|
27 | - */ |
|
28 | - private $ee_config; |
|
29 | - |
|
30 | - |
|
31 | - public function __construct(EE_Network_Config $network_config, EE_Config $ee_config) |
|
32 | - { |
|
33 | - $this->network_config = $network_config; |
|
34 | - $this->ee_config = $ee_config; |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Get the site license key for the site. |
|
40 | - */ |
|
41 | - public function siteLicenseKey() |
|
42 | - { |
|
43 | - return $this->network_config->core->site_license_key; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - public function i18nDomain() |
|
48 | - { |
|
49 | - return 'event_espresso'; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - public function checkPeriod() |
|
54 | - { |
|
55 | - return 24; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - public function optionKey() |
|
60 | - { |
|
61 | - return 'ee_site_license_key'; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - public function optionsPageSlug() |
|
66 | - { |
|
67 | - return 'espresso_general_settings'; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - public function hostServerUrl() |
|
72 | - { |
|
73 | - return defined('PUE_UPDATES_ENDPOINT') |
|
74 | - ? PUE_UPDATES_ENDPOINT |
|
75 | - : 'https://eventespresso.com'; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - public function pluginSlug() |
|
80 | - { |
|
81 | - // Note: PUE uses a simple preg_match to determine what type is currently installed based on version number. |
|
82 | - // So it's important that you use a key for the version type that is unique and not found in another key. |
|
83 | - // For example: |
|
84 | - // $plugin_slug['premium']['p'] = 'some-premium-slug'; |
|
85 | - // $plugin_slug['prerelease']['pr'] = 'some-pre-release-slug'; |
|
86 | - // The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr ) |
|
87 | - // so doing something like: |
|
88 | - // $plugin_slug['premium']['p'] = 'some-premium-slug'; |
|
89 | - // $plugin_slug['prerelease']['b'] = 'some-pre-release-slug'; |
|
90 | - // ..WOULD work! |
|
91 | - return array( |
|
92 | - 'free' => array('decaf' => 'event-espresso-core-decaf'), |
|
93 | - 'premium' => array('p' => 'event-espresso-core-reg'), |
|
94 | - 'prerelease' => array('beta' => 'event-espresso-core-pr'), |
|
95 | - ); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Return whether the site is opted in for UXIP or not. |
|
101 | - * |
|
102 | - * @return bool |
|
103 | - */ |
|
104 | - public function isOptedInForUxip() |
|
105 | - { |
|
106 | - return filter_var($this->ee_config->core->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Return whether the site has been notified about UXIP or not. |
|
112 | - * |
|
113 | - * @return bool |
|
114 | - */ |
|
115 | - public function hasNotifiedForUxip() |
|
116 | - { |
|
117 | - return filter_var($this->ee_config->core->ee_ueip_has_notified, FILTER_VALIDATE_BOOLEAN); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Set the site opted in for UXIP. |
|
123 | - */ |
|
124 | - public function setHasOptedInForUxip() |
|
125 | - { |
|
126 | - $this->ee_config->core->ee_ueip_optin = true; |
|
127 | - $this->ee_config->update_espresso_config(false, false); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * Set the site opted out for UXIP |
|
133 | - */ |
|
134 | - public function setHasOptedOutForUxip() |
|
135 | - { |
|
136 | - $this->ee_config->core->ee_ueip_optin = false; |
|
137 | - $this->ee_config->update_espresso_config(false, false); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - public function setHasNotifiedAboutUxip() |
|
142 | - { |
|
143 | - $this->ee_config->core->ee_ueip_has_notified = true; |
|
144 | - $this->ee_config->update_espresso_config(false, false); |
|
145 | - } |
|
19 | + /** |
|
20 | + * @var EE_Network_Config |
|
21 | + */ |
|
22 | + private $network_config; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * @var EE_Config |
|
27 | + */ |
|
28 | + private $ee_config; |
|
29 | + |
|
30 | + |
|
31 | + public function __construct(EE_Network_Config $network_config, EE_Config $ee_config) |
|
32 | + { |
|
33 | + $this->network_config = $network_config; |
|
34 | + $this->ee_config = $ee_config; |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Get the site license key for the site. |
|
40 | + */ |
|
41 | + public function siteLicenseKey() |
|
42 | + { |
|
43 | + return $this->network_config->core->site_license_key; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + public function i18nDomain() |
|
48 | + { |
|
49 | + return 'event_espresso'; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + public function checkPeriod() |
|
54 | + { |
|
55 | + return 24; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + public function optionKey() |
|
60 | + { |
|
61 | + return 'ee_site_license_key'; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + public function optionsPageSlug() |
|
66 | + { |
|
67 | + return 'espresso_general_settings'; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + public function hostServerUrl() |
|
72 | + { |
|
73 | + return defined('PUE_UPDATES_ENDPOINT') |
|
74 | + ? PUE_UPDATES_ENDPOINT |
|
75 | + : 'https://eventespresso.com'; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + public function pluginSlug() |
|
80 | + { |
|
81 | + // Note: PUE uses a simple preg_match to determine what type is currently installed based on version number. |
|
82 | + // So it's important that you use a key for the version type that is unique and not found in another key. |
|
83 | + // For example: |
|
84 | + // $plugin_slug['premium']['p'] = 'some-premium-slug'; |
|
85 | + // $plugin_slug['prerelease']['pr'] = 'some-pre-release-slug'; |
|
86 | + // The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr ) |
|
87 | + // so doing something like: |
|
88 | + // $plugin_slug['premium']['p'] = 'some-premium-slug'; |
|
89 | + // $plugin_slug['prerelease']['b'] = 'some-pre-release-slug'; |
|
90 | + // ..WOULD work! |
|
91 | + return array( |
|
92 | + 'free' => array('decaf' => 'event-espresso-core-decaf'), |
|
93 | + 'premium' => array('p' => 'event-espresso-core-reg'), |
|
94 | + 'prerelease' => array('beta' => 'event-espresso-core-pr'), |
|
95 | + ); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Return whether the site is opted in for UXIP or not. |
|
101 | + * |
|
102 | + * @return bool |
|
103 | + */ |
|
104 | + public function isOptedInForUxip() |
|
105 | + { |
|
106 | + return filter_var($this->ee_config->core->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Return whether the site has been notified about UXIP or not. |
|
112 | + * |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | + public function hasNotifiedForUxip() |
|
116 | + { |
|
117 | + return filter_var($this->ee_config->core->ee_ueip_has_notified, FILTER_VALIDATE_BOOLEAN); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Set the site opted in for UXIP. |
|
123 | + */ |
|
124 | + public function setHasOptedInForUxip() |
|
125 | + { |
|
126 | + $this->ee_config->core->ee_ueip_optin = true; |
|
127 | + $this->ee_config->update_espresso_config(false, false); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * Set the site opted out for UXIP |
|
133 | + */ |
|
134 | + public function setHasOptedOutForUxip() |
|
135 | + { |
|
136 | + $this->ee_config->core->ee_ueip_optin = false; |
|
137 | + $this->ee_config->update_espresso_config(false, false); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + public function setHasNotifiedAboutUxip() |
|
142 | + { |
|
143 | + $this->ee_config->core->ee_ueip_has_notified = true; |
|
144 | + $this->ee_config->update_espresso_config(false, false); |
|
145 | + } |
|
146 | 146 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function addAlias(ClassAlias $alias) |
99 | 99 | { |
100 | - $this->aliases[ $alias->alias() ] = $alias; |
|
100 | + $this->aliases[$alias->alias()] = $alias; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function resolveAlias($param_fqcn) |
108 | 108 | { |
109 | - return isset($this->aliases[ $param_fqcn ]) |
|
110 | - ? $this->aliases[ $param_fqcn ]->fqcn() |
|
109 | + return isset($this->aliases[$param_fqcn]) |
|
110 | + ? $this->aliases[$param_fqcn]->fqcn() |
|
111 | 111 | : $this->classCache()->getFqnForAlias($param_fqcn); |
112 | 112 | } |
113 | 113 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | $this->resolveDependenciesForClass($param_class); |
171 | 171 | } |
172 | 172 | $param_class = $this->resolveAlias($param_class); |
173 | - $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
173 | + $dependencies[$param_class] = EE_Dependency_Map::load_from_cache; |
|
174 | 174 | } |
175 | 175 | $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
176 | 176 | } |
@@ -23,155 +23,155 @@ |
||
23 | 23 | abstract class DependencyResolver implements DependencyResolverInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var Mirror $mirror |
|
28 | - */ |
|
29 | - private $mirror; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var ClassInterfaceCache $class_cache |
|
33 | - */ |
|
34 | - private $class_cache; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var EE_Dependency_Map $dependency_map |
|
38 | - */ |
|
39 | - private $dependency_map; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var ClassAlias[] $aliases |
|
43 | - */ |
|
44 | - protected $aliases = array(); |
|
45 | - |
|
46 | - /** |
|
47 | - * @var array $namespace_roots |
|
48 | - */ |
|
49 | - protected $namespace_roots = array(); |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * RouteMatchSpecificationDependencyResolver constructor. |
|
54 | - * |
|
55 | - * @param Mirror $mirror |
|
56 | - * @param ClassInterfaceCache $class_cache |
|
57 | - * @param EE_Dependency_Map $dependency_map |
|
58 | - */ |
|
59 | - public function __construct( |
|
60 | - Mirror $mirror, |
|
61 | - ClassInterfaceCache $class_cache, |
|
62 | - EE_Dependency_Map $dependency_map |
|
63 | - ) { |
|
64 | - $this->mirror = $mirror; |
|
65 | - $this->class_cache = $class_cache; |
|
66 | - $this->dependency_map = $dependency_map; |
|
67 | - $this->initialize(); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @return Mirror |
|
72 | - */ |
|
73 | - public function mirror() |
|
74 | - { |
|
75 | - return $this->mirror; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @return ClassInterfaceCache |
|
80 | - */ |
|
81 | - public function classCache() |
|
82 | - { |
|
83 | - return $this->class_cache; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @return EE_Dependency_Map |
|
88 | - */ |
|
89 | - public function dependencyMap() |
|
90 | - { |
|
91 | - return $this->dependency_map; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @param ClassAlias $alias |
|
96 | - * @throws InvalidAliasException |
|
97 | - */ |
|
98 | - public function addAlias(ClassAlias $alias) |
|
99 | - { |
|
100 | - $this->aliases[ $alias->alias() ] = $alias; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function resolveAlias($param_fqcn) |
|
108 | - { |
|
109 | - return isset($this->aliases[ $param_fqcn ]) |
|
110 | - ? $this->aliases[ $param_fqcn ]->fqcn() |
|
111 | - : $this->classCache()->getFqnForAlias($param_fqcn); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Primarily used to indicate the namespace root for composite objects |
|
116 | - * so that dependencies requiring the same DependencyResolver can be acquired |
|
117 | - * for example: |
|
118 | - * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C |
|
119 | - * may all implement Vendor\path\to\Interface, |
|
120 | - * but Vendor\path\to\class\C could be a composite object |
|
121 | - * that requires Vendor\path\to\class\A and Vendor\path\to\class\B, |
|
122 | - * and needs both of those dependencies resolved, which would therefore require |
|
123 | - * the use of the same DependencyResolver. |
|
124 | - * |
|
125 | - * By specifying a namespace root of "Vendor\path\to\", |
|
126 | - * then all classes that are descendants of that namespace |
|
127 | - * will use DependencyResolver to acquire the classes they need |
|
128 | - * |
|
129 | - * @param string $namespace_root Partial namespace used for detecting other classes |
|
130 | - * that should employ this same DependencyResolver |
|
131 | - */ |
|
132 | - public function addNamespaceRoot($namespace_root) |
|
133 | - { |
|
134 | - $this->namespace_roots[] = $namespace_root; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Returns true if the parameter FQCN belongs to one of |
|
139 | - * the namespaces that utilizes this DependencyResolver |
|
140 | - * |
|
141 | - * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
142 | - * @return boolean |
|
143 | - * @since 4.9.71.p |
|
144 | - */ |
|
145 | - public function dependencyRecursionExists($param_fqcn) |
|
146 | - { |
|
147 | - foreach ($this->namespace_roots as $namespace_root) { |
|
148 | - if (strpos($param_fqcn, $namespace_root) !== false) { |
|
149 | - return true; |
|
150 | - } |
|
151 | - } |
|
152 | - return false; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @param string $fqcn Fully Qualified Class Name |
|
158 | - * @throws InvalidDataTypeException |
|
159 | - * @throws ReflectionException |
|
160 | - * @since 4.9.71.p |
|
161 | - */ |
|
162 | - public function resolveDependenciesForClass($fqcn) |
|
163 | - { |
|
164 | - $dependencies = array(); |
|
165 | - $params = $this->mirror()->getParameters($fqcn); |
|
166 | - foreach ($params as $index => $param) { |
|
167 | - // is this a dependency for a specific class ? |
|
168 | - $param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index); |
|
169 | - if ($this->dependencyRecursionExists($param_class)) { |
|
170 | - $this->resolveDependenciesForClass($param_class); |
|
171 | - } |
|
172 | - $param_class = $this->resolveAlias($param_class); |
|
173 | - $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
174 | - } |
|
175 | - $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
|
176 | - } |
|
26 | + /** |
|
27 | + * @var Mirror $mirror |
|
28 | + */ |
|
29 | + private $mirror; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var ClassInterfaceCache $class_cache |
|
33 | + */ |
|
34 | + private $class_cache; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var EE_Dependency_Map $dependency_map |
|
38 | + */ |
|
39 | + private $dependency_map; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var ClassAlias[] $aliases |
|
43 | + */ |
|
44 | + protected $aliases = array(); |
|
45 | + |
|
46 | + /** |
|
47 | + * @var array $namespace_roots |
|
48 | + */ |
|
49 | + protected $namespace_roots = array(); |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * RouteMatchSpecificationDependencyResolver constructor. |
|
54 | + * |
|
55 | + * @param Mirror $mirror |
|
56 | + * @param ClassInterfaceCache $class_cache |
|
57 | + * @param EE_Dependency_Map $dependency_map |
|
58 | + */ |
|
59 | + public function __construct( |
|
60 | + Mirror $mirror, |
|
61 | + ClassInterfaceCache $class_cache, |
|
62 | + EE_Dependency_Map $dependency_map |
|
63 | + ) { |
|
64 | + $this->mirror = $mirror; |
|
65 | + $this->class_cache = $class_cache; |
|
66 | + $this->dependency_map = $dependency_map; |
|
67 | + $this->initialize(); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @return Mirror |
|
72 | + */ |
|
73 | + public function mirror() |
|
74 | + { |
|
75 | + return $this->mirror; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @return ClassInterfaceCache |
|
80 | + */ |
|
81 | + public function classCache() |
|
82 | + { |
|
83 | + return $this->class_cache; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @return EE_Dependency_Map |
|
88 | + */ |
|
89 | + public function dependencyMap() |
|
90 | + { |
|
91 | + return $this->dependency_map; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @param ClassAlias $alias |
|
96 | + * @throws InvalidAliasException |
|
97 | + */ |
|
98 | + public function addAlias(ClassAlias $alias) |
|
99 | + { |
|
100 | + $this->aliases[ $alias->alias() ] = $alias; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function resolveAlias($param_fqcn) |
|
108 | + { |
|
109 | + return isset($this->aliases[ $param_fqcn ]) |
|
110 | + ? $this->aliases[ $param_fqcn ]->fqcn() |
|
111 | + : $this->classCache()->getFqnForAlias($param_fqcn); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Primarily used to indicate the namespace root for composite objects |
|
116 | + * so that dependencies requiring the same DependencyResolver can be acquired |
|
117 | + * for example: |
|
118 | + * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C |
|
119 | + * may all implement Vendor\path\to\Interface, |
|
120 | + * but Vendor\path\to\class\C could be a composite object |
|
121 | + * that requires Vendor\path\to\class\A and Vendor\path\to\class\B, |
|
122 | + * and needs both of those dependencies resolved, which would therefore require |
|
123 | + * the use of the same DependencyResolver. |
|
124 | + * |
|
125 | + * By specifying a namespace root of "Vendor\path\to\", |
|
126 | + * then all classes that are descendants of that namespace |
|
127 | + * will use DependencyResolver to acquire the classes they need |
|
128 | + * |
|
129 | + * @param string $namespace_root Partial namespace used for detecting other classes |
|
130 | + * that should employ this same DependencyResolver |
|
131 | + */ |
|
132 | + public function addNamespaceRoot($namespace_root) |
|
133 | + { |
|
134 | + $this->namespace_roots[] = $namespace_root; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Returns true if the parameter FQCN belongs to one of |
|
139 | + * the namespaces that utilizes this DependencyResolver |
|
140 | + * |
|
141 | + * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
142 | + * @return boolean |
|
143 | + * @since 4.9.71.p |
|
144 | + */ |
|
145 | + public function dependencyRecursionExists($param_fqcn) |
|
146 | + { |
|
147 | + foreach ($this->namespace_roots as $namespace_root) { |
|
148 | + if (strpos($param_fqcn, $namespace_root) !== false) { |
|
149 | + return true; |
|
150 | + } |
|
151 | + } |
|
152 | + return false; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @param string $fqcn Fully Qualified Class Name |
|
158 | + * @throws InvalidDataTypeException |
|
159 | + * @throws ReflectionException |
|
160 | + * @since 4.9.71.p |
|
161 | + */ |
|
162 | + public function resolveDependenciesForClass($fqcn) |
|
163 | + { |
|
164 | + $dependencies = array(); |
|
165 | + $params = $this->mirror()->getParameters($fqcn); |
|
166 | + foreach ($params as $index => $param) { |
|
167 | + // is this a dependency for a specific class ? |
|
168 | + $param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index); |
|
169 | + if ($this->dependencyRecursionExists($param_class)) { |
|
170 | + $this->resolveDependenciesForClass($param_class); |
|
171 | + } |
|
172 | + $param_class = $this->resolveAlias($param_class); |
|
173 | + $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
174 | + } |
|
175 | + $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
|
176 | + } |
|
177 | 177 | } |
@@ -15,145 +15,145 @@ |
||
15 | 15 | class CustomTaxonomyDefinitions |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var array $taxonomies |
|
20 | - */ |
|
21 | - private $taxonomies; |
|
18 | + /** |
|
19 | + * @var array $taxonomies |
|
20 | + */ |
|
21 | + private $taxonomies; |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * EspressoCustomPostTypeDefinitions constructor. |
|
26 | - */ |
|
27 | - public function __construct() |
|
28 | - { |
|
29 | - $this->setTaxonomies(); |
|
30 | - add_filter('pre_term_description', array($this, 'filterCustomTermDescription'), 1, 2); |
|
31 | - } |
|
24 | + /** |
|
25 | + * EspressoCustomPostTypeDefinitions constructor. |
|
26 | + */ |
|
27 | + public function __construct() |
|
28 | + { |
|
29 | + $this->setTaxonomies(); |
|
30 | + add_filter('pre_term_description', array($this, 'filterCustomTermDescription'), 1, 2); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - private function setTaxonomies() |
|
35 | - { |
|
36 | - $this->taxonomies = array( |
|
37 | - 'espresso_event_categories' => array( |
|
38 | - 'singular_name' => esc_html__('Event Category', 'event_espresso'), |
|
39 | - 'plural_name' => esc_html__('Event Categories', 'event_espresso'), |
|
40 | - 'args' => array( |
|
41 | - 'public' => true, |
|
42 | - 'show_in_nav_menus' => true, |
|
43 | - 'show_in_rest' => true, |
|
44 | - 'capabilities' => array( |
|
45 | - 'manage_terms' => 'ee_manage_event_categories', |
|
46 | - 'edit_terms' => 'ee_edit_event_category', |
|
47 | - 'delete_terms' => 'ee_delete_event_category', |
|
48 | - 'assign_terms' => 'ee_assign_event_category', |
|
49 | - ), |
|
50 | - 'rewrite' => array( |
|
51 | - 'slug' => EEH_URL::slugify( |
|
52 | - __('event-category', 'event_espresso'), |
|
53 | - 'event-category' |
|
54 | - ) |
|
55 | - ), |
|
56 | - ), |
|
57 | - ), |
|
58 | - 'espresso_venue_categories' => array( |
|
59 | - 'singular_name' => esc_html__('Venue Category', 'event_espresso'), |
|
60 | - 'plural_name' => esc_html__('Venue Categories', 'event_espresso'), |
|
61 | - 'args' => array( |
|
62 | - 'public' => true, |
|
63 | - 'show_in_nav_menus' => false, // by default this doesn't show for decaf |
|
64 | - 'show_in_rest' => true, |
|
65 | - 'capabilities' => array( |
|
66 | - 'manage_terms' => 'ee_manage_venue_categories', |
|
67 | - 'edit_terms' => 'ee_edit_venue_category', |
|
68 | - 'delete_terms' => 'ee_delete_venue_category', |
|
69 | - 'assign_terms' => 'ee_assign_venue_category', |
|
70 | - ), |
|
71 | - 'rewrite' => array( |
|
72 | - 'slug' => EEH_URL::slugify( |
|
73 | - __('venue-category', 'event_espresso'), |
|
74 | - 'venue-category' |
|
75 | - ) |
|
76 | - ), |
|
77 | - ), |
|
78 | - ), |
|
79 | - 'espresso_event_type' => array( |
|
80 | - 'singular_name' => esc_html__('Event Type', 'event_espresso'), |
|
81 | - 'plural_name' => esc_html__('Event Types', 'event_espresso'), |
|
82 | - 'args' => array( |
|
83 | - 'public' => true, |
|
84 | - 'show_ui' => false, |
|
85 | - 'show_in_rest' => true, |
|
86 | - 'capabilities' => array( |
|
87 | - 'manage_terms' => 'ee_read_event_type', |
|
88 | - 'edit_terms' => 'ee_edit_event_type', |
|
89 | - 'delete_terms' => 'ee_delete_event_type', |
|
90 | - 'assign_terms' => 'ee_assign_event_type', |
|
91 | - ), |
|
92 | - 'rewrite' => array( |
|
93 | - 'slug' => EEH_URL::slugify( |
|
94 | - __('event-type', 'event_espresso'), |
|
95 | - 'event-type' |
|
96 | - ) |
|
97 | - ), |
|
98 | - 'hierarchical' => true, |
|
99 | - ), |
|
100 | - ), |
|
101 | - ); |
|
102 | - } |
|
34 | + private function setTaxonomies() |
|
35 | + { |
|
36 | + $this->taxonomies = array( |
|
37 | + 'espresso_event_categories' => array( |
|
38 | + 'singular_name' => esc_html__('Event Category', 'event_espresso'), |
|
39 | + 'plural_name' => esc_html__('Event Categories', 'event_espresso'), |
|
40 | + 'args' => array( |
|
41 | + 'public' => true, |
|
42 | + 'show_in_nav_menus' => true, |
|
43 | + 'show_in_rest' => true, |
|
44 | + 'capabilities' => array( |
|
45 | + 'manage_terms' => 'ee_manage_event_categories', |
|
46 | + 'edit_terms' => 'ee_edit_event_category', |
|
47 | + 'delete_terms' => 'ee_delete_event_category', |
|
48 | + 'assign_terms' => 'ee_assign_event_category', |
|
49 | + ), |
|
50 | + 'rewrite' => array( |
|
51 | + 'slug' => EEH_URL::slugify( |
|
52 | + __('event-category', 'event_espresso'), |
|
53 | + 'event-category' |
|
54 | + ) |
|
55 | + ), |
|
56 | + ), |
|
57 | + ), |
|
58 | + 'espresso_venue_categories' => array( |
|
59 | + 'singular_name' => esc_html__('Venue Category', 'event_espresso'), |
|
60 | + 'plural_name' => esc_html__('Venue Categories', 'event_espresso'), |
|
61 | + 'args' => array( |
|
62 | + 'public' => true, |
|
63 | + 'show_in_nav_menus' => false, // by default this doesn't show for decaf |
|
64 | + 'show_in_rest' => true, |
|
65 | + 'capabilities' => array( |
|
66 | + 'manage_terms' => 'ee_manage_venue_categories', |
|
67 | + 'edit_terms' => 'ee_edit_venue_category', |
|
68 | + 'delete_terms' => 'ee_delete_venue_category', |
|
69 | + 'assign_terms' => 'ee_assign_venue_category', |
|
70 | + ), |
|
71 | + 'rewrite' => array( |
|
72 | + 'slug' => EEH_URL::slugify( |
|
73 | + __('venue-category', 'event_espresso'), |
|
74 | + 'venue-category' |
|
75 | + ) |
|
76 | + ), |
|
77 | + ), |
|
78 | + ), |
|
79 | + 'espresso_event_type' => array( |
|
80 | + 'singular_name' => esc_html__('Event Type', 'event_espresso'), |
|
81 | + 'plural_name' => esc_html__('Event Types', 'event_espresso'), |
|
82 | + 'args' => array( |
|
83 | + 'public' => true, |
|
84 | + 'show_ui' => false, |
|
85 | + 'show_in_rest' => true, |
|
86 | + 'capabilities' => array( |
|
87 | + 'manage_terms' => 'ee_read_event_type', |
|
88 | + 'edit_terms' => 'ee_edit_event_type', |
|
89 | + 'delete_terms' => 'ee_delete_event_type', |
|
90 | + 'assign_terms' => 'ee_assign_event_type', |
|
91 | + ), |
|
92 | + 'rewrite' => array( |
|
93 | + 'slug' => EEH_URL::slugify( |
|
94 | + __('event-type', 'event_espresso'), |
|
95 | + 'event-type' |
|
96 | + ) |
|
97 | + ), |
|
98 | + 'hierarchical' => true, |
|
99 | + ), |
|
100 | + ), |
|
101 | + ); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | - /** |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - public function getCustomTaxonomyDefinitions() |
|
109 | - { |
|
110 | - return (array) apply_filters( |
|
111 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
112 | - // legacy filter applied for now, |
|
113 | - // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
114 | - apply_filters( |
|
115 | - 'FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', |
|
116 | - $this->taxonomies |
|
117 | - ) |
|
118 | - ); |
|
119 | - } |
|
105 | + /** |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + public function getCustomTaxonomyDefinitions() |
|
109 | + { |
|
110 | + return (array) apply_filters( |
|
111 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
112 | + // legacy filter applied for now, |
|
113 | + // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
114 | + apply_filters( |
|
115 | + 'FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', |
|
116 | + $this->taxonomies |
|
117 | + ) |
|
118 | + ); |
|
119 | + } |
|
120 | 120 | |
121 | 121 | |
122 | - /** |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function getCustomTaxonomySlugs() |
|
126 | - { |
|
127 | - return array_keys($this->getCustomTaxonomyDefinitions()); |
|
128 | - } |
|
122 | + /** |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function getCustomTaxonomySlugs() |
|
126 | + { |
|
127 | + return array_keys($this->getCustomTaxonomyDefinitions()); |
|
128 | + } |
|
129 | 129 | |
130 | 130 | |
131 | - /** |
|
132 | - * By default, WordPress strips all html from term taxonomy description content. |
|
133 | - * The purpose of this method is to remove that restriction |
|
134 | - * and ensure that we still run ee term taxonomy descriptions |
|
135 | - * through some full html sanitization equivalent to the post content field. |
|
136 | - * So first we remove default filter for term description |
|
137 | - * but we have to do this earlier before wp sets their own filter |
|
138 | - * because they just set a global filter on all term descriptions |
|
139 | - * before the custom term description filter. |
|
140 | - * Really sux. |
|
141 | - * |
|
142 | - * @param string $description The description content. |
|
143 | - * @param string $taxonomy The taxonomy name for the taxonomy being filtered. |
|
144 | - * @return string |
|
145 | - */ |
|
146 | - public function filterCustomTermDescription($description, $taxonomy) |
|
147 | - { |
|
148 | - // get a list of EE taxonomies |
|
149 | - $custom_taxonomies = $this->getCustomTaxonomySlugs(); |
|
150 | - // only do our own thing if the taxonomy listed is an ee taxonomy. |
|
151 | - if (in_array($taxonomy, $custom_taxonomies, true)) { |
|
152 | - // remove default wp filter |
|
153 | - remove_filter('pre_term_description', 'wp_filter_kses'); |
|
154 | - // sanitize THIS content. |
|
155 | - $description = wp_kses($description, wp_kses_allowed_html('post')); |
|
156 | - } |
|
157 | - return $description; |
|
158 | - } |
|
131 | + /** |
|
132 | + * By default, WordPress strips all html from term taxonomy description content. |
|
133 | + * The purpose of this method is to remove that restriction |
|
134 | + * and ensure that we still run ee term taxonomy descriptions |
|
135 | + * through some full html sanitization equivalent to the post content field. |
|
136 | + * So first we remove default filter for term description |
|
137 | + * but we have to do this earlier before wp sets their own filter |
|
138 | + * because they just set a global filter on all term descriptions |
|
139 | + * before the custom term description filter. |
|
140 | + * Really sux. |
|
141 | + * |
|
142 | + * @param string $description The description content. |
|
143 | + * @param string $taxonomy The taxonomy name for the taxonomy being filtered. |
|
144 | + * @return string |
|
145 | + */ |
|
146 | + public function filterCustomTermDescription($description, $taxonomy) |
|
147 | + { |
|
148 | + // get a list of EE taxonomies |
|
149 | + $custom_taxonomies = $this->getCustomTaxonomySlugs(); |
|
150 | + // only do our own thing if the taxonomy listed is an ee taxonomy. |
|
151 | + if (in_array($taxonomy, $custom_taxonomies, true)) { |
|
152 | + // remove default wp filter |
|
153 | + remove_filter('pre_term_description', 'wp_filter_kses'); |
|
154 | + // sanitize THIS content. |
|
155 | + $description = wp_kses($description, wp_kses_allowed_html('post')); |
|
156 | + } |
|
157 | + return $description; |
|
158 | + } |
|
159 | 159 | } |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | * allowed) |
561 | 561 | * |
562 | 562 | * @param string $datetime_string mysql timestamp in UTC |
563 | - * @return mixed null | DateTime |
|
563 | + * @return null|DbSafeDateTime null | DateTime |
|
564 | 564 | * @throws \EE_Error |
565 | 565 | */ |
566 | 566 | public function prepare_for_set_from_db($datetime_string) |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | * |
713 | 713 | * @param \DateTimeZone $DateTimeZone |
714 | 714 | * @param int $time |
715 | - * @return mixed |
|
715 | + * @return integer |
|
716 | 716 | * @throws \DomainException |
717 | 717 | */ |
718 | 718 | public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
@@ -753,7 +753,7 @@ discard block |
||
753 | 753 | /** |
754 | 754 | * Gets the default datetime object from the field's default time |
755 | 755 | * @since 4.9.66.p |
756 | - * @return DbSafeDateTime|null |
|
756 | + * @return DateTime|null |
|
757 | 757 | * @throws InvalidArgumentException |
758 | 758 | * @throws InvalidDataTypeException |
759 | 759 | * @throws InvalidInterfaceException |
@@ -15,757 +15,757 @@ |
||
15 | 15 | class EE_Datetime_Field extends EE_Model_Field_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
20 | - * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
21 | - * |
|
22 | - * @type string unix_timestamp_regex |
|
23 | - */ |
|
24 | - const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @type string mysql_timestamp_format |
|
28 | - */ |
|
29 | - const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @type string mysql_date_format |
|
33 | - */ |
|
34 | - const mysql_date_format = 'Y-m-d'; |
|
35 | - |
|
36 | - /** |
|
37 | - * @type string mysql_time_format |
|
38 | - */ |
|
39 | - const mysql_time_format = 'H:i:s'; |
|
40 | - |
|
41 | - /** |
|
42 | - * Const for using in the default value. If the field's default is set to this, |
|
43 | - * then we will return the time of calling `get_default_value()`, not |
|
44 | - * just the current time at construction |
|
45 | - */ |
|
46 | - const now = 'now'; |
|
47 | - |
|
48 | - /** |
|
49 | - * The following properties hold the default formats for date and time. |
|
50 | - * Defaults are set via the constructor and can be overridden on class instantiation. |
|
51 | - * However they can also be overridden later by the set_format() method |
|
52 | - * (and corresponding set_date_format, set_time_format methods); |
|
53 | - */ |
|
54 | - /** |
|
55 | - * @type string $_date_format |
|
56 | - */ |
|
57 | - protected $_date_format = ''; |
|
58 | - |
|
59 | - /** |
|
60 | - * @type string $_time_format |
|
61 | - */ |
|
62 | - protected $_time_format = ''; |
|
63 | - |
|
64 | - /** |
|
65 | - * @type string $_pretty_date_format |
|
66 | - */ |
|
67 | - protected $_pretty_date_format = ''; |
|
68 | - |
|
69 | - /** |
|
70 | - * @type string $_pretty_time_format |
|
71 | - */ |
|
72 | - protected $_pretty_time_format = ''; |
|
73 | - |
|
74 | - /** |
|
75 | - * @type DateTimeZone $_DateTimeZone |
|
76 | - */ |
|
77 | - protected $_DateTimeZone; |
|
78 | - |
|
79 | - /** |
|
80 | - * @type DateTimeZone $_UTC_DateTimeZone |
|
81 | - */ |
|
82 | - protected $_UTC_DateTimeZone; |
|
83 | - |
|
84 | - /** |
|
85 | - * @type DateTimeZone $_blog_DateTimeZone |
|
86 | - */ |
|
87 | - protected $_blog_DateTimeZone; |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
92 | - * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
93 | - * and time returned via getters. |
|
94 | - * |
|
95 | - * @var mixed (null|string) |
|
96 | - */ |
|
97 | - protected $_date_time_output; |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * timezone string |
|
102 | - * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
103 | - * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
104 | - * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
105 | - * |
|
106 | - * @var string |
|
107 | - */ |
|
108 | - protected $_timezone_string; |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
113 | - * offsets for comparison purposes). |
|
114 | - * |
|
115 | - * @var int |
|
116 | - */ |
|
117 | - protected $_blog_offset; |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @param string $table_column |
|
123 | - * @param string $nice_name |
|
124 | - * @param bool $nullable |
|
125 | - * @param string $default_value |
|
126 | - * @param string $timezone_string |
|
127 | - * @param string $date_format |
|
128 | - * @param string $time_format |
|
129 | - * @param string $pretty_date_format |
|
130 | - * @param string $pretty_time_format |
|
131 | - * @throws EE_Error |
|
132 | - * @throws InvalidArgumentException |
|
133 | - */ |
|
134 | - public function __construct( |
|
135 | - $table_column, |
|
136 | - $nice_name, |
|
137 | - $nullable, |
|
138 | - $default_value, |
|
139 | - $timezone_string = '', |
|
140 | - $date_format = '', |
|
141 | - $time_format = '', |
|
142 | - $pretty_date_format = '', |
|
143 | - $pretty_time_format = '' |
|
144 | - ) { |
|
145 | - |
|
146 | - $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
147 | - $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
148 | - $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
149 | - $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
150 | - |
|
151 | - parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
152 | - $this->set_timezone($timezone_string); |
|
153 | - $this->setSchemaFormat('date-time'); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @return DateTimeZone |
|
159 | - * @throws \EE_Error |
|
160 | - */ |
|
161 | - public function get_UTC_DateTimeZone() |
|
162 | - { |
|
163 | - return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
164 | - ? $this->_UTC_DateTimeZone |
|
165 | - : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @return DateTimeZone |
|
171 | - * @throws \EE_Error |
|
172 | - */ |
|
173 | - public function get_blog_DateTimeZone() |
|
174 | - { |
|
175 | - return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
176 | - ? $this->_blog_DateTimeZone |
|
177 | - : $this->_create_timezone_object_from_timezone_string(''); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
183 | - * |
|
184 | - * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
185 | - * timestamp |
|
186 | - * @return DateTime |
|
187 | - */ |
|
188 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
189 | - { |
|
190 | - return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
196 | - * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
197 | - * |
|
198 | - * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
199 | - * @return string The final assembled format string. |
|
200 | - */ |
|
201 | - protected function _get_date_time_output($pretty = false) |
|
202 | - { |
|
203 | - |
|
204 | - switch ($this->_date_time_output) { |
|
205 | - case 'time': |
|
206 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
207 | - break; |
|
208 | - |
|
209 | - case 'date': |
|
210 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
211 | - break; |
|
212 | - |
|
213 | - default: |
|
214 | - return $pretty |
|
215 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
216 | - : $this->_date_format . ' ' . $this->_time_format; |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
223 | - * returned (using the format properties) |
|
224 | - * |
|
225 | - * @param string $what acceptable values are 'time' or 'date'. |
|
226 | - * Any other value will be set but will always result |
|
227 | - * in both 'date' and 'time' being returned. |
|
228 | - * @return void |
|
229 | - */ |
|
230 | - public function set_date_time_output($what = null) |
|
231 | - { |
|
232 | - $this->_date_time_output = $what; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
238 | - * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
239 | - * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
240 | - * We also set some other properties in this method. |
|
241 | - * |
|
242 | - * @param string $timezone_string A valid timezone string as described by @link |
|
243 | - * http://www.php.net/manual/en/timezones.php |
|
244 | - * @return void |
|
245 | - * @throws InvalidArgumentException |
|
246 | - * @throws InvalidDataTypeException |
|
247 | - * @throws InvalidInterfaceException |
|
248 | - */ |
|
249 | - public function set_timezone($timezone_string) |
|
250 | - { |
|
251 | - if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
252 | - // leave the timezone AS-IS if we already have one and |
|
253 | - // the function arg didn't provide one |
|
254 | - return; |
|
255 | - } |
|
256 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
257 | - $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
258 | - $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * _create_timezone_object_from_timezone_name |
|
264 | - * |
|
265 | - * @access protected |
|
266 | - * @param string $timezone_string |
|
267 | - * @return \DateTimeZone |
|
268 | - * @throws InvalidArgumentException |
|
269 | - * @throws InvalidDataTypeException |
|
270 | - * @throws InvalidInterfaceException |
|
271 | - */ |
|
272 | - protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
273 | - { |
|
274 | - return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * This just returns whatever is set for the current timezone. |
|
280 | - * |
|
281 | - * @access public |
|
282 | - * @return string timezone string |
|
283 | - */ |
|
284 | - public function get_timezone() |
|
285 | - { |
|
286 | - return $this->_timezone_string; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * set the $_date_format property |
|
292 | - * |
|
293 | - * @access public |
|
294 | - * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
295 | - * @param bool $pretty Whether to set pretty format or not. |
|
296 | - * @return void |
|
297 | - */ |
|
298 | - public function set_date_format($format, $pretty = false) |
|
299 | - { |
|
300 | - if ($pretty) { |
|
301 | - $this->_pretty_date_format = $format; |
|
302 | - } else { |
|
303 | - $this->_date_format = $format; |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * return the $_date_format property value. |
|
310 | - * |
|
311 | - * @param bool $pretty Whether to get pretty format or not. |
|
312 | - * @return string |
|
313 | - */ |
|
314 | - public function get_date_format($pretty = false) |
|
315 | - { |
|
316 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * set the $_time_format property |
|
322 | - * |
|
323 | - * @access public |
|
324 | - * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
325 | - * @param bool $pretty Whether to set pretty format or not. |
|
326 | - * @return void |
|
327 | - */ |
|
328 | - public function set_time_format($format, $pretty = false) |
|
329 | - { |
|
330 | - if ($pretty) { |
|
331 | - $this->_pretty_time_format = $format; |
|
332 | - } else { |
|
333 | - $this->_time_format = $format; |
|
334 | - } |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * return the $_time_format property value. |
|
340 | - * |
|
341 | - * @param bool $pretty Whether to get pretty format or not. |
|
342 | - * @return string |
|
343 | - */ |
|
344 | - public function get_time_format($pretty = false) |
|
345 | - { |
|
346 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * set the $_pretty_date_format property |
|
352 | - * |
|
353 | - * @access public |
|
354 | - * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
355 | - * @return void |
|
356 | - */ |
|
357 | - public function set_pretty_date_format($format) |
|
358 | - { |
|
359 | - $this->_pretty_date_format = $format; |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * set the $_pretty_time_format property |
|
365 | - * |
|
366 | - * @access public |
|
367 | - * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
368 | - * @return void |
|
369 | - */ |
|
370 | - public function set_pretty_time_format($format) |
|
371 | - { |
|
372 | - $this->_pretty_time_format = $format; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * Only sets the time portion of the datetime. |
|
378 | - * |
|
379 | - * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
380 | - * @param DateTime $current current DateTime object for the datetime field |
|
381 | - * @return DateTime |
|
382 | - */ |
|
383 | - public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
384 | - { |
|
385 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
386 | - // Otherwise parse the string. |
|
387 | - if ($time_to_set_string instanceof DateTime) { |
|
388 | - $parsed = array( |
|
389 | - 'hour' => $time_to_set_string->format('H'), |
|
390 | - 'minute' => $time_to_set_string->format('i'), |
|
391 | - 'second' => $time_to_set_string->format('s'), |
|
392 | - ); |
|
393 | - } else { |
|
394 | - // parse incoming string |
|
395 | - $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
396 | - } |
|
397 | - EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone); |
|
398 | - return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * Only sets the date portion of the datetime. |
|
404 | - * |
|
405 | - * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
406 | - * @param DateTime $current current DateTime object for the datetime field |
|
407 | - * @return DateTime |
|
408 | - */ |
|
409 | - public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
410 | - { |
|
411 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
412 | - // Otherwise parse the string. |
|
413 | - if ($date_to_set_string instanceof DateTime) { |
|
414 | - $parsed = array( |
|
415 | - 'year' => $date_to_set_string->format('Y'), |
|
416 | - 'month' => $date_to_set_string->format('m'), |
|
417 | - 'day' => $date_to_set_string->format('d'), |
|
418 | - ); |
|
419 | - } else { |
|
420 | - // parse incoming string |
|
421 | - $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
422 | - } |
|
423 | - EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone); |
|
424 | - return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
430 | - * datetime gets to this stage it should ALREADY be in UTC time |
|
431 | - * |
|
432 | - * @param DateTime $DateTime |
|
433 | - * @return string formatted date time for given timezone |
|
434 | - * @throws \EE_Error |
|
435 | - */ |
|
436 | - public function prepare_for_get($DateTime) |
|
437 | - { |
|
438 | - return $this->_prepare_for_display($DateTime); |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
444 | - * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
445 | - * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
446 | - * abbreviation to the date_string. |
|
447 | - * |
|
448 | - * @param mixed $DateTime |
|
449 | - * @param null $schema |
|
450 | - * @return string |
|
451 | - * @throws \EE_Error |
|
452 | - */ |
|
453 | - public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
454 | - { |
|
455 | - return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
461 | - * timezone). |
|
462 | - * |
|
463 | - * @param DateTime $DateTime |
|
464 | - * @param bool|string $schema |
|
465 | - * @return string |
|
466 | - * @throws \EE_Error |
|
467 | - */ |
|
468 | - protected function _prepare_for_display($DateTime, $schema = false) |
|
469 | - { |
|
470 | - if (! $DateTime instanceof DateTime) { |
|
471 | - if ($this->_nullable) { |
|
472 | - return ''; |
|
473 | - } else { |
|
474 | - if (WP_DEBUG) { |
|
475 | - throw new EE_Error( |
|
476 | - sprintf( |
|
477 | - __( |
|
478 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
479 | - 'event_espresso' |
|
480 | - ), |
|
481 | - $this->_nicename |
|
482 | - ) |
|
483 | - ); |
|
484 | - } else { |
|
485 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
486 | - EE_Error::add_error( |
|
487 | - sprintf( |
|
488 | - __( |
|
489 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
490 | - 'event_espresso' |
|
491 | - ), |
|
492 | - $this->_nicename |
|
493 | - ) |
|
494 | - ); |
|
495 | - } |
|
496 | - } |
|
497 | - } |
|
498 | - $format_string = $this->_get_date_time_output($schema); |
|
499 | - EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone); |
|
500 | - if ($schema) { |
|
501 | - if ($this->_display_timezone()) { |
|
502 | - // must be explicit because schema could equal true. |
|
503 | - if ($schema === 'no_html') { |
|
504 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
505 | - } else { |
|
506 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
507 | - } |
|
508 | - } else { |
|
509 | - $timezone_string = ''; |
|
510 | - } |
|
511 | - |
|
512 | - return $DateTime->format($format_string) . $timezone_string; |
|
513 | - } |
|
514 | - return $DateTime->format($format_string); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
520 | - * timezone). |
|
521 | - * |
|
522 | - * @param mixed $datetime_value u |
|
523 | - * @return string mysql timestamp in UTC |
|
524 | - * @throws \EE_Error |
|
525 | - */ |
|
526 | - public function prepare_for_use_in_db($datetime_value) |
|
527 | - { |
|
528 | - // we allow an empty value or DateTime object, but nothing else. |
|
529 | - if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
530 | - throw new EE_Error( |
|
531 | - sprintf( |
|
532 | - __( |
|
533 | - 'The incoming value being prepared for setting in the database must either be empty or a php |
|
18 | + /** |
|
19 | + * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
20 | + * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
21 | + * |
|
22 | + * @type string unix_timestamp_regex |
|
23 | + */ |
|
24 | + const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @type string mysql_timestamp_format |
|
28 | + */ |
|
29 | + const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @type string mysql_date_format |
|
33 | + */ |
|
34 | + const mysql_date_format = 'Y-m-d'; |
|
35 | + |
|
36 | + /** |
|
37 | + * @type string mysql_time_format |
|
38 | + */ |
|
39 | + const mysql_time_format = 'H:i:s'; |
|
40 | + |
|
41 | + /** |
|
42 | + * Const for using in the default value. If the field's default is set to this, |
|
43 | + * then we will return the time of calling `get_default_value()`, not |
|
44 | + * just the current time at construction |
|
45 | + */ |
|
46 | + const now = 'now'; |
|
47 | + |
|
48 | + /** |
|
49 | + * The following properties hold the default formats for date and time. |
|
50 | + * Defaults are set via the constructor and can be overridden on class instantiation. |
|
51 | + * However they can also be overridden later by the set_format() method |
|
52 | + * (and corresponding set_date_format, set_time_format methods); |
|
53 | + */ |
|
54 | + /** |
|
55 | + * @type string $_date_format |
|
56 | + */ |
|
57 | + protected $_date_format = ''; |
|
58 | + |
|
59 | + /** |
|
60 | + * @type string $_time_format |
|
61 | + */ |
|
62 | + protected $_time_format = ''; |
|
63 | + |
|
64 | + /** |
|
65 | + * @type string $_pretty_date_format |
|
66 | + */ |
|
67 | + protected $_pretty_date_format = ''; |
|
68 | + |
|
69 | + /** |
|
70 | + * @type string $_pretty_time_format |
|
71 | + */ |
|
72 | + protected $_pretty_time_format = ''; |
|
73 | + |
|
74 | + /** |
|
75 | + * @type DateTimeZone $_DateTimeZone |
|
76 | + */ |
|
77 | + protected $_DateTimeZone; |
|
78 | + |
|
79 | + /** |
|
80 | + * @type DateTimeZone $_UTC_DateTimeZone |
|
81 | + */ |
|
82 | + protected $_UTC_DateTimeZone; |
|
83 | + |
|
84 | + /** |
|
85 | + * @type DateTimeZone $_blog_DateTimeZone |
|
86 | + */ |
|
87 | + protected $_blog_DateTimeZone; |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
92 | + * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
93 | + * and time returned via getters. |
|
94 | + * |
|
95 | + * @var mixed (null|string) |
|
96 | + */ |
|
97 | + protected $_date_time_output; |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * timezone string |
|
102 | + * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
103 | + * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
104 | + * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
105 | + * |
|
106 | + * @var string |
|
107 | + */ |
|
108 | + protected $_timezone_string; |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
113 | + * offsets for comparison purposes). |
|
114 | + * |
|
115 | + * @var int |
|
116 | + */ |
|
117 | + protected $_blog_offset; |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @param string $table_column |
|
123 | + * @param string $nice_name |
|
124 | + * @param bool $nullable |
|
125 | + * @param string $default_value |
|
126 | + * @param string $timezone_string |
|
127 | + * @param string $date_format |
|
128 | + * @param string $time_format |
|
129 | + * @param string $pretty_date_format |
|
130 | + * @param string $pretty_time_format |
|
131 | + * @throws EE_Error |
|
132 | + * @throws InvalidArgumentException |
|
133 | + */ |
|
134 | + public function __construct( |
|
135 | + $table_column, |
|
136 | + $nice_name, |
|
137 | + $nullable, |
|
138 | + $default_value, |
|
139 | + $timezone_string = '', |
|
140 | + $date_format = '', |
|
141 | + $time_format = '', |
|
142 | + $pretty_date_format = '', |
|
143 | + $pretty_time_format = '' |
|
144 | + ) { |
|
145 | + |
|
146 | + $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
147 | + $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
148 | + $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
149 | + $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
150 | + |
|
151 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
152 | + $this->set_timezone($timezone_string); |
|
153 | + $this->setSchemaFormat('date-time'); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @return DateTimeZone |
|
159 | + * @throws \EE_Error |
|
160 | + */ |
|
161 | + public function get_UTC_DateTimeZone() |
|
162 | + { |
|
163 | + return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
164 | + ? $this->_UTC_DateTimeZone |
|
165 | + : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @return DateTimeZone |
|
171 | + * @throws \EE_Error |
|
172 | + */ |
|
173 | + public function get_blog_DateTimeZone() |
|
174 | + { |
|
175 | + return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
176 | + ? $this->_blog_DateTimeZone |
|
177 | + : $this->_create_timezone_object_from_timezone_string(''); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
183 | + * |
|
184 | + * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
185 | + * timestamp |
|
186 | + * @return DateTime |
|
187 | + */ |
|
188 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
189 | + { |
|
190 | + return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
196 | + * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
197 | + * |
|
198 | + * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
199 | + * @return string The final assembled format string. |
|
200 | + */ |
|
201 | + protected function _get_date_time_output($pretty = false) |
|
202 | + { |
|
203 | + |
|
204 | + switch ($this->_date_time_output) { |
|
205 | + case 'time': |
|
206 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
207 | + break; |
|
208 | + |
|
209 | + case 'date': |
|
210 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
211 | + break; |
|
212 | + |
|
213 | + default: |
|
214 | + return $pretty |
|
215 | + ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
216 | + : $this->_date_format . ' ' . $this->_time_format; |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
223 | + * returned (using the format properties) |
|
224 | + * |
|
225 | + * @param string $what acceptable values are 'time' or 'date'. |
|
226 | + * Any other value will be set but will always result |
|
227 | + * in both 'date' and 'time' being returned. |
|
228 | + * @return void |
|
229 | + */ |
|
230 | + public function set_date_time_output($what = null) |
|
231 | + { |
|
232 | + $this->_date_time_output = $what; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
238 | + * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
239 | + * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
240 | + * We also set some other properties in this method. |
|
241 | + * |
|
242 | + * @param string $timezone_string A valid timezone string as described by @link |
|
243 | + * http://www.php.net/manual/en/timezones.php |
|
244 | + * @return void |
|
245 | + * @throws InvalidArgumentException |
|
246 | + * @throws InvalidDataTypeException |
|
247 | + * @throws InvalidInterfaceException |
|
248 | + */ |
|
249 | + public function set_timezone($timezone_string) |
|
250 | + { |
|
251 | + if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
252 | + // leave the timezone AS-IS if we already have one and |
|
253 | + // the function arg didn't provide one |
|
254 | + return; |
|
255 | + } |
|
256 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
257 | + $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
258 | + $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * _create_timezone_object_from_timezone_name |
|
264 | + * |
|
265 | + * @access protected |
|
266 | + * @param string $timezone_string |
|
267 | + * @return \DateTimeZone |
|
268 | + * @throws InvalidArgumentException |
|
269 | + * @throws InvalidDataTypeException |
|
270 | + * @throws InvalidInterfaceException |
|
271 | + */ |
|
272 | + protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
273 | + { |
|
274 | + return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * This just returns whatever is set for the current timezone. |
|
280 | + * |
|
281 | + * @access public |
|
282 | + * @return string timezone string |
|
283 | + */ |
|
284 | + public function get_timezone() |
|
285 | + { |
|
286 | + return $this->_timezone_string; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * set the $_date_format property |
|
292 | + * |
|
293 | + * @access public |
|
294 | + * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
295 | + * @param bool $pretty Whether to set pretty format or not. |
|
296 | + * @return void |
|
297 | + */ |
|
298 | + public function set_date_format($format, $pretty = false) |
|
299 | + { |
|
300 | + if ($pretty) { |
|
301 | + $this->_pretty_date_format = $format; |
|
302 | + } else { |
|
303 | + $this->_date_format = $format; |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * return the $_date_format property value. |
|
310 | + * |
|
311 | + * @param bool $pretty Whether to get pretty format or not. |
|
312 | + * @return string |
|
313 | + */ |
|
314 | + public function get_date_format($pretty = false) |
|
315 | + { |
|
316 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * set the $_time_format property |
|
322 | + * |
|
323 | + * @access public |
|
324 | + * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
325 | + * @param bool $pretty Whether to set pretty format or not. |
|
326 | + * @return void |
|
327 | + */ |
|
328 | + public function set_time_format($format, $pretty = false) |
|
329 | + { |
|
330 | + if ($pretty) { |
|
331 | + $this->_pretty_time_format = $format; |
|
332 | + } else { |
|
333 | + $this->_time_format = $format; |
|
334 | + } |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * return the $_time_format property value. |
|
340 | + * |
|
341 | + * @param bool $pretty Whether to get pretty format or not. |
|
342 | + * @return string |
|
343 | + */ |
|
344 | + public function get_time_format($pretty = false) |
|
345 | + { |
|
346 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * set the $_pretty_date_format property |
|
352 | + * |
|
353 | + * @access public |
|
354 | + * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
355 | + * @return void |
|
356 | + */ |
|
357 | + public function set_pretty_date_format($format) |
|
358 | + { |
|
359 | + $this->_pretty_date_format = $format; |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * set the $_pretty_time_format property |
|
365 | + * |
|
366 | + * @access public |
|
367 | + * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
368 | + * @return void |
|
369 | + */ |
|
370 | + public function set_pretty_time_format($format) |
|
371 | + { |
|
372 | + $this->_pretty_time_format = $format; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * Only sets the time portion of the datetime. |
|
378 | + * |
|
379 | + * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
380 | + * @param DateTime $current current DateTime object for the datetime field |
|
381 | + * @return DateTime |
|
382 | + */ |
|
383 | + public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
384 | + { |
|
385 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
386 | + // Otherwise parse the string. |
|
387 | + if ($time_to_set_string instanceof DateTime) { |
|
388 | + $parsed = array( |
|
389 | + 'hour' => $time_to_set_string->format('H'), |
|
390 | + 'minute' => $time_to_set_string->format('i'), |
|
391 | + 'second' => $time_to_set_string->format('s'), |
|
392 | + ); |
|
393 | + } else { |
|
394 | + // parse incoming string |
|
395 | + $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
396 | + } |
|
397 | + EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone); |
|
398 | + return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * Only sets the date portion of the datetime. |
|
404 | + * |
|
405 | + * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
406 | + * @param DateTime $current current DateTime object for the datetime field |
|
407 | + * @return DateTime |
|
408 | + */ |
|
409 | + public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
410 | + { |
|
411 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
412 | + // Otherwise parse the string. |
|
413 | + if ($date_to_set_string instanceof DateTime) { |
|
414 | + $parsed = array( |
|
415 | + 'year' => $date_to_set_string->format('Y'), |
|
416 | + 'month' => $date_to_set_string->format('m'), |
|
417 | + 'day' => $date_to_set_string->format('d'), |
|
418 | + ); |
|
419 | + } else { |
|
420 | + // parse incoming string |
|
421 | + $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
422 | + } |
|
423 | + EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone); |
|
424 | + return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
430 | + * datetime gets to this stage it should ALREADY be in UTC time |
|
431 | + * |
|
432 | + * @param DateTime $DateTime |
|
433 | + * @return string formatted date time for given timezone |
|
434 | + * @throws \EE_Error |
|
435 | + */ |
|
436 | + public function prepare_for_get($DateTime) |
|
437 | + { |
|
438 | + return $this->_prepare_for_display($DateTime); |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
444 | + * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
445 | + * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
446 | + * abbreviation to the date_string. |
|
447 | + * |
|
448 | + * @param mixed $DateTime |
|
449 | + * @param null $schema |
|
450 | + * @return string |
|
451 | + * @throws \EE_Error |
|
452 | + */ |
|
453 | + public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
454 | + { |
|
455 | + return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
461 | + * timezone). |
|
462 | + * |
|
463 | + * @param DateTime $DateTime |
|
464 | + * @param bool|string $schema |
|
465 | + * @return string |
|
466 | + * @throws \EE_Error |
|
467 | + */ |
|
468 | + protected function _prepare_for_display($DateTime, $schema = false) |
|
469 | + { |
|
470 | + if (! $DateTime instanceof DateTime) { |
|
471 | + if ($this->_nullable) { |
|
472 | + return ''; |
|
473 | + } else { |
|
474 | + if (WP_DEBUG) { |
|
475 | + throw new EE_Error( |
|
476 | + sprintf( |
|
477 | + __( |
|
478 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
479 | + 'event_espresso' |
|
480 | + ), |
|
481 | + $this->_nicename |
|
482 | + ) |
|
483 | + ); |
|
484 | + } else { |
|
485 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
486 | + EE_Error::add_error( |
|
487 | + sprintf( |
|
488 | + __( |
|
489 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
490 | + 'event_espresso' |
|
491 | + ), |
|
492 | + $this->_nicename |
|
493 | + ) |
|
494 | + ); |
|
495 | + } |
|
496 | + } |
|
497 | + } |
|
498 | + $format_string = $this->_get_date_time_output($schema); |
|
499 | + EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone); |
|
500 | + if ($schema) { |
|
501 | + if ($this->_display_timezone()) { |
|
502 | + // must be explicit because schema could equal true. |
|
503 | + if ($schema === 'no_html') { |
|
504 | + $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
505 | + } else { |
|
506 | + $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
507 | + } |
|
508 | + } else { |
|
509 | + $timezone_string = ''; |
|
510 | + } |
|
511 | + |
|
512 | + return $DateTime->format($format_string) . $timezone_string; |
|
513 | + } |
|
514 | + return $DateTime->format($format_string); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
520 | + * timezone). |
|
521 | + * |
|
522 | + * @param mixed $datetime_value u |
|
523 | + * @return string mysql timestamp in UTC |
|
524 | + * @throws \EE_Error |
|
525 | + */ |
|
526 | + public function prepare_for_use_in_db($datetime_value) |
|
527 | + { |
|
528 | + // we allow an empty value or DateTime object, but nothing else. |
|
529 | + if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
530 | + throw new EE_Error( |
|
531 | + sprintf( |
|
532 | + __( |
|
533 | + 'The incoming value being prepared for setting in the database must either be empty or a php |
|
534 | 534 | DateTime object, instead of: %1$s %2$s', |
535 | - 'event_espresso' |
|
536 | - ), |
|
537 | - '<br />', |
|
538 | - print_r($datetime_value, true) |
|
539 | - ) |
|
540 | - ); |
|
541 | - } |
|
542 | - |
|
543 | - if ($datetime_value instanceof DateTime) { |
|
544 | - if (! $datetime_value instanceof DbSafeDateTime) { |
|
545 | - $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
546 | - } |
|
547 | - EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone()); |
|
548 | - return $datetime_value->format( |
|
549 | - EE_Datetime_Field::mysql_timestamp_format |
|
550 | - ); |
|
551 | - } |
|
552 | - |
|
553 | - // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
554 | - return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
560 | - * allowed) |
|
561 | - * |
|
562 | - * @param string $datetime_string mysql timestamp in UTC |
|
563 | - * @return mixed null | DateTime |
|
564 | - * @throws \EE_Error |
|
565 | - */ |
|
566 | - public function prepare_for_set_from_db($datetime_string) |
|
567 | - { |
|
568 | - // if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
569 | - if (empty($datetime_string) && $this->_nullable) { |
|
570 | - return null; |
|
571 | - } |
|
572 | - // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
573 | - if (empty($datetime_string)) { |
|
574 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
575 | - } else { |
|
576 | - $DateTime = DbSafeDateTime::createFromFormat( |
|
577 | - EE_Datetime_Field::mysql_timestamp_format, |
|
578 | - $datetime_string, |
|
579 | - $this->get_UTC_DateTimeZone() |
|
580 | - ); |
|
581 | - } |
|
582 | - |
|
583 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
584 | - // if still no datetime object, then let's just use now |
|
585 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
586 | - } |
|
587 | - // THEN apply the field's set DateTimeZone |
|
588 | - EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone); |
|
589 | - return $DateTime; |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * All this method does is determine if we're going to display the timezone string or not on any output. |
|
595 | - * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
596 | - * If so, then true. |
|
597 | - * |
|
598 | - * @return bool true for yes false for no |
|
599 | - * @throws \EE_Error |
|
600 | - */ |
|
601 | - protected function _display_timezone() |
|
602 | - { |
|
603 | - |
|
604 | - // first let's do a comparison of timezone strings. |
|
605 | - // If they match then we can get out without any further calculations |
|
606 | - $blog_string = get_option('timezone_string'); |
|
607 | - if ($blog_string === $this->_timezone_string) { |
|
608 | - return false; |
|
609 | - } |
|
610 | - // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
611 | - $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
612 | - $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
613 | - // now compare |
|
614 | - return $blog_offset !== $this_offset; |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - /** |
|
619 | - * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
620 | - * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
621 | - * with. |
|
622 | - * |
|
623 | - * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
624 | - * in the format that is set on the date_field (or DateTime |
|
625 | - * object)! |
|
626 | - * @return DateTime |
|
627 | - */ |
|
628 | - protected function _get_date_object($date_string) |
|
629 | - { |
|
630 | - // first if this is an empty date_string and nullable is allowed, just return null. |
|
631 | - if ($this->_nullable && empty($date_string)) { |
|
632 | - return null; |
|
633 | - } |
|
634 | - |
|
635 | - // if incoming date |
|
636 | - if ($date_string instanceof DateTime) { |
|
637 | - EEH_DTT_Helper::setTimezone($date_string, $this->_DateTimeZone); |
|
638 | - return $date_string; |
|
639 | - } |
|
640 | - // if empty date_string and made it here. |
|
641 | - // Return a datetime object for now in the given timezone. |
|
642 | - if (empty($date_string)) { |
|
643 | - return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
644 | - } |
|
645 | - // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
646 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
647 | - try { |
|
648 | - // This is operating under the assumption that the incoming Unix timestamp |
|
649 | - // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
650 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
651 | - $DateTime->setTimestamp($date_string); |
|
652 | - |
|
653 | - return $DateTime; |
|
654 | - } catch (Exception $e) { |
|
655 | - // should be rare, but if things got fooled then let's just continue |
|
656 | - } |
|
657 | - } |
|
658 | - // not a unix timestamp. So we will use the set format on this object and set timezone to |
|
659 | - // create the DateTime object. |
|
660 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
661 | - try { |
|
662 | - $DateTime = DbSafeDateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
663 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
664 | - throw new EE_Error( |
|
665 | - sprintf( |
|
666 | - __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
667 | - $date_string, |
|
668 | - $format |
|
669 | - ) |
|
670 | - ); |
|
671 | - } |
|
672 | - } catch (Exception $e) { |
|
673 | - // if we made it here then likely then something went really wrong. |
|
674 | - // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
675 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
676 | - } |
|
677 | - |
|
678 | - return $DateTime; |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * get_timezone_transitions |
|
685 | - * |
|
686 | - * @param \DateTimeZone $DateTimeZone |
|
687 | - * @param int $time |
|
688 | - * @param bool $first_only |
|
689 | - * @return mixed |
|
690 | - */ |
|
691 | - public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
692 | - { |
|
693 | - return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only); |
|
694 | - } |
|
695 | - |
|
696 | - |
|
697 | - |
|
698 | - /** |
|
699 | - * get_timezone_offset |
|
700 | - * |
|
701 | - * @param \DateTimeZone $DateTimeZone |
|
702 | - * @param int $time |
|
703 | - * @return mixed |
|
704 | - * @throws \DomainException |
|
705 | - */ |
|
706 | - public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
707 | - { |
|
708 | - return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time); |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - /** |
|
713 | - * This will take an incoming timezone string and return the abbreviation for that timezone |
|
714 | - * |
|
715 | - * @param string $timezone_string |
|
716 | - * @return string abbreviation |
|
717 | - * @throws \EE_Error |
|
718 | - */ |
|
719 | - public function get_timezone_abbrev($timezone_string) |
|
720 | - { |
|
721 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
722 | - $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
723 | - |
|
724 | - return $dateTime->format('T'); |
|
725 | - } |
|
726 | - |
|
727 | - /** |
|
728 | - * Overrides the parent to allow for having a dynamic "now" value |
|
729 | - * |
|
730 | - * @return mixed |
|
731 | - */ |
|
732 | - public function get_default_value() |
|
733 | - { |
|
734 | - if ($this->_default_value === EE_Datetime_Field::now) { |
|
735 | - return time(); |
|
736 | - } else { |
|
737 | - return parent::get_default_value(); |
|
738 | - } |
|
739 | - } |
|
740 | - |
|
741 | - /** |
|
742 | - * Gets the default datetime object from the field's default time |
|
743 | - * @since 4.9.66.p |
|
744 | - * @return DbSafeDateTime|null |
|
745 | - * @throws InvalidArgumentException |
|
746 | - * @throws InvalidDataTypeException |
|
747 | - * @throws InvalidInterfaceException |
|
748 | - */ |
|
749 | - public function getDefaultDateTimeObj() |
|
750 | - { |
|
751 | - $default_raw = $this->get_default_value(); |
|
752 | - if ($default_raw instanceof DateTime) { |
|
753 | - return $default_raw; |
|
754 | - } elseif (is_null($default_raw)) { |
|
755 | - return $default_raw; |
|
756 | - } else { |
|
757 | - return new DbSafeDateTime( |
|
758 | - $this->get_default_value(), |
|
759 | - EEH_DTT_Helper::get_valid_timezone_string($this->get_timezone()) |
|
760 | - ); |
|
761 | - } |
|
762 | - } |
|
763 | - |
|
764 | - public function getSchemaDescription() |
|
765 | - { |
|
766 | - return sprintf( |
|
767 | - esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
768 | - $this->get_nicename() |
|
769 | - ); |
|
770 | - } |
|
535 | + 'event_espresso' |
|
536 | + ), |
|
537 | + '<br />', |
|
538 | + print_r($datetime_value, true) |
|
539 | + ) |
|
540 | + ); |
|
541 | + } |
|
542 | + |
|
543 | + if ($datetime_value instanceof DateTime) { |
|
544 | + if (! $datetime_value instanceof DbSafeDateTime) { |
|
545 | + $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
546 | + } |
|
547 | + EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone()); |
|
548 | + return $datetime_value->format( |
|
549 | + EE_Datetime_Field::mysql_timestamp_format |
|
550 | + ); |
|
551 | + } |
|
552 | + |
|
553 | + // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
554 | + return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
560 | + * allowed) |
|
561 | + * |
|
562 | + * @param string $datetime_string mysql timestamp in UTC |
|
563 | + * @return mixed null | DateTime |
|
564 | + * @throws \EE_Error |
|
565 | + */ |
|
566 | + public function prepare_for_set_from_db($datetime_string) |
|
567 | + { |
|
568 | + // if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
569 | + if (empty($datetime_string) && $this->_nullable) { |
|
570 | + return null; |
|
571 | + } |
|
572 | + // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
573 | + if (empty($datetime_string)) { |
|
574 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
575 | + } else { |
|
576 | + $DateTime = DbSafeDateTime::createFromFormat( |
|
577 | + EE_Datetime_Field::mysql_timestamp_format, |
|
578 | + $datetime_string, |
|
579 | + $this->get_UTC_DateTimeZone() |
|
580 | + ); |
|
581 | + } |
|
582 | + |
|
583 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
584 | + // if still no datetime object, then let's just use now |
|
585 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
586 | + } |
|
587 | + // THEN apply the field's set DateTimeZone |
|
588 | + EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone); |
|
589 | + return $DateTime; |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * All this method does is determine if we're going to display the timezone string or not on any output. |
|
595 | + * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
596 | + * If so, then true. |
|
597 | + * |
|
598 | + * @return bool true for yes false for no |
|
599 | + * @throws \EE_Error |
|
600 | + */ |
|
601 | + protected function _display_timezone() |
|
602 | + { |
|
603 | + |
|
604 | + // first let's do a comparison of timezone strings. |
|
605 | + // If they match then we can get out without any further calculations |
|
606 | + $blog_string = get_option('timezone_string'); |
|
607 | + if ($blog_string === $this->_timezone_string) { |
|
608 | + return false; |
|
609 | + } |
|
610 | + // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
611 | + $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
612 | + $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
613 | + // now compare |
|
614 | + return $blog_offset !== $this_offset; |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + /** |
|
619 | + * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
620 | + * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
621 | + * with. |
|
622 | + * |
|
623 | + * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
624 | + * in the format that is set on the date_field (or DateTime |
|
625 | + * object)! |
|
626 | + * @return DateTime |
|
627 | + */ |
|
628 | + protected function _get_date_object($date_string) |
|
629 | + { |
|
630 | + // first if this is an empty date_string and nullable is allowed, just return null. |
|
631 | + if ($this->_nullable && empty($date_string)) { |
|
632 | + return null; |
|
633 | + } |
|
634 | + |
|
635 | + // if incoming date |
|
636 | + if ($date_string instanceof DateTime) { |
|
637 | + EEH_DTT_Helper::setTimezone($date_string, $this->_DateTimeZone); |
|
638 | + return $date_string; |
|
639 | + } |
|
640 | + // if empty date_string and made it here. |
|
641 | + // Return a datetime object for now in the given timezone. |
|
642 | + if (empty($date_string)) { |
|
643 | + return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
644 | + } |
|
645 | + // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
646 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
647 | + try { |
|
648 | + // This is operating under the assumption that the incoming Unix timestamp |
|
649 | + // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
650 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
651 | + $DateTime->setTimestamp($date_string); |
|
652 | + |
|
653 | + return $DateTime; |
|
654 | + } catch (Exception $e) { |
|
655 | + // should be rare, but if things got fooled then let's just continue |
|
656 | + } |
|
657 | + } |
|
658 | + // not a unix timestamp. So we will use the set format on this object and set timezone to |
|
659 | + // create the DateTime object. |
|
660 | + $format = $this->_date_format . ' ' . $this->_time_format; |
|
661 | + try { |
|
662 | + $DateTime = DbSafeDateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
663 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
664 | + throw new EE_Error( |
|
665 | + sprintf( |
|
666 | + __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
667 | + $date_string, |
|
668 | + $format |
|
669 | + ) |
|
670 | + ); |
|
671 | + } |
|
672 | + } catch (Exception $e) { |
|
673 | + // if we made it here then likely then something went really wrong. |
|
674 | + // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
675 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
676 | + } |
|
677 | + |
|
678 | + return $DateTime; |
|
679 | + } |
|
680 | + |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * get_timezone_transitions |
|
685 | + * |
|
686 | + * @param \DateTimeZone $DateTimeZone |
|
687 | + * @param int $time |
|
688 | + * @param bool $first_only |
|
689 | + * @return mixed |
|
690 | + */ |
|
691 | + public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
692 | + { |
|
693 | + return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only); |
|
694 | + } |
|
695 | + |
|
696 | + |
|
697 | + |
|
698 | + /** |
|
699 | + * get_timezone_offset |
|
700 | + * |
|
701 | + * @param \DateTimeZone $DateTimeZone |
|
702 | + * @param int $time |
|
703 | + * @return mixed |
|
704 | + * @throws \DomainException |
|
705 | + */ |
|
706 | + public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
707 | + { |
|
708 | + return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time); |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + /** |
|
713 | + * This will take an incoming timezone string and return the abbreviation for that timezone |
|
714 | + * |
|
715 | + * @param string $timezone_string |
|
716 | + * @return string abbreviation |
|
717 | + * @throws \EE_Error |
|
718 | + */ |
|
719 | + public function get_timezone_abbrev($timezone_string) |
|
720 | + { |
|
721 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
722 | + $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
723 | + |
|
724 | + return $dateTime->format('T'); |
|
725 | + } |
|
726 | + |
|
727 | + /** |
|
728 | + * Overrides the parent to allow for having a dynamic "now" value |
|
729 | + * |
|
730 | + * @return mixed |
|
731 | + */ |
|
732 | + public function get_default_value() |
|
733 | + { |
|
734 | + if ($this->_default_value === EE_Datetime_Field::now) { |
|
735 | + return time(); |
|
736 | + } else { |
|
737 | + return parent::get_default_value(); |
|
738 | + } |
|
739 | + } |
|
740 | + |
|
741 | + /** |
|
742 | + * Gets the default datetime object from the field's default time |
|
743 | + * @since 4.9.66.p |
|
744 | + * @return DbSafeDateTime|null |
|
745 | + * @throws InvalidArgumentException |
|
746 | + * @throws InvalidDataTypeException |
|
747 | + * @throws InvalidInterfaceException |
|
748 | + */ |
|
749 | + public function getDefaultDateTimeObj() |
|
750 | + { |
|
751 | + $default_raw = $this->get_default_value(); |
|
752 | + if ($default_raw instanceof DateTime) { |
|
753 | + return $default_raw; |
|
754 | + } elseif (is_null($default_raw)) { |
|
755 | + return $default_raw; |
|
756 | + } else { |
|
757 | + return new DbSafeDateTime( |
|
758 | + $this->get_default_value(), |
|
759 | + EEH_DTT_Helper::get_valid_timezone_string($this->get_timezone()) |
|
760 | + ); |
|
761 | + } |
|
762 | + } |
|
763 | + |
|
764 | + public function getSchemaDescription() |
|
765 | + { |
|
766 | + return sprintf( |
|
767 | + esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
768 | + $this->get_nicename() |
|
769 | + ); |
|
770 | + } |
|
771 | 771 | } |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | |
213 | 213 | default: |
214 | 214 | return $pretty |
215 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
216 | - : $this->_date_format . ' ' . $this->_time_format; |
|
215 | + ? $this->_pretty_date_format.' '.$this->_pretty_time_format |
|
216 | + : $this->_date_format.' '.$this->_time_format; |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | */ |
468 | 468 | protected function _prepare_for_display($DateTime, $schema = false) |
469 | 469 | { |
470 | - if (! $DateTime instanceof DateTime) { |
|
470 | + if ( ! $DateTime instanceof DateTime) { |
|
471 | 471 | if ($this->_nullable) { |
472 | 472 | return ''; |
473 | 473 | } else { |
@@ -501,15 +501,15 @@ discard block |
||
501 | 501 | if ($this->_display_timezone()) { |
502 | 502 | // must be explicit because schema could equal true. |
503 | 503 | if ($schema === 'no_html') { |
504 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
504 | + $timezone_string = ' ('.$DateTime->format('T').')'; |
|
505 | 505 | } else { |
506 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
506 | + $timezone_string = ' <span class="ee_dtt_timezone_string">('.$DateTime->format('T').')</span>'; |
|
507 | 507 | } |
508 | 508 | } else { |
509 | 509 | $timezone_string = ''; |
510 | 510 | } |
511 | 511 | |
512 | - return $DateTime->format($format_string) . $timezone_string; |
|
512 | + return $DateTime->format($format_string).$timezone_string; |
|
513 | 513 | } |
514 | 514 | return $DateTime->format($format_string); |
515 | 515 | } |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | public function prepare_for_use_in_db($datetime_value) |
527 | 527 | { |
528 | 528 | // we allow an empty value or DateTime object, but nothing else. |
529 | - if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
529 | + if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
530 | 530 | throw new EE_Error( |
531 | 531 | sprintf( |
532 | 532 | __( |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | } |
542 | 542 | |
543 | 543 | if ($datetime_value instanceof DateTime) { |
544 | - if (! $datetime_value instanceof DbSafeDateTime) { |
|
544 | + if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
545 | 545 | $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
546 | 546 | } |
547 | 547 | EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone()); |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | ); |
581 | 581 | } |
582 | 582 | |
583 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
583 | + if ( ! $DateTime instanceof DbSafeDateTime) { |
|
584 | 584 | // if still no datetime object, then let's just use now |
585 | 585 | $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
586 | 586 | } |
@@ -657,10 +657,10 @@ discard block |
||
657 | 657 | } |
658 | 658 | // not a unix timestamp. So we will use the set format on this object and set timezone to |
659 | 659 | // create the DateTime object. |
660 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
660 | + $format = $this->_date_format.' '.$this->_time_format; |
|
661 | 661 | try { |
662 | 662 | $DateTime = DbSafeDateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
663 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
663 | + if ( ! $DateTime instanceof DbSafeDateTime) { |
|
664 | 664 | throw new EE_Error( |
665 | 665 | sprintf( |
666 | 666 | __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |