@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | continue; |
70 | 70 | } |
71 | 71 | if ($relation instanceof EE_Has_Many_Relation) { |
72 | - $this->nodes[ $relationName ] = new RelationNode( |
|
72 | + $this->nodes[$relationName] = new RelationNode( |
|
73 | 73 | $this->id, |
74 | 74 | $this->model, |
75 | 75 | $relation->get_other_model(), |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $this->dont_traverse_models |
83 | 83 | ) |
84 | 84 | ) { |
85 | - $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode( |
|
85 | + $this->nodes[$relation->get_join_model()->get_this_model_name()] = new RelationNode( |
|
86 | 86 | $this->id, |
87 | 87 | $this->model, |
88 | 88 | $relation->get_join_model(), |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | // To save on space when serializing, only bother keeping a record of relation nodes that actually found |
131 | 131 | // related model objects. |
132 | 132 | if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) { |
133 | - unset($this->nodes[ $model_name ]); |
|
133 | + unset($this->nodes[$model_name]); |
|
134 | 134 | } |
135 | 135 | if ($num_identified >= $model_objects_to_identify) { |
136 | 136 | // ...but admit we're wrong if the work exceeded the budget. |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | $tree['rels'] = null; |
162 | 162 | } else { |
163 | 163 | foreach ($this->nodes as $relation_name => $relation_node) { |
164 | - $tree['rels'][ $relation_name ] = $relation_node->toArray(); |
|
164 | + $tree['rels'][$relation_name] = $relation_node->toArray(); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | return $tree; |
@@ -23,218 +23,218 @@ |
||
23 | 23 | */ |
24 | 24 | class ModelObjNode extends BaseNode |
25 | 25 | { |
26 | - /** |
|
27 | - * @var int|string |
|
28 | - */ |
|
29 | - protected $id; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var EEM_Base |
|
33 | - */ |
|
34 | - protected $model; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var RelationNode[] |
|
38 | - */ |
|
39 | - protected $nodes; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * We don't pass the model objects because this needs to serialize to something tiny for effiency. |
|
44 | - * |
|
45 | - * @param $model_obj_id |
|
46 | - * @param EEM_Base $model |
|
47 | - * @param array $dont_traverse_models array of model names we DON'T want to traverse. |
|
48 | - */ |
|
49 | - public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = []) |
|
50 | - { |
|
51 | - $this->id = $model_obj_id; |
|
52 | - $this->model = $model; |
|
53 | - $this->dont_traverse_models = $dont_traverse_models; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Creates a relation node for each relation of this model's relations. |
|
59 | - * Does NOT call `discover` on them yet though. |
|
60 | - * |
|
61 | - * @throws EE_Error |
|
62 | - * @throws InvalidDataTypeException |
|
63 | - * @throws InvalidInterfaceException |
|
64 | - * @throws InvalidArgumentException |
|
65 | - * @throws ReflectionException |
|
66 | - * @since 4.10.12.p |
|
67 | - */ |
|
68 | - protected function discover() |
|
69 | - { |
|
70 | - $this->nodes = []; |
|
71 | - foreach ($this->model->relation_settings() as $relationName => $relation) { |
|
72 | - // Make sure this isn't one of the models we were told to not traverse into. |
|
73 | - if (in_array($relationName, $this->dont_traverse_models)) { |
|
74 | - continue; |
|
75 | - } |
|
76 | - if ($relation instanceof EE_Has_Many_Relation) { |
|
77 | - $this->nodes[ $relationName ] = new RelationNode( |
|
78 | - $this->id, |
|
79 | - $this->model, |
|
80 | - $relation->get_other_model(), |
|
81 | - $this->dont_traverse_models |
|
82 | - ); |
|
83 | - } elseif ( |
|
84 | - $relation instanceof EE_HABTM_Relation && |
|
85 | - ! in_array( |
|
86 | - $relation->get_join_model()->get_this_model_name(), |
|
87 | - $this->dont_traverse_models |
|
88 | - ) |
|
89 | - ) { |
|
90 | - $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode( |
|
91 | - $this->id, |
|
92 | - $this->model, |
|
93 | - $relation->get_join_model(), |
|
94 | - $this->dont_traverse_models |
|
95 | - ); |
|
96 | - } |
|
97 | - } |
|
98 | - ksort($this->nodes); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * Whether this item has already been initialized |
|
104 | - */ |
|
105 | - protected function isDiscovered() |
|
106 | - { |
|
107 | - return $this->nodes !== null && is_array($this->nodes); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @since 4.10.12.p |
|
112 | - * @return boolean |
|
113 | - */ |
|
114 | - public function isComplete() |
|
115 | - { |
|
116 | - if ($this->complete === null) { |
|
117 | - $this->complete = false; |
|
118 | - } |
|
119 | - return $this->complete; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * Triggers working on each child relation node that has work to do. |
|
125 | - * |
|
126 | - * @param $model_objects_to_identify |
|
127 | - * @return int units of work done |
|
128 | - * @since 4.10.12.p |
|
129 | - */ |
|
130 | - protected function work($model_objects_to_identify) |
|
131 | - { |
|
132 | - $num_identified = 0; |
|
133 | - // Begin assuming we'll finish all the work on this node and its children... |
|
134 | - $this->complete = true; |
|
135 | - foreach ($this->nodes as $model_name => $relation_node) { |
|
136 | - $num_identified += $relation_node->visit($model_objects_to_identify - $num_identified); |
|
137 | - // To save on space when serializing, only bother keeping a record of relation nodes that actually found |
|
138 | - // related model objects. |
|
139 | - if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) { |
|
140 | - unset($this->nodes[ $model_name ]); |
|
141 | - } |
|
142 | - if ($num_identified >= $model_objects_to_identify) { |
|
143 | - // ...but admit we're wrong if the work exceeded the budget. |
|
144 | - $this->complete = false; |
|
145 | - break; |
|
146 | - } |
|
147 | - } |
|
148 | - return $num_identified; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @return array |
|
154 | - * @throws EE_Error |
|
155 | - * @throws InvalidDataTypeException |
|
156 | - * @throws InvalidInterfaceException |
|
157 | - * @throws InvalidArgumentException |
|
158 | - * @throws ReflectionException |
|
159 | - * @since 4.10.12.p |
|
160 | - */ |
|
161 | - public function toArray() |
|
162 | - { |
|
163 | - $tree = [ |
|
164 | - 'id' => $this->id, |
|
165 | - 'complete' => $this->isComplete(), |
|
166 | - 'rels' => [], |
|
167 | - ]; |
|
168 | - if ($this->nodes === null) { |
|
169 | - $tree['rels'] = null; |
|
170 | - } else { |
|
171 | - foreach ($this->nodes as $relation_name => $relation_node) { |
|
172 | - $tree['rels'][ $relation_name ] = $relation_node->toArray(); |
|
173 | - } |
|
174 | - } |
|
175 | - return $tree; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @return array|mixed |
|
181 | - * @throws InvalidArgumentException |
|
182 | - * @throws InvalidDataTypeException |
|
183 | - * @throws InvalidInterfaceException |
|
184 | - * @throws ReflectionException |
|
185 | - * @throws EE_Error |
|
186 | - * @since 4.10.12.p |
|
187 | - */ |
|
188 | - public function getIds() |
|
189 | - { |
|
190 | - $ids = [ |
|
191 | - $this->model->get_this_model_name() => [ |
|
192 | - $this->id => $this->id, |
|
193 | - ], |
|
194 | - ]; |
|
195 | - if ($this->nodes && is_array($this->nodes)) { |
|
196 | - foreach ($this->nodes as $relation_node) { |
|
197 | - $ids = array_replace_recursive($ids, $relation_node->getIds()); |
|
198 | - } |
|
199 | - } |
|
200 | - return $ids; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Don't serialize the models. Just record their names on some dynamic properties. |
|
206 | - * |
|
207 | - * @since 4.10.12.p |
|
208 | - */ |
|
209 | - public function __sleep() |
|
210 | - { |
|
211 | - $this->m = $this->model->get_this_model_name(); |
|
212 | - return array_merge( |
|
213 | - [ |
|
214 | - 'm', |
|
215 | - 'id', |
|
216 | - 'nodes', |
|
217 | - ], |
|
218 | - parent::__sleep() |
|
219 | - ); |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * Use the dynamic properties to instantiate the models we use. |
|
225 | - * |
|
226 | - * @throws EE_Error |
|
227 | - * @throws InvalidArgumentException |
|
228 | - * @throws InvalidDataTypeException |
|
229 | - * @throws InvalidInterfaceException |
|
230 | - * @throws ReflectionException |
|
231 | - * @since 4.10.12.p |
|
232 | - */ |
|
233 | - public function __wakeup() |
|
234 | - { |
|
235 | - $this->model = EE_Registry::instance()->load_model($this->m); |
|
236 | - parent::__wakeup(); |
|
237 | - } |
|
26 | + /** |
|
27 | + * @var int|string |
|
28 | + */ |
|
29 | + protected $id; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var EEM_Base |
|
33 | + */ |
|
34 | + protected $model; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var RelationNode[] |
|
38 | + */ |
|
39 | + protected $nodes; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * We don't pass the model objects because this needs to serialize to something tiny for effiency. |
|
44 | + * |
|
45 | + * @param $model_obj_id |
|
46 | + * @param EEM_Base $model |
|
47 | + * @param array $dont_traverse_models array of model names we DON'T want to traverse. |
|
48 | + */ |
|
49 | + public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = []) |
|
50 | + { |
|
51 | + $this->id = $model_obj_id; |
|
52 | + $this->model = $model; |
|
53 | + $this->dont_traverse_models = $dont_traverse_models; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Creates a relation node for each relation of this model's relations. |
|
59 | + * Does NOT call `discover` on them yet though. |
|
60 | + * |
|
61 | + * @throws EE_Error |
|
62 | + * @throws InvalidDataTypeException |
|
63 | + * @throws InvalidInterfaceException |
|
64 | + * @throws InvalidArgumentException |
|
65 | + * @throws ReflectionException |
|
66 | + * @since 4.10.12.p |
|
67 | + */ |
|
68 | + protected function discover() |
|
69 | + { |
|
70 | + $this->nodes = []; |
|
71 | + foreach ($this->model->relation_settings() as $relationName => $relation) { |
|
72 | + // Make sure this isn't one of the models we were told to not traverse into. |
|
73 | + if (in_array($relationName, $this->dont_traverse_models)) { |
|
74 | + continue; |
|
75 | + } |
|
76 | + if ($relation instanceof EE_Has_Many_Relation) { |
|
77 | + $this->nodes[ $relationName ] = new RelationNode( |
|
78 | + $this->id, |
|
79 | + $this->model, |
|
80 | + $relation->get_other_model(), |
|
81 | + $this->dont_traverse_models |
|
82 | + ); |
|
83 | + } elseif ( |
|
84 | + $relation instanceof EE_HABTM_Relation && |
|
85 | + ! in_array( |
|
86 | + $relation->get_join_model()->get_this_model_name(), |
|
87 | + $this->dont_traverse_models |
|
88 | + ) |
|
89 | + ) { |
|
90 | + $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode( |
|
91 | + $this->id, |
|
92 | + $this->model, |
|
93 | + $relation->get_join_model(), |
|
94 | + $this->dont_traverse_models |
|
95 | + ); |
|
96 | + } |
|
97 | + } |
|
98 | + ksort($this->nodes); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * Whether this item has already been initialized |
|
104 | + */ |
|
105 | + protected function isDiscovered() |
|
106 | + { |
|
107 | + return $this->nodes !== null && is_array($this->nodes); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @since 4.10.12.p |
|
112 | + * @return boolean |
|
113 | + */ |
|
114 | + public function isComplete() |
|
115 | + { |
|
116 | + if ($this->complete === null) { |
|
117 | + $this->complete = false; |
|
118 | + } |
|
119 | + return $this->complete; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * Triggers working on each child relation node that has work to do. |
|
125 | + * |
|
126 | + * @param $model_objects_to_identify |
|
127 | + * @return int units of work done |
|
128 | + * @since 4.10.12.p |
|
129 | + */ |
|
130 | + protected function work($model_objects_to_identify) |
|
131 | + { |
|
132 | + $num_identified = 0; |
|
133 | + // Begin assuming we'll finish all the work on this node and its children... |
|
134 | + $this->complete = true; |
|
135 | + foreach ($this->nodes as $model_name => $relation_node) { |
|
136 | + $num_identified += $relation_node->visit($model_objects_to_identify - $num_identified); |
|
137 | + // To save on space when serializing, only bother keeping a record of relation nodes that actually found |
|
138 | + // related model objects. |
|
139 | + if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) { |
|
140 | + unset($this->nodes[ $model_name ]); |
|
141 | + } |
|
142 | + if ($num_identified >= $model_objects_to_identify) { |
|
143 | + // ...but admit we're wrong if the work exceeded the budget. |
|
144 | + $this->complete = false; |
|
145 | + break; |
|
146 | + } |
|
147 | + } |
|
148 | + return $num_identified; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @return array |
|
154 | + * @throws EE_Error |
|
155 | + * @throws InvalidDataTypeException |
|
156 | + * @throws InvalidInterfaceException |
|
157 | + * @throws InvalidArgumentException |
|
158 | + * @throws ReflectionException |
|
159 | + * @since 4.10.12.p |
|
160 | + */ |
|
161 | + public function toArray() |
|
162 | + { |
|
163 | + $tree = [ |
|
164 | + 'id' => $this->id, |
|
165 | + 'complete' => $this->isComplete(), |
|
166 | + 'rels' => [], |
|
167 | + ]; |
|
168 | + if ($this->nodes === null) { |
|
169 | + $tree['rels'] = null; |
|
170 | + } else { |
|
171 | + foreach ($this->nodes as $relation_name => $relation_node) { |
|
172 | + $tree['rels'][ $relation_name ] = $relation_node->toArray(); |
|
173 | + } |
|
174 | + } |
|
175 | + return $tree; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @return array|mixed |
|
181 | + * @throws InvalidArgumentException |
|
182 | + * @throws InvalidDataTypeException |
|
183 | + * @throws InvalidInterfaceException |
|
184 | + * @throws ReflectionException |
|
185 | + * @throws EE_Error |
|
186 | + * @since 4.10.12.p |
|
187 | + */ |
|
188 | + public function getIds() |
|
189 | + { |
|
190 | + $ids = [ |
|
191 | + $this->model->get_this_model_name() => [ |
|
192 | + $this->id => $this->id, |
|
193 | + ], |
|
194 | + ]; |
|
195 | + if ($this->nodes && is_array($this->nodes)) { |
|
196 | + foreach ($this->nodes as $relation_node) { |
|
197 | + $ids = array_replace_recursive($ids, $relation_node->getIds()); |
|
198 | + } |
|
199 | + } |
|
200 | + return $ids; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Don't serialize the models. Just record their names on some dynamic properties. |
|
206 | + * |
|
207 | + * @since 4.10.12.p |
|
208 | + */ |
|
209 | + public function __sleep() |
|
210 | + { |
|
211 | + $this->m = $this->model->get_this_model_name(); |
|
212 | + return array_merge( |
|
213 | + [ |
|
214 | + 'm', |
|
215 | + 'id', |
|
216 | + 'nodes', |
|
217 | + ], |
|
218 | + parent::__sleep() |
|
219 | + ); |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * Use the dynamic properties to instantiate the models we use. |
|
225 | + * |
|
226 | + * @throws EE_Error |
|
227 | + * @throws InvalidArgumentException |
|
228 | + * @throws InvalidDataTypeException |
|
229 | + * @throws InvalidInterfaceException |
|
230 | + * @throws ReflectionException |
|
231 | + * @since 4.10.12.p |
|
232 | + */ |
|
233 | + public function __wakeup() |
|
234 | + { |
|
235 | + $this->model = EE_Registry::instance()->load_model($this->m); |
|
236 | + parent::__wakeup(); |
|
237 | + } |
|
238 | 238 | } |
239 | 239 | // End of file Visitor.php |
240 | 240 | // Location: EventEspresso\core\services\orm\tree_traversal/Visitor.php |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | protected static function getRequest() |
134 | 134 | { |
135 | 135 | static $request; |
136 | - if (! $request instanceof RequestInterface) { |
|
136 | + if ( ! $request instanceof RequestInterface) { |
|
137 | 137 | $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
138 | 138 | } |
139 | 139 | return $request; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | protected static function getResponse() |
148 | 148 | { |
149 | 149 | static $response; |
150 | - if (! $response instanceof RequestInterface) { |
|
150 | + if ( ! $response instanceof RequestInterface) { |
|
151 | 151 | $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class); |
152 | 152 | } |
153 | 153 | return $response; |
@@ -14,141 +14,141 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class EED_Module extends EE_Configurable implements ResettableInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * rendered output to be returned to WP |
|
19 | - * |
|
20 | - * @var string $output |
|
21 | - */ |
|
22 | - protected $output = ''; |
|
23 | - |
|
24 | - /** |
|
25 | - * the current active espresso template theme |
|
26 | - * |
|
27 | - * @var string $theme |
|
28 | - */ |
|
29 | - protected $theme = ''; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - public static function reset() |
|
36 | - { |
|
37 | - $module_name = get_called_class(); |
|
38 | - new $module_name(); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
44 | - * |
|
45 | - * @access public |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public static function set_hooks() |
|
49 | - { |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
55 | - * |
|
56 | - * @access public |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - public static function set_hooks_admin() |
|
60 | - { |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * run - initial module setup |
|
66 | - * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
67 | - * |
|
68 | - * @access public |
|
69 | - * @var WP $WP |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - abstract public function run($WP); |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * EED_Module constructor. |
|
77 | - */ |
|
78 | - final public function __construct() |
|
79 | - { |
|
80 | - $this->theme = EE_Config::get_current_theme(); |
|
81 | - $module_name = $this->module_name(); |
|
82 | - EE_Registry::instance()->modules->{$module_name} = $this; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @param string $module_name |
|
88 | - * @return EED_Module|mixed |
|
89 | - * @throws EE_Error |
|
90 | - * @throws ReflectionException |
|
91 | - */ |
|
92 | - protected static function get_instance($module_name = '') |
|
93 | - { |
|
94 | - $module_name = ! empty($module_name) |
|
95 | - ? $module_name |
|
96 | - : get_called_class(); |
|
97 | - if ( |
|
98 | - ! isset(EE_Registry::instance()->modules->{$module_name}) |
|
99 | - || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module |
|
100 | - ) { |
|
101 | - EE_Registry::instance()->add_module($module_name); |
|
102 | - } |
|
103 | - return EE_Registry::instance()->get_module($module_name); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * module_name |
|
109 | - * |
|
110 | - * @access public |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function module_name() |
|
114 | - { |
|
115 | - return get_class($this); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function theme() |
|
123 | - { |
|
124 | - return $this->theme; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @return RequestInterface |
|
130 | - * @since 4.10.14.p |
|
131 | - */ |
|
132 | - protected static function getRequest() |
|
133 | - { |
|
134 | - static $request; |
|
135 | - if (! $request instanceof RequestInterface) { |
|
136 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
137 | - } |
|
138 | - return $request; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return ResponseInterface |
|
144 | - * @since 4.10.14.p |
|
145 | - */ |
|
146 | - protected static function getResponse() |
|
147 | - { |
|
148 | - static $response; |
|
149 | - if (! $response instanceof RequestInterface) { |
|
150 | - $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class); |
|
151 | - } |
|
152 | - return $response; |
|
153 | - } |
|
17 | + /** |
|
18 | + * rendered output to be returned to WP |
|
19 | + * |
|
20 | + * @var string $output |
|
21 | + */ |
|
22 | + protected $output = ''; |
|
23 | + |
|
24 | + /** |
|
25 | + * the current active espresso template theme |
|
26 | + * |
|
27 | + * @var string $theme |
|
28 | + */ |
|
29 | + protected $theme = ''; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + public static function reset() |
|
36 | + { |
|
37 | + $module_name = get_called_class(); |
|
38 | + new $module_name(); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
44 | + * |
|
45 | + * @access public |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public static function set_hooks() |
|
49 | + { |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
55 | + * |
|
56 | + * @access public |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + public static function set_hooks_admin() |
|
60 | + { |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * run - initial module setup |
|
66 | + * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
67 | + * |
|
68 | + * @access public |
|
69 | + * @var WP $WP |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + abstract public function run($WP); |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * EED_Module constructor. |
|
77 | + */ |
|
78 | + final public function __construct() |
|
79 | + { |
|
80 | + $this->theme = EE_Config::get_current_theme(); |
|
81 | + $module_name = $this->module_name(); |
|
82 | + EE_Registry::instance()->modules->{$module_name} = $this; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @param string $module_name |
|
88 | + * @return EED_Module|mixed |
|
89 | + * @throws EE_Error |
|
90 | + * @throws ReflectionException |
|
91 | + */ |
|
92 | + protected static function get_instance($module_name = '') |
|
93 | + { |
|
94 | + $module_name = ! empty($module_name) |
|
95 | + ? $module_name |
|
96 | + : get_called_class(); |
|
97 | + if ( |
|
98 | + ! isset(EE_Registry::instance()->modules->{$module_name}) |
|
99 | + || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module |
|
100 | + ) { |
|
101 | + EE_Registry::instance()->add_module($module_name); |
|
102 | + } |
|
103 | + return EE_Registry::instance()->get_module($module_name); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * module_name |
|
109 | + * |
|
110 | + * @access public |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function module_name() |
|
114 | + { |
|
115 | + return get_class($this); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function theme() |
|
123 | + { |
|
124 | + return $this->theme; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @return RequestInterface |
|
130 | + * @since 4.10.14.p |
|
131 | + */ |
|
132 | + protected static function getRequest() |
|
133 | + { |
|
134 | + static $request; |
|
135 | + if (! $request instanceof RequestInterface) { |
|
136 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
137 | + } |
|
138 | + return $request; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return ResponseInterface |
|
144 | + * @since 4.10.14.p |
|
145 | + */ |
|
146 | + protected static function getResponse() |
|
147 | + { |
|
148 | + static $response; |
|
149 | + if (! $response instanceof RequestInterface) { |
|
150 | + $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class); |
|
151 | + } |
|
152 | + return $response; |
|
153 | + } |
|
154 | 154 | } |
@@ -94,16 +94,16 @@ |
||
94 | 94 | ? $this->_extra_data['template']['question_list'] |
95 | 95 | : $template; |
96 | 96 | $ans_result = ''; |
97 | - $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
98 | - ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
97 | + $answers = ! empty($this->_extra_data['data']->registrations[$reg_obj->ID()]['ans_objs']) |
|
98 | + ? $this->_extra_data['data']->registrations[$reg_obj->ID()]['ans_objs'] |
|
99 | 99 | : []; |
100 | 100 | $questions = ! empty($this->_extra_data['data']->questions) |
101 | 101 | ? $this->_extra_data['data']->questions |
102 | 102 | : []; |
103 | 103 | foreach ($answers as $answer) { |
104 | 104 | // first see if the question is in our $questions array. If not then try to get from answer object |
105 | - $question = isset($questions[ $answer->ID() ]) |
|
106 | - ? $questions[ $answer->ID() ] |
|
105 | + $question = isset($questions[$answer->ID()]) |
|
106 | + ? $questions[$answer->ID()] |
|
107 | 107 | : null; |
108 | 108 | $question = ! $question instanceof EE_Question |
109 | 109 | ? $answer->question() |
@@ -15,113 +15,113 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_Question_List_Shortcodes extends EE_Shortcodes |
17 | 17 | { |
18 | - public function __construct() |
|
19 | - { |
|
20 | - parent::__construct(); |
|
21 | - } |
|
18 | + public function __construct() |
|
19 | + { |
|
20 | + parent::__construct(); |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | - protected function _init_props() |
|
25 | - { |
|
26 | - $this->label = esc_html__('Questions and Answers Shortcodes', 'event_espresso'); |
|
27 | - $this->description = esc_html__('All shortcodes related to custom questions and answers', 'event_espresso'); |
|
28 | - $this->_shortcodes = [ |
|
29 | - '[QUESTION_LIST]' => esc_html__( |
|
30 | - 'This is used to indicate where you want the list of questions and answers to show for the registrant. You place this within the "[attendee_list]" field.', |
|
31 | - 'event_espresso' |
|
32 | - ), |
|
33 | - ]; |
|
34 | - } |
|
24 | + protected function _init_props() |
|
25 | + { |
|
26 | + $this->label = esc_html__('Questions and Answers Shortcodes', 'event_espresso'); |
|
27 | + $this->description = esc_html__('All shortcodes related to custom questions and answers', 'event_espresso'); |
|
28 | + $this->_shortcodes = [ |
|
29 | + '[QUESTION_LIST]' => esc_html__( |
|
30 | + 'This is used to indicate where you want the list of questions and answers to show for the registrant. You place this within the "[attendee_list]" field.', |
|
31 | + 'event_espresso' |
|
32 | + ), |
|
33 | + ]; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * @param string $shortcode |
|
39 | - * @return string |
|
40 | - * @throws EE_Error |
|
41 | - * @throws ReflectionException |
|
42 | - */ |
|
43 | - protected function _parser($shortcode) |
|
44 | - { |
|
45 | - switch ($shortcode) { |
|
46 | - case '[QUESTION_LIST]': |
|
47 | - return $this->_get_question_list(); |
|
48 | - } |
|
49 | - return ''; |
|
50 | - } |
|
37 | + /** |
|
38 | + * @param string $shortcode |
|
39 | + * @return string |
|
40 | + * @throws EE_Error |
|
41 | + * @throws ReflectionException |
|
42 | + */ |
|
43 | + protected function _parser($shortcode) |
|
44 | + { |
|
45 | + switch ($shortcode) { |
|
46 | + case '[QUESTION_LIST]': |
|
47 | + return $this->_get_question_list(); |
|
48 | + } |
|
49 | + return ''; |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @return string |
|
55 | - * @throws EE_Error |
|
56 | - * @throws ReflectionException |
|
57 | - */ |
|
58 | - protected function _get_question_list() |
|
59 | - { |
|
60 | - $this->_validate_list_requirements(); |
|
53 | + /** |
|
54 | + * @return string |
|
55 | + * @throws EE_Error |
|
56 | + * @throws ReflectionException |
|
57 | + */ |
|
58 | + protected function _get_question_list() |
|
59 | + { |
|
60 | + $this->_validate_list_requirements(); |
|
61 | 61 | |
62 | - // for when [QUESTION_LIST] is used in the [attendee_list] field. |
|
63 | - if ($this->_data['data'] instanceof EE_Registration) { |
|
64 | - return $this->_get_question_answer_list_for_attendee(); |
|
65 | - } |
|
62 | + // for when [QUESTION_LIST] is used in the [attendee_list] field. |
|
63 | + if ($this->_data['data'] instanceof EE_Registration) { |
|
64 | + return $this->_get_question_answer_list_for_attendee(); |
|
65 | + } |
|
66 | 66 | |
67 | - // for when [QUESTION_LIST] is used in the main content field. |
|
68 | - if ( |
|
69 | - $this->_data['data'] instanceof EE_Messages_Addressee |
|
70 | - && $this->_data['data']->reg_obj instanceof EE_Registration |
|
71 | - ) { |
|
72 | - return $this->_get_question_answer_list_for_attendee($this->_data['data']->reg_obj); |
|
73 | - } |
|
74 | - return ''; |
|
75 | - } |
|
67 | + // for when [QUESTION_LIST] is used in the main content field. |
|
68 | + if ( |
|
69 | + $this->_data['data'] instanceof EE_Messages_Addressee |
|
70 | + && $this->_data['data']->reg_obj instanceof EE_Registration |
|
71 | + ) { |
|
72 | + return $this->_get_question_answer_list_for_attendee($this->_data['data']->reg_obj); |
|
73 | + } |
|
74 | + return ''; |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - /** |
|
79 | - * Note when we parse the "[question_list]" shortcode for attendees we're actually going to retrieve the list of |
|
80 | - * answers for that attendee since that is what we really need (we can derive the questions from the answers); |
|
81 | - * |
|
82 | - * @param null $reg_obj |
|
83 | - * @return string parsed template. |
|
84 | - * @throws EE_Error |
|
85 | - * @throws ReflectionException |
|
86 | - */ |
|
87 | - private function _get_question_answer_list_for_attendee($reg_obj = null) |
|
88 | - { |
|
89 | - $valid_shortcodes = ['question']; |
|
90 | - $reg_obj = $reg_obj instanceof EE_Registration |
|
91 | - ? $reg_obj |
|
92 | - : $this->_data['data']; |
|
93 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['question_list']) |
|
94 | - ? $this->_data['template']['question_list'] |
|
95 | - : ''; |
|
96 | - $template = empty($template) && isset($this->_extra_data['template']['question_list']) |
|
97 | - ? $this->_extra_data['template']['question_list'] |
|
98 | - : $template; |
|
99 | - $ans_result = ''; |
|
100 | - $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
101 | - ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
102 | - : []; |
|
103 | - $questions = ! empty($this->_extra_data['data']->questions) |
|
104 | - ? $this->_extra_data['data']->questions |
|
105 | - : []; |
|
106 | - foreach ($answers as $answer) { |
|
107 | - // first see if the question is in our $questions array. If not then try to get from answer object |
|
108 | - $question = isset($questions[ $answer->ID() ]) |
|
109 | - ? $questions[ $answer->ID() ] |
|
110 | - : null; |
|
111 | - $question = ! $question instanceof EE_Question |
|
112 | - ? $answer->question() |
|
113 | - : $question; |
|
114 | - if ($question instanceof EE_Question and $question->admin_only()) { |
|
115 | - continue; |
|
116 | - } |
|
117 | - $ans_result .= $this->_shortcode_helper->parse_question_list_template( |
|
118 | - $template, |
|
119 | - $answer, |
|
120 | - $valid_shortcodes, |
|
121 | - $this->_extra_data |
|
122 | - ); |
|
123 | - } |
|
78 | + /** |
|
79 | + * Note when we parse the "[question_list]" shortcode for attendees we're actually going to retrieve the list of |
|
80 | + * answers for that attendee since that is what we really need (we can derive the questions from the answers); |
|
81 | + * |
|
82 | + * @param null $reg_obj |
|
83 | + * @return string parsed template. |
|
84 | + * @throws EE_Error |
|
85 | + * @throws ReflectionException |
|
86 | + */ |
|
87 | + private function _get_question_answer_list_for_attendee($reg_obj = null) |
|
88 | + { |
|
89 | + $valid_shortcodes = ['question']; |
|
90 | + $reg_obj = $reg_obj instanceof EE_Registration |
|
91 | + ? $reg_obj |
|
92 | + : $this->_data['data']; |
|
93 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['question_list']) |
|
94 | + ? $this->_data['template']['question_list'] |
|
95 | + : ''; |
|
96 | + $template = empty($template) && isset($this->_extra_data['template']['question_list']) |
|
97 | + ? $this->_extra_data['template']['question_list'] |
|
98 | + : $template; |
|
99 | + $ans_result = ''; |
|
100 | + $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
101 | + ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
102 | + : []; |
|
103 | + $questions = ! empty($this->_extra_data['data']->questions) |
|
104 | + ? $this->_extra_data['data']->questions |
|
105 | + : []; |
|
106 | + foreach ($answers as $answer) { |
|
107 | + // first see if the question is in our $questions array. If not then try to get from answer object |
|
108 | + $question = isset($questions[ $answer->ID() ]) |
|
109 | + ? $questions[ $answer->ID() ] |
|
110 | + : null; |
|
111 | + $question = ! $question instanceof EE_Question |
|
112 | + ? $answer->question() |
|
113 | + : $question; |
|
114 | + if ($question instanceof EE_Question and $question->admin_only()) { |
|
115 | + continue; |
|
116 | + } |
|
117 | + $ans_result .= $this->_shortcode_helper->parse_question_list_template( |
|
118 | + $template, |
|
119 | + $answer, |
|
120 | + $valid_shortcodes, |
|
121 | + $this->_extra_data |
|
122 | + ); |
|
123 | + } |
|
124 | 124 | |
125 | - return $ans_result; |
|
126 | - } |
|
125 | + return $ans_result; |
|
126 | + } |
|
127 | 127 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | ) { |
70 | 70 | $new_value_maybe_array = []; |
71 | 71 | foreach ($original_value_maybe_array as $array_key => $array_item) { |
72 | - $new_value_maybe_array[ $array_key ] = ModelDataTranslator::prepareFieldValueFromJson( |
|
72 | + $new_value_maybe_array[$array_key] = ModelDataTranslator::prepareFieldValueFromJson( |
|
73 | 73 | $field_obj, |
74 | 74 | $array_item, |
75 | 75 | $requested_version, |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | if (is_array($original_value_maybe_array)) { |
104 | 104 | $new_value = []; |
105 | 105 | foreach ($original_value_maybe_array as $key => $value) { |
106 | - $new_value[ $key ] = ModelDataTranslator::prepareFieldValuesForJson( |
|
106 | + $new_value[$key] = ModelDataTranslator::prepareFieldValuesForJson( |
|
107 | 107 | $field_obj, |
108 | 108 | $value, |
109 | 109 | $request_version |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | '0', |
245 | 245 | STR_PAD_LEFT |
246 | 246 | ); |
247 | - return $original_timestamp . $offset_sign . $offset_string; |
|
247 | + return $original_timestamp.$offset_sign.$offset_string; |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | // first, check if its a MySQL timestamp in GMT |
324 | 324 | $datetime_obj = DateTime::createFromFormat('Y-m-d H:i:s', $original_value); |
325 | 325 | } |
326 | - if (! $datetime_obj instanceof DateTime) { |
|
326 | + if ( ! $datetime_obj instanceof DateTime) { |
|
327 | 327 | // so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format? |
328 | 328 | $datetime_obj = $field_obj->prepare_for_set($original_value); |
329 | 329 | } |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | $original_value, |
350 | 350 | $field_obj->get_name(), |
351 | 351 | $field_obj->get_model_name(), |
352 | - $field_obj->get_time_format() . ' ' . $field_obj->get_time_format() |
|
352 | + $field_obj->get_time_format().' '.$field_obj->get_time_format() |
|
353 | 353 | ) |
354 | 354 | ); |
355 | 355 | } |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | } |
364 | 364 | // are we about to send an object? just don't. We have no good way to represent it in JSON. |
365 | 365 | // can't just check using is_object() because that missed PHP incomplete objects |
366 | - if (! ModelDataTranslator::isRepresentableInJson($new_value)) { |
|
366 | + if ( ! ModelDataTranslator::isRepresentableInJson($new_value)) { |
|
367 | 367 | $new_value = [ |
368 | 368 | 'error_code' => 'php_object_not_return', |
369 | 369 | 'error_message' => esc_html__( |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | if ($query_param_meta->getField() instanceof EE_Model_Field_Base) { |
415 | 415 | $translated_value = $query_param_meta->determineConditionsQueryParameterValue(); |
416 | 416 | if ( |
417 | - (isset($query_param_for_models[ $query_param_meta->getQueryParamKey() ]) |
|
417 | + (isset($query_param_for_models[$query_param_meta->getQueryParamKey()]) |
|
418 | 418 | && $query_param_meta->isGmtField()) |
419 | 419 | || $translated_value === null |
420 | 420 | ) { |
@@ -423,11 +423,11 @@ discard block |
||
423 | 423 | // OR we couldn't create a translated value from their input |
424 | 424 | continue; |
425 | 425 | } |
426 | - $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $translated_value; |
|
426 | + $query_param_for_models[$query_param_meta->getQueryParamKey()] = $translated_value; |
|
427 | 427 | } else { |
428 | 428 | $nested_query_params = $query_param_meta->determineNestedConditionQueryParameters(); |
429 | 429 | if ($nested_query_params) { |
430 | - $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $nested_query_params; |
|
430 | + $query_param_for_models[$query_param_meta->getQueryParamKey()] = $nested_query_params; |
|
431 | 431 | } |
432 | 432 | } |
433 | 433 | } |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | */ |
458 | 458 | public static function removeGmtFromFieldName($field_name) |
459 | 459 | { |
460 | - if (! ModelDataTranslator::isGmtDateFieldName($field_name)) { |
|
460 | + if ( ! ModelDataTranslator::isGmtDateFieldName($field_name)) { |
|
461 | 461 | return $field_name; |
462 | 462 | } |
463 | 463 | $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey( |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | { |
501 | 501 | $new_array = []; |
502 | 502 | foreach ($field_names as $key => $field_name) { |
503 | - $new_array[ $key ] = ModelDataTranslator::prepareFieldNameFromJson($field_name); |
|
503 | + $new_array[$key] = ModelDataTranslator::prepareFieldNameFromJson($field_name); |
|
504 | 504 | } |
505 | 505 | return $new_array; |
506 | 506 | } |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | { |
518 | 518 | $new_array = []; |
519 | 519 | foreach ($field_names_as_keys as $field_name => $value) { |
520 | - $new_array[ ModelDataTranslator::prepareFieldNameFromJson($field_name) ] = $value; |
|
520 | + $new_array[ModelDataTranslator::prepareFieldNameFromJson($field_name)] = $value; |
|
521 | 521 | } |
522 | 522 | return $new_array; |
523 | 523 | } |
@@ -613,10 +613,10 @@ discard block |
||
613 | 613 | $requested_version |
614 | 614 | ); |
615 | 615 | } |
616 | - $query_param_for_models[ $query_param_key ] = $translated_value; |
|
616 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
617 | 617 | } else { |
618 | 618 | // so it's not for a field, assume it's a logic query param key |
619 | - $query_param_for_models[ $query_param_key ] = |
|
619 | + $query_param_for_models[$query_param_key] = |
|
620 | 620 | ModelDataTranslator::prepareConditionsQueryParamsForRestApi( |
621 | 621 | $query_param_value, |
622 | 622 | $model, |
@@ -668,11 +668,11 @@ discard block |
||
668 | 668 | ); |
669 | 669 | } |
670 | 670 | $number_of_parts = count($query_param_parts); |
671 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
671 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
672 | 672 | $field_name = $last_query_param_part; |
673 | 673 | if ($number_of_parts !== 1) { |
674 | 674 | // the last part is the column name, and there are only 2parts. therefore... |
675 | - $model = EE_Registry::instance()->load_model($query_param_parts[ $number_of_parts - 2 ]); |
|
675 | + $model = EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
676 | 676 | } |
677 | 677 | try { |
678 | 678 | return $model->field_settings_for($field_name, false); |
@@ -38,658 +38,658 @@ |
||
38 | 38 | */ |
39 | 39 | class ModelDataTranslator |
40 | 40 | { |
41 | - /** |
|
42 | - * We used to use -1 for infinity in the rest api, but that's ambiguous for |
|
43 | - * fields that COULD contain -1; so we use null |
|
44 | - */ |
|
45 | - const EE_INF_IN_REST = null; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Prepares a possible array of input values from JSON for use by the models |
|
50 | - * |
|
51 | - * @param EE_Model_Field_Base $field_obj |
|
52 | - * @param mixed $original_value_maybe_array |
|
53 | - * @param string $requested_version |
|
54 | - * @param string $timezone_string treat values as being in this timezone |
|
55 | - * @return mixed |
|
56 | - * @throws RestException |
|
57 | - * @throws EE_Error |
|
58 | - */ |
|
59 | - public static function prepareFieldValuesFromJson( |
|
60 | - $field_obj, |
|
61 | - $original_value_maybe_array, |
|
62 | - $requested_version, |
|
63 | - $timezone_string = 'UTC' |
|
64 | - ) { |
|
65 | - if ( |
|
66 | - is_array($original_value_maybe_array) |
|
67 | - && ! $field_obj instanceof EE_Serialized_Text_Field |
|
68 | - ) { |
|
69 | - $new_value_maybe_array = []; |
|
70 | - foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
71 | - $new_value_maybe_array[ $array_key ] = ModelDataTranslator::prepareFieldValueFromJson( |
|
72 | - $field_obj, |
|
73 | - $array_item, |
|
74 | - $requested_version, |
|
75 | - $timezone_string |
|
76 | - ); |
|
77 | - } |
|
78 | - } else { |
|
79 | - $new_value_maybe_array = ModelDataTranslator::prepareFieldValueFromJson( |
|
80 | - $field_obj, |
|
81 | - $original_value_maybe_array, |
|
82 | - $requested_version, |
|
83 | - $timezone_string |
|
84 | - ); |
|
85 | - } |
|
86 | - return $new_value_maybe_array; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Prepares an array of field values FOR use in JSON/REST API |
|
92 | - * |
|
93 | - * @param EE_Model_Field_Base $field_obj |
|
94 | - * @param mixed $original_value_maybe_array |
|
95 | - * @param string $request_version (eg 4.8.36) |
|
96 | - * @return array|int|string |
|
97 | - * @throws EE_Error |
|
98 | - * @throws EE_Error |
|
99 | - */ |
|
100 | - public static function prepareFieldValuesForJson($field_obj, $original_value_maybe_array, $request_version) |
|
101 | - { |
|
102 | - if (is_array($original_value_maybe_array)) { |
|
103 | - $new_value = []; |
|
104 | - foreach ($original_value_maybe_array as $key => $value) { |
|
105 | - $new_value[ $key ] = ModelDataTranslator::prepareFieldValuesForJson( |
|
106 | - $field_obj, |
|
107 | - $value, |
|
108 | - $request_version |
|
109 | - ); |
|
110 | - } |
|
111 | - } else { |
|
112 | - $new_value = ModelDataTranslator::prepareFieldValueForJson( |
|
113 | - $field_obj, |
|
114 | - $original_value_maybe_array, |
|
115 | - $request_version |
|
116 | - ); |
|
117 | - } |
|
118 | - return $new_value; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * Prepares incoming data from the json or request parameters for the models' |
|
124 | - * "$query_params". |
|
125 | - * |
|
126 | - * @param EE_Model_Field_Base $field_obj |
|
127 | - * @param mixed $original_value |
|
128 | - * @param string $requested_version |
|
129 | - * @param string $timezone_string treat values as being in this timezone |
|
130 | - * @return mixed |
|
131 | - * @throws RestException |
|
132 | - * @throws DomainException |
|
133 | - * @throws EE_Error |
|
134 | - */ |
|
135 | - public static function prepareFieldValueFromJson( |
|
136 | - $field_obj, |
|
137 | - $original_value, |
|
138 | - $requested_version, |
|
139 | - $timezone_string = 'UTC' |
|
140 | - ) { |
|
141 | - // check if they accidentally submitted an error value. If so throw an exception |
|
142 | - if ( |
|
143 | - is_array($original_value) |
|
144 | - && isset($original_value['error_code'], $original_value['error_message']) |
|
145 | - ) { |
|
146 | - throw new RestException( |
|
147 | - 'rest_submitted_error_value', |
|
148 | - sprintf( |
|
149 | - esc_html__( |
|
150 | - 'You tried to submit a JSON error object as a value for %1$s. That\'s not allowed.', |
|
151 | - 'event_espresso' |
|
152 | - ), |
|
153 | - $field_obj->get_name() |
|
154 | - ), |
|
155 | - [ |
|
156 | - 'status' => 400, |
|
157 | - ] |
|
158 | - ); |
|
159 | - } |
|
160 | - // double-check for serialized PHP. We never accept serialized PHP. No way Jose. |
|
161 | - ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value); |
|
162 | - $timezone_string = |
|
163 | - $timezone_string !== '' |
|
164 | - ? $timezone_string |
|
165 | - : get_option('timezone_string', ''); |
|
166 | - // walk through the submitted data and double-check for serialized PHP. We never accept serialized PHP. No |
|
167 | - // way Jose. |
|
168 | - ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value); |
|
169 | - if ( |
|
170 | - $field_obj instanceof EE_Infinite_Integer_Field |
|
171 | - && in_array($original_value, [null, ''], true) |
|
172 | - ) { |
|
173 | - $new_value = EE_INF; |
|
174 | - } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
175 | - $new_value = rest_parse_date( |
|
176 | - self::getTimestampWithTimezoneOffset($original_value, $field_obj, $timezone_string) |
|
177 | - ); |
|
178 | - if ($new_value === false) { |
|
179 | - throw new RestException( |
|
180 | - 'invalid_format_for_timestamp', |
|
181 | - sprintf( |
|
182 | - esc_html__( |
|
183 | - 'Timestamps received on a request as the value for Date and Time fields must be in %1$s/%2$s format. The timestamp provided (%3$s) is not that format.', |
|
184 | - 'event_espresso' |
|
185 | - ), |
|
186 | - 'RFC3339', |
|
187 | - 'ISO8601', |
|
188 | - $original_value |
|
189 | - ), |
|
190 | - [ |
|
191 | - 'status' => 400, |
|
192 | - ] |
|
193 | - ); |
|
194 | - } |
|
195 | - } elseif ($field_obj instanceof EE_Boolean_Field) { |
|
196 | - // Interpreted the strings "false", "true", "on", "off" appropriately. |
|
197 | - $new_value = filter_var($original_value, FILTER_VALIDATE_BOOLEAN); |
|
198 | - } else { |
|
199 | - $new_value = $original_value; |
|
200 | - } |
|
201 | - return $new_value; |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * This checks if the incoming timestamp has timezone information already on it and if it doesn't then adds timezone |
|
207 | - * information via details obtained from the host site. |
|
208 | - * |
|
209 | - * @param string $original_timestamp |
|
210 | - * @param EE_Datetime_Field $datetime_field |
|
211 | - * @param $timezone_string |
|
212 | - * @return string |
|
213 | - * @throws DomainException |
|
214 | - */ |
|
215 | - private static function getTimestampWithTimezoneOffset( |
|
216 | - $original_timestamp, |
|
217 | - EE_Datetime_Field $datetime_field, |
|
218 | - $timezone_string |
|
219 | - ) { |
|
220 | - // already have timezone information? |
|
221 | - if (preg_match('/Z|([+-])(\d{2}:\d{2})/', $original_timestamp)) { |
|
222 | - // yes, we're ignoring the timezone. |
|
223 | - return $original_timestamp; |
|
224 | - } |
|
225 | - // need to append timezone |
|
226 | - list($offset_sign, $offset_secs) = self::parseTimezoneOffset( |
|
227 | - $datetime_field->get_timezone_offset( |
|
228 | - new DateTimeZone($timezone_string), |
|
229 | - $original_timestamp |
|
230 | - ) |
|
231 | - ); |
|
232 | - $offset_string = |
|
233 | - str_pad( |
|
234 | - floor($offset_secs / HOUR_IN_SECONDS), |
|
235 | - 2, |
|
236 | - '0', |
|
237 | - STR_PAD_LEFT |
|
238 | - ) |
|
239 | - . ':' |
|
240 | - . str_pad( |
|
241 | - ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS, |
|
242 | - 2, |
|
243 | - '0', |
|
244 | - STR_PAD_LEFT |
|
245 | - ); |
|
246 | - return $original_timestamp . $offset_sign . $offset_string; |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * Throws an exception if $data is a serialized PHP string (or somehow an actually PHP object, although I don't |
|
252 | - * think that can happen). If $data is an array, recurses into its keys and values |
|
253 | - * |
|
254 | - * @param mixed $data |
|
255 | - * @return void |
|
256 | - * @throws RestException |
|
257 | - */ |
|
258 | - public static function throwExceptionIfContainsSerializedData($data) |
|
259 | - { |
|
260 | - if (is_array($data)) { |
|
261 | - foreach ($data as $key => $value) { |
|
262 | - ModelDataTranslator::throwExceptionIfContainsSerializedData($key); |
|
263 | - ModelDataTranslator::throwExceptionIfContainsSerializedData($value); |
|
264 | - } |
|
265 | - } else { |
|
266 | - if (is_serialized($data) || is_object($data)) { |
|
267 | - throw new RestException( |
|
268 | - 'serialized_data_submission_prohibited', |
|
269 | - esc_html__( |
|
270 | - // @codingStandardsIgnoreStart |
|
271 | - 'You tried to submit a string of serialized text. Serialized PHP is prohibited over the EE4 REST API.', |
|
272 | - // @codingStandardsIgnoreEnd |
|
273 | - 'event_espresso' |
|
274 | - ) |
|
275 | - ); |
|
276 | - } |
|
277 | - } |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * determines what's going on with them timezone strings |
|
283 | - * |
|
284 | - * @param int $timezone_offset |
|
285 | - * @return array |
|
286 | - */ |
|
287 | - private static function parseTimezoneOffset($timezone_offset) |
|
288 | - { |
|
289 | - $first_char = substr((string) $timezone_offset, 0, 1); |
|
290 | - if ($first_char === '+' || $first_char === '-') { |
|
291 | - $offset_sign = $first_char; |
|
292 | - $offset_secs = substr((string) $timezone_offset, 1); |
|
293 | - } else { |
|
294 | - $offset_sign = '+'; |
|
295 | - $offset_secs = $timezone_offset; |
|
296 | - } |
|
297 | - return [$offset_sign, $offset_secs]; |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Prepares a field's value for display in the API |
|
303 | - * |
|
304 | - * @param EE_Model_Field_Base $field_obj |
|
305 | - * @param mixed $original_value |
|
306 | - * @param string $requested_version |
|
307 | - * @return mixed |
|
308 | - * @throws EE_Error |
|
309 | - * @throws EE_Error |
|
310 | - */ |
|
311 | - public static function prepareFieldValueForJson($field_obj, $original_value, $requested_version) |
|
312 | - { |
|
313 | - if ($original_value === EE_INF) { |
|
314 | - $new_value = ModelDataTranslator::EE_INF_IN_REST; |
|
315 | - } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
316 | - if (is_string($original_value)) { |
|
317 | - // did they submit a string of a unix timestamp? |
|
318 | - if (is_numeric($original_value)) { |
|
319 | - $datetime_obj = new DateTime(); |
|
320 | - $datetime_obj->setTimestamp((int) $original_value); |
|
321 | - } else { |
|
322 | - // first, check if its a MySQL timestamp in GMT |
|
323 | - $datetime_obj = DateTime::createFromFormat('Y-m-d H:i:s', $original_value); |
|
324 | - } |
|
325 | - if (! $datetime_obj instanceof DateTime) { |
|
326 | - // so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format? |
|
327 | - $datetime_obj = $field_obj->prepare_for_set($original_value); |
|
328 | - } |
|
329 | - $original_value = $datetime_obj; |
|
330 | - } |
|
331 | - if ($original_value instanceof DateTime) { |
|
332 | - $new_value = $original_value->format('Y-m-d H:i:s'); |
|
333 | - } elseif (is_int($original_value) || is_float($original_value)) { |
|
334 | - $new_value = date('Y-m-d H:i:s', $original_value); |
|
335 | - } elseif ($original_value === null || $original_value === '') { |
|
336 | - $new_value = null; |
|
337 | - } else { |
|
338 | - // so it's not a datetime object, unix timestamp (as string or int), |
|
339 | - // MySQL timestamp, or even a string in the field object's format. So no idea what it is |
|
340 | - throw new EE_Error( |
|
341 | - sprintf( |
|
342 | - esc_html__( |
|
343 | - // @codingStandardsIgnoreStart |
|
344 | - 'The value "%1$s" for the field "%2$s" on model "%3$s" could not be understood. It should be a PHP DateTime, unix timestamp, MySQL date, or string in the format "%4$s".', |
|
345 | - // @codingStandardsIgnoreEnd |
|
346 | - 'event_espresso' |
|
347 | - ), |
|
348 | - $original_value, |
|
349 | - $field_obj->get_name(), |
|
350 | - $field_obj->get_model_name(), |
|
351 | - $field_obj->get_time_format() . ' ' . $field_obj->get_time_format() |
|
352 | - ) |
|
353 | - ); |
|
354 | - } |
|
355 | - if ($new_value !== null) { |
|
356 | - $new_value = mysql2date('Y-m-d\TH:i:s', $new_value, false); |
|
357 | - } |
|
358 | - } else { |
|
359 | - $new_value = $original_value; |
|
360 | - } |
|
361 | - // are we about to send an object? just don't. We have no good way to represent it in JSON. |
|
362 | - // can't just check using is_object() because that missed PHP incomplete objects |
|
363 | - if (! ModelDataTranslator::isRepresentableInJson($new_value)) { |
|
364 | - $new_value = [ |
|
365 | - 'error_code' => 'php_object_not_return', |
|
366 | - 'error_message' => esc_html__( |
|
367 | - 'The value of this field in the database is a PHP object, which can\'t be represented in JSON.', |
|
368 | - 'event_espresso' |
|
369 | - ), |
|
370 | - ]; |
|
371 | - } |
|
372 | - return apply_filters( |
|
373 | - 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
374 | - $new_value, |
|
375 | - $field_obj, |
|
376 | - $original_value, |
|
377 | - $requested_version |
|
378 | - ); |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * Prepares condition-query-parameters (like what's in where and having) from |
|
384 | - * the format expected in the API to use in the models |
|
385 | - * |
|
386 | - * @param array $inputted_query_params_of_this_type |
|
387 | - * @param EEM_Base $model |
|
388 | - * @param string $requested_version |
|
389 | - * @param boolean $writing whether this data will be written to the DB, or if we're just building a query. |
|
390 | - * If we're writing to the DB, we don't expect any operators, or any logic query |
|
391 | - * parameters, and we also won't accept serialized data unless the current user has |
|
392 | - * unfiltered_html. |
|
393 | - * @return array |
|
394 | - * @throws DomainException |
|
395 | - * @throws EE_Error |
|
396 | - * @throws RestException |
|
397 | - * @throws InvalidDataTypeException |
|
398 | - * @throws InvalidInterfaceException |
|
399 | - * @throws InvalidArgumentException |
|
400 | - */ |
|
401 | - public static function prepareConditionsQueryParamsForModels( |
|
402 | - $inputted_query_params_of_this_type, |
|
403 | - EEM_Base $model, |
|
404 | - $requested_version, |
|
405 | - $writing = false |
|
406 | - ) { |
|
407 | - $query_param_for_models = []; |
|
408 | - $context = new RestIncomingQueryParamContext($model, $requested_version, $writing); |
|
409 | - foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
410 | - $query_param_meta = new RestIncomingQueryParamMetadata($query_param_key, $query_param_value, $context); |
|
411 | - if ($query_param_meta->getField() instanceof EE_Model_Field_Base) { |
|
412 | - $translated_value = $query_param_meta->determineConditionsQueryParameterValue(); |
|
413 | - if ( |
|
414 | - (isset($query_param_for_models[ $query_param_meta->getQueryParamKey() ]) |
|
415 | - && $query_param_meta->isGmtField()) |
|
416 | - || $translated_value === null |
|
417 | - ) { |
|
418 | - // they have already provided a non-gmt field, ignore the gmt one. That's what WP core |
|
419 | - // currently does (they might change it though). See https://core.trac.wordpress.org/ticket/39954 |
|
420 | - // OR we couldn't create a translated value from their input |
|
421 | - continue; |
|
422 | - } |
|
423 | - $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $translated_value; |
|
424 | - } else { |
|
425 | - $nested_query_params = $query_param_meta->determineNestedConditionQueryParameters(); |
|
426 | - if ($nested_query_params) { |
|
427 | - $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $nested_query_params; |
|
428 | - } |
|
429 | - } |
|
430 | - } |
|
431 | - return $query_param_for_models; |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * Mostly checks if the last 4 characters are "_gmt", indicating its a |
|
437 | - * gmt date field name |
|
438 | - * |
|
439 | - * @param string $field_name |
|
440 | - * @return boolean |
|
441 | - */ |
|
442 | - public static function isGmtDateFieldName($field_name) |
|
443 | - { |
|
444 | - $field_name = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($field_name); |
|
445 | - return substr($field_name, -4, 4) === '_gmt'; |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone) |
|
451 | - * |
|
452 | - * @param string $field_name |
|
453 | - * @return string |
|
454 | - */ |
|
455 | - public static function removeGmtFromFieldName($field_name) |
|
456 | - { |
|
457 | - if (! ModelDataTranslator::isGmtDateFieldName($field_name)) { |
|
458 | - return $field_name; |
|
459 | - } |
|
460 | - $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey( |
|
461 | - $field_name |
|
462 | - ); |
|
463 | - $query_param_sans_gmt_and_sans_stars = substr( |
|
464 | - $query_param_sans_stars, |
|
465 | - 0, |
|
466 | - strrpos( |
|
467 | - $field_name, |
|
468 | - '_gmt' |
|
469 | - ) |
|
470 | - ); |
|
471 | - return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name); |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * Takes a field name from the REST API and prepares it for the model querying |
|
477 | - * |
|
478 | - * @param string $field_name |
|
479 | - * @return string |
|
480 | - */ |
|
481 | - public static function prepareFieldNameFromJson($field_name) |
|
482 | - { |
|
483 | - if (ModelDataTranslator::isGmtDateFieldName($field_name)) { |
|
484 | - return ModelDataTranslator::removeGmtFromFieldName($field_name); |
|
485 | - } |
|
486 | - return $field_name; |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * Takes array of field names from REST API and prepares for models |
|
492 | - * |
|
493 | - * @param array $field_names |
|
494 | - * @return array of field names (possibly include model prefixes) |
|
495 | - */ |
|
496 | - public static function prepareFieldNamesFromJson(array $field_names) |
|
497 | - { |
|
498 | - $new_array = []; |
|
499 | - foreach ($field_names as $key => $field_name) { |
|
500 | - $new_array[ $key ] = ModelDataTranslator::prepareFieldNameFromJson($field_name); |
|
501 | - } |
|
502 | - return $new_array; |
|
503 | - } |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * Takes array where array keys are field names (possibly with model path prefixes) |
|
508 | - * from the REST API and prepares them for model querying |
|
509 | - * |
|
510 | - * @param array $field_names_as_keys |
|
511 | - * @return array |
|
512 | - */ |
|
513 | - public static function prepareFieldNamesInArrayKeysFromJson(array $field_names_as_keys) |
|
514 | - { |
|
515 | - $new_array = []; |
|
516 | - foreach ($field_names_as_keys as $field_name => $value) { |
|
517 | - $new_array[ ModelDataTranslator::prepareFieldNameFromJson($field_name) ] = $value; |
|
518 | - } |
|
519 | - return $new_array; |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - /** |
|
524 | - * Prepares an array of model query params for use in the REST API |
|
525 | - * |
|
526 | - * @param array $model_query_params |
|
527 | - * @param EEM_Base $model |
|
528 | - * @param string $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4 |
|
529 | - * REST API |
|
530 | - * @return array which can be passed into the EE4 REST API when querying a model resource |
|
531 | - * @throws EE_Error |
|
532 | - * @throws ReflectionException |
|
533 | - */ |
|
534 | - public static function prepareQueryParamsForRestApi( |
|
535 | - array $model_query_params, |
|
536 | - EEM_Base $model, |
|
537 | - $requested_version = null |
|
538 | - ) { |
|
539 | - if ($requested_version === null) { |
|
540 | - $requested_version = EED_Core_Rest_Api::latest_rest_api_version(); |
|
541 | - } |
|
542 | - $rest_query_params = $model_query_params; |
|
543 | - if (isset($model_query_params[0])) { |
|
544 | - $rest_query_params['where'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi( |
|
545 | - $model_query_params[0], |
|
546 | - $model, |
|
547 | - $requested_version |
|
548 | - ); |
|
549 | - unset($rest_query_params[0]); |
|
550 | - } |
|
551 | - if (isset($model_query_params['having'])) { |
|
552 | - $rest_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi( |
|
553 | - $model_query_params['having'], |
|
554 | - $model, |
|
555 | - $requested_version |
|
556 | - ); |
|
557 | - } |
|
558 | - return apply_filters( |
|
559 | - 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', |
|
560 | - $rest_query_params, |
|
561 | - $model_query_params, |
|
562 | - $model, |
|
563 | - $requested_version |
|
564 | - ); |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api |
|
570 | - * |
|
571 | - * @param array $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params |
|
572 | - * @param EEM_Base $model |
|
573 | - * @param string $requested_version eg "4.8.36" |
|
574 | - * @return array ready for use in the rest api query params |
|
575 | - * @throws EE_Error |
|
576 | - * @throws RestException if somehow a PHP object were in the query params' values,*@throws |
|
577 | - * @throws ReflectionException |
|
578 | - * ReflectionException |
|
579 | - * (which would be really unusual) |
|
580 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
581 | - */ |
|
582 | - public static function prepareConditionsQueryParamsForRestApi( |
|
583 | - $inputted_query_params_of_this_type, |
|
584 | - EEM_Base $model, |
|
585 | - $requested_version |
|
586 | - ) { |
|
587 | - $query_param_for_models = []; |
|
588 | - foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
589 | - $field = ModelDataTranslator::deduceFieldFromQueryParam( |
|
590 | - ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($query_param_key), |
|
591 | - $model |
|
592 | - ); |
|
593 | - if ($field instanceof EE_Model_Field_Base) { |
|
594 | - // did they specify an operator? |
|
595 | - if (is_array($query_param_value)) { |
|
596 | - $op = $query_param_value[0]; |
|
597 | - $translated_value = [$op]; |
|
598 | - if (isset($query_param_value[1])) { |
|
599 | - $value = $query_param_value[1]; |
|
600 | - $translated_value[1] = ModelDataTranslator::prepareFieldValuesForJson( |
|
601 | - $field, |
|
602 | - $value, |
|
603 | - $requested_version |
|
604 | - ); |
|
605 | - } |
|
606 | - } else { |
|
607 | - $translated_value = ModelDataTranslator::prepareFieldValueForJson( |
|
608 | - $field, |
|
609 | - $query_param_value, |
|
610 | - $requested_version |
|
611 | - ); |
|
612 | - } |
|
613 | - $query_param_for_models[ $query_param_key ] = $translated_value; |
|
614 | - } else { |
|
615 | - // so it's not for a field, assume it's a logic query param key |
|
616 | - $query_param_for_models[ $query_param_key ] = |
|
617 | - ModelDataTranslator::prepareConditionsQueryParamsForRestApi( |
|
618 | - $query_param_value, |
|
619 | - $model, |
|
620 | - $requested_version |
|
621 | - ); |
|
622 | - } |
|
623 | - } |
|
624 | - return $query_param_for_models; |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - /** |
|
629 | - * @param $condition_query_param_key |
|
630 | - * @return string |
|
631 | - */ |
|
632 | - public static function removeStarsAndAnythingAfterFromConditionQueryParamKey($condition_query_param_key) |
|
633 | - { |
|
634 | - $pos_of_star = strpos($condition_query_param_key, '*'); |
|
635 | - if ($pos_of_star === false) { |
|
636 | - return $condition_query_param_key; |
|
637 | - } |
|
638 | - return substr($condition_query_param_key, 0, $pos_of_star); |
|
639 | - } |
|
640 | - |
|
641 | - |
|
642 | - /** |
|
643 | - * Takes the input parameter and finds the model field that it indicates. |
|
644 | - * |
|
645 | - * @param string $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID |
|
646 | - * @param EEM_Base $model |
|
647 | - * @return EE_Model_Field_Base |
|
648 | - * @throws EE_Error |
|
649 | - * @throws ReflectionException |
|
650 | - */ |
|
651 | - public static function deduceFieldFromQueryParam($query_param_name, EEM_Base $model) |
|
652 | - { |
|
653 | - // ok, now proceed with deducing which part is the model's name, and which is the field's name |
|
654 | - // which will help us find the database table and column |
|
655 | - $query_param_parts = explode('.', $query_param_name); |
|
656 | - if (empty($query_param_parts)) { |
|
657 | - throw new EE_Error( |
|
658 | - sprintf( |
|
659 | - esc_html__( |
|
660 | - '_extract_column_name is empty when trying to extract column and table name from %s', |
|
661 | - 'event_espresso' |
|
662 | - ), |
|
663 | - $query_param_name |
|
664 | - ) |
|
665 | - ); |
|
666 | - } |
|
667 | - $number_of_parts = count($query_param_parts); |
|
668 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
669 | - $field_name = $last_query_param_part; |
|
670 | - if ($number_of_parts !== 1) { |
|
671 | - // the last part is the column name, and there are only 2parts. therefore... |
|
672 | - $model = EE_Registry::instance()->load_model($query_param_parts[ $number_of_parts - 2 ]); |
|
673 | - } |
|
674 | - try { |
|
675 | - return $model->field_settings_for($field_name, false); |
|
676 | - } catch (EE_Error $e) { |
|
677 | - return null; |
|
678 | - } |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * Returns true if $data can be easily represented in JSON. |
|
684 | - * Basically, objects and resources can't be represented in JSON easily. |
|
685 | - * |
|
686 | - * @param mixed $data |
|
687 | - * @return bool |
|
688 | - */ |
|
689 | - protected static function isRepresentableInJson($data) |
|
690 | - { |
|
691 | - return is_scalar($data) |
|
692 | - || is_array($data) |
|
693 | - || is_null($data); |
|
694 | - } |
|
41 | + /** |
|
42 | + * We used to use -1 for infinity in the rest api, but that's ambiguous for |
|
43 | + * fields that COULD contain -1; so we use null |
|
44 | + */ |
|
45 | + const EE_INF_IN_REST = null; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Prepares a possible array of input values from JSON for use by the models |
|
50 | + * |
|
51 | + * @param EE_Model_Field_Base $field_obj |
|
52 | + * @param mixed $original_value_maybe_array |
|
53 | + * @param string $requested_version |
|
54 | + * @param string $timezone_string treat values as being in this timezone |
|
55 | + * @return mixed |
|
56 | + * @throws RestException |
|
57 | + * @throws EE_Error |
|
58 | + */ |
|
59 | + public static function prepareFieldValuesFromJson( |
|
60 | + $field_obj, |
|
61 | + $original_value_maybe_array, |
|
62 | + $requested_version, |
|
63 | + $timezone_string = 'UTC' |
|
64 | + ) { |
|
65 | + if ( |
|
66 | + is_array($original_value_maybe_array) |
|
67 | + && ! $field_obj instanceof EE_Serialized_Text_Field |
|
68 | + ) { |
|
69 | + $new_value_maybe_array = []; |
|
70 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
71 | + $new_value_maybe_array[ $array_key ] = ModelDataTranslator::prepareFieldValueFromJson( |
|
72 | + $field_obj, |
|
73 | + $array_item, |
|
74 | + $requested_version, |
|
75 | + $timezone_string |
|
76 | + ); |
|
77 | + } |
|
78 | + } else { |
|
79 | + $new_value_maybe_array = ModelDataTranslator::prepareFieldValueFromJson( |
|
80 | + $field_obj, |
|
81 | + $original_value_maybe_array, |
|
82 | + $requested_version, |
|
83 | + $timezone_string |
|
84 | + ); |
|
85 | + } |
|
86 | + return $new_value_maybe_array; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Prepares an array of field values FOR use in JSON/REST API |
|
92 | + * |
|
93 | + * @param EE_Model_Field_Base $field_obj |
|
94 | + * @param mixed $original_value_maybe_array |
|
95 | + * @param string $request_version (eg 4.8.36) |
|
96 | + * @return array|int|string |
|
97 | + * @throws EE_Error |
|
98 | + * @throws EE_Error |
|
99 | + */ |
|
100 | + public static function prepareFieldValuesForJson($field_obj, $original_value_maybe_array, $request_version) |
|
101 | + { |
|
102 | + if (is_array($original_value_maybe_array)) { |
|
103 | + $new_value = []; |
|
104 | + foreach ($original_value_maybe_array as $key => $value) { |
|
105 | + $new_value[ $key ] = ModelDataTranslator::prepareFieldValuesForJson( |
|
106 | + $field_obj, |
|
107 | + $value, |
|
108 | + $request_version |
|
109 | + ); |
|
110 | + } |
|
111 | + } else { |
|
112 | + $new_value = ModelDataTranslator::prepareFieldValueForJson( |
|
113 | + $field_obj, |
|
114 | + $original_value_maybe_array, |
|
115 | + $request_version |
|
116 | + ); |
|
117 | + } |
|
118 | + return $new_value; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * Prepares incoming data from the json or request parameters for the models' |
|
124 | + * "$query_params". |
|
125 | + * |
|
126 | + * @param EE_Model_Field_Base $field_obj |
|
127 | + * @param mixed $original_value |
|
128 | + * @param string $requested_version |
|
129 | + * @param string $timezone_string treat values as being in this timezone |
|
130 | + * @return mixed |
|
131 | + * @throws RestException |
|
132 | + * @throws DomainException |
|
133 | + * @throws EE_Error |
|
134 | + */ |
|
135 | + public static function prepareFieldValueFromJson( |
|
136 | + $field_obj, |
|
137 | + $original_value, |
|
138 | + $requested_version, |
|
139 | + $timezone_string = 'UTC' |
|
140 | + ) { |
|
141 | + // check if they accidentally submitted an error value. If so throw an exception |
|
142 | + if ( |
|
143 | + is_array($original_value) |
|
144 | + && isset($original_value['error_code'], $original_value['error_message']) |
|
145 | + ) { |
|
146 | + throw new RestException( |
|
147 | + 'rest_submitted_error_value', |
|
148 | + sprintf( |
|
149 | + esc_html__( |
|
150 | + 'You tried to submit a JSON error object as a value for %1$s. That\'s not allowed.', |
|
151 | + 'event_espresso' |
|
152 | + ), |
|
153 | + $field_obj->get_name() |
|
154 | + ), |
|
155 | + [ |
|
156 | + 'status' => 400, |
|
157 | + ] |
|
158 | + ); |
|
159 | + } |
|
160 | + // double-check for serialized PHP. We never accept serialized PHP. No way Jose. |
|
161 | + ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value); |
|
162 | + $timezone_string = |
|
163 | + $timezone_string !== '' |
|
164 | + ? $timezone_string |
|
165 | + : get_option('timezone_string', ''); |
|
166 | + // walk through the submitted data and double-check for serialized PHP. We never accept serialized PHP. No |
|
167 | + // way Jose. |
|
168 | + ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value); |
|
169 | + if ( |
|
170 | + $field_obj instanceof EE_Infinite_Integer_Field |
|
171 | + && in_array($original_value, [null, ''], true) |
|
172 | + ) { |
|
173 | + $new_value = EE_INF; |
|
174 | + } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
175 | + $new_value = rest_parse_date( |
|
176 | + self::getTimestampWithTimezoneOffset($original_value, $field_obj, $timezone_string) |
|
177 | + ); |
|
178 | + if ($new_value === false) { |
|
179 | + throw new RestException( |
|
180 | + 'invalid_format_for_timestamp', |
|
181 | + sprintf( |
|
182 | + esc_html__( |
|
183 | + 'Timestamps received on a request as the value for Date and Time fields must be in %1$s/%2$s format. The timestamp provided (%3$s) is not that format.', |
|
184 | + 'event_espresso' |
|
185 | + ), |
|
186 | + 'RFC3339', |
|
187 | + 'ISO8601', |
|
188 | + $original_value |
|
189 | + ), |
|
190 | + [ |
|
191 | + 'status' => 400, |
|
192 | + ] |
|
193 | + ); |
|
194 | + } |
|
195 | + } elseif ($field_obj instanceof EE_Boolean_Field) { |
|
196 | + // Interpreted the strings "false", "true", "on", "off" appropriately. |
|
197 | + $new_value = filter_var($original_value, FILTER_VALIDATE_BOOLEAN); |
|
198 | + } else { |
|
199 | + $new_value = $original_value; |
|
200 | + } |
|
201 | + return $new_value; |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * This checks if the incoming timestamp has timezone information already on it and if it doesn't then adds timezone |
|
207 | + * information via details obtained from the host site. |
|
208 | + * |
|
209 | + * @param string $original_timestamp |
|
210 | + * @param EE_Datetime_Field $datetime_field |
|
211 | + * @param $timezone_string |
|
212 | + * @return string |
|
213 | + * @throws DomainException |
|
214 | + */ |
|
215 | + private static function getTimestampWithTimezoneOffset( |
|
216 | + $original_timestamp, |
|
217 | + EE_Datetime_Field $datetime_field, |
|
218 | + $timezone_string |
|
219 | + ) { |
|
220 | + // already have timezone information? |
|
221 | + if (preg_match('/Z|([+-])(\d{2}:\d{2})/', $original_timestamp)) { |
|
222 | + // yes, we're ignoring the timezone. |
|
223 | + return $original_timestamp; |
|
224 | + } |
|
225 | + // need to append timezone |
|
226 | + list($offset_sign, $offset_secs) = self::parseTimezoneOffset( |
|
227 | + $datetime_field->get_timezone_offset( |
|
228 | + new DateTimeZone($timezone_string), |
|
229 | + $original_timestamp |
|
230 | + ) |
|
231 | + ); |
|
232 | + $offset_string = |
|
233 | + str_pad( |
|
234 | + floor($offset_secs / HOUR_IN_SECONDS), |
|
235 | + 2, |
|
236 | + '0', |
|
237 | + STR_PAD_LEFT |
|
238 | + ) |
|
239 | + . ':' |
|
240 | + . str_pad( |
|
241 | + ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS, |
|
242 | + 2, |
|
243 | + '0', |
|
244 | + STR_PAD_LEFT |
|
245 | + ); |
|
246 | + return $original_timestamp . $offset_sign . $offset_string; |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * Throws an exception if $data is a serialized PHP string (or somehow an actually PHP object, although I don't |
|
252 | + * think that can happen). If $data is an array, recurses into its keys and values |
|
253 | + * |
|
254 | + * @param mixed $data |
|
255 | + * @return void |
|
256 | + * @throws RestException |
|
257 | + */ |
|
258 | + public static function throwExceptionIfContainsSerializedData($data) |
|
259 | + { |
|
260 | + if (is_array($data)) { |
|
261 | + foreach ($data as $key => $value) { |
|
262 | + ModelDataTranslator::throwExceptionIfContainsSerializedData($key); |
|
263 | + ModelDataTranslator::throwExceptionIfContainsSerializedData($value); |
|
264 | + } |
|
265 | + } else { |
|
266 | + if (is_serialized($data) || is_object($data)) { |
|
267 | + throw new RestException( |
|
268 | + 'serialized_data_submission_prohibited', |
|
269 | + esc_html__( |
|
270 | + // @codingStandardsIgnoreStart |
|
271 | + 'You tried to submit a string of serialized text. Serialized PHP is prohibited over the EE4 REST API.', |
|
272 | + // @codingStandardsIgnoreEnd |
|
273 | + 'event_espresso' |
|
274 | + ) |
|
275 | + ); |
|
276 | + } |
|
277 | + } |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * determines what's going on with them timezone strings |
|
283 | + * |
|
284 | + * @param int $timezone_offset |
|
285 | + * @return array |
|
286 | + */ |
|
287 | + private static function parseTimezoneOffset($timezone_offset) |
|
288 | + { |
|
289 | + $first_char = substr((string) $timezone_offset, 0, 1); |
|
290 | + if ($first_char === '+' || $first_char === '-') { |
|
291 | + $offset_sign = $first_char; |
|
292 | + $offset_secs = substr((string) $timezone_offset, 1); |
|
293 | + } else { |
|
294 | + $offset_sign = '+'; |
|
295 | + $offset_secs = $timezone_offset; |
|
296 | + } |
|
297 | + return [$offset_sign, $offset_secs]; |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Prepares a field's value for display in the API |
|
303 | + * |
|
304 | + * @param EE_Model_Field_Base $field_obj |
|
305 | + * @param mixed $original_value |
|
306 | + * @param string $requested_version |
|
307 | + * @return mixed |
|
308 | + * @throws EE_Error |
|
309 | + * @throws EE_Error |
|
310 | + */ |
|
311 | + public static function prepareFieldValueForJson($field_obj, $original_value, $requested_version) |
|
312 | + { |
|
313 | + if ($original_value === EE_INF) { |
|
314 | + $new_value = ModelDataTranslator::EE_INF_IN_REST; |
|
315 | + } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
316 | + if (is_string($original_value)) { |
|
317 | + // did they submit a string of a unix timestamp? |
|
318 | + if (is_numeric($original_value)) { |
|
319 | + $datetime_obj = new DateTime(); |
|
320 | + $datetime_obj->setTimestamp((int) $original_value); |
|
321 | + } else { |
|
322 | + // first, check if its a MySQL timestamp in GMT |
|
323 | + $datetime_obj = DateTime::createFromFormat('Y-m-d H:i:s', $original_value); |
|
324 | + } |
|
325 | + if (! $datetime_obj instanceof DateTime) { |
|
326 | + // so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format? |
|
327 | + $datetime_obj = $field_obj->prepare_for_set($original_value); |
|
328 | + } |
|
329 | + $original_value = $datetime_obj; |
|
330 | + } |
|
331 | + if ($original_value instanceof DateTime) { |
|
332 | + $new_value = $original_value->format('Y-m-d H:i:s'); |
|
333 | + } elseif (is_int($original_value) || is_float($original_value)) { |
|
334 | + $new_value = date('Y-m-d H:i:s', $original_value); |
|
335 | + } elseif ($original_value === null || $original_value === '') { |
|
336 | + $new_value = null; |
|
337 | + } else { |
|
338 | + // so it's not a datetime object, unix timestamp (as string or int), |
|
339 | + // MySQL timestamp, or even a string in the field object's format. So no idea what it is |
|
340 | + throw new EE_Error( |
|
341 | + sprintf( |
|
342 | + esc_html__( |
|
343 | + // @codingStandardsIgnoreStart |
|
344 | + 'The value "%1$s" for the field "%2$s" on model "%3$s" could not be understood. It should be a PHP DateTime, unix timestamp, MySQL date, or string in the format "%4$s".', |
|
345 | + // @codingStandardsIgnoreEnd |
|
346 | + 'event_espresso' |
|
347 | + ), |
|
348 | + $original_value, |
|
349 | + $field_obj->get_name(), |
|
350 | + $field_obj->get_model_name(), |
|
351 | + $field_obj->get_time_format() . ' ' . $field_obj->get_time_format() |
|
352 | + ) |
|
353 | + ); |
|
354 | + } |
|
355 | + if ($new_value !== null) { |
|
356 | + $new_value = mysql2date('Y-m-d\TH:i:s', $new_value, false); |
|
357 | + } |
|
358 | + } else { |
|
359 | + $new_value = $original_value; |
|
360 | + } |
|
361 | + // are we about to send an object? just don't. We have no good way to represent it in JSON. |
|
362 | + // can't just check using is_object() because that missed PHP incomplete objects |
|
363 | + if (! ModelDataTranslator::isRepresentableInJson($new_value)) { |
|
364 | + $new_value = [ |
|
365 | + 'error_code' => 'php_object_not_return', |
|
366 | + 'error_message' => esc_html__( |
|
367 | + 'The value of this field in the database is a PHP object, which can\'t be represented in JSON.', |
|
368 | + 'event_espresso' |
|
369 | + ), |
|
370 | + ]; |
|
371 | + } |
|
372 | + return apply_filters( |
|
373 | + 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
374 | + $new_value, |
|
375 | + $field_obj, |
|
376 | + $original_value, |
|
377 | + $requested_version |
|
378 | + ); |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * Prepares condition-query-parameters (like what's in where and having) from |
|
384 | + * the format expected in the API to use in the models |
|
385 | + * |
|
386 | + * @param array $inputted_query_params_of_this_type |
|
387 | + * @param EEM_Base $model |
|
388 | + * @param string $requested_version |
|
389 | + * @param boolean $writing whether this data will be written to the DB, or if we're just building a query. |
|
390 | + * If we're writing to the DB, we don't expect any operators, or any logic query |
|
391 | + * parameters, and we also won't accept serialized data unless the current user has |
|
392 | + * unfiltered_html. |
|
393 | + * @return array |
|
394 | + * @throws DomainException |
|
395 | + * @throws EE_Error |
|
396 | + * @throws RestException |
|
397 | + * @throws InvalidDataTypeException |
|
398 | + * @throws InvalidInterfaceException |
|
399 | + * @throws InvalidArgumentException |
|
400 | + */ |
|
401 | + public static function prepareConditionsQueryParamsForModels( |
|
402 | + $inputted_query_params_of_this_type, |
|
403 | + EEM_Base $model, |
|
404 | + $requested_version, |
|
405 | + $writing = false |
|
406 | + ) { |
|
407 | + $query_param_for_models = []; |
|
408 | + $context = new RestIncomingQueryParamContext($model, $requested_version, $writing); |
|
409 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
410 | + $query_param_meta = new RestIncomingQueryParamMetadata($query_param_key, $query_param_value, $context); |
|
411 | + if ($query_param_meta->getField() instanceof EE_Model_Field_Base) { |
|
412 | + $translated_value = $query_param_meta->determineConditionsQueryParameterValue(); |
|
413 | + if ( |
|
414 | + (isset($query_param_for_models[ $query_param_meta->getQueryParamKey() ]) |
|
415 | + && $query_param_meta->isGmtField()) |
|
416 | + || $translated_value === null |
|
417 | + ) { |
|
418 | + // they have already provided a non-gmt field, ignore the gmt one. That's what WP core |
|
419 | + // currently does (they might change it though). See https://core.trac.wordpress.org/ticket/39954 |
|
420 | + // OR we couldn't create a translated value from their input |
|
421 | + continue; |
|
422 | + } |
|
423 | + $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $translated_value; |
|
424 | + } else { |
|
425 | + $nested_query_params = $query_param_meta->determineNestedConditionQueryParameters(); |
|
426 | + if ($nested_query_params) { |
|
427 | + $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $nested_query_params; |
|
428 | + } |
|
429 | + } |
|
430 | + } |
|
431 | + return $query_param_for_models; |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * Mostly checks if the last 4 characters are "_gmt", indicating its a |
|
437 | + * gmt date field name |
|
438 | + * |
|
439 | + * @param string $field_name |
|
440 | + * @return boolean |
|
441 | + */ |
|
442 | + public static function isGmtDateFieldName($field_name) |
|
443 | + { |
|
444 | + $field_name = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($field_name); |
|
445 | + return substr($field_name, -4, 4) === '_gmt'; |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone) |
|
451 | + * |
|
452 | + * @param string $field_name |
|
453 | + * @return string |
|
454 | + */ |
|
455 | + public static function removeGmtFromFieldName($field_name) |
|
456 | + { |
|
457 | + if (! ModelDataTranslator::isGmtDateFieldName($field_name)) { |
|
458 | + return $field_name; |
|
459 | + } |
|
460 | + $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey( |
|
461 | + $field_name |
|
462 | + ); |
|
463 | + $query_param_sans_gmt_and_sans_stars = substr( |
|
464 | + $query_param_sans_stars, |
|
465 | + 0, |
|
466 | + strrpos( |
|
467 | + $field_name, |
|
468 | + '_gmt' |
|
469 | + ) |
|
470 | + ); |
|
471 | + return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name); |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * Takes a field name from the REST API and prepares it for the model querying |
|
477 | + * |
|
478 | + * @param string $field_name |
|
479 | + * @return string |
|
480 | + */ |
|
481 | + public static function prepareFieldNameFromJson($field_name) |
|
482 | + { |
|
483 | + if (ModelDataTranslator::isGmtDateFieldName($field_name)) { |
|
484 | + return ModelDataTranslator::removeGmtFromFieldName($field_name); |
|
485 | + } |
|
486 | + return $field_name; |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * Takes array of field names from REST API and prepares for models |
|
492 | + * |
|
493 | + * @param array $field_names |
|
494 | + * @return array of field names (possibly include model prefixes) |
|
495 | + */ |
|
496 | + public static function prepareFieldNamesFromJson(array $field_names) |
|
497 | + { |
|
498 | + $new_array = []; |
|
499 | + foreach ($field_names as $key => $field_name) { |
|
500 | + $new_array[ $key ] = ModelDataTranslator::prepareFieldNameFromJson($field_name); |
|
501 | + } |
|
502 | + return $new_array; |
|
503 | + } |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * Takes array where array keys are field names (possibly with model path prefixes) |
|
508 | + * from the REST API and prepares them for model querying |
|
509 | + * |
|
510 | + * @param array $field_names_as_keys |
|
511 | + * @return array |
|
512 | + */ |
|
513 | + public static function prepareFieldNamesInArrayKeysFromJson(array $field_names_as_keys) |
|
514 | + { |
|
515 | + $new_array = []; |
|
516 | + foreach ($field_names_as_keys as $field_name => $value) { |
|
517 | + $new_array[ ModelDataTranslator::prepareFieldNameFromJson($field_name) ] = $value; |
|
518 | + } |
|
519 | + return $new_array; |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + /** |
|
524 | + * Prepares an array of model query params for use in the REST API |
|
525 | + * |
|
526 | + * @param array $model_query_params |
|
527 | + * @param EEM_Base $model |
|
528 | + * @param string $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4 |
|
529 | + * REST API |
|
530 | + * @return array which can be passed into the EE4 REST API when querying a model resource |
|
531 | + * @throws EE_Error |
|
532 | + * @throws ReflectionException |
|
533 | + */ |
|
534 | + public static function prepareQueryParamsForRestApi( |
|
535 | + array $model_query_params, |
|
536 | + EEM_Base $model, |
|
537 | + $requested_version = null |
|
538 | + ) { |
|
539 | + if ($requested_version === null) { |
|
540 | + $requested_version = EED_Core_Rest_Api::latest_rest_api_version(); |
|
541 | + } |
|
542 | + $rest_query_params = $model_query_params; |
|
543 | + if (isset($model_query_params[0])) { |
|
544 | + $rest_query_params['where'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi( |
|
545 | + $model_query_params[0], |
|
546 | + $model, |
|
547 | + $requested_version |
|
548 | + ); |
|
549 | + unset($rest_query_params[0]); |
|
550 | + } |
|
551 | + if (isset($model_query_params['having'])) { |
|
552 | + $rest_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi( |
|
553 | + $model_query_params['having'], |
|
554 | + $model, |
|
555 | + $requested_version |
|
556 | + ); |
|
557 | + } |
|
558 | + return apply_filters( |
|
559 | + 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', |
|
560 | + $rest_query_params, |
|
561 | + $model_query_params, |
|
562 | + $model, |
|
563 | + $requested_version |
|
564 | + ); |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api |
|
570 | + * |
|
571 | + * @param array $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params |
|
572 | + * @param EEM_Base $model |
|
573 | + * @param string $requested_version eg "4.8.36" |
|
574 | + * @return array ready for use in the rest api query params |
|
575 | + * @throws EE_Error |
|
576 | + * @throws RestException if somehow a PHP object were in the query params' values,*@throws |
|
577 | + * @throws ReflectionException |
|
578 | + * ReflectionException |
|
579 | + * (which would be really unusual) |
|
580 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
581 | + */ |
|
582 | + public static function prepareConditionsQueryParamsForRestApi( |
|
583 | + $inputted_query_params_of_this_type, |
|
584 | + EEM_Base $model, |
|
585 | + $requested_version |
|
586 | + ) { |
|
587 | + $query_param_for_models = []; |
|
588 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
589 | + $field = ModelDataTranslator::deduceFieldFromQueryParam( |
|
590 | + ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($query_param_key), |
|
591 | + $model |
|
592 | + ); |
|
593 | + if ($field instanceof EE_Model_Field_Base) { |
|
594 | + // did they specify an operator? |
|
595 | + if (is_array($query_param_value)) { |
|
596 | + $op = $query_param_value[0]; |
|
597 | + $translated_value = [$op]; |
|
598 | + if (isset($query_param_value[1])) { |
|
599 | + $value = $query_param_value[1]; |
|
600 | + $translated_value[1] = ModelDataTranslator::prepareFieldValuesForJson( |
|
601 | + $field, |
|
602 | + $value, |
|
603 | + $requested_version |
|
604 | + ); |
|
605 | + } |
|
606 | + } else { |
|
607 | + $translated_value = ModelDataTranslator::prepareFieldValueForJson( |
|
608 | + $field, |
|
609 | + $query_param_value, |
|
610 | + $requested_version |
|
611 | + ); |
|
612 | + } |
|
613 | + $query_param_for_models[ $query_param_key ] = $translated_value; |
|
614 | + } else { |
|
615 | + // so it's not for a field, assume it's a logic query param key |
|
616 | + $query_param_for_models[ $query_param_key ] = |
|
617 | + ModelDataTranslator::prepareConditionsQueryParamsForRestApi( |
|
618 | + $query_param_value, |
|
619 | + $model, |
|
620 | + $requested_version |
|
621 | + ); |
|
622 | + } |
|
623 | + } |
|
624 | + return $query_param_for_models; |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + /** |
|
629 | + * @param $condition_query_param_key |
|
630 | + * @return string |
|
631 | + */ |
|
632 | + public static function removeStarsAndAnythingAfterFromConditionQueryParamKey($condition_query_param_key) |
|
633 | + { |
|
634 | + $pos_of_star = strpos($condition_query_param_key, '*'); |
|
635 | + if ($pos_of_star === false) { |
|
636 | + return $condition_query_param_key; |
|
637 | + } |
|
638 | + return substr($condition_query_param_key, 0, $pos_of_star); |
|
639 | + } |
|
640 | + |
|
641 | + |
|
642 | + /** |
|
643 | + * Takes the input parameter and finds the model field that it indicates. |
|
644 | + * |
|
645 | + * @param string $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID |
|
646 | + * @param EEM_Base $model |
|
647 | + * @return EE_Model_Field_Base |
|
648 | + * @throws EE_Error |
|
649 | + * @throws ReflectionException |
|
650 | + */ |
|
651 | + public static function deduceFieldFromQueryParam($query_param_name, EEM_Base $model) |
|
652 | + { |
|
653 | + // ok, now proceed with deducing which part is the model's name, and which is the field's name |
|
654 | + // which will help us find the database table and column |
|
655 | + $query_param_parts = explode('.', $query_param_name); |
|
656 | + if (empty($query_param_parts)) { |
|
657 | + throw new EE_Error( |
|
658 | + sprintf( |
|
659 | + esc_html__( |
|
660 | + '_extract_column_name is empty when trying to extract column and table name from %s', |
|
661 | + 'event_espresso' |
|
662 | + ), |
|
663 | + $query_param_name |
|
664 | + ) |
|
665 | + ); |
|
666 | + } |
|
667 | + $number_of_parts = count($query_param_parts); |
|
668 | + $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
669 | + $field_name = $last_query_param_part; |
|
670 | + if ($number_of_parts !== 1) { |
|
671 | + // the last part is the column name, and there are only 2parts. therefore... |
|
672 | + $model = EE_Registry::instance()->load_model($query_param_parts[ $number_of_parts - 2 ]); |
|
673 | + } |
|
674 | + try { |
|
675 | + return $model->field_settings_for($field_name, false); |
|
676 | + } catch (EE_Error $e) { |
|
677 | + return null; |
|
678 | + } |
|
679 | + } |
|
680 | + |
|
681 | + |
|
682 | + /** |
|
683 | + * Returns true if $data can be easily represented in JSON. |
|
684 | + * Basically, objects and resources can't be represented in JSON easily. |
|
685 | + * |
|
686 | + * @param mixed $data |
|
687 | + * @return bool |
|
688 | + */ |
|
689 | + protected static function isRepresentableInJson($data) |
|
690 | + { |
|
691 | + return is_scalar($data) |
|
692 | + || is_array($data) |
|
693 | + || is_null($data); |
|
694 | + } |
|
695 | 695 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | ? null |
115 | 115 | : $this->_data; |
116 | 116 | |
117 | - if (! $registration instanceof EE_Registration) { |
|
117 | + if ( ! $registration instanceof EE_Registration) { |
|
118 | 118 | // let's attempt to get the txn_id for the error message. |
119 | 119 | $txn_id = isset($this->_extra->txn) && $this->_extra->txn instanceof EE_Transaction |
120 | 120 | ? $this->_extra->txn->ID() |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | // attendee obj for this registration |
134 | - $attendee = isset($this->_extra->registrations[ $registration->ID() ]['att_obj']) |
|
135 | - ? $this->_extra->registrations[ $registration->ID() ]['att_obj'] |
|
134 | + $attendee = isset($this->_extra->registrations[$registration->ID()]['att_obj']) |
|
135 | + ? $this->_extra->registrations[$registration->ID()]['att_obj'] |
|
136 | 136 | : null; |
137 | 137 | |
138 | - if (! $attendee instanceof EE_Attendee) { |
|
139 | - $msg = esc_html__( |
|
138 | + if ( ! $attendee instanceof EE_Attendee) { |
|
139 | + $msg = esc_html__( |
|
140 | 140 | 'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.', |
141 | 141 | 'event_espresso' |
142 | 142 | ); |
@@ -15,192 +15,192 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_Attendee_Shortcodes extends EE_Shortcodes |
17 | 17 | { |
18 | - /** |
|
19 | - * hold all extra data. |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $_extra; |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * EE_Attendee_Shortcodes constructor. |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - parent::__construct(); |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - protected function _init_props() |
|
36 | - { |
|
37 | - $this->label = esc_html__('Attendee Shortcodes', 'event_espresso'); |
|
38 | - $this->description = esc_html__('All shortcodes specific to attendee related data', 'event_espresso'); |
|
39 | - $this->_shortcodes = [ |
|
40 | - '[FNAME]' => esc_html__('First Name of an attendee.', 'event_espresso'), |
|
41 | - '[LNAME]' => esc_html__('Last Name of an attendee.', 'event_espresso'), |
|
42 | - '[ATTENDEE_EMAIL]' => esc_html__('Email address for the attendee.', 'event_espresso'), |
|
43 | - '[EDIT_ATTENDEE_LINK]' => esc_html__( |
|
44 | - 'Edit Registration Link (typically you\'d only use this for messages going to event administrators)', |
|
45 | - 'event_espresso' |
|
46 | - ), |
|
47 | - '[REGISTRATION_ID]' => esc_html__( |
|
48 | - 'Unique Registration ID for the registration', |
|
49 | - 'event_espresso' |
|
50 | - ), |
|
51 | - '[REGISTRATION_CODE]' => esc_html__( |
|
52 | - 'Unique Registration Code for the registration', |
|
53 | - 'event_espresso' |
|
54 | - ), |
|
55 | - '[REGISTRATION_STATUS_ID]' => esc_html__( |
|
56 | - 'Parses to the registration status for the attendee', |
|
57 | - 'event_espresso' |
|
58 | - ), |
|
59 | - '[REGISTRATION_STATUS_LABEL]' => esc_html__( |
|
60 | - 'Parses to the status label for the registrant', |
|
61 | - 'event_espresso' |
|
62 | - ), |
|
63 | - '[REGISTRATION_TOTAL_AMOUNT_PAID]' => esc_html__( |
|
64 | - 'Parses to the total amount paid for this registration.', |
|
65 | - 'event_espresso' |
|
66 | - ), |
|
67 | - '[FRONTEND_EDIT_REG_LINK]' => esc_html__( |
|
68 | - 'Generates a link for the given registration to edit this registration details on the frontend.', |
|
69 | - 'event_espresso' |
|
70 | - ), |
|
71 | - '[PHONE_NUMBER]' => esc_html__( |
|
72 | - 'The Phone Number for the Registration.', |
|
73 | - 'event_espresso' |
|
74 | - ), |
|
75 | - '[ADDRESS]' => esc_html__('The Address for the Registration', 'event_espresso'), |
|
76 | - '[ADDRESS2]' => esc_html__( |
|
77 | - 'Whatever was in the address 2 field for the registration.', |
|
78 | - 'event_espresso' |
|
79 | - ), |
|
80 | - '[CITY]' => esc_html__('The city for the registration.', 'event_espresso'), |
|
81 | - '[ZIP_PC]' => esc_html__( |
|
82 | - 'The ZIP (or Postal) Code for the Registration.', |
|
83 | - 'event_espresso' |
|
84 | - ), |
|
85 | - '[ADDRESS_STATE]' => esc_html__( |
|
86 | - 'The state/province for the registration.', |
|
87 | - 'event_espresso' |
|
88 | - ), |
|
89 | - '[COUNTRY]' => esc_html__('The country for the registration.', 'event_espresso'), |
|
90 | - ]; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * handles shortcode parsing |
|
96 | - * |
|
97 | - * @access protected |
|
98 | - * @param string $shortcode the shortcode to be parsed. |
|
99 | - * @return string |
|
100 | - * @throws EE_Error |
|
101 | - * @throws ReflectionException |
|
102 | - */ |
|
103 | - protected function _parser($shortcode) |
|
104 | - { |
|
105 | - |
|
106 | - |
|
107 | - $this->_extra = ! empty($this->_extra_data) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
108 | - ? $this->_extra_data['data'] |
|
109 | - : null; |
|
110 | - |
|
111 | - // incoming object should only be a registration object. |
|
112 | - $registration = ! $this->_data instanceof EE_Registration |
|
113 | - ? null |
|
114 | - : $this->_data; |
|
115 | - |
|
116 | - if (! $registration instanceof EE_Registration) { |
|
117 | - // let's attempt to get the txn_id for the error message. |
|
118 | - $txn_id = isset($this->_extra->txn) && $this->_extra->txn instanceof EE_Transaction |
|
119 | - ? $this->_extra->txn->ID() |
|
120 | - : esc_html__('Unknown', 'event_espresso'); |
|
121 | - $msg = esc_html__( |
|
122 | - 'There is no EE_Registration object in the data sent to the EE_Attendee Shortcode Parser for the messages system.', |
|
123 | - 'event_espresso' |
|
124 | - ); |
|
125 | - $dev_msg = sprintf( |
|
126 | - esc_html__('The transaction ID for this request is: %s', 'event_espresso'), |
|
127 | - $txn_id |
|
128 | - ); |
|
129 | - throw new EE_Error("{$msg}||{$msg} {$dev_msg}"); |
|
130 | - } |
|
131 | - |
|
132 | - // attendee obj for this registration |
|
133 | - $attendee = isset($this->_extra->registrations[ $registration->ID() ]['att_obj']) |
|
134 | - ? $this->_extra->registrations[ $registration->ID() ]['att_obj'] |
|
135 | - : null; |
|
136 | - |
|
137 | - if (! $attendee instanceof EE_Attendee) { |
|
138 | - $msg = esc_html__( |
|
139 | - 'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.', |
|
140 | - 'event_espresso' |
|
141 | - ); |
|
142 | - $dev_msg = sprintf( |
|
143 | - esc_html__('The registration ID for this request is: %s', 'event_espresso'), |
|
144 | - $registration->ID() |
|
145 | - ); |
|
146 | - throw new EE_Error("{$msg}||{$msg} {$dev_msg}"); |
|
147 | - } |
|
148 | - |
|
149 | - switch ($shortcode) { |
|
150 | - case '[FNAME]': |
|
151 | - return $attendee->fname(); |
|
152 | - |
|
153 | - case '[LNAME]': |
|
154 | - return $attendee->lname(); |
|
155 | - |
|
156 | - case '[ATTENDEE_EMAIL]': |
|
157 | - return $attendee->email(); |
|
158 | - |
|
159 | - case '[EDIT_ATTENDEE_LINK]': |
|
160 | - return $registration->get_admin_edit_url(); |
|
161 | - |
|
162 | - case '[REGISTRATION_CODE]': |
|
163 | - return $registration->reg_code(); |
|
164 | - |
|
165 | - case '[REGISTRATION_ID]': |
|
166 | - return $registration->ID(); |
|
167 | - |
|
168 | - case '[FRONTEND_EDIT_REG_LINK]': |
|
169 | - return $registration->edit_attendee_information_url(); |
|
170 | - |
|
171 | - case '[PHONE_NUMBER]': |
|
172 | - return $attendee->phone(); |
|
173 | - |
|
174 | - case '[ADDRESS]': |
|
175 | - return $attendee->address(); |
|
176 | - |
|
177 | - case '[ADDRESS2]': |
|
178 | - return $attendee->address2(); |
|
179 | - |
|
180 | - case '[CITY]': |
|
181 | - return $attendee->city(); |
|
182 | - |
|
183 | - case '[ZIP_PC]': |
|
184 | - return $attendee->zip(); |
|
185 | - |
|
186 | - case '[ADDRESS_STATE]': |
|
187 | - $state_obj = $attendee->state_obj(); |
|
188 | - return $state_obj instanceof EE_State ? $state_obj->name() : ''; |
|
189 | - |
|
190 | - case '[COUNTRY]': |
|
191 | - $country_obj = $attendee->country_obj(); |
|
192 | - return $country_obj instanceof EE_Country ? $country_obj->name() : ''; |
|
193 | - |
|
194 | - case '[REGISTRATION_STATUS_ID]': |
|
195 | - return $registration->status_ID(); |
|
196 | - |
|
197 | - case '[REGISTRATION_STATUS_LABEL]': |
|
198 | - return $registration->pretty_status(); |
|
199 | - |
|
200 | - case '[REGISTRATION_TOTAL_AMOUNT_PAID]': |
|
201 | - return $registration->pretty_paid(); |
|
202 | - } |
|
203 | - |
|
204 | - return ''; |
|
205 | - } |
|
18 | + /** |
|
19 | + * hold all extra data. |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $_extra; |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * EE_Attendee_Shortcodes constructor. |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + parent::__construct(); |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + protected function _init_props() |
|
36 | + { |
|
37 | + $this->label = esc_html__('Attendee Shortcodes', 'event_espresso'); |
|
38 | + $this->description = esc_html__('All shortcodes specific to attendee related data', 'event_espresso'); |
|
39 | + $this->_shortcodes = [ |
|
40 | + '[FNAME]' => esc_html__('First Name of an attendee.', 'event_espresso'), |
|
41 | + '[LNAME]' => esc_html__('Last Name of an attendee.', 'event_espresso'), |
|
42 | + '[ATTENDEE_EMAIL]' => esc_html__('Email address for the attendee.', 'event_espresso'), |
|
43 | + '[EDIT_ATTENDEE_LINK]' => esc_html__( |
|
44 | + 'Edit Registration Link (typically you\'d only use this for messages going to event administrators)', |
|
45 | + 'event_espresso' |
|
46 | + ), |
|
47 | + '[REGISTRATION_ID]' => esc_html__( |
|
48 | + 'Unique Registration ID for the registration', |
|
49 | + 'event_espresso' |
|
50 | + ), |
|
51 | + '[REGISTRATION_CODE]' => esc_html__( |
|
52 | + 'Unique Registration Code for the registration', |
|
53 | + 'event_espresso' |
|
54 | + ), |
|
55 | + '[REGISTRATION_STATUS_ID]' => esc_html__( |
|
56 | + 'Parses to the registration status for the attendee', |
|
57 | + 'event_espresso' |
|
58 | + ), |
|
59 | + '[REGISTRATION_STATUS_LABEL]' => esc_html__( |
|
60 | + 'Parses to the status label for the registrant', |
|
61 | + 'event_espresso' |
|
62 | + ), |
|
63 | + '[REGISTRATION_TOTAL_AMOUNT_PAID]' => esc_html__( |
|
64 | + 'Parses to the total amount paid for this registration.', |
|
65 | + 'event_espresso' |
|
66 | + ), |
|
67 | + '[FRONTEND_EDIT_REG_LINK]' => esc_html__( |
|
68 | + 'Generates a link for the given registration to edit this registration details on the frontend.', |
|
69 | + 'event_espresso' |
|
70 | + ), |
|
71 | + '[PHONE_NUMBER]' => esc_html__( |
|
72 | + 'The Phone Number for the Registration.', |
|
73 | + 'event_espresso' |
|
74 | + ), |
|
75 | + '[ADDRESS]' => esc_html__('The Address for the Registration', 'event_espresso'), |
|
76 | + '[ADDRESS2]' => esc_html__( |
|
77 | + 'Whatever was in the address 2 field for the registration.', |
|
78 | + 'event_espresso' |
|
79 | + ), |
|
80 | + '[CITY]' => esc_html__('The city for the registration.', 'event_espresso'), |
|
81 | + '[ZIP_PC]' => esc_html__( |
|
82 | + 'The ZIP (or Postal) Code for the Registration.', |
|
83 | + 'event_espresso' |
|
84 | + ), |
|
85 | + '[ADDRESS_STATE]' => esc_html__( |
|
86 | + 'The state/province for the registration.', |
|
87 | + 'event_espresso' |
|
88 | + ), |
|
89 | + '[COUNTRY]' => esc_html__('The country for the registration.', 'event_espresso'), |
|
90 | + ]; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * handles shortcode parsing |
|
96 | + * |
|
97 | + * @access protected |
|
98 | + * @param string $shortcode the shortcode to be parsed. |
|
99 | + * @return string |
|
100 | + * @throws EE_Error |
|
101 | + * @throws ReflectionException |
|
102 | + */ |
|
103 | + protected function _parser($shortcode) |
|
104 | + { |
|
105 | + |
|
106 | + |
|
107 | + $this->_extra = ! empty($this->_extra_data) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
108 | + ? $this->_extra_data['data'] |
|
109 | + : null; |
|
110 | + |
|
111 | + // incoming object should only be a registration object. |
|
112 | + $registration = ! $this->_data instanceof EE_Registration |
|
113 | + ? null |
|
114 | + : $this->_data; |
|
115 | + |
|
116 | + if (! $registration instanceof EE_Registration) { |
|
117 | + // let's attempt to get the txn_id for the error message. |
|
118 | + $txn_id = isset($this->_extra->txn) && $this->_extra->txn instanceof EE_Transaction |
|
119 | + ? $this->_extra->txn->ID() |
|
120 | + : esc_html__('Unknown', 'event_espresso'); |
|
121 | + $msg = esc_html__( |
|
122 | + 'There is no EE_Registration object in the data sent to the EE_Attendee Shortcode Parser for the messages system.', |
|
123 | + 'event_espresso' |
|
124 | + ); |
|
125 | + $dev_msg = sprintf( |
|
126 | + esc_html__('The transaction ID for this request is: %s', 'event_espresso'), |
|
127 | + $txn_id |
|
128 | + ); |
|
129 | + throw new EE_Error("{$msg}||{$msg} {$dev_msg}"); |
|
130 | + } |
|
131 | + |
|
132 | + // attendee obj for this registration |
|
133 | + $attendee = isset($this->_extra->registrations[ $registration->ID() ]['att_obj']) |
|
134 | + ? $this->_extra->registrations[ $registration->ID() ]['att_obj'] |
|
135 | + : null; |
|
136 | + |
|
137 | + if (! $attendee instanceof EE_Attendee) { |
|
138 | + $msg = esc_html__( |
|
139 | + 'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.', |
|
140 | + 'event_espresso' |
|
141 | + ); |
|
142 | + $dev_msg = sprintf( |
|
143 | + esc_html__('The registration ID for this request is: %s', 'event_espresso'), |
|
144 | + $registration->ID() |
|
145 | + ); |
|
146 | + throw new EE_Error("{$msg}||{$msg} {$dev_msg}"); |
|
147 | + } |
|
148 | + |
|
149 | + switch ($shortcode) { |
|
150 | + case '[FNAME]': |
|
151 | + return $attendee->fname(); |
|
152 | + |
|
153 | + case '[LNAME]': |
|
154 | + return $attendee->lname(); |
|
155 | + |
|
156 | + case '[ATTENDEE_EMAIL]': |
|
157 | + return $attendee->email(); |
|
158 | + |
|
159 | + case '[EDIT_ATTENDEE_LINK]': |
|
160 | + return $registration->get_admin_edit_url(); |
|
161 | + |
|
162 | + case '[REGISTRATION_CODE]': |
|
163 | + return $registration->reg_code(); |
|
164 | + |
|
165 | + case '[REGISTRATION_ID]': |
|
166 | + return $registration->ID(); |
|
167 | + |
|
168 | + case '[FRONTEND_EDIT_REG_LINK]': |
|
169 | + return $registration->edit_attendee_information_url(); |
|
170 | + |
|
171 | + case '[PHONE_NUMBER]': |
|
172 | + return $attendee->phone(); |
|
173 | + |
|
174 | + case '[ADDRESS]': |
|
175 | + return $attendee->address(); |
|
176 | + |
|
177 | + case '[ADDRESS2]': |
|
178 | + return $attendee->address2(); |
|
179 | + |
|
180 | + case '[CITY]': |
|
181 | + return $attendee->city(); |
|
182 | + |
|
183 | + case '[ZIP_PC]': |
|
184 | + return $attendee->zip(); |
|
185 | + |
|
186 | + case '[ADDRESS_STATE]': |
|
187 | + $state_obj = $attendee->state_obj(); |
|
188 | + return $state_obj instanceof EE_State ? $state_obj->name() : ''; |
|
189 | + |
|
190 | + case '[COUNTRY]': |
|
191 | + $country_obj = $attendee->country_obj(); |
|
192 | + return $country_obj instanceof EE_Country ? $country_obj->name() : ''; |
|
193 | + |
|
194 | + case '[REGISTRATION_STATUS_ID]': |
|
195 | + return $registration->status_ID(); |
|
196 | + |
|
197 | + case '[REGISTRATION_STATUS_LABEL]': |
|
198 | + return $registration->pretty_status(); |
|
199 | + |
|
200 | + case '[REGISTRATION_TOTAL_AMOUNT_PAID]': |
|
201 | + return $registration->pretty_paid(); |
|
202 | + } |
|
203 | + |
|
204 | + return ''; |
|
205 | + } |
|
206 | 206 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $att_result = ''; |
160 | 160 | $registrations = |
161 | 161 | isset($this->_extra_data['data']->tickets) |
162 | - ? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs'] |
|
162 | + ? $this->_extra_data['data']->tickets[$ticket->ID()]['reg_objs'] |
|
163 | 163 | : []; |
164 | 164 | |
165 | 165 | // each attendee in this case should be an attendee object. |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | private function _get_registrations_from_event(EE_Event $event) |
186 | 186 | { |
187 | 187 | return isset($this->_extra_data['data']->events) |
188 | - ? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs'] |
|
188 | + ? $this->_extra_data['data']->events[$event->ID()]['reg_objs'] |
|
189 | 189 | : []; |
190 | 190 | } |
191 | 191 | } |
@@ -18,167 +18,167 @@ |
||
18 | 18 | */ |
19 | 19 | class EE_Attendee_List_Shortcodes extends EE_Shortcodes |
20 | 20 | { |
21 | - protected function _init_props() |
|
22 | - { |
|
23 | - $this->label = esc_html__('Attendee List Shortcodes', 'event_espresso'); |
|
24 | - $this->description = esc_html__('All shortcodes specific to attendee lists', 'event_espresso'); |
|
25 | - $this->_shortcodes = [ |
|
26 | - '[ATTENDEE_LIST]' => esc_html__('Will output a list of attendees', 'event_espresso'), |
|
27 | - ]; |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @param string $shortcode |
|
33 | - * @return string |
|
34 | - * @throws EE_Error |
|
35 | - * @throws ReflectionException |
|
36 | - */ |
|
37 | - protected function _parser($shortcode) |
|
38 | - { |
|
39 | - switch ($shortcode) { |
|
40 | - case '[ATTENDEE_LIST]': |
|
41 | - return $this->_get_attendee_list(); |
|
42 | - } |
|
43 | - return ''; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * figure out what the incoming data is and then return the appropriate parsed value. |
|
49 | - * |
|
50 | - * @return string |
|
51 | - * @throws EE_Error |
|
52 | - * @throws ReflectionException |
|
53 | - */ |
|
54 | - private function _get_attendee_list() |
|
55 | - { |
|
56 | - $this->_validate_list_requirements(); |
|
57 | - |
|
58 | - if ($this->_data['data'] instanceof EE_Messages_Addressee) { |
|
59 | - return $this->_get_attendee_list_for_main(); |
|
60 | - } |
|
61 | - if ($this->_data['data'] instanceof EE_Event) { |
|
62 | - return $this->_get_attendee_list_for_event(); |
|
63 | - } |
|
64 | - if ($this->_data['data'] instanceof EE_Ticket) { |
|
65 | - return $this->_get_registration_list_for_ticket(); |
|
66 | - } |
|
67 | - // prevent recursive loop |
|
68 | - return ''; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * This returns the parsed attendee list for main template; |
|
74 | - */ |
|
75 | - private function _get_attendee_list_for_main() |
|
76 | - { |
|
77 | - $valid_shortcodes = ['attendee', 'event_list', 'ticket_list', 'question_list', 'recipient_details']; |
|
78 | - $template = $this->_data['template']; |
|
79 | - $data = $this->_data['data']; |
|
80 | - $attendees = ''; |
|
81 | - |
|
82 | - |
|
83 | - // now we need to loop through the attendee list and send data to the EE_Parser helper. |
|
84 | - foreach ($data->reg_objs as $registration) { |
|
85 | - $attendees .= $this->_shortcode_helper->parse_attendee_list_template( |
|
86 | - $template, |
|
87 | - $registration, |
|
88 | - $valid_shortcodes, |
|
89 | - $this->_extra_data |
|
90 | - ); |
|
91 | - } |
|
92 | - |
|
93 | - return $attendees; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * return parsed list of attendees for an event |
|
99 | - * |
|
100 | - * @return string |
|
101 | - * @throws EE_Error |
|
102 | - * @throws ReflectionException |
|
103 | - */ |
|
104 | - private function _get_attendee_list_for_event() |
|
105 | - { |
|
106 | - $valid_shortcodes = ['attendee', 'ticket_list', 'question_list', 'recipient_details']; |
|
107 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list']) |
|
108 | - ? $this->_data['template']['attendee_list'] |
|
109 | - : $this->_extra_data['template']['attendee_list']; |
|
110 | - $event = $this->_data['data']; |
|
111 | - |
|
112 | - // let's remove any existing [EVENT_LIST] shortcode from the attendee list template so that we don't get recursion. |
|
113 | - $template = str_replace('[EVENT_LIST]', '', $template); |
|
114 | - |
|
115 | - // here we're setting up the attendees for the attendee_list template for THIS event. |
|
116 | - $att_result = ''; |
|
117 | - $registrations = $this->_get_registrations_from_event($event); |
|
118 | - |
|
119 | - // each attendee in this case should be an attendee object. |
|
120 | - foreach ($registrations as $registration) { |
|
121 | - $att_result .= $this->_shortcode_helper->parse_attendee_list_template( |
|
122 | - $template, |
|
123 | - $registration, |
|
124 | - $valid_shortcodes, |
|
125 | - $this->_extra_data |
|
126 | - ); |
|
127 | - } |
|
128 | - |
|
129 | - return $att_result; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * return parsed list of attendees for a ticket |
|
135 | - * |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - private function _get_registration_list_for_ticket() |
|
139 | - { |
|
140 | - $valid_shortcodes = ['attendee', 'event_list', 'question_list', 'recipient_details']; |
|
141 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list']) |
|
142 | - ? $this->_data['template']['attendee_list'] |
|
143 | - : $this->_extra_data['template']['attendee_list']; |
|
144 | - $ticket = $this->_data['data']; |
|
145 | - |
|
146 | - // let's remove any existing [TICKET_LIST] (or related) shortcode from the attendee list template so that we don't get recursion. |
|
147 | - $template = str_replace('[TICKET_LIST]', '', $template); |
|
148 | - $template = str_replace('[RECIPIENT_TICKET_LIST]', '', $template); |
|
149 | - $template = str_replace('[PRIMARY_REGISTRANT_TICKET_LIST]', '', $template); |
|
150 | - |
|
151 | - // here we're setting up the attendees for the attendee_list template for THIS ticket. |
|
152 | - $att_result = ''; |
|
153 | - $registrations = |
|
154 | - isset($this->_extra_data['data']->tickets) |
|
155 | - ? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs'] |
|
156 | - : []; |
|
157 | - |
|
158 | - // each attendee in this case should be an attendee object. |
|
159 | - foreach ($registrations as $registration) { |
|
160 | - $att_result .= $this->_shortcode_helper->parse_attendee_list_template( |
|
161 | - $template, |
|
162 | - $registration, |
|
163 | - $valid_shortcodes, |
|
164 | - $this->_extra_data |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - return $att_result; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * @param EE_Event $event |
|
174 | - * @return array|mixed |
|
175 | - * @throws EE_Error |
|
176 | - * @throws ReflectionException |
|
177 | - */ |
|
178 | - private function _get_registrations_from_event(EE_Event $event) |
|
179 | - { |
|
180 | - return isset($this->_extra_data['data']->events) |
|
181 | - ? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs'] |
|
182 | - : []; |
|
183 | - } |
|
21 | + protected function _init_props() |
|
22 | + { |
|
23 | + $this->label = esc_html__('Attendee List Shortcodes', 'event_espresso'); |
|
24 | + $this->description = esc_html__('All shortcodes specific to attendee lists', 'event_espresso'); |
|
25 | + $this->_shortcodes = [ |
|
26 | + '[ATTENDEE_LIST]' => esc_html__('Will output a list of attendees', 'event_espresso'), |
|
27 | + ]; |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @param string $shortcode |
|
33 | + * @return string |
|
34 | + * @throws EE_Error |
|
35 | + * @throws ReflectionException |
|
36 | + */ |
|
37 | + protected function _parser($shortcode) |
|
38 | + { |
|
39 | + switch ($shortcode) { |
|
40 | + case '[ATTENDEE_LIST]': |
|
41 | + return $this->_get_attendee_list(); |
|
42 | + } |
|
43 | + return ''; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * figure out what the incoming data is and then return the appropriate parsed value. |
|
49 | + * |
|
50 | + * @return string |
|
51 | + * @throws EE_Error |
|
52 | + * @throws ReflectionException |
|
53 | + */ |
|
54 | + private function _get_attendee_list() |
|
55 | + { |
|
56 | + $this->_validate_list_requirements(); |
|
57 | + |
|
58 | + if ($this->_data['data'] instanceof EE_Messages_Addressee) { |
|
59 | + return $this->_get_attendee_list_for_main(); |
|
60 | + } |
|
61 | + if ($this->_data['data'] instanceof EE_Event) { |
|
62 | + return $this->_get_attendee_list_for_event(); |
|
63 | + } |
|
64 | + if ($this->_data['data'] instanceof EE_Ticket) { |
|
65 | + return $this->_get_registration_list_for_ticket(); |
|
66 | + } |
|
67 | + // prevent recursive loop |
|
68 | + return ''; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * This returns the parsed attendee list for main template; |
|
74 | + */ |
|
75 | + private function _get_attendee_list_for_main() |
|
76 | + { |
|
77 | + $valid_shortcodes = ['attendee', 'event_list', 'ticket_list', 'question_list', 'recipient_details']; |
|
78 | + $template = $this->_data['template']; |
|
79 | + $data = $this->_data['data']; |
|
80 | + $attendees = ''; |
|
81 | + |
|
82 | + |
|
83 | + // now we need to loop through the attendee list and send data to the EE_Parser helper. |
|
84 | + foreach ($data->reg_objs as $registration) { |
|
85 | + $attendees .= $this->_shortcode_helper->parse_attendee_list_template( |
|
86 | + $template, |
|
87 | + $registration, |
|
88 | + $valid_shortcodes, |
|
89 | + $this->_extra_data |
|
90 | + ); |
|
91 | + } |
|
92 | + |
|
93 | + return $attendees; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * return parsed list of attendees for an event |
|
99 | + * |
|
100 | + * @return string |
|
101 | + * @throws EE_Error |
|
102 | + * @throws ReflectionException |
|
103 | + */ |
|
104 | + private function _get_attendee_list_for_event() |
|
105 | + { |
|
106 | + $valid_shortcodes = ['attendee', 'ticket_list', 'question_list', 'recipient_details']; |
|
107 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list']) |
|
108 | + ? $this->_data['template']['attendee_list'] |
|
109 | + : $this->_extra_data['template']['attendee_list']; |
|
110 | + $event = $this->_data['data']; |
|
111 | + |
|
112 | + // let's remove any existing [EVENT_LIST] shortcode from the attendee list template so that we don't get recursion. |
|
113 | + $template = str_replace('[EVENT_LIST]', '', $template); |
|
114 | + |
|
115 | + // here we're setting up the attendees for the attendee_list template for THIS event. |
|
116 | + $att_result = ''; |
|
117 | + $registrations = $this->_get_registrations_from_event($event); |
|
118 | + |
|
119 | + // each attendee in this case should be an attendee object. |
|
120 | + foreach ($registrations as $registration) { |
|
121 | + $att_result .= $this->_shortcode_helper->parse_attendee_list_template( |
|
122 | + $template, |
|
123 | + $registration, |
|
124 | + $valid_shortcodes, |
|
125 | + $this->_extra_data |
|
126 | + ); |
|
127 | + } |
|
128 | + |
|
129 | + return $att_result; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * return parsed list of attendees for a ticket |
|
135 | + * |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + private function _get_registration_list_for_ticket() |
|
139 | + { |
|
140 | + $valid_shortcodes = ['attendee', 'event_list', 'question_list', 'recipient_details']; |
|
141 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list']) |
|
142 | + ? $this->_data['template']['attendee_list'] |
|
143 | + : $this->_extra_data['template']['attendee_list']; |
|
144 | + $ticket = $this->_data['data']; |
|
145 | + |
|
146 | + // let's remove any existing [TICKET_LIST] (or related) shortcode from the attendee list template so that we don't get recursion. |
|
147 | + $template = str_replace('[TICKET_LIST]', '', $template); |
|
148 | + $template = str_replace('[RECIPIENT_TICKET_LIST]', '', $template); |
|
149 | + $template = str_replace('[PRIMARY_REGISTRANT_TICKET_LIST]', '', $template); |
|
150 | + |
|
151 | + // here we're setting up the attendees for the attendee_list template for THIS ticket. |
|
152 | + $att_result = ''; |
|
153 | + $registrations = |
|
154 | + isset($this->_extra_data['data']->tickets) |
|
155 | + ? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs'] |
|
156 | + : []; |
|
157 | + |
|
158 | + // each attendee in this case should be an attendee object. |
|
159 | + foreach ($registrations as $registration) { |
|
160 | + $att_result .= $this->_shortcode_helper->parse_attendee_list_template( |
|
161 | + $template, |
|
162 | + $registration, |
|
163 | + $valid_shortcodes, |
|
164 | + $this->_extra_data |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + return $att_result; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * @param EE_Event $event |
|
174 | + * @return array|mixed |
|
175 | + * @throws EE_Error |
|
176 | + * @throws ReflectionException |
|
177 | + */ |
|
178 | + private function _get_registrations_from_event(EE_Event $event) |
|
179 | + { |
|
180 | + return isset($this->_extra_data['data']->events) |
|
181 | + ? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs'] |
|
182 | + : []; |
|
183 | + } |
|
184 | 184 | } |
@@ -7,10 +7,10 @@ discard block |
||
7 | 7 | ?> |
8 | 8 | <h2><?php esc_html_e('Event Registration Data', 'event_espresso'); ?></h2> |
9 | 9 | <p><?php |
10 | - esc_html_e( |
|
11 | - 'We collect information about you during event registration. This information may include but is not limited to:', |
|
12 | - 'event_espresso' |
|
13 | - ); ?></p> |
|
10 | + esc_html_e( |
|
11 | + 'We collect information about you during event registration. This information may include but is not limited to:', |
|
12 | + 'event_espresso' |
|
13 | + ); ?></p> |
|
14 | 14 | <ul> |
15 | 15 | <li><?php esc_html_e('Your names', 'event_espresso'); ?></li> |
16 | 16 | <li><?php esc_html_e('Billing address', 'event_espresso'); ?></li> |
@@ -18,16 +18,16 @@ discard block |
||
18 | 18 | <li><?php esc_html_e('Email address', 'event_espresso'); ?></li> |
19 | 19 | <li><?php esc_html_e('Phone number', 'event_espresso'); ?></li> |
20 | 20 | <li><?php |
21 | - esc_html_e( |
|
22 | - 'Location and traffic data (including partial IP address and browser type)', |
|
23 | - 'event_espresso' |
|
24 | - ); ?> |
|
21 | + esc_html_e( |
|
22 | + 'Location and traffic data (including partial IP address and browser type)', |
|
23 | + 'event_espresso' |
|
24 | + ); ?> |
|
25 | 25 | </li> |
26 | 26 | <li><?php |
27 | - esc_html_e( |
|
28 | - 'Any other details that might be requested from you for the purpose of processing your registration or ticket purchase', |
|
29 | - 'event_espresso' |
|
30 | - ); ?> |
|
27 | + esc_html_e( |
|
28 | + 'Any other details that might be requested from you for the purpose of processing your registration or ticket purchase', |
|
29 | + 'event_espresso' |
|
30 | + ); ?> |
|
31 | 31 | </li> |
32 | 32 | </ul> |
33 | 33 | |
@@ -36,101 +36,101 @@ discard block |
||
36 | 36 | <li><?php esc_html_e('Send you important account/purchase/service information.', 'event_espresso'); ?></li> |
37 | 37 | <li><?php esc_html_e('Respond to your queries, refund requests, or complaints.', 'event_espresso'); ?></li> |
38 | 38 | <li><?php |
39 | - esc_html_e( |
|
40 | - 'Process payments and prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', |
|
41 | - 'event_espresso' |
|
42 | - ); ?></li> |
|
39 | + esc_html_e( |
|
40 | + 'Process payments and prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', |
|
41 | + 'event_espresso' |
|
42 | + ); ?></li> |
|
43 | 43 | <li><?php |
44 | - esc_html_e( |
|
45 | - 'Set up and administer your account, provide technical and customer support, and to verify your identity.', |
|
46 | - 'event_espresso' |
|
47 | - ); ?></li> |
|
44 | + esc_html_e( |
|
45 | + 'Set up and administer your account, provide technical and customer support, and to verify your identity.', |
|
46 | + 'event_espresso' |
|
47 | + ); ?></li> |
|
48 | 48 | </ul> |
49 | 49 | |
50 | 50 | <?php if (! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?> |
51 | 51 | <h2><?php esc_html_e('Billing Information', 'event_espresso'); ?> </h2> |
52 | 52 | <?php |
53 | - // if onsite or offsite payment methods are active |
|
54 | - if (! empty($active_onsite_payment_methods)) { ?> |
|
53 | + // if onsite or offsite payment methods are active |
|
54 | + if (! empty($active_onsite_payment_methods)) { ?> |
|
55 | 55 | <p><?php |
56 | - esc_html_e( |
|
57 | - 'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.', |
|
58 | - 'event_espresso' |
|
59 | - ); ?></p> |
|
56 | + esc_html_e( |
|
57 | + 'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.', |
|
58 | + 'event_espresso' |
|
59 | + ); ?></p> |
|
60 | 60 | <p><?php |
61 | - printf( |
|
62 | - esc_html_x( |
|
63 | - 'Please see the privacy policy of %1$s.', |
|
64 | - 'Please see the privacy policy of PayPal Pro', |
|
65 | - 'event_espresso' |
|
66 | - ), |
|
67 | - implode( |
|
68 | - ', ', |
|
69 | - array_merge( |
|
70 | - $active_onsite_payment_methods, |
|
71 | - $active_offsite_payment_methods |
|
72 | - ) |
|
73 | - ) |
|
74 | - ); ?></p> |
|
61 | + printf( |
|
62 | + esc_html_x( |
|
63 | + 'Please see the privacy policy of %1$s.', |
|
64 | + 'Please see the privacy policy of PayPal Pro', |
|
65 | + 'event_espresso' |
|
66 | + ), |
|
67 | + implode( |
|
68 | + ', ', |
|
69 | + array_merge( |
|
70 | + $active_onsite_payment_methods, |
|
71 | + $active_offsite_payment_methods |
|
72 | + ) |
|
73 | + ) |
|
74 | + ); ?></p> |
|
75 | 75 | <p><?php |
76 | - esc_html_e( |
|
77 | - 'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).', |
|
78 | - 'event_espresso' |
|
79 | - ); ?></p> |
|
76 | + esc_html_e( |
|
77 | + 'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).', |
|
78 | + 'event_espresso' |
|
79 | + ); ?></p> |
|
80 | 80 | <?php } elseif (! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?> |
81 | 81 | <p><?php |
82 | - printf( |
|
83 | - esc_html_x( |
|
84 | - 'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of %1$s.', |
|
85 | - 'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of PayPal Pro.', |
|
86 | - 'event_espresso' |
|
87 | - ), |
|
88 | - implode(', ', $active_offsite_payment_methods) |
|
89 | - ); ?></p> |
|
82 | + printf( |
|
83 | + esc_html_x( |
|
84 | + 'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of %1$s.', |
|
85 | + 'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of PayPal Pro.', |
|
86 | + 'event_espresso' |
|
87 | + ), |
|
88 | + implode(', ', $active_offsite_payment_methods) |
|
89 | + ); ?></p> |
|
90 | 90 | <?php } ?> |
91 | 91 | <h2><?php esc_html_e('Payment Logging', 'event_espresso'); ?></h2> |
92 | 92 | <p><?php |
93 | - esc_html_e( |
|
94 | - 'Site administrators may keep a log of communications with the payment processors in order to verify payments are being processed correctly. These logs are automatically deleted after a week.', |
|
95 | - 'event_espresso' |
|
96 | - ); ?></p> |
|
93 | + esc_html_e( |
|
94 | + 'Site administrators may keep a log of communications with the payment processors in order to verify payments are being processed correctly. These logs are automatically deleted after a week.', |
|
95 | + 'event_espresso' |
|
96 | + ); ?></p> |
|
97 | 97 | <?php } ?> |
98 | 98 | |
99 | 99 | <h2><?php esc_html_e('Event Registration Cookies', 'event_espresso'); ?></h2> |
100 | 100 | <p><?php |
101 | - printf( |
|
102 | - esc_html_x( |
|
103 | - 'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts %1$s.', |
|
104 | - 'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts 2 hours.', |
|
105 | - 'event_espresso' |
|
106 | - ), |
|
107 | - $session_lifespan |
|
108 | - ); ?></p> |
|
101 | + printf( |
|
102 | + esc_html_x( |
|
103 | + 'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts %1$s.', |
|
104 | + 'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts 2 hours.', |
|
105 | + 'event_espresso' |
|
106 | + ), |
|
107 | + $session_lifespan |
|
108 | + ); ?></p> |
|
109 | 109 | |
110 | 110 | <h2><?php esc_html_e('Email History Data', 'event_espresso'); ?></h2> |
111 | 111 | <p><?php |
112 | - esc_html_e( |
|
113 | - 'We keep a record of the emails sent to you. This is to ensure communication is successfully sent and its information is accurate.', |
|
114 | - 'event_espresso' |
|
115 | - ); ?></p> |
|
112 | + esc_html_e( |
|
113 | + 'We keep a record of the emails sent to you. This is to ensure communication is successfully sent and its information is accurate.', |
|
114 | + 'event_espresso' |
|
115 | + ); ?></p> |
|
116 | 116 | |
117 | 117 | <h2><?php esc_html_e('Event Check-In Record', 'event_espresso'); ?></h2> |
118 | 118 | <p><?php |
119 | - esc_html_e( |
|
120 | - 'When you attend an event, an event manager may record the time you check in or out of the event.', |
|
121 | - 'event_espresso' |
|
122 | - ); ?></p> |
|
119 | + esc_html_e( |
|
120 | + 'When you attend an event, an event manager may record the time you check in or out of the event.', |
|
121 | + 'event_espresso' |
|
122 | + ); ?></p> |
|
123 | 123 | |
124 | 124 | <h2><?php esc_html_e('Event Registration Data Retention', 'event_espresso'); ?></h2> |
125 | 125 | <p><?php |
126 | - esc_html_e( |
|
127 | - 'Personal data is stored at least until the date of the event, and may be kept indefinitely in case of future registrations.', |
|
128 | - 'event_espresso' |
|
129 | - ); ?></p> |
|
126 | + esc_html_e( |
|
127 | + 'Personal data is stored at least until the date of the event, and may be kept indefinitely in case of future registrations.', |
|
128 | + 'event_espresso' |
|
129 | + ); ?></p> |
|
130 | 130 | |
131 | 131 | <h2><?php esc_html_e('Event Registration Data Erasure and Export', 'event_espresso'); ?></h2> |
132 | 132 | <p><?php |
133 | - esc_html_e( |
|
134 | - 'You have the right to request your personal data be sent to you electronically, and the right to request your registration data be erased after the event. To do so, please contact the event manager or site administrator.', |
|
135 | - 'event_espresso' |
|
136 | - ); ?></p> |
|
133 | + esc_html_e( |
|
134 | + 'You have the right to request your personal data be sent to you electronically, and the right to request your registration data be erased after the event. To do so, please contact the event manager or site administrator.', |
|
135 | + 'event_espresso' |
|
136 | + ); ?></p> |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | ); ?></li> |
48 | 48 | </ul> |
49 | 49 | |
50 | -<?php if (! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?> |
|
50 | +<?php if ( ! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?> |
|
51 | 51 | <h2><?php esc_html_e('Billing Information', 'event_espresso'); ?> </h2> |
52 | 52 | <?php |
53 | 53 | // if onsite or offsite payment methods are active |
54 | - if (! empty($active_onsite_payment_methods)) { ?> |
|
54 | + if ( ! empty($active_onsite_payment_methods)) { ?> |
|
55 | 55 | <p><?php |
56 | 56 | esc_html_e( |
57 | 57 | 'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.', |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | 'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).', |
78 | 78 | 'event_espresso' |
79 | 79 | ); ?></p> |
80 | - <?php } elseif (! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?> |
|
80 | + <?php } elseif ( ! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?> |
|
81 | 81 | <p><?php |
82 | 82 | printf( |
83 | 83 | esc_html_x( |
@@ -11,48 +11,48 @@ |
||
11 | 11 | * @version 4+ |
12 | 12 | */ |
13 | 13 | if (have_posts()) : |
14 | - if (apply_filters('FHEE__archive_espresso_events_template__show_header', true)) : ?> |
|
14 | + if (apply_filters('FHEE__archive_espresso_events_template__show_header', true)) : ?> |
|
15 | 15 | <header class="page-header"> |
16 | 16 | <h1 class="page-title"> |
17 | 17 | <?php |
18 | - if (is_day()) : |
|
19 | - printf(esc_html__('Today\'s Events: %s', 'event_espresso'), get_the_date()); |
|
20 | - elseif (is_month()) : |
|
21 | - printf( |
|
22 | - esc_html__('Events This Month: %s', 'event_espresso'), |
|
23 | - get_the_date(_x('F Y', 'monthly archives date format', 'event_espresso')) |
|
24 | - ); |
|
25 | - elseif (is_year()) : |
|
26 | - printf( |
|
27 | - esc_html__('Events This Year: %s', 'event_espresso'), |
|
28 | - get_the_date(_x('Y', 'yearly archives date format', 'event_espresso')) |
|
29 | - ); |
|
30 | - else : |
|
31 | - echo apply_filters( |
|
32 | - 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
33 | - esc_html__('Upcoming Events', 'event_espresso') |
|
34 | - ); |
|
35 | - endif; |
|
36 | - ?> |
|
18 | + if (is_day()) : |
|
19 | + printf(esc_html__('Today\'s Events: %s', 'event_espresso'), get_the_date()); |
|
20 | + elseif (is_month()) : |
|
21 | + printf( |
|
22 | + esc_html__('Events This Month: %s', 'event_espresso'), |
|
23 | + get_the_date(_x('F Y', 'monthly archives date format', 'event_espresso')) |
|
24 | + ); |
|
25 | + elseif (is_year()) : |
|
26 | + printf( |
|
27 | + esc_html__('Events This Year: %s', 'event_espresso'), |
|
28 | + get_the_date(_x('Y', 'yearly archives date format', 'event_espresso')) |
|
29 | + ); |
|
30 | + else : |
|
31 | + echo apply_filters( |
|
32 | + 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
33 | + esc_html__('Upcoming Events', 'event_espresso') |
|
34 | + ); |
|
35 | + endif; |
|
36 | + ?> |
|
37 | 37 | </h1> |
38 | 38 | |
39 | 39 | </header><!-- .page-header --> |
40 | 40 | |
41 | 41 | <?php |
42 | - endif; |
|
43 | - // allow other stuff |
|
44 | - do_action('AHEE__archive_espresso_events_template__before_loop'); |
|
45 | - // Start the Loop. |
|
46 | - while (have_posts()) : the_post(); |
|
47 | - // Include the post TYPE-specific template for the content. |
|
48 | - espresso_get_template_part('content', 'espresso_events-shortcode'); |
|
49 | - endwhile; |
|
50 | - // Previous/next page navigation. |
|
51 | - espresso_pagination(); |
|
52 | - // allow moar other stuff |
|
53 | - do_action('AHEE__archive_espresso_events_template__after_loop'); |
|
42 | + endif; |
|
43 | + // allow other stuff |
|
44 | + do_action('AHEE__archive_espresso_events_template__before_loop'); |
|
45 | + // Start the Loop. |
|
46 | + while (have_posts()) : the_post(); |
|
47 | + // Include the post TYPE-specific template for the content. |
|
48 | + espresso_get_template_part('content', 'espresso_events-shortcode'); |
|
49 | + endwhile; |
|
50 | + // Previous/next page navigation. |
|
51 | + espresso_pagination(); |
|
52 | + // allow moar other stuff |
|
53 | + do_action('AHEE__archive_espresso_events_template__after_loop'); |
|
54 | 54 | else : |
55 | - // If no content, include the "No posts found" template. |
|
56 | - espresso_get_template_part('content', 'none'); |
|
55 | + // If no content, include the "No posts found" template. |
|
56 | + espresso_get_template_part('content', 'none'); |
|
57 | 57 | endif; |
58 | 58 |
@@ -27,11 +27,13 @@ discard block |
||
27 | 27 | esc_html__('Events This Year: %s', 'event_espresso'), |
28 | 28 | get_the_date(_x('Y', 'yearly archives date format', 'event_espresso')) |
29 | 29 | ); |
30 | - else : |
|
30 | + else { |
|
31 | + : |
|
31 | 32 | echo apply_filters( |
32 | 33 | 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
33 | 34 | esc_html__('Upcoming Events', 'event_espresso') |
34 | 35 | ); |
36 | + } |
|
35 | 37 | endif; |
36 | 38 | ?> |
37 | 39 | </h1> |
@@ -51,8 +53,10 @@ discard block |
||
51 | 53 | espresso_pagination(); |
52 | 54 | // allow moar other stuff |
53 | 55 | do_action('AHEE__archive_espresso_events_template__after_loop'); |
54 | -else : |
|
56 | +else { |
|
57 | + : |
|
55 | 58 | // If no content, include the "No posts found" template. |
56 | 59 | espresso_get_template_part('content', 'none'); |
60 | +} |
|
57 | 61 | endif; |
58 | 62 |
@@ -9,9 +9,9 @@ discard block |
||
9 | 9 | * @ link http://www.eventespresso.com |
10 | 10 | * @ version 4+ |
11 | 11 | */ |
12 | -define( 'EE_THEME_FUNCTIONS_LOADED', TRUE ); |
|
12 | +define('EE_THEME_FUNCTIONS_LOADED', TRUE); |
|
13 | 13 | |
14 | -if ( ! function_exists( 'espresso_pagination' ) ) { |
|
14 | +if ( ! function_exists('espresso_pagination')) { |
|
15 | 15 | /** |
16 | 16 | * espresso_pagination |
17 | 17 | * |
@@ -23,21 +23,21 @@ discard block |
||
23 | 23 | $big = 999999999; // need an unlikely integer |
24 | 24 | $pagination = paginate_links( |
25 | 25 | array( |
26 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
26 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
27 | 27 | 'format' => '?paged=%#%', |
28 | - 'current' => max( 1, get_query_var( 'paged' ) ), |
|
28 | + 'current' => max(1, get_query_var('paged')), |
|
29 | 29 | 'total' => $wp_query->max_num_pages, |
30 | 30 | 'show_all' => true, |
31 | 31 | 'end_size' => 10, |
32 | 32 | 'mid_size' => 6, |
33 | 33 | 'prev_next' => true, |
34 | - 'prev_text' => esc_html__( '‹ PREV', 'event_espresso' ), |
|
35 | - 'next_text' => esc_html__( 'NEXT ›', 'event_espresso' ), |
|
34 | + 'prev_text' => esc_html__('‹ PREV', 'event_espresso'), |
|
35 | + 'next_text' => esc_html__('NEXT ›', 'event_espresso'), |
|
36 | 36 | 'type' => 'plain', |
37 | 37 | 'add_args' => false, |
38 | 38 | 'add_fragment' => '' |
39 | 39 | ) |
40 | 40 | ); |
41 | - echo ! empty( $pagination ) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
41 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : ''; |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | \ No newline at end of file |