@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | public function setOrder($order) |
114 | 114 | { |
115 | 115 | $order = absint($order); |
116 | - if (! $order > 0) { |
|
116 | + if ( ! $order > 0) { |
|
117 | 117 | throw new InvalidArgumentException( |
118 | 118 | esc_html__('The form order property must be a positive integer.', 'event_espresso') |
119 | 119 | ); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function setRedirectUrl($redirect_url) |
144 | 144 | { |
145 | - if (! is_string($redirect_url)) { |
|
145 | + if ( ! is_string($redirect_url)) { |
|
146 | 146 | throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string'); |
147 | 147 | } |
148 | 148 | if (empty($redirect_url)) { |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | ); |
200 | 200 | } |
201 | 201 | foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) { |
202 | - unset($this->redirect_args[ $redirect_arg_key ]); |
|
202 | + unset($this->redirect_args[$redirect_arg_key]); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 |
@@ -18,227 +18,227 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class SequentialStepForm extends FormHandler implements SequentialStepFormInterface |
20 | 20 | { |
21 | - const REDIRECT_TO_NEXT_STEP = 'redirect_to_next_step'; |
|
22 | - |
|
23 | - const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step'; |
|
24 | - |
|
25 | - const REDIRECT_TO_PREV_STEP = 'redirect_to_prev_step'; |
|
26 | - |
|
27 | - const REDIRECT_TO_OTHER = 'redirect_to_other'; |
|
28 | - |
|
29 | - /** |
|
30 | - * numerical value used for sorting form steps |
|
31 | - * |
|
32 | - * @var int $order |
|
33 | - */ |
|
34 | - private $order = 1; |
|
35 | - |
|
36 | - /** |
|
37 | - * a final URL with all form related parameters added |
|
38 | - * that will be used to advance to the next step |
|
39 | - * |
|
40 | - * @var string $redirect_url |
|
41 | - */ |
|
42 | - private $redirect_url = ''; |
|
43 | - |
|
44 | - /** |
|
45 | - * URL params in key value pairs |
|
46 | - * |
|
47 | - * @var array $redirect_args |
|
48 | - */ |
|
49 | - private $redirect_args = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * Which step should be redirected to after form processing. |
|
53 | - * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP |
|
54 | - * If a form is invalid and requires errors to be corrected, |
|
55 | - * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted |
|
56 | - * Some form handlers do not have a form that is displayable, |
|
57 | - * and only perform data processing, but if an error occurs, |
|
58 | - * then this value needs to be set to REDIRECT_TO_PREV_STEP |
|
59 | - * since the current step has no displayable content. |
|
60 | - * if the form is completely finished, and needs to redirect to somewhere |
|
61 | - * completely different, then this value will be REDIRECT_TO_OTHER |
|
62 | - * |
|
63 | - * @var string $redirect_to |
|
64 | - */ |
|
65 | - private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP; |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * SequentialStepForm constructor |
|
70 | - * |
|
71 | - * @param int $order |
|
72 | - * @param string $form_name |
|
73 | - * @param string $admin_name |
|
74 | - * @param string $slug |
|
75 | - * @param string $form_action |
|
76 | - * @param string $form_config |
|
77 | - * @param EE_Registry|null $registry |
|
78 | - * @throws InvalidArgumentException |
|
79 | - * @throws InvalidDataTypeException |
|
80 | - * @throws DomainException |
|
81 | - */ |
|
82 | - public function __construct( |
|
83 | - $order, |
|
84 | - $form_name, |
|
85 | - $admin_name, |
|
86 | - $slug, |
|
87 | - $form_action = '', |
|
88 | - $form_config = 'add_form_tags_and_submit', |
|
89 | - ?EE_Registry $registry = null |
|
90 | - ) { |
|
91 | - $this->setOrder($order); |
|
92 | - parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @return int |
|
99 | - */ |
|
100 | - public function order() |
|
101 | - { |
|
102 | - return $this->order; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @param int $order |
|
109 | - * @throws InvalidArgumentException |
|
110 | - */ |
|
111 | - public function setOrder($order) |
|
112 | - { |
|
113 | - $order = absint($order); |
|
114 | - if (! $order > 0) { |
|
115 | - throw new InvalidArgumentException( |
|
116 | - esc_html__('The form order property must be a positive integer.', 'event_espresso') |
|
117 | - ); |
|
118 | - } |
|
119 | - $this->order = $order; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public function redirectUrl() |
|
128 | - { |
|
129 | - return ! empty($this->redirect_args) |
|
130 | - ? add_query_arg($this->redirect_args, $this->redirect_url) |
|
131 | - : $this->redirect_url; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @param string $redirect_url |
|
138 | - * @throws InvalidDataTypeException |
|
139 | - * @throws InvalidArgumentException |
|
140 | - */ |
|
141 | - public function setRedirectUrl($redirect_url) |
|
142 | - { |
|
143 | - if (! is_string($redirect_url)) { |
|
144 | - throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string'); |
|
145 | - } |
|
146 | - if (empty($redirect_url)) { |
|
147 | - throw new InvalidArgumentException( |
|
148 | - esc_html__('The redirect URL can not be an empty string.', 'event_espresso') |
|
149 | - ); |
|
150 | - } |
|
151 | - $this->redirect_url = $redirect_url; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @param array $redirect_args |
|
158 | - * @throws InvalidDataTypeException |
|
159 | - * @throws InvalidArgumentException |
|
160 | - */ |
|
161 | - public function addRedirectArgs($redirect_args = array()) |
|
162 | - { |
|
163 | - if (is_object($redirect_args)) { |
|
164 | - throw new InvalidDataTypeException( |
|
165 | - '$redirect_args', |
|
166 | - $redirect_args, |
|
167 | - 'anything other than an object was expected.' |
|
168 | - ); |
|
169 | - } |
|
170 | - if (empty($redirect_args)) { |
|
171 | - throw new InvalidArgumentException( |
|
172 | - esc_html__('The redirect argument can not be an empty array.', 'event_espresso') |
|
173 | - ); |
|
174 | - } |
|
175 | - $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * @param array $redirect_arg_keys_to_remove |
|
182 | - * @throws InvalidDataTypeException |
|
183 | - * @throws InvalidArgumentException |
|
184 | - */ |
|
185 | - public function removeRedirectArgs($redirect_arg_keys_to_remove = array()) |
|
186 | - { |
|
187 | - if (is_object($redirect_arg_keys_to_remove)) { |
|
188 | - throw new InvalidDataTypeException( |
|
189 | - '$redirect_arg_keys_to_remove', |
|
190 | - $redirect_arg_keys_to_remove, |
|
191 | - 'anything other than an object was expected.' |
|
192 | - ); |
|
193 | - } |
|
194 | - if (empty($redirect_arg_keys_to_remove)) { |
|
195 | - throw new InvalidArgumentException( |
|
196 | - esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso') |
|
197 | - ); |
|
198 | - } |
|
199 | - foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) { |
|
200 | - unset($this->redirect_args[ $redirect_arg_key ]); |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * @return string |
|
208 | - */ |
|
209 | - public function redirectTo() |
|
210 | - { |
|
211 | - return $this->redirect_to; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * @param string $redirect_to |
|
218 | - * @throws InvalidDataTypeException |
|
219 | - */ |
|
220 | - public function setRedirectTo($redirect_to) |
|
221 | - { |
|
222 | - if ( |
|
223 | - ! in_array( |
|
224 | - $redirect_to, |
|
225 | - array( |
|
226 | - SequentialStepForm::REDIRECT_TO_NEXT_STEP, |
|
227 | - SequentialStepForm::REDIRECT_TO_CURRENT_STEP, |
|
228 | - SequentialStepForm::REDIRECT_TO_PREV_STEP, |
|
229 | - SequentialStepForm::REDIRECT_TO_OTHER, |
|
230 | - ), |
|
231 | - true |
|
232 | - ) |
|
233 | - ) { |
|
234 | - throw new InvalidDataTypeException( |
|
235 | - 'setRedirectTo()', |
|
236 | - $redirect_to, |
|
237 | - 'one of the SequentialStepForm class constants was expected.' |
|
238 | - ); |
|
239 | - } |
|
240 | - $this->redirect_to = $redirect_to; |
|
241 | - } |
|
21 | + const REDIRECT_TO_NEXT_STEP = 'redirect_to_next_step'; |
|
22 | + |
|
23 | + const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step'; |
|
24 | + |
|
25 | + const REDIRECT_TO_PREV_STEP = 'redirect_to_prev_step'; |
|
26 | + |
|
27 | + const REDIRECT_TO_OTHER = 'redirect_to_other'; |
|
28 | + |
|
29 | + /** |
|
30 | + * numerical value used for sorting form steps |
|
31 | + * |
|
32 | + * @var int $order |
|
33 | + */ |
|
34 | + private $order = 1; |
|
35 | + |
|
36 | + /** |
|
37 | + * a final URL with all form related parameters added |
|
38 | + * that will be used to advance to the next step |
|
39 | + * |
|
40 | + * @var string $redirect_url |
|
41 | + */ |
|
42 | + private $redirect_url = ''; |
|
43 | + |
|
44 | + /** |
|
45 | + * URL params in key value pairs |
|
46 | + * |
|
47 | + * @var array $redirect_args |
|
48 | + */ |
|
49 | + private $redirect_args = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * Which step should be redirected to after form processing. |
|
53 | + * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP |
|
54 | + * If a form is invalid and requires errors to be corrected, |
|
55 | + * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted |
|
56 | + * Some form handlers do not have a form that is displayable, |
|
57 | + * and only perform data processing, but if an error occurs, |
|
58 | + * then this value needs to be set to REDIRECT_TO_PREV_STEP |
|
59 | + * since the current step has no displayable content. |
|
60 | + * if the form is completely finished, and needs to redirect to somewhere |
|
61 | + * completely different, then this value will be REDIRECT_TO_OTHER |
|
62 | + * |
|
63 | + * @var string $redirect_to |
|
64 | + */ |
|
65 | + private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP; |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * SequentialStepForm constructor |
|
70 | + * |
|
71 | + * @param int $order |
|
72 | + * @param string $form_name |
|
73 | + * @param string $admin_name |
|
74 | + * @param string $slug |
|
75 | + * @param string $form_action |
|
76 | + * @param string $form_config |
|
77 | + * @param EE_Registry|null $registry |
|
78 | + * @throws InvalidArgumentException |
|
79 | + * @throws InvalidDataTypeException |
|
80 | + * @throws DomainException |
|
81 | + */ |
|
82 | + public function __construct( |
|
83 | + $order, |
|
84 | + $form_name, |
|
85 | + $admin_name, |
|
86 | + $slug, |
|
87 | + $form_action = '', |
|
88 | + $form_config = 'add_form_tags_and_submit', |
|
89 | + ?EE_Registry $registry = null |
|
90 | + ) { |
|
91 | + $this->setOrder($order); |
|
92 | + parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @return int |
|
99 | + */ |
|
100 | + public function order() |
|
101 | + { |
|
102 | + return $this->order; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @param int $order |
|
109 | + * @throws InvalidArgumentException |
|
110 | + */ |
|
111 | + public function setOrder($order) |
|
112 | + { |
|
113 | + $order = absint($order); |
|
114 | + if (! $order > 0) { |
|
115 | + throw new InvalidArgumentException( |
|
116 | + esc_html__('The form order property must be a positive integer.', 'event_espresso') |
|
117 | + ); |
|
118 | + } |
|
119 | + $this->order = $order; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public function redirectUrl() |
|
128 | + { |
|
129 | + return ! empty($this->redirect_args) |
|
130 | + ? add_query_arg($this->redirect_args, $this->redirect_url) |
|
131 | + : $this->redirect_url; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @param string $redirect_url |
|
138 | + * @throws InvalidDataTypeException |
|
139 | + * @throws InvalidArgumentException |
|
140 | + */ |
|
141 | + public function setRedirectUrl($redirect_url) |
|
142 | + { |
|
143 | + if (! is_string($redirect_url)) { |
|
144 | + throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string'); |
|
145 | + } |
|
146 | + if (empty($redirect_url)) { |
|
147 | + throw new InvalidArgumentException( |
|
148 | + esc_html__('The redirect URL can not be an empty string.', 'event_espresso') |
|
149 | + ); |
|
150 | + } |
|
151 | + $this->redirect_url = $redirect_url; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @param array $redirect_args |
|
158 | + * @throws InvalidDataTypeException |
|
159 | + * @throws InvalidArgumentException |
|
160 | + */ |
|
161 | + public function addRedirectArgs($redirect_args = array()) |
|
162 | + { |
|
163 | + if (is_object($redirect_args)) { |
|
164 | + throw new InvalidDataTypeException( |
|
165 | + '$redirect_args', |
|
166 | + $redirect_args, |
|
167 | + 'anything other than an object was expected.' |
|
168 | + ); |
|
169 | + } |
|
170 | + if (empty($redirect_args)) { |
|
171 | + throw new InvalidArgumentException( |
|
172 | + esc_html__('The redirect argument can not be an empty array.', 'event_espresso') |
|
173 | + ); |
|
174 | + } |
|
175 | + $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * @param array $redirect_arg_keys_to_remove |
|
182 | + * @throws InvalidDataTypeException |
|
183 | + * @throws InvalidArgumentException |
|
184 | + */ |
|
185 | + public function removeRedirectArgs($redirect_arg_keys_to_remove = array()) |
|
186 | + { |
|
187 | + if (is_object($redirect_arg_keys_to_remove)) { |
|
188 | + throw new InvalidDataTypeException( |
|
189 | + '$redirect_arg_keys_to_remove', |
|
190 | + $redirect_arg_keys_to_remove, |
|
191 | + 'anything other than an object was expected.' |
|
192 | + ); |
|
193 | + } |
|
194 | + if (empty($redirect_arg_keys_to_remove)) { |
|
195 | + throw new InvalidArgumentException( |
|
196 | + esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso') |
|
197 | + ); |
|
198 | + } |
|
199 | + foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) { |
|
200 | + unset($this->redirect_args[ $redirect_arg_key ]); |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * @return string |
|
208 | + */ |
|
209 | + public function redirectTo() |
|
210 | + { |
|
211 | + return $this->redirect_to; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * @param string $redirect_to |
|
218 | + * @throws InvalidDataTypeException |
|
219 | + */ |
|
220 | + public function setRedirectTo($redirect_to) |
|
221 | + { |
|
222 | + if ( |
|
223 | + ! in_array( |
|
224 | + $redirect_to, |
|
225 | + array( |
|
226 | + SequentialStepForm::REDIRECT_TO_NEXT_STEP, |
|
227 | + SequentialStepForm::REDIRECT_TO_CURRENT_STEP, |
|
228 | + SequentialStepForm::REDIRECT_TO_PREV_STEP, |
|
229 | + SequentialStepForm::REDIRECT_TO_OTHER, |
|
230 | + ), |
|
231 | + true |
|
232 | + ) |
|
233 | + ) { |
|
234 | + throw new InvalidDataTypeException( |
|
235 | + 'setRedirectTo()', |
|
236 | + $redirect_to, |
|
237 | + 'one of the SequentialStepForm class constants was expected.' |
|
238 | + ); |
|
239 | + } |
|
240 | + $this->redirect_to = $redirect_to; |
|
241 | + } |
|
242 | 242 | } |
243 | 243 | // End of file SequentialStepForm.php |
244 | 244 | // Location: /SequentialStepForm.php |
@@ -9,153 +9,153 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_Model_Parser |
11 | 11 | { |
12 | - const table_alias_model_relation_chain_separator = '__'; |
|
13 | - const table_alias_model_relation_chain_prefix_end = '___'; |
|
14 | - /** |
|
15 | - * Adds a period onto the front and end of the string. This often helps in searching. |
|
16 | - * For example, if we want to find the model name "Event", it can be tricky when the following are possible |
|
17 | - * "","Event.EVT_ID","Event","Event_Venue.Venue.VNU_ID",etc. It's easier to look for ".Event." in |
|
18 | - * "..",".Event.EVT_ID.", ".Event.", and ".Event_Venue.Venue.VNU_ID", especially when the last example should NOT |
|
19 | - * be found because the "Event" model isn't mentioned- it's just a string that has a model name that coincidentally |
|
20 | - * has it as a substring |
|
21 | - * @param string $string_to_pad |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public static function pad_with_periods($string_to_pad) |
|
25 | - { |
|
26 | - return "." . $string_to_pad . "."; |
|
27 | - } |
|
28 | - /** |
|
29 | - * Basically undoes _pad_with_periods |
|
30 | - * @param string $string_to_trim |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public static function trim_periods($string_to_trim) |
|
34 | - { |
|
35 | - return trim($string_to_trim, '.'); |
|
36 | - } |
|
12 | + const table_alias_model_relation_chain_separator = '__'; |
|
13 | + const table_alias_model_relation_chain_prefix_end = '___'; |
|
14 | + /** |
|
15 | + * Adds a period onto the front and end of the string. This often helps in searching. |
|
16 | + * For example, if we want to find the model name "Event", it can be tricky when the following are possible |
|
17 | + * "","Event.EVT_ID","Event","Event_Venue.Venue.VNU_ID",etc. It's easier to look for ".Event." in |
|
18 | + * "..",".Event.EVT_ID.", ".Event.", and ".Event_Venue.Venue.VNU_ID", especially when the last example should NOT |
|
19 | + * be found because the "Event" model isn't mentioned- it's just a string that has a model name that coincidentally |
|
20 | + * has it as a substring |
|
21 | + * @param string $string_to_pad |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public static function pad_with_periods($string_to_pad) |
|
25 | + { |
|
26 | + return "." . $string_to_pad . "."; |
|
27 | + } |
|
28 | + /** |
|
29 | + * Basically undoes _pad_with_periods |
|
30 | + * @param string $string_to_trim |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public static function trim_periods($string_to_trim) |
|
34 | + { |
|
35 | + return trim($string_to_trim, '.'); |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Gets the calculated table's alias |
|
42 | - * @param string $model_relation_chain or query param |
|
43 | - * @param $this_model_name |
|
44 | - * @return string which can be added onto table aliases to make them unique |
|
45 | - */ |
|
46 | - public static function extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this_model_name) |
|
47 | - { |
|
48 | - // eg $model_relation_chain = 'Venue.Event_Venue.Event.Registration", and $this_model_name = 'Event' |
|
49 | - $model_relation_chain = self::pad_with_periods($model_relation_chain); |
|
50 | - $this_model_name = self::pad_with_periods($this_model_name); |
|
51 | - // eg '.Venue.Event_Venue.Event.Registration." and '.Event.' |
|
52 | - // remove this model name and everything afterwards |
|
53 | - $pos_of_model_name = strpos($model_relation_chain, $this_model_name); |
|
54 | - $model_relation_chain = substr($model_relation_chain, 0, $pos_of_model_name); |
|
55 | - // eg '.Venue.Event_Venue.' |
|
56 | - // trim periods |
|
57 | - $model_relation_chain = self::trim_periods($model_relation_chain); |
|
58 | - // eg 'Venue.Event_Venue' |
|
59 | - // replace periods with double-underscores |
|
60 | - $model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain); |
|
61 | - // eg 'Venue__Event_Venue' |
|
62 | - if ($model_relation_chain != '') { |
|
63 | - $model_relation_chain = $model_relation_chain . self::table_alias_model_relation_chain_prefix_end; |
|
64 | - } |
|
65 | - // eg 'Venue_Event_Venue___' |
|
66 | - return $model_relation_chain; |
|
67 | - } |
|
68 | - /** |
|
69 | - * Gets the table's alias (without prefix or anything) |
|
70 | - * @param string $table_alias_with_model_relation_chain_prefix which CAN have a table alias model relation chain prefix (or not) |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public static function remove_table_alias_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix) |
|
74 | - { |
|
75 | - // does this actually have a table alias model relation chain prefix? |
|
76 | - $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end); |
|
77 | - if ($pos !== false) { |
|
78 | - // yes |
|
79 | - // find that triple underscore and remove it and everything before it |
|
80 | - $table_alias = substr($table_alias_with_model_relation_chain_prefix, $pos + strlen(self::table_alias_model_relation_chain_prefix_end)); |
|
81 | - } else { |
|
82 | - $table_alias = $table_alias_with_model_relation_chain_prefix; |
|
83 | - } |
|
84 | - return $table_alias; |
|
85 | - } |
|
86 | - /** |
|
87 | - * Gets the table alias model relation chain prefix from the table alias already containing it |
|
88 | - * @param string $table_alias_with_model_relation_chain_prefix |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public static function get_prefix_from_table_alias_with_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix) |
|
92 | - { |
|
93 | - // does this actually have a table alias model relation chain prefix? |
|
94 | - $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end); |
|
95 | - if ($pos !== false) { |
|
96 | - // yes |
|
97 | - // find that triple underscore and remove it and everything before it |
|
98 | - $prefix = substr($table_alias_with_model_relation_chain_prefix, 0, $pos + strlen(self::table_alias_model_relation_chain_prefix_end)); |
|
99 | - } else { |
|
100 | - $prefix = ''; |
|
101 | - } |
|
102 | - return $prefix; |
|
103 | - } |
|
40 | + /** |
|
41 | + * Gets the calculated table's alias |
|
42 | + * @param string $model_relation_chain or query param |
|
43 | + * @param $this_model_name |
|
44 | + * @return string which can be added onto table aliases to make them unique |
|
45 | + */ |
|
46 | + public static function extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this_model_name) |
|
47 | + { |
|
48 | + // eg $model_relation_chain = 'Venue.Event_Venue.Event.Registration", and $this_model_name = 'Event' |
|
49 | + $model_relation_chain = self::pad_with_periods($model_relation_chain); |
|
50 | + $this_model_name = self::pad_with_periods($this_model_name); |
|
51 | + // eg '.Venue.Event_Venue.Event.Registration." and '.Event.' |
|
52 | + // remove this model name and everything afterwards |
|
53 | + $pos_of_model_name = strpos($model_relation_chain, $this_model_name); |
|
54 | + $model_relation_chain = substr($model_relation_chain, 0, $pos_of_model_name); |
|
55 | + // eg '.Venue.Event_Venue.' |
|
56 | + // trim periods |
|
57 | + $model_relation_chain = self::trim_periods($model_relation_chain); |
|
58 | + // eg 'Venue.Event_Venue' |
|
59 | + // replace periods with double-underscores |
|
60 | + $model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain); |
|
61 | + // eg 'Venue__Event_Venue' |
|
62 | + if ($model_relation_chain != '') { |
|
63 | + $model_relation_chain = $model_relation_chain . self::table_alias_model_relation_chain_prefix_end; |
|
64 | + } |
|
65 | + // eg 'Venue_Event_Venue___' |
|
66 | + return $model_relation_chain; |
|
67 | + } |
|
68 | + /** |
|
69 | + * Gets the table's alias (without prefix or anything) |
|
70 | + * @param string $table_alias_with_model_relation_chain_prefix which CAN have a table alias model relation chain prefix (or not) |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public static function remove_table_alias_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix) |
|
74 | + { |
|
75 | + // does this actually have a table alias model relation chain prefix? |
|
76 | + $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end); |
|
77 | + if ($pos !== false) { |
|
78 | + // yes |
|
79 | + // find that triple underscore and remove it and everything before it |
|
80 | + $table_alias = substr($table_alias_with_model_relation_chain_prefix, $pos + strlen(self::table_alias_model_relation_chain_prefix_end)); |
|
81 | + } else { |
|
82 | + $table_alias = $table_alias_with_model_relation_chain_prefix; |
|
83 | + } |
|
84 | + return $table_alias; |
|
85 | + } |
|
86 | + /** |
|
87 | + * Gets the table alias model relation chain prefix from the table alias already containing it |
|
88 | + * @param string $table_alias_with_model_relation_chain_prefix |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public static function get_prefix_from_table_alias_with_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix) |
|
92 | + { |
|
93 | + // does this actually have a table alias model relation chain prefix? |
|
94 | + $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end); |
|
95 | + if ($pos !== false) { |
|
96 | + // yes |
|
97 | + // find that triple underscore and remove it and everything before it |
|
98 | + $prefix = substr($table_alias_with_model_relation_chain_prefix, 0, $pos + strlen(self::table_alias_model_relation_chain_prefix_end)); |
|
99 | + } else { |
|
100 | + $prefix = ''; |
|
101 | + } |
|
102 | + return $prefix; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Gets the table alias model relation chain prefix (ie, what can be prepended onto |
|
107 | - * EE_Model_Field::get_qualified_column() to get the proper column name for that field |
|
108 | - * in a specific query) from teh query param (eg 'Registration.Event.EVT_ID'). |
|
109 | - * |
|
110 | - * @param string $model_name of the model on which the related query param was found to be belong |
|
111 | - * @param string $original_query_param |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public static function extract_table_alias_model_relation_chain_from_query_param($model_name, $original_query_param) |
|
115 | - { |
|
116 | - $relation_chain = self::extract_model_relation_chain($model_name, $original_query_param); |
|
117 | - $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($relation_chain, $model_name); |
|
118 | - return $table_alias_with_model_relation_chain_prefix; |
|
119 | - } |
|
120 | - /** |
|
121 | - * Gets the model relation chain to $model_name from the $original_query_param. |
|
122 | - * Eg, if $model_name were 'Payment', and $original_query_param were 'Registration.Transaction.Payment.PAY_ID', |
|
123 | - * this would return 'Registration.Transaction.Payment'. Also if the query param were 'Registration.Transaction.Payment' |
|
124 | - * and $model_name were 'Payment', it should return 'Registration.Transaction.Payment' |
|
125 | - * @param string $model_name |
|
126 | - * @param string $original_query_param |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public static function extract_model_relation_chain($model_name, $original_query_param) |
|
130 | - { |
|
131 | - // prefix and postfix both with a period, as this facilitates searching |
|
132 | - $model_name = EE_Model_Parser::pad_with_periods($model_name); |
|
133 | - $original_query_param = EE_Model_Parser::pad_with_periods($original_query_param); |
|
134 | - $pos_of_model_string = strpos($original_query_param, $model_name); |
|
135 | - // eg, if we're looking for the model relation chain from Event to Payment, the original query param is probably something like |
|
136 | - // "Registration.Transaction.Payment.PAY_ID", $pos_of_model_string points to the 'P' or Payment. We want the string |
|
137 | - // "Registration.Transaction.Payment" |
|
138 | - $model_relation_chain = substr($original_query_param, 0, $pos_of_model_string + strlen($model_name)); |
|
139 | - return EE_Model_Parser::trim_periods($model_relation_chain); |
|
140 | - } |
|
105 | + /** |
|
106 | + * Gets the table alias model relation chain prefix (ie, what can be prepended onto |
|
107 | + * EE_Model_Field::get_qualified_column() to get the proper column name for that field |
|
108 | + * in a specific query) from teh query param (eg 'Registration.Event.EVT_ID'). |
|
109 | + * |
|
110 | + * @param string $model_name of the model on which the related query param was found to be belong |
|
111 | + * @param string $original_query_param |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public static function extract_table_alias_model_relation_chain_from_query_param($model_name, $original_query_param) |
|
115 | + { |
|
116 | + $relation_chain = self::extract_model_relation_chain($model_name, $original_query_param); |
|
117 | + $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($relation_chain, $model_name); |
|
118 | + return $table_alias_with_model_relation_chain_prefix; |
|
119 | + } |
|
120 | + /** |
|
121 | + * Gets the model relation chain to $model_name from the $original_query_param. |
|
122 | + * Eg, if $model_name were 'Payment', and $original_query_param were 'Registration.Transaction.Payment.PAY_ID', |
|
123 | + * this would return 'Registration.Transaction.Payment'. Also if the query param were 'Registration.Transaction.Payment' |
|
124 | + * and $model_name were 'Payment', it should return 'Registration.Transaction.Payment' |
|
125 | + * @param string $model_name |
|
126 | + * @param string $original_query_param |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public static function extract_model_relation_chain($model_name, $original_query_param) |
|
130 | + { |
|
131 | + // prefix and postfix both with a period, as this facilitates searching |
|
132 | + $model_name = EE_Model_Parser::pad_with_periods($model_name); |
|
133 | + $original_query_param = EE_Model_Parser::pad_with_periods($original_query_param); |
|
134 | + $pos_of_model_string = strpos($original_query_param, $model_name); |
|
135 | + // eg, if we're looking for the model relation chain from Event to Payment, the original query param is probably something like |
|
136 | + // "Registration.Transaction.Payment.PAY_ID", $pos_of_model_string points to the 'P' or Payment. We want the string |
|
137 | + // "Registration.Transaction.Payment" |
|
138 | + $model_relation_chain = substr($original_query_param, 0, $pos_of_model_string + strlen($model_name)); |
|
139 | + return EE_Model_Parser::trim_periods($model_relation_chain); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Replaces the specified model in teh model relation chain with teh join model. |
|
144 | - * Eg EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain( |
|
145 | - * "Ticket", "Datetime_Ticket", "Datetime.Ticket" ) will return |
|
146 | - * "Datetime.Datetime_Ticket" which can be used to find the table alias model relation chain prefix |
|
147 | - * using EE_Model_Parser::extract_table_alias_model_relation_chain_prefix |
|
148 | - * @param string $model_name |
|
149 | - * @param string $join_model_name |
|
150 | - * @param string $model_relation_chain |
|
151 | - * @return string |
|
152 | - */ |
|
153 | - public static function replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_name, $model_relation_chain) |
|
154 | - { |
|
155 | - $model_name = EE_Model_Parser::pad_with_periods($model_name); |
|
156 | - $join_model_name = EE_Model_Parser::pad_with_periods($join_model_name); |
|
157 | - $model_relation_chain = EE_Model_Parser::pad_with_periods($model_relation_chain); |
|
158 | - $replaced_with_periods = str_replace($model_name, $join_model_name, $model_relation_chain); |
|
159 | - return EE_Model_Parser::trim_periods($replaced_with_periods); |
|
160 | - } |
|
142 | + /** |
|
143 | + * Replaces the specified model in teh model relation chain with teh join model. |
|
144 | + * Eg EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain( |
|
145 | + * "Ticket", "Datetime_Ticket", "Datetime.Ticket" ) will return |
|
146 | + * "Datetime.Datetime_Ticket" which can be used to find the table alias model relation chain prefix |
|
147 | + * using EE_Model_Parser::extract_table_alias_model_relation_chain_prefix |
|
148 | + * @param string $model_name |
|
149 | + * @param string $join_model_name |
|
150 | + * @param string $model_relation_chain |
|
151 | + * @return string |
|
152 | + */ |
|
153 | + public static function replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_name, $model_relation_chain) |
|
154 | + { |
|
155 | + $model_name = EE_Model_Parser::pad_with_periods($model_name); |
|
156 | + $join_model_name = EE_Model_Parser::pad_with_periods($join_model_name); |
|
157 | + $model_relation_chain = EE_Model_Parser::pad_with_periods($model_relation_chain); |
|
158 | + $replaced_with_periods = str_replace($model_name, $join_model_name, $model_relation_chain); |
|
159 | + return EE_Model_Parser::trim_periods($replaced_with_periods); |
|
160 | + } |
|
161 | 161 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public static function pad_with_periods($string_to_pad) |
25 | 25 | { |
26 | - return "." . $string_to_pad . "."; |
|
26 | + return ".".$string_to_pad."."; |
|
27 | 27 | } |
28 | 28 | /** |
29 | 29 | * Basically undoes _pad_with_periods |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain); |
61 | 61 | // eg 'Venue__Event_Venue' |
62 | 62 | if ($model_relation_chain != '') { |
63 | - $model_relation_chain = $model_relation_chain . self::table_alias_model_relation_chain_prefix_end; |
|
63 | + $model_relation_chain = $model_relation_chain.self::table_alias_model_relation_chain_prefix_end; |
|
64 | 64 | } |
65 | 65 | // eg 'Venue_Event_Venue___' |
66 | 66 | return $model_relation_chain; |
@@ -8,118 +8,118 @@ |
||
8 | 8 | */ |
9 | 9 | class EE_Secondary_Table extends EE_Table_Base |
10 | 10 | { |
11 | - protected $_extra_join_conditions; |
|
11 | + protected $_extra_join_conditions; |
|
12 | 12 | |
13 | - /** |
|
14 | - * |
|
15 | - * @global type $wpdb |
|
16 | - * @param string $table_name with or without wpdb prefix |
|
17 | - * @param string $pk_column name of primary key column on THIS table |
|
18 | - * @param string $fk_column the name of the COLUMN that is a foreign key to the primary table's primary key |
|
19 | - * @param string $extra_join_conditions string for additional SQL to add onto the join statement's ON condition |
|
20 | - * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install, |
|
21 | - * or whether each site on a multisite install has a copy of this table |
|
22 | - */ |
|
23 | - public function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false) |
|
24 | - { |
|
25 | - $this->_fk_on_table = $fk_column; |
|
26 | - $this->_extra_join_conditions = $extra_join_conditions; |
|
27 | - parent::__construct($table_name, $pk_column, $global); |
|
28 | - } |
|
29 | - public function get_fk_on_table() |
|
30 | - { |
|
31 | - return $this->_fk_on_table; |
|
32 | - } |
|
33 | - public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table) |
|
34 | - { |
|
35 | - $this->_table_to_join_with = $table; |
|
36 | - } |
|
37 | - /** |
|
38 | - * |
|
39 | - * @return string of sql like "Event.post_type = 'event'", which gets added to |
|
40 | - * the end of the join statement with the primary table |
|
41 | - */ |
|
42 | - public function get_extra_join_conditions() |
|
43 | - { |
|
44 | - return $this->_extra_join_conditions; |
|
45 | - } |
|
46 | - /** |
|
47 | - * |
|
48 | - * @return EE_Primary_Table |
|
49 | - */ |
|
50 | - public function get_table_to_join_with() |
|
51 | - { |
|
52 | - return $this->_table_to_join_with; |
|
53 | - } |
|
54 | - /** |
|
55 | - * creates join statement FROM primary table |
|
56 | - * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk |
|
57 | - * |
|
58 | - * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery) |
|
59 | - * @return string of SQL |
|
60 | - */ |
|
61 | - public function get_join_sql($primary_table_alias_with_model_chain_prefix) |
|
62 | - { |
|
13 | + /** |
|
14 | + * |
|
15 | + * @global type $wpdb |
|
16 | + * @param string $table_name with or without wpdb prefix |
|
17 | + * @param string $pk_column name of primary key column on THIS table |
|
18 | + * @param string $fk_column the name of the COLUMN that is a foreign key to the primary table's primary key |
|
19 | + * @param string $extra_join_conditions string for additional SQL to add onto the join statement's ON condition |
|
20 | + * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install, |
|
21 | + * or whether each site on a multisite install has a copy of this table |
|
22 | + */ |
|
23 | + public function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false) |
|
24 | + { |
|
25 | + $this->_fk_on_table = $fk_column; |
|
26 | + $this->_extra_join_conditions = $extra_join_conditions; |
|
27 | + parent::__construct($table_name, $pk_column, $global); |
|
28 | + } |
|
29 | + public function get_fk_on_table() |
|
30 | + { |
|
31 | + return $this->_fk_on_table; |
|
32 | + } |
|
33 | + public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table) |
|
34 | + { |
|
35 | + $this->_table_to_join_with = $table; |
|
36 | + } |
|
37 | + /** |
|
38 | + * |
|
39 | + * @return string of sql like "Event.post_type = 'event'", which gets added to |
|
40 | + * the end of the join statement with the primary table |
|
41 | + */ |
|
42 | + public function get_extra_join_conditions() |
|
43 | + { |
|
44 | + return $this->_extra_join_conditions; |
|
45 | + } |
|
46 | + /** |
|
47 | + * |
|
48 | + * @return EE_Primary_Table |
|
49 | + */ |
|
50 | + public function get_table_to_join_with() |
|
51 | + { |
|
52 | + return $this->_table_to_join_with; |
|
53 | + } |
|
54 | + /** |
|
55 | + * creates join statement FROM primary table |
|
56 | + * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk |
|
57 | + * |
|
58 | + * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery) |
|
59 | + * @return string of SQL |
|
60 | + */ |
|
61 | + public function get_join_sql($primary_table_alias_with_model_chain_prefix) |
|
62 | + { |
|
63 | 63 | |
64 | - $table_name = $this->get_table_name(); |
|
65 | - $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias(); |
|
66 | - $other_table_pk = $this->get_table_to_join_with()->get_pk_column(); |
|
67 | - $fk = $this->get_fk_on_table(); |
|
68 | - $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk "; |
|
69 | - if ($this->get_extra_join_conditions()) { |
|
70 | - $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
71 | - } |
|
72 | - return $join_sql; |
|
73 | - } |
|
64 | + $table_name = $this->get_table_name(); |
|
65 | + $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias(); |
|
66 | + $other_table_pk = $this->get_table_to_join_with()->get_pk_column(); |
|
67 | + $fk = $this->get_fk_on_table(); |
|
68 | + $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk "; |
|
69 | + if ($this->get_extra_join_conditions()) { |
|
70 | + $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
71 | + } |
|
72 | + return $join_sql; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * Produces join SQL like get_join_sql, except instead of joining the primary table to the |
|
78 | - * secondary table, does the inverse: joins the secondary table to the primary one. (Eg, isntead of |
|
79 | - * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns |
|
80 | - * " LEFT JOIN primary_table AS Primary ON ...". |
|
81 | - * This is useful if the secondary table is already included in the SQL, but the primary table is not yet. |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix) |
|
85 | - { |
|
86 | - $primary_table_name = $this->get_table_to_join_with()->get_table_name(); |
|
87 | - $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias(); |
|
88 | - $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column(); |
|
89 | - $fk = $this->get_fk_on_table(); |
|
90 | - $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk "; |
|
91 | - if ($this->get_extra_join_conditions()) { |
|
92 | - $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
93 | - } |
|
94 | - return $join_sql; |
|
95 | - } |
|
76 | + /** |
|
77 | + * Produces join SQL like get_join_sql, except instead of joining the primary table to the |
|
78 | + * secondary table, does the inverse: joins the secondary table to the primary one. (Eg, isntead of |
|
79 | + * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns |
|
80 | + * " LEFT JOIN primary_table AS Primary ON ...". |
|
81 | + * This is useful if the secondary table is already included in the SQL, but the primary table is not yet. |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix) |
|
85 | + { |
|
86 | + $primary_table_name = $this->get_table_to_join_with()->get_table_name(); |
|
87 | + $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias(); |
|
88 | + $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column(); |
|
89 | + $fk = $this->get_fk_on_table(); |
|
90 | + $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk "; |
|
91 | + if ($this->get_extra_join_conditions()) { |
|
92 | + $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
93 | + } |
|
94 | + return $join_sql; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * This prepares the join on the other table using a select with a internal limit. |
|
99 | - * @param mixed (array|string) $limit limit |
|
100 | - * @return string SQL to return |
|
101 | - */ |
|
102 | - public function get_select_join_limit_join($limit) |
|
103 | - { |
|
104 | - // first get the select |
|
105 | - $select = $this->get_select_join_limit($limit); |
|
106 | - $join_sql = $this->get_join_sql($select); |
|
107 | - return $join_sql; |
|
108 | - } |
|
97 | + /** |
|
98 | + * This prepares the join on the other table using a select with a internal limit. |
|
99 | + * @param mixed (array|string) $limit limit |
|
100 | + * @return string SQL to return |
|
101 | + */ |
|
102 | + public function get_select_join_limit_join($limit) |
|
103 | + { |
|
104 | + // first get the select |
|
105 | + $select = $this->get_select_join_limit($limit); |
|
106 | + $join_sql = $this->get_join_sql($select); |
|
107 | + return $join_sql; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | 111 | |
112 | - public function get_fully_qualified_fk_column() |
|
113 | - { |
|
114 | - $table_alias = $this->get_table_alias(); |
|
115 | - $fk = $this->get_fk_on_table(); |
|
116 | - return $table_alias . '.' . $fk; |
|
117 | - } |
|
112 | + public function get_fully_qualified_fk_column() |
|
113 | + { |
|
114 | + $table_alias = $this->get_table_alias(); |
|
115 | + $fk = $this->get_fk_on_table(); |
|
116 | + return $table_alias . '.' . $fk; |
|
117 | + } |
|
118 | 118 | |
119 | - public function get_fully_qualified_pk_on_fk_table() |
|
120 | - { |
|
121 | - $table_alias = $this->get_table_to_join_with()->get_table_alias(); |
|
122 | - $pk = $this->get_table_to_join_with()->get_pk_column(); |
|
123 | - return $table_alias . '.' . $pk; |
|
124 | - } |
|
119 | + public function get_fully_qualified_pk_on_fk_table() |
|
120 | + { |
|
121 | + $table_alias = $this->get_table_to_join_with()->get_table_alias(); |
|
122 | + $pk = $this->get_table_to_join_with()->get_pk_column(); |
|
123 | + return $table_alias . '.' . $pk; |
|
124 | + } |
|
125 | 125 | } |
@@ -62,12 +62,12 @@ discard block |
||
62 | 62 | { |
63 | 63 | |
64 | 64 | $table_name = $this->get_table_name(); |
65 | - $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias(); |
|
65 | + $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix).$this->get_table_alias(); |
|
66 | 66 | $other_table_pk = $this->get_table_to_join_with()->get_pk_column(); |
67 | 67 | $fk = $this->get_fk_on_table(); |
68 | 68 | $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk "; |
69 | 69 | if ($this->get_extra_join_conditions()) { |
70 | - $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
70 | + $join_sql .= "AND ".$this->get_extra_join_conditions(); |
|
71 | 71 | } |
72 | 72 | return $join_sql; |
73 | 73 | } |
@@ -84,12 +84,12 @@ discard block |
||
84 | 84 | public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix) |
85 | 85 | { |
86 | 86 | $primary_table_name = $this->get_table_to_join_with()->get_table_name(); |
87 | - $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias(); |
|
88 | - $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column(); |
|
87 | + $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix).$this->get_table_to_join_with()->get_table_alias(); |
|
88 | + $primary_table_pk = $this->get_table_to_join_with()->get_pk_column(); // $this->get_pk_column(); |
|
89 | 89 | $fk = $this->get_fk_on_table(); |
90 | 90 | $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk "; |
91 | 91 | if ($this->get_extra_join_conditions()) { |
92 | - $join_sql .= "AND " . $this->get_extra_join_conditions(); |
|
92 | + $join_sql .= "AND ".$this->get_extra_join_conditions(); |
|
93 | 93 | } |
94 | 94 | return $join_sql; |
95 | 95 | } |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | { |
114 | 114 | $table_alias = $this->get_table_alias(); |
115 | 115 | $fk = $this->get_fk_on_table(); |
116 | - return $table_alias . '.' . $fk; |
|
116 | + return $table_alias.'.'.$fk; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | public function get_fully_qualified_pk_on_fk_table() |
120 | 120 | { |
121 | 121 | $table_alias = $this->get_table_to_join_with()->get_table_alias(); |
122 | 122 | $pk = $this->get_table_to_join_with()->get_pk_column(); |
123 | - return $table_alias . '.' . $pk; |
|
123 | + return $table_alias.'.'.$pk; |
|
124 | 124 | } |
125 | 125 | } |
@@ -6,45 +6,45 @@ |
||
6 | 6 | */ |
7 | 7 | class EE_Index |
8 | 8 | { |
9 | - protected $_name; |
|
10 | - protected $_field_names; |
|
11 | - protected $_model_name; |
|
12 | - public function __construct($fields) |
|
13 | - { |
|
14 | - $this->_field_names = $fields; |
|
15 | - } |
|
16 | - public function _construct_finalize($name, $model_name) |
|
17 | - { |
|
18 | - $this->_name = $name; |
|
19 | - $this->_model_name = $model_name; |
|
20 | - } |
|
21 | - public function field_names() |
|
22 | - { |
|
23 | - return $this->_field_names; |
|
24 | - } |
|
25 | - /** |
|
26 | - * Internally used by get_this_model() and get_other_model() |
|
27 | - * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
28 | - * @return EEM_Base |
|
29 | - */ |
|
30 | - protected function _get_model($model_name) |
|
31 | - { |
|
32 | - $modelInstance = call_user_func("EEM_" . $model_name . "::instance"); |
|
33 | - return $modelInstance; |
|
34 | - } |
|
35 | - /** |
|
36 | - * Gets all the fields for this index |
|
37 | - * @return EE_Model_Field_Base[] |
|
38 | - */ |
|
39 | - public function fields() |
|
40 | - { |
|
41 | - $fields = array(); |
|
42 | - $model = $this->_get_model($this->_model_name); |
|
43 | - foreach ($model->field_settings() as $field_name => $field_obj) { |
|
44 | - if (in_array($field_name, $this->field_names())) { |
|
45 | - $fields[ $field_name ] = $field_obj; |
|
46 | - } |
|
47 | - } |
|
48 | - return $fields; |
|
49 | - } |
|
9 | + protected $_name; |
|
10 | + protected $_field_names; |
|
11 | + protected $_model_name; |
|
12 | + public function __construct($fields) |
|
13 | + { |
|
14 | + $this->_field_names = $fields; |
|
15 | + } |
|
16 | + public function _construct_finalize($name, $model_name) |
|
17 | + { |
|
18 | + $this->_name = $name; |
|
19 | + $this->_model_name = $model_name; |
|
20 | + } |
|
21 | + public function field_names() |
|
22 | + { |
|
23 | + return $this->_field_names; |
|
24 | + } |
|
25 | + /** |
|
26 | + * Internally used by get_this_model() and get_other_model() |
|
27 | + * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
28 | + * @return EEM_Base |
|
29 | + */ |
|
30 | + protected function _get_model($model_name) |
|
31 | + { |
|
32 | + $modelInstance = call_user_func("EEM_" . $model_name . "::instance"); |
|
33 | + return $modelInstance; |
|
34 | + } |
|
35 | + /** |
|
36 | + * Gets all the fields for this index |
|
37 | + * @return EE_Model_Field_Base[] |
|
38 | + */ |
|
39 | + public function fields() |
|
40 | + { |
|
41 | + $fields = array(); |
|
42 | + $model = $this->_get_model($this->_model_name); |
|
43 | + foreach ($model->field_settings() as $field_name => $field_obj) { |
|
44 | + if (in_array($field_name, $this->field_names())) { |
|
45 | + $fields[ $field_name ] = $field_obj; |
|
46 | + } |
|
47 | + } |
|
48 | + return $fields; |
|
49 | + } |
|
50 | 50 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | protected function _get_model($model_name) |
31 | 31 | { |
32 | - $modelInstance = call_user_func("EEM_" . $model_name . "::instance"); |
|
32 | + $modelInstance = call_user_func("EEM_".$model_name."::instance"); |
|
33 | 33 | return $modelInstance; |
34 | 34 | } |
35 | 35 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $model = $this->_get_model($this->_model_name); |
43 | 43 | foreach ($model->field_settings() as $field_name => $field_obj) { |
44 | 44 | if (in_array($field_name, $this->field_names())) { |
45 | - $fields[ $field_name ] = $field_obj; |
|
45 | + $fields[$field_name] = $field_obj; |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | return $fields; |
@@ -25,6 +25,6 @@ |
||
25 | 25 | */ |
26 | 26 | public function get_table_sql() |
27 | 27 | { |
28 | - return " " . $this->get_table_name() . " AS " . $this->get_table_alias() . " "; |
|
28 | + return " ".$this->get_table_name()." AS ".$this->get_table_alias()." "; |
|
29 | 29 | } |
30 | 30 | } |
@@ -6,24 +6,24 @@ |
||
6 | 6 | */ |
7 | 7 | class EE_Primary_Table extends EE_Table_Base |
8 | 8 | { |
9 | - /** |
|
10 | - * |
|
11 | - * @global type $wpdb |
|
12 | - * @param string $table_name with or without wpdb prefix |
|
13 | - * @param string $pk_column name of primary key column |
|
14 | - * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install, |
|
15 | - * or whether each site on a multisite install has a copy of this table |
|
16 | - */ |
|
17 | - public function __construct($table_name, $pk_column = null, $global = false) |
|
18 | - { |
|
19 | - parent::__construct($table_name, $pk_column, $global); |
|
20 | - } |
|
21 | - /** |
|
22 | - * Gets SQL for this table and assigning it an alias. Eg " wp_esp_attendee AS Attendee " |
|
23 | - * @return string |
|
24 | - */ |
|
25 | - public function get_table_sql() |
|
26 | - { |
|
27 | - return " " . $this->get_table_name() . " AS " . $this->get_table_alias() . " "; |
|
28 | - } |
|
9 | + /** |
|
10 | + * |
|
11 | + * @global type $wpdb |
|
12 | + * @param string $table_name with or without wpdb prefix |
|
13 | + * @param string $pk_column name of primary key column |
|
14 | + * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install, |
|
15 | + * or whether each site on a multisite install has a copy of this table |
|
16 | + */ |
|
17 | + public function __construct($table_name, $pk_column = null, $global = false) |
|
18 | + { |
|
19 | + parent::__construct($table_name, $pk_column, $global); |
|
20 | + } |
|
21 | + /** |
|
22 | + * Gets SQL for this table and assigning it an alias. Eg " wp_esp_attendee AS Attendee " |
|
23 | + * @return string |
|
24 | + */ |
|
25 | + public function get_table_sql() |
|
26 | + { |
|
27 | + return " " . $this->get_table_name() . " AS " . $this->get_table_alias() . " "; |
|
28 | + } |
|
29 | 29 | } |
@@ -33,384 +33,384 @@ |
||
33 | 33 | */ |
34 | 34 | class EEH_Inflector |
35 | 35 | { |
36 | - // ------ CLASS METHODS ------ // |
|
37 | - // ---- Public methods ---- // |
|
38 | - // {{{ pluralize() |
|
39 | - |
|
40 | - /** |
|
41 | - * Just calls self::pluralize and strtolower on $word and returns it |
|
42 | - * @param string $word |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public static function pluralize_and_lower($word) |
|
46 | - { |
|
47 | - return strtolower(self::pluralize($word)); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @param string $word |
|
54 | - * @return mixed |
|
55 | - */ |
|
56 | - public static function singularize_and_upper($word) |
|
57 | - { |
|
58 | - return str_replace(' ', '_', self::humanize(self::singularize($word), 'all')); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Pluralizes English nouns. |
|
65 | - * |
|
66 | - * @access public |
|
67 | - * @static |
|
68 | - * @param string $word English noun to pluralize |
|
69 | - * @return string Plural noun |
|
70 | - */ |
|
71 | - public static function pluralize($word) |
|
72 | - { |
|
73 | - $plural = array( |
|
74 | - '/(quiz)$/i' => '\1zes', |
|
75 | - '/^(ox)$/i' => '\1en', |
|
76 | - '/([m|l])ouse$/i' => '\1ice', |
|
77 | - '/(matr|vert|ind)ix|ex$/i' => '\1ices', |
|
78 | - '/(x|ch|ss|sh)$/i' => '\1es', |
|
79 | - '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
80 | - '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
81 | - '/(hive)$/i' => '\1s', |
|
82 | - '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
83 | - '/sis$/i' => 'ses', |
|
84 | - '/([ti])um$/i' => '\1a', |
|
85 | - '/(buffal|tomat)o$/i' => '\1oes', |
|
86 | - '/(bu)s$/i' => '\1ses', |
|
87 | - '/(alias|status)/i' => '\1es', |
|
88 | - '/(octop|vir)us$/i' => '\1i', |
|
89 | - '/(ax|test)is$/i' => '\1es', |
|
90 | - '/s$/i' => 's', |
|
91 | - '/$/' => 's'); |
|
92 | - |
|
93 | - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
94 | - |
|
95 | - $irregular = array( |
|
96 | - 'person' => 'people', |
|
97 | - 'man' => 'men', |
|
98 | - 'child' => 'children', |
|
99 | - 'sex' => 'sexes', |
|
100 | - 'move' => 'moves'); |
|
101 | - |
|
102 | - $lowercased_word = strtolower($word); |
|
103 | - |
|
104 | - foreach ($uncountable as $_uncountable) { |
|
105 | - if ( |
|
106 | - substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
107 | - ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ]) |
|
108 | - ) { |
|
109 | - return $word; |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - foreach ($irregular as $_plural => $_singular) { |
|
114 | - if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) { |
|
115 | - return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - foreach ($plural as $rule => $replacement) { |
|
120 | - if (preg_match($rule, $word)) { |
|
121 | - return preg_replace($rule, $replacement, $word); |
|
122 | - } |
|
123 | - } |
|
124 | - return false; |
|
125 | - } |
|
126 | - |
|
127 | - // }}} |
|
128 | - // {{{ singularize() |
|
129 | - |
|
130 | - /** |
|
131 | - * Singularizes English nouns. |
|
132 | - * |
|
133 | - * @access public |
|
134 | - * @static |
|
135 | - * @param string $word English noun to singularize |
|
136 | - * @return string Singular noun. |
|
137 | - */ |
|
138 | - public static function singularize($word) |
|
139 | - { |
|
140 | - $singular = array( |
|
141 | - '/(quiz)zes$/i' => '\1', |
|
142 | - '/(matr)ices$/i' => '\1ix', |
|
143 | - '/(vert|ind)ices$/i' => '\1ex', |
|
144 | - '/^(ox)en/i' => '\1', |
|
145 | - '/(alias|status)es$/i' => '\1', |
|
146 | - '/([octop|vir])i$/i' => '\1us', |
|
147 | - '/(cris|ax|test)es$/i' => '\1is', |
|
148 | - '/(shoe)s$/i' => '\1', |
|
149 | - '/(o)es$/i' => '\1', |
|
150 | - '/(bus)es$/i' => '\1', |
|
151 | - '/([m|l])ice$/i' => '\1ouse', |
|
152 | - '/(x|ch|ss|sh)es$/i' => '\1', |
|
153 | - '/(m)ovies$/i' => '\1ovie', |
|
154 | - '/(s)eries$/i' => '\1eries', |
|
155 | - '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
156 | - '/([lr])ves$/i' => '\1f', |
|
157 | - '/(tive)s$/i' => '\1', |
|
158 | - '/(hive)s$/i' => '\1', |
|
159 | - '/([^f])ves$/i' => '\1fe', |
|
160 | - '/(^analy)ses$/i' => '\1sis', |
|
161 | - '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
162 | - '/([ti])a$/i' => '\1um', |
|
163 | - '/(n)ews$/i' => '\1ews', |
|
164 | - '/s$/i' => '', |
|
165 | - ); |
|
166 | - |
|
167 | - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
168 | - |
|
169 | - $irregular = array( |
|
170 | - 'person' => 'people', |
|
171 | - 'man' => 'men', |
|
172 | - 'child' => 'children', |
|
173 | - 'sex' => 'sexes', |
|
174 | - 'move' => 'moves'); |
|
175 | - |
|
176 | - $lowercased_word = strtolower($word); |
|
177 | - foreach ($uncountable as $_uncountable) { |
|
178 | - if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) { |
|
179 | - return $word; |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - foreach ($irregular as $_plural => $_singular) { |
|
184 | - if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) { |
|
185 | - return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - foreach ($singular as $rule => $replacement) { |
|
190 | - if (preg_match($rule, $word)) { |
|
191 | - return preg_replace($rule, $replacement, $word); |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - return $word; |
|
196 | - } |
|
197 | - |
|
198 | - // }}} |
|
199 | - // {{{ titleize() |
|
200 | - |
|
201 | - /** |
|
202 | - * Converts an underscored or CamelCase word into a English |
|
203 | - * sentence. |
|
204 | - * |
|
205 | - * The titleize static function converts text like "WelcomePage", |
|
206 | - * "welcome_page" or "welcome page" to this "Welcome |
|
207 | - * Page". |
|
208 | - * If second parameter is set to 'first' it will only |
|
209 | - * capitalize the first character of the title. |
|
210 | - * |
|
211 | - * @access public |
|
212 | - * @static |
|
213 | - * @param string $word Word to format as tile |
|
214 | - * @param string $uppercase If set to 'first' it will only uppercase the |
|
215 | - * first character. Otherwise it will uppercase all |
|
216 | - * the words in the title. |
|
217 | - * @return string Text formatted as title |
|
218 | - */ |
|
219 | - public static function titleize($word, $uppercase = '') |
|
220 | - { |
|
221 | - $uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords'; |
|
222 | - return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
|
223 | - } |
|
224 | - |
|
225 | - // }}} |
|
226 | - // {{{ camelize() |
|
227 | - |
|
228 | - /** |
|
229 | - * Returns given word as CamelCased |
|
230 | - * |
|
231 | - * Converts a word like "send_email" to "SendEmail". It |
|
232 | - * will remove non alphanumeric character from the word, so |
|
233 | - * "who's online" will be converted to "WhoSOnline" |
|
234 | - * |
|
235 | - * @access public |
|
236 | - * @static |
|
237 | - * @see variablize |
|
238 | - * @param string $word Word to convert to camel case |
|
239 | - * @return string UpperCamelCasedWord |
|
240 | - */ |
|
241 | - public static function camelize($word) |
|
242 | - { |
|
243 | - return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention |
|
250 | - * with the new PSR-based naming conventions |
|
251 | - * @param $word |
|
252 | - * @return string |
|
253 | - */ |
|
254 | - public static function camelize_all_but_first($word) |
|
255 | - { |
|
256 | - return lcfirst(EEH_Inflector::camelize($word)); |
|
257 | - } |
|
258 | - // }}} |
|
259 | - // {{{ underscore() |
|
260 | - |
|
261 | - /** |
|
262 | - * Converts a word "into_it_s_underscored_version" |
|
263 | - * |
|
264 | - * Convert any "CamelCased" or "ordinary Word" into an |
|
265 | - * "underscored_word". |
|
266 | - * |
|
267 | - * This can be really useful for creating friendly URLs. |
|
268 | - * |
|
269 | - * @access public |
|
270 | - * @static |
|
271 | - * @param string $word Word to underscore |
|
272 | - * @return string Underscored word |
|
273 | - */ |
|
274 | - public static function underscore($word) |
|
275 | - { |
|
276 | - return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
|
277 | - } |
|
278 | - |
|
279 | - // }}} |
|
280 | - // {{{ humanize() |
|
281 | - |
|
282 | - /** |
|
283 | - * Returns a human-readable string from $word |
|
284 | - * |
|
285 | - * Returns a human-readable string from $word, by replacing |
|
286 | - * underscores with a space, and by upper-casing the initial |
|
287 | - * character by default. |
|
288 | - * |
|
289 | - * If you need to uppercase all the words you just have to |
|
290 | - * pass 'all' as a second parameter. |
|
291 | - * |
|
292 | - * @access public |
|
293 | - * @static |
|
294 | - * @param string $word String to "humanize" |
|
295 | - * @param string $uppercase If set to 'all' it will uppercase all the words |
|
296 | - * instead of just the first one. |
|
297 | - * @return string Human-readable word |
|
298 | - */ |
|
299 | - public static function humanize($word, $uppercase = '') |
|
300 | - { |
|
301 | - // make special exceptions for acronyms |
|
302 | - $word = str_replace('wp_', 'WP_', $word); |
|
303 | - $uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst'; |
|
304 | - return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
|
305 | - } |
|
306 | - |
|
307 | - // }}} |
|
308 | - // {{{ variablize() |
|
309 | - |
|
310 | - /** |
|
311 | - * Same as camelize but first char is underscored |
|
312 | - * |
|
313 | - * Converts a word like "send_email" to "sendEmail". It |
|
314 | - * will remove non alphanumeric character from the word, so |
|
315 | - * "who's online" will be converted to "whoSOnline" |
|
316 | - * |
|
317 | - * @access public |
|
318 | - * @static |
|
319 | - * @see camelize |
|
320 | - * @param string $word Word to lowerCamelCase |
|
321 | - * @return string Returns a lowerCamelCasedWord |
|
322 | - */ |
|
323 | - public static function variablize($word) |
|
324 | - { |
|
325 | - $word = EEH_Inflector::camelize($word); |
|
326 | - return strtolower($word[0]) . substr($word, 1); |
|
327 | - } |
|
328 | - |
|
329 | - // }}} |
|
330 | - // {{{ tableize() |
|
331 | - |
|
332 | - /** |
|
333 | - * Converts a class name to its table name according to rails |
|
334 | - * naming conventions. |
|
335 | - * |
|
336 | - * Converts "Person" to "people" |
|
337 | - * |
|
338 | - * @access public |
|
339 | - * @static |
|
340 | - * @see classify |
|
341 | - * @param string $class_name Class name for getting related table_name. |
|
342 | - * @return string plural_table_name |
|
343 | - */ |
|
344 | - public static function tableize($class_name) |
|
345 | - { |
|
346 | - return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
|
347 | - } |
|
348 | - |
|
349 | - // }}} |
|
350 | - // {{{ classify() |
|
351 | - |
|
352 | - /** |
|
353 | - * Converts a table name to its class name according to rails |
|
354 | - * naming conventions. |
|
355 | - * |
|
356 | - * Converts "people" to "Person" |
|
357 | - * |
|
358 | - * @access public |
|
359 | - * @static |
|
360 | - * @see tableize |
|
361 | - * @param string $table_name Table name for getting related ClassName. |
|
362 | - * @return string SingularClassName |
|
363 | - */ |
|
364 | - public static function classify($table_name) |
|
365 | - { |
|
366 | - return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
|
367 | - } |
|
368 | - |
|
369 | - // }}} |
|
370 | - // {{{ ordinalize() |
|
371 | - |
|
372 | - /** |
|
373 | - * Converts number to its ordinal English form. |
|
374 | - * |
|
375 | - * This method converts 13 to 13th, 2 to 2nd ... |
|
376 | - * |
|
377 | - * @access public |
|
378 | - * @static |
|
379 | - * @param integer $number Number to get its ordinal value |
|
380 | - * @return string Ordinal representation of given string. |
|
381 | - */ |
|
382 | - public static function ordinalize($number) |
|
383 | - { |
|
384 | - if (in_array(($number % 100), range(11, 13))) { |
|
385 | - return $number . 'th'; |
|
386 | - } else { |
|
387 | - switch (($number % 10)) { |
|
388 | - case 1: |
|
389 | - return $number . 'st'; |
|
390 | - break; |
|
391 | - case 2: |
|
392 | - return $number . 'nd'; |
|
393 | - break; |
|
394 | - case 3: |
|
395 | - return $number . 'rd'; |
|
396 | - default: |
|
397 | - return $number . 'th'; |
|
398 | - break; |
|
399 | - } |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * @param $string |
|
407 | - * @return string |
|
408 | - */ |
|
409 | - public static function add_indefinite_article($string) |
|
410 | - { |
|
411 | - if (strtolower($string) === 'null') { |
|
412 | - return $string; |
|
413 | - } |
|
414 | - return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string; |
|
415 | - } |
|
36 | + // ------ CLASS METHODS ------ // |
|
37 | + // ---- Public methods ---- // |
|
38 | + // {{{ pluralize() |
|
39 | + |
|
40 | + /** |
|
41 | + * Just calls self::pluralize and strtolower on $word and returns it |
|
42 | + * @param string $word |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public static function pluralize_and_lower($word) |
|
46 | + { |
|
47 | + return strtolower(self::pluralize($word)); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @param string $word |
|
54 | + * @return mixed |
|
55 | + */ |
|
56 | + public static function singularize_and_upper($word) |
|
57 | + { |
|
58 | + return str_replace(' ', '_', self::humanize(self::singularize($word), 'all')); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Pluralizes English nouns. |
|
65 | + * |
|
66 | + * @access public |
|
67 | + * @static |
|
68 | + * @param string $word English noun to pluralize |
|
69 | + * @return string Plural noun |
|
70 | + */ |
|
71 | + public static function pluralize($word) |
|
72 | + { |
|
73 | + $plural = array( |
|
74 | + '/(quiz)$/i' => '\1zes', |
|
75 | + '/^(ox)$/i' => '\1en', |
|
76 | + '/([m|l])ouse$/i' => '\1ice', |
|
77 | + '/(matr|vert|ind)ix|ex$/i' => '\1ices', |
|
78 | + '/(x|ch|ss|sh)$/i' => '\1es', |
|
79 | + '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
80 | + '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
81 | + '/(hive)$/i' => '\1s', |
|
82 | + '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
83 | + '/sis$/i' => 'ses', |
|
84 | + '/([ti])um$/i' => '\1a', |
|
85 | + '/(buffal|tomat)o$/i' => '\1oes', |
|
86 | + '/(bu)s$/i' => '\1ses', |
|
87 | + '/(alias|status)/i' => '\1es', |
|
88 | + '/(octop|vir)us$/i' => '\1i', |
|
89 | + '/(ax|test)is$/i' => '\1es', |
|
90 | + '/s$/i' => 's', |
|
91 | + '/$/' => 's'); |
|
92 | + |
|
93 | + $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
94 | + |
|
95 | + $irregular = array( |
|
96 | + 'person' => 'people', |
|
97 | + 'man' => 'men', |
|
98 | + 'child' => 'children', |
|
99 | + 'sex' => 'sexes', |
|
100 | + 'move' => 'moves'); |
|
101 | + |
|
102 | + $lowercased_word = strtolower($word); |
|
103 | + |
|
104 | + foreach ($uncountable as $_uncountable) { |
|
105 | + if ( |
|
106 | + substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
107 | + ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ]) |
|
108 | + ) { |
|
109 | + return $word; |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + foreach ($irregular as $_plural => $_singular) { |
|
114 | + if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) { |
|
115 | + return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + foreach ($plural as $rule => $replacement) { |
|
120 | + if (preg_match($rule, $word)) { |
|
121 | + return preg_replace($rule, $replacement, $word); |
|
122 | + } |
|
123 | + } |
|
124 | + return false; |
|
125 | + } |
|
126 | + |
|
127 | + // }}} |
|
128 | + // {{{ singularize() |
|
129 | + |
|
130 | + /** |
|
131 | + * Singularizes English nouns. |
|
132 | + * |
|
133 | + * @access public |
|
134 | + * @static |
|
135 | + * @param string $word English noun to singularize |
|
136 | + * @return string Singular noun. |
|
137 | + */ |
|
138 | + public static function singularize($word) |
|
139 | + { |
|
140 | + $singular = array( |
|
141 | + '/(quiz)zes$/i' => '\1', |
|
142 | + '/(matr)ices$/i' => '\1ix', |
|
143 | + '/(vert|ind)ices$/i' => '\1ex', |
|
144 | + '/^(ox)en/i' => '\1', |
|
145 | + '/(alias|status)es$/i' => '\1', |
|
146 | + '/([octop|vir])i$/i' => '\1us', |
|
147 | + '/(cris|ax|test)es$/i' => '\1is', |
|
148 | + '/(shoe)s$/i' => '\1', |
|
149 | + '/(o)es$/i' => '\1', |
|
150 | + '/(bus)es$/i' => '\1', |
|
151 | + '/([m|l])ice$/i' => '\1ouse', |
|
152 | + '/(x|ch|ss|sh)es$/i' => '\1', |
|
153 | + '/(m)ovies$/i' => '\1ovie', |
|
154 | + '/(s)eries$/i' => '\1eries', |
|
155 | + '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
156 | + '/([lr])ves$/i' => '\1f', |
|
157 | + '/(tive)s$/i' => '\1', |
|
158 | + '/(hive)s$/i' => '\1', |
|
159 | + '/([^f])ves$/i' => '\1fe', |
|
160 | + '/(^analy)ses$/i' => '\1sis', |
|
161 | + '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
162 | + '/([ti])a$/i' => '\1um', |
|
163 | + '/(n)ews$/i' => '\1ews', |
|
164 | + '/s$/i' => '', |
|
165 | + ); |
|
166 | + |
|
167 | + $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
168 | + |
|
169 | + $irregular = array( |
|
170 | + 'person' => 'people', |
|
171 | + 'man' => 'men', |
|
172 | + 'child' => 'children', |
|
173 | + 'sex' => 'sexes', |
|
174 | + 'move' => 'moves'); |
|
175 | + |
|
176 | + $lowercased_word = strtolower($word); |
|
177 | + foreach ($uncountable as $_uncountable) { |
|
178 | + if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) { |
|
179 | + return $word; |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + foreach ($irregular as $_plural => $_singular) { |
|
184 | + if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) { |
|
185 | + return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + foreach ($singular as $rule => $replacement) { |
|
190 | + if (preg_match($rule, $word)) { |
|
191 | + return preg_replace($rule, $replacement, $word); |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + return $word; |
|
196 | + } |
|
197 | + |
|
198 | + // }}} |
|
199 | + // {{{ titleize() |
|
200 | + |
|
201 | + /** |
|
202 | + * Converts an underscored or CamelCase word into a English |
|
203 | + * sentence. |
|
204 | + * |
|
205 | + * The titleize static function converts text like "WelcomePage", |
|
206 | + * "welcome_page" or "welcome page" to this "Welcome |
|
207 | + * Page". |
|
208 | + * If second parameter is set to 'first' it will only |
|
209 | + * capitalize the first character of the title. |
|
210 | + * |
|
211 | + * @access public |
|
212 | + * @static |
|
213 | + * @param string $word Word to format as tile |
|
214 | + * @param string $uppercase If set to 'first' it will only uppercase the |
|
215 | + * first character. Otherwise it will uppercase all |
|
216 | + * the words in the title. |
|
217 | + * @return string Text formatted as title |
|
218 | + */ |
|
219 | + public static function titleize($word, $uppercase = '') |
|
220 | + { |
|
221 | + $uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords'; |
|
222 | + return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
|
223 | + } |
|
224 | + |
|
225 | + // }}} |
|
226 | + // {{{ camelize() |
|
227 | + |
|
228 | + /** |
|
229 | + * Returns given word as CamelCased |
|
230 | + * |
|
231 | + * Converts a word like "send_email" to "SendEmail". It |
|
232 | + * will remove non alphanumeric character from the word, so |
|
233 | + * "who's online" will be converted to "WhoSOnline" |
|
234 | + * |
|
235 | + * @access public |
|
236 | + * @static |
|
237 | + * @see variablize |
|
238 | + * @param string $word Word to convert to camel case |
|
239 | + * @return string UpperCamelCasedWord |
|
240 | + */ |
|
241 | + public static function camelize($word) |
|
242 | + { |
|
243 | + return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention |
|
250 | + * with the new PSR-based naming conventions |
|
251 | + * @param $word |
|
252 | + * @return string |
|
253 | + */ |
|
254 | + public static function camelize_all_but_first($word) |
|
255 | + { |
|
256 | + return lcfirst(EEH_Inflector::camelize($word)); |
|
257 | + } |
|
258 | + // }}} |
|
259 | + // {{{ underscore() |
|
260 | + |
|
261 | + /** |
|
262 | + * Converts a word "into_it_s_underscored_version" |
|
263 | + * |
|
264 | + * Convert any "CamelCased" or "ordinary Word" into an |
|
265 | + * "underscored_word". |
|
266 | + * |
|
267 | + * This can be really useful for creating friendly URLs. |
|
268 | + * |
|
269 | + * @access public |
|
270 | + * @static |
|
271 | + * @param string $word Word to underscore |
|
272 | + * @return string Underscored word |
|
273 | + */ |
|
274 | + public static function underscore($word) |
|
275 | + { |
|
276 | + return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
|
277 | + } |
|
278 | + |
|
279 | + // }}} |
|
280 | + // {{{ humanize() |
|
281 | + |
|
282 | + /** |
|
283 | + * Returns a human-readable string from $word |
|
284 | + * |
|
285 | + * Returns a human-readable string from $word, by replacing |
|
286 | + * underscores with a space, and by upper-casing the initial |
|
287 | + * character by default. |
|
288 | + * |
|
289 | + * If you need to uppercase all the words you just have to |
|
290 | + * pass 'all' as a second parameter. |
|
291 | + * |
|
292 | + * @access public |
|
293 | + * @static |
|
294 | + * @param string $word String to "humanize" |
|
295 | + * @param string $uppercase If set to 'all' it will uppercase all the words |
|
296 | + * instead of just the first one. |
|
297 | + * @return string Human-readable word |
|
298 | + */ |
|
299 | + public static function humanize($word, $uppercase = '') |
|
300 | + { |
|
301 | + // make special exceptions for acronyms |
|
302 | + $word = str_replace('wp_', 'WP_', $word); |
|
303 | + $uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst'; |
|
304 | + return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
|
305 | + } |
|
306 | + |
|
307 | + // }}} |
|
308 | + // {{{ variablize() |
|
309 | + |
|
310 | + /** |
|
311 | + * Same as camelize but first char is underscored |
|
312 | + * |
|
313 | + * Converts a word like "send_email" to "sendEmail". It |
|
314 | + * will remove non alphanumeric character from the word, so |
|
315 | + * "who's online" will be converted to "whoSOnline" |
|
316 | + * |
|
317 | + * @access public |
|
318 | + * @static |
|
319 | + * @see camelize |
|
320 | + * @param string $word Word to lowerCamelCase |
|
321 | + * @return string Returns a lowerCamelCasedWord |
|
322 | + */ |
|
323 | + public static function variablize($word) |
|
324 | + { |
|
325 | + $word = EEH_Inflector::camelize($word); |
|
326 | + return strtolower($word[0]) . substr($word, 1); |
|
327 | + } |
|
328 | + |
|
329 | + // }}} |
|
330 | + // {{{ tableize() |
|
331 | + |
|
332 | + /** |
|
333 | + * Converts a class name to its table name according to rails |
|
334 | + * naming conventions. |
|
335 | + * |
|
336 | + * Converts "Person" to "people" |
|
337 | + * |
|
338 | + * @access public |
|
339 | + * @static |
|
340 | + * @see classify |
|
341 | + * @param string $class_name Class name for getting related table_name. |
|
342 | + * @return string plural_table_name |
|
343 | + */ |
|
344 | + public static function tableize($class_name) |
|
345 | + { |
|
346 | + return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
|
347 | + } |
|
348 | + |
|
349 | + // }}} |
|
350 | + // {{{ classify() |
|
351 | + |
|
352 | + /** |
|
353 | + * Converts a table name to its class name according to rails |
|
354 | + * naming conventions. |
|
355 | + * |
|
356 | + * Converts "people" to "Person" |
|
357 | + * |
|
358 | + * @access public |
|
359 | + * @static |
|
360 | + * @see tableize |
|
361 | + * @param string $table_name Table name for getting related ClassName. |
|
362 | + * @return string SingularClassName |
|
363 | + */ |
|
364 | + public static function classify($table_name) |
|
365 | + { |
|
366 | + return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
|
367 | + } |
|
368 | + |
|
369 | + // }}} |
|
370 | + // {{{ ordinalize() |
|
371 | + |
|
372 | + /** |
|
373 | + * Converts number to its ordinal English form. |
|
374 | + * |
|
375 | + * This method converts 13 to 13th, 2 to 2nd ... |
|
376 | + * |
|
377 | + * @access public |
|
378 | + * @static |
|
379 | + * @param integer $number Number to get its ordinal value |
|
380 | + * @return string Ordinal representation of given string. |
|
381 | + */ |
|
382 | + public static function ordinalize($number) |
|
383 | + { |
|
384 | + if (in_array(($number % 100), range(11, 13))) { |
|
385 | + return $number . 'th'; |
|
386 | + } else { |
|
387 | + switch (($number % 10)) { |
|
388 | + case 1: |
|
389 | + return $number . 'st'; |
|
390 | + break; |
|
391 | + case 2: |
|
392 | + return $number . 'nd'; |
|
393 | + break; |
|
394 | + case 3: |
|
395 | + return $number . 'rd'; |
|
396 | + default: |
|
397 | + return $number . 'th'; |
|
398 | + break; |
|
399 | + } |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * @param $string |
|
407 | + * @return string |
|
408 | + */ |
|
409 | + public static function add_indefinite_article($string) |
|
410 | + { |
|
411 | + if (strtolower($string) === 'null') { |
|
412 | + return $string; |
|
413 | + } |
|
414 | + return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string; |
|
415 | + } |
|
416 | 416 | } |
@@ -104,15 +104,15 @@ discard block |
||
104 | 104 | foreach ($uncountable as $_uncountable) { |
105 | 105 | if ( |
106 | 106 | substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
107 | - ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ]) |
|
107 | + ! ctype_alpha($lowercased_word[strlen($lowercased_word) - strlen($_uncountable)]) |
|
108 | 108 | ) { |
109 | 109 | return $word; |
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | 113 | foreach ($irregular as $_plural => $_singular) { |
114 | - if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) { |
|
115 | - return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
114 | + if (preg_match('/('.$_plural.')$/i', $word, $arr)) { |
|
115 | + return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | foreach ($irregular as $_plural => $_singular) { |
184 | - if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) { |
|
185 | - return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
184 | + if (preg_match('/('.$_singular.')$/i', $word, $arr)) { |
|
185 | + return preg_replace('/('.$_singular.')$/i', substr($arr[0], 0, 1).substr($_plural, 1), $word); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | public static function variablize($word) |
324 | 324 | { |
325 | 325 | $word = EEH_Inflector::camelize($word); |
326 | - return strtolower($word[0]) . substr($word, 1); |
|
326 | + return strtolower($word[0]).substr($word, 1); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // }}} |
@@ -382,19 +382,19 @@ discard block |
||
382 | 382 | public static function ordinalize($number) |
383 | 383 | { |
384 | 384 | if (in_array(($number % 100), range(11, 13))) { |
385 | - return $number . 'th'; |
|
385 | + return $number.'th'; |
|
386 | 386 | } else { |
387 | 387 | switch (($number % 10)) { |
388 | 388 | case 1: |
389 | - return $number . 'st'; |
|
389 | + return $number.'st'; |
|
390 | 390 | break; |
391 | 391 | case 2: |
392 | - return $number . 'nd'; |
|
392 | + return $number.'nd'; |
|
393 | 393 | break; |
394 | 394 | case 3: |
395 | - return $number . 'rd'; |
|
395 | + return $number.'rd'; |
|
396 | 396 | default: |
397 | - return $number . 'th'; |
|
397 | + return $number.'th'; |
|
398 | 398 | break; |
399 | 399 | } |
400 | 400 | } |
@@ -411,6 +411,6 @@ discard block |
||
411 | 411 | if (strtolower($string) === 'null') { |
412 | 412 | return $string; |
413 | 413 | } |
414 | - return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string; |
|
414 | + return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ').$string; |
|
415 | 415 | } |
416 | 416 | } |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | if ($sc_obj instanceof EE_Shortcodes) { |
209 | 209 | // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
210 | 210 | preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
211 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
211 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode; |
|
212 | 212 | |
213 | - if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
213 | + if ( ! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
214 | 214 | continue; // the given shortcode isn't in this object |
215 | 215 | } |
216 | 216 | |
217 | 217 | // if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
218 | - if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
218 | + if ( ! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
219 | 219 | $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
220 | 220 | } else { |
221 | 221 | $data_send = $this->_data; |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | foreach ($valid_shortcodes as $shortcode_ref) { |
272 | 272 | $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
273 | 273 | $ref = str_replace(' ', '_', $ref); |
274 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
274 | + $classname = 'EE_'.$ref.'_Shortcodes'; |
|
275 | 275 | if (class_exists($classname)) { |
276 | 276 | $this->_shortcode_objs[] = new $classname(); |
277 | 277 | } |
@@ -11,268 +11,268 @@ |
||
11 | 11 | */ |
12 | 12 | class EEH_Parse_Shortcodes |
13 | 13 | { |
14 | - /** |
|
15 | - * holds the template |
|
16 | - * |
|
17 | - * @access private |
|
18 | - * @var mixed (string|array) |
|
19 | - */ |
|
20 | - private $_template; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * holds the incoming data object |
|
25 | - * |
|
26 | - * @access private |
|
27 | - * @var object |
|
28 | - */ |
|
29 | - private $_data; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * will hold an array of EE_Shortcodes library objects. |
|
34 | - * |
|
35 | - * @access private |
|
36 | - * @var EE_Shortcodes[] |
|
37 | - */ |
|
38 | - private $_shortcode_objs = array(); |
|
39 | - |
|
40 | - |
|
41 | - public function __construct() |
|
42 | - { |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * This kicks off the parsing of shortcodes in message templates |
|
48 | - * |
|
49 | - * @param string $template This is the incoming string to be parsed |
|
50 | - * @param EE_Messages_Addressee $data This is the incoming data object |
|
51 | - * @param array $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries |
|
52 | - * @param EE_message_type $message_type The message type that called the parser |
|
53 | - * @param EE_messenger $messenger The active messenger for this parsing session. |
|
54 | - * @param EE_Message $message |
|
55 | - * @return string The parsed template string |
|
56 | - */ |
|
57 | - public function parse_message_template( |
|
58 | - $template, |
|
59 | - EE_Messages_Addressee $data, |
|
60 | - $valid_shortcodes, |
|
61 | - EE_message_type $message_type, |
|
62 | - EE_messenger $messenger, |
|
63 | - EE_Message $message |
|
64 | - ) { |
|
65 | - $extra_data = array( |
|
66 | - 'messenger' => $messenger, |
|
67 | - 'message_type' => $message_type, |
|
68 | - 'message' => $message, |
|
69 | - ); |
|
70 | - $this->_init_data($template, $data, $valid_shortcodes, $extra_data); |
|
71 | - $this->_template = is_array($template) ? $template['main'] : $template; |
|
72 | - return $this->_parse_message_template(); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - public function parse_attendee_list_template( |
|
77 | - $template, |
|
78 | - EE_Registration $registration, |
|
79 | - $valid_shortcodes, |
|
80 | - $extra_data = array() |
|
81 | - ) { |
|
82 | - $this->_init_data($template, $registration, $valid_shortcodes, $extra_data); |
|
83 | - $this->_template = is_array($template) ? $template['attendee_list'] : $template; |
|
84 | - return $this->_parse_message_template(); |
|
85 | - } |
|
86 | - |
|
87 | - public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) |
|
88 | - { |
|
89 | - $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
|
90 | - $this->_template = is_array($template) ? $template['event_list'] : $template; |
|
91 | - return $this->_parse_message_template(); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) |
|
96 | - { |
|
97 | - $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
|
98 | - $this->_template = is_array($template) ? $template['ticket_list'] : $template; |
|
99 | - return $this->_parse_message_template(); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - public function parse_line_item_list_template( |
|
104 | - $template, |
|
105 | - EE_Line_Item $line_item, |
|
106 | - $valid_shortcodes, |
|
107 | - $extra_data = array() |
|
108 | - ) { |
|
109 | - $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data); |
|
110 | - $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template; |
|
111 | - return $this->_parse_message_template(); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - public function parse_payment_list_template( |
|
116 | - $template, |
|
117 | - EE_Payment $payment_item, |
|
118 | - $valid_shortcodes, |
|
119 | - $extra_data = array() |
|
120 | - ) { |
|
121 | - $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data); |
|
122 | - $this->_template = is_array($template) ? $template['payment_list'] : $template; |
|
123 | - return $this->_parse_message_template(); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - public function parse_datetime_list_template( |
|
128 | - $template, |
|
129 | - EE_Datetime $datetime, |
|
130 | - $valid_shortcodes, |
|
131 | - $extra_data = array() |
|
132 | - ) { |
|
133 | - $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data); |
|
134 | - $this->_template = is_array($template) ? $template['datetime_list'] : $template; |
|
135 | - return $this->_parse_message_template(); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array()) |
|
140 | - { |
|
141 | - $this->_init_data($template, $answer, $valid_shortcodes, $extra_data); |
|
142 | - $this->_template = is_array($template) ? $template['question_list'] : $template; |
|
143 | - return $this->_parse_message_template(); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - private function _init_data($template, $data, $valid_shortcodes, $extra_data = array()) |
|
148 | - { |
|
149 | - $this->_reset_props(); |
|
150 | - $this->_data['template'] = $template; |
|
151 | - $this->_data['data'] = $data; |
|
152 | - $this->_data['extra_data'] = $extra_data; |
|
153 | - $this->_set_shortcodes($valid_shortcodes); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - private function _reset_props() |
|
158 | - { |
|
159 | - $this->_template = $this->_data = null; |
|
160 | - $this->_shortcode_objs = array(); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * takes the given template and parses it with the $_shortcodes property |
|
166 | - * |
|
167 | - * @access private |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - private function _parse_message_template() |
|
171 | - { |
|
172 | - // now let's get a list of shortcodes that are found in the given template |
|
173 | - preg_match_all('/(\[.+?\])/', $this->_template, $matches); |
|
174 | - $shortcodes = (array) $matches[0]; // this should be an array of shortcodes in the template string. |
|
175 | - |
|
176 | - $matched_code = array(); |
|
177 | - $sc_values = array(); |
|
178 | - |
|
179 | - $list_type_shortcodes = array( |
|
180 | - '[ATTENDEE_LIST]', |
|
181 | - '[EVENT_LIST]', |
|
182 | - '[TICKET_LIST]', |
|
183 | - '[DATETIME_LIST]', |
|
184 | - '[QUESTION_LIST]', |
|
185 | - '[RECIPIENT_QUESTION_LIST]', |
|
186 | - '[PRIMARY_REGISTRANT_QUESTION_LIST]', |
|
187 | - '[RECIPIENT_TICKET_LIST]', |
|
188 | - '[PRIMARY_REGISTRANT_TICKET_LIST]', |
|
189 | - '[RECIPIENT_DATETIME_LIST]', |
|
190 | - '[PRIMARY_REGISTRANT_DATETIME_LIST]', |
|
191 | - '[TICKET_LINE_ITEM_LIST]', |
|
192 | - '[TAX_LINE_ITEM_LIST]', |
|
193 | - '[ADDITIONAL_LINE_ITEM_LIST]', |
|
194 | - '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
195 | - '[PAYMENT_LIST_*]', |
|
196 | - ); |
|
197 | - |
|
198 | - $list_type_shortcodes = apply_filters( |
|
199 | - 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
200 | - $list_type_shortcodes |
|
201 | - ); |
|
202 | - |
|
203 | - // now lets go ahead and loop through our parsers for each shortcode and setup the values |
|
204 | - foreach ($shortcodes as $shortcode) { |
|
205 | - foreach ($this->_shortcode_objs as $sc_obj) { |
|
206 | - if ($sc_obj instanceof EE_Shortcodes) { |
|
207 | - // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
208 | - preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
209 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
210 | - |
|
211 | - if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
212 | - continue; // the given shortcode isn't in this object |
|
213 | - } |
|
214 | - |
|
215 | - // if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
|
216 | - if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
217 | - $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
218 | - } else { |
|
219 | - $data_send = $this->_data; |
|
220 | - } |
|
221 | - |
|
222 | - // is this a conditional type shortcode? If it is then we actually parse the template here. |
|
223 | - if ($this->_is_conditional_shortcode($shortcode)) { |
|
224 | - // most shortcode parsers are not going to have a match for this shortcode and will return an |
|
225 | - // empty string so we need to make sure that we're only replacing the template when there is a non empty string. |
|
226 | - $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
227 | - if ($parsed) { |
|
228 | - $this->_template = $parsed; |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
233 | - |
|
234 | - $matched_code[] = $shortcode; |
|
235 | - $sc_values[] = $parsed; |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - // now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out. |
|
241 | - $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template); |
|
242 | - return $parsed; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * Simply returns whether the given shortcode matches the structure for a conditional shortcode. |
|
248 | - * |
|
249 | - * Does it match this format: `[IF_` |
|
250 | - * |
|
251 | - * @param $shortcode |
|
252 | - */ |
|
253 | - protected function _is_conditional_shortcode($shortcode) |
|
254 | - { |
|
255 | - return strpos($shortcode, '[IF_') === 0; |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of |
|
261 | - * various EE_Shortcode library objects |
|
262 | - * |
|
263 | - * @access private |
|
264 | - * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects |
|
265 | - * @return void |
|
266 | - */ |
|
267 | - private function _set_shortcodes($valid_shortcodes) |
|
268 | - { |
|
269 | - foreach ($valid_shortcodes as $shortcode_ref) { |
|
270 | - $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
|
271 | - $ref = str_replace(' ', '_', $ref); |
|
272 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
273 | - if (class_exists($classname)) { |
|
274 | - $this->_shortcode_objs[] = new $classname(); |
|
275 | - } |
|
276 | - } |
|
277 | - } |
|
14 | + /** |
|
15 | + * holds the template |
|
16 | + * |
|
17 | + * @access private |
|
18 | + * @var mixed (string|array) |
|
19 | + */ |
|
20 | + private $_template; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * holds the incoming data object |
|
25 | + * |
|
26 | + * @access private |
|
27 | + * @var object |
|
28 | + */ |
|
29 | + private $_data; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * will hold an array of EE_Shortcodes library objects. |
|
34 | + * |
|
35 | + * @access private |
|
36 | + * @var EE_Shortcodes[] |
|
37 | + */ |
|
38 | + private $_shortcode_objs = array(); |
|
39 | + |
|
40 | + |
|
41 | + public function __construct() |
|
42 | + { |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * This kicks off the parsing of shortcodes in message templates |
|
48 | + * |
|
49 | + * @param string $template This is the incoming string to be parsed |
|
50 | + * @param EE_Messages_Addressee $data This is the incoming data object |
|
51 | + * @param array $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries |
|
52 | + * @param EE_message_type $message_type The message type that called the parser |
|
53 | + * @param EE_messenger $messenger The active messenger for this parsing session. |
|
54 | + * @param EE_Message $message |
|
55 | + * @return string The parsed template string |
|
56 | + */ |
|
57 | + public function parse_message_template( |
|
58 | + $template, |
|
59 | + EE_Messages_Addressee $data, |
|
60 | + $valid_shortcodes, |
|
61 | + EE_message_type $message_type, |
|
62 | + EE_messenger $messenger, |
|
63 | + EE_Message $message |
|
64 | + ) { |
|
65 | + $extra_data = array( |
|
66 | + 'messenger' => $messenger, |
|
67 | + 'message_type' => $message_type, |
|
68 | + 'message' => $message, |
|
69 | + ); |
|
70 | + $this->_init_data($template, $data, $valid_shortcodes, $extra_data); |
|
71 | + $this->_template = is_array($template) ? $template['main'] : $template; |
|
72 | + return $this->_parse_message_template(); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + public function parse_attendee_list_template( |
|
77 | + $template, |
|
78 | + EE_Registration $registration, |
|
79 | + $valid_shortcodes, |
|
80 | + $extra_data = array() |
|
81 | + ) { |
|
82 | + $this->_init_data($template, $registration, $valid_shortcodes, $extra_data); |
|
83 | + $this->_template = is_array($template) ? $template['attendee_list'] : $template; |
|
84 | + return $this->_parse_message_template(); |
|
85 | + } |
|
86 | + |
|
87 | + public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) |
|
88 | + { |
|
89 | + $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
|
90 | + $this->_template = is_array($template) ? $template['event_list'] : $template; |
|
91 | + return $this->_parse_message_template(); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) |
|
96 | + { |
|
97 | + $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
|
98 | + $this->_template = is_array($template) ? $template['ticket_list'] : $template; |
|
99 | + return $this->_parse_message_template(); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + public function parse_line_item_list_template( |
|
104 | + $template, |
|
105 | + EE_Line_Item $line_item, |
|
106 | + $valid_shortcodes, |
|
107 | + $extra_data = array() |
|
108 | + ) { |
|
109 | + $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data); |
|
110 | + $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template; |
|
111 | + return $this->_parse_message_template(); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + public function parse_payment_list_template( |
|
116 | + $template, |
|
117 | + EE_Payment $payment_item, |
|
118 | + $valid_shortcodes, |
|
119 | + $extra_data = array() |
|
120 | + ) { |
|
121 | + $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data); |
|
122 | + $this->_template = is_array($template) ? $template['payment_list'] : $template; |
|
123 | + return $this->_parse_message_template(); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + public function parse_datetime_list_template( |
|
128 | + $template, |
|
129 | + EE_Datetime $datetime, |
|
130 | + $valid_shortcodes, |
|
131 | + $extra_data = array() |
|
132 | + ) { |
|
133 | + $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data); |
|
134 | + $this->_template = is_array($template) ? $template['datetime_list'] : $template; |
|
135 | + return $this->_parse_message_template(); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array()) |
|
140 | + { |
|
141 | + $this->_init_data($template, $answer, $valid_shortcodes, $extra_data); |
|
142 | + $this->_template = is_array($template) ? $template['question_list'] : $template; |
|
143 | + return $this->_parse_message_template(); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + private function _init_data($template, $data, $valid_shortcodes, $extra_data = array()) |
|
148 | + { |
|
149 | + $this->_reset_props(); |
|
150 | + $this->_data['template'] = $template; |
|
151 | + $this->_data['data'] = $data; |
|
152 | + $this->_data['extra_data'] = $extra_data; |
|
153 | + $this->_set_shortcodes($valid_shortcodes); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + private function _reset_props() |
|
158 | + { |
|
159 | + $this->_template = $this->_data = null; |
|
160 | + $this->_shortcode_objs = array(); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * takes the given template and parses it with the $_shortcodes property |
|
166 | + * |
|
167 | + * @access private |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + private function _parse_message_template() |
|
171 | + { |
|
172 | + // now let's get a list of shortcodes that are found in the given template |
|
173 | + preg_match_all('/(\[.+?\])/', $this->_template, $matches); |
|
174 | + $shortcodes = (array) $matches[0]; // this should be an array of shortcodes in the template string. |
|
175 | + |
|
176 | + $matched_code = array(); |
|
177 | + $sc_values = array(); |
|
178 | + |
|
179 | + $list_type_shortcodes = array( |
|
180 | + '[ATTENDEE_LIST]', |
|
181 | + '[EVENT_LIST]', |
|
182 | + '[TICKET_LIST]', |
|
183 | + '[DATETIME_LIST]', |
|
184 | + '[QUESTION_LIST]', |
|
185 | + '[RECIPIENT_QUESTION_LIST]', |
|
186 | + '[PRIMARY_REGISTRANT_QUESTION_LIST]', |
|
187 | + '[RECIPIENT_TICKET_LIST]', |
|
188 | + '[PRIMARY_REGISTRANT_TICKET_LIST]', |
|
189 | + '[RECIPIENT_DATETIME_LIST]', |
|
190 | + '[PRIMARY_REGISTRANT_DATETIME_LIST]', |
|
191 | + '[TICKET_LINE_ITEM_LIST]', |
|
192 | + '[TAX_LINE_ITEM_LIST]', |
|
193 | + '[ADDITIONAL_LINE_ITEM_LIST]', |
|
194 | + '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
195 | + '[PAYMENT_LIST_*]', |
|
196 | + ); |
|
197 | + |
|
198 | + $list_type_shortcodes = apply_filters( |
|
199 | + 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
200 | + $list_type_shortcodes |
|
201 | + ); |
|
202 | + |
|
203 | + // now lets go ahead and loop through our parsers for each shortcode and setup the values |
|
204 | + foreach ($shortcodes as $shortcode) { |
|
205 | + foreach ($this->_shortcode_objs as $sc_obj) { |
|
206 | + if ($sc_obj instanceof EE_Shortcodes) { |
|
207 | + // we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
208 | + preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
209 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
210 | + |
|
211 | + if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
212 | + continue; // the given shortcode isn't in this object |
|
213 | + } |
|
214 | + |
|
215 | + // if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
|
216 | + if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
217 | + $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
218 | + } else { |
|
219 | + $data_send = $this->_data; |
|
220 | + } |
|
221 | + |
|
222 | + // is this a conditional type shortcode? If it is then we actually parse the template here. |
|
223 | + if ($this->_is_conditional_shortcode($shortcode)) { |
|
224 | + // most shortcode parsers are not going to have a match for this shortcode and will return an |
|
225 | + // empty string so we need to make sure that we're only replacing the template when there is a non empty string. |
|
226 | + $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
227 | + if ($parsed) { |
|
228 | + $this->_template = $parsed; |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
233 | + |
|
234 | + $matched_code[] = $shortcode; |
|
235 | + $sc_values[] = $parsed; |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + // now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out. |
|
241 | + $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template); |
|
242 | + return $parsed; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * Simply returns whether the given shortcode matches the structure for a conditional shortcode. |
|
248 | + * |
|
249 | + * Does it match this format: `[IF_` |
|
250 | + * |
|
251 | + * @param $shortcode |
|
252 | + */ |
|
253 | + protected function _is_conditional_shortcode($shortcode) |
|
254 | + { |
|
255 | + return strpos($shortcode, '[IF_') === 0; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of |
|
261 | + * various EE_Shortcode library objects |
|
262 | + * |
|
263 | + * @access private |
|
264 | + * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects |
|
265 | + * @return void |
|
266 | + */ |
|
267 | + private function _set_shortcodes($valid_shortcodes) |
|
268 | + { |
|
269 | + foreach ($valid_shortcodes as $shortcode_ref) { |
|
270 | + $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
|
271 | + $ref = str_replace(' ', '_', $ref); |
|
272 | + $classname = 'EE_' . $ref . '_Shortcodes'; |
|
273 | + if (class_exists($classname)) { |
|
274 | + $this->_shortcode_objs[] = new $classname(); |
|
275 | + } |
|
276 | + } |
|
277 | + } |
|
278 | 278 | } |
@@ -17,340 +17,340 @@ |
||
17 | 17 | */ |
18 | 18 | class CustomSelects |
19 | 19 | { |
20 | - const TYPE_SIMPLE = 'simple'; |
|
21 | - const TYPE_COMPLEX = 'complex'; |
|
22 | - const TYPE_STRUCTURED = 'structured'; |
|
23 | - |
|
24 | - private $valid_operators = array('COUNT', 'SUM'); |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * Original incoming select array |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - private $original_selects; |
|
33 | - |
|
34 | - /** |
|
35 | - * Select string that can be added to the query |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private $columns_to_select_expression; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * An array of aliases for the columns included in the incoming select array. |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - private $column_aliases_in_select; |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Enum representation of the "type" of array coming into this value object. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - private $type = ''; |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * CustomSelects constructor. |
|
60 | - * Incoming selects can be in one of the following formats: |
|
61 | - * ---- self::TYPE_SIMPLE array ---- |
|
62 | - * This is considered the "simple" type. In this case the array is an numerically indexed array with single or |
|
63 | - * multiple columns to select as the values. |
|
64 | - * eg. array( 'ATT_ID', 'REG_ID' ) |
|
65 | - * eg. array( '*' ) |
|
66 | - * If you want to use the columns in any WHERE, GROUP BY, or HAVING clauses, you must instead use the "complex" or |
|
67 | - * "structured" method. |
|
68 | - * ---- self::TYPE_COMPLEX array ---- |
|
69 | - * This is considered the "complex" type. In this case the array is indexed by arbitrary strings that serve as |
|
70 | - * column alias, and the value is an numerically indexed array where there are two values. The first value (0) is |
|
71 | - * the selection and the second value (1) is the data type. Data types must be one of the types defined in |
|
72 | - * EEM_Base::$_valid_wpdb_data_types. |
|
73 | - * eg. array( 'count' => array('count(REG_ID)', '%d') ) |
|
74 | - * Complex array configuration allows for using the column alias in any WHERE, GROUP BY, or HAVING clauses. |
|
75 | - * ---- self::TYPE_STRUCTURED array --- |
|
76 | - * This is considered the "structured" type. This type is similar to the complex type except that the array attached |
|
77 | - * to the column alias contains three values. The first value is the qualified column name (which can include |
|
78 | - * join syntax for models). The second value is the operator performed on the column (i.e. 'COUNT', 'SUM' etc)., |
|
79 | - * the third value is the data type. Note, if the select does not have an operator, you can use an empty string for |
|
80 | - * the second value. |
|
81 | - * Note: for now SUM is only for simple single column expressions (i.e. SUM(Transaction.TXN_total)) |
|
82 | - * eg. array( 'registration_count' => array('Registration.REG_ID', 'count', '%d') ); |
|
83 | - * NOTE: mixing array types in the incoming $select will cause errors. |
|
84 | - * |
|
85 | - * @param array $selects |
|
86 | - * @throws InvalidArgumentException |
|
87 | - */ |
|
88 | - public function __construct(array $selects) |
|
89 | - { |
|
90 | - $this->original_selects = $selects; |
|
91 | - $this->deriveType($selects); |
|
92 | - $this->deriveParts($selects); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Derives what type of custom select has been sent in. |
|
98 | - * |
|
99 | - * @param array $selects |
|
100 | - * @throws InvalidArgumentException |
|
101 | - */ |
|
102 | - private function deriveType(array $selects) |
|
103 | - { |
|
104 | - // first if the first key for this array is an integer then its coming in as a simple format, so we'll also |
|
105 | - // ensure all elements of the array are simple. |
|
106 | - if (is_int(key($selects))) { |
|
107 | - // let's ensure all keys are ints |
|
108 | - $invalid_keys = array_filter( |
|
109 | - array_keys($selects), |
|
110 | - function ($value) { |
|
111 | - return ! is_int($value); |
|
112 | - } |
|
113 | - ); |
|
114 | - if (! empty($invalid_keys)) { |
|
115 | - throw new InvalidArgumentException( |
|
116 | - sprintf( |
|
117 | - esc_html__( |
|
118 | - 'Incoming array looks like its formatted for "%1$s" type selects, however it has elements that are not indexed numerically', |
|
119 | - 'event_espresso' |
|
120 | - ), |
|
121 | - self::TYPE_SIMPLE |
|
122 | - ) |
|
123 | - ); |
|
124 | - } |
|
125 | - $this->type = self::TYPE_SIMPLE; |
|
126 | - return; |
|
127 | - } |
|
128 | - // made it here so that means we've got either complex or structured selects. Let's find out which by popping |
|
129 | - // the first array element off. |
|
130 | - $first_element = reset($selects); |
|
131 | - |
|
132 | - if (! is_array($first_element)) { |
|
133 | - throw new InvalidArgumentException( |
|
134 | - sprintf( |
|
135 | - esc_html__( |
|
136 | - 'Incoming array looks like its formatted as a "%1$s" or "%2$s" type. However, the values in the array must be arrays themselves and they are not.', |
|
137 | - 'event_espresso' |
|
138 | - ), |
|
139 | - self::TYPE_COMPLEX, |
|
140 | - self::TYPE_STRUCTURED |
|
141 | - ) |
|
142 | - ); |
|
143 | - } |
|
144 | - $this->type = count($first_element) === 2 |
|
145 | - ? self::TYPE_COMPLEX |
|
146 | - : self::TYPE_STRUCTURED; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * Sets up the various properties for the vo depending on type. |
|
152 | - * |
|
153 | - * @param array $selects |
|
154 | - * @throws InvalidArgumentException |
|
155 | - */ |
|
156 | - private function deriveParts(array $selects) |
|
157 | - { |
|
158 | - $column_parts = array(); |
|
159 | - switch ($this->type) { |
|
160 | - case self::TYPE_SIMPLE: |
|
161 | - $column_parts = $selects; |
|
162 | - $this->column_aliases_in_select = $selects; |
|
163 | - break; |
|
164 | - case self::TYPE_COMPLEX: |
|
165 | - foreach ($selects as $alias => $parts) { |
|
166 | - $this->validateSelectValueForType($parts, $alias); |
|
167 | - $column_parts[] = "{$parts[0]} AS {$alias}"; |
|
168 | - $this->column_aliases_in_select[] = $alias; |
|
169 | - } |
|
170 | - break; |
|
171 | - case self::TYPE_STRUCTURED: |
|
172 | - foreach ($selects as $alias => $parts) { |
|
173 | - $this->validateSelectValueForType($parts, $alias); |
|
174 | - $column_parts[] = $parts[1] !== '' |
|
175 | - ? $this->assembleSelectStringWithOperator($parts, $alias) |
|
176 | - : "{$parts[0]} AS {$alias}"; |
|
177 | - $this->column_aliases_in_select[] = $alias; |
|
178 | - } |
|
179 | - break; |
|
180 | - } |
|
181 | - $this->columns_to_select_expression = implode(', ', $column_parts); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Validates self::TYPE_COMPLEX and self::TYPE_STRUCTURED select statement parts. |
|
187 | - * |
|
188 | - * @param array $select_parts |
|
189 | - * @param string $alias |
|
190 | - * @throws InvalidArgumentException |
|
191 | - */ |
|
192 | - private function validateSelectValueForType(array $select_parts, $alias) |
|
193 | - { |
|
194 | - $valid_data_types = array('%d', '%s', '%f'); |
|
195 | - if (count($select_parts) !== $this->expectedSelectPartCountForType()) { |
|
196 | - throw new InvalidArgumentException( |
|
197 | - sprintf( |
|
198 | - esc_html__( |
|
199 | - 'The provided select part array for the %1$s column is expected to have a count of %2$d because the incoming select array is of type %3$s. However the count was %4$d.', |
|
200 | - 'event_espresso' |
|
201 | - ), |
|
202 | - $alias, |
|
203 | - $this->expectedSelectPartCountForType(), |
|
204 | - $this->type, |
|
205 | - count($select_parts) |
|
206 | - ) |
|
207 | - ); |
|
208 | - } |
|
209 | - // validate data type. |
|
210 | - $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
|
211 | - $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
|
212 | - |
|
213 | - if (! in_array($data_type, $valid_data_types, true)) { |
|
214 | - throw new InvalidArgumentException( |
|
215 | - sprintf( |
|
216 | - esc_html__( |
|
217 | - 'Datatype %1$s (for selection "%2$s" and alias "%3$s") is not a valid wpdb datatype (eg %%s)', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - $data_type, |
|
221 | - $select_parts[0], |
|
222 | - $alias, |
|
223 | - implode(', ', $valid_data_types) |
|
224 | - ) |
|
225 | - ); |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * Each type will have an expected count of array elements, this returns what that expected count is. |
|
232 | - * |
|
233 | - * @param string $type |
|
234 | - * @return int |
|
235 | - */ |
|
236 | - private function expectedSelectPartCountForType($type = '') |
|
237 | - { |
|
238 | - $type = $type === '' ? $this->type : $type; |
|
239 | - $types_count_map = array( |
|
240 | - self::TYPE_COMPLEX => 2, |
|
241 | - self::TYPE_STRUCTURED => 3, |
|
242 | - ); |
|
243 | - return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Prepares the select statement part for for structured type selects. |
|
249 | - * |
|
250 | - * @param array $select_parts |
|
251 | - * @param string $alias |
|
252 | - * @return string |
|
253 | - * @throws InvalidArgumentException |
|
254 | - */ |
|
255 | - private function assembleSelectStringWithOperator(array $select_parts, $alias) |
|
256 | - { |
|
257 | - $operator = strtoupper($select_parts[1]); |
|
258 | - // validate operator |
|
259 | - if (! in_array($operator, $this->valid_operators, true)) { |
|
260 | - throw new InvalidArgumentException( |
|
261 | - sprintf( |
|
262 | - esc_html__( |
|
263 | - 'An invalid operator has been provided (%1$s) for the column %2$s. Valid operators must be one of the following: %3$s.', |
|
264 | - 'event_espresso' |
|
265 | - ), |
|
266 | - $operator, |
|
267 | - $alias, |
|
268 | - implode(', ', $this->valid_operators) |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * Return the datatype from the given select part. |
|
278 | - * Remember the select_part has already been validated on object instantiation. |
|
279 | - * |
|
280 | - * @param array $select_part |
|
281 | - * @return string |
|
282 | - */ |
|
283 | - private function getDataTypeForSelectType(array $select_part) |
|
284 | - { |
|
285 | - switch ($this->type) { |
|
286 | - case self::TYPE_COMPLEX: |
|
287 | - return $select_part[1]; |
|
288 | - case self::TYPE_STRUCTURED: |
|
289 | - return $select_part[2]; |
|
290 | - default: |
|
291 | - return ''; |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * Returns the original select array sent into the VO. |
|
298 | - * |
|
299 | - * @return array |
|
300 | - */ |
|
301 | - public function originalSelects() |
|
302 | - { |
|
303 | - return $this->original_selects; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * Returns the final assembled select expression derived from the incoming select array. |
|
309 | - * |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function columnsToSelectExpression() |
|
313 | - { |
|
314 | - return $this->columns_to_select_expression; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Returns all the column aliases derived from the incoming select array. |
|
320 | - * |
|
321 | - * @return array |
|
322 | - */ |
|
323 | - public function columnAliases() |
|
324 | - { |
|
325 | - return $this->column_aliases_in_select; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Returns the enum type for the incoming select array. |
|
331 | - * |
|
332 | - * @return string |
|
333 | - */ |
|
334 | - public function type() |
|
335 | - { |
|
336 | - return $this->type; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * Return the datatype for the given column_alias |
|
342 | - * |
|
343 | - * @param string $column_alias |
|
344 | - * @return string (if there's no data type we return string as the default). |
|
345 | - */ |
|
346 | - public function getDataTypeForAlias($column_alias) |
|
347 | - { |
|
348 | - if ( |
|
349 | - isset($this->original_selects[ $column_alias ]) |
|
350 | - && in_array($column_alias, $this->columnAliases(), true) |
|
351 | - ) { |
|
352 | - return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]); |
|
353 | - } |
|
354 | - return '%s'; |
|
355 | - } |
|
20 | + const TYPE_SIMPLE = 'simple'; |
|
21 | + const TYPE_COMPLEX = 'complex'; |
|
22 | + const TYPE_STRUCTURED = 'structured'; |
|
23 | + |
|
24 | + private $valid_operators = array('COUNT', 'SUM'); |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * Original incoming select array |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + private $original_selects; |
|
33 | + |
|
34 | + /** |
|
35 | + * Select string that can be added to the query |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private $columns_to_select_expression; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * An array of aliases for the columns included in the incoming select array. |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + private $column_aliases_in_select; |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Enum representation of the "type" of array coming into this value object. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + private $type = ''; |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * CustomSelects constructor. |
|
60 | + * Incoming selects can be in one of the following formats: |
|
61 | + * ---- self::TYPE_SIMPLE array ---- |
|
62 | + * This is considered the "simple" type. In this case the array is an numerically indexed array with single or |
|
63 | + * multiple columns to select as the values. |
|
64 | + * eg. array( 'ATT_ID', 'REG_ID' ) |
|
65 | + * eg. array( '*' ) |
|
66 | + * If you want to use the columns in any WHERE, GROUP BY, or HAVING clauses, you must instead use the "complex" or |
|
67 | + * "structured" method. |
|
68 | + * ---- self::TYPE_COMPLEX array ---- |
|
69 | + * This is considered the "complex" type. In this case the array is indexed by arbitrary strings that serve as |
|
70 | + * column alias, and the value is an numerically indexed array where there are two values. The first value (0) is |
|
71 | + * the selection and the second value (1) is the data type. Data types must be one of the types defined in |
|
72 | + * EEM_Base::$_valid_wpdb_data_types. |
|
73 | + * eg. array( 'count' => array('count(REG_ID)', '%d') ) |
|
74 | + * Complex array configuration allows for using the column alias in any WHERE, GROUP BY, or HAVING clauses. |
|
75 | + * ---- self::TYPE_STRUCTURED array --- |
|
76 | + * This is considered the "structured" type. This type is similar to the complex type except that the array attached |
|
77 | + * to the column alias contains three values. The first value is the qualified column name (which can include |
|
78 | + * join syntax for models). The second value is the operator performed on the column (i.e. 'COUNT', 'SUM' etc)., |
|
79 | + * the third value is the data type. Note, if the select does not have an operator, you can use an empty string for |
|
80 | + * the second value. |
|
81 | + * Note: for now SUM is only for simple single column expressions (i.e. SUM(Transaction.TXN_total)) |
|
82 | + * eg. array( 'registration_count' => array('Registration.REG_ID', 'count', '%d') ); |
|
83 | + * NOTE: mixing array types in the incoming $select will cause errors. |
|
84 | + * |
|
85 | + * @param array $selects |
|
86 | + * @throws InvalidArgumentException |
|
87 | + */ |
|
88 | + public function __construct(array $selects) |
|
89 | + { |
|
90 | + $this->original_selects = $selects; |
|
91 | + $this->deriveType($selects); |
|
92 | + $this->deriveParts($selects); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Derives what type of custom select has been sent in. |
|
98 | + * |
|
99 | + * @param array $selects |
|
100 | + * @throws InvalidArgumentException |
|
101 | + */ |
|
102 | + private function deriveType(array $selects) |
|
103 | + { |
|
104 | + // first if the first key for this array is an integer then its coming in as a simple format, so we'll also |
|
105 | + // ensure all elements of the array are simple. |
|
106 | + if (is_int(key($selects))) { |
|
107 | + // let's ensure all keys are ints |
|
108 | + $invalid_keys = array_filter( |
|
109 | + array_keys($selects), |
|
110 | + function ($value) { |
|
111 | + return ! is_int($value); |
|
112 | + } |
|
113 | + ); |
|
114 | + if (! empty($invalid_keys)) { |
|
115 | + throw new InvalidArgumentException( |
|
116 | + sprintf( |
|
117 | + esc_html__( |
|
118 | + 'Incoming array looks like its formatted for "%1$s" type selects, however it has elements that are not indexed numerically', |
|
119 | + 'event_espresso' |
|
120 | + ), |
|
121 | + self::TYPE_SIMPLE |
|
122 | + ) |
|
123 | + ); |
|
124 | + } |
|
125 | + $this->type = self::TYPE_SIMPLE; |
|
126 | + return; |
|
127 | + } |
|
128 | + // made it here so that means we've got either complex or structured selects. Let's find out which by popping |
|
129 | + // the first array element off. |
|
130 | + $first_element = reset($selects); |
|
131 | + |
|
132 | + if (! is_array($first_element)) { |
|
133 | + throw new InvalidArgumentException( |
|
134 | + sprintf( |
|
135 | + esc_html__( |
|
136 | + 'Incoming array looks like its formatted as a "%1$s" or "%2$s" type. However, the values in the array must be arrays themselves and they are not.', |
|
137 | + 'event_espresso' |
|
138 | + ), |
|
139 | + self::TYPE_COMPLEX, |
|
140 | + self::TYPE_STRUCTURED |
|
141 | + ) |
|
142 | + ); |
|
143 | + } |
|
144 | + $this->type = count($first_element) === 2 |
|
145 | + ? self::TYPE_COMPLEX |
|
146 | + : self::TYPE_STRUCTURED; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * Sets up the various properties for the vo depending on type. |
|
152 | + * |
|
153 | + * @param array $selects |
|
154 | + * @throws InvalidArgumentException |
|
155 | + */ |
|
156 | + private function deriveParts(array $selects) |
|
157 | + { |
|
158 | + $column_parts = array(); |
|
159 | + switch ($this->type) { |
|
160 | + case self::TYPE_SIMPLE: |
|
161 | + $column_parts = $selects; |
|
162 | + $this->column_aliases_in_select = $selects; |
|
163 | + break; |
|
164 | + case self::TYPE_COMPLEX: |
|
165 | + foreach ($selects as $alias => $parts) { |
|
166 | + $this->validateSelectValueForType($parts, $alias); |
|
167 | + $column_parts[] = "{$parts[0]} AS {$alias}"; |
|
168 | + $this->column_aliases_in_select[] = $alias; |
|
169 | + } |
|
170 | + break; |
|
171 | + case self::TYPE_STRUCTURED: |
|
172 | + foreach ($selects as $alias => $parts) { |
|
173 | + $this->validateSelectValueForType($parts, $alias); |
|
174 | + $column_parts[] = $parts[1] !== '' |
|
175 | + ? $this->assembleSelectStringWithOperator($parts, $alias) |
|
176 | + : "{$parts[0]} AS {$alias}"; |
|
177 | + $this->column_aliases_in_select[] = $alias; |
|
178 | + } |
|
179 | + break; |
|
180 | + } |
|
181 | + $this->columns_to_select_expression = implode(', ', $column_parts); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Validates self::TYPE_COMPLEX and self::TYPE_STRUCTURED select statement parts. |
|
187 | + * |
|
188 | + * @param array $select_parts |
|
189 | + * @param string $alias |
|
190 | + * @throws InvalidArgumentException |
|
191 | + */ |
|
192 | + private function validateSelectValueForType(array $select_parts, $alias) |
|
193 | + { |
|
194 | + $valid_data_types = array('%d', '%s', '%f'); |
|
195 | + if (count($select_parts) !== $this->expectedSelectPartCountForType()) { |
|
196 | + throw new InvalidArgumentException( |
|
197 | + sprintf( |
|
198 | + esc_html__( |
|
199 | + 'The provided select part array for the %1$s column is expected to have a count of %2$d because the incoming select array is of type %3$s. However the count was %4$d.', |
|
200 | + 'event_espresso' |
|
201 | + ), |
|
202 | + $alias, |
|
203 | + $this->expectedSelectPartCountForType(), |
|
204 | + $this->type, |
|
205 | + count($select_parts) |
|
206 | + ) |
|
207 | + ); |
|
208 | + } |
|
209 | + // validate data type. |
|
210 | + $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
|
211 | + $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
|
212 | + |
|
213 | + if (! in_array($data_type, $valid_data_types, true)) { |
|
214 | + throw new InvalidArgumentException( |
|
215 | + sprintf( |
|
216 | + esc_html__( |
|
217 | + 'Datatype %1$s (for selection "%2$s" and alias "%3$s") is not a valid wpdb datatype (eg %%s)', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + $data_type, |
|
221 | + $select_parts[0], |
|
222 | + $alias, |
|
223 | + implode(', ', $valid_data_types) |
|
224 | + ) |
|
225 | + ); |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * Each type will have an expected count of array elements, this returns what that expected count is. |
|
232 | + * |
|
233 | + * @param string $type |
|
234 | + * @return int |
|
235 | + */ |
|
236 | + private function expectedSelectPartCountForType($type = '') |
|
237 | + { |
|
238 | + $type = $type === '' ? $this->type : $type; |
|
239 | + $types_count_map = array( |
|
240 | + self::TYPE_COMPLEX => 2, |
|
241 | + self::TYPE_STRUCTURED => 3, |
|
242 | + ); |
|
243 | + return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Prepares the select statement part for for structured type selects. |
|
249 | + * |
|
250 | + * @param array $select_parts |
|
251 | + * @param string $alias |
|
252 | + * @return string |
|
253 | + * @throws InvalidArgumentException |
|
254 | + */ |
|
255 | + private function assembleSelectStringWithOperator(array $select_parts, $alias) |
|
256 | + { |
|
257 | + $operator = strtoupper($select_parts[1]); |
|
258 | + // validate operator |
|
259 | + if (! in_array($operator, $this->valid_operators, true)) { |
|
260 | + throw new InvalidArgumentException( |
|
261 | + sprintf( |
|
262 | + esc_html__( |
|
263 | + 'An invalid operator has been provided (%1$s) for the column %2$s. Valid operators must be one of the following: %3$s.', |
|
264 | + 'event_espresso' |
|
265 | + ), |
|
266 | + $operator, |
|
267 | + $alias, |
|
268 | + implode(', ', $this->valid_operators) |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * Return the datatype from the given select part. |
|
278 | + * Remember the select_part has already been validated on object instantiation. |
|
279 | + * |
|
280 | + * @param array $select_part |
|
281 | + * @return string |
|
282 | + */ |
|
283 | + private function getDataTypeForSelectType(array $select_part) |
|
284 | + { |
|
285 | + switch ($this->type) { |
|
286 | + case self::TYPE_COMPLEX: |
|
287 | + return $select_part[1]; |
|
288 | + case self::TYPE_STRUCTURED: |
|
289 | + return $select_part[2]; |
|
290 | + default: |
|
291 | + return ''; |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * Returns the original select array sent into the VO. |
|
298 | + * |
|
299 | + * @return array |
|
300 | + */ |
|
301 | + public function originalSelects() |
|
302 | + { |
|
303 | + return $this->original_selects; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * Returns the final assembled select expression derived from the incoming select array. |
|
309 | + * |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function columnsToSelectExpression() |
|
313 | + { |
|
314 | + return $this->columns_to_select_expression; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Returns all the column aliases derived from the incoming select array. |
|
320 | + * |
|
321 | + * @return array |
|
322 | + */ |
|
323 | + public function columnAliases() |
|
324 | + { |
|
325 | + return $this->column_aliases_in_select; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Returns the enum type for the incoming select array. |
|
331 | + * |
|
332 | + * @return string |
|
333 | + */ |
|
334 | + public function type() |
|
335 | + { |
|
336 | + return $this->type; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * Return the datatype for the given column_alias |
|
342 | + * |
|
343 | + * @param string $column_alias |
|
344 | + * @return string (if there's no data type we return string as the default). |
|
345 | + */ |
|
346 | + public function getDataTypeForAlias($column_alias) |
|
347 | + { |
|
348 | + if ( |
|
349 | + isset($this->original_selects[ $column_alias ]) |
|
350 | + && in_array($column_alias, $this->columnAliases(), true) |
|
351 | + ) { |
|
352 | + return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]); |
|
353 | + } |
|
354 | + return '%s'; |
|
355 | + } |
|
356 | 356 | } |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | // let's ensure all keys are ints |
108 | 108 | $invalid_keys = array_filter( |
109 | 109 | array_keys($selects), |
110 | - function ($value) { |
|
110 | + function($value) { |
|
111 | 111 | return ! is_int($value); |
112 | 112 | } |
113 | 113 | ); |
114 | - if (! empty($invalid_keys)) { |
|
114 | + if ( ! empty($invalid_keys)) { |
|
115 | 115 | throw new InvalidArgumentException( |
116 | 116 | sprintf( |
117 | 117 | esc_html__( |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | // the first array element off. |
130 | 130 | $first_element = reset($selects); |
131 | 131 | |
132 | - if (! is_array($first_element)) { |
|
132 | + if ( ! is_array($first_element)) { |
|
133 | 133 | throw new InvalidArgumentException( |
134 | 134 | sprintf( |
135 | 135 | esc_html__( |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
211 | 211 | $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
212 | 212 | |
213 | - if (! in_array($data_type, $valid_data_types, true)) { |
|
213 | + if ( ! in_array($data_type, $valid_data_types, true)) { |
|
214 | 214 | throw new InvalidArgumentException( |
215 | 215 | sprintf( |
216 | 216 | esc_html__( |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | self::TYPE_COMPLEX => 2, |
241 | 241 | self::TYPE_STRUCTURED => 3, |
242 | 242 | ); |
243 | - return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0; |
|
243 | + return isset($types_count_map[$type]) ? $types_count_map[$type] : 0; |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | { |
257 | 257 | $operator = strtoupper($select_parts[1]); |
258 | 258 | // validate operator |
259 | - if (! in_array($operator, $this->valid_operators, true)) { |
|
259 | + if ( ! in_array($operator, $this->valid_operators, true)) { |
|
260 | 260 | throw new InvalidArgumentException( |
261 | 261 | sprintf( |
262 | 262 | esc_html__( |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | ) |
270 | 270 | ); |
271 | 271 | } |
272 | - return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
272 | + return $operator.'('.$select_parts[0].') AS '.$alias; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | |
@@ -346,10 +346,10 @@ discard block |
||
346 | 346 | public function getDataTypeForAlias($column_alias) |
347 | 347 | { |
348 | 348 | if ( |
349 | - isset($this->original_selects[ $column_alias ]) |
|
349 | + isset($this->original_selects[$column_alias]) |
|
350 | 350 | && in_array($column_alias, $this->columnAliases(), true) |
351 | 351 | ) { |
352 | - return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]); |
|
352 | + return $this->getDataTypeForSelectType($this->original_selects[$column_alias]); |
|
353 | 353 | } |
354 | 354 | return '%s'; |
355 | 355 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | if (is_array($this->_CPTs)) { |
129 | 129 | foreach ($this->_CPTs as $CPT_type => $CPT) { |
130 | 130 | if (isset($CPT['plural_slug'])) { |
131 | - $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type; |
|
131 | + $_CPT_endpoints [(string) $CPT['plural_slug']] = $CPT_type; |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | public function pre_get_posts($WP_Query) |
152 | 152 | { |
153 | 153 | // check that post-type is set |
154 | - if (! $WP_Query instanceof WP_Query) { |
|
154 | + if ( ! $WP_Query instanceof WP_Query) { |
|
155 | 155 | return; |
156 | 156 | } |
157 | 157 | // add our conditionals |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
196 | 196 | foreach ($terms as $term) { |
197 | 197 | if ($term instanceof EE_Term) { |
198 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
198 | + $this->_CPT_terms[$term->slug()] = $term; |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | } |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | // loop thru our taxonomies |
261 | 261 | foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
262 | 262 | // check if one of our taxonomies is set as a query var |
263 | - if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
263 | + if (isset($WP_Query->query[$CPT_taxonomy])) { |
|
264 | 264 | // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
265 | 265 | foreach ($this->_CPTs as $post_type => $CPT) { |
266 | 266 | // verify our CPT has args, is public and has taxonomies set |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | break; |
285 | 285 | default: |
286 | 286 | do_action( |
287 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
287 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_'.$post_type.'_post_type', |
|
288 | 288 | $WP_Query, |
289 | 289 | $this |
290 | 290 | ); |
@@ -309,11 +309,11 @@ discard block |
||
309 | 309 | // loop thru post_types as array |
310 | 310 | foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
311 | 311 | // is current query for an EE CPT ? |
312 | - if (isset($this->_CPTs[ $post_type ])) { |
|
312 | + if (isset($this->_CPTs[$post_type])) { |
|
313 | 313 | // is EE on or off ? |
314 | 314 | if (EE_Maintenance_Mode::instance()->level()) { |
315 | 315 | // reroute CPT template view to maintenance_mode.template.php |
316 | - if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
316 | + if ( ! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
317 | 317 | add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
318 | 318 | } |
319 | 319 | if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | 'EventEspresso\core\CPTs\CptQueryModifier', |
342 | 342 | array( |
343 | 343 | $post_type, |
344 | - $this->_CPTs[ $post_type ], |
|
344 | + $this->_CPTs[$post_type], |
|
345 | 345 | $WP_Query, |
346 | 346 | ) |
347 | 347 | ); |
@@ -15,449 +15,449 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_CPT_Strategy extends EE_Base |
17 | 17 | { |
18 | - /** |
|
19 | - * @var EE_CPT_Strategy $_instance |
|
20 | - */ |
|
21 | - private static $_instance; |
|
22 | - |
|
23 | - /** |
|
24 | - * the current page, if it utilizes CPTs |
|
25 | - * |
|
26 | - * @var array $CPT |
|
27 | - */ |
|
28 | - protected $CPT; |
|
29 | - |
|
30 | - /** |
|
31 | - * return value from CustomPostTypeDefinitions::getDefinitions() |
|
32 | - * |
|
33 | - * @var array $_CPTs |
|
34 | - */ |
|
35 | - protected $_CPTs = array(); |
|
36 | - |
|
37 | - /** |
|
38 | - * @var array $_CPT_taxonomies |
|
39 | - */ |
|
40 | - protected $_CPT_taxonomies = array(); |
|
41 | - |
|
42 | - /** |
|
43 | - * @var array $_CPT_terms |
|
44 | - */ |
|
45 | - protected $_CPT_terms = array(); |
|
46 | - |
|
47 | - /** |
|
48 | - * @var array $_CPT_endpoints |
|
49 | - */ |
|
50 | - protected $_CPT_endpoints = array(); |
|
51 | - |
|
52 | - /** |
|
53 | - * @var EEM_Base $CPT_model |
|
54 | - */ |
|
55 | - protected $CPT_model; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier |
|
59 | - */ |
|
60 | - protected $query_modifier; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @singleton method used to instantiate class object |
|
65 | - * @param CustomPostTypeDefinitions|null $custom_post_types |
|
66 | - * @param CustomTaxonomyDefinitions|null $taxonomies |
|
67 | - * @return EE_CPT_Strategy |
|
68 | - */ |
|
69 | - public static function instance( |
|
70 | - CustomPostTypeDefinitions $custom_post_types = null, |
|
71 | - CustomTaxonomyDefinitions $taxonomies = null |
|
72 | - ) { |
|
73 | - // check if class object is instantiated |
|
74 | - if ( |
|
75 | - ! self::$_instance instanceof EE_CPT_Strategy |
|
76 | - && $custom_post_types instanceof CustomPostTypeDefinitions |
|
77 | - && $taxonomies instanceof CustomTaxonomyDefinitions |
|
78 | - ) { |
|
79 | - self::$_instance = new self($custom_post_types, $taxonomies); |
|
80 | - } |
|
81 | - return self::$_instance; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @param CustomPostTypeDefinitions $custom_post_types |
|
87 | - * @param CustomTaxonomyDefinitions $taxonomies |
|
88 | - */ |
|
89 | - protected function __construct( |
|
90 | - CustomPostTypeDefinitions $custom_post_types, |
|
91 | - CustomTaxonomyDefinitions $taxonomies |
|
92 | - ) { |
|
93 | - // get CPT data |
|
94 | - $this->_CPTs = $custom_post_types->getDefinitions(); |
|
95 | - $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
96 | - $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
97 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 5); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - public function get_CPT_endpoints() |
|
105 | - { |
|
106 | - return $this->_CPT_endpoints; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @return array |
|
112 | - */ |
|
113 | - public function get_CPT_taxonomies() |
|
114 | - { |
|
115 | - return $this->_CPT_taxonomies; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * add CPT "slugs" to array of default espresso "pages" |
|
121 | - * |
|
122 | - * @return array |
|
123 | - */ |
|
124 | - private function _set_CPT_endpoints() |
|
125 | - { |
|
126 | - $_CPT_endpoints = array(); |
|
127 | - if (is_array($this->_CPTs)) { |
|
128 | - foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
129 | - if (isset($CPT['plural_slug'])) { |
|
130 | - $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type; |
|
131 | - } |
|
132 | - } |
|
133 | - } |
|
134 | - return $_CPT_endpoints; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
140 | - * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
141 | - * adding EE objects to the post to facilitate further querying of related data etc) |
|
142 | - * |
|
143 | - * @param WP_Query $WP_Query |
|
144 | - * @return void |
|
145 | - * @throws \EE_Error |
|
146 | - * @throws \InvalidArgumentException |
|
147 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
148 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
149 | - */ |
|
150 | - public function pre_get_posts($WP_Query) |
|
151 | - { |
|
152 | - // check that post-type is set |
|
153 | - if (! $WP_Query instanceof WP_Query) { |
|
154 | - return; |
|
155 | - } |
|
156 | - // add our conditionals |
|
157 | - $this->_set_EE_tags_on_WP_Query($WP_Query); |
|
158 | - // check for terms |
|
159 | - $this->_set_post_type_for_terms($WP_Query); |
|
160 | - // make sure paging is always set |
|
161 | - $this->_set_paging($WP_Query); |
|
162 | - // is a taxonomy set ? |
|
163 | - $this->_set_CPT_taxonomies_on_WP_Query($WP_Query); |
|
164 | - // loop thru post_types if set |
|
165 | - $this->_process_WP_Query_post_types($WP_Query); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param WP_Query $WP_Query |
|
171 | - * @return void |
|
172 | - */ |
|
173 | - private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query) |
|
174 | - { |
|
175 | - $WP_Query->is_espresso_event_single = false; |
|
176 | - $WP_Query->is_espresso_event_archive = false; |
|
177 | - $WP_Query->is_espresso_event_taxonomy = false; |
|
178 | - $WP_Query->is_espresso_venue_single = false; |
|
179 | - $WP_Query->is_espresso_venue_archive = false; |
|
180 | - $WP_Query->is_espresso_venue_taxonomy = false; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @return void |
|
186 | - * @throws EE_Error |
|
187 | - * @throws InvalidArgumentException |
|
188 | - * @throws InvalidDataTypeException |
|
189 | - * @throws InvalidInterfaceException |
|
190 | - */ |
|
191 | - private function _set_CPT_terms() |
|
192 | - { |
|
193 | - if (empty($this->_CPT_terms)) { |
|
194 | - $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
195 | - foreach ($terms as $term) { |
|
196 | - if ($term instanceof EE_Term) { |
|
197 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * @param WP_Query $WP_Query |
|
206 | - * @return void |
|
207 | - * @throws EE_Error |
|
208 | - * @throws InvalidArgumentException |
|
209 | - * @throws InvalidDataTypeException |
|
210 | - * @throws InvalidInterfaceException |
|
211 | - */ |
|
212 | - private function _set_post_type_for_terms(WP_Query $WP_Query) |
|
213 | - { |
|
214 | - // is a tag set ? |
|
215 | - if (isset($WP_Query->query['tag'])) { |
|
216 | - // get term for tag |
|
217 | - $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']); |
|
218 | - // verify the term |
|
219 | - if ($term instanceof EE_Term) { |
|
220 | - $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type); |
|
221 | - $term->post_type = apply_filters( |
|
222 | - 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
223 | - $term->post_type, |
|
224 | - $term |
|
225 | - ); |
|
226 | - // if a post type is already set |
|
227 | - if (isset($WP_Query->query_vars['post_type'])) { |
|
228 | - // add to existing array |
|
229 | - $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type); |
|
230 | - } |
|
231 | - // just set post_type to our CPT |
|
232 | - $WP_Query->set('post_type', array_unique($term->post_type)); |
|
233 | - } |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @param WP_Query $WP_Query |
|
240 | - * @return void |
|
241 | - */ |
|
242 | - public function _set_paging($WP_Query) |
|
243 | - { |
|
244 | - if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
245 | - $page = get_query_var('page') ? get_query_var('page') : null; |
|
246 | - $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
247 | - $WP_Query->set('paged', $paged); |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param \WP_Query $WP_Query |
|
254 | - */ |
|
255 | - protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query) |
|
256 | - { |
|
257 | - // is a taxonomy set ? |
|
258 | - if ($WP_Query->is_tax) { |
|
259 | - // loop thru our taxonomies |
|
260 | - foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
261 | - // check if one of our taxonomies is set as a query var |
|
262 | - if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
263 | - // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
264 | - foreach ($this->_CPTs as $post_type => $CPT) { |
|
265 | - // verify our CPT has args, is public and has taxonomies set |
|
266 | - if ( |
|
267 | - isset($CPT['args']['public']) |
|
268 | - && $CPT['args']['public'] |
|
269 | - && ! empty($CPT['args']['taxonomies']) |
|
270 | - && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
271 | - ) { |
|
272 | - // if so, then add this CPT post_type to the current query's array of post_types' |
|
273 | - $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type']) |
|
274 | - ? (array) $WP_Query->query_vars['post_type'] |
|
275 | - : array(); |
|
276 | - $WP_Query->query_vars['post_type'][] = $post_type; |
|
277 | - switch ($post_type) { |
|
278 | - case 'espresso_events': |
|
279 | - $WP_Query->is_espresso_event_taxonomy = true; |
|
280 | - break; |
|
281 | - case 'espresso_venues': |
|
282 | - $WP_Query->is_espresso_venue_taxonomy = true; |
|
283 | - break; |
|
284 | - default: |
|
285 | - do_action( |
|
286 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
287 | - $WP_Query, |
|
288 | - $this |
|
289 | - ); |
|
290 | - } |
|
291 | - } |
|
292 | - } |
|
293 | - } |
|
294 | - } |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * @param \WP_Query $WP_Query |
|
301 | - * @throws InvalidArgumentException |
|
302 | - * @throws InvalidDataTypeException |
|
303 | - * @throws InvalidInterfaceException |
|
304 | - */ |
|
305 | - protected function _process_WP_Query_post_types(WP_Query $WP_Query) |
|
306 | - { |
|
307 | - if (isset($WP_Query->query_vars['post_type'])) { |
|
308 | - // loop thru post_types as array |
|
309 | - foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
|
310 | - // is current query for an EE CPT ? |
|
311 | - if (isset($this->_CPTs[ $post_type ])) { |
|
312 | - // is EE on or off ? |
|
313 | - if (EE_Maintenance_Mode::instance()->level()) { |
|
314 | - // reroute CPT template view to maintenance_mode.template.php |
|
315 | - if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
316 | - add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
|
317 | - } |
|
318 | - if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
|
319 | - add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1); |
|
320 | - } |
|
321 | - return; |
|
322 | - } |
|
323 | - $this->_generate_CptQueryModifier($WP_Query, $post_type); |
|
324 | - } |
|
325 | - } |
|
326 | - } |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * @param \WP_Query $WP_Query |
|
332 | - * @param string $post_type |
|
333 | - * @throws InvalidArgumentException |
|
334 | - * @throws InvalidDataTypeException |
|
335 | - * @throws InvalidInterfaceException |
|
336 | - */ |
|
337 | - protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type) |
|
338 | - { |
|
339 | - $this->query_modifier = LoaderFactory::getLoader()->getShared( |
|
340 | - 'EventEspresso\core\CPTs\CptQueryModifier', |
|
341 | - array( |
|
342 | - $post_type, |
|
343 | - $this->_CPTs[ $post_type ], |
|
344 | - $WP_Query, |
|
345 | - ) |
|
346 | - ); |
|
347 | - $this->_CPT_taxonomies = $this->query_modifier->taxonomies(); |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * inject_EE_shortcode_placeholder |
|
353 | - * in order to display the M-Mode notice on our CPT routes, |
|
354 | - * we need to first inject what looks like one of our shortcodes, |
|
355 | - * so that it can be replaced with the actual M-Mode notice |
|
356 | - * |
|
357 | - * @return string |
|
358 | - */ |
|
359 | - public function inject_EE_shortcode_placeholder() |
|
360 | - { |
|
361 | - return '[ESPRESSO_'; |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * @deprecated |
|
367 | - * @since 4.8.41 |
|
368 | - * @return void |
|
369 | - */ |
|
370 | - public function _possibly_set_ee_request_var() |
|
371 | - { |
|
372 | - $this->query_modifier->setRequestVarsIfCpt(); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * @deprecated |
|
378 | - * @since 4.8.41 |
|
379 | - * @param $SQL |
|
380 | - * @return string |
|
381 | - */ |
|
382 | - public function posts_fields($SQL) |
|
383 | - { |
|
384 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
385 | - return $this->query_modifier->postsFields($SQL); |
|
386 | - } |
|
387 | - return $SQL; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * @deprecated |
|
393 | - * @since 4.8.41 |
|
394 | - * @param $SQL |
|
395 | - * @return string |
|
396 | - */ |
|
397 | - public function posts_join($SQL) |
|
398 | - { |
|
399 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
400 | - return $this->query_modifier->postsJoin($SQL); |
|
401 | - } |
|
402 | - return $SQL; |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * @deprecated |
|
408 | - * @since 4.8.41 |
|
409 | - * @param \WP_Post[] $posts |
|
410 | - * @return \WP_Post[] |
|
411 | - */ |
|
412 | - public function the_posts($posts) |
|
413 | - { |
|
414 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
415 | - $this->query_modifier->thePosts($posts); |
|
416 | - } |
|
417 | - return $posts; |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * @deprecated |
|
423 | - * @since 4.8.41 |
|
424 | - * @param $url |
|
425 | - * @param $ID |
|
426 | - * @return string |
|
427 | - */ |
|
428 | - public function get_edit_post_link($url, $ID) |
|
429 | - { |
|
430 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
431 | - return $this->query_modifier->getEditPostLink($url, $ID); |
|
432 | - } |
|
433 | - return ''; |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * @deprecated |
|
439 | - * @since 4.8.41 |
|
440 | - * @param null $WP_Query |
|
441 | - */ |
|
442 | - protected function _do_template_filters($WP_Query = null) |
|
443 | - { |
|
444 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
445 | - $this->query_modifier->addTemplateFilters(); |
|
446 | - } |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * @deprecated |
|
452 | - * @since 4.8.41 |
|
453 | - * @param string $current_template Existing default template path derived for this page call. |
|
454 | - * @return string the path to the full template file. |
|
455 | - */ |
|
456 | - public function single_cpt_template($current_template) |
|
457 | - { |
|
458 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
459 | - return $this->query_modifier->singleCptTemplate($current_template); |
|
460 | - } |
|
461 | - return $current_template; |
|
462 | - } |
|
18 | + /** |
|
19 | + * @var EE_CPT_Strategy $_instance |
|
20 | + */ |
|
21 | + private static $_instance; |
|
22 | + |
|
23 | + /** |
|
24 | + * the current page, if it utilizes CPTs |
|
25 | + * |
|
26 | + * @var array $CPT |
|
27 | + */ |
|
28 | + protected $CPT; |
|
29 | + |
|
30 | + /** |
|
31 | + * return value from CustomPostTypeDefinitions::getDefinitions() |
|
32 | + * |
|
33 | + * @var array $_CPTs |
|
34 | + */ |
|
35 | + protected $_CPTs = array(); |
|
36 | + |
|
37 | + /** |
|
38 | + * @var array $_CPT_taxonomies |
|
39 | + */ |
|
40 | + protected $_CPT_taxonomies = array(); |
|
41 | + |
|
42 | + /** |
|
43 | + * @var array $_CPT_terms |
|
44 | + */ |
|
45 | + protected $_CPT_terms = array(); |
|
46 | + |
|
47 | + /** |
|
48 | + * @var array $_CPT_endpoints |
|
49 | + */ |
|
50 | + protected $_CPT_endpoints = array(); |
|
51 | + |
|
52 | + /** |
|
53 | + * @var EEM_Base $CPT_model |
|
54 | + */ |
|
55 | + protected $CPT_model; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier |
|
59 | + */ |
|
60 | + protected $query_modifier; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @singleton method used to instantiate class object |
|
65 | + * @param CustomPostTypeDefinitions|null $custom_post_types |
|
66 | + * @param CustomTaxonomyDefinitions|null $taxonomies |
|
67 | + * @return EE_CPT_Strategy |
|
68 | + */ |
|
69 | + public static function instance( |
|
70 | + CustomPostTypeDefinitions $custom_post_types = null, |
|
71 | + CustomTaxonomyDefinitions $taxonomies = null |
|
72 | + ) { |
|
73 | + // check if class object is instantiated |
|
74 | + if ( |
|
75 | + ! self::$_instance instanceof EE_CPT_Strategy |
|
76 | + && $custom_post_types instanceof CustomPostTypeDefinitions |
|
77 | + && $taxonomies instanceof CustomTaxonomyDefinitions |
|
78 | + ) { |
|
79 | + self::$_instance = new self($custom_post_types, $taxonomies); |
|
80 | + } |
|
81 | + return self::$_instance; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @param CustomPostTypeDefinitions $custom_post_types |
|
87 | + * @param CustomTaxonomyDefinitions $taxonomies |
|
88 | + */ |
|
89 | + protected function __construct( |
|
90 | + CustomPostTypeDefinitions $custom_post_types, |
|
91 | + CustomTaxonomyDefinitions $taxonomies |
|
92 | + ) { |
|
93 | + // get CPT data |
|
94 | + $this->_CPTs = $custom_post_types->getDefinitions(); |
|
95 | + $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
96 | + $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
97 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 5); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + public function get_CPT_endpoints() |
|
105 | + { |
|
106 | + return $this->_CPT_endpoints; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @return array |
|
112 | + */ |
|
113 | + public function get_CPT_taxonomies() |
|
114 | + { |
|
115 | + return $this->_CPT_taxonomies; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * add CPT "slugs" to array of default espresso "pages" |
|
121 | + * |
|
122 | + * @return array |
|
123 | + */ |
|
124 | + private function _set_CPT_endpoints() |
|
125 | + { |
|
126 | + $_CPT_endpoints = array(); |
|
127 | + if (is_array($this->_CPTs)) { |
|
128 | + foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
129 | + if (isset($CPT['plural_slug'])) { |
|
130 | + $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type; |
|
131 | + } |
|
132 | + } |
|
133 | + } |
|
134 | + return $_CPT_endpoints; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
140 | + * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
141 | + * adding EE objects to the post to facilitate further querying of related data etc) |
|
142 | + * |
|
143 | + * @param WP_Query $WP_Query |
|
144 | + * @return void |
|
145 | + * @throws \EE_Error |
|
146 | + * @throws \InvalidArgumentException |
|
147 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
148 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
149 | + */ |
|
150 | + public function pre_get_posts($WP_Query) |
|
151 | + { |
|
152 | + // check that post-type is set |
|
153 | + if (! $WP_Query instanceof WP_Query) { |
|
154 | + return; |
|
155 | + } |
|
156 | + // add our conditionals |
|
157 | + $this->_set_EE_tags_on_WP_Query($WP_Query); |
|
158 | + // check for terms |
|
159 | + $this->_set_post_type_for_terms($WP_Query); |
|
160 | + // make sure paging is always set |
|
161 | + $this->_set_paging($WP_Query); |
|
162 | + // is a taxonomy set ? |
|
163 | + $this->_set_CPT_taxonomies_on_WP_Query($WP_Query); |
|
164 | + // loop thru post_types if set |
|
165 | + $this->_process_WP_Query_post_types($WP_Query); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param WP_Query $WP_Query |
|
171 | + * @return void |
|
172 | + */ |
|
173 | + private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query) |
|
174 | + { |
|
175 | + $WP_Query->is_espresso_event_single = false; |
|
176 | + $WP_Query->is_espresso_event_archive = false; |
|
177 | + $WP_Query->is_espresso_event_taxonomy = false; |
|
178 | + $WP_Query->is_espresso_venue_single = false; |
|
179 | + $WP_Query->is_espresso_venue_archive = false; |
|
180 | + $WP_Query->is_espresso_venue_taxonomy = false; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @return void |
|
186 | + * @throws EE_Error |
|
187 | + * @throws InvalidArgumentException |
|
188 | + * @throws InvalidDataTypeException |
|
189 | + * @throws InvalidInterfaceException |
|
190 | + */ |
|
191 | + private function _set_CPT_terms() |
|
192 | + { |
|
193 | + if (empty($this->_CPT_terms)) { |
|
194 | + $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
195 | + foreach ($terms as $term) { |
|
196 | + if ($term instanceof EE_Term) { |
|
197 | + $this->_CPT_terms[ $term->slug() ] = $term; |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * @param WP_Query $WP_Query |
|
206 | + * @return void |
|
207 | + * @throws EE_Error |
|
208 | + * @throws InvalidArgumentException |
|
209 | + * @throws InvalidDataTypeException |
|
210 | + * @throws InvalidInterfaceException |
|
211 | + */ |
|
212 | + private function _set_post_type_for_terms(WP_Query $WP_Query) |
|
213 | + { |
|
214 | + // is a tag set ? |
|
215 | + if (isset($WP_Query->query['tag'])) { |
|
216 | + // get term for tag |
|
217 | + $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']); |
|
218 | + // verify the term |
|
219 | + if ($term instanceof EE_Term) { |
|
220 | + $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type); |
|
221 | + $term->post_type = apply_filters( |
|
222 | + 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
223 | + $term->post_type, |
|
224 | + $term |
|
225 | + ); |
|
226 | + // if a post type is already set |
|
227 | + if (isset($WP_Query->query_vars['post_type'])) { |
|
228 | + // add to existing array |
|
229 | + $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type); |
|
230 | + } |
|
231 | + // just set post_type to our CPT |
|
232 | + $WP_Query->set('post_type', array_unique($term->post_type)); |
|
233 | + } |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @param WP_Query $WP_Query |
|
240 | + * @return void |
|
241 | + */ |
|
242 | + public function _set_paging($WP_Query) |
|
243 | + { |
|
244 | + if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
245 | + $page = get_query_var('page') ? get_query_var('page') : null; |
|
246 | + $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
247 | + $WP_Query->set('paged', $paged); |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param \WP_Query $WP_Query |
|
254 | + */ |
|
255 | + protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query) |
|
256 | + { |
|
257 | + // is a taxonomy set ? |
|
258 | + if ($WP_Query->is_tax) { |
|
259 | + // loop thru our taxonomies |
|
260 | + foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
261 | + // check if one of our taxonomies is set as a query var |
|
262 | + if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
263 | + // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
264 | + foreach ($this->_CPTs as $post_type => $CPT) { |
|
265 | + // verify our CPT has args, is public and has taxonomies set |
|
266 | + if ( |
|
267 | + isset($CPT['args']['public']) |
|
268 | + && $CPT['args']['public'] |
|
269 | + && ! empty($CPT['args']['taxonomies']) |
|
270 | + && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
271 | + ) { |
|
272 | + // if so, then add this CPT post_type to the current query's array of post_types' |
|
273 | + $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type']) |
|
274 | + ? (array) $WP_Query->query_vars['post_type'] |
|
275 | + : array(); |
|
276 | + $WP_Query->query_vars['post_type'][] = $post_type; |
|
277 | + switch ($post_type) { |
|
278 | + case 'espresso_events': |
|
279 | + $WP_Query->is_espresso_event_taxonomy = true; |
|
280 | + break; |
|
281 | + case 'espresso_venues': |
|
282 | + $WP_Query->is_espresso_venue_taxonomy = true; |
|
283 | + break; |
|
284 | + default: |
|
285 | + do_action( |
|
286 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
287 | + $WP_Query, |
|
288 | + $this |
|
289 | + ); |
|
290 | + } |
|
291 | + } |
|
292 | + } |
|
293 | + } |
|
294 | + } |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * @param \WP_Query $WP_Query |
|
301 | + * @throws InvalidArgumentException |
|
302 | + * @throws InvalidDataTypeException |
|
303 | + * @throws InvalidInterfaceException |
|
304 | + */ |
|
305 | + protected function _process_WP_Query_post_types(WP_Query $WP_Query) |
|
306 | + { |
|
307 | + if (isset($WP_Query->query_vars['post_type'])) { |
|
308 | + // loop thru post_types as array |
|
309 | + foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
|
310 | + // is current query for an EE CPT ? |
|
311 | + if (isset($this->_CPTs[ $post_type ])) { |
|
312 | + // is EE on or off ? |
|
313 | + if (EE_Maintenance_Mode::instance()->level()) { |
|
314 | + // reroute CPT template view to maintenance_mode.template.php |
|
315 | + if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
316 | + add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
|
317 | + } |
|
318 | + if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
|
319 | + add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1); |
|
320 | + } |
|
321 | + return; |
|
322 | + } |
|
323 | + $this->_generate_CptQueryModifier($WP_Query, $post_type); |
|
324 | + } |
|
325 | + } |
|
326 | + } |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * @param \WP_Query $WP_Query |
|
332 | + * @param string $post_type |
|
333 | + * @throws InvalidArgumentException |
|
334 | + * @throws InvalidDataTypeException |
|
335 | + * @throws InvalidInterfaceException |
|
336 | + */ |
|
337 | + protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type) |
|
338 | + { |
|
339 | + $this->query_modifier = LoaderFactory::getLoader()->getShared( |
|
340 | + 'EventEspresso\core\CPTs\CptQueryModifier', |
|
341 | + array( |
|
342 | + $post_type, |
|
343 | + $this->_CPTs[ $post_type ], |
|
344 | + $WP_Query, |
|
345 | + ) |
|
346 | + ); |
|
347 | + $this->_CPT_taxonomies = $this->query_modifier->taxonomies(); |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * inject_EE_shortcode_placeholder |
|
353 | + * in order to display the M-Mode notice on our CPT routes, |
|
354 | + * we need to first inject what looks like one of our shortcodes, |
|
355 | + * so that it can be replaced with the actual M-Mode notice |
|
356 | + * |
|
357 | + * @return string |
|
358 | + */ |
|
359 | + public function inject_EE_shortcode_placeholder() |
|
360 | + { |
|
361 | + return '[ESPRESSO_'; |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * @deprecated |
|
367 | + * @since 4.8.41 |
|
368 | + * @return void |
|
369 | + */ |
|
370 | + public function _possibly_set_ee_request_var() |
|
371 | + { |
|
372 | + $this->query_modifier->setRequestVarsIfCpt(); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * @deprecated |
|
378 | + * @since 4.8.41 |
|
379 | + * @param $SQL |
|
380 | + * @return string |
|
381 | + */ |
|
382 | + public function posts_fields($SQL) |
|
383 | + { |
|
384 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
385 | + return $this->query_modifier->postsFields($SQL); |
|
386 | + } |
|
387 | + return $SQL; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * @deprecated |
|
393 | + * @since 4.8.41 |
|
394 | + * @param $SQL |
|
395 | + * @return string |
|
396 | + */ |
|
397 | + public function posts_join($SQL) |
|
398 | + { |
|
399 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
400 | + return $this->query_modifier->postsJoin($SQL); |
|
401 | + } |
|
402 | + return $SQL; |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * @deprecated |
|
408 | + * @since 4.8.41 |
|
409 | + * @param \WP_Post[] $posts |
|
410 | + * @return \WP_Post[] |
|
411 | + */ |
|
412 | + public function the_posts($posts) |
|
413 | + { |
|
414 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
415 | + $this->query_modifier->thePosts($posts); |
|
416 | + } |
|
417 | + return $posts; |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * @deprecated |
|
423 | + * @since 4.8.41 |
|
424 | + * @param $url |
|
425 | + * @param $ID |
|
426 | + * @return string |
|
427 | + */ |
|
428 | + public function get_edit_post_link($url, $ID) |
|
429 | + { |
|
430 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
431 | + return $this->query_modifier->getEditPostLink($url, $ID); |
|
432 | + } |
|
433 | + return ''; |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * @deprecated |
|
439 | + * @since 4.8.41 |
|
440 | + * @param null $WP_Query |
|
441 | + */ |
|
442 | + protected function _do_template_filters($WP_Query = null) |
|
443 | + { |
|
444 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
445 | + $this->query_modifier->addTemplateFilters(); |
|
446 | + } |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * @deprecated |
|
452 | + * @since 4.8.41 |
|
453 | + * @param string $current_template Existing default template path derived for this page call. |
|
454 | + * @return string the path to the full template file. |
|
455 | + */ |
|
456 | + public function single_cpt_template($current_template) |
|
457 | + { |
|
458 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
459 | + return $this->query_modifier->singleCptTemplate($current_template); |
|
460 | + } |
|
461 | + return $current_template; |
|
462 | + } |
|
463 | 463 | } |