@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | protected function _extend_properties() |
65 | 65 | { |
66 | - define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
66 | + define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'messages/assets/'); |
|
67 | 67 | $this->_ajax_func = ['ee_msgs_create_new_custom' => 'create_new_custom']; |
68 | 68 | $this->_metaboxes = [ |
69 | 69 | 0 => [ |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | $this->_scripts_styles = [ |
79 | 79 | 'registers' => [ |
80 | 80 | 'events_msg_admin' => [ |
81 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
81 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL.'events_messages_admin.js', |
|
82 | 82 | 'depends' => ['ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'], |
83 | 83 | ], |
84 | 84 | 'events_msg_admin_css' => [ |
85 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
85 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL.'ee_msg_events_admin.css', |
|
86 | 86 | 'type' => 'css', |
87 | 87 | ], |
88 | 88 | ], |
@@ -154,18 +154,18 @@ discard block |
||
154 | 154 | ['action' => 'settings'], |
155 | 155 | EE_MSG_ADMIN_URL |
156 | 156 | ); |
157 | - $error_msg = sprintf( |
|
157 | + $error_msg = sprintf( |
|
158 | 158 | esc_html__( |
159 | 159 | 'There are no active messengers. So no notifications will go out for %1$sany%2$s events. You will want to %3$sActivate a Messenger%4$s.', |
160 | 160 | 'event_espresso' |
161 | 161 | ), |
162 | 162 | '<strong>', |
163 | 163 | '</strong>', |
164 | - '<a href="' . $msg_activate_url . '">', |
|
164 | + '<a href="'.$msg_activate_url.'">', |
|
165 | 165 | '</a>' |
166 | 166 | ); |
167 | - $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
168 | - $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
167 | + $error_content = '<div class="error"><p>'.$error_msg.'</p></div>'; |
|
168 | + $internal_content = '<div id="messages-error"><p>'.$error_msg.'</p></div>'; |
|
169 | 169 | |
170 | 170 | echo $error_content; |
171 | 171 | echo $internal_content; |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | ['event' => $EVT_ID] |
187 | 187 | ); |
188 | 188 | |
189 | - if (! empty($tab_content)) { |
|
190 | - $tabs[ $name ] = $tab_content; |
|
189 | + if ( ! empty($tab_content)) { |
|
190 | + $tabs[$name] = $tab_content; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | $notices = ' |
202 | 202 | <div id="espresso-ajax-loading" class="ajax-loader-grey"> |
203 | 203 | <span class="ee-spinner ee-spin"></span> |
204 | - <span class="hidden">' . esc_html__('loading...', 'event_espresso') . '</span> |
|
204 | + <span class="hidden">' . esc_html__('loading...', 'event_espresso').'</span> |
|
205 | 205 | </div> |
206 | 206 | <div class="ee-notices"></div>'; |
207 | 207 | |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | } |
211 | 211 | |
212 | 212 | do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
213 | - echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
213 | + echo $notices.'<div class="messages-tabs-content">'.$tabbed_content.'</div>'; |
|
214 | 214 | do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
215 | 215 | return ''; |
216 | 216 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function create_new_custom() |
229 | 229 | { |
230 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
230 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
231 | 231 | wp_die(esc_html__('You don\'t have privileges to do this action', 'event_espresso')); |
232 | 232 | } |
233 | 233 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | public function edit_admin_footer() |
271 | 271 | { |
272 | 272 | EEH_Template::display_template( |
273 | - EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
273 | + EE_CORE_CAF_ADMIN_EXTEND.'messages/templates/create_custom_template_form.template.php' |
|
274 | 274 | ); |
275 | 275 | } |
276 | 276 |
@@ -15,283 +15,283 @@ |
||
15 | 15 | class espresso_events_Messages_Hooks_Extend extends espresso_events_Messages_Hooks |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var Messages_Admin_Page |
|
20 | - */ |
|
21 | - protected $_page_object; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * espresso_events_Messages_Hooks_Extend constructor. |
|
26 | - * |
|
27 | - * @param EE_Admin_Page $admin_page |
|
28 | - * @throws EE_Error |
|
29 | - */ |
|
30 | - public function __construct(EE_Admin_Page $admin_page) |
|
31 | - { |
|
32 | - /** |
|
33 | - * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages |
|
34 | - */ |
|
35 | - if ( |
|
36 | - ! EE_Registry::instance()->CAP->current_user_can( |
|
37 | - 'ee_edit_messages', |
|
38 | - 'messages_events_editor_metabox' |
|
39 | - ) |
|
40 | - ) { |
|
41 | - return; |
|
42 | - } |
|
43 | - add_filter( |
|
44 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
45 | - [$this, 'caf_updates'], |
|
46 | - 10 |
|
47 | - ); |
|
48 | - add_action( |
|
49 | - 'AHEE__Extend_Events_Admin_Page___duplicate_event__after', |
|
50 | - [$this, 'duplicate_custom_message_settings'], |
|
51 | - 10, |
|
52 | - 2 |
|
53 | - ); |
|
54 | - parent::__construct($admin_page); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * extending the properties set in espresso_events_Messages_Hooks |
|
60 | - * |
|
61 | - * @access protected |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - protected function _extend_properties() |
|
65 | - { |
|
66 | - define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
67 | - $this->_ajax_func = ['ee_msgs_create_new_custom' => 'create_new_custom']; |
|
68 | - $this->_metaboxes = [ |
|
69 | - 0 => [ |
|
70 | - 'page_route' => ['edit', 'create_new'], |
|
71 | - 'func' => 'messages_metabox', |
|
72 | - 'label' => esc_html__('Notifications', 'event_espresso'), |
|
73 | - 'priority' => 'high', |
|
74 | - ], |
|
75 | - ]; |
|
76 | - |
|
77 | - // see explanation for layout in EE_Admin_Hooks |
|
78 | - $this->_scripts_styles = [ |
|
79 | - 'registers' => [ |
|
80 | - 'events_msg_admin' => [ |
|
81 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
82 | - 'depends' => ['ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'], |
|
83 | - ], |
|
84 | - 'events_msg_admin_css' => [ |
|
85 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
86 | - 'type' => 'css', |
|
87 | - ], |
|
88 | - ], |
|
89 | - 'enqueues' => [ |
|
90 | - 'events_msg_admin' => ['edit', 'create_new'], |
|
91 | - 'events_msg_admin_css' => ['edit', 'create_new'], |
|
92 | - ], |
|
93 | - ]; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - public function caf_updates($update_callbacks) |
|
98 | - { |
|
99 | - $update_callbacks[] = [$this, 'attach_evt_message_templates']; |
|
100 | - return $update_callbacks; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Handles attaching Message Templates to the Event on save. |
|
106 | - * |
|
107 | - * @param EE_Event $event EE event object |
|
108 | - * @param array $data The request data from the form |
|
109 | - * @return bool success or fail |
|
110 | - * @throws EE_Error |
|
111 | - * @throws ReflectionException |
|
112 | - */ |
|
113 | - public function attach_evt_message_templates($event, $data) |
|
114 | - { |
|
115 | - // first we remove all existing relations on the Event for message types. |
|
116 | - $event->_remove_relations('Message_Template_Group'); |
|
117 | - // now let's just loop through the selected templates and add relations! |
|
118 | - if (isset($data['event_message_templates_relation'])) { |
|
119 | - foreach ($data['event_message_templates_relation'] as $grp_ID) { |
|
120 | - $event->_add_relation_to($grp_ID, 'Message_Template_Group'); |
|
121 | - } |
|
122 | - } |
|
123 | - // now save |
|
124 | - return $event->save(); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @param $event |
|
130 | - * @param $callback_args |
|
131 | - * @return string |
|
132 | - * @throws EE_Error |
|
133 | - * @throws ReflectionException |
|
134 | - */ |
|
135 | - public function messages_metabox($event, $callback_args) |
|
136 | - { |
|
137 | - // convert 'evt_id' to 'EVT_ID' |
|
138 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
139 | - $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
|
140 | - $EVT_ID = $this->request->getRequestParam('evt_id', $EVT_ID, 'int'); |
|
141 | - $this->request->setRequestParam('EVT_ID', $EVT_ID); |
|
142 | - |
|
143 | - // get the active messengers (b/c messenger objects have the active message templates) |
|
144 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
145 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
146 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
147 | - $tabs = []; |
|
148 | - |
|
149 | - // empty messengers? |
|
150 | - // Note message types will always have at least one available because every messenger has a default message type |
|
151 | - // associated with it (payment) if no other message types are selected. |
|
152 | - if (empty($active_messengers)) { |
|
153 | - $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce( |
|
154 | - ['action' => 'settings'], |
|
155 | - EE_MSG_ADMIN_URL |
|
156 | - ); |
|
157 | - $error_msg = sprintf( |
|
158 | - esc_html__( |
|
159 | - 'There are no active messengers. So no notifications will go out for %1$sany%2$s events. You will want to %3$sActivate a Messenger%4$s.', |
|
160 | - 'event_espresso' |
|
161 | - ), |
|
162 | - '<strong>', |
|
163 | - '</strong>', |
|
164 | - '<a href="' . $msg_activate_url . '">', |
|
165 | - '</a>' |
|
166 | - ); |
|
167 | - $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
168 | - $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
169 | - |
|
170 | - echo $error_content; |
|
171 | - echo $internal_content; |
|
172 | - return ''; |
|
173 | - } |
|
174 | - |
|
175 | - // get content for active messengers |
|
176 | - foreach ($active_messengers as $name => $messenger) { |
|
177 | - // first check if there are any active message types for this messenger. |
|
178 | - $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name); |
|
179 | - if (empty($active_mts)) { |
|
180 | - continue; |
|
181 | - } |
|
182 | - |
|
183 | - $tab_content = $messenger->get_messenger_admin_page_content( |
|
184 | - 'events', |
|
185 | - 'edit', |
|
186 | - ['event' => $EVT_ID] |
|
187 | - ); |
|
188 | - |
|
189 | - if (! empty($tab_content)) { |
|
190 | - $tabs[ $name ] = $tab_content; |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - // we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper. |
|
196 | - $tabbed_content = EEH_Tabbed_Content::display($tabs); |
|
197 | - if ($tabbed_content instanceof WP_Error) { |
|
198 | - $tabbed_content = $tabbed_content->get_error_message(); |
|
199 | - } |
|
200 | - |
|
201 | - $notices = ' |
|
18 | + /** |
|
19 | + * @var Messages_Admin_Page |
|
20 | + */ |
|
21 | + protected $_page_object; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * espresso_events_Messages_Hooks_Extend constructor. |
|
26 | + * |
|
27 | + * @param EE_Admin_Page $admin_page |
|
28 | + * @throws EE_Error |
|
29 | + */ |
|
30 | + public function __construct(EE_Admin_Page $admin_page) |
|
31 | + { |
|
32 | + /** |
|
33 | + * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages |
|
34 | + */ |
|
35 | + if ( |
|
36 | + ! EE_Registry::instance()->CAP->current_user_can( |
|
37 | + 'ee_edit_messages', |
|
38 | + 'messages_events_editor_metabox' |
|
39 | + ) |
|
40 | + ) { |
|
41 | + return; |
|
42 | + } |
|
43 | + add_filter( |
|
44 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
45 | + [$this, 'caf_updates'], |
|
46 | + 10 |
|
47 | + ); |
|
48 | + add_action( |
|
49 | + 'AHEE__Extend_Events_Admin_Page___duplicate_event__after', |
|
50 | + [$this, 'duplicate_custom_message_settings'], |
|
51 | + 10, |
|
52 | + 2 |
|
53 | + ); |
|
54 | + parent::__construct($admin_page); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * extending the properties set in espresso_events_Messages_Hooks |
|
60 | + * |
|
61 | + * @access protected |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + protected function _extend_properties() |
|
65 | + { |
|
66 | + define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
67 | + $this->_ajax_func = ['ee_msgs_create_new_custom' => 'create_new_custom']; |
|
68 | + $this->_metaboxes = [ |
|
69 | + 0 => [ |
|
70 | + 'page_route' => ['edit', 'create_new'], |
|
71 | + 'func' => 'messages_metabox', |
|
72 | + 'label' => esc_html__('Notifications', 'event_espresso'), |
|
73 | + 'priority' => 'high', |
|
74 | + ], |
|
75 | + ]; |
|
76 | + |
|
77 | + // see explanation for layout in EE_Admin_Hooks |
|
78 | + $this->_scripts_styles = [ |
|
79 | + 'registers' => [ |
|
80 | + 'events_msg_admin' => [ |
|
81 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
82 | + 'depends' => ['ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'], |
|
83 | + ], |
|
84 | + 'events_msg_admin_css' => [ |
|
85 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
86 | + 'type' => 'css', |
|
87 | + ], |
|
88 | + ], |
|
89 | + 'enqueues' => [ |
|
90 | + 'events_msg_admin' => ['edit', 'create_new'], |
|
91 | + 'events_msg_admin_css' => ['edit', 'create_new'], |
|
92 | + ], |
|
93 | + ]; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + public function caf_updates($update_callbacks) |
|
98 | + { |
|
99 | + $update_callbacks[] = [$this, 'attach_evt_message_templates']; |
|
100 | + return $update_callbacks; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Handles attaching Message Templates to the Event on save. |
|
106 | + * |
|
107 | + * @param EE_Event $event EE event object |
|
108 | + * @param array $data The request data from the form |
|
109 | + * @return bool success or fail |
|
110 | + * @throws EE_Error |
|
111 | + * @throws ReflectionException |
|
112 | + */ |
|
113 | + public function attach_evt_message_templates($event, $data) |
|
114 | + { |
|
115 | + // first we remove all existing relations on the Event for message types. |
|
116 | + $event->_remove_relations('Message_Template_Group'); |
|
117 | + // now let's just loop through the selected templates and add relations! |
|
118 | + if (isset($data['event_message_templates_relation'])) { |
|
119 | + foreach ($data['event_message_templates_relation'] as $grp_ID) { |
|
120 | + $event->_add_relation_to($grp_ID, 'Message_Template_Group'); |
|
121 | + } |
|
122 | + } |
|
123 | + // now save |
|
124 | + return $event->save(); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @param $event |
|
130 | + * @param $callback_args |
|
131 | + * @return string |
|
132 | + * @throws EE_Error |
|
133 | + * @throws ReflectionException |
|
134 | + */ |
|
135 | + public function messages_metabox($event, $callback_args) |
|
136 | + { |
|
137 | + // convert 'evt_id' to 'EVT_ID' |
|
138 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
139 | + $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
|
140 | + $EVT_ID = $this->request->getRequestParam('evt_id', $EVT_ID, 'int'); |
|
141 | + $this->request->setRequestParam('EVT_ID', $EVT_ID); |
|
142 | + |
|
143 | + // get the active messengers (b/c messenger objects have the active message templates) |
|
144 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
145 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
146 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
147 | + $tabs = []; |
|
148 | + |
|
149 | + // empty messengers? |
|
150 | + // Note message types will always have at least one available because every messenger has a default message type |
|
151 | + // associated with it (payment) if no other message types are selected. |
|
152 | + if (empty($active_messengers)) { |
|
153 | + $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce( |
|
154 | + ['action' => 'settings'], |
|
155 | + EE_MSG_ADMIN_URL |
|
156 | + ); |
|
157 | + $error_msg = sprintf( |
|
158 | + esc_html__( |
|
159 | + 'There are no active messengers. So no notifications will go out for %1$sany%2$s events. You will want to %3$sActivate a Messenger%4$s.', |
|
160 | + 'event_espresso' |
|
161 | + ), |
|
162 | + '<strong>', |
|
163 | + '</strong>', |
|
164 | + '<a href="' . $msg_activate_url . '">', |
|
165 | + '</a>' |
|
166 | + ); |
|
167 | + $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
168 | + $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
169 | + |
|
170 | + echo $error_content; |
|
171 | + echo $internal_content; |
|
172 | + return ''; |
|
173 | + } |
|
174 | + |
|
175 | + // get content for active messengers |
|
176 | + foreach ($active_messengers as $name => $messenger) { |
|
177 | + // first check if there are any active message types for this messenger. |
|
178 | + $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name); |
|
179 | + if (empty($active_mts)) { |
|
180 | + continue; |
|
181 | + } |
|
182 | + |
|
183 | + $tab_content = $messenger->get_messenger_admin_page_content( |
|
184 | + 'events', |
|
185 | + 'edit', |
|
186 | + ['event' => $EVT_ID] |
|
187 | + ); |
|
188 | + |
|
189 | + if (! empty($tab_content)) { |
|
190 | + $tabs[ $name ] = $tab_content; |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + // we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper. |
|
196 | + $tabbed_content = EEH_Tabbed_Content::display($tabs); |
|
197 | + if ($tabbed_content instanceof WP_Error) { |
|
198 | + $tabbed_content = $tabbed_content->get_error_message(); |
|
199 | + } |
|
200 | + |
|
201 | + $notices = ' |
|
202 | 202 | <div id="espresso-ajax-loading" class="ajax-loader-grey"> |
203 | 203 | <span class="ee-spinner ee-spin"></span> |
204 | 204 | <span class="hidden">' . esc_html__('loading...', 'event_espresso') . '</span> |
205 | 205 | </div> |
206 | 206 | <div class="ee-notices"></div>'; |
207 | 207 | |
208 | - if (defined('DOING_AJAX')) { |
|
209 | - return $tabbed_content; |
|
210 | - } |
|
211 | - |
|
212 | - do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
|
213 | - echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
214 | - do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
|
215 | - return ''; |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * Ajax callback for ee_msgs_create_new_custom ajax request. |
|
221 | - * Takes incoming GRP_ID and name and description values from ajax request |
|
222 | - * to create a new custom template based off of the incoming GRP_ID. |
|
223 | - * |
|
224 | - * @access public |
|
225 | - * @return void |
|
226 | - * @throws EE_Error |
|
227 | - * @throws ReflectionException |
|
228 | - */ |
|
229 | - public function create_new_custom() |
|
230 | - { |
|
231 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
232 | - wp_die(esc_html__('You don\'t have privileges to do this action', 'event_espresso')); |
|
233 | - } |
|
234 | - |
|
235 | - /** @var RequestInterface $request */ |
|
236 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
237 | - |
|
238 | - // let's clean up the request data a bit for downstream usage of name and description. |
|
239 | - $templateName = $this->request->getRequestParam('custom_template_args[MTP_name]', ''); |
|
240 | - $request->setRequestParam('templateName', $templateName); |
|
241 | - $templateDescription = $this->request->getRequestParam('custom_template_args[MTP_description]', ''); |
|
242 | - $request->setRequestParam('templateDescription', $templateDescription); |
|
243 | - |
|
244 | - // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent |
|
245 | - $this->_set_page_object(); |
|
246 | - |
|
247 | - // is this a template switch if so EE_Admin_Page child needs this object |
|
248 | - $this->_page_object->set_hook_object($this); |
|
249 | - |
|
250 | - $this->_page_object->add_message_template( |
|
251 | - $this->request->getRequestParam('messageType', ''), |
|
252 | - $this->request->getRequestParam('messenger', ''), |
|
253 | - $this->request->getRequestParam('group_ID', 0, 'int') |
|
254 | - ); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - public function create_new_admin_footer() |
|
259 | - { |
|
260 | - $this->edit_admin_footer(); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * This is the dynamic method for this class |
|
266 | - * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page. |
|
267 | - * |
|
268 | - * @return void |
|
269 | - * @throws DomainException |
|
270 | - */ |
|
271 | - public function edit_admin_footer() |
|
272 | - { |
|
273 | - EEH_Template::display_template( |
|
274 | - EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
275 | - ); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate |
|
281 | - * the assigned custom message templates. |
|
282 | - * |
|
283 | - * @param EE_Event $new_event |
|
284 | - * @param EE_Event $original_event |
|
285 | - * @throws EE_Error |
|
286 | - * @throws ReflectionException |
|
287 | - */ |
|
288 | - public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event) |
|
289 | - { |
|
290 | - $message_template_groups = $original_event->get_many_related('Message_Template_Group'); |
|
291 | - foreach ($message_template_groups as $message_template_group) { |
|
292 | - $new_event->_add_relation_to($message_template_group, 'Message_Template_Group'); |
|
293 | - } |
|
294 | - // save new event |
|
295 | - $new_event->save(); |
|
296 | - } |
|
208 | + if (defined('DOING_AJAX')) { |
|
209 | + return $tabbed_content; |
|
210 | + } |
|
211 | + |
|
212 | + do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
|
213 | + echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
214 | + do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
|
215 | + return ''; |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * Ajax callback for ee_msgs_create_new_custom ajax request. |
|
221 | + * Takes incoming GRP_ID and name and description values from ajax request |
|
222 | + * to create a new custom template based off of the incoming GRP_ID. |
|
223 | + * |
|
224 | + * @access public |
|
225 | + * @return void |
|
226 | + * @throws EE_Error |
|
227 | + * @throws ReflectionException |
|
228 | + */ |
|
229 | + public function create_new_custom() |
|
230 | + { |
|
231 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
232 | + wp_die(esc_html__('You don\'t have privileges to do this action', 'event_espresso')); |
|
233 | + } |
|
234 | + |
|
235 | + /** @var RequestInterface $request */ |
|
236 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
237 | + |
|
238 | + // let's clean up the request data a bit for downstream usage of name and description. |
|
239 | + $templateName = $this->request->getRequestParam('custom_template_args[MTP_name]', ''); |
|
240 | + $request->setRequestParam('templateName', $templateName); |
|
241 | + $templateDescription = $this->request->getRequestParam('custom_template_args[MTP_description]', ''); |
|
242 | + $request->setRequestParam('templateDescription', $templateDescription); |
|
243 | + |
|
244 | + // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent |
|
245 | + $this->_set_page_object(); |
|
246 | + |
|
247 | + // is this a template switch if so EE_Admin_Page child needs this object |
|
248 | + $this->_page_object->set_hook_object($this); |
|
249 | + |
|
250 | + $this->_page_object->add_message_template( |
|
251 | + $this->request->getRequestParam('messageType', ''), |
|
252 | + $this->request->getRequestParam('messenger', ''), |
|
253 | + $this->request->getRequestParam('group_ID', 0, 'int') |
|
254 | + ); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + public function create_new_admin_footer() |
|
259 | + { |
|
260 | + $this->edit_admin_footer(); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * This is the dynamic method for this class |
|
266 | + * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page. |
|
267 | + * |
|
268 | + * @return void |
|
269 | + * @throws DomainException |
|
270 | + */ |
|
271 | + public function edit_admin_footer() |
|
272 | + { |
|
273 | + EEH_Template::display_template( |
|
274 | + EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
275 | + ); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate |
|
281 | + * the assigned custom message templates. |
|
282 | + * |
|
283 | + * @param EE_Event $new_event |
|
284 | + * @param EE_Event $original_event |
|
285 | + * @throws EE_Error |
|
286 | + * @throws ReflectionException |
|
287 | + */ |
|
288 | + public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event) |
|
289 | + { |
|
290 | + $message_template_groups = $original_event->get_many_related('Message_Template_Group'); |
|
291 | + foreach ($message_template_groups as $message_template_group) { |
|
292 | + $new_event->_add_relation_to($message_template_group, 'Message_Template_Group'); |
|
293 | + } |
|
294 | + // save new event |
|
295 | + $new_event->save(); |
|
296 | + } |
|
297 | 297 | } |
@@ -6,67 +6,67 @@ |
||
6 | 6 | |
7 | 7 | class RequestSanitizer |
8 | 8 | { |
9 | - /** |
|
10 | - * Will sanitize the supplied request parameter based on the specified data type |
|
11 | - * |
|
12 | - * @param mixed $param the supplied request parameter |
|
13 | - * @param string $type the specified data type (default: "string") |
|
14 | - * valid values: "bool", "float", "int", "key", "url", or "string" |
|
15 | - * @param bool $is_array if true, then $param will be treated as an array of $type |
|
16 | - * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator |
|
17 | - * @return array|bool|float|int|string |
|
18 | - * @since 4.10.14.p |
|
19 | - */ |
|
20 | - public function clean($param, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
21 | - { |
|
22 | - if ($delimiter !== '' && is_string($param)) { |
|
23 | - $param = explode($delimiter, $param); |
|
24 | - $is_array = is_array($param); |
|
25 | - // unset the delimiter else this function will recurse forever when we loop over the array of results |
|
26 | - $delimiter = ''; |
|
27 | - } |
|
28 | - // check if we are getting an improperly typed array and correct |
|
29 | - $is_array = $is_array && is_array($param); |
|
30 | - if ($is_array) { |
|
31 | - $values = []; |
|
32 | - foreach ((array) $param as $key => $value) { |
|
33 | - $values[ $key ] = $this->clean($value, $type, is_array($value), $delimiter); |
|
34 | - } |
|
35 | - return $values; |
|
36 | - } |
|
37 | - return $this->sanitizeParam($param, $type); |
|
38 | - } |
|
9 | + /** |
|
10 | + * Will sanitize the supplied request parameter based on the specified data type |
|
11 | + * |
|
12 | + * @param mixed $param the supplied request parameter |
|
13 | + * @param string $type the specified data type (default: "string") |
|
14 | + * valid values: "bool", "float", "int", "key", "url", or "string" |
|
15 | + * @param bool $is_array if true, then $param will be treated as an array of $type |
|
16 | + * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator |
|
17 | + * @return array|bool|float|int|string |
|
18 | + * @since 4.10.14.p |
|
19 | + */ |
|
20 | + public function clean($param, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
21 | + { |
|
22 | + if ($delimiter !== '' && is_string($param)) { |
|
23 | + $param = explode($delimiter, $param); |
|
24 | + $is_array = is_array($param); |
|
25 | + // unset the delimiter else this function will recurse forever when we loop over the array of results |
|
26 | + $delimiter = ''; |
|
27 | + } |
|
28 | + // check if we are getting an improperly typed array and correct |
|
29 | + $is_array = $is_array && is_array($param); |
|
30 | + if ($is_array) { |
|
31 | + $values = []; |
|
32 | + foreach ((array) $param as $key => $value) { |
|
33 | + $values[ $key ] = $this->clean($value, $type, is_array($value), $delimiter); |
|
34 | + } |
|
35 | + return $values; |
|
36 | + } |
|
37 | + return $this->sanitizeParam($param, $type); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param mixed $param |
|
43 | - * @param string $type |
|
44 | - * @return array|float|int|mixed|string|string[]|null |
|
45 | - * @since 4.10.20.p |
|
46 | - */ |
|
47 | - public function sanitizeParam($param, $type = DataType::STRING) |
|
48 | - { |
|
49 | - switch ($type) { |
|
50 | - case DataType::BOOL: |
|
51 | - return filter_var($param, FILTER_VALIDATE_BOOLEAN); |
|
52 | - case DataType::FLOAT: |
|
53 | - return (float) $param; |
|
54 | - case DataType::FQCN: |
|
55 | - return preg_replace('[^\\\w\d]', '', $param); |
|
56 | - case DataType::HTML: |
|
57 | - $allowed_tags = AllowedTags::getAllowedTags(); |
|
58 | - return wp_kses($param, $allowed_tags); |
|
59 | - case DataType::INT: |
|
60 | - return (int) $param; |
|
61 | - case DataType::KEY: |
|
62 | - return sanitize_key($param); |
|
63 | - case DataType::TITLE: |
|
64 | - return sanitize_title($param); |
|
65 | - case DataType::URL: |
|
66 | - return esc_url_raw($param); |
|
67 | - case DataType::STRING: |
|
68 | - default: |
|
69 | - return sanitize_text_field($param); |
|
70 | - } |
|
71 | - } |
|
41 | + /** |
|
42 | + * @param mixed $param |
|
43 | + * @param string $type |
|
44 | + * @return array|float|int|mixed|string|string[]|null |
|
45 | + * @since 4.10.20.p |
|
46 | + */ |
|
47 | + public function sanitizeParam($param, $type = DataType::STRING) |
|
48 | + { |
|
49 | + switch ($type) { |
|
50 | + case DataType::BOOL: |
|
51 | + return filter_var($param, FILTER_VALIDATE_BOOLEAN); |
|
52 | + case DataType::FLOAT: |
|
53 | + return (float) $param; |
|
54 | + case DataType::FQCN: |
|
55 | + return preg_replace('[^\\\w\d]', '', $param); |
|
56 | + case DataType::HTML: |
|
57 | + $allowed_tags = AllowedTags::getAllowedTags(); |
|
58 | + return wp_kses($param, $allowed_tags); |
|
59 | + case DataType::INT: |
|
60 | + return (int) $param; |
|
61 | + case DataType::KEY: |
|
62 | + return sanitize_key($param); |
|
63 | + case DataType::TITLE: |
|
64 | + return sanitize_title($param); |
|
65 | + case DataType::URL: |
|
66 | + return esc_url_raw($param); |
|
67 | + case DataType::STRING: |
|
68 | + default: |
|
69 | + return sanitize_text_field($param); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | } |
@@ -13,102 +13,102 @@ |
||
13 | 13 | class AllowedTags |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var array[] |
|
18 | - */ |
|
19 | - private static $attributes = [ |
|
20 | - 'action' => [], |
|
21 | - 'align' => [], |
|
22 | - 'alt' => [], |
|
23 | - 'class' => [], |
|
24 | - 'data' => [], |
|
25 | - 'for' => [], |
|
26 | - 'height' => [], |
|
27 | - 'href' => [], |
|
28 | - 'id' => [], |
|
29 | - 'method' => [], |
|
30 | - 'name' => [], |
|
31 | - 'novalidate' => [], |
|
32 | - 'rel' => [], |
|
33 | - 'src' => [], |
|
34 | - 'style' => [], |
|
35 | - 'tabindex' => [], |
|
36 | - 'target' => [], |
|
37 | - 'title' => [], |
|
38 | - 'type' => [], |
|
39 | - 'value' => [], |
|
40 | - 'width' => [], |
|
41 | - ]; |
|
16 | + /** |
|
17 | + * @var array[] |
|
18 | + */ |
|
19 | + private static $attributes = [ |
|
20 | + 'action' => [], |
|
21 | + 'align' => [], |
|
22 | + 'alt' => [], |
|
23 | + 'class' => [], |
|
24 | + 'data' => [], |
|
25 | + 'for' => [], |
|
26 | + 'height' => [], |
|
27 | + 'href' => [], |
|
28 | + 'id' => [], |
|
29 | + 'method' => [], |
|
30 | + 'name' => [], |
|
31 | + 'novalidate' => [], |
|
32 | + 'rel' => [], |
|
33 | + 'src' => [], |
|
34 | + 'style' => [], |
|
35 | + 'tabindex' => [], |
|
36 | + 'target' => [], |
|
37 | + 'title' => [], |
|
38 | + 'type' => [], |
|
39 | + 'value' => [], |
|
40 | + 'width' => [], |
|
41 | + ]; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - private static $tags = [ |
|
48 | - 'a', |
|
49 | - 'abbr', |
|
50 | - 'b', |
|
51 | - 'br', |
|
52 | - 'code', |
|
53 | - 'div', |
|
54 | - 'em', |
|
55 | - 'form', |
|
56 | - 'h1', |
|
57 | - 'h2', |
|
58 | - 'h3', |
|
59 | - 'h4', |
|
60 | - 'h5', |
|
61 | - 'h6', |
|
62 | - 'hr', |
|
63 | - 'i', |
|
64 | - 'iframe', |
|
65 | - 'img', |
|
66 | - 'input', |
|
67 | - 'label', |
|
68 | - 'li', |
|
69 | - 'ol', |
|
70 | - 'p', |
|
71 | - 'pre', |
|
72 | - 'script', |
|
73 | - 'small', |
|
74 | - 'span', |
|
75 | - 'strong', |
|
76 | - 'style', |
|
77 | - 'table', |
|
78 | - 'td', |
|
79 | - 'textarea', |
|
80 | - 'tr', |
|
81 | - 'ul', |
|
82 | - ]; |
|
44 | + /** |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + private static $tags = [ |
|
48 | + 'a', |
|
49 | + 'abbr', |
|
50 | + 'b', |
|
51 | + 'br', |
|
52 | + 'code', |
|
53 | + 'div', |
|
54 | + 'em', |
|
55 | + 'form', |
|
56 | + 'h1', |
|
57 | + 'h2', |
|
58 | + 'h3', |
|
59 | + 'h4', |
|
60 | + 'h5', |
|
61 | + 'h6', |
|
62 | + 'hr', |
|
63 | + 'i', |
|
64 | + 'iframe', |
|
65 | + 'img', |
|
66 | + 'input', |
|
67 | + 'label', |
|
68 | + 'li', |
|
69 | + 'ol', |
|
70 | + 'p', |
|
71 | + 'pre', |
|
72 | + 'script', |
|
73 | + 'small', |
|
74 | + 'span', |
|
75 | + 'strong', |
|
76 | + 'style', |
|
77 | + 'table', |
|
78 | + 'td', |
|
79 | + 'textarea', |
|
80 | + 'tr', |
|
81 | + 'ul', |
|
82 | + ]; |
|
83 | 83 | |
84 | - /** |
|
85 | - * @var array |
|
86 | - */ |
|
87 | - private static $allowed_tags; |
|
84 | + /** |
|
85 | + * @var array |
|
86 | + */ |
|
87 | + private static $allowed_tags; |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * merges additional tags and attributes into the WP global $allowedposttags |
|
92 | - */ |
|
93 | - private static function initializeAllowedTags() |
|
94 | - { |
|
95 | - global $allowedposttags; |
|
96 | - $allowed_tags = []; |
|
97 | - foreach (AllowedTags::$tags as $tag) { |
|
98 | - $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
99 | - } |
|
100 | - AllowedTags::$allowed_tags = array_merge_recursive($allowedposttags, $allowed_tags); |
|
101 | - } |
|
90 | + /** |
|
91 | + * merges additional tags and attributes into the WP global $allowedposttags |
|
92 | + */ |
|
93 | + private static function initializeAllowedTags() |
|
94 | + { |
|
95 | + global $allowedposttags; |
|
96 | + $allowed_tags = []; |
|
97 | + foreach (AllowedTags::$tags as $tag) { |
|
98 | + $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
99 | + } |
|
100 | + AllowedTags::$allowed_tags = array_merge_recursive($allowedposttags, $allowed_tags); |
|
101 | + } |
|
102 | 102 | |
103 | 103 | |
104 | - /** |
|
105 | - * @return array[] |
|
106 | - */ |
|
107 | - public static function getAllowedTags() |
|
108 | - { |
|
109 | - if (empty(AllowedTags::$allowed_tags)) { |
|
110 | - AllowedTags::initializeAllowedTags(); |
|
111 | - } |
|
112 | - return AllowedTags::$allowed_tags; |
|
113 | - } |
|
104 | + /** |
|
105 | + * @return array[] |
|
106 | + */ |
|
107 | + public static function getAllowedTags() |
|
108 | + { |
|
109 | + if (empty(AllowedTags::$allowed_tags)) { |
|
110 | + AllowedTags::initializeAllowedTags(); |
|
111 | + } |
|
112 | + return AllowedTags::$allowed_tags; |
|
113 | + } |
|
114 | 114 | } |
@@ -95,7 +95,7 @@ |
||
95 | 95 | global $allowedposttags; |
96 | 96 | $allowed_tags = []; |
97 | 97 | foreach (AllowedTags::$tags as $tag) { |
98 | - $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
98 | + $allowed_tags[$tag] = AllowedTags::$attributes; |
|
99 | 99 | } |
100 | 100 | AllowedTags::$allowed_tags = array_merge_recursive($allowedposttags, $allowed_tags); |
101 | 101 | } |
@@ -16,195 +16,195 @@ |
||
16 | 16 | interface RequestInterface extends RequestTypeContextCheckerInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @param RequestTypeContextCheckerInterface $type |
|
21 | - */ |
|
22 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
19 | + /** |
|
20 | + * @param RequestTypeContextCheckerInterface $type |
|
21 | + */ |
|
22 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * @return array |
|
27 | - */ |
|
28 | - public function getParams(); |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - public function postParams(); |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @return array |
|
39 | - */ |
|
40 | - public function cookieParams(); |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function serverParams(); |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * @param string $key |
|
51 | - * @param mixed|null $default |
|
52 | - * @return array|int|float|string |
|
53 | - */ |
|
54 | - public function getServerParam($key, $default = null); |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $key |
|
59 | - * @param array|int|float|string $value |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public function setServerParam($key, $value); |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $key |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function serverParamIsSet($key); |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public function filesParams(); |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * returns sanitized contents of $_REQUEST |
|
80 | - * |
|
81 | - * @return array |
|
82 | - */ |
|
83 | - public function requestParams(); |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @param string $key |
|
88 | - * @param string $value |
|
89 | - * @param bool $override_ee |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - public function setRequestParam($key, $value, $override_ee = false); |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * returns the value for a request param if the given key exists |
|
97 | - * |
|
98 | - * @param string $key |
|
99 | - * @param mixed|null $default |
|
100 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
101 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
102 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
103 | - * @return array|bool|float|int|string |
|
104 | - */ |
|
105 | - public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = ''); |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * check if param exists |
|
110 | - * |
|
111 | - * @param string $key |
|
112 | - * @return bool |
|
113 | - */ |
|
114 | - public function requestParamIsSet($key); |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
119 | - * and return the value for the first match found |
|
120 | - * wildcards can be either of the following: |
|
121 | - * ? to represent a single character of any type |
|
122 | - * * to represent one or more characters of any type |
|
123 | - * |
|
124 | - * @param string $pattern |
|
125 | - * @param mixed|null $default |
|
126 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
127 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
128 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
129 | - * @return array|bool|float|int|string |
|
130 | - */ |
|
131 | - public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = ''); |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
136 | - * wildcards can be either of the following: |
|
137 | - * ? to represent a single character of any type |
|
138 | - * * to represent one or more characters of any type |
|
139 | - * returns true if a match is found or false if not |
|
140 | - * |
|
141 | - * @param string $pattern |
|
142 | - * @return false|int |
|
143 | - */ |
|
144 | - public function matches($pattern); |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * remove param |
|
149 | - * |
|
150 | - * @param string $key |
|
151 | - * @param bool $unset_from_global_too |
|
152 | - */ |
|
153 | - public function unSetRequestParam($key, $unset_from_global_too = false); |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * remove params |
|
158 | - * |
|
159 | - * @param array $keys |
|
160 | - * @param bool $unset_from_global_too |
|
161 | - */ |
|
162 | - public function unSetRequestParams(array $keys, $unset_from_global_too = false); |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - public function ipAddress(); |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not. |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function requestUri($relativeToWpRoot = false); |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function userAgent(); |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @param string $user_agent |
|
186 | - */ |
|
187 | - public function setUserAgent($user_agent = ''); |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * @return bool |
|
192 | - */ |
|
193 | - public function isBot(); |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @param bool $is_bot |
|
198 | - */ |
|
199 | - public function setIsBot($is_bot); |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * merges the incoming array of parameters into the existing request parameters |
|
204 | - * |
|
205 | - * @param array $request_params |
|
206 | - * @return mixed |
|
207 | - * @since 4.10.24.p |
|
208 | - */ |
|
209 | - public function mergeRequestParams(array $request_params); |
|
25 | + /** |
|
26 | + * @return array |
|
27 | + */ |
|
28 | + public function getParams(); |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + public function postParams(); |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @return array |
|
39 | + */ |
|
40 | + public function cookieParams(); |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function serverParams(); |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * @param string $key |
|
51 | + * @param mixed|null $default |
|
52 | + * @return array|int|float|string |
|
53 | + */ |
|
54 | + public function getServerParam($key, $default = null); |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $key |
|
59 | + * @param array|int|float|string $value |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public function setServerParam($key, $value); |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $key |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function serverParamIsSet($key); |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public function filesParams(); |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * returns sanitized contents of $_REQUEST |
|
80 | + * |
|
81 | + * @return array |
|
82 | + */ |
|
83 | + public function requestParams(); |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @param string $key |
|
88 | + * @param string $value |
|
89 | + * @param bool $override_ee |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + public function setRequestParam($key, $value, $override_ee = false); |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * returns the value for a request param if the given key exists |
|
97 | + * |
|
98 | + * @param string $key |
|
99 | + * @param mixed|null $default |
|
100 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
101 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
102 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
103 | + * @return array|bool|float|int|string |
|
104 | + */ |
|
105 | + public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = ''); |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * check if param exists |
|
110 | + * |
|
111 | + * @param string $key |
|
112 | + * @return bool |
|
113 | + */ |
|
114 | + public function requestParamIsSet($key); |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
119 | + * and return the value for the first match found |
|
120 | + * wildcards can be either of the following: |
|
121 | + * ? to represent a single character of any type |
|
122 | + * * to represent one or more characters of any type |
|
123 | + * |
|
124 | + * @param string $pattern |
|
125 | + * @param mixed|null $default |
|
126 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
127 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
128 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
129 | + * @return array|bool|float|int|string |
|
130 | + */ |
|
131 | + public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = ''); |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
136 | + * wildcards can be either of the following: |
|
137 | + * ? to represent a single character of any type |
|
138 | + * * to represent one or more characters of any type |
|
139 | + * returns true if a match is found or false if not |
|
140 | + * |
|
141 | + * @param string $pattern |
|
142 | + * @return false|int |
|
143 | + */ |
|
144 | + public function matches($pattern); |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * remove param |
|
149 | + * |
|
150 | + * @param string $key |
|
151 | + * @param bool $unset_from_global_too |
|
152 | + */ |
|
153 | + public function unSetRequestParam($key, $unset_from_global_too = false); |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * remove params |
|
158 | + * |
|
159 | + * @param array $keys |
|
160 | + * @param bool $unset_from_global_too |
|
161 | + */ |
|
162 | + public function unSetRequestParams(array $keys, $unset_from_global_too = false); |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + public function ipAddress(); |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not. |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function requestUri($relativeToWpRoot = false); |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function userAgent(); |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @param string $user_agent |
|
186 | + */ |
|
187 | + public function setUserAgent($user_agent = ''); |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * @return bool |
|
192 | + */ |
|
193 | + public function isBot(); |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @param bool $is_bot |
|
198 | + */ |
|
199 | + public function setIsBot($is_bot); |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * merges the incoming array of parameters into the existing request parameters |
|
204 | + * |
|
205 | + * @param array $request_params |
|
206 | + * @return mixed |
|
207 | + * @since 4.10.24.p |
|
208 | + */ |
|
209 | + public function mergeRequestParams(array $request_params); |
|
210 | 210 | } |
@@ -17,495 +17,495 @@ |
||
17 | 17 | class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * $_COOKIE parameters |
|
22 | - * |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $cookies; |
|
26 | - |
|
27 | - /** |
|
28 | - * $_FILES parameters |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $files; |
|
33 | - |
|
34 | - /** |
|
35 | - * true if current user appears to be some kind of bot |
|
36 | - * |
|
37 | - * @var bool |
|
38 | - */ |
|
39 | - protected $is_bot; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var RequestParams |
|
43 | - */ |
|
44 | - protected $request_params; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var RequestTypeContextCheckerInterface |
|
48 | - */ |
|
49 | - protected $request_type; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var ServerParams |
|
53 | - */ |
|
54 | - protected $server_params; |
|
55 | - |
|
56 | - |
|
57 | - public function __construct( |
|
58 | - RequestParams $request_params, |
|
59 | - ServerParams $server_params, |
|
60 | - array $cookies = [], |
|
61 | - array $files = [] |
|
62 | - ) { |
|
63 | - $this->cookies = ! empty($cookies) |
|
64 | - ? $cookies |
|
65 | - : filter_input_array(INPUT_COOKIE, FILTER_SANITIZE_STRING); |
|
66 | - $this->files = ! empty($files) ? $files : $_FILES; |
|
67 | - $this->request_params = $request_params; |
|
68 | - $this->server_params = $server_params; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @param RequestTypeContextCheckerInterface $type |
|
74 | - */ |
|
75 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
76 | - { |
|
77 | - $this->request_type = $type; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public function getParams() |
|
85 | - { |
|
86 | - return $this->request_params->getParams(); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - public function postParams() |
|
94 | - { |
|
95 | - return $this->request_params->postParams(); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - public function cookieParams() |
|
103 | - { |
|
104 | - return $this->cookies; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - public function serverParams() |
|
112 | - { |
|
113 | - return $this->server_params->getAllServerParams(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $key |
|
119 | - * @param mixed|null $default |
|
120 | - * @return array|int|float|string |
|
121 | - */ |
|
122 | - public function getServerParam($key, $default = null) |
|
123 | - { |
|
124 | - return $this->server_params->getServerParam($key, $default); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @param string $key |
|
130 | - * @param array|int|float|string $value |
|
131 | - * @return void |
|
132 | - */ |
|
133 | - public function setServerParam($key, $value) |
|
134 | - { |
|
135 | - $this->server_params->setServerParam($key, $value); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $key |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - public function serverParamIsSet($key) |
|
144 | - { |
|
145 | - return $this->server_params->serverParamIsSet($key); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @return array |
|
151 | - */ |
|
152 | - public function filesParams() |
|
153 | - { |
|
154 | - return $this->files; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * returns sanitized contents of $_REQUEST |
|
160 | - * |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public function requestParams() |
|
164 | - { |
|
165 | - return $this->request_params->requestParams(); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param string $key |
|
171 | - * @param mixed|null $value |
|
172 | - * @param bool $override_ee |
|
173 | - * @return void |
|
174 | - */ |
|
175 | - public function setRequestParam($key, $value, $override_ee = false) |
|
176 | - { |
|
177 | - $this->request_params->setRequestParam($key, $value, $override_ee); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * merges the incoming array of parameters into the existing request parameters |
|
183 | - * |
|
184 | - * @param array $request_params |
|
185 | - * @return void |
|
186 | - * @since 4.10.24.p |
|
187 | - */ |
|
188 | - public function mergeRequestParams(array $request_params) |
|
189 | - { |
|
190 | - $this->request_params->mergeRequestParams($request_params); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * returns sanitized value for a request param if the given key exists |
|
196 | - * |
|
197 | - * @param string $key |
|
198 | - * @param mixed|null $default |
|
199 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
200 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
201 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
202 | - * @return array|bool|float|int|string |
|
203 | - */ |
|
204 | - public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
205 | - { |
|
206 | - return $this->request_params->getRequestParam($key, $default, $type, $is_array, $delimiter); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * check if param exists |
|
212 | - * |
|
213 | - * @param string $key |
|
214 | - * @return bool |
|
215 | - */ |
|
216 | - public function requestParamIsSet($key) |
|
217 | - { |
|
218 | - return $this->request_params->requestParamIsSet($key); |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
224 | - * and return the sanitized value for the first match found |
|
225 | - * wildcards can be either of the following: |
|
226 | - * ? to represent a single character of any type |
|
227 | - * * to represent one or more characters of any type |
|
228 | - * |
|
229 | - * @param string $pattern |
|
230 | - * @param mixed|null $default |
|
231 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
232 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
233 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
234 | - * @return array|bool|float|int|string |
|
235 | - */ |
|
236 | - public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
237 | - { |
|
238 | - return $this->request_params->getMatch($pattern, $default, $type, $is_array, $delimiter); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
244 | - * wildcards can be either of the following: |
|
245 | - * ? to represent a single character of any type |
|
246 | - * * to represent one or more characters of any type |
|
247 | - * returns true if a match is found or false if not |
|
248 | - * |
|
249 | - * @param string $pattern |
|
250 | - * @return bool |
|
251 | - */ |
|
252 | - public function matches($pattern) |
|
253 | - { |
|
254 | - return $this->request_params->matches($pattern); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * remove param |
|
260 | - * |
|
261 | - * @param $key |
|
262 | - * @param bool $unset_from_global_too |
|
263 | - */ |
|
264 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
265 | - { |
|
266 | - $this->request_params->unSetRequestParam($key, $unset_from_global_too); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * remove params |
|
272 | - * |
|
273 | - * @param array $keys |
|
274 | - * @param bool $unset_from_global_too |
|
275 | - */ |
|
276 | - public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
277 | - { |
|
278 | - $this->request_params->unSetRequestParams($keys, $unset_from_global_too); |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * @return string |
|
284 | - */ |
|
285 | - public function ipAddress() |
|
286 | - { |
|
287 | - return $this->server_params->ipAddress(); |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
293 | - * |
|
294 | - * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
295 | - * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
296 | - * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
297 | - * @return string |
|
298 | - */ |
|
299 | - public function requestUri($relativeToWpRoot = false) |
|
300 | - { |
|
301 | - return $this->server_params->requestUri(); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * @return string |
|
307 | - */ |
|
308 | - public function userAgent() |
|
309 | - { |
|
310 | - return $this->server_params->userAgent(); |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * @param string $user_agent |
|
316 | - */ |
|
317 | - public function setUserAgent($user_agent = '') |
|
318 | - { |
|
319 | - $this->server_params->setUserAgent($user_agent); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * @return bool |
|
325 | - */ |
|
326 | - public function isBot() |
|
327 | - { |
|
328 | - return $this->is_bot; |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * @param bool $is_bot |
|
334 | - */ |
|
335 | - public function setIsBot($is_bot) |
|
336 | - { |
|
337 | - $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * @return bool |
|
343 | - */ |
|
344 | - public function isActivation() |
|
345 | - { |
|
346 | - return $this->request_type->isActivation(); |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * @param $is_activation |
|
352 | - * @return bool |
|
353 | - */ |
|
354 | - public function setIsActivation($is_activation) |
|
355 | - { |
|
356 | - return $this->request_type->setIsActivation($is_activation); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * @return bool |
|
362 | - */ |
|
363 | - public function isAdmin() |
|
364 | - { |
|
365 | - return $this->request_type->isAdmin(); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * @return bool |
|
371 | - */ |
|
372 | - public function isAdminAjax() |
|
373 | - { |
|
374 | - return $this->request_type->isAdminAjax(); |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * @return bool |
|
380 | - */ |
|
381 | - public function isAjax() |
|
382 | - { |
|
383 | - return $this->request_type->isAjax(); |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * @return bool |
|
389 | - */ |
|
390 | - public function isEeAjax() |
|
391 | - { |
|
392 | - return $this->request_type->isEeAjax(); |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * @return bool |
|
398 | - */ |
|
399 | - public function isOtherAjax() |
|
400 | - { |
|
401 | - return $this->request_type->isOtherAjax(); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - public function isApi() |
|
409 | - { |
|
410 | - return $this->request_type->isApi(); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * @return bool |
|
416 | - */ |
|
417 | - public function isCli() |
|
418 | - { |
|
419 | - return $this->request_type->isCli(); |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * @return bool |
|
425 | - */ |
|
426 | - public function isCron() |
|
427 | - { |
|
428 | - return $this->request_type->isCron(); |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * @return bool |
|
434 | - */ |
|
435 | - public function isFeed() |
|
436 | - { |
|
437 | - return $this->request_type->isFeed(); |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * @return bool |
|
443 | - */ |
|
444 | - public function isFrontend() |
|
445 | - { |
|
446 | - return $this->request_type->isFrontend(); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * @return bool |
|
452 | - */ |
|
453 | - public function isFrontAjax() |
|
454 | - { |
|
455 | - return $this->request_type->isFrontAjax(); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * @return bool |
|
461 | - */ |
|
462 | - public function isIframe() |
|
463 | - { |
|
464 | - return $this->request_type->isIframe(); |
|
465 | - } |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * @return bool |
|
470 | - */ |
|
471 | - public function isWordPressApi() |
|
472 | - { |
|
473 | - return $this->request_type->isWordPressApi(); |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * @return bool |
|
479 | - */ |
|
480 | - public function isWordPressHeartbeat() |
|
481 | - { |
|
482 | - return $this->request_type->isWordPressHeartbeat(); |
|
483 | - } |
|
484 | - |
|
485 | - |
|
486 | - /** |
|
487 | - * @return bool |
|
488 | - */ |
|
489 | - public function isWordPressScrape() |
|
490 | - { |
|
491 | - return $this->request_type->isWordPressScrape(); |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * @return string |
|
497 | - */ |
|
498 | - public function slug() |
|
499 | - { |
|
500 | - return $this->request_type->slug(); |
|
501 | - } |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * @return RequestTypeContextCheckerInterface |
|
506 | - */ |
|
507 | - public function getRequestType() |
|
508 | - { |
|
509 | - return $this->request_type; |
|
510 | - } |
|
20 | + /** |
|
21 | + * $_COOKIE parameters |
|
22 | + * |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $cookies; |
|
26 | + |
|
27 | + /** |
|
28 | + * $_FILES parameters |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $files; |
|
33 | + |
|
34 | + /** |
|
35 | + * true if current user appears to be some kind of bot |
|
36 | + * |
|
37 | + * @var bool |
|
38 | + */ |
|
39 | + protected $is_bot; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var RequestParams |
|
43 | + */ |
|
44 | + protected $request_params; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var RequestTypeContextCheckerInterface |
|
48 | + */ |
|
49 | + protected $request_type; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var ServerParams |
|
53 | + */ |
|
54 | + protected $server_params; |
|
55 | + |
|
56 | + |
|
57 | + public function __construct( |
|
58 | + RequestParams $request_params, |
|
59 | + ServerParams $server_params, |
|
60 | + array $cookies = [], |
|
61 | + array $files = [] |
|
62 | + ) { |
|
63 | + $this->cookies = ! empty($cookies) |
|
64 | + ? $cookies |
|
65 | + : filter_input_array(INPUT_COOKIE, FILTER_SANITIZE_STRING); |
|
66 | + $this->files = ! empty($files) ? $files : $_FILES; |
|
67 | + $this->request_params = $request_params; |
|
68 | + $this->server_params = $server_params; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @param RequestTypeContextCheckerInterface $type |
|
74 | + */ |
|
75 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
76 | + { |
|
77 | + $this->request_type = $type; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public function getParams() |
|
85 | + { |
|
86 | + return $this->request_params->getParams(); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + public function postParams() |
|
94 | + { |
|
95 | + return $this->request_params->postParams(); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + public function cookieParams() |
|
103 | + { |
|
104 | + return $this->cookies; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + public function serverParams() |
|
112 | + { |
|
113 | + return $this->server_params->getAllServerParams(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $key |
|
119 | + * @param mixed|null $default |
|
120 | + * @return array|int|float|string |
|
121 | + */ |
|
122 | + public function getServerParam($key, $default = null) |
|
123 | + { |
|
124 | + return $this->server_params->getServerParam($key, $default); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @param string $key |
|
130 | + * @param array|int|float|string $value |
|
131 | + * @return void |
|
132 | + */ |
|
133 | + public function setServerParam($key, $value) |
|
134 | + { |
|
135 | + $this->server_params->setServerParam($key, $value); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $key |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + public function serverParamIsSet($key) |
|
144 | + { |
|
145 | + return $this->server_params->serverParamIsSet($key); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @return array |
|
151 | + */ |
|
152 | + public function filesParams() |
|
153 | + { |
|
154 | + return $this->files; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * returns sanitized contents of $_REQUEST |
|
160 | + * |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public function requestParams() |
|
164 | + { |
|
165 | + return $this->request_params->requestParams(); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param string $key |
|
171 | + * @param mixed|null $value |
|
172 | + * @param bool $override_ee |
|
173 | + * @return void |
|
174 | + */ |
|
175 | + public function setRequestParam($key, $value, $override_ee = false) |
|
176 | + { |
|
177 | + $this->request_params->setRequestParam($key, $value, $override_ee); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * merges the incoming array of parameters into the existing request parameters |
|
183 | + * |
|
184 | + * @param array $request_params |
|
185 | + * @return void |
|
186 | + * @since 4.10.24.p |
|
187 | + */ |
|
188 | + public function mergeRequestParams(array $request_params) |
|
189 | + { |
|
190 | + $this->request_params->mergeRequestParams($request_params); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * returns sanitized value for a request param if the given key exists |
|
196 | + * |
|
197 | + * @param string $key |
|
198 | + * @param mixed|null $default |
|
199 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
200 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
201 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
202 | + * @return array|bool|float|int|string |
|
203 | + */ |
|
204 | + public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
205 | + { |
|
206 | + return $this->request_params->getRequestParam($key, $default, $type, $is_array, $delimiter); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * check if param exists |
|
212 | + * |
|
213 | + * @param string $key |
|
214 | + * @return bool |
|
215 | + */ |
|
216 | + public function requestParamIsSet($key) |
|
217 | + { |
|
218 | + return $this->request_params->requestParamIsSet($key); |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
224 | + * and return the sanitized value for the first match found |
|
225 | + * wildcards can be either of the following: |
|
226 | + * ? to represent a single character of any type |
|
227 | + * * to represent one or more characters of any type |
|
228 | + * |
|
229 | + * @param string $pattern |
|
230 | + * @param mixed|null $default |
|
231 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
232 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
233 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
234 | + * @return array|bool|float|int|string |
|
235 | + */ |
|
236 | + public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
237 | + { |
|
238 | + return $this->request_params->getMatch($pattern, $default, $type, $is_array, $delimiter); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
244 | + * wildcards can be either of the following: |
|
245 | + * ? to represent a single character of any type |
|
246 | + * * to represent one or more characters of any type |
|
247 | + * returns true if a match is found or false if not |
|
248 | + * |
|
249 | + * @param string $pattern |
|
250 | + * @return bool |
|
251 | + */ |
|
252 | + public function matches($pattern) |
|
253 | + { |
|
254 | + return $this->request_params->matches($pattern); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * remove param |
|
260 | + * |
|
261 | + * @param $key |
|
262 | + * @param bool $unset_from_global_too |
|
263 | + */ |
|
264 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
265 | + { |
|
266 | + $this->request_params->unSetRequestParam($key, $unset_from_global_too); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * remove params |
|
272 | + * |
|
273 | + * @param array $keys |
|
274 | + * @param bool $unset_from_global_too |
|
275 | + */ |
|
276 | + public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
277 | + { |
|
278 | + $this->request_params->unSetRequestParams($keys, $unset_from_global_too); |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * @return string |
|
284 | + */ |
|
285 | + public function ipAddress() |
|
286 | + { |
|
287 | + return $this->server_params->ipAddress(); |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
293 | + * |
|
294 | + * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
295 | + * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
296 | + * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
297 | + * @return string |
|
298 | + */ |
|
299 | + public function requestUri($relativeToWpRoot = false) |
|
300 | + { |
|
301 | + return $this->server_params->requestUri(); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * @return string |
|
307 | + */ |
|
308 | + public function userAgent() |
|
309 | + { |
|
310 | + return $this->server_params->userAgent(); |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * @param string $user_agent |
|
316 | + */ |
|
317 | + public function setUserAgent($user_agent = '') |
|
318 | + { |
|
319 | + $this->server_params->setUserAgent($user_agent); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * @return bool |
|
325 | + */ |
|
326 | + public function isBot() |
|
327 | + { |
|
328 | + return $this->is_bot; |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * @param bool $is_bot |
|
334 | + */ |
|
335 | + public function setIsBot($is_bot) |
|
336 | + { |
|
337 | + $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * @return bool |
|
343 | + */ |
|
344 | + public function isActivation() |
|
345 | + { |
|
346 | + return $this->request_type->isActivation(); |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * @param $is_activation |
|
352 | + * @return bool |
|
353 | + */ |
|
354 | + public function setIsActivation($is_activation) |
|
355 | + { |
|
356 | + return $this->request_type->setIsActivation($is_activation); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * @return bool |
|
362 | + */ |
|
363 | + public function isAdmin() |
|
364 | + { |
|
365 | + return $this->request_type->isAdmin(); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * @return bool |
|
371 | + */ |
|
372 | + public function isAdminAjax() |
|
373 | + { |
|
374 | + return $this->request_type->isAdminAjax(); |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * @return bool |
|
380 | + */ |
|
381 | + public function isAjax() |
|
382 | + { |
|
383 | + return $this->request_type->isAjax(); |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * @return bool |
|
389 | + */ |
|
390 | + public function isEeAjax() |
|
391 | + { |
|
392 | + return $this->request_type->isEeAjax(); |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * @return bool |
|
398 | + */ |
|
399 | + public function isOtherAjax() |
|
400 | + { |
|
401 | + return $this->request_type->isOtherAjax(); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * @return bool |
|
407 | + */ |
|
408 | + public function isApi() |
|
409 | + { |
|
410 | + return $this->request_type->isApi(); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * @return bool |
|
416 | + */ |
|
417 | + public function isCli() |
|
418 | + { |
|
419 | + return $this->request_type->isCli(); |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * @return bool |
|
425 | + */ |
|
426 | + public function isCron() |
|
427 | + { |
|
428 | + return $this->request_type->isCron(); |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * @return bool |
|
434 | + */ |
|
435 | + public function isFeed() |
|
436 | + { |
|
437 | + return $this->request_type->isFeed(); |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * @return bool |
|
443 | + */ |
|
444 | + public function isFrontend() |
|
445 | + { |
|
446 | + return $this->request_type->isFrontend(); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * @return bool |
|
452 | + */ |
|
453 | + public function isFrontAjax() |
|
454 | + { |
|
455 | + return $this->request_type->isFrontAjax(); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * @return bool |
|
461 | + */ |
|
462 | + public function isIframe() |
|
463 | + { |
|
464 | + return $this->request_type->isIframe(); |
|
465 | + } |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * @return bool |
|
470 | + */ |
|
471 | + public function isWordPressApi() |
|
472 | + { |
|
473 | + return $this->request_type->isWordPressApi(); |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * @return bool |
|
479 | + */ |
|
480 | + public function isWordPressHeartbeat() |
|
481 | + { |
|
482 | + return $this->request_type->isWordPressHeartbeat(); |
|
483 | + } |
|
484 | + |
|
485 | + |
|
486 | + /** |
|
487 | + * @return bool |
|
488 | + */ |
|
489 | + public function isWordPressScrape() |
|
490 | + { |
|
491 | + return $this->request_type->isWordPressScrape(); |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * @return string |
|
497 | + */ |
|
498 | + public function slug() |
|
499 | + { |
|
500 | + return $this->request_type->slug(); |
|
501 | + } |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * @return RequestTypeContextCheckerInterface |
|
506 | + */ |
|
507 | + public function getRequestType() |
|
508 | + { |
|
509 | + return $this->request_type; |
|
510 | + } |
|
511 | 511 | } |
@@ -12,58 +12,58 @@ |
||
12 | 12 | */ |
13 | 13 | class DataType |
14 | 14 | { |
15 | - // can't use ARRAY as name until we switch to PHP 7+ |
|
16 | - // const ARRAY = 'array'; |
|
15 | + // can't use ARRAY as name until we switch to PHP 7+ |
|
16 | + // const ARRAY = 'array'; |
|
17 | 17 | |
18 | - const BOOL = 'bool'; |
|
19 | - const BOOLEAN = 'bool'; |
|
18 | + const BOOL = 'bool'; |
|
19 | + const BOOLEAN = 'bool'; |
|
20 | 20 | |
21 | - const DOUBLE = 'float'; |
|
22 | - const FLOAT = 'float'; |
|
21 | + const DOUBLE = 'float'; |
|
22 | + const FLOAT = 'float'; |
|
23 | 23 | |
24 | - const FQCN = 'fqcn'; |
|
24 | + const FQCN = 'fqcn'; |
|
25 | 25 | |
26 | - const HTML = 'html'; |
|
26 | + const HTML = 'html'; |
|
27 | 27 | |
28 | - const INT = 'int'; |
|
29 | - const INTEGER = 'int'; |
|
28 | + const INT = 'int'; |
|
29 | + const INTEGER = 'int'; |
|
30 | 30 | |
31 | - const KEY = 'key'; |
|
31 | + const KEY = 'key'; |
|
32 | 32 | |
33 | - const OBJECT = 'object'; |
|
33 | + const OBJECT = 'object'; |
|
34 | 34 | |
35 | - const NULL = 'null'; |
|
35 | + const NULL = 'null'; |
|
36 | 36 | |
37 | - const TITLE = 'title'; |
|
37 | + const TITLE = 'title'; |
|
38 | 38 | |
39 | - const URL = 'url'; |
|
39 | + const URL = 'url'; |
|
40 | 40 | |
41 | - const STRING = 'string'; |
|
41 | + const STRING = 'string'; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param mixed $param |
|
46 | - * @param string $type |
|
47 | - * @return mixed |
|
48 | - */ |
|
49 | - public static function setDataType($param, $type) |
|
50 | - { |
|
51 | - switch ($type) { |
|
52 | - case DataType::NULL: |
|
53 | - return null; |
|
54 | - case DataType::OBJECT: |
|
55 | - return $param; |
|
56 | - case DataType::FQCN: |
|
57 | - case DataType::HTML: |
|
58 | - case DataType::KEY: |
|
59 | - case DataType::STRING: |
|
60 | - case DataType::TITLE: |
|
61 | - case DataType::URL: |
|
62 | - settype($param, DataType::STRING); |
|
63 | - break; |
|
64 | - default: |
|
65 | - settype($param, $type); |
|
66 | - } |
|
67 | - return $param; |
|
68 | - } |
|
44 | + /** |
|
45 | + * @param mixed $param |
|
46 | + * @param string $type |
|
47 | + * @return mixed |
|
48 | + */ |
|
49 | + public static function setDataType($param, $type) |
|
50 | + { |
|
51 | + switch ($type) { |
|
52 | + case DataType::NULL: |
|
53 | + return null; |
|
54 | + case DataType::OBJECT: |
|
55 | + return $param; |
|
56 | + case DataType::FQCN: |
|
57 | + case DataType::HTML: |
|
58 | + case DataType::KEY: |
|
59 | + case DataType::STRING: |
|
60 | + case DataType::TITLE: |
|
61 | + case DataType::URL: |
|
62 | + settype($param, DataType::STRING); |
|
63 | + break; |
|
64 | + default: |
|
65 | + settype($param, $type); |
|
66 | + } |
|
67 | + return $param; |
|
68 | + } |
|
69 | 69 | } |
@@ -17,13 +17,13 @@ discard block |
||
17 | 17 | * Used for matches() and parameterDrillDown() |
18 | 18 | * 'bool' will return true or false if match is found or not |
19 | 19 | */ |
20 | - const RETURN_BOOL = 'bool'; |
|
20 | + const RETURN_BOOL = 'bool'; |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * Used for matches() and parameterDrillDown() |
24 | 24 | * 'key' will return the first key found that matches the supplied pattern |
25 | 25 | */ |
26 | - const RETURN_KEY = 'key'; |
|
26 | + const RETURN_KEY = 'key'; |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Used for matches() and parameterDrillDown() |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | { |
114 | 114 | // don't allow "ee" to be overwritten unless explicitly instructed to do so |
115 | 115 | if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) { |
116 | - $this->request[ $key ] = $value; |
|
116 | + $this->request[$key] = $value; |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | preg_quote($pattern, '/') |
238 | 238 | ); |
239 | 239 | foreach ($request_params as $key => $request_param) { |
240 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
240 | + if (preg_match('/^'.$pattern.'$/is', $key)) { |
|
241 | 241 | // return value for request param |
242 | 242 | if ($return === self::RETURN_VALUE) { |
243 | 243 | return $request_param; |
@@ -299,30 +299,30 @@ discard block |
||
299 | 299 | $key = $real_key ?: $key; |
300 | 300 | } |
301 | 301 | // check if top level key exists |
302 | - if (isset($request_params[ $key ])) { |
|
302 | + if (isset($request_params[$key])) { |
|
303 | 303 | // build a new key to pass along like: 'second[third]' |
304 | 304 | // or just 'second' depending on depth of keys |
305 | 305 | $key_string = array_shift($keys); |
306 | - if (! empty($keys)) { |
|
307 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
306 | + if ( ! empty($keys)) { |
|
307 | + $key_string .= '['.implode('][', $keys).']'; |
|
308 | 308 | } |
309 | 309 | return $this->parameterDrillDown( |
310 | 310 | $key_string, |
311 | 311 | $default, |
312 | 312 | $callback, |
313 | 313 | $return, |
314 | - $request_params[ $key ] |
|
314 | + $request_params[$key] |
|
315 | 315 | ); |
316 | 316 | } |
317 | 317 | } |
318 | 318 | if ($callback === 'is_set') { |
319 | - return isset($request_params[ $key ]); |
|
319 | + return isset($request_params[$key]); |
|
320 | 320 | } |
321 | 321 | if ($callback === 'match') { |
322 | 322 | return $this->match($key, $request_params, $default, $return); |
323 | 323 | } |
324 | - return isset($request_params[ $key ]) |
|
325 | - ? $request_params[ $key ] |
|
324 | + return isset($request_params[$key]) |
|
325 | + ? $request_params[$key] |
|
326 | 326 | : $default; |
327 | 327 | } |
328 | 328 | |
@@ -336,12 +336,12 @@ discard block |
||
336 | 336 | public function unSetRequestParam($key, $unset_from_global_too = false) |
337 | 337 | { |
338 | 338 | // because unset may not actually remove var |
339 | - $this->get[ $key ] = null; |
|
340 | - $this->post[ $key ] = null; |
|
341 | - $this->request[ $key ] = null; |
|
342 | - unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]); |
|
339 | + $this->get[$key] = null; |
|
340 | + $this->post[$key] = null; |
|
341 | + $this->request[$key] = null; |
|
342 | + unset($this->get[$key], $this->post[$key], $this->request[$key]); |
|
343 | 343 | if ($unset_from_global_too) { |
344 | - unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]); |
|
344 | + unset($_GET[$key], $_POST[$key], $_REQUEST[$key]); |
|
345 | 345 | } |
346 | 346 | } |
347 | 347 |
@@ -13,349 +13,349 @@ |
||
13 | 13 | */ |
14 | 14 | class RequestParams |
15 | 15 | { |
16 | - /** |
|
17 | - * Used for matches() and parameterDrillDown() |
|
18 | - * 'bool' will return true or false if match is found or not |
|
19 | - */ |
|
20 | - const RETURN_BOOL = 'bool'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Used for matches() and parameterDrillDown() |
|
24 | - * 'key' will return the first key found that matches the supplied pattern |
|
25 | - */ |
|
26 | - const RETURN_KEY = 'key'; |
|
27 | - |
|
28 | - /** |
|
29 | - * Used for matches() and parameterDrillDown() |
|
30 | - * 'value' will return the value for the first request parameter |
|
31 | - */ |
|
32 | - const RETURN_VALUE = 'value'; |
|
33 | - |
|
34 | - /** |
|
35 | - * $_GET parameters |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $get; |
|
40 | - |
|
41 | - /** |
|
42 | - * $_POST parameters |
|
43 | - * |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - protected $post; |
|
47 | - |
|
48 | - /** |
|
49 | - * $_REQUEST parameters |
|
50 | - * |
|
51 | - * @var array |
|
52 | - */ |
|
53 | - protected $request; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var RequestSanitizer |
|
57 | - */ |
|
58 | - protected $sanitizer; |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * RequestParams constructor. |
|
63 | - * |
|
64 | - * @param RequestSanitizer $sanitizer |
|
65 | - * @param array $get |
|
66 | - * @param array $post |
|
67 | - */ |
|
68 | - public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = []) |
|
69 | - { |
|
70 | - $this->sanitizer = $sanitizer; |
|
71 | - $this->get = ! empty($get) ? $get : $_GET; |
|
72 | - $this->post = ! empty($post) ? $post : $_POST; |
|
73 | - $this->request = array_merge($this->get, $this->post); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - public function getParams() |
|
81 | - { |
|
82 | - return $this->get; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - public function postParams() |
|
90 | - { |
|
91 | - return $this->post; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * returns contents of $_REQUEST |
|
97 | - * |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - public function requestParams() |
|
101 | - { |
|
102 | - return $this->request; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @param string $key |
|
108 | - * @param mixed|null $value |
|
109 | - * @param bool $override_ee |
|
110 | - * @return void |
|
111 | - */ |
|
112 | - public function setRequestParam($key, $value, $override_ee = false) |
|
113 | - { |
|
114 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
115 | - if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) { |
|
116 | - $this->request[ $key ] = $value; |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * merges the incoming array of parameters into the existing request parameters |
|
123 | - * |
|
124 | - * @param array $request_params |
|
125 | - * @return void |
|
126 | - * @since 4.10.24.p |
|
127 | - */ |
|
128 | - public function mergeRequestParams(array $request_params) |
|
129 | - { |
|
130 | - $this->request = array_merge($this->request, $request_params); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * returns the value for a request param if the given key exists |
|
136 | - * |
|
137 | - * @param string $key |
|
138 | - * @param mixed|null $default |
|
139 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
140 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
141 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
142 | - * @return array|bool|float|int|string |
|
143 | - */ |
|
144 | - public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
145 | - { |
|
146 | - $param = $this->sanitizer->clean( |
|
147 | - $this->parameterDrillDown($key, $default, 'get'), |
|
148 | - $type, |
|
149 | - $is_array, |
|
150 | - $delimiter |
|
151 | - ); |
|
152 | - $type = $is_array ? 'array' : $type; |
|
153 | - return DataType::setDataType($param, $type); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * check if param exists |
|
159 | - * |
|
160 | - * @param string $key |
|
161 | - * @return bool |
|
162 | - */ |
|
163 | - public function requestParamIsSet($key) |
|
164 | - { |
|
165 | - return (bool) $this->parameterDrillDown($key); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
171 | - * and return the value for the first match found |
|
172 | - * wildcards can be either of the following: |
|
173 | - * ? to represent a single character of any type |
|
174 | - * * to represent one or more characters of any type |
|
175 | - * |
|
176 | - * @param string $pattern |
|
177 | - * @param mixed|null $default |
|
178 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
179 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
180 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
181 | - * @return array|bool|float|int|string |
|
182 | - */ |
|
183 | - public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
184 | - { |
|
185 | - $param = $this->sanitizer->clean( |
|
186 | - $this->parameterDrillDown($pattern, $default, 'match'), |
|
187 | - $type, |
|
188 | - $is_array, |
|
189 | - $delimiter |
|
190 | - ); |
|
191 | - $type = $is_array ? 'array' : $type; |
|
192 | - return DataType::setDataType($param, $type); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
198 | - * wildcards can be either of the following: |
|
199 | - * ? to represent a single character of any type |
|
200 | - * * to represent one or more characters of any type |
|
201 | - * returns true if a match is found or false if not |
|
202 | - * |
|
203 | - * @param string $pattern |
|
204 | - * @return bool |
|
205 | - */ |
|
206 | - public function matches($pattern) |
|
207 | - { |
|
208 | - return (bool) $this->parameterDrillDown($pattern, false, 'match', self::RETURN_BOOL); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
214 | - * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
215 | - * and used to search through the current request's parameter keys |
|
216 | - * @param array $request_params The array of request parameters to search through |
|
217 | - * @param mixed $default [optional] The value to be returned if no match is found. |
|
218 | - * Default is null |
|
219 | - * @param string $return [optional] Controls what kind of value is returned. |
|
220 | - * Options are the RETURN_* constants: |
|
221 | - * RETURN_BOOL will return true or false if match is found or not |
|
222 | - * RETURN_KEY will return the first key found that matches the supplied pattern |
|
223 | - * RETURN_VALUE will return the value for the first request parameter |
|
224 | - * whose key matches the supplied pattern |
|
225 | - * Default is 'value' |
|
226 | - * @return boolean|string |
|
227 | - */ |
|
228 | - private function match($pattern, array $request_params, $default = null, $return = self::RETURN_VALUE) |
|
229 | - { |
|
230 | - $return = in_array($return, [self::RETURN_BOOL, self::RETURN_KEY, self::RETURN_VALUE], true) |
|
231 | - ? $return |
|
232 | - : 'is_set'; |
|
233 | - // replace wildcard chars with regex chars |
|
234 | - $pattern = str_replace( |
|
235 | - ['\*', '\?'], |
|
236 | - ['.*', '.'], |
|
237 | - preg_quote($pattern, '/') |
|
238 | - ); |
|
239 | - foreach ($request_params as $key => $request_param) { |
|
240 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
241 | - // return value for request param |
|
242 | - if ($return === self::RETURN_VALUE) { |
|
243 | - return $request_param; |
|
244 | - } |
|
245 | - // or actual key or true just to indicate it was found |
|
246 | - return $return === self::RETURN_KEY ? $key : true; |
|
247 | - } |
|
248 | - } |
|
249 | - // match not found so return default value or false |
|
250 | - return $return === self::RETURN_VALUE ? $default : false; |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * the supplied key can be a simple string to represent a "top-level" request parameter |
|
256 | - * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
257 | - * by using square brackets to surround keys for deeper array elements. |
|
258 | - * For example : |
|
259 | - * if the supplied $key was: "first[second][third]" |
|
260 | - * then this will attempt to drill down into the request parameter array to find a value. |
|
261 | - * Given the following request parameters: |
|
262 | - * array( |
|
263 | - * 'first' => array( |
|
264 | - * 'second' => array( |
|
265 | - * 'third' => 'has a value' |
|
266 | - * ) |
|
267 | - * ) |
|
268 | - * ) |
|
269 | - * would return true if default parameters were set |
|
270 | - * |
|
271 | - * @param string $callback |
|
272 | - * @param $key |
|
273 | - * @param null $default |
|
274 | - * @param string $return |
|
275 | - * @param mixed $request_params |
|
276 | - * @return bool|mixed|null |
|
277 | - */ |
|
278 | - private function parameterDrillDown( |
|
279 | - $key, |
|
280 | - $default = null, |
|
281 | - $callback = 'is_set', |
|
282 | - $return = self::RETURN_VALUE, |
|
283 | - $request_params = [] |
|
284 | - ) { |
|
285 | - $callback = in_array($callback, ['is_set', 'get', 'match'], true) |
|
286 | - ? $callback |
|
287 | - : 'is_set'; |
|
288 | - $request_params = ! empty($request_params) |
|
289 | - ? $request_params |
|
290 | - : $this->request; |
|
291 | - // does incoming key represent an array like 'first[second][third]' ? |
|
292 | - if (strpos($key, '[') !== false) { |
|
293 | - // turn it into an actual array |
|
294 | - $key = str_replace(']', '', $key); |
|
295 | - $keys = explode('[', $key); |
|
296 | - $key = array_shift($keys); |
|
297 | - if ($callback === 'match') { |
|
298 | - $real_key = $this->match($key, $request_params, $default, self::RETURN_KEY); |
|
299 | - $key = $real_key ?: $key; |
|
300 | - } |
|
301 | - // check if top level key exists |
|
302 | - if (isset($request_params[ $key ])) { |
|
303 | - // build a new key to pass along like: 'second[third]' |
|
304 | - // or just 'second' depending on depth of keys |
|
305 | - $key_string = array_shift($keys); |
|
306 | - if (! empty($keys)) { |
|
307 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
308 | - } |
|
309 | - return $this->parameterDrillDown( |
|
310 | - $key_string, |
|
311 | - $default, |
|
312 | - $callback, |
|
313 | - $return, |
|
314 | - $request_params[ $key ] |
|
315 | - ); |
|
316 | - } |
|
317 | - } |
|
318 | - if ($callback === 'is_set') { |
|
319 | - return isset($request_params[ $key ]); |
|
320 | - } |
|
321 | - if ($callback === 'match') { |
|
322 | - return $this->match($key, $request_params, $default, $return); |
|
323 | - } |
|
324 | - return isset($request_params[ $key ]) |
|
325 | - ? $request_params[ $key ] |
|
326 | - : $default; |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * remove param |
|
332 | - * |
|
333 | - * @param $key |
|
334 | - * @param bool $unset_from_global_too |
|
335 | - */ |
|
336 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
337 | - { |
|
338 | - // because unset may not actually remove var |
|
339 | - $this->get[ $key ] = null; |
|
340 | - $this->post[ $key ] = null; |
|
341 | - $this->request[ $key ] = null; |
|
342 | - unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]); |
|
343 | - if ($unset_from_global_too) { |
|
344 | - unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]); |
|
345 | - } |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * remove params |
|
351 | - * |
|
352 | - * @param array $keys |
|
353 | - * @param bool $unset_from_global_too |
|
354 | - */ |
|
355 | - public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
356 | - { |
|
357 | - foreach ($keys as $key) { |
|
358 | - $this->unSetRequestParam($key, $unset_from_global_too); |
|
359 | - } |
|
360 | - } |
|
16 | + /** |
|
17 | + * Used for matches() and parameterDrillDown() |
|
18 | + * 'bool' will return true or false if match is found or not |
|
19 | + */ |
|
20 | + const RETURN_BOOL = 'bool'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Used for matches() and parameterDrillDown() |
|
24 | + * 'key' will return the first key found that matches the supplied pattern |
|
25 | + */ |
|
26 | + const RETURN_KEY = 'key'; |
|
27 | + |
|
28 | + /** |
|
29 | + * Used for matches() and parameterDrillDown() |
|
30 | + * 'value' will return the value for the first request parameter |
|
31 | + */ |
|
32 | + const RETURN_VALUE = 'value'; |
|
33 | + |
|
34 | + /** |
|
35 | + * $_GET parameters |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $get; |
|
40 | + |
|
41 | + /** |
|
42 | + * $_POST parameters |
|
43 | + * |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $post; |
|
47 | + |
|
48 | + /** |
|
49 | + * $_REQUEST parameters |
|
50 | + * |
|
51 | + * @var array |
|
52 | + */ |
|
53 | + protected $request; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var RequestSanitizer |
|
57 | + */ |
|
58 | + protected $sanitizer; |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * RequestParams constructor. |
|
63 | + * |
|
64 | + * @param RequestSanitizer $sanitizer |
|
65 | + * @param array $get |
|
66 | + * @param array $post |
|
67 | + */ |
|
68 | + public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = []) |
|
69 | + { |
|
70 | + $this->sanitizer = $sanitizer; |
|
71 | + $this->get = ! empty($get) ? $get : $_GET; |
|
72 | + $this->post = ! empty($post) ? $post : $_POST; |
|
73 | + $this->request = array_merge($this->get, $this->post); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + public function getParams() |
|
81 | + { |
|
82 | + return $this->get; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + public function postParams() |
|
90 | + { |
|
91 | + return $this->post; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * returns contents of $_REQUEST |
|
97 | + * |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + public function requestParams() |
|
101 | + { |
|
102 | + return $this->request; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @param string $key |
|
108 | + * @param mixed|null $value |
|
109 | + * @param bool $override_ee |
|
110 | + * @return void |
|
111 | + */ |
|
112 | + public function setRequestParam($key, $value, $override_ee = false) |
|
113 | + { |
|
114 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
115 | + if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) { |
|
116 | + $this->request[ $key ] = $value; |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * merges the incoming array of parameters into the existing request parameters |
|
123 | + * |
|
124 | + * @param array $request_params |
|
125 | + * @return void |
|
126 | + * @since 4.10.24.p |
|
127 | + */ |
|
128 | + public function mergeRequestParams(array $request_params) |
|
129 | + { |
|
130 | + $this->request = array_merge($this->request, $request_params); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * returns the value for a request param if the given key exists |
|
136 | + * |
|
137 | + * @param string $key |
|
138 | + * @param mixed|null $default |
|
139 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
140 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
141 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
142 | + * @return array|bool|float|int|string |
|
143 | + */ |
|
144 | + public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
145 | + { |
|
146 | + $param = $this->sanitizer->clean( |
|
147 | + $this->parameterDrillDown($key, $default, 'get'), |
|
148 | + $type, |
|
149 | + $is_array, |
|
150 | + $delimiter |
|
151 | + ); |
|
152 | + $type = $is_array ? 'array' : $type; |
|
153 | + return DataType::setDataType($param, $type); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * check if param exists |
|
159 | + * |
|
160 | + * @param string $key |
|
161 | + * @return bool |
|
162 | + */ |
|
163 | + public function requestParamIsSet($key) |
|
164 | + { |
|
165 | + return (bool) $this->parameterDrillDown($key); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
171 | + * and return the value for the first match found |
|
172 | + * wildcards can be either of the following: |
|
173 | + * ? to represent a single character of any type |
|
174 | + * * to represent one or more characters of any type |
|
175 | + * |
|
176 | + * @param string $pattern |
|
177 | + * @param mixed|null $default |
|
178 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
179 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
180 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
181 | + * @return array|bool|float|int|string |
|
182 | + */ |
|
183 | + public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
184 | + { |
|
185 | + $param = $this->sanitizer->clean( |
|
186 | + $this->parameterDrillDown($pattern, $default, 'match'), |
|
187 | + $type, |
|
188 | + $is_array, |
|
189 | + $delimiter |
|
190 | + ); |
|
191 | + $type = $is_array ? 'array' : $type; |
|
192 | + return DataType::setDataType($param, $type); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
198 | + * wildcards can be either of the following: |
|
199 | + * ? to represent a single character of any type |
|
200 | + * * to represent one or more characters of any type |
|
201 | + * returns true if a match is found or false if not |
|
202 | + * |
|
203 | + * @param string $pattern |
|
204 | + * @return bool |
|
205 | + */ |
|
206 | + public function matches($pattern) |
|
207 | + { |
|
208 | + return (bool) $this->parameterDrillDown($pattern, false, 'match', self::RETURN_BOOL); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
214 | + * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
215 | + * and used to search through the current request's parameter keys |
|
216 | + * @param array $request_params The array of request parameters to search through |
|
217 | + * @param mixed $default [optional] The value to be returned if no match is found. |
|
218 | + * Default is null |
|
219 | + * @param string $return [optional] Controls what kind of value is returned. |
|
220 | + * Options are the RETURN_* constants: |
|
221 | + * RETURN_BOOL will return true or false if match is found or not |
|
222 | + * RETURN_KEY will return the first key found that matches the supplied pattern |
|
223 | + * RETURN_VALUE will return the value for the first request parameter |
|
224 | + * whose key matches the supplied pattern |
|
225 | + * Default is 'value' |
|
226 | + * @return boolean|string |
|
227 | + */ |
|
228 | + private function match($pattern, array $request_params, $default = null, $return = self::RETURN_VALUE) |
|
229 | + { |
|
230 | + $return = in_array($return, [self::RETURN_BOOL, self::RETURN_KEY, self::RETURN_VALUE], true) |
|
231 | + ? $return |
|
232 | + : 'is_set'; |
|
233 | + // replace wildcard chars with regex chars |
|
234 | + $pattern = str_replace( |
|
235 | + ['\*', '\?'], |
|
236 | + ['.*', '.'], |
|
237 | + preg_quote($pattern, '/') |
|
238 | + ); |
|
239 | + foreach ($request_params as $key => $request_param) { |
|
240 | + if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
241 | + // return value for request param |
|
242 | + if ($return === self::RETURN_VALUE) { |
|
243 | + return $request_param; |
|
244 | + } |
|
245 | + // or actual key or true just to indicate it was found |
|
246 | + return $return === self::RETURN_KEY ? $key : true; |
|
247 | + } |
|
248 | + } |
|
249 | + // match not found so return default value or false |
|
250 | + return $return === self::RETURN_VALUE ? $default : false; |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * the supplied key can be a simple string to represent a "top-level" request parameter |
|
256 | + * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
257 | + * by using square brackets to surround keys for deeper array elements. |
|
258 | + * For example : |
|
259 | + * if the supplied $key was: "first[second][third]" |
|
260 | + * then this will attempt to drill down into the request parameter array to find a value. |
|
261 | + * Given the following request parameters: |
|
262 | + * array( |
|
263 | + * 'first' => array( |
|
264 | + * 'second' => array( |
|
265 | + * 'third' => 'has a value' |
|
266 | + * ) |
|
267 | + * ) |
|
268 | + * ) |
|
269 | + * would return true if default parameters were set |
|
270 | + * |
|
271 | + * @param string $callback |
|
272 | + * @param $key |
|
273 | + * @param null $default |
|
274 | + * @param string $return |
|
275 | + * @param mixed $request_params |
|
276 | + * @return bool|mixed|null |
|
277 | + */ |
|
278 | + private function parameterDrillDown( |
|
279 | + $key, |
|
280 | + $default = null, |
|
281 | + $callback = 'is_set', |
|
282 | + $return = self::RETURN_VALUE, |
|
283 | + $request_params = [] |
|
284 | + ) { |
|
285 | + $callback = in_array($callback, ['is_set', 'get', 'match'], true) |
|
286 | + ? $callback |
|
287 | + : 'is_set'; |
|
288 | + $request_params = ! empty($request_params) |
|
289 | + ? $request_params |
|
290 | + : $this->request; |
|
291 | + // does incoming key represent an array like 'first[second][third]' ? |
|
292 | + if (strpos($key, '[') !== false) { |
|
293 | + // turn it into an actual array |
|
294 | + $key = str_replace(']', '', $key); |
|
295 | + $keys = explode('[', $key); |
|
296 | + $key = array_shift($keys); |
|
297 | + if ($callback === 'match') { |
|
298 | + $real_key = $this->match($key, $request_params, $default, self::RETURN_KEY); |
|
299 | + $key = $real_key ?: $key; |
|
300 | + } |
|
301 | + // check if top level key exists |
|
302 | + if (isset($request_params[ $key ])) { |
|
303 | + // build a new key to pass along like: 'second[third]' |
|
304 | + // or just 'second' depending on depth of keys |
|
305 | + $key_string = array_shift($keys); |
|
306 | + if (! empty($keys)) { |
|
307 | + $key_string .= '[' . implode('][', $keys) . ']'; |
|
308 | + } |
|
309 | + return $this->parameterDrillDown( |
|
310 | + $key_string, |
|
311 | + $default, |
|
312 | + $callback, |
|
313 | + $return, |
|
314 | + $request_params[ $key ] |
|
315 | + ); |
|
316 | + } |
|
317 | + } |
|
318 | + if ($callback === 'is_set') { |
|
319 | + return isset($request_params[ $key ]); |
|
320 | + } |
|
321 | + if ($callback === 'match') { |
|
322 | + return $this->match($key, $request_params, $default, $return); |
|
323 | + } |
|
324 | + return isset($request_params[ $key ]) |
|
325 | + ? $request_params[ $key ] |
|
326 | + : $default; |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * remove param |
|
332 | + * |
|
333 | + * @param $key |
|
334 | + * @param bool $unset_from_global_too |
|
335 | + */ |
|
336 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
337 | + { |
|
338 | + // because unset may not actually remove var |
|
339 | + $this->get[ $key ] = null; |
|
340 | + $this->post[ $key ] = null; |
|
341 | + $this->request[ $key ] = null; |
|
342 | + unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]); |
|
343 | + if ($unset_from_global_too) { |
|
344 | + unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]); |
|
345 | + } |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * remove params |
|
351 | + * |
|
352 | + * @param array $keys |
|
353 | + * @param bool $unset_from_global_too |
|
354 | + */ |
|
355 | + public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
356 | + { |
|
357 | + foreach ($keys as $key) { |
|
358 | + $this->unSetRequestParam($key, $unset_from_global_too); |
|
359 | + } |
|
360 | + } |
|
361 | 361 | } |
@@ -23,321 +23,321 @@ |
||
23 | 23 | */ |
24 | 24 | class CurrentPage |
25 | 25 | { |
26 | - /** |
|
27 | - * @var EE_CPT_Strategy |
|
28 | - */ |
|
29 | - private $cpt_strategy; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var bool |
|
33 | - */ |
|
34 | - private $initialized; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var bool |
|
38 | - */ |
|
39 | - private $is_espresso_page; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var int |
|
43 | - */ |
|
44 | - private $post_id = 0; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - private $post_name = ''; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var array |
|
53 | - */ |
|
54 | - private $post_type = []; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var RequestInterface $request |
|
58 | - */ |
|
59 | - private $request; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * CurrentPage constructor. |
|
64 | - * |
|
65 | - * @param EE_CPT_Strategy $cpt_strategy |
|
66 | - * @param RequestInterface $request |
|
67 | - */ |
|
68 | - public function __construct(EE_CPT_Strategy $cpt_strategy, RequestInterface $request) |
|
69 | - { |
|
70 | - $this->cpt_strategy = $cpt_strategy; |
|
71 | - $this->request = $request; |
|
72 | - $this->initialized = is_admin(); |
|
73 | - // analyse the incoming WP request |
|
74 | - add_action('parse_request', [$this, 'parseQueryVars'], 2, 1); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @param WP $WP |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public function parseQueryVars(WP $WP = null) |
|
83 | - { |
|
84 | - if ($this->initialized) { |
|
85 | - return; |
|
86 | - } |
|
87 | - // if somebody forgot to provide us with WP, that's ok because its global |
|
88 | - if (! $WP instanceof WP) { |
|
89 | - global $WP; |
|
90 | - } |
|
91 | - $this->post_id = $this->getPostId($WP); |
|
92 | - $this->post_name = $this->getPostName($WP); |
|
93 | - $this->post_type = $this->getPostType($WP); |
|
94 | - // true or false ? is this page being used by EE ? |
|
95 | - $this->setEspressoPage(); |
|
96 | - remove_action('parse_request', [$this, 'parseRequest'], 2); |
|
97 | - $this->initialized = true; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Just a helper method for getting the url for the displayed page. |
|
103 | - * |
|
104 | - * @param WP|null $WP |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function getPermalink(WP $WP = null) |
|
108 | - { |
|
109 | - $post_id = $this->post_id ?: $this->getPostId($WP); |
|
110 | - if ($post_id) { |
|
111 | - return get_permalink($post_id); |
|
112 | - } |
|
113 | - if (! $WP instanceof WP) { |
|
114 | - global $WP; |
|
115 | - } |
|
116 | - if ($WP instanceof WP && $WP->request) { |
|
117 | - return site_url($WP->request); |
|
118 | - } |
|
119 | - return esc_url_raw(site_url($_SERVER['REQUEST_URI'])); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - public function espressoPostType() |
|
127 | - { |
|
128 | - return array_filter( |
|
129 | - $this->post_type, |
|
130 | - function ($post_type) { |
|
131 | - return strpos($post_type, 'espresso_') === 0; |
|
132 | - } |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * pokes and prods the WP object query_vars in an attempt to shake out a page/post ID |
|
139 | - * |
|
140 | - * @param WP $WP |
|
141 | - * @return int |
|
142 | - */ |
|
143 | - private function getPostId(WP $WP = null) |
|
144 | - { |
|
145 | - $post_id = null; |
|
146 | - if ($WP instanceof WP) { |
|
147 | - // look for the post ID in the aptly named 'p' query var |
|
148 | - if (isset($WP->query_vars['p'])) { |
|
149 | - $post_id = $WP->query_vars['p']; |
|
150 | - } |
|
151 | - // not a post? what about a page? |
|
152 | - if (! $post_id && isset($WP->query_vars['page_id'])) { |
|
153 | - $post_id = $WP->query_vars['page_id']; |
|
154 | - } |
|
155 | - // ok... maybe pretty permalinks are off and the ID is set in the raw request... |
|
156 | - // but hasn't been processed yet ie: this method is being called too early :\ |
|
157 | - if (! $post_id && $WP->request !== null && is_numeric(basename($WP->request))) { |
|
158 | - $post_id = basename($WP->request); |
|
159 | - } |
|
160 | - } |
|
161 | - // none of the above? ok what about an explicit "post_id" URL parameter? |
|
162 | - if (! $post_id && $this->request->requestParamIsSet('post_id')) { |
|
163 | - $post_id = $this->request->getRequestParam('post_id'); |
|
164 | - } |
|
165 | - return $post_id; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * similar to getPostId() above but attempts to obtain the "name" for the current page/post |
|
171 | - * |
|
172 | - * @param WP $WP |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - private function getPostName(WP $WP = null) |
|
176 | - { |
|
177 | - global $wpdb; |
|
178 | - $post_name = null; |
|
179 | - if ($WP instanceof WP) { |
|
180 | - // if this is a post, then is the post name set? |
|
181 | - if (isset($WP->query_vars['name']) && ! empty($WP->query_vars['name'])) { |
|
182 | - $post_name = $WP->query_vars['name']; |
|
183 | - } |
|
184 | - // what about the page name? |
|
185 | - if (! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) { |
|
186 | - $post_name = $WP->query_vars['pagename']; |
|
187 | - } |
|
188 | - // this stinks but let's run a query to try and get the post name from the URL |
|
189 | - // (assuming pretty permalinks are on) |
|
190 | - if (! $post_name && ! empty($WP->request)) { |
|
191 | - $possible_post_name = basename($WP->request); |
|
192 | - if (! is_numeric($possible_post_name)) { |
|
193 | - $SQL = "SELECT ID from {$wpdb->posts}"; |
|
194 | - $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
195 | - $SQL .= ' AND post_name=%s'; |
|
196 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
197 | - if ($possible_post_name) { |
|
198 | - $post_name = $possible_post_name; |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - } |
|
203 | - // ug... ok... nothing yet... but do we have a post ID? |
|
204 | - // if so then... sigh... run a query to get the post name :\ |
|
205 | - if (! $post_name && $this->post_id) { |
|
206 | - $SQL = "SELECT post_name from {$wpdb->posts}"; |
|
207 | - $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
208 | - $SQL .= ' AND ID=%d'; |
|
209 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->post_id)); |
|
210 | - if ($possible_post_name) { |
|
211 | - $post_name = $possible_post_name; |
|
212 | - } |
|
213 | - } |
|
214 | - // still nothing? ok what about an explicit 'post_name' URL parameter? |
|
215 | - if (! $post_name && $this->request->requestParamIsSet('post_name')) { |
|
216 | - $post_name = $this->request->getRequestParam('post_name'); |
|
217 | - } |
|
218 | - return $post_name; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * also similar to getPostId() and getPostName() above but not as insane |
|
224 | - * |
|
225 | - * @param WP $WP |
|
226 | - * @return array |
|
227 | - */ |
|
228 | - private function getPostType(WP $WP = null) |
|
229 | - { |
|
230 | - $post_types = []; |
|
231 | - if ($WP instanceof WP) { |
|
232 | - $post_types = isset($WP->query_vars['post_type']) |
|
233 | - ? (array) $WP->query_vars['post_type'] |
|
234 | - : []; |
|
235 | - } |
|
236 | - if (empty($post_types) && $this->request->requestParamIsSet('post_type')) { |
|
237 | - $post_types = $this->request->getRequestParam('post_type', [], DataType::STRING, true); |
|
238 | - } |
|
239 | - return (array) $post_types; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * if TRUE, then the current page is somehow utilizing EE logic |
|
245 | - * |
|
246 | - * @return bool |
|
247 | - */ |
|
248 | - public function isEspressoPage() |
|
249 | - { |
|
250 | - if ($this->is_espresso_page === null) { |
|
251 | - $this->setEspressoPage(); |
|
252 | - } |
|
253 | - return $this->is_espresso_page; |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * @return int |
|
259 | - */ |
|
260 | - public function postId() |
|
261 | - { |
|
262 | - return $this->post_id; |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public function postName() |
|
270 | - { |
|
271 | - return $this->post_name; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @return array |
|
277 | - */ |
|
278 | - public function postType() |
|
279 | - { |
|
280 | - return $this->post_type; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * for manually indicating the current page will utilize EE logic |
|
286 | - * |
|
287 | - * @param null|bool $value |
|
288 | - * @return void |
|
289 | - */ |
|
290 | - public function setEspressoPage($value = null) |
|
291 | - { |
|
292 | - $this->is_espresso_page = $value !== null |
|
293 | - ? filter_var($value, FILTER_VALIDATE_BOOLEAN) |
|
294 | - : $this->testForEspressoPage(); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * attempts to determine if the current page/post is an EE related page/post |
|
300 | - * because it utilizes one of our CPT taxonomies, endpoints, or post types |
|
301 | - * |
|
302 | - * @return bool |
|
303 | - */ |
|
304 | - private function testForEspressoPage() |
|
305 | - { |
|
306 | - // in case it has already been set |
|
307 | - if ($this->is_espresso_page) { |
|
308 | - return true; |
|
309 | - } |
|
310 | - global $WP; |
|
311 | - $espresso_CPT_taxonomies = $this->cpt_strategy->get_CPT_taxonomies(); |
|
312 | - if (is_array($espresso_CPT_taxonomies)) { |
|
313 | - foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
314 | - if (isset($WP->query_vars, $WP->query_vars[ $espresso_CPT_taxonomy ])) { |
|
315 | - return true; |
|
316 | - } |
|
317 | - } |
|
318 | - } |
|
319 | - // load espresso CPT endpoints |
|
320 | - $espresso_CPT_endpoints = $this->cpt_strategy->get_CPT_endpoints(); |
|
321 | - $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
322 | - foreach ($this->post_type as $post_type) { |
|
323 | - // was a post name passed ? |
|
324 | - if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
325 | - // kk we know this is an espresso page, but is it a specific post ? |
|
326 | - if (! $this->post_name) { |
|
327 | - $espresso_post_type = $this->request->getRequestParam('post_type'); |
|
328 | - // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
329 | - // this essentially sets the post_name to "events" (or whatever EE CPT) |
|
330 | - $post_name = isset($post_type_CPT_endpoints[ $espresso_post_type ]) |
|
331 | - ? $post_type_CPT_endpoints[ $espresso_post_type ] |
|
332 | - : ''; |
|
333 | - // if the post type matches one of ours then set the post name to the endpoint |
|
334 | - if ($post_name) { |
|
335 | - $this->post_name = $post_name; |
|
336 | - } |
|
337 | - } |
|
338 | - return true; |
|
339 | - } |
|
340 | - } |
|
341 | - return false; |
|
342 | - } |
|
26 | + /** |
|
27 | + * @var EE_CPT_Strategy |
|
28 | + */ |
|
29 | + private $cpt_strategy; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var bool |
|
33 | + */ |
|
34 | + private $initialized; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var bool |
|
38 | + */ |
|
39 | + private $is_espresso_page; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var int |
|
43 | + */ |
|
44 | + private $post_id = 0; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + private $post_name = ''; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var array |
|
53 | + */ |
|
54 | + private $post_type = []; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var RequestInterface $request |
|
58 | + */ |
|
59 | + private $request; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * CurrentPage constructor. |
|
64 | + * |
|
65 | + * @param EE_CPT_Strategy $cpt_strategy |
|
66 | + * @param RequestInterface $request |
|
67 | + */ |
|
68 | + public function __construct(EE_CPT_Strategy $cpt_strategy, RequestInterface $request) |
|
69 | + { |
|
70 | + $this->cpt_strategy = $cpt_strategy; |
|
71 | + $this->request = $request; |
|
72 | + $this->initialized = is_admin(); |
|
73 | + // analyse the incoming WP request |
|
74 | + add_action('parse_request', [$this, 'parseQueryVars'], 2, 1); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @param WP $WP |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public function parseQueryVars(WP $WP = null) |
|
83 | + { |
|
84 | + if ($this->initialized) { |
|
85 | + return; |
|
86 | + } |
|
87 | + // if somebody forgot to provide us with WP, that's ok because its global |
|
88 | + if (! $WP instanceof WP) { |
|
89 | + global $WP; |
|
90 | + } |
|
91 | + $this->post_id = $this->getPostId($WP); |
|
92 | + $this->post_name = $this->getPostName($WP); |
|
93 | + $this->post_type = $this->getPostType($WP); |
|
94 | + // true or false ? is this page being used by EE ? |
|
95 | + $this->setEspressoPage(); |
|
96 | + remove_action('parse_request', [$this, 'parseRequest'], 2); |
|
97 | + $this->initialized = true; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Just a helper method for getting the url for the displayed page. |
|
103 | + * |
|
104 | + * @param WP|null $WP |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function getPermalink(WP $WP = null) |
|
108 | + { |
|
109 | + $post_id = $this->post_id ?: $this->getPostId($WP); |
|
110 | + if ($post_id) { |
|
111 | + return get_permalink($post_id); |
|
112 | + } |
|
113 | + if (! $WP instanceof WP) { |
|
114 | + global $WP; |
|
115 | + } |
|
116 | + if ($WP instanceof WP && $WP->request) { |
|
117 | + return site_url($WP->request); |
|
118 | + } |
|
119 | + return esc_url_raw(site_url($_SERVER['REQUEST_URI'])); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + public function espressoPostType() |
|
127 | + { |
|
128 | + return array_filter( |
|
129 | + $this->post_type, |
|
130 | + function ($post_type) { |
|
131 | + return strpos($post_type, 'espresso_') === 0; |
|
132 | + } |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * pokes and prods the WP object query_vars in an attempt to shake out a page/post ID |
|
139 | + * |
|
140 | + * @param WP $WP |
|
141 | + * @return int |
|
142 | + */ |
|
143 | + private function getPostId(WP $WP = null) |
|
144 | + { |
|
145 | + $post_id = null; |
|
146 | + if ($WP instanceof WP) { |
|
147 | + // look for the post ID in the aptly named 'p' query var |
|
148 | + if (isset($WP->query_vars['p'])) { |
|
149 | + $post_id = $WP->query_vars['p']; |
|
150 | + } |
|
151 | + // not a post? what about a page? |
|
152 | + if (! $post_id && isset($WP->query_vars['page_id'])) { |
|
153 | + $post_id = $WP->query_vars['page_id']; |
|
154 | + } |
|
155 | + // ok... maybe pretty permalinks are off and the ID is set in the raw request... |
|
156 | + // but hasn't been processed yet ie: this method is being called too early :\ |
|
157 | + if (! $post_id && $WP->request !== null && is_numeric(basename($WP->request))) { |
|
158 | + $post_id = basename($WP->request); |
|
159 | + } |
|
160 | + } |
|
161 | + // none of the above? ok what about an explicit "post_id" URL parameter? |
|
162 | + if (! $post_id && $this->request->requestParamIsSet('post_id')) { |
|
163 | + $post_id = $this->request->getRequestParam('post_id'); |
|
164 | + } |
|
165 | + return $post_id; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * similar to getPostId() above but attempts to obtain the "name" for the current page/post |
|
171 | + * |
|
172 | + * @param WP $WP |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + private function getPostName(WP $WP = null) |
|
176 | + { |
|
177 | + global $wpdb; |
|
178 | + $post_name = null; |
|
179 | + if ($WP instanceof WP) { |
|
180 | + // if this is a post, then is the post name set? |
|
181 | + if (isset($WP->query_vars['name']) && ! empty($WP->query_vars['name'])) { |
|
182 | + $post_name = $WP->query_vars['name']; |
|
183 | + } |
|
184 | + // what about the page name? |
|
185 | + if (! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) { |
|
186 | + $post_name = $WP->query_vars['pagename']; |
|
187 | + } |
|
188 | + // this stinks but let's run a query to try and get the post name from the URL |
|
189 | + // (assuming pretty permalinks are on) |
|
190 | + if (! $post_name && ! empty($WP->request)) { |
|
191 | + $possible_post_name = basename($WP->request); |
|
192 | + if (! is_numeric($possible_post_name)) { |
|
193 | + $SQL = "SELECT ID from {$wpdb->posts}"; |
|
194 | + $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
195 | + $SQL .= ' AND post_name=%s'; |
|
196 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
197 | + if ($possible_post_name) { |
|
198 | + $post_name = $possible_post_name; |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + } |
|
203 | + // ug... ok... nothing yet... but do we have a post ID? |
|
204 | + // if so then... sigh... run a query to get the post name :\ |
|
205 | + if (! $post_name && $this->post_id) { |
|
206 | + $SQL = "SELECT post_name from {$wpdb->posts}"; |
|
207 | + $SQL .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')"; |
|
208 | + $SQL .= ' AND ID=%d'; |
|
209 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->post_id)); |
|
210 | + if ($possible_post_name) { |
|
211 | + $post_name = $possible_post_name; |
|
212 | + } |
|
213 | + } |
|
214 | + // still nothing? ok what about an explicit 'post_name' URL parameter? |
|
215 | + if (! $post_name && $this->request->requestParamIsSet('post_name')) { |
|
216 | + $post_name = $this->request->getRequestParam('post_name'); |
|
217 | + } |
|
218 | + return $post_name; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * also similar to getPostId() and getPostName() above but not as insane |
|
224 | + * |
|
225 | + * @param WP $WP |
|
226 | + * @return array |
|
227 | + */ |
|
228 | + private function getPostType(WP $WP = null) |
|
229 | + { |
|
230 | + $post_types = []; |
|
231 | + if ($WP instanceof WP) { |
|
232 | + $post_types = isset($WP->query_vars['post_type']) |
|
233 | + ? (array) $WP->query_vars['post_type'] |
|
234 | + : []; |
|
235 | + } |
|
236 | + if (empty($post_types) && $this->request->requestParamIsSet('post_type')) { |
|
237 | + $post_types = $this->request->getRequestParam('post_type', [], DataType::STRING, true); |
|
238 | + } |
|
239 | + return (array) $post_types; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * if TRUE, then the current page is somehow utilizing EE logic |
|
245 | + * |
|
246 | + * @return bool |
|
247 | + */ |
|
248 | + public function isEspressoPage() |
|
249 | + { |
|
250 | + if ($this->is_espresso_page === null) { |
|
251 | + $this->setEspressoPage(); |
|
252 | + } |
|
253 | + return $this->is_espresso_page; |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * @return int |
|
259 | + */ |
|
260 | + public function postId() |
|
261 | + { |
|
262 | + return $this->post_id; |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public function postName() |
|
270 | + { |
|
271 | + return $this->post_name; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @return array |
|
277 | + */ |
|
278 | + public function postType() |
|
279 | + { |
|
280 | + return $this->post_type; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * for manually indicating the current page will utilize EE logic |
|
286 | + * |
|
287 | + * @param null|bool $value |
|
288 | + * @return void |
|
289 | + */ |
|
290 | + public function setEspressoPage($value = null) |
|
291 | + { |
|
292 | + $this->is_espresso_page = $value !== null |
|
293 | + ? filter_var($value, FILTER_VALIDATE_BOOLEAN) |
|
294 | + : $this->testForEspressoPage(); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * attempts to determine if the current page/post is an EE related page/post |
|
300 | + * because it utilizes one of our CPT taxonomies, endpoints, or post types |
|
301 | + * |
|
302 | + * @return bool |
|
303 | + */ |
|
304 | + private function testForEspressoPage() |
|
305 | + { |
|
306 | + // in case it has already been set |
|
307 | + if ($this->is_espresso_page) { |
|
308 | + return true; |
|
309 | + } |
|
310 | + global $WP; |
|
311 | + $espresso_CPT_taxonomies = $this->cpt_strategy->get_CPT_taxonomies(); |
|
312 | + if (is_array($espresso_CPT_taxonomies)) { |
|
313 | + foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
314 | + if (isset($WP->query_vars, $WP->query_vars[ $espresso_CPT_taxonomy ])) { |
|
315 | + return true; |
|
316 | + } |
|
317 | + } |
|
318 | + } |
|
319 | + // load espresso CPT endpoints |
|
320 | + $espresso_CPT_endpoints = $this->cpt_strategy->get_CPT_endpoints(); |
|
321 | + $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
322 | + foreach ($this->post_type as $post_type) { |
|
323 | + // was a post name passed ? |
|
324 | + if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
325 | + // kk we know this is an espresso page, but is it a specific post ? |
|
326 | + if (! $this->post_name) { |
|
327 | + $espresso_post_type = $this->request->getRequestParam('post_type'); |
|
328 | + // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
329 | + // this essentially sets the post_name to "events" (or whatever EE CPT) |
|
330 | + $post_name = isset($post_type_CPT_endpoints[ $espresso_post_type ]) |
|
331 | + ? $post_type_CPT_endpoints[ $espresso_post_type ] |
|
332 | + : ''; |
|
333 | + // if the post type matches one of ours then set the post name to the endpoint |
|
334 | + if ($post_name) { |
|
335 | + $this->post_name = $post_name; |
|
336 | + } |
|
337 | + } |
|
338 | + return true; |
|
339 | + } |
|
340 | + } |
|
341 | + return false; |
|
342 | + } |
|
343 | 343 | } |
@@ -13,221 +13,221 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays |
|
18 | - * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects |
|
19 | - * |
|
20 | - * @uses array_udiff core php function for setting up our own array comparison |
|
21 | - * @uses self::_compare_objects as the custom method for array_udiff |
|
22 | - * @param array $array1 an array of objects |
|
23 | - * @param array $array2 an array of objects |
|
24 | - * @return array an array of objects found in array 1 that aren't found in array 2. |
|
25 | - */ |
|
26 | - public static function object_array_diff($array1, $array2) |
|
27 | - { |
|
28 | - return array_udiff($array1, $array2, array('self', '_compare_objects')); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed |
|
33 | - * |
|
34 | - * @param array $array |
|
35 | - * @return boolean |
|
36 | - */ |
|
37 | - public static function is_associative_array(array $array) |
|
38 | - { |
|
39 | - return array_keys($array) !== range(0, count($array) - 1); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Gets an item from the array and leave the array intact. Use in place of end() |
|
44 | - * when you don't want to change the array |
|
45 | - * |
|
46 | - * @param array $arr |
|
47 | - * @return mixed what ever is in the array |
|
48 | - */ |
|
49 | - public static function get_one_item_from_array($arr) |
|
50 | - { |
|
51 | - $item = end($arr); |
|
52 | - reset($arr); |
|
53 | - return $item; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Detects if this is a multi-dimensional array |
|
58 | - * meaning that at least one top-level value is an array. Eg [ [], ...] |
|
59 | - * |
|
60 | - * @param mixed $arr |
|
61 | - * @return boolean |
|
62 | - */ |
|
63 | - public static function is_multi_dimensional_array($arr) |
|
64 | - { |
|
65 | - if (is_array($arr)) { |
|
66 | - foreach ($arr as $item) { |
|
67 | - if (is_array($item)) { |
|
68 | - return true; // yep, there's at least 2 levels to this array |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
72 | - return false; // there's only 1 level, or it's not an array at all! |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default |
|
77 | - * |
|
78 | - * @param array $arr |
|
79 | - * @param mixed $index |
|
80 | - * @param mixed $default |
|
81 | - * @return mixed |
|
82 | - */ |
|
83 | - public static function is_set($arr, $index, $default) |
|
84 | - { |
|
85 | - return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118 |
|
90 | - * |
|
91 | - * @param mixed $value usually a string, but could be an array or object |
|
92 | - * @return mixed the UN-serialized data |
|
93 | - */ |
|
94 | - public static function maybe_unserialize($value) |
|
95 | - { |
|
96 | - $data = maybe_unserialize($value); |
|
97 | - // it's possible that this still has serialized data if it's the session. |
|
98 | - // WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesn't unserialize this automatically. |
|
99 | - $token = 'C'; |
|
100 | - $data = is_string($data) ? trim($data) : $data; |
|
101 | - if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) { |
|
102 | - return unserialize($data); |
|
103 | - } else { |
|
104 | - return $data; |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * insert_into_array |
|
111 | - * |
|
112 | - * @param array $target_array the array to insert new data into |
|
113 | - * @param array $array_to_insert the new data to be inserted |
|
114 | - * @param int | string $offset a known key within $target_array where new data will be inserted |
|
115 | - * @param bool $add_before whether to add new data before or after the offset key |
|
116 | - * @param bool $preserve_keys whether or not to reset numerically indexed arrays |
|
117 | - * @return array |
|
118 | - */ |
|
119 | - public static function insert_into_array( |
|
120 | - $target_array = array(), |
|
121 | - $array_to_insert = array(), |
|
122 | - $offset = null, |
|
123 | - $add_before = true, |
|
124 | - $preserve_keys = true |
|
125 | - ) { |
|
126 | - // ensure incoming arrays are actually arrays |
|
127 | - $target_array = (array) $target_array; |
|
128 | - $array_to_insert = (array) $array_to_insert; |
|
129 | - // if no offset key was supplied |
|
130 | - if (empty($offset)) { |
|
131 | - // use start or end of $target_array based on whether we are adding before or not |
|
132 | - $offset = $add_before ? 0 : count($target_array); |
|
133 | - } |
|
134 | - // if offset key is a string, then find the corresponding numeric location for that element |
|
135 | - $offset = is_int($offset) ? $offset : array_search($offset, array_keys($target_array)); |
|
136 | - // add one to the offset if adding after |
|
137 | - $offset = $add_before ? $offset : $offset + 1; |
|
138 | - // but ensure offset does not exceed the length of the array |
|
139 | - $offset = $offset > count($target_array) ? count($target_array) : $offset; |
|
140 | - // reindex array ??? |
|
141 | - if ($preserve_keys) { |
|
142 | - // take a slice of the target array from the beginning till the offset, |
|
143 | - // then add the new data |
|
144 | - // then add another slice that starts at the offset and goes till the end |
|
145 | - return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice( |
|
146 | - $target_array, |
|
147 | - $offset, |
|
148 | - null, |
|
149 | - true |
|
150 | - ); |
|
151 | - } else { |
|
152 | - // since we don't want to preserve keys, we can use array_splice |
|
153 | - array_splice($target_array, $offset, 0, $array_to_insert); |
|
154 | - return $target_array; |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * array_merge() is slow and should never be used while looping over data |
|
161 | - * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster |
|
162 | - * so really this acts more like array_replace( $array1, $array2 ) |
|
163 | - * or a union with the arrays flipped ( $array2 + $array1 ) |
|
164 | - * this saves a few lines of code and improves readability |
|
165 | - * |
|
166 | - * @param array $array1 |
|
167 | - * @param array $array2 |
|
168 | - * @return array |
|
169 | - */ |
|
170 | - public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
|
171 | - { |
|
172 | - foreach ($array2 as $key => $value) { |
|
173 | - $array1[ $key ] = $value; |
|
174 | - } |
|
175 | - return $array1; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * given a flat array like $array = array('A', 'B', 'C') |
|
181 | - * will convert into a multidimensional array like $array[A][B][C] |
|
182 | - * if $final_value is provided and is anything other than null, |
|
183 | - * then that will be set as the value for the innermost array key |
|
184 | - * like so: $array[A][B][C] = $final_value |
|
185 | - * |
|
186 | - * @param array $flat_array |
|
187 | - * @param mixed $final_value |
|
188 | - * @return array |
|
189 | - */ |
|
190 | - public static function convert_array_values_to_keys(array $flat_array, $final_value = null) |
|
191 | - { |
|
192 | - $multidimensional = array(); |
|
193 | - $reference = &$multidimensional; |
|
194 | - foreach ($flat_array as $key) { |
|
195 | - $reference[ $key ] = array(); |
|
196 | - $reference = &$reference[ $key ]; |
|
197 | - } |
|
198 | - if ($final_value !== null) { |
|
199 | - $reference = $final_value; |
|
200 | - } |
|
201 | - return $multidimensional; |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
207 | - * @param array $array |
|
208 | - * @return bool |
|
209 | - */ |
|
210 | - public static function is_array_numerically_and_sequentially_indexed(array $array) |
|
211 | - { |
|
212 | - return empty($array) || array_keys($array) === range(0, count($array) - 1); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * recursively walks through an array and adds slashes to all no array elements |
|
218 | - * |
|
219 | - * @param mixed $element |
|
220 | - * @return array|string |
|
221 | - * @since $VID:$ |
|
222 | - */ |
|
223 | - public static function addSlashesRecursively($element) |
|
224 | - { |
|
225 | - if (is_array($element)) { |
|
226 | - foreach ($element as $key => $value) { |
|
227 | - $element[ $key ] = EEH_Array::addSlashesRecursively($value); |
|
228 | - } |
|
229 | - return $element; |
|
230 | - } |
|
231 | - return is_string($element) ? addslashes($element) : $element; |
|
232 | - } |
|
16 | + /** |
|
17 | + * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays |
|
18 | + * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects |
|
19 | + * |
|
20 | + * @uses array_udiff core php function for setting up our own array comparison |
|
21 | + * @uses self::_compare_objects as the custom method for array_udiff |
|
22 | + * @param array $array1 an array of objects |
|
23 | + * @param array $array2 an array of objects |
|
24 | + * @return array an array of objects found in array 1 that aren't found in array 2. |
|
25 | + */ |
|
26 | + public static function object_array_diff($array1, $array2) |
|
27 | + { |
|
28 | + return array_udiff($array1, $array2, array('self', '_compare_objects')); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed |
|
33 | + * |
|
34 | + * @param array $array |
|
35 | + * @return boolean |
|
36 | + */ |
|
37 | + public static function is_associative_array(array $array) |
|
38 | + { |
|
39 | + return array_keys($array) !== range(0, count($array) - 1); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Gets an item from the array and leave the array intact. Use in place of end() |
|
44 | + * when you don't want to change the array |
|
45 | + * |
|
46 | + * @param array $arr |
|
47 | + * @return mixed what ever is in the array |
|
48 | + */ |
|
49 | + public static function get_one_item_from_array($arr) |
|
50 | + { |
|
51 | + $item = end($arr); |
|
52 | + reset($arr); |
|
53 | + return $item; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Detects if this is a multi-dimensional array |
|
58 | + * meaning that at least one top-level value is an array. Eg [ [], ...] |
|
59 | + * |
|
60 | + * @param mixed $arr |
|
61 | + * @return boolean |
|
62 | + */ |
|
63 | + public static function is_multi_dimensional_array($arr) |
|
64 | + { |
|
65 | + if (is_array($arr)) { |
|
66 | + foreach ($arr as $item) { |
|
67 | + if (is_array($item)) { |
|
68 | + return true; // yep, there's at least 2 levels to this array |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | + return false; // there's only 1 level, or it's not an array at all! |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default |
|
77 | + * |
|
78 | + * @param array $arr |
|
79 | + * @param mixed $index |
|
80 | + * @param mixed $default |
|
81 | + * @return mixed |
|
82 | + */ |
|
83 | + public static function is_set($arr, $index, $default) |
|
84 | + { |
|
85 | + return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118 |
|
90 | + * |
|
91 | + * @param mixed $value usually a string, but could be an array or object |
|
92 | + * @return mixed the UN-serialized data |
|
93 | + */ |
|
94 | + public static function maybe_unserialize($value) |
|
95 | + { |
|
96 | + $data = maybe_unserialize($value); |
|
97 | + // it's possible that this still has serialized data if it's the session. |
|
98 | + // WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesn't unserialize this automatically. |
|
99 | + $token = 'C'; |
|
100 | + $data = is_string($data) ? trim($data) : $data; |
|
101 | + if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) { |
|
102 | + return unserialize($data); |
|
103 | + } else { |
|
104 | + return $data; |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * insert_into_array |
|
111 | + * |
|
112 | + * @param array $target_array the array to insert new data into |
|
113 | + * @param array $array_to_insert the new data to be inserted |
|
114 | + * @param int | string $offset a known key within $target_array where new data will be inserted |
|
115 | + * @param bool $add_before whether to add new data before or after the offset key |
|
116 | + * @param bool $preserve_keys whether or not to reset numerically indexed arrays |
|
117 | + * @return array |
|
118 | + */ |
|
119 | + public static function insert_into_array( |
|
120 | + $target_array = array(), |
|
121 | + $array_to_insert = array(), |
|
122 | + $offset = null, |
|
123 | + $add_before = true, |
|
124 | + $preserve_keys = true |
|
125 | + ) { |
|
126 | + // ensure incoming arrays are actually arrays |
|
127 | + $target_array = (array) $target_array; |
|
128 | + $array_to_insert = (array) $array_to_insert; |
|
129 | + // if no offset key was supplied |
|
130 | + if (empty($offset)) { |
|
131 | + // use start or end of $target_array based on whether we are adding before or not |
|
132 | + $offset = $add_before ? 0 : count($target_array); |
|
133 | + } |
|
134 | + // if offset key is a string, then find the corresponding numeric location for that element |
|
135 | + $offset = is_int($offset) ? $offset : array_search($offset, array_keys($target_array)); |
|
136 | + // add one to the offset if adding after |
|
137 | + $offset = $add_before ? $offset : $offset + 1; |
|
138 | + // but ensure offset does not exceed the length of the array |
|
139 | + $offset = $offset > count($target_array) ? count($target_array) : $offset; |
|
140 | + // reindex array ??? |
|
141 | + if ($preserve_keys) { |
|
142 | + // take a slice of the target array from the beginning till the offset, |
|
143 | + // then add the new data |
|
144 | + // then add another slice that starts at the offset and goes till the end |
|
145 | + return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice( |
|
146 | + $target_array, |
|
147 | + $offset, |
|
148 | + null, |
|
149 | + true |
|
150 | + ); |
|
151 | + } else { |
|
152 | + // since we don't want to preserve keys, we can use array_splice |
|
153 | + array_splice($target_array, $offset, 0, $array_to_insert); |
|
154 | + return $target_array; |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * array_merge() is slow and should never be used while looping over data |
|
161 | + * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster |
|
162 | + * so really this acts more like array_replace( $array1, $array2 ) |
|
163 | + * or a union with the arrays flipped ( $array2 + $array1 ) |
|
164 | + * this saves a few lines of code and improves readability |
|
165 | + * |
|
166 | + * @param array $array1 |
|
167 | + * @param array $array2 |
|
168 | + * @return array |
|
169 | + */ |
|
170 | + public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
|
171 | + { |
|
172 | + foreach ($array2 as $key => $value) { |
|
173 | + $array1[ $key ] = $value; |
|
174 | + } |
|
175 | + return $array1; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * given a flat array like $array = array('A', 'B', 'C') |
|
181 | + * will convert into a multidimensional array like $array[A][B][C] |
|
182 | + * if $final_value is provided and is anything other than null, |
|
183 | + * then that will be set as the value for the innermost array key |
|
184 | + * like so: $array[A][B][C] = $final_value |
|
185 | + * |
|
186 | + * @param array $flat_array |
|
187 | + * @param mixed $final_value |
|
188 | + * @return array |
|
189 | + */ |
|
190 | + public static function convert_array_values_to_keys(array $flat_array, $final_value = null) |
|
191 | + { |
|
192 | + $multidimensional = array(); |
|
193 | + $reference = &$multidimensional; |
|
194 | + foreach ($flat_array as $key) { |
|
195 | + $reference[ $key ] = array(); |
|
196 | + $reference = &$reference[ $key ]; |
|
197 | + } |
|
198 | + if ($final_value !== null) { |
|
199 | + $reference = $final_value; |
|
200 | + } |
|
201 | + return $multidimensional; |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
207 | + * @param array $array |
|
208 | + * @return bool |
|
209 | + */ |
|
210 | + public static function is_array_numerically_and_sequentially_indexed(array $array) |
|
211 | + { |
|
212 | + return empty($array) || array_keys($array) === range(0, count($array) - 1); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * recursively walks through an array and adds slashes to all no array elements |
|
218 | + * |
|
219 | + * @param mixed $element |
|
220 | + * @return array|string |
|
221 | + * @since $VID:$ |
|
222 | + */ |
|
223 | + public static function addSlashesRecursively($element) |
|
224 | + { |
|
225 | + if (is_array($element)) { |
|
226 | + foreach ($element as $key => $value) { |
|
227 | + $element[ $key ] = EEH_Array::addSlashesRecursively($value); |
|
228 | + } |
|
229 | + return $element; |
|
230 | + } |
|
231 | + return is_string($element) ? addslashes($element) : $element; |
|
232 | + } |
|
233 | 233 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public static function is_set($arr, $index, $default) |
84 | 84 | { |
85 | - return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
85 | + return isset($arr[$index]) ? $arr[$index] : $default; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
171 | 171 | { |
172 | 172 | foreach ($array2 as $key => $value) { |
173 | - $array1[ $key ] = $value; |
|
173 | + $array1[$key] = $value; |
|
174 | 174 | } |
175 | 175 | return $array1; |
176 | 176 | } |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | $multidimensional = array(); |
193 | 193 | $reference = &$multidimensional; |
194 | 194 | foreach ($flat_array as $key) { |
195 | - $reference[ $key ] = array(); |
|
196 | - $reference = &$reference[ $key ]; |
|
195 | + $reference[$key] = array(); |
|
196 | + $reference = &$reference[$key]; |
|
197 | 197 | } |
198 | 198 | if ($final_value !== null) { |
199 | 199 | $reference = $final_value; |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | { |
225 | 225 | if (is_array($element)) { |
226 | 226 | foreach ($element as $key => $value) { |
227 | - $element[ $key ] = EEH_Array::addSlashesRecursively($value); |
|
227 | + $element[$key] = EEH_Array::addSlashesRecursively($value); |
|
228 | 228 | } |
229 | 229 | return $element; |
230 | 230 | } |