@@ -37,138 +37,138 @@ |
||
37 | 37 | * @since 4.0 |
38 | 38 | */ |
39 | 39 | if (function_exists('espresso_version')) { |
40 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | - /** |
|
42 | - * espresso_duplicate_plugin_error |
|
43 | - * displays if more than one version of EE is activated at the same time. |
|
44 | - */ |
|
45 | - function espresso_duplicate_plugin_error() |
|
46 | - { |
|
47 | - ?> |
|
40 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | + /** |
|
42 | + * espresso_duplicate_plugin_error |
|
43 | + * displays if more than one version of EE is activated at the same time. |
|
44 | + */ |
|
45 | + function espresso_duplicate_plugin_error() |
|
46 | + { |
|
47 | + ?> |
|
48 | 48 | <div class="error"> |
49 | 49 | <p> |
50 | 50 | <?php |
51 | - echo esc_html__( |
|
52 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
53 | - 'event_espresso' |
|
54 | - ); ?> |
|
51 | + echo esc_html__( |
|
52 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
53 | + 'event_espresso' |
|
54 | + ); ?> |
|
55 | 55 | </p> |
56 | 56 | </div> |
57 | 57 | <?php |
58 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
59 | - } |
|
60 | - } |
|
61 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
58 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
59 | + } |
|
60 | + } |
|
61 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | 62 | } else { |
63 | - define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); |
|
64 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | - /** |
|
66 | - * espresso_minimum_php_version_error |
|
67 | - * |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - function espresso_minimum_php_version_error() |
|
71 | - { |
|
72 | - ?> |
|
63 | + define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); |
|
64 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | + /** |
|
66 | + * espresso_minimum_php_version_error |
|
67 | + * |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + function espresso_minimum_php_version_error() |
|
71 | + { |
|
72 | + ?> |
|
73 | 73 | <div class="error"> |
74 | 74 | <p> |
75 | 75 | <?php |
76 | - printf( |
|
77 | - esc_html__( |
|
78 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
79 | - 'event_espresso' |
|
80 | - ), |
|
81 | - EE_MIN_PHP_VER_REQUIRED, |
|
82 | - PHP_VERSION, |
|
83 | - '<br/>', |
|
84 | - '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>' |
|
85 | - ); |
|
86 | - ?> |
|
76 | + printf( |
|
77 | + esc_html__( |
|
78 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
79 | + 'event_espresso' |
|
80 | + ), |
|
81 | + EE_MIN_PHP_VER_REQUIRED, |
|
82 | + PHP_VERSION, |
|
83 | + '<br/>', |
|
84 | + '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>' |
|
85 | + ); |
|
86 | + ?> |
|
87 | 87 | </p> |
88 | 88 | </div> |
89 | 89 | <?php |
90 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
91 | - } |
|
90 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
91 | + } |
|
92 | 92 | |
93 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
94 | - } else { |
|
95 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
93 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
94 | + } else { |
|
95 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
96 | 96 | |
97 | - require_once __DIR__ . '/vendor/autoload.php'; |
|
97 | + require_once __DIR__ . '/vendor/autoload.php'; |
|
98 | 98 | |
99 | - /** |
|
100 | - * espresso_version |
|
101 | - * Returns the plugin version |
|
102 | - * |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - function espresso_version(): string |
|
106 | - { |
|
107 | - return apply_filters('FHEE__espresso__espresso_version', '5.0.36.rc.000'); |
|
108 | - } |
|
99 | + /** |
|
100 | + * espresso_version |
|
101 | + * Returns the plugin version |
|
102 | + * |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + function espresso_version(): string |
|
106 | + { |
|
107 | + return apply_filters('FHEE__espresso__espresso_version', '5.0.36.rc.000'); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * espresso_plugin_activation |
|
112 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
113 | - */ |
|
114 | - function espresso_plugin_activation() |
|
115 | - { |
|
116 | - update_option('ee_espresso_activation', true); |
|
117 | - update_option('event-espresso-core_allow_tracking', 'no'); |
|
118 | - update_option('event-espresso-core_tracking_notice', 'hide'); |
|
119 | - // Run WP GraphQL activation callback |
|
120 | - espressoLoadWpGraphQL(); |
|
121 | - graphql_activation_callback(); |
|
122 | - } |
|
110 | + /** |
|
111 | + * espresso_plugin_activation |
|
112 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
113 | + */ |
|
114 | + function espresso_plugin_activation() |
|
115 | + { |
|
116 | + update_option('ee_espresso_activation', true); |
|
117 | + update_option('event-espresso-core_allow_tracking', 'no'); |
|
118 | + update_option('event-espresso-core_tracking_notice', 'hide'); |
|
119 | + // Run WP GraphQL activation callback |
|
120 | + espressoLoadWpGraphQL(); |
|
121 | + graphql_activation_callback(); |
|
122 | + } |
|
123 | 123 | |
124 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
124 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
125 | 125 | |
126 | - /** |
|
127 | - * espresso_plugin_deactivation |
|
128 | - */ |
|
129 | - function espresso_plugin_deactivation() |
|
130 | - { |
|
131 | - // Run WP GraphQL deactivation callback |
|
132 | - espressoLoadWpGraphQL(); |
|
133 | - graphql_deactivation_callback(); |
|
134 | - delete_option('event-espresso-core_allow_tracking'); |
|
135 | - delete_option('event-espresso-core_tracking_notice'); |
|
136 | - } |
|
137 | - register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
126 | + /** |
|
127 | + * espresso_plugin_deactivation |
|
128 | + */ |
|
129 | + function espresso_plugin_deactivation() |
|
130 | + { |
|
131 | + // Run WP GraphQL deactivation callback |
|
132 | + espressoLoadWpGraphQL(); |
|
133 | + graphql_deactivation_callback(); |
|
134 | + delete_option('event-espresso-core_allow_tracking'); |
|
135 | + delete_option('event-espresso-core_tracking_notice'); |
|
136 | + } |
|
137 | + register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
138 | 138 | |
139 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
140 | - bootstrap_espresso(); |
|
141 | - } |
|
139 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
140 | + bootstrap_espresso(); |
|
141 | + } |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | if (! function_exists('espresso_deactivate_plugin')) { |
145 | - /** |
|
146 | - * deactivate_plugin |
|
147 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
148 | - * |
|
149 | - * @access public |
|
150 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
151 | - * @return void |
|
152 | - */ |
|
153 | - function espresso_deactivate_plugin(string $plugin_basename = '') |
|
154 | - { |
|
155 | - if (! function_exists('deactivate_plugins')) { |
|
156 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
157 | - } |
|
158 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
159 | - deactivate_plugins($plugin_basename); |
|
160 | - } |
|
145 | + /** |
|
146 | + * deactivate_plugin |
|
147 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
148 | + * |
|
149 | + * @access public |
|
150 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
151 | + * @return void |
|
152 | + */ |
|
153 | + function espresso_deactivate_plugin(string $plugin_basename = '') |
|
154 | + { |
|
155 | + if (! function_exists('deactivate_plugins')) { |
|
156 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
157 | + } |
|
158 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
159 | + deactivate_plugins($plugin_basename); |
|
160 | + } |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | |
164 | 164 | if (! function_exists('espressoLoadWpGraphQL')) { |
165 | - function espressoLoadWpGraphQL() |
|
166 | - { |
|
167 | - if ( |
|
168 | - ! class_exists('WPGraphQL') |
|
169 | - && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php') |
|
170 | - ) { |
|
171 | - require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php'; |
|
172 | - } |
|
173 | - } |
|
165 | + function espressoLoadWpGraphQL() |
|
166 | + { |
|
167 | + if ( |
|
168 | + ! class_exists('WPGraphQL') |
|
169 | + && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php') |
|
170 | + ) { |
|
171 | + require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php'; |
|
172 | + } |
|
173 | + } |
|
174 | 174 | } |
@@ -17,699 +17,699 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class Registration_Form_Admin_Page extends EE_Admin_Page |
19 | 19 | { |
20 | - /** |
|
21 | - * holds the specific question object for the question details screen |
|
22 | - */ |
|
23 | - protected ?EE_Question $_question = null; |
|
24 | - |
|
25 | - /** |
|
26 | - * holds the specific question group object for the question group details screen |
|
27 | - */ |
|
28 | - protected ?EE_Question_Group $_question_group = null; |
|
29 | - |
|
30 | - protected EEM_Question $_question_model; |
|
31 | - |
|
32 | - protected EEM_Question_Group $_question_group_model; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @Constructor |
|
37 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
38 | - * @throws EE_Error |
|
39 | - * @throws ReflectionException |
|
40 | - */ |
|
41 | - public function __construct($routing = true) |
|
42 | - { |
|
43 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
44 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
45 | - $this->_question_model = EEM_Question::instance(); |
|
46 | - $this->_question_group_model = EEM_Question_Group::instance(); |
|
47 | - parent::__construct($routing); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - protected function _init_page_props() |
|
52 | - { |
|
53 | - $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
54 | - $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
55 | - $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
56 | - $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - protected function _ajax_hooks() |
|
61 | - { |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - protected function _define_page_props() |
|
66 | - { |
|
67 | - $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
68 | - $this->_labels = [ |
|
69 | - 'buttons' => [ |
|
70 | - 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
71 | - ], |
|
72 | - 'publishbox' => [ |
|
73 | - 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
74 | - ], |
|
75 | - ]; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - *_set_page_routes |
|
81 | - */ |
|
82 | - protected function _set_page_routes() |
|
83 | - { |
|
84 | - $qst_id = |
|
85 | - ! empty($this->_req_data['QST_ID']) |
|
86 | - ? $this->_req_data['QST_ID'] |
|
87 | - : 0; |
|
88 | - $this->_page_routes = [ |
|
89 | - 'default' => [ |
|
90 | - 'func' => [$this, '_questions_overview_list_table'], |
|
91 | - 'capability' => 'ee_read_questions', |
|
92 | - ], |
|
93 | - |
|
94 | - 'edit_question' => [ |
|
95 | - 'func' => [$this, '_edit_question'], |
|
96 | - 'capability' => 'ee_edit_question', |
|
97 | - 'obj_id' => $qst_id, |
|
98 | - 'args' => ['edit'], |
|
99 | - ], |
|
100 | - |
|
101 | - 'question_groups' => [ |
|
102 | - 'func' => [$this, '_questions_groups_preview'], |
|
103 | - 'capability' => 'ee_read_question_groups', |
|
104 | - ], |
|
105 | - |
|
106 | - 'update_question' => [ |
|
107 | - 'func' => [$this, '_insert_or_update_question'], |
|
108 | - 'args' => ['new_question' => false], |
|
109 | - 'capability' => 'ee_edit_question', |
|
110 | - 'obj_id' => $qst_id, |
|
111 | - 'noheader' => true, |
|
112 | - ], |
|
113 | - ]; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - protected function _set_page_config() |
|
118 | - { |
|
119 | - $this->_page_config = [ |
|
120 | - 'default' => [ |
|
121 | - 'nav' => [ |
|
122 | - 'label' => esc_html__('Questions', 'event_espresso'), |
|
123 | - 'icon' => 'dashicons-editor-help', |
|
124 | - 'order' => 10, |
|
125 | - ], |
|
126 | - 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
127 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
128 | - 'help_tabs' => [ |
|
129 | - 'registration_form_questions_overview_help_tab' => [ |
|
130 | - 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
131 | - 'filename' => 'registration_form_questions_overview', |
|
132 | - ], |
|
133 | - 'registration_form_questions_overview_table_column_headings_help_tab' => [ |
|
134 | - 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
135 | - 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
136 | - ], |
|
137 | - 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => [ |
|
138 | - 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
139 | - 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
140 | - ], |
|
141 | - ], |
|
142 | - 'require_nonce' => false, |
|
143 | - ], |
|
144 | - |
|
145 | - 'question_groups' => [ |
|
146 | - 'nav' => [ |
|
147 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
148 | - 'icon' => 'dashicons-forms', |
|
149 | - 'order' => 20, |
|
150 | - ], |
|
151 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
152 | - 'help_tabs' => [ |
|
153 | - 'registration_form_question_groups_help_tab' => [ |
|
154 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
155 | - 'filename' => 'registration_form_question_groups', |
|
156 | - ], |
|
157 | - ], |
|
158 | - 'require_nonce' => false, |
|
159 | - ], |
|
160 | - |
|
161 | - 'edit_question' => [ |
|
162 | - 'nav' => [ |
|
163 | - 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
164 | - 'icon' => 'dashicons-edit-large', |
|
165 | - 'order' => 15, |
|
166 | - 'persistent' => false, |
|
167 | - 'url' => isset($this->_req_data['question_id']) |
|
168 | - ? add_query_arg( |
|
169 | - ['question_id' => $this->_req_data['question_id']], |
|
170 | - $this->_current_page_view_url |
|
171 | - ) |
|
172 | - : $this->_admin_base_url, |
|
173 | - ], |
|
174 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
175 | - 'help_tabs' => [ |
|
176 | - 'registration_form_edit_question_group_help_tab' => [ |
|
177 | - 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
178 | - 'filename' => 'registration_form_edit_question', |
|
179 | - ], |
|
180 | - ], |
|
181 | - 'require_nonce' => false, |
|
182 | - ], |
|
183 | - ]; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - protected function _add_screen_options() |
|
188 | - { |
|
189 | - // todo |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - protected function _add_screen_options_default() |
|
194 | - { |
|
195 | - $page_title = $this->_admin_page_title; |
|
196 | - $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
197 | - $this->_per_page_screen_option(); |
|
198 | - $this->_admin_page_title = $page_title; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - protected function _add_screen_options_question_groups() |
|
203 | - { |
|
204 | - $page_title = $this->_admin_page_title; |
|
205 | - $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
206 | - $this->_per_page_screen_option(); |
|
207 | - $this->_admin_page_title = $page_title; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - // none of the below group are currently used for Event Categories |
|
212 | - protected function _add_feature_pointers() |
|
213 | - { |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - public function load_scripts_styles() |
|
218 | - { |
|
219 | - wp_register_style( |
|
220 | - 'espresso_registration', |
|
221 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', |
|
222 | - [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN], |
|
223 | - EVENT_ESPRESSO_VERSION |
|
224 | - ); |
|
225 | - wp_enqueue_style('espresso_registration'); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - public function admin_init() |
|
230 | - { |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - public function admin_notices() |
|
235 | - { |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - public function admin_footer_scripts() |
|
240 | - { |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - public function load_scripts_styles_default() |
|
245 | - { |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - public function load_scripts_styles_add_question() |
|
250 | - { |
|
251 | - $this->load_scripts_styles_question_details(); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - public function load_scripts_styles_edit_question() |
|
256 | - { |
|
257 | - $this->load_scripts_styles_question_details(); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * Loads the JS required for adding or editing a question |
|
263 | - */ |
|
264 | - protected function load_scripts_styles_question_details() |
|
265 | - { |
|
266 | - $this->load_scripts_styles_forms(); |
|
267 | - wp_register_script( |
|
268 | - 'espresso_registration_form_single', |
|
269 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', |
|
270 | - ['jquery-ui-sortable'], |
|
271 | - EVENT_ESPRESSO_VERSION, |
|
272 | - true |
|
273 | - ); |
|
274 | - wp_enqueue_script('espresso_registration_form_single'); |
|
275 | - wp_localize_script( |
|
276 | - 'espresso_registration_form_single', |
|
277 | - 'ee_question_data', |
|
278 | - [ |
|
279 | - 'question_types_with_max' => $this->_question_model->questionTypesWithMaxLength(), |
|
280 | - 'question_type_with_options' => $this->_question_model->question_types_with_options(), |
|
281 | - ] |
|
282 | - ); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - public function recaptcha_info_help_tab() |
|
287 | - { |
|
288 | - EEH_Template::display_template(REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - public function load_scripts_styles_forms() |
|
293 | - { |
|
294 | - // styles |
|
295 | - wp_enqueue_style('espresso-ui-theme'); |
|
296 | - // scripts |
|
297 | - wp_enqueue_script('ee_admin_js'); |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - protected function _set_list_table_views_default() |
|
302 | - { |
|
303 | - $this->_views = [ |
|
304 | - 'all' => [ |
|
305 | - 'slug' => 'all', |
|
306 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
307 | - 'count' => 0, |
|
308 | - ], |
|
309 | - ]; |
|
310 | - |
|
311 | - if ( |
|
312 | - $this->capabilities->current_user_can( |
|
313 | - 'ee_delete_questions', |
|
314 | - 'espresso_registration_form_trash_questions' |
|
315 | - ) |
|
316 | - ) { |
|
317 | - $this->_views['trash'] = [ |
|
318 | - 'slug' => 'trash', |
|
319 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
320 | - 'count' => 0, |
|
321 | - ]; |
|
322 | - } |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * This just previews the question groups tab that comes in caffeinated. |
|
328 | - * |
|
329 | - * @return void html |
|
330 | - * @throws EE_Error |
|
331 | - */ |
|
332 | - protected function _questions_groups_preview() |
|
333 | - { |
|
334 | - $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
335 | - $this->_template_args['preview_img'] = |
|
336 | - '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' |
|
337 | - . esc_attr__( |
|
338 | - 'Preview Question Groups Overview List Table screenshot', |
|
339 | - 'event_espresso' |
|
340 | - ) . '" />'; |
|
341 | - $this->_template_args['preview_text'] = '<strong>' |
|
342 | - . esc_html__( |
|
343 | - 'Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
344 | - 'event_espresso' |
|
345 | - ) . '</strong>'; |
|
346 | - $this->display_admin_caf_preview_page('question_groups_tab'); |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * Extracts the question field's values from the POST request to update or insert them |
|
352 | - * |
|
353 | - * @param EEM_Base $model |
|
354 | - * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
355 | - * @throws EE_Error |
|
356 | - * @throws ReflectionException |
|
357 | - */ |
|
358 | - protected function _set_column_values_for(EEM_Base $model): array |
|
359 | - { |
|
360 | - $column_values = []; |
|
361 | - // some initial checks for proper values. |
|
362 | - $QST_ID = $this->request->getRequestParam('QST_ID', 0, DataType::INT); |
|
363 | - // if QST_admin_only, then no matter what QST_required is we disable. |
|
364 | - $QST_admin_only = $this->request->getRequestParam('QST_admin_only', false, DataType::BOOL); |
|
365 | - if ($QST_admin_only) { |
|
366 | - $this->request->setRequestParam('QST_required', false); |
|
367 | - } |
|
368 | - // if the question shouldn't have a max length, don't let them set one |
|
369 | - if ( |
|
370 | - ! ( |
|
371 | - $this->request->requestParamIsSet('QST_type') |
|
372 | - && $this->request->requestParamIsSet('QST_max') |
|
373 | - ) || ! in_array( |
|
374 | - $this->request->getRequestParam('QST_type', '', DataType::STRING), |
|
375 | - $this->_question_model->questionTypesWithMaxLength(), |
|
376 | - true |
|
377 | - ) |
|
378 | - ) { |
|
379 | - // they're not allowed to set the max |
|
380 | - $this->request->unSetRequestParam('QST_max', true); |
|
381 | - } |
|
382 | - foreach ($model->field_settings() as $fieldName => $settings) { |
|
383 | - switch($fieldName) { |
|
384 | - case 'QSG_identifier': |
|
385 | - // basically if QSG_identifier is empty or not set |
|
386 | - if (! $this->request->getRequestParam('QSG_identifier', '', DataType::STRING)) { |
|
387 | - $QSG_name = $this->request->getRequestParam('QSG_name', '', DataType::STRING); |
|
388 | - $column_values[ $fieldName ] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
389 | - } |
|
390 | - break; |
|
391 | - |
|
392 | - case 'QST_display_text': |
|
393 | - $column_values[ $fieldName ] = $this->request->getRequestParam('QST_display_text', '', DataType::HTML); |
|
394 | - break; |
|
395 | - |
|
396 | - case 'QST_admin_label': |
|
397 | - if (! $this->request->getRequestParam('QST_admin_label', '', DataType::STRING)) { |
|
398 | - // the admin label is blank, use a slug version of the question text |
|
399 | - $QST_text = $this->request->getRequestParam('QST_display_text', '', DataType::STRING); |
|
400 | - $column_values[ $fieldName ] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
401 | - } else { |
|
402 | - // admin label set, use it |
|
403 | - $column_values[ $fieldName ] = $this->request->getRequestParam('QST_admin_label', '', DataType::STRING); |
|
404 | - } |
|
405 | - break; |
|
406 | - |
|
407 | - case 'QST_admin_only': |
|
408 | - if (! $QST_admin_only) { |
|
409 | - $column_values[ $fieldName ] = false; |
|
410 | - } |
|
411 | - break; |
|
412 | - |
|
413 | - case 'QST_max': |
|
414 | - $qst_system = $this->_question_model->get_var( |
|
415 | - [ [ 'QST_ID' => $QST_ID ] ], |
|
416 | - 'QST_system' |
|
417 | - ); |
|
418 | - |
|
419 | - $max_max = $this->_question_model->absolute_max_for_system_question((string) $qst_system); |
|
420 | - $QST_max = $this->request->getRequestParam('QST_max', 0, DataType::INT); |
|
421 | - if ($QST_max === 0 || $QST_max > $max_max) { |
|
422 | - $column_values[ $fieldName ] = $max_max; |
|
423 | - } |
|
424 | - break; |
|
425 | - |
|
426 | - default: |
|
427 | - // only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
428 | - if ($this->request->requestParamIsSet($fieldName)) { |
|
429 | - // convert the schema type to the appropriate data type |
|
430 | - $schema_type = DataType::convertModelFieldSchemaType($settings->getSchemaType()); |
|
431 | - $column_values[ $fieldName ] = $this->request->getRequestParam($fieldName, null, $schema_type); |
|
432 | - } |
|
433 | - } |
|
434 | - } |
|
435 | - // validation for this data to be performed by the model before insertion. |
|
436 | - return $column_values; |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - *_questions_overview_list_table |
|
442 | - * |
|
443 | - * @throws EE_Error |
|
444 | - */ |
|
445 | - protected function _questions_overview_list_table() |
|
446 | - { |
|
447 | - $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
448 | - $this->display_admin_list_table_page_with_sidebar(); |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * _edit_question |
|
454 | - * |
|
455 | - * @throws EE_Error |
|
456 | - * @throws ReflectionException |
|
457 | - */ |
|
458 | - protected function _edit_question() |
|
459 | - { |
|
460 | - $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) |
|
461 | - ? absint($this->_req_data['QST_ID']) |
|
462 | - : false; |
|
463 | - |
|
464 | - switch ($this->_req_action) { |
|
465 | - case 'add_question': |
|
466 | - $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
467 | - break; |
|
468 | - case 'edit_question': |
|
469 | - $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
470 | - break; |
|
471 | - default: |
|
472 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
473 | - } |
|
474 | - |
|
475 | - // add PRC_ID to title if editing |
|
476 | - $this->_admin_page_title = |
|
477 | - $ID |
|
478 | - ? $this->_admin_page_title . ' # ' . $ID |
|
479 | - : $this->_admin_page_title; |
|
480 | - if ($ID) { |
|
481 | - $question = $this->_question_model->get_one_by_ID($ID); |
|
482 | - $additional_hidden_fields = ['QST_ID' => ['type' => 'hidden', 'value' => $ID]]; |
|
483 | - $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
484 | - } else { |
|
485 | - $question = EE_Question::new_instance(); |
|
486 | - $question->set_order_to_latest(); |
|
487 | - $this->_set_add_edit_form_tags('insert_question'); |
|
488 | - } |
|
489 | - if ($question->system_ID() === EEM_Attendee::system_question_phone) { |
|
490 | - $question_types = array_intersect_key( |
|
491 | - $this->_question_model->allowed_question_types(), |
|
492 | - array_flip( |
|
493 | - [ |
|
494 | - EEM_Question::QST_type_text, |
|
495 | - EEM_Question::QST_type_us_phone, |
|
496 | - ] |
|
497 | - ) |
|
498 | - ); |
|
499 | - } else { |
|
500 | - $question_types = $question->has_answers() |
|
501 | - ? $this->_question_model->question_types_in_same_category($question->type()) |
|
502 | - : $this->_question_model->allowed_question_types(); |
|
503 | - } |
|
504 | - $this->_template_args['QST_ID'] = $ID; |
|
505 | - $this->_template_args['question'] = $question; |
|
506 | - $this->_template_args['question_types'] = $question_types; |
|
507 | - $this->_template_args['max_max'] = |
|
508 | - $this->_question_model->absolute_max_for_system_question( |
|
509 | - $question->system_ID() |
|
510 | - ); |
|
511 | - $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
512 | - $this->_set_publish_post_box_vars('id', $ID); |
|
513 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
514 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
515 | - $this->_template_args, |
|
516 | - true |
|
517 | - ); |
|
518 | - |
|
519 | - // the details template wrapper |
|
520 | - $this->display_admin_page_with_sidebar(); |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * @return string |
|
526 | - * @throws EE_Error |
|
527 | - * @throws ReflectionException |
|
528 | - */ |
|
529 | - protected function _get_question_type_descriptions(): string |
|
530 | - { |
|
531 | - EE_Registry::instance()->load_helper('HTML'); |
|
532 | - $descriptions = ''; |
|
533 | - $question_type_descriptions = $this->_question_model->question_descriptions(); |
|
534 | - foreach ($question_type_descriptions as $type => $question_type_description) { |
|
535 | - if ($type == 'HTML_TEXTAREA') { |
|
536 | - $html = new EE_Simple_HTML_Validation_Strategy(); |
|
537 | - $question_type_description .= sprintf( |
|
538 | - esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
539 | - '<br/>', |
|
540 | - $html->get_list_of_allowed_tags() |
|
541 | - ); |
|
542 | - } |
|
543 | - $descriptions .= EEH_HTML::p( |
|
544 | - $question_type_description, |
|
545 | - 'question_type_description-' . $type, |
|
546 | - 'question_type_description description', |
|
547 | - 'display:none;' |
|
548 | - ); |
|
549 | - } |
|
550 | - return $descriptions; |
|
551 | - } |
|
552 | - |
|
553 | - |
|
554 | - /** |
|
555 | - * @param bool $new_question |
|
556 | - * @throws EE_Error |
|
557 | - * @throws ReflectionException |
|
558 | - */ |
|
559 | - protected function _insert_or_update_question(bool $new_question = true) |
|
560 | - { |
|
561 | - $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
562 | - if ($new_question) { |
|
563 | - $question = EE_Question::new_instance($set_column_values); |
|
564 | - $action_desc = 'added'; |
|
565 | - } else { |
|
566 | - $question = $this->_question_model->get_one_by_ID( |
|
567 | - $this->request->getRequestParam('QST_ID', 0, DataType::INT) |
|
568 | - ); |
|
569 | - foreach ($set_column_values as $field => $new_value) { |
|
570 | - $question->set($field, $new_value); |
|
571 | - } |
|
572 | - $action_desc = 'updated'; |
|
573 | - } |
|
574 | - $success = $question->save(); |
|
575 | - $ID = $question->ID(); |
|
576 | - if ($ID && $question->should_have_question_options()) { |
|
577 | - // save the related options |
|
578 | - // trash removed options, save old ones |
|
579 | - // get list of all options |
|
580 | - $options = $question->options(); |
|
581 | - $question_options = $this->request->getRequestParam('question_options', [], DataType::HTML, true); |
|
582 | - $QSO_default = $this->request->getRequestParam('QSO_default', null, DataType::INT); |
|
583 | - if (! empty($options)) { |
|
584 | - foreach ($options as $option_ID => $option) { |
|
585 | - $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
586 | - if ($option_req_index !== false) { |
|
587 | - $question_options[ $option_req_index ]['QSO_default'] = $option_req_index === $QSO_default; |
|
588 | - $option->save($question_options[ $option_req_index ]); |
|
589 | - } else { |
|
590 | - // not found, remove it |
|
591 | - $option->delete(); |
|
592 | - } |
|
593 | - } |
|
594 | - } |
|
595 | - // save new related options |
|
596 | - foreach ($question_options as $index => $option_req_data) { |
|
597 | - // skip $index that is from our sample |
|
598 | - if ($index === 'xxcountxx') { |
|
599 | - continue; |
|
600 | - } |
|
601 | - // note we allow saving blank options. |
|
602 | - if (empty($option_req_data['QSO_ID'])) { |
|
603 | - // no ID! save it! |
|
604 | - $new_option = EE_Question_Option::new_instance( |
|
605 | - [ |
|
606 | - 'QSO_value' => $option_req_data['QSO_value'], |
|
607 | - 'QSO_desc' => $option_req_data['QSO_desc'], |
|
608 | - 'QSO_default' => $index === $QSO_default, |
|
609 | - 'QSO_order' => $option_req_data['QSO_order'], |
|
610 | - 'QST_ID' => $question->ID(), |
|
611 | - ] |
|
612 | - ); |
|
613 | - $new_option->save(); |
|
614 | - } |
|
615 | - } |
|
616 | - } |
|
617 | - |
|
618 | - $success = apply_filters( |
|
619 | - 'FHEE__Registration_Form_Admin_Page___insert_or_update_question__success', |
|
620 | - (int) $success, |
|
621 | - $question, |
|
622 | - $this |
|
623 | - ); |
|
624 | - |
|
625 | - $query_args = ['action' => 'edit_question', 'QST_ID' => $ID]; |
|
626 | - if ($success !== 0) { |
|
627 | - $msg = $new_question |
|
628 | - ? sprintf( |
|
629 | - esc_html__('The %s has been created', 'event_espresso'), |
|
630 | - $this->_question_model->item_name() |
|
631 | - ) |
|
632 | - : sprintf( |
|
633 | - esc_html__('The %s has been updated', 'event_espresso'), |
|
634 | - $this->_question_model->item_name() |
|
635 | - ); |
|
636 | - EE_Error::add_success($msg); |
|
637 | - } |
|
638 | - |
|
639 | - $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - /** |
|
644 | - * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
645 | - * by ID |
|
646 | - * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
647 | - * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
648 | - * |
|
649 | - * @param int $ID of the question option to find |
|
650 | - * @return int index in question_options array if successful, FALSE if unsuccessful |
|
651 | - */ |
|
652 | - protected function _get_option_req_data_index(int $ID) |
|
653 | - { |
|
654 | - $req_data_for_question_options = $this->_req_data['question_options']; |
|
655 | - foreach ($req_data_for_question_options as $num => $option_data) { |
|
656 | - if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) { |
|
657 | - return $num; |
|
658 | - } |
|
659 | - } |
|
660 | - return false; |
|
661 | - } |
|
662 | - |
|
663 | - |
|
664 | - |
|
665 | - |
|
666 | - /* QUERIES */ |
|
667 | - /** |
|
668 | - * For internal use in getting all the query parameters |
|
669 | - * (because it's pretty well the same between question, question groups, |
|
670 | - * and for both when searching for trashed and untrashed ones) |
|
671 | - * |
|
672 | - * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
673 | - * @param int $per_page |
|
674 | - * @param int $current_page |
|
675 | - * @return array model query params, |
|
676 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
677 | - */ |
|
678 | - protected function get_query_params(EEM_Base $model, int $per_page = 10, int $current_page = 10): array |
|
679 | - { |
|
680 | - $query_params = []; |
|
681 | - $offset = ($current_page - 1) * $per_page; |
|
682 | - $query_params['limit'] = [$offset, $per_page]; |
|
683 | - |
|
684 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
685 | - ? $this->_req_data['order'] |
|
686 | - : 'ASC'; |
|
687 | - |
|
688 | - $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
689 | - |
|
690 | - $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
691 | - |
|
692 | - $query_params['order_by'] = [$field_to_order_by => $order]; |
|
693 | - |
|
694 | - $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
695 | - if (! empty($search_string)) { |
|
696 | - if ($model instanceof EEM_Question_Group) { |
|
697 | - $query_params[0] = [ |
|
698 | - 'OR' => [ |
|
699 | - 'QSG_name' => ['LIKE', "%$search_string%"], |
|
700 | - 'QSG_desc' => ['LIKE', "%$search_string%"], |
|
701 | - ], |
|
702 | - ]; |
|
703 | - } else { |
|
704 | - $query_params[0] = [ |
|
705 | - 'QST_display_text' => ['LIKE', "%$search_string%"], |
|
706 | - ]; |
|
707 | - } |
|
708 | - } |
|
709 | - |
|
710 | - // capability checks (just leaving this commented out for reference because |
|
711 | - // it illustrates some complicated query params that could be useful when fully implemented) |
|
712 | - /*if ( $model instanceof EEM_Question_Group ) { |
|
20 | + /** |
|
21 | + * holds the specific question object for the question details screen |
|
22 | + */ |
|
23 | + protected ?EE_Question $_question = null; |
|
24 | + |
|
25 | + /** |
|
26 | + * holds the specific question group object for the question group details screen |
|
27 | + */ |
|
28 | + protected ?EE_Question_Group $_question_group = null; |
|
29 | + |
|
30 | + protected EEM_Question $_question_model; |
|
31 | + |
|
32 | + protected EEM_Question_Group $_question_group_model; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @Constructor |
|
37 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
38 | + * @throws EE_Error |
|
39 | + * @throws ReflectionException |
|
40 | + */ |
|
41 | + public function __construct($routing = true) |
|
42 | + { |
|
43 | + require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
44 | + require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
45 | + $this->_question_model = EEM_Question::instance(); |
|
46 | + $this->_question_group_model = EEM_Question_Group::instance(); |
|
47 | + parent::__construct($routing); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + protected function _init_page_props() |
|
52 | + { |
|
53 | + $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
54 | + $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
55 | + $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
56 | + $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + protected function _ajax_hooks() |
|
61 | + { |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + protected function _define_page_props() |
|
66 | + { |
|
67 | + $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
68 | + $this->_labels = [ |
|
69 | + 'buttons' => [ |
|
70 | + 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
71 | + ], |
|
72 | + 'publishbox' => [ |
|
73 | + 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
74 | + ], |
|
75 | + ]; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + *_set_page_routes |
|
81 | + */ |
|
82 | + protected function _set_page_routes() |
|
83 | + { |
|
84 | + $qst_id = |
|
85 | + ! empty($this->_req_data['QST_ID']) |
|
86 | + ? $this->_req_data['QST_ID'] |
|
87 | + : 0; |
|
88 | + $this->_page_routes = [ |
|
89 | + 'default' => [ |
|
90 | + 'func' => [$this, '_questions_overview_list_table'], |
|
91 | + 'capability' => 'ee_read_questions', |
|
92 | + ], |
|
93 | + |
|
94 | + 'edit_question' => [ |
|
95 | + 'func' => [$this, '_edit_question'], |
|
96 | + 'capability' => 'ee_edit_question', |
|
97 | + 'obj_id' => $qst_id, |
|
98 | + 'args' => ['edit'], |
|
99 | + ], |
|
100 | + |
|
101 | + 'question_groups' => [ |
|
102 | + 'func' => [$this, '_questions_groups_preview'], |
|
103 | + 'capability' => 'ee_read_question_groups', |
|
104 | + ], |
|
105 | + |
|
106 | + 'update_question' => [ |
|
107 | + 'func' => [$this, '_insert_or_update_question'], |
|
108 | + 'args' => ['new_question' => false], |
|
109 | + 'capability' => 'ee_edit_question', |
|
110 | + 'obj_id' => $qst_id, |
|
111 | + 'noheader' => true, |
|
112 | + ], |
|
113 | + ]; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + protected function _set_page_config() |
|
118 | + { |
|
119 | + $this->_page_config = [ |
|
120 | + 'default' => [ |
|
121 | + 'nav' => [ |
|
122 | + 'label' => esc_html__('Questions', 'event_espresso'), |
|
123 | + 'icon' => 'dashicons-editor-help', |
|
124 | + 'order' => 10, |
|
125 | + ], |
|
126 | + 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
127 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
128 | + 'help_tabs' => [ |
|
129 | + 'registration_form_questions_overview_help_tab' => [ |
|
130 | + 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
131 | + 'filename' => 'registration_form_questions_overview', |
|
132 | + ], |
|
133 | + 'registration_form_questions_overview_table_column_headings_help_tab' => [ |
|
134 | + 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
135 | + 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
136 | + ], |
|
137 | + 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => [ |
|
138 | + 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
139 | + 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
140 | + ], |
|
141 | + ], |
|
142 | + 'require_nonce' => false, |
|
143 | + ], |
|
144 | + |
|
145 | + 'question_groups' => [ |
|
146 | + 'nav' => [ |
|
147 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
148 | + 'icon' => 'dashicons-forms', |
|
149 | + 'order' => 20, |
|
150 | + ], |
|
151 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
152 | + 'help_tabs' => [ |
|
153 | + 'registration_form_question_groups_help_tab' => [ |
|
154 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
155 | + 'filename' => 'registration_form_question_groups', |
|
156 | + ], |
|
157 | + ], |
|
158 | + 'require_nonce' => false, |
|
159 | + ], |
|
160 | + |
|
161 | + 'edit_question' => [ |
|
162 | + 'nav' => [ |
|
163 | + 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
164 | + 'icon' => 'dashicons-edit-large', |
|
165 | + 'order' => 15, |
|
166 | + 'persistent' => false, |
|
167 | + 'url' => isset($this->_req_data['question_id']) |
|
168 | + ? add_query_arg( |
|
169 | + ['question_id' => $this->_req_data['question_id']], |
|
170 | + $this->_current_page_view_url |
|
171 | + ) |
|
172 | + : $this->_admin_base_url, |
|
173 | + ], |
|
174 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
175 | + 'help_tabs' => [ |
|
176 | + 'registration_form_edit_question_group_help_tab' => [ |
|
177 | + 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
178 | + 'filename' => 'registration_form_edit_question', |
|
179 | + ], |
|
180 | + ], |
|
181 | + 'require_nonce' => false, |
|
182 | + ], |
|
183 | + ]; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + protected function _add_screen_options() |
|
188 | + { |
|
189 | + // todo |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + protected function _add_screen_options_default() |
|
194 | + { |
|
195 | + $page_title = $this->_admin_page_title; |
|
196 | + $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
197 | + $this->_per_page_screen_option(); |
|
198 | + $this->_admin_page_title = $page_title; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + protected function _add_screen_options_question_groups() |
|
203 | + { |
|
204 | + $page_title = $this->_admin_page_title; |
|
205 | + $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
206 | + $this->_per_page_screen_option(); |
|
207 | + $this->_admin_page_title = $page_title; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + // none of the below group are currently used for Event Categories |
|
212 | + protected function _add_feature_pointers() |
|
213 | + { |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + public function load_scripts_styles() |
|
218 | + { |
|
219 | + wp_register_style( |
|
220 | + 'espresso_registration', |
|
221 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', |
|
222 | + [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN], |
|
223 | + EVENT_ESPRESSO_VERSION |
|
224 | + ); |
|
225 | + wp_enqueue_style('espresso_registration'); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + public function admin_init() |
|
230 | + { |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + public function admin_notices() |
|
235 | + { |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + public function admin_footer_scripts() |
|
240 | + { |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + public function load_scripts_styles_default() |
|
245 | + { |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + public function load_scripts_styles_add_question() |
|
250 | + { |
|
251 | + $this->load_scripts_styles_question_details(); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + public function load_scripts_styles_edit_question() |
|
256 | + { |
|
257 | + $this->load_scripts_styles_question_details(); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * Loads the JS required for adding or editing a question |
|
263 | + */ |
|
264 | + protected function load_scripts_styles_question_details() |
|
265 | + { |
|
266 | + $this->load_scripts_styles_forms(); |
|
267 | + wp_register_script( |
|
268 | + 'espresso_registration_form_single', |
|
269 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', |
|
270 | + ['jquery-ui-sortable'], |
|
271 | + EVENT_ESPRESSO_VERSION, |
|
272 | + true |
|
273 | + ); |
|
274 | + wp_enqueue_script('espresso_registration_form_single'); |
|
275 | + wp_localize_script( |
|
276 | + 'espresso_registration_form_single', |
|
277 | + 'ee_question_data', |
|
278 | + [ |
|
279 | + 'question_types_with_max' => $this->_question_model->questionTypesWithMaxLength(), |
|
280 | + 'question_type_with_options' => $this->_question_model->question_types_with_options(), |
|
281 | + ] |
|
282 | + ); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + public function recaptcha_info_help_tab() |
|
287 | + { |
|
288 | + EEH_Template::display_template(REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + public function load_scripts_styles_forms() |
|
293 | + { |
|
294 | + // styles |
|
295 | + wp_enqueue_style('espresso-ui-theme'); |
|
296 | + // scripts |
|
297 | + wp_enqueue_script('ee_admin_js'); |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + protected function _set_list_table_views_default() |
|
302 | + { |
|
303 | + $this->_views = [ |
|
304 | + 'all' => [ |
|
305 | + 'slug' => 'all', |
|
306 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
307 | + 'count' => 0, |
|
308 | + ], |
|
309 | + ]; |
|
310 | + |
|
311 | + if ( |
|
312 | + $this->capabilities->current_user_can( |
|
313 | + 'ee_delete_questions', |
|
314 | + 'espresso_registration_form_trash_questions' |
|
315 | + ) |
|
316 | + ) { |
|
317 | + $this->_views['trash'] = [ |
|
318 | + 'slug' => 'trash', |
|
319 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
320 | + 'count' => 0, |
|
321 | + ]; |
|
322 | + } |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * This just previews the question groups tab that comes in caffeinated. |
|
328 | + * |
|
329 | + * @return void html |
|
330 | + * @throws EE_Error |
|
331 | + */ |
|
332 | + protected function _questions_groups_preview() |
|
333 | + { |
|
334 | + $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
335 | + $this->_template_args['preview_img'] = |
|
336 | + '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' |
|
337 | + . esc_attr__( |
|
338 | + 'Preview Question Groups Overview List Table screenshot', |
|
339 | + 'event_espresso' |
|
340 | + ) . '" />'; |
|
341 | + $this->_template_args['preview_text'] = '<strong>' |
|
342 | + . esc_html__( |
|
343 | + 'Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
344 | + 'event_espresso' |
|
345 | + ) . '</strong>'; |
|
346 | + $this->display_admin_caf_preview_page('question_groups_tab'); |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * Extracts the question field's values from the POST request to update or insert them |
|
352 | + * |
|
353 | + * @param EEM_Base $model |
|
354 | + * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
355 | + * @throws EE_Error |
|
356 | + * @throws ReflectionException |
|
357 | + */ |
|
358 | + protected function _set_column_values_for(EEM_Base $model): array |
|
359 | + { |
|
360 | + $column_values = []; |
|
361 | + // some initial checks for proper values. |
|
362 | + $QST_ID = $this->request->getRequestParam('QST_ID', 0, DataType::INT); |
|
363 | + // if QST_admin_only, then no matter what QST_required is we disable. |
|
364 | + $QST_admin_only = $this->request->getRequestParam('QST_admin_only', false, DataType::BOOL); |
|
365 | + if ($QST_admin_only) { |
|
366 | + $this->request->setRequestParam('QST_required', false); |
|
367 | + } |
|
368 | + // if the question shouldn't have a max length, don't let them set one |
|
369 | + if ( |
|
370 | + ! ( |
|
371 | + $this->request->requestParamIsSet('QST_type') |
|
372 | + && $this->request->requestParamIsSet('QST_max') |
|
373 | + ) || ! in_array( |
|
374 | + $this->request->getRequestParam('QST_type', '', DataType::STRING), |
|
375 | + $this->_question_model->questionTypesWithMaxLength(), |
|
376 | + true |
|
377 | + ) |
|
378 | + ) { |
|
379 | + // they're not allowed to set the max |
|
380 | + $this->request->unSetRequestParam('QST_max', true); |
|
381 | + } |
|
382 | + foreach ($model->field_settings() as $fieldName => $settings) { |
|
383 | + switch($fieldName) { |
|
384 | + case 'QSG_identifier': |
|
385 | + // basically if QSG_identifier is empty or not set |
|
386 | + if (! $this->request->getRequestParam('QSG_identifier', '', DataType::STRING)) { |
|
387 | + $QSG_name = $this->request->getRequestParam('QSG_name', '', DataType::STRING); |
|
388 | + $column_values[ $fieldName ] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
389 | + } |
|
390 | + break; |
|
391 | + |
|
392 | + case 'QST_display_text': |
|
393 | + $column_values[ $fieldName ] = $this->request->getRequestParam('QST_display_text', '', DataType::HTML); |
|
394 | + break; |
|
395 | + |
|
396 | + case 'QST_admin_label': |
|
397 | + if (! $this->request->getRequestParam('QST_admin_label', '', DataType::STRING)) { |
|
398 | + // the admin label is blank, use a slug version of the question text |
|
399 | + $QST_text = $this->request->getRequestParam('QST_display_text', '', DataType::STRING); |
|
400 | + $column_values[ $fieldName ] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
401 | + } else { |
|
402 | + // admin label set, use it |
|
403 | + $column_values[ $fieldName ] = $this->request->getRequestParam('QST_admin_label', '', DataType::STRING); |
|
404 | + } |
|
405 | + break; |
|
406 | + |
|
407 | + case 'QST_admin_only': |
|
408 | + if (! $QST_admin_only) { |
|
409 | + $column_values[ $fieldName ] = false; |
|
410 | + } |
|
411 | + break; |
|
412 | + |
|
413 | + case 'QST_max': |
|
414 | + $qst_system = $this->_question_model->get_var( |
|
415 | + [ [ 'QST_ID' => $QST_ID ] ], |
|
416 | + 'QST_system' |
|
417 | + ); |
|
418 | + |
|
419 | + $max_max = $this->_question_model->absolute_max_for_system_question((string) $qst_system); |
|
420 | + $QST_max = $this->request->getRequestParam('QST_max', 0, DataType::INT); |
|
421 | + if ($QST_max === 0 || $QST_max > $max_max) { |
|
422 | + $column_values[ $fieldName ] = $max_max; |
|
423 | + } |
|
424 | + break; |
|
425 | + |
|
426 | + default: |
|
427 | + // only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
428 | + if ($this->request->requestParamIsSet($fieldName)) { |
|
429 | + // convert the schema type to the appropriate data type |
|
430 | + $schema_type = DataType::convertModelFieldSchemaType($settings->getSchemaType()); |
|
431 | + $column_values[ $fieldName ] = $this->request->getRequestParam($fieldName, null, $schema_type); |
|
432 | + } |
|
433 | + } |
|
434 | + } |
|
435 | + // validation for this data to be performed by the model before insertion. |
|
436 | + return $column_values; |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + *_questions_overview_list_table |
|
442 | + * |
|
443 | + * @throws EE_Error |
|
444 | + */ |
|
445 | + protected function _questions_overview_list_table() |
|
446 | + { |
|
447 | + $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
448 | + $this->display_admin_list_table_page_with_sidebar(); |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * _edit_question |
|
454 | + * |
|
455 | + * @throws EE_Error |
|
456 | + * @throws ReflectionException |
|
457 | + */ |
|
458 | + protected function _edit_question() |
|
459 | + { |
|
460 | + $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) |
|
461 | + ? absint($this->_req_data['QST_ID']) |
|
462 | + : false; |
|
463 | + |
|
464 | + switch ($this->_req_action) { |
|
465 | + case 'add_question': |
|
466 | + $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
467 | + break; |
|
468 | + case 'edit_question': |
|
469 | + $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
470 | + break; |
|
471 | + default: |
|
472 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
473 | + } |
|
474 | + |
|
475 | + // add PRC_ID to title if editing |
|
476 | + $this->_admin_page_title = |
|
477 | + $ID |
|
478 | + ? $this->_admin_page_title . ' # ' . $ID |
|
479 | + : $this->_admin_page_title; |
|
480 | + if ($ID) { |
|
481 | + $question = $this->_question_model->get_one_by_ID($ID); |
|
482 | + $additional_hidden_fields = ['QST_ID' => ['type' => 'hidden', 'value' => $ID]]; |
|
483 | + $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
484 | + } else { |
|
485 | + $question = EE_Question::new_instance(); |
|
486 | + $question->set_order_to_latest(); |
|
487 | + $this->_set_add_edit_form_tags('insert_question'); |
|
488 | + } |
|
489 | + if ($question->system_ID() === EEM_Attendee::system_question_phone) { |
|
490 | + $question_types = array_intersect_key( |
|
491 | + $this->_question_model->allowed_question_types(), |
|
492 | + array_flip( |
|
493 | + [ |
|
494 | + EEM_Question::QST_type_text, |
|
495 | + EEM_Question::QST_type_us_phone, |
|
496 | + ] |
|
497 | + ) |
|
498 | + ); |
|
499 | + } else { |
|
500 | + $question_types = $question->has_answers() |
|
501 | + ? $this->_question_model->question_types_in_same_category($question->type()) |
|
502 | + : $this->_question_model->allowed_question_types(); |
|
503 | + } |
|
504 | + $this->_template_args['QST_ID'] = $ID; |
|
505 | + $this->_template_args['question'] = $question; |
|
506 | + $this->_template_args['question_types'] = $question_types; |
|
507 | + $this->_template_args['max_max'] = |
|
508 | + $this->_question_model->absolute_max_for_system_question( |
|
509 | + $question->system_ID() |
|
510 | + ); |
|
511 | + $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
512 | + $this->_set_publish_post_box_vars('id', $ID); |
|
513 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
514 | + REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
515 | + $this->_template_args, |
|
516 | + true |
|
517 | + ); |
|
518 | + |
|
519 | + // the details template wrapper |
|
520 | + $this->display_admin_page_with_sidebar(); |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * @return string |
|
526 | + * @throws EE_Error |
|
527 | + * @throws ReflectionException |
|
528 | + */ |
|
529 | + protected function _get_question_type_descriptions(): string |
|
530 | + { |
|
531 | + EE_Registry::instance()->load_helper('HTML'); |
|
532 | + $descriptions = ''; |
|
533 | + $question_type_descriptions = $this->_question_model->question_descriptions(); |
|
534 | + foreach ($question_type_descriptions as $type => $question_type_description) { |
|
535 | + if ($type == 'HTML_TEXTAREA') { |
|
536 | + $html = new EE_Simple_HTML_Validation_Strategy(); |
|
537 | + $question_type_description .= sprintf( |
|
538 | + esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
539 | + '<br/>', |
|
540 | + $html->get_list_of_allowed_tags() |
|
541 | + ); |
|
542 | + } |
|
543 | + $descriptions .= EEH_HTML::p( |
|
544 | + $question_type_description, |
|
545 | + 'question_type_description-' . $type, |
|
546 | + 'question_type_description description', |
|
547 | + 'display:none;' |
|
548 | + ); |
|
549 | + } |
|
550 | + return $descriptions; |
|
551 | + } |
|
552 | + |
|
553 | + |
|
554 | + /** |
|
555 | + * @param bool $new_question |
|
556 | + * @throws EE_Error |
|
557 | + * @throws ReflectionException |
|
558 | + */ |
|
559 | + protected function _insert_or_update_question(bool $new_question = true) |
|
560 | + { |
|
561 | + $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
562 | + if ($new_question) { |
|
563 | + $question = EE_Question::new_instance($set_column_values); |
|
564 | + $action_desc = 'added'; |
|
565 | + } else { |
|
566 | + $question = $this->_question_model->get_one_by_ID( |
|
567 | + $this->request->getRequestParam('QST_ID', 0, DataType::INT) |
|
568 | + ); |
|
569 | + foreach ($set_column_values as $field => $new_value) { |
|
570 | + $question->set($field, $new_value); |
|
571 | + } |
|
572 | + $action_desc = 'updated'; |
|
573 | + } |
|
574 | + $success = $question->save(); |
|
575 | + $ID = $question->ID(); |
|
576 | + if ($ID && $question->should_have_question_options()) { |
|
577 | + // save the related options |
|
578 | + // trash removed options, save old ones |
|
579 | + // get list of all options |
|
580 | + $options = $question->options(); |
|
581 | + $question_options = $this->request->getRequestParam('question_options', [], DataType::HTML, true); |
|
582 | + $QSO_default = $this->request->getRequestParam('QSO_default', null, DataType::INT); |
|
583 | + if (! empty($options)) { |
|
584 | + foreach ($options as $option_ID => $option) { |
|
585 | + $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
586 | + if ($option_req_index !== false) { |
|
587 | + $question_options[ $option_req_index ]['QSO_default'] = $option_req_index === $QSO_default; |
|
588 | + $option->save($question_options[ $option_req_index ]); |
|
589 | + } else { |
|
590 | + // not found, remove it |
|
591 | + $option->delete(); |
|
592 | + } |
|
593 | + } |
|
594 | + } |
|
595 | + // save new related options |
|
596 | + foreach ($question_options as $index => $option_req_data) { |
|
597 | + // skip $index that is from our sample |
|
598 | + if ($index === 'xxcountxx') { |
|
599 | + continue; |
|
600 | + } |
|
601 | + // note we allow saving blank options. |
|
602 | + if (empty($option_req_data['QSO_ID'])) { |
|
603 | + // no ID! save it! |
|
604 | + $new_option = EE_Question_Option::new_instance( |
|
605 | + [ |
|
606 | + 'QSO_value' => $option_req_data['QSO_value'], |
|
607 | + 'QSO_desc' => $option_req_data['QSO_desc'], |
|
608 | + 'QSO_default' => $index === $QSO_default, |
|
609 | + 'QSO_order' => $option_req_data['QSO_order'], |
|
610 | + 'QST_ID' => $question->ID(), |
|
611 | + ] |
|
612 | + ); |
|
613 | + $new_option->save(); |
|
614 | + } |
|
615 | + } |
|
616 | + } |
|
617 | + |
|
618 | + $success = apply_filters( |
|
619 | + 'FHEE__Registration_Form_Admin_Page___insert_or_update_question__success', |
|
620 | + (int) $success, |
|
621 | + $question, |
|
622 | + $this |
|
623 | + ); |
|
624 | + |
|
625 | + $query_args = ['action' => 'edit_question', 'QST_ID' => $ID]; |
|
626 | + if ($success !== 0) { |
|
627 | + $msg = $new_question |
|
628 | + ? sprintf( |
|
629 | + esc_html__('The %s has been created', 'event_espresso'), |
|
630 | + $this->_question_model->item_name() |
|
631 | + ) |
|
632 | + : sprintf( |
|
633 | + esc_html__('The %s has been updated', 'event_espresso'), |
|
634 | + $this->_question_model->item_name() |
|
635 | + ); |
|
636 | + EE_Error::add_success($msg); |
|
637 | + } |
|
638 | + |
|
639 | + $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + /** |
|
644 | + * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
645 | + * by ID |
|
646 | + * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
647 | + * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
648 | + * |
|
649 | + * @param int $ID of the question option to find |
|
650 | + * @return int index in question_options array if successful, FALSE if unsuccessful |
|
651 | + */ |
|
652 | + protected function _get_option_req_data_index(int $ID) |
|
653 | + { |
|
654 | + $req_data_for_question_options = $this->_req_data['question_options']; |
|
655 | + foreach ($req_data_for_question_options as $num => $option_data) { |
|
656 | + if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) { |
|
657 | + return $num; |
|
658 | + } |
|
659 | + } |
|
660 | + return false; |
|
661 | + } |
|
662 | + |
|
663 | + |
|
664 | + |
|
665 | + |
|
666 | + /* QUERIES */ |
|
667 | + /** |
|
668 | + * For internal use in getting all the query parameters |
|
669 | + * (because it's pretty well the same between question, question groups, |
|
670 | + * and for both when searching for trashed and untrashed ones) |
|
671 | + * |
|
672 | + * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
673 | + * @param int $per_page |
|
674 | + * @param int $current_page |
|
675 | + * @return array model query params, |
|
676 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
677 | + */ |
|
678 | + protected function get_query_params(EEM_Base $model, int $per_page = 10, int $current_page = 10): array |
|
679 | + { |
|
680 | + $query_params = []; |
|
681 | + $offset = ($current_page - 1) * $per_page; |
|
682 | + $query_params['limit'] = [$offset, $per_page]; |
|
683 | + |
|
684 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
685 | + ? $this->_req_data['order'] |
|
686 | + : 'ASC'; |
|
687 | + |
|
688 | + $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
689 | + |
|
690 | + $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
691 | + |
|
692 | + $query_params['order_by'] = [$field_to_order_by => $order]; |
|
693 | + |
|
694 | + $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
695 | + if (! empty($search_string)) { |
|
696 | + if ($model instanceof EEM_Question_Group) { |
|
697 | + $query_params[0] = [ |
|
698 | + 'OR' => [ |
|
699 | + 'QSG_name' => ['LIKE', "%$search_string%"], |
|
700 | + 'QSG_desc' => ['LIKE', "%$search_string%"], |
|
701 | + ], |
|
702 | + ]; |
|
703 | + } else { |
|
704 | + $query_params[0] = [ |
|
705 | + 'QST_display_text' => ['LIKE', "%$search_string%"], |
|
706 | + ]; |
|
707 | + } |
|
708 | + } |
|
709 | + |
|
710 | + // capability checks (just leaving this commented out for reference because |
|
711 | + // it illustrates some complicated query params that could be useful when fully implemented) |
|
712 | + /*if ( $model instanceof EEM_Question_Group ) { |
|
713 | 713 | if ( |
714 | 714 | ! $this->capabilities->current_user_can( |
715 | 715 | 'edit_others_question_groups', |
@@ -749,59 +749,59 @@ discard block |
||
749 | 749 | } |
750 | 750 | }/**/ |
751 | 751 | |
752 | - return $query_params; |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - /** |
|
757 | - * @param int $per_page |
|
758 | - * @param int $current_page |
|
759 | - * @param bool $count |
|
760 | - * @return EE_Question[]|int |
|
761 | - * @throws EE_Error |
|
762 | - * @throws ReflectionException |
|
763 | - */ |
|
764 | - public function get_questions(int $per_page = 10, int $current_page = 1, bool $count = false) |
|
765 | - { |
|
766 | - $query_params = $this->get_query_params($this->_question_model, $per_page, $current_page); |
|
767 | - if ($count) { |
|
768 | - $where = isset($query_params[0]) ? [$query_params[0]] : []; |
|
769 | - return $this->_question_model->count($where); |
|
770 | - } |
|
771 | - return $this->_question_model->get_all($query_params); |
|
772 | - } |
|
773 | - |
|
774 | - |
|
775 | - /** |
|
776 | - * @param int $per_page |
|
777 | - * @param int $current_page |
|
778 | - * @param bool $count |
|
779 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
780 | - * @throws EE_Error |
|
781 | - */ |
|
782 | - public function get_trashed_questions(int $per_page, int $current_page = 1, bool $count = false) |
|
783 | - { |
|
784 | - $query_params = $this->get_query_params($this->_question_model, $per_page, $current_page); |
|
785 | - $where = isset($query_params[0]) ? [$query_params[0]] : []; |
|
786 | - return $count |
|
787 | - ? $this->_question_model->count_deleted($where) |
|
788 | - : $this->_question_model->get_all_deleted($query_params); |
|
789 | - } |
|
790 | - |
|
791 | - |
|
792 | - /** |
|
793 | - * @param int $per_page |
|
794 | - * @param int $current_page |
|
795 | - * @param bool $count |
|
796 | - * @return EE_Question_Group[]|int |
|
797 | - * @throws EE_Error |
|
798 | - * @throws ReflectionException |
|
799 | - */ |
|
800 | - public function get_question_groups(int $per_page, int $current_page = 1, bool $count = false) |
|
801 | - { |
|
802 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
803 | - return $this->_question_group_model->get_all( |
|
804 | - $this->get_query_params($this->_question_group_model, $per_page, $current_page) |
|
805 | - ); |
|
806 | - } |
|
752 | + return $query_params; |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + /** |
|
757 | + * @param int $per_page |
|
758 | + * @param int $current_page |
|
759 | + * @param bool $count |
|
760 | + * @return EE_Question[]|int |
|
761 | + * @throws EE_Error |
|
762 | + * @throws ReflectionException |
|
763 | + */ |
|
764 | + public function get_questions(int $per_page = 10, int $current_page = 1, bool $count = false) |
|
765 | + { |
|
766 | + $query_params = $this->get_query_params($this->_question_model, $per_page, $current_page); |
|
767 | + if ($count) { |
|
768 | + $where = isset($query_params[0]) ? [$query_params[0]] : []; |
|
769 | + return $this->_question_model->count($where); |
|
770 | + } |
|
771 | + return $this->_question_model->get_all($query_params); |
|
772 | + } |
|
773 | + |
|
774 | + |
|
775 | + /** |
|
776 | + * @param int $per_page |
|
777 | + * @param int $current_page |
|
778 | + * @param bool $count |
|
779 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
780 | + * @throws EE_Error |
|
781 | + */ |
|
782 | + public function get_trashed_questions(int $per_page, int $current_page = 1, bool $count = false) |
|
783 | + { |
|
784 | + $query_params = $this->get_query_params($this->_question_model, $per_page, $current_page); |
|
785 | + $where = isset($query_params[0]) ? [$query_params[0]] : []; |
|
786 | + return $count |
|
787 | + ? $this->_question_model->count_deleted($where) |
|
788 | + : $this->_question_model->get_all_deleted($query_params); |
|
789 | + } |
|
790 | + |
|
791 | + |
|
792 | + /** |
|
793 | + * @param int $per_page |
|
794 | + * @param int $current_page |
|
795 | + * @param bool $count |
|
796 | + * @return EE_Question_Group[]|int |
|
797 | + * @throws EE_Error |
|
798 | + * @throws ReflectionException |
|
799 | + */ |
|
800 | + public function get_question_groups(int $per_page, int $current_page = 1, bool $count = false) |
|
801 | + { |
|
802 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
803 | + return $this->_question_group_model->get_all( |
|
804 | + $this->get_query_params($this->_question_group_model, $per_page, $current_page) |
|
805 | + ); |
|
806 | + } |
|
807 | 807 | } |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function __construct($routing = true) |
42 | 42 | { |
43 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
44 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
43 | + require_once(EE_MODELS.'EEM_Question.model.php'); |
|
44 | + require_once(EE_MODELS.'EEM_Question_Group.model.php'); |
|
45 | 45 | $this->_question_model = EEM_Question::instance(); |
46 | 46 | $this->_question_group_model = EEM_Question_Group::instance(); |
47 | 47 | parent::__construct($routing); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected function _set_page_routes() |
83 | 83 | { |
84 | - $qst_id = |
|
84 | + $qst_id = |
|
85 | 85 | ! empty($this->_req_data['QST_ID']) |
86 | 86 | ? $this->_req_data['QST_ID'] |
87 | 87 | : 0; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | { |
219 | 219 | wp_register_style( |
220 | 220 | 'espresso_registration', |
221 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', |
|
221 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.css', |
|
222 | 222 | [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN], |
223 | 223 | EVENT_ESPRESSO_VERSION |
224 | 224 | ); |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | $this->load_scripts_styles_forms(); |
267 | 267 | wp_register_script( |
268 | 268 | 'espresso_registration_form_single', |
269 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', |
|
269 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', |
|
270 | 270 | ['jquery-ui-sortable'], |
271 | 271 | EVENT_ESPRESSO_VERSION, |
272 | 272 | true |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | |
286 | 286 | public function recaptcha_info_help_tab() |
287 | 287 | { |
288 | - EEH_Template::display_template(REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'); |
|
288 | + EEH_Template::display_template(REGISTRATION_FORM_TEMPLATE_PATH.'recaptcha_info_help_tab.template.php'); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | |
@@ -333,16 +333,16 @@ discard block |
||
333 | 333 | { |
334 | 334 | $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
335 | 335 | $this->_template_args['preview_img'] = |
336 | - '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' |
|
336 | + '<img src="'.REGISTRATION_FORM_ASSETS_URL.'caf_reg_form_preview.jpg" alt="' |
|
337 | 337 | . esc_attr__( |
338 | 338 | 'Preview Question Groups Overview List Table screenshot', |
339 | 339 | 'event_espresso' |
340 | - ) . '" />'; |
|
340 | + ).'" />'; |
|
341 | 341 | $this->_template_args['preview_text'] = '<strong>' |
342 | 342 | . esc_html__( |
343 | 343 | 'Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
344 | 344 | 'event_espresso' |
345 | - ) . '</strong>'; |
|
345 | + ).'</strong>'; |
|
346 | 346 | $this->display_admin_caf_preview_page('question_groups_tab'); |
347 | 347 | } |
348 | 348 | |
@@ -380,46 +380,46 @@ discard block |
||
380 | 380 | $this->request->unSetRequestParam('QST_max', true); |
381 | 381 | } |
382 | 382 | foreach ($model->field_settings() as $fieldName => $settings) { |
383 | - switch($fieldName) { |
|
383 | + switch ($fieldName) { |
|
384 | 384 | case 'QSG_identifier': |
385 | 385 | // basically if QSG_identifier is empty or not set |
386 | - if (! $this->request->getRequestParam('QSG_identifier', '', DataType::STRING)) { |
|
386 | + if ( ! $this->request->getRequestParam('QSG_identifier', '', DataType::STRING)) { |
|
387 | 387 | $QSG_name = $this->request->getRequestParam('QSG_name', '', DataType::STRING); |
388 | - $column_values[ $fieldName ] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
388 | + $column_values[$fieldName] = sanitize_title($QSG_name).'-'.uniqid('', true); |
|
389 | 389 | } |
390 | 390 | break; |
391 | 391 | |
392 | 392 | case 'QST_display_text': |
393 | - $column_values[ $fieldName ] = $this->request->getRequestParam('QST_display_text', '', DataType::HTML); |
|
393 | + $column_values[$fieldName] = $this->request->getRequestParam('QST_display_text', '', DataType::HTML); |
|
394 | 394 | break; |
395 | 395 | |
396 | 396 | case 'QST_admin_label': |
397 | - if (! $this->request->getRequestParam('QST_admin_label', '', DataType::STRING)) { |
|
397 | + if ( ! $this->request->getRequestParam('QST_admin_label', '', DataType::STRING)) { |
|
398 | 398 | // the admin label is blank, use a slug version of the question text |
399 | 399 | $QST_text = $this->request->getRequestParam('QST_display_text', '', DataType::STRING); |
400 | - $column_values[ $fieldName ] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
400 | + $column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
401 | 401 | } else { |
402 | 402 | // admin label set, use it |
403 | - $column_values[ $fieldName ] = $this->request->getRequestParam('QST_admin_label', '', DataType::STRING); |
|
403 | + $column_values[$fieldName] = $this->request->getRequestParam('QST_admin_label', '', DataType::STRING); |
|
404 | 404 | } |
405 | 405 | break; |
406 | 406 | |
407 | 407 | case 'QST_admin_only': |
408 | - if (! $QST_admin_only) { |
|
409 | - $column_values[ $fieldName ] = false; |
|
408 | + if ( ! $QST_admin_only) { |
|
409 | + $column_values[$fieldName] = false; |
|
410 | 410 | } |
411 | 411 | break; |
412 | 412 | |
413 | 413 | case 'QST_max': |
414 | 414 | $qst_system = $this->_question_model->get_var( |
415 | - [ [ 'QST_ID' => $QST_ID ] ], |
|
415 | + [['QST_ID' => $QST_ID]], |
|
416 | 416 | 'QST_system' |
417 | 417 | ); |
418 | 418 | |
419 | 419 | $max_max = $this->_question_model->absolute_max_for_system_question((string) $qst_system); |
420 | 420 | $QST_max = $this->request->getRequestParam('QST_max', 0, DataType::INT); |
421 | 421 | if ($QST_max === 0 || $QST_max > $max_max) { |
422 | - $column_values[ $fieldName ] = $max_max; |
|
422 | + $column_values[$fieldName] = $max_max; |
|
423 | 423 | } |
424 | 424 | break; |
425 | 425 | |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | if ($this->request->requestParamIsSet($fieldName)) { |
429 | 429 | // convert the schema type to the appropriate data type |
430 | 430 | $schema_type = DataType::convertModelFieldSchemaType($settings->getSchemaType()); |
431 | - $column_values[ $fieldName ] = $this->request->getRequestParam($fieldName, null, $schema_type); |
|
431 | + $column_values[$fieldName] = $this->request->getRequestParam($fieldName, null, $schema_type); |
|
432 | 432 | } |
433 | 433 | } |
434 | 434 | } |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | // add PRC_ID to title if editing |
476 | 476 | $this->_admin_page_title = |
477 | 477 | $ID |
478 | - ? $this->_admin_page_title . ' # ' . $ID |
|
478 | + ? $this->_admin_page_title.' # '.$ID |
|
479 | 479 | : $this->_admin_page_title; |
480 | 480 | if ($ID) { |
481 | 481 | $question = $this->_question_model->get_one_by_ID($ID); |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
512 | 512 | $this->_set_publish_post_box_vars('id', $ID); |
513 | 513 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
514 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
514 | + REGISTRATION_FORM_TEMPLATE_PATH.'questions_main_meta_box.template.php', |
|
515 | 515 | $this->_template_args, |
516 | 516 | true |
517 | 517 | ); |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | $question_type_descriptions = $this->_question_model->question_descriptions(); |
534 | 534 | foreach ($question_type_descriptions as $type => $question_type_description) { |
535 | 535 | if ($type == 'HTML_TEXTAREA') { |
536 | - $html = new EE_Simple_HTML_Validation_Strategy(); |
|
536 | + $html = new EE_Simple_HTML_Validation_Strategy(); |
|
537 | 537 | $question_type_description .= sprintf( |
538 | 538 | esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
539 | 539 | '<br/>', |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | } |
543 | 543 | $descriptions .= EEH_HTML::p( |
544 | 544 | $question_type_description, |
545 | - 'question_type_description-' . $type, |
|
545 | + 'question_type_description-'.$type, |
|
546 | 546 | 'question_type_description description', |
547 | 547 | 'display:none;' |
548 | 548 | ); |
@@ -580,12 +580,12 @@ discard block |
||
580 | 580 | $options = $question->options(); |
581 | 581 | $question_options = $this->request->getRequestParam('question_options', [], DataType::HTML, true); |
582 | 582 | $QSO_default = $this->request->getRequestParam('QSO_default', null, DataType::INT); |
583 | - if (! empty($options)) { |
|
583 | + if ( ! empty($options)) { |
|
584 | 584 | foreach ($options as $option_ID => $option) { |
585 | 585 | $option_req_index = $this->_get_option_req_data_index($option_ID); |
586 | 586 | if ($option_req_index !== false) { |
587 | - $question_options[ $option_req_index ]['QSO_default'] = $option_req_index === $QSO_default; |
|
588 | - $option->save($question_options[ $option_req_index ]); |
|
587 | + $question_options[$option_req_index]['QSO_default'] = $option_req_index === $QSO_default; |
|
588 | + $option->save($question_options[$option_req_index]); |
|
589 | 589 | } else { |
590 | 590 | // not found, remove it |
591 | 591 | $option->delete(); |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | $offset = ($current_page - 1) * $per_page; |
682 | 682 | $query_params['limit'] = [$offset, $per_page]; |
683 | 683 | |
684 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
684 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
685 | 685 | ? $this->_req_data['order'] |
686 | 686 | : 'ASC'; |
687 | 687 | |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | $query_params['order_by'] = [$field_to_order_by => $order]; |
693 | 693 | |
694 | 694 | $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
695 | - if (! empty($search_string)) { |
|
695 | + if ( ! empty($search_string)) { |
|
696 | 696 | if ($model instanceof EEM_Question_Group) { |
697 | 697 | $query_params[0] = [ |
698 | 698 | 'OR' => [ |
@@ -9,36 +9,36 @@ discard block |
||
9 | 9 | use EventEspresso\core\services\request\sanitizers\AllowedTags; |
10 | 10 | |
11 | 11 | if (! function_exists('espresso_get_template_part')) { |
12 | - /** |
|
13 | - * espresso_get_template_part |
|
14 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
15 | - * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
16 | - * |
|
17 | - * @param string $slug The slug name for the generic template. |
|
18 | - * @param string $name The name of the specialised template. |
|
19 | - */ |
|
20 | - function espresso_get_template_part($slug = '', $name = '') |
|
21 | - { |
|
22 | - EEH_Template::get_template_part($slug, $name); |
|
23 | - } |
|
12 | + /** |
|
13 | + * espresso_get_template_part |
|
14 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
15 | + * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
16 | + * |
|
17 | + * @param string $slug The slug name for the generic template. |
|
18 | + * @param string $name The name of the specialised template. |
|
19 | + */ |
|
20 | + function espresso_get_template_part($slug = '', $name = '') |
|
21 | + { |
|
22 | + EEH_Template::get_template_part($slug, $name); |
|
23 | + } |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | |
27 | 27 | if (! function_exists('espresso_get_object_css_class')) { |
28 | - /** |
|
29 | - * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
30 | - * |
|
31 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
32 | - * @param string $prefix added to the beginning of the generated class |
|
33 | - * @param string $suffix added to the end of the generated class |
|
34 | - * @return string |
|
35 | - * @throws EE_Error |
|
36 | - * @throws ReflectionException |
|
37 | - */ |
|
38 | - function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
39 | - { |
|
40 | - return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
41 | - } |
|
28 | + /** |
|
29 | + * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
30 | + * |
|
31 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
32 | + * @param string $prefix added to the beginning of the generated class |
|
33 | + * @param string $suffix added to the end of the generated class |
|
34 | + * @return string |
|
35 | + * @throws EE_Error |
|
36 | + * @throws ReflectionException |
|
37 | + */ |
|
38 | + function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
39 | + { |
|
40 | + return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | |
@@ -52,668 +52,668 @@ discard block |
||
52 | 52 | */ |
53 | 53 | class EEH_Template |
54 | 54 | { |
55 | - private static array $_espresso_themes = []; |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
60 | - * |
|
61 | - * @return boolean |
|
62 | - */ |
|
63 | - public static function is_espresso_theme() |
|
64 | - { |
|
65 | - return wp_get_theme()->get('TextDomain') === 'event_espresso'; |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
71 | - * load its functions.php file ( if not already loaded ) |
|
72 | - * |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public static function load_espresso_theme_functions() |
|
76 | - { |
|
77 | - if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
78 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
79 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
80 | - } |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
87 | - * |
|
88 | - * @return array |
|
89 | - */ |
|
90 | - public static function get_espresso_themes(): array |
|
91 | - { |
|
92 | - if (empty(EEH_Template::$_espresso_themes)) { |
|
93 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
94 | - if (empty($espresso_themes)) { |
|
95 | - return []; |
|
96 | - } |
|
97 | - if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
98 | - unset($espresso_themes[ $key ]); |
|
99 | - } |
|
100 | - EEH_Template::$_espresso_themes = []; |
|
101 | - foreach ($espresso_themes as $espresso_theme) { |
|
102 | - EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
103 | - } |
|
104 | - } |
|
105 | - return EEH_Template::$_espresso_themes; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * EEH_Template::get_template_part |
|
111 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
112 | - * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
113 | - * filtering based off of the entire template part name |
|
114 | - * |
|
115 | - * @param string $slug The slug name for the generic template. |
|
116 | - * @param string $name The name of the specialised template. |
|
117 | - * @param array $template_args |
|
118 | - * @param bool $return_string |
|
119 | - * @return string the html output for the formatted money value |
|
120 | - */ |
|
121 | - public static function get_template_part( |
|
122 | - $slug = '', |
|
123 | - $name = '', |
|
124 | - $template_args = [], |
|
125 | - $return_string = false |
|
126 | - ) { |
|
127 | - do_action("get_template_part_$slug-$name", $slug, $name); |
|
128 | - $template = $slug; |
|
129 | - $name = (string) $name; |
|
130 | - if ($name != '') { |
|
131 | - $template .= "-$name"; |
|
132 | - } |
|
133 | - $template .= ".php"; |
|
134 | - // allow template parts to be turned off via something like: |
|
135 | - // add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
136 | - if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_$name", true)) { |
|
137 | - return EEH_Template::locate_template($template, $template_args, true, $return_string); |
|
138 | - } |
|
139 | - return ''; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * locate_template |
|
145 | - * locate a template file by looking in the following places, in the following order: |
|
146 | - * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
147 | - * <assumed full absolute server path> |
|
148 | - * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
149 | - * <server path up to>/wp-content/uploads/espresso/templates/ |
|
150 | - * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
151 | - * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
152 | - * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
153 | - * as soon as the template is found in one of these locations, it will be returned or loaded |
|
154 | - * Example: |
|
155 | - * You are using the WordPress Twenty Sixteen theme, |
|
156 | - * and you want to customize the "some-event.template.php" template, |
|
157 | - * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
158 | - * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
159 | - * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
160 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
161 | - * /relative/path/to/some-event.template.php |
|
162 | - * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
163 | - * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
164 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
165 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
166 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
167 | - * Had you passed an absolute path to your template that was in some other location, |
|
168 | - * ie: "/absolute/path/to/some-event.template.php" |
|
169 | - * then the search would have been : |
|
170 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
171 | - * /absolute/path/to/some-event.template.php |
|
172 | - * and stopped there upon finding it in the second location |
|
173 | - * |
|
174 | - * @param array|string $templates array of template file names including extension (or just a single string) |
|
175 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
176 | - * @param boolean $load whether to pass the located template path on to the |
|
177 | - * EEH_Template::display_template() method or simply return it |
|
178 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
179 | - * string |
|
180 | - * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
181 | - * generate a custom template or not. Used in places where you don't actually |
|
182 | - * load the template, you just want to know if there's a custom version of it. |
|
183 | - * @return string|true |
|
184 | - * @throws DomainException |
|
185 | - * @throws InvalidArgumentException |
|
186 | - * @throws InvalidDataTypeException |
|
187 | - * @throws InvalidInterfaceException |
|
188 | - */ |
|
189 | - public static function locate_template( |
|
190 | - $templates = [], |
|
191 | - array $template_args = [], |
|
192 | - bool $load = true, |
|
193 | - bool $return_string = true, |
|
194 | - bool $check_if_custom = false |
|
195 | - ) { |
|
196 | - $cache_id = TemplateCache::generateCacheID(__FUNCTION__, func_get_args()); |
|
197 | - $template_path = TemplateCache::get($cache_id); |
|
198 | - $template_path = $template_path ?: self::resolveTemplatePath($cache_id, (array) $templates, $check_if_custom); |
|
199 | - |
|
200 | - if ($check_if_custom && ! empty($template_path)) { |
|
201 | - return true; |
|
202 | - } |
|
203 | - |
|
204 | - // if we got it and you want to see it... |
|
205 | - if ($template_path && $load && ! $check_if_custom) { |
|
206 | - if ($return_string) { |
|
207 | - return EEH_Template::display_template($template_path, $template_args, true); |
|
208 | - } |
|
209 | - EEH_Template::display_template($template_path, $template_args); |
|
210 | - } |
|
211 | - return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * Resolves the path of a template by checking various possible locations. |
|
217 | - * |
|
218 | - * This method checks for the existence of a template in several locations, |
|
219 | - * including the current theme folder, the uploads directory, and the plugin's own template directory. |
|
220 | - * It uses the provided cache ID to store and retrieve the resolved path from a cache for performance. |
|
221 | - * If the template is not found in any of the checked locations, an empty string is returned. |
|
222 | - * |
|
223 | - * @param string $cache_id The ID used for caching the resolved path. |
|
224 | - * @param array $templates An array of template file names to search for. |
|
225 | - * @param bool $check_if_custom If true, the method will only check if a custom template exists |
|
226 | - * and won't include core plugin folders. |
|
227 | - * @return string The resolved template path, or an empty string if the template was not found. |
|
228 | - * @since 5.0.21.p |
|
229 | - */ |
|
230 | - private static function resolveTemplatePath(string $cache_id, array $templates, bool $check_if_custom): string |
|
231 | - { |
|
232 | - // first use WP locate_template to check for template in the current theme folder |
|
233 | - $template_path = $templates ? locate_template($templates) : ''; |
|
234 | - // not in the theme |
|
235 | - if (empty($template_path)) { |
|
236 | - // not even a template to look for ? |
|
237 | - if (empty($templates)) { |
|
238 | - $loader = LoaderFactory::getLoader(); |
|
239 | - /** @var RequestInterface $request */ |
|
240 | - $request = $loader->getShared(RequestInterface::class); |
|
241 | - // get post_type |
|
242 | - $post_type = $request->getRequestParam('post_type'); |
|
243 | - /** @var CustomPostTypeDefinitions $custom_post_types */ |
|
244 | - $custom_post_types = $loader->getShared(CustomPostTypeDefinitions::class); |
|
245 | - // get array of EE Custom Post Types |
|
246 | - $EE_CPTs = $custom_post_types->getDefinitions(); |
|
247 | - // build template name based on request |
|
248 | - if (isset($EE_CPTs[ $post_type ])) { |
|
249 | - $archive_or_single = is_archive() ? 'archive' : ''; |
|
250 | - $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
251 | - $templates[] = $archive_or_single . '-' . $post_type . '.php'; |
|
252 | - } |
|
253 | - } |
|
254 | - // currently active EE template theme |
|
255 | - $current_theme = EE_Config::get_current_theme(); |
|
256 | - // array of paths to folders that may contain templates |
|
257 | - $template_folder_paths = [ |
|
258 | - // root of the /wp-content/uploads/espresso/templates/ folder |
|
259 | - EVENT_ESPRESSO_TEMPLATE_DIR |
|
260 | - ]; |
|
261 | - |
|
262 | - // add core plugin folders for checking only if we're not $check_if_custom |
|
263 | - if (! $check_if_custom) { |
|
264 | - $core_paths = [ |
|
265 | - // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
266 | - EE_PUBLIC . $current_theme, |
|
267 | - // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
268 | - EE_TEMPLATES . $current_theme, |
|
269 | - // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
270 | - EE_PLUGIN_DIR_PATH, |
|
271 | - ]; |
|
272 | - $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
273 | - } |
|
274 | - |
|
275 | - // now filter that array |
|
276 | - $template_folder_paths = (array) apply_filters( |
|
277 | - 'FHEE__EEH_Template__locate_template__template_folder_paths', |
|
278 | - $template_folder_paths |
|
279 | - ); |
|
280 | - |
|
281 | - // array to hold all possible template paths |
|
282 | - $full_template_paths = []; |
|
283 | - $file_name = ''; |
|
284 | - |
|
285 | - // loop through $templates |
|
286 | - foreach ($templates as $template) { |
|
287 | - // normalize directory separators |
|
288 | - $template = EEH_File::standardise_directory_separators($template); |
|
289 | - $file_name = basename($template); |
|
290 | - $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
291 | - // while looping through all template folder paths |
|
292 | - foreach ($template_folder_paths as $template_folder_path) { |
|
293 | - // normalize directory separators |
|
294 | - $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
295 | - // determine if any common base path exists between the two paths |
|
296 | - $common_base_path = EEH_Template::_find_common_base_path( |
|
297 | - [$template_folder_path, $template_path_minus_file_name] |
|
298 | - ); |
|
299 | - if ($common_base_path !== '') { |
|
300 | - // both paths have a common base, so just tack the filename onto our search path |
|
301 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
302 | - } else { |
|
303 | - // no common base path, so let's just concatenate |
|
304 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
305 | - } |
|
306 | - // build up our template locations array by adding our resolved paths |
|
307 | - $full_template_paths[] = $resolved_path; |
|
308 | - } |
|
309 | - // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
310 | - array_unshift($full_template_paths, $template); |
|
311 | - // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
312 | - array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
313 | - } |
|
314 | - // filter final array of full template paths |
|
315 | - $full_template_paths = apply_filters( |
|
316 | - 'FHEE__EEH_Template__locate_template__full_template_paths', |
|
317 | - $full_template_paths, |
|
318 | - $file_name |
|
319 | - ); |
|
320 | - // now loop through our final array of template location paths and check each location |
|
321 | - foreach ((array) $full_template_paths as $full_template_path) { |
|
322 | - if (is_readable($full_template_path)) { |
|
323 | - $template_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $full_template_path); |
|
324 | - TemplateCache::set($cache_id, $template_path); |
|
325 | - break; |
|
326 | - } |
|
327 | - } |
|
328 | - } |
|
329 | - |
|
330 | - // Display a deprecated notice if the template file is located in the WordPress uploads directory |
|
331 | - if (strpos($template_path, 'wp-content/uploads/espresso') !== false) { |
|
332 | - EE_Error::doing_it_wrong( |
|
333 | - __CLASS__, |
|
334 | - esc_html__( |
|
335 | - 'The use of the WordPress uploads directory as a location to override template files has been deprecated.', |
|
336 | - 'event_espresso' |
|
337 | - ), |
|
338 | - '5.0.0' |
|
339 | - ); |
|
340 | - } |
|
341 | - |
|
342 | - // hook that can be used to display the full template path that will be used |
|
343 | - do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
344 | - |
|
345 | - return $template_path; |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * _find_common_base_path |
|
351 | - * given two paths, this determines if there is a common base path between the two |
|
352 | - * |
|
353 | - * @param array $paths |
|
354 | - * @return string |
|
355 | - */ |
|
356 | - protected static function _find_common_base_path($paths) |
|
357 | - { |
|
358 | - $last_offset = 0; |
|
359 | - $common_base_path = ''; |
|
360 | - while (($index = strpos($paths[0], '/', $last_offset)) !== false) { |
|
361 | - $dir_length = $index - $last_offset + 1; |
|
362 | - $directory = substr($paths[0], $last_offset, $dir_length); |
|
363 | - foreach ($paths as $path) { |
|
364 | - if (substr($path, $last_offset, $dir_length) != $directory) { |
|
365 | - return $common_base_path; |
|
366 | - } |
|
367 | - } |
|
368 | - $common_base_path .= $directory; |
|
369 | - $last_offset = $index + 1; |
|
370 | - } |
|
371 | - return substr($common_base_path, 0, -1); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * load and display a template |
|
377 | - * |
|
378 | - * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
379 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
380 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
381 | - * string |
|
382 | - * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
383 | - * not found or is not readable |
|
384 | - * @return string |
|
385 | - * @throws DomainException |
|
386 | - */ |
|
387 | - public static function display_template( |
|
388 | - $template_path = '', |
|
389 | - $template_args = [], |
|
390 | - $return_string = false, |
|
391 | - $throw_exceptions = false |
|
392 | - ) { |
|
393 | - /** |
|
394 | - * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
395 | - * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
396 | - * the display_template method are templates we DON'T want modified (usually because of js |
|
397 | - * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
398 | - * using this. |
|
399 | - * |
|
400 | - * @since 4.6.0 |
|
401 | - */ |
|
402 | - $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
403 | - $template_args = (array) apply_filters( |
|
404 | - 'FHEE__EEH_Template__display_template__template_args', |
|
405 | - $template_args, |
|
406 | - $template_path |
|
407 | - ); |
|
408 | - |
|
409 | - // you gimme nuttin - YOU GET NUTTIN !! |
|
410 | - if (! $template_path || ! is_readable($template_path)) { |
|
411 | - // ignore whether template is accessible ? |
|
412 | - if ($throw_exceptions) { |
|
413 | - throw new DomainException( |
|
414 | - esc_html__('Invalid, unreadable, or missing file.', 'event_espresso') |
|
415 | - ); |
|
416 | - } |
|
417 | - return ''; |
|
418 | - } |
|
419 | - |
|
420 | - extract($template_args, EXTR_SKIP); |
|
421 | - // because we might want to return a string, we are going to capture the output |
|
422 | - ob_start(); |
|
423 | - include($template_path); |
|
424 | - $template = ob_get_clean(); |
|
425 | - |
|
426 | - if ($return_string) { |
|
427 | - return $template; |
|
428 | - } |
|
429 | - echo wp_kses($template, AllowedTags::getWithFullTags()); |
|
430 | - return ''; |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
436 | - * |
|
437 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
438 | - * @param string $prefix added to the beginning of the generated class |
|
439 | - * @param string $suffix added to the end of the generated class |
|
440 | - * @return string |
|
441 | - * @throws EE_Error |
|
442 | - * @throws ReflectionException |
|
443 | - */ |
|
444 | - public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
445 | - { |
|
446 | - // in the beginning... |
|
447 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
448 | - // da muddle |
|
449 | - $class = ''; |
|
450 | - // the end |
|
451 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
452 | - // is the passed object an EE object ? |
|
453 | - if ($object instanceof EE_Base_Class) { |
|
454 | - // grab the exact type of object |
|
455 | - $obj_class = get_class($object); |
|
456 | - // depending on the type of object... |
|
457 | - // no specifics just yet... |
|
458 | - $class = strtolower(str_replace('_', '-', $obj_class)); |
|
459 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
460 | - } |
|
461 | - return $prefix . $class . $suffix; |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - /** |
|
466 | - * EEH_Template::format_currency |
|
467 | - * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
468 | - * the country currency settings from the supplied country ISO code |
|
469 | - * |
|
470 | - * @param float $amount raw money value |
|
471 | - * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
472 | - * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
473 | - * @param string $CNT_ISO 2-letter ISO code for a country |
|
474 | - * @param string $cur_code_span_class |
|
475 | - * @return string the html output for the formatted money value |
|
476 | - */ |
|
477 | - public static function format_currency( |
|
478 | - $amount = null, |
|
479 | - $return_raw = false, |
|
480 | - $display_code = true, |
|
481 | - $CNT_ISO = '', |
|
482 | - $cur_code_span_class = 'currency-code' |
|
483 | - ) { |
|
484 | - // ensure amount was received |
|
485 | - if ($amount === null) { |
|
486 | - $msg = esc_html__('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
487 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
488 | - return ''; |
|
489 | - } |
|
490 | - // ensure amount is float |
|
491 | - $amount = (float) apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
492 | - $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
493 | - // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
494 | - $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
495 | - // still a number, or was amount converted to a string like "free" ? |
|
496 | - if (! is_float($amount_formatted)) { |
|
497 | - return esc_html($amount_formatted); |
|
498 | - } |
|
499 | - try { |
|
500 | - // was a country ISO code passed ? if so generate currency config object for that country |
|
501 | - $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
502 | - } catch (Exception $e) { |
|
503 | - // eat exception |
|
504 | - $mny = null; |
|
505 | - } |
|
506 | - // verify results |
|
507 | - if (! $mny instanceof EE_Currency_Config) { |
|
508 | - // set default config country currency settings |
|
509 | - $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
510 | - ? EE_Registry::instance()->CFG->currency |
|
511 | - : new EE_Currency_Config(); |
|
512 | - } |
|
513 | - // format float |
|
514 | - $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
515 | - // add formatting ? |
|
516 | - if (! $return_raw) { |
|
517 | - // add currency sign |
|
518 | - if ($mny->sign_b4) { |
|
519 | - if ($amount >= 0) { |
|
520 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
521 | - } else { |
|
522 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
523 | - } |
|
524 | - } else { |
|
525 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
526 | - } |
|
527 | - |
|
528 | - // filter to allow global setting of display_code |
|
529 | - $display_code = (bool) apply_filters( |
|
530 | - 'FHEE__EEH_Template__format_currency__display_code', |
|
531 | - $display_code |
|
532 | - ); |
|
533 | - |
|
534 | - // add currency code ? |
|
535 | - $amount_formatted = $display_code |
|
536 | - ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">' . $mny->code . '</span>' |
|
537 | - : $amount_formatted; |
|
538 | - } |
|
539 | - // filter results |
|
540 | - $amount_formatted = apply_filters( |
|
541 | - 'FHEE__EEH_Template__format_currency__amount_formatted', |
|
542 | - $amount_formatted, |
|
543 | - $mny, |
|
544 | - $return_raw |
|
545 | - ); |
|
546 | - // clean up vars |
|
547 | - unset($mny); |
|
548 | - // return formatted currency amount |
|
549 | - return $amount_formatted; |
|
550 | - } |
|
551 | - |
|
552 | - |
|
553 | - /** |
|
554 | - * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
555 | - * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
556 | - * related status model or model object (i.e. in documentation etc.) |
|
557 | - * |
|
558 | - * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
559 | - * match, then 'Unknown' will be returned. |
|
560 | - * @param boolean $plural Whether to return plural or not |
|
561 | - * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
562 | - * @return string The localized label for the status id. |
|
563 | - * @throws EE_Error |
|
564 | - */ |
|
565 | - public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
566 | - { |
|
567 | - $status = EEM_Status::instance()->localized_status( |
|
568 | - [$status_id => esc_html__('unknown', 'event_espresso')], |
|
569 | - $plural, |
|
570 | - $schema |
|
571 | - ); |
|
572 | - return $status[ $status_id ]; |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - /** |
|
577 | - * This helper just returns a button or link for the given parameters |
|
578 | - * |
|
579 | - * @param string $url the url for the link, note that `esc_url` will be called on it |
|
580 | - * @param string $label What is the label you want displayed for the button |
|
581 | - * @param string $class what class is used for the button (defaults to 'button--primary') |
|
582 | - * @param string $icon |
|
583 | - * @param string $title |
|
584 | - * @return string the html output for the button |
|
585 | - */ |
|
586 | - public static function get_button_or_link($url, $label, $class = 'button button--primary', $icon = '', $title = '') |
|
587 | - { |
|
588 | - $icon_html = ''; |
|
589 | - if (! empty($icon)) { |
|
590 | - $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
591 | - $dashicons = array_filter($dashicons); |
|
592 | - $count = count($dashicons); |
|
593 | - $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
594 | - foreach ($dashicons as $dashicon) { |
|
595 | - $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
596 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
597 | - } |
|
598 | - $icon_html .= $count > 1 ? '</span>' : ''; |
|
599 | - } |
|
600 | - // sanitize & escape |
|
601 | - $id = sanitize_title_with_dashes($label); |
|
602 | - $url = esc_url_raw($url); |
|
603 | - $class = esc_attr($class); |
|
604 | - $title = esc_attr($title); |
|
605 | - $class .= $title ? ' ee-aria-tooltip' : ''; |
|
606 | - $title = $title ? " aria-label='{$title}'" : ''; |
|
607 | - $label = esc_html($label); |
|
608 | - return "<a id='{$id}' href='{$url}' class='{$class}'{$title}>{$icon_html}{$label}</a>"; |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * This returns a generated link that will load the related help tab on admin pages. |
|
614 | - * |
|
615 | - * @param string $help_tab_id the id for the connected help tab |
|
616 | - * @param bool|string $page The page identifier for the page the help tab is on |
|
617 | - * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
618 | - * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
619 | - * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
620 | - * @return string generated link |
|
621 | - */ |
|
622 | - public static function get_help_tab_link( |
|
623 | - $help_tab_id, |
|
624 | - $page = false, |
|
625 | - $action = false, |
|
626 | - $icon_style = false, |
|
627 | - $help_text = false |
|
628 | - ) { |
|
629 | - /** @var RequestInterface $request */ |
|
630 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
631 | - $page = $page ?: $request->getRequestParam('page', '', 'key'); |
|
632 | - $action = $action ?: $request->getRequestParam('action', 'default', 'key'); |
|
633 | - |
|
634 | - |
|
635 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
636 | - $icon = ! $icon_style ? 'dashicons-editor-help' : $icon_style; |
|
637 | - $help_text = ! $help_text ? '' : $help_text; |
|
638 | - return ' |
|
55 | + private static array $_espresso_themes = []; |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
60 | + * |
|
61 | + * @return boolean |
|
62 | + */ |
|
63 | + public static function is_espresso_theme() |
|
64 | + { |
|
65 | + return wp_get_theme()->get('TextDomain') === 'event_espresso'; |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
71 | + * load its functions.php file ( if not already loaded ) |
|
72 | + * |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public static function load_espresso_theme_functions() |
|
76 | + { |
|
77 | + if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
78 | + if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
79 | + require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
80 | + } |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
87 | + * |
|
88 | + * @return array |
|
89 | + */ |
|
90 | + public static function get_espresso_themes(): array |
|
91 | + { |
|
92 | + if (empty(EEH_Template::$_espresso_themes)) { |
|
93 | + $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
94 | + if (empty($espresso_themes)) { |
|
95 | + return []; |
|
96 | + } |
|
97 | + if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
98 | + unset($espresso_themes[ $key ]); |
|
99 | + } |
|
100 | + EEH_Template::$_espresso_themes = []; |
|
101 | + foreach ($espresso_themes as $espresso_theme) { |
|
102 | + EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
103 | + } |
|
104 | + } |
|
105 | + return EEH_Template::$_espresso_themes; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * EEH_Template::get_template_part |
|
111 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
112 | + * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
113 | + * filtering based off of the entire template part name |
|
114 | + * |
|
115 | + * @param string $slug The slug name for the generic template. |
|
116 | + * @param string $name The name of the specialised template. |
|
117 | + * @param array $template_args |
|
118 | + * @param bool $return_string |
|
119 | + * @return string the html output for the formatted money value |
|
120 | + */ |
|
121 | + public static function get_template_part( |
|
122 | + $slug = '', |
|
123 | + $name = '', |
|
124 | + $template_args = [], |
|
125 | + $return_string = false |
|
126 | + ) { |
|
127 | + do_action("get_template_part_$slug-$name", $slug, $name); |
|
128 | + $template = $slug; |
|
129 | + $name = (string) $name; |
|
130 | + if ($name != '') { |
|
131 | + $template .= "-$name"; |
|
132 | + } |
|
133 | + $template .= ".php"; |
|
134 | + // allow template parts to be turned off via something like: |
|
135 | + // add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
136 | + if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_$name", true)) { |
|
137 | + return EEH_Template::locate_template($template, $template_args, true, $return_string); |
|
138 | + } |
|
139 | + return ''; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * locate_template |
|
145 | + * locate a template file by looking in the following places, in the following order: |
|
146 | + * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
147 | + * <assumed full absolute server path> |
|
148 | + * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
149 | + * <server path up to>/wp-content/uploads/espresso/templates/ |
|
150 | + * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
151 | + * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
152 | + * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
153 | + * as soon as the template is found in one of these locations, it will be returned or loaded |
|
154 | + * Example: |
|
155 | + * You are using the WordPress Twenty Sixteen theme, |
|
156 | + * and you want to customize the "some-event.template.php" template, |
|
157 | + * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
158 | + * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
159 | + * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
160 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
161 | + * /relative/path/to/some-event.template.php |
|
162 | + * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
163 | + * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
164 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
165 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
166 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
167 | + * Had you passed an absolute path to your template that was in some other location, |
|
168 | + * ie: "/absolute/path/to/some-event.template.php" |
|
169 | + * then the search would have been : |
|
170 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
171 | + * /absolute/path/to/some-event.template.php |
|
172 | + * and stopped there upon finding it in the second location |
|
173 | + * |
|
174 | + * @param array|string $templates array of template file names including extension (or just a single string) |
|
175 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
176 | + * @param boolean $load whether to pass the located template path on to the |
|
177 | + * EEH_Template::display_template() method or simply return it |
|
178 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
179 | + * string |
|
180 | + * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
181 | + * generate a custom template or not. Used in places where you don't actually |
|
182 | + * load the template, you just want to know if there's a custom version of it. |
|
183 | + * @return string|true |
|
184 | + * @throws DomainException |
|
185 | + * @throws InvalidArgumentException |
|
186 | + * @throws InvalidDataTypeException |
|
187 | + * @throws InvalidInterfaceException |
|
188 | + */ |
|
189 | + public static function locate_template( |
|
190 | + $templates = [], |
|
191 | + array $template_args = [], |
|
192 | + bool $load = true, |
|
193 | + bool $return_string = true, |
|
194 | + bool $check_if_custom = false |
|
195 | + ) { |
|
196 | + $cache_id = TemplateCache::generateCacheID(__FUNCTION__, func_get_args()); |
|
197 | + $template_path = TemplateCache::get($cache_id); |
|
198 | + $template_path = $template_path ?: self::resolveTemplatePath($cache_id, (array) $templates, $check_if_custom); |
|
199 | + |
|
200 | + if ($check_if_custom && ! empty($template_path)) { |
|
201 | + return true; |
|
202 | + } |
|
203 | + |
|
204 | + // if we got it and you want to see it... |
|
205 | + if ($template_path && $load && ! $check_if_custom) { |
|
206 | + if ($return_string) { |
|
207 | + return EEH_Template::display_template($template_path, $template_args, true); |
|
208 | + } |
|
209 | + EEH_Template::display_template($template_path, $template_args); |
|
210 | + } |
|
211 | + return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * Resolves the path of a template by checking various possible locations. |
|
217 | + * |
|
218 | + * This method checks for the existence of a template in several locations, |
|
219 | + * including the current theme folder, the uploads directory, and the plugin's own template directory. |
|
220 | + * It uses the provided cache ID to store and retrieve the resolved path from a cache for performance. |
|
221 | + * If the template is not found in any of the checked locations, an empty string is returned. |
|
222 | + * |
|
223 | + * @param string $cache_id The ID used for caching the resolved path. |
|
224 | + * @param array $templates An array of template file names to search for. |
|
225 | + * @param bool $check_if_custom If true, the method will only check if a custom template exists |
|
226 | + * and won't include core plugin folders. |
|
227 | + * @return string The resolved template path, or an empty string if the template was not found. |
|
228 | + * @since 5.0.21.p |
|
229 | + */ |
|
230 | + private static function resolveTemplatePath(string $cache_id, array $templates, bool $check_if_custom): string |
|
231 | + { |
|
232 | + // first use WP locate_template to check for template in the current theme folder |
|
233 | + $template_path = $templates ? locate_template($templates) : ''; |
|
234 | + // not in the theme |
|
235 | + if (empty($template_path)) { |
|
236 | + // not even a template to look for ? |
|
237 | + if (empty($templates)) { |
|
238 | + $loader = LoaderFactory::getLoader(); |
|
239 | + /** @var RequestInterface $request */ |
|
240 | + $request = $loader->getShared(RequestInterface::class); |
|
241 | + // get post_type |
|
242 | + $post_type = $request->getRequestParam('post_type'); |
|
243 | + /** @var CustomPostTypeDefinitions $custom_post_types */ |
|
244 | + $custom_post_types = $loader->getShared(CustomPostTypeDefinitions::class); |
|
245 | + // get array of EE Custom Post Types |
|
246 | + $EE_CPTs = $custom_post_types->getDefinitions(); |
|
247 | + // build template name based on request |
|
248 | + if (isset($EE_CPTs[ $post_type ])) { |
|
249 | + $archive_or_single = is_archive() ? 'archive' : ''; |
|
250 | + $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
251 | + $templates[] = $archive_or_single . '-' . $post_type . '.php'; |
|
252 | + } |
|
253 | + } |
|
254 | + // currently active EE template theme |
|
255 | + $current_theme = EE_Config::get_current_theme(); |
|
256 | + // array of paths to folders that may contain templates |
|
257 | + $template_folder_paths = [ |
|
258 | + // root of the /wp-content/uploads/espresso/templates/ folder |
|
259 | + EVENT_ESPRESSO_TEMPLATE_DIR |
|
260 | + ]; |
|
261 | + |
|
262 | + // add core plugin folders for checking only if we're not $check_if_custom |
|
263 | + if (! $check_if_custom) { |
|
264 | + $core_paths = [ |
|
265 | + // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
266 | + EE_PUBLIC . $current_theme, |
|
267 | + // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
268 | + EE_TEMPLATES . $current_theme, |
|
269 | + // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
270 | + EE_PLUGIN_DIR_PATH, |
|
271 | + ]; |
|
272 | + $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
273 | + } |
|
274 | + |
|
275 | + // now filter that array |
|
276 | + $template_folder_paths = (array) apply_filters( |
|
277 | + 'FHEE__EEH_Template__locate_template__template_folder_paths', |
|
278 | + $template_folder_paths |
|
279 | + ); |
|
280 | + |
|
281 | + // array to hold all possible template paths |
|
282 | + $full_template_paths = []; |
|
283 | + $file_name = ''; |
|
284 | + |
|
285 | + // loop through $templates |
|
286 | + foreach ($templates as $template) { |
|
287 | + // normalize directory separators |
|
288 | + $template = EEH_File::standardise_directory_separators($template); |
|
289 | + $file_name = basename($template); |
|
290 | + $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
291 | + // while looping through all template folder paths |
|
292 | + foreach ($template_folder_paths as $template_folder_path) { |
|
293 | + // normalize directory separators |
|
294 | + $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
295 | + // determine if any common base path exists between the two paths |
|
296 | + $common_base_path = EEH_Template::_find_common_base_path( |
|
297 | + [$template_folder_path, $template_path_minus_file_name] |
|
298 | + ); |
|
299 | + if ($common_base_path !== '') { |
|
300 | + // both paths have a common base, so just tack the filename onto our search path |
|
301 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
302 | + } else { |
|
303 | + // no common base path, so let's just concatenate |
|
304 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
305 | + } |
|
306 | + // build up our template locations array by adding our resolved paths |
|
307 | + $full_template_paths[] = $resolved_path; |
|
308 | + } |
|
309 | + // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
310 | + array_unshift($full_template_paths, $template); |
|
311 | + // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
312 | + array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
313 | + } |
|
314 | + // filter final array of full template paths |
|
315 | + $full_template_paths = apply_filters( |
|
316 | + 'FHEE__EEH_Template__locate_template__full_template_paths', |
|
317 | + $full_template_paths, |
|
318 | + $file_name |
|
319 | + ); |
|
320 | + // now loop through our final array of template location paths and check each location |
|
321 | + foreach ((array) $full_template_paths as $full_template_path) { |
|
322 | + if (is_readable($full_template_path)) { |
|
323 | + $template_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $full_template_path); |
|
324 | + TemplateCache::set($cache_id, $template_path); |
|
325 | + break; |
|
326 | + } |
|
327 | + } |
|
328 | + } |
|
329 | + |
|
330 | + // Display a deprecated notice if the template file is located in the WordPress uploads directory |
|
331 | + if (strpos($template_path, 'wp-content/uploads/espresso') !== false) { |
|
332 | + EE_Error::doing_it_wrong( |
|
333 | + __CLASS__, |
|
334 | + esc_html__( |
|
335 | + 'The use of the WordPress uploads directory as a location to override template files has been deprecated.', |
|
336 | + 'event_espresso' |
|
337 | + ), |
|
338 | + '5.0.0' |
|
339 | + ); |
|
340 | + } |
|
341 | + |
|
342 | + // hook that can be used to display the full template path that will be used |
|
343 | + do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
344 | + |
|
345 | + return $template_path; |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * _find_common_base_path |
|
351 | + * given two paths, this determines if there is a common base path between the two |
|
352 | + * |
|
353 | + * @param array $paths |
|
354 | + * @return string |
|
355 | + */ |
|
356 | + protected static function _find_common_base_path($paths) |
|
357 | + { |
|
358 | + $last_offset = 0; |
|
359 | + $common_base_path = ''; |
|
360 | + while (($index = strpos($paths[0], '/', $last_offset)) !== false) { |
|
361 | + $dir_length = $index - $last_offset + 1; |
|
362 | + $directory = substr($paths[0], $last_offset, $dir_length); |
|
363 | + foreach ($paths as $path) { |
|
364 | + if (substr($path, $last_offset, $dir_length) != $directory) { |
|
365 | + return $common_base_path; |
|
366 | + } |
|
367 | + } |
|
368 | + $common_base_path .= $directory; |
|
369 | + $last_offset = $index + 1; |
|
370 | + } |
|
371 | + return substr($common_base_path, 0, -1); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * load and display a template |
|
377 | + * |
|
378 | + * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
379 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
380 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
381 | + * string |
|
382 | + * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
383 | + * not found or is not readable |
|
384 | + * @return string |
|
385 | + * @throws DomainException |
|
386 | + */ |
|
387 | + public static function display_template( |
|
388 | + $template_path = '', |
|
389 | + $template_args = [], |
|
390 | + $return_string = false, |
|
391 | + $throw_exceptions = false |
|
392 | + ) { |
|
393 | + /** |
|
394 | + * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
395 | + * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
396 | + * the display_template method are templates we DON'T want modified (usually because of js |
|
397 | + * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
398 | + * using this. |
|
399 | + * |
|
400 | + * @since 4.6.0 |
|
401 | + */ |
|
402 | + $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
403 | + $template_args = (array) apply_filters( |
|
404 | + 'FHEE__EEH_Template__display_template__template_args', |
|
405 | + $template_args, |
|
406 | + $template_path |
|
407 | + ); |
|
408 | + |
|
409 | + // you gimme nuttin - YOU GET NUTTIN !! |
|
410 | + if (! $template_path || ! is_readable($template_path)) { |
|
411 | + // ignore whether template is accessible ? |
|
412 | + if ($throw_exceptions) { |
|
413 | + throw new DomainException( |
|
414 | + esc_html__('Invalid, unreadable, or missing file.', 'event_espresso') |
|
415 | + ); |
|
416 | + } |
|
417 | + return ''; |
|
418 | + } |
|
419 | + |
|
420 | + extract($template_args, EXTR_SKIP); |
|
421 | + // because we might want to return a string, we are going to capture the output |
|
422 | + ob_start(); |
|
423 | + include($template_path); |
|
424 | + $template = ob_get_clean(); |
|
425 | + |
|
426 | + if ($return_string) { |
|
427 | + return $template; |
|
428 | + } |
|
429 | + echo wp_kses($template, AllowedTags::getWithFullTags()); |
|
430 | + return ''; |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
436 | + * |
|
437 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
438 | + * @param string $prefix added to the beginning of the generated class |
|
439 | + * @param string $suffix added to the end of the generated class |
|
440 | + * @return string |
|
441 | + * @throws EE_Error |
|
442 | + * @throws ReflectionException |
|
443 | + */ |
|
444 | + public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
445 | + { |
|
446 | + // in the beginning... |
|
447 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
448 | + // da muddle |
|
449 | + $class = ''; |
|
450 | + // the end |
|
451 | + $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
452 | + // is the passed object an EE object ? |
|
453 | + if ($object instanceof EE_Base_Class) { |
|
454 | + // grab the exact type of object |
|
455 | + $obj_class = get_class($object); |
|
456 | + // depending on the type of object... |
|
457 | + // no specifics just yet... |
|
458 | + $class = strtolower(str_replace('_', '-', $obj_class)); |
|
459 | + $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
460 | + } |
|
461 | + return $prefix . $class . $suffix; |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + /** |
|
466 | + * EEH_Template::format_currency |
|
467 | + * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
468 | + * the country currency settings from the supplied country ISO code |
|
469 | + * |
|
470 | + * @param float $amount raw money value |
|
471 | + * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
472 | + * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
473 | + * @param string $CNT_ISO 2-letter ISO code for a country |
|
474 | + * @param string $cur_code_span_class |
|
475 | + * @return string the html output for the formatted money value |
|
476 | + */ |
|
477 | + public static function format_currency( |
|
478 | + $amount = null, |
|
479 | + $return_raw = false, |
|
480 | + $display_code = true, |
|
481 | + $CNT_ISO = '', |
|
482 | + $cur_code_span_class = 'currency-code' |
|
483 | + ) { |
|
484 | + // ensure amount was received |
|
485 | + if ($amount === null) { |
|
486 | + $msg = esc_html__('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
487 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
488 | + return ''; |
|
489 | + } |
|
490 | + // ensure amount is float |
|
491 | + $amount = (float) apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
492 | + $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
493 | + // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
494 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
495 | + // still a number, or was amount converted to a string like "free" ? |
|
496 | + if (! is_float($amount_formatted)) { |
|
497 | + return esc_html($amount_formatted); |
|
498 | + } |
|
499 | + try { |
|
500 | + // was a country ISO code passed ? if so generate currency config object for that country |
|
501 | + $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
502 | + } catch (Exception $e) { |
|
503 | + // eat exception |
|
504 | + $mny = null; |
|
505 | + } |
|
506 | + // verify results |
|
507 | + if (! $mny instanceof EE_Currency_Config) { |
|
508 | + // set default config country currency settings |
|
509 | + $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
510 | + ? EE_Registry::instance()->CFG->currency |
|
511 | + : new EE_Currency_Config(); |
|
512 | + } |
|
513 | + // format float |
|
514 | + $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
515 | + // add formatting ? |
|
516 | + if (! $return_raw) { |
|
517 | + // add currency sign |
|
518 | + if ($mny->sign_b4) { |
|
519 | + if ($amount >= 0) { |
|
520 | + $amount_formatted = $mny->sign . $amount_formatted; |
|
521 | + } else { |
|
522 | + $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
523 | + } |
|
524 | + } else { |
|
525 | + $amount_formatted = $amount_formatted . $mny->sign; |
|
526 | + } |
|
527 | + |
|
528 | + // filter to allow global setting of display_code |
|
529 | + $display_code = (bool) apply_filters( |
|
530 | + 'FHEE__EEH_Template__format_currency__display_code', |
|
531 | + $display_code |
|
532 | + ); |
|
533 | + |
|
534 | + // add currency code ? |
|
535 | + $amount_formatted = $display_code |
|
536 | + ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">' . $mny->code . '</span>' |
|
537 | + : $amount_formatted; |
|
538 | + } |
|
539 | + // filter results |
|
540 | + $amount_formatted = apply_filters( |
|
541 | + 'FHEE__EEH_Template__format_currency__amount_formatted', |
|
542 | + $amount_formatted, |
|
543 | + $mny, |
|
544 | + $return_raw |
|
545 | + ); |
|
546 | + // clean up vars |
|
547 | + unset($mny); |
|
548 | + // return formatted currency amount |
|
549 | + return $amount_formatted; |
|
550 | + } |
|
551 | + |
|
552 | + |
|
553 | + /** |
|
554 | + * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
555 | + * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
556 | + * related status model or model object (i.e. in documentation etc.) |
|
557 | + * |
|
558 | + * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
559 | + * match, then 'Unknown' will be returned. |
|
560 | + * @param boolean $plural Whether to return plural or not |
|
561 | + * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
562 | + * @return string The localized label for the status id. |
|
563 | + * @throws EE_Error |
|
564 | + */ |
|
565 | + public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
566 | + { |
|
567 | + $status = EEM_Status::instance()->localized_status( |
|
568 | + [$status_id => esc_html__('unknown', 'event_espresso')], |
|
569 | + $plural, |
|
570 | + $schema |
|
571 | + ); |
|
572 | + return $status[ $status_id ]; |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + /** |
|
577 | + * This helper just returns a button or link for the given parameters |
|
578 | + * |
|
579 | + * @param string $url the url for the link, note that `esc_url` will be called on it |
|
580 | + * @param string $label What is the label you want displayed for the button |
|
581 | + * @param string $class what class is used for the button (defaults to 'button--primary') |
|
582 | + * @param string $icon |
|
583 | + * @param string $title |
|
584 | + * @return string the html output for the button |
|
585 | + */ |
|
586 | + public static function get_button_or_link($url, $label, $class = 'button button--primary', $icon = '', $title = '') |
|
587 | + { |
|
588 | + $icon_html = ''; |
|
589 | + if (! empty($icon)) { |
|
590 | + $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
591 | + $dashicons = array_filter($dashicons); |
|
592 | + $count = count($dashicons); |
|
593 | + $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
594 | + foreach ($dashicons as $dashicon) { |
|
595 | + $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
596 | + $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
597 | + } |
|
598 | + $icon_html .= $count > 1 ? '</span>' : ''; |
|
599 | + } |
|
600 | + // sanitize & escape |
|
601 | + $id = sanitize_title_with_dashes($label); |
|
602 | + $url = esc_url_raw($url); |
|
603 | + $class = esc_attr($class); |
|
604 | + $title = esc_attr($title); |
|
605 | + $class .= $title ? ' ee-aria-tooltip' : ''; |
|
606 | + $title = $title ? " aria-label='{$title}'" : ''; |
|
607 | + $label = esc_html($label); |
|
608 | + return "<a id='{$id}' href='{$url}' class='{$class}'{$title}>{$icon_html}{$label}</a>"; |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * This returns a generated link that will load the related help tab on admin pages. |
|
614 | + * |
|
615 | + * @param string $help_tab_id the id for the connected help tab |
|
616 | + * @param bool|string $page The page identifier for the page the help tab is on |
|
617 | + * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
618 | + * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
619 | + * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
620 | + * @return string generated link |
|
621 | + */ |
|
622 | + public static function get_help_tab_link( |
|
623 | + $help_tab_id, |
|
624 | + $page = false, |
|
625 | + $action = false, |
|
626 | + $icon_style = false, |
|
627 | + $help_text = false |
|
628 | + ) { |
|
629 | + /** @var RequestInterface $request */ |
|
630 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
631 | + $page = $page ?: $request->getRequestParam('page', '', 'key'); |
|
632 | + $action = $action ?: $request->getRequestParam('action', 'default', 'key'); |
|
633 | + |
|
634 | + |
|
635 | + $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
636 | + $icon = ! $icon_style ? 'dashicons-editor-help' : $icon_style; |
|
637 | + $help_text = ! $help_text ? '' : $help_text; |
|
638 | + return ' |
|
639 | 639 | <a id="' . esc_attr($help_tab_lnk) . '" |
640 | 640 | class="espresso-help-tab-lnk ee-help-btn ee-aria-tooltip dashicons ' . esc_attr($icon) . '" |
641 | 641 | aria-label="' . esc_attr__( |
642 | - 'Click to open the \'Help\' tab for more information about this feature.', |
|
643 | - 'event_espresso' |
|
644 | - ) . '" |
|
642 | + 'Click to open the \'Help\' tab for more information about this feature.', |
|
643 | + 'event_espresso' |
|
644 | + ) . '" |
|
645 | 645 | > |
646 | 646 | ' . wp_kses($help_text, AllowedTags::getAllowedTags()) . ' |
647 | 647 | </a>'; |
648 | - } |
|
649 | - |
|
650 | - |
|
651 | - /** |
|
652 | - * This is a helper method to generate a status legend for a given status array. |
|
653 | - * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
654 | - * status_array. |
|
655 | - * |
|
656 | - * @param array $status_array array of statuses that will make up the legend. In format: |
|
657 | - * array( |
|
658 | - * 'status_item' => 'status_name' |
|
659 | - * ) |
|
660 | - * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
661 | - * the legend. |
|
662 | - * @return string html structure for status. |
|
663 | - * @throws EE_Error |
|
664 | - */ |
|
665 | - public static function status_legend($status_array, $active_status = '') |
|
666 | - { |
|
667 | - if (! is_array($status_array)) { |
|
668 | - throw new EE_Error( |
|
669 | - esc_html__( |
|
670 | - 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
671 | - 'event_espresso' |
|
672 | - ) |
|
673 | - ); |
|
674 | - } |
|
675 | - |
|
676 | - $content = ' |
|
648 | + } |
|
649 | + |
|
650 | + |
|
651 | + /** |
|
652 | + * This is a helper method to generate a status legend for a given status array. |
|
653 | + * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
654 | + * status_array. |
|
655 | + * |
|
656 | + * @param array $status_array array of statuses that will make up the legend. In format: |
|
657 | + * array( |
|
658 | + * 'status_item' => 'status_name' |
|
659 | + * ) |
|
660 | + * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
661 | + * the legend. |
|
662 | + * @return string html structure for status. |
|
663 | + * @throws EE_Error |
|
664 | + */ |
|
665 | + public static function status_legend($status_array, $active_status = '') |
|
666 | + { |
|
667 | + if (! is_array($status_array)) { |
|
668 | + throw new EE_Error( |
|
669 | + esc_html__( |
|
670 | + 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
671 | + 'event_espresso' |
|
672 | + ) |
|
673 | + ); |
|
674 | + } |
|
675 | + |
|
676 | + $content = ' |
|
677 | 677 | <div class="ee-list-table-legend-container"> |
678 | 678 | <h4 class="status-legend-title"> |
679 | 679 | ' . esc_html__('Status Legend', 'event_espresso') . ' |
680 | 680 | </h4> |
681 | 681 | <dl class="ee-list-table-legend">'; |
682 | 682 | |
683 | - foreach ($status_array as $item => $status) { |
|
684 | - $active_class = $active_status == $status ? 'class="ee-is-active-status"' : ''; |
|
685 | - $content .= ' |
|
683 | + foreach ($status_array as $item => $status) { |
|
684 | + $active_class = $active_status == $status ? 'class="ee-is-active-status"' : ''; |
|
685 | + $content .= ' |
|
686 | 686 | <dt id="' . esc_attr('ee-legend-item-tooltip-' . $item) . '" ' . $active_class . '> |
687 | 687 | <span class="' . esc_attr('ee-status-legend ee-status-bg--' . $status) . '"></span> |
688 | 688 | <span class="ee-legend-description"> |
689 | 689 | ' . EEH_Template::pretty_status($status, false, 'sentence') . ' |
690 | 690 | </span> |
691 | 691 | </dt>'; |
692 | - } |
|
692 | + } |
|
693 | 693 | |
694 | - $content .= ' |
|
694 | + $content .= ' |
|
695 | 695 | </dl> |
696 | 696 | </div> |
697 | 697 | '; |
698 | - return $content; |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - /** |
|
703 | - * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
704 | - * that's nice for presenting in the wp admin |
|
705 | - * |
|
706 | - * @param mixed $data |
|
707 | - * @return string |
|
708 | - */ |
|
709 | - public static function layout_array_as_table($data) |
|
710 | - { |
|
711 | - if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
712 | - $data = (array) $data; |
|
713 | - } |
|
714 | - ob_start(); |
|
715 | - if (is_array($data)) { |
|
716 | - if (EEH_Array::is_associative_array($data)) { ?> |
|
698 | + return $content; |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + /** |
|
703 | + * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
704 | + * that's nice for presenting in the wp admin |
|
705 | + * |
|
706 | + * @param mixed $data |
|
707 | + * @return string |
|
708 | + */ |
|
709 | + public static function layout_array_as_table($data) |
|
710 | + { |
|
711 | + if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
712 | + $data = (array) $data; |
|
713 | + } |
|
714 | + ob_start(); |
|
715 | + if (is_array($data)) { |
|
716 | + if (EEH_Array::is_associative_array($data)) { ?> |
|
717 | 717 | <table class="widefat"> |
718 | 718 | <tbody> |
719 | 719 | <?php foreach ($data as $data_key => $data_values) { ?> |
@@ -731,304 +731,304 @@ discard block |
||
731 | 731 | <?php } else { ?> |
732 | 732 | <ul> |
733 | 733 | <?php |
734 | - foreach ($data as $datum) { |
|
735 | - echo "<li>"; |
|
736 | - echo self::layout_array_as_table($datum); |
|
737 | - echo "</li>"; |
|
738 | - } ?> |
|
734 | + foreach ($data as $datum) { |
|
735 | + echo "<li>"; |
|
736 | + echo self::layout_array_as_table($datum); |
|
737 | + echo "</li>"; |
|
738 | + } ?> |
|
739 | 739 | </ul> |
740 | 740 | <?php } |
741 | - } else { |
|
742 | - // simple value |
|
743 | - echo esc_html($data); |
|
744 | - } |
|
745 | - return ob_get_clean(); |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
751 | - * |
|
752 | - * @param $total_items |
|
753 | - * @param $current |
|
754 | - * @param $per_page |
|
755 | - * @param $url |
|
756 | - * @param bool $show_num_field |
|
757 | - * @param string $paged_arg_name |
|
758 | - * @param array $items_label |
|
759 | - * @see self:get_paging_html() for argument docs. |
|
760 | - * @since 4.4.0 |
|
761 | - */ |
|
762 | - public static function paging_html( |
|
763 | - $total_items, |
|
764 | - $current, |
|
765 | - $per_page, |
|
766 | - $url, |
|
767 | - $show_num_field = true, |
|
768 | - $paged_arg_name = 'paged', |
|
769 | - $items_label = [] |
|
770 | - ) { |
|
771 | - echo self::get_paging_html( |
|
772 | - $total_items, |
|
773 | - $current, |
|
774 | - $per_page, |
|
775 | - $url, |
|
776 | - $show_num_field, |
|
777 | - $paged_arg_name, |
|
778 | - $items_label |
|
779 | - ); |
|
780 | - } |
|
781 | - |
|
782 | - |
|
783 | - /** |
|
784 | - * A method for generating paging similar to WP_List_Table |
|
785 | - * |
|
786 | - * @param int $total_items How many total items there are to page. |
|
787 | - * @param int $current What the current page is. |
|
788 | - * @param int $per_page How many items per page. |
|
789 | - * @param string $url What the base url for page links is. |
|
790 | - * @param bool $show_num_field Whether to show the input for changing page number. |
|
791 | - * @param string $paged_arg_name The name of the key for the paged query argument. |
|
792 | - * @param array $items_label An array of singular/plural values for the items label: |
|
793 | - * array( |
|
794 | - * 'single' => 'item', |
|
795 | - * 'plural' => 'items' |
|
796 | - * ) |
|
797 | - * @return string |
|
798 | - * @since 4.4.0 |
|
799 | - * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
800 | - */ |
|
801 | - public static function get_paging_html( |
|
802 | - int $total_items, |
|
803 | - int $current, |
|
804 | - int $per_page, |
|
805 | - string $url, |
|
806 | - bool $show_num_field = true, |
|
807 | - string $paged_arg_name = 'paged', |
|
808 | - array $items_label = [], |
|
809 | - string $button_size = 'small' |
|
810 | - ): string { |
|
811 | - $page_links = []; |
|
812 | - $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
813 | - |
|
814 | - // filter items_label |
|
815 | - $items_label = apply_filters( |
|
816 | - 'FHEE__EEH_Template__get_paging_html__items_label', |
|
817 | - $items_label |
|
818 | - ); |
|
819 | - |
|
820 | - if ( |
|
821 | - empty($items_label) |
|
822 | - || ! is_array($items_label) |
|
823 | - || ! isset($items_label['single']) |
|
824 | - || ! isset($items_label['plural']) |
|
825 | - ) { |
|
826 | - $items_label = [ |
|
827 | - 'single' => esc_html__('1 item', 'event_espresso'), |
|
828 | - 'plural' => esc_html__('%s items', 'event_espresso'), |
|
829 | - ]; |
|
830 | - } else { |
|
831 | - $items_label = [ |
|
832 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
833 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
834 | - ]; |
|
835 | - } |
|
836 | - |
|
837 | - $total_pages = (int) ceil($total_items / $per_page); |
|
838 | - |
|
839 | - if ($total_pages <= 1) { |
|
840 | - return ''; |
|
841 | - } |
|
842 | - |
|
843 | - $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
844 | - |
|
845 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
846 | - |
|
847 | - $disable_first = $current === 1 ? 'disabled' : ''; |
|
848 | - $disable_last = $current === $total_pages ? 'disabled' : ''; |
|
849 | - |
|
850 | - $button_size = in_array($button_size, ['tiny', 'small', 'default', 'big']) ? $button_size : 'small'; |
|
851 | - $button_classes = "button button--secondary button--icon-only button--$button_size"; |
|
852 | - |
|
853 | - $page_links[] = sprintf( |
|
854 | - '<a class="%s" aria-label="%s" href="%s"><span class="ee-pagination-arrow">%s</span></a>', |
|
855 | - esc_attr("first-page $button_classes $disable_first"), |
|
856 | - esc_attr__('Go to the first page', 'event_espresso'), |
|
857 | - esc_url_raw(remove_query_arg($paged_arg_name, $url)), |
|
858 | - '«' |
|
859 | - ); |
|
860 | - |
|
861 | - $page_links[] = sprintf( |
|
862 | - '<a class="%s" aria-label="%s" href="%s"><span class="ee-pagination-arrow">%s</span></a>', |
|
863 | - esc_attr("prev-page $button_classes $disable_first"), |
|
864 | - esc_attr__('Go to the previous page', 'event_espresso'), |
|
865 | - esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
866 | - '‹' |
|
867 | - ); |
|
868 | - |
|
869 | - $html_current_page = $show_num_field |
|
870 | - ? sprintf( |
|
871 | - "<input class='current-page ee-input-size--small' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
872 | - esc_attr__('Current page', 'event_espresso'), |
|
873 | - esc_attr($current), |
|
874 | - strlen($total_pages) |
|
875 | - ) |
|
876 | - : $current; |
|
877 | - |
|
878 | - $html_total_pages = sprintf( |
|
879 | - '<span class="total-pages">%s</span>', |
|
880 | - number_format_i18n($total_pages) |
|
881 | - ); |
|
882 | - $page_links[] = sprintf( |
|
883 | - _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
|
884 | - "{$html_current_page}<span class='paging-input-of'>", |
|
885 | - "</span>{$html_total_pages}", |
|
886 | - '<span class="paging-input">', |
|
887 | - '</span>' |
|
888 | - ); |
|
889 | - |
|
890 | - $page_links[] = sprintf( |
|
891 | - '<a class="%s" aria-label="%s" href="%s"><span class="ee-pagination-arrow">%s</span></a>', |
|
892 | - esc_attr("next-page $button_classes $disable_last"), |
|
893 | - esc_attr__('Go to the next page', 'event_espresso'), |
|
894 | - esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
895 | - '›' |
|
896 | - ); |
|
897 | - |
|
898 | - $page_links[] = sprintf( |
|
899 | - '<a class="%s" aria-label="%s" href="%s"><span class="ee-pagination-arrow">%s</span></a>', |
|
900 | - esc_attr("last-page $button_classes $disable_last"), |
|
901 | - esc_attr__('Go to the last page', 'event_espresso'), |
|
902 | - esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
903 | - '»' |
|
904 | - ); |
|
905 | - |
|
906 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
907 | - |
|
908 | - $page_class = ' no-pages'; |
|
909 | - if ($total_pages) { |
|
910 | - $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
911 | - } |
|
912 | - |
|
913 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
914 | - } |
|
915 | - |
|
916 | - |
|
917 | - /** |
|
918 | - * @param string|null $wrap_class |
|
919 | - * @param string|null $wrap_id |
|
920 | - * @param array $query_args |
|
921 | - * @return string |
|
922 | - */ |
|
923 | - public static function powered_by_event_espresso( |
|
924 | - ?string $wrap_class = '', |
|
925 | - ?string $wrap_id = '', |
|
926 | - array $query_args = [] |
|
927 | - ): string { |
|
928 | - $request = LoaderFactory::getShared(RequestInterface::class); |
|
929 | - if ( |
|
930 | - $request->isActivation() |
|
931 | - || strpos($request->requestUri(true), 'wp-admin/update.php') !== false |
|
932 | - ) { |
|
933 | - return ''; |
|
934 | - } |
|
935 | - $cache_id = TemplateCache::generateCacheID(__FUNCTION__, func_get_args()); |
|
936 | - $cache = TemplateCache::get($cache_id); |
|
937 | - if ($cache) { |
|
938 | - return $cache; |
|
939 | - } |
|
940 | - |
|
941 | - $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
942 | - if ( |
|
943 | - ! $admin |
|
944 | - && ! apply_filters( |
|
945 | - 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
946 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
947 | - ) |
|
948 | - ) { |
|
949 | - return ''; |
|
950 | - } |
|
951 | - $tag = $admin ? 'span' : 'div'; |
|
952 | - $attributes = ! empty($wrap_id) ? " id='$wrap_id'" : ''; |
|
953 | - $wrap_class = $admin ? "$wrap_class ee-layout-row ee-layout-row--inline" : $wrap_class; |
|
954 | - $attributes .= ! empty($wrap_class) |
|
955 | - ? " class='$wrap_class powered-by-event-espresso-credit'" |
|
956 | - : ' class="powered-by-event-espresso-credit"'; |
|
957 | - $query_args = array_merge( |
|
958 | - [ |
|
959 | - 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
960 | - 'utm_source' => 'powered_by_event_espresso', |
|
961 | - 'utm_medium' => 'link', |
|
962 | - 'utm_campaign' => 'powered_by', |
|
963 | - ], |
|
964 | - $query_args |
|
965 | - ); |
|
966 | - $powered_by = apply_filters( |
|
967 | - 'FHEE__EEH_Template__powered_by_event_espresso_text', |
|
968 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
969 | - ); |
|
970 | - $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
971 | - $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
972 | - $template = (string) apply_filters( |
|
973 | - 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
974 | - sprintf( |
|
975 | - esc_html_x( |
|
976 | - '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
977 | - 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
978 | - 'event_espresso' |
|
979 | - ), |
|
980 | - "<$tag$attributes style='margin-inline:.5rem;'>", |
|
981 | - " <a href='$url' target='_blank' rel='nofollow' style='margin-inline: .25rem;'>$powered_by</a></$tag> ", |
|
982 | - $admin ? '' : '<br />' |
|
983 | - ), |
|
984 | - $wrap_class, |
|
985 | - $wrap_id |
|
986 | - ); |
|
987 | - TemplateCache::set($cache_id, $template); |
|
988 | - return $template; |
|
989 | - } |
|
990 | - |
|
991 | - |
|
992 | - /** |
|
993 | - * @param string $image_name |
|
994 | - * @return string|null |
|
995 | - * @since 4.10.14.p |
|
996 | - */ |
|
997 | - public static function getScreenshotUrl($image_name) |
|
998 | - { |
|
999 | - return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg'); |
|
1000 | - } |
|
741 | + } else { |
|
742 | + // simple value |
|
743 | + echo esc_html($data); |
|
744 | + } |
|
745 | + return ob_get_clean(); |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
751 | + * |
|
752 | + * @param $total_items |
|
753 | + * @param $current |
|
754 | + * @param $per_page |
|
755 | + * @param $url |
|
756 | + * @param bool $show_num_field |
|
757 | + * @param string $paged_arg_name |
|
758 | + * @param array $items_label |
|
759 | + * @see self:get_paging_html() for argument docs. |
|
760 | + * @since 4.4.0 |
|
761 | + */ |
|
762 | + public static function paging_html( |
|
763 | + $total_items, |
|
764 | + $current, |
|
765 | + $per_page, |
|
766 | + $url, |
|
767 | + $show_num_field = true, |
|
768 | + $paged_arg_name = 'paged', |
|
769 | + $items_label = [] |
|
770 | + ) { |
|
771 | + echo self::get_paging_html( |
|
772 | + $total_items, |
|
773 | + $current, |
|
774 | + $per_page, |
|
775 | + $url, |
|
776 | + $show_num_field, |
|
777 | + $paged_arg_name, |
|
778 | + $items_label |
|
779 | + ); |
|
780 | + } |
|
781 | + |
|
782 | + |
|
783 | + /** |
|
784 | + * A method for generating paging similar to WP_List_Table |
|
785 | + * |
|
786 | + * @param int $total_items How many total items there are to page. |
|
787 | + * @param int $current What the current page is. |
|
788 | + * @param int $per_page How many items per page. |
|
789 | + * @param string $url What the base url for page links is. |
|
790 | + * @param bool $show_num_field Whether to show the input for changing page number. |
|
791 | + * @param string $paged_arg_name The name of the key for the paged query argument. |
|
792 | + * @param array $items_label An array of singular/plural values for the items label: |
|
793 | + * array( |
|
794 | + * 'single' => 'item', |
|
795 | + * 'plural' => 'items' |
|
796 | + * ) |
|
797 | + * @return string |
|
798 | + * @since 4.4.0 |
|
799 | + * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
800 | + */ |
|
801 | + public static function get_paging_html( |
|
802 | + int $total_items, |
|
803 | + int $current, |
|
804 | + int $per_page, |
|
805 | + string $url, |
|
806 | + bool $show_num_field = true, |
|
807 | + string $paged_arg_name = 'paged', |
|
808 | + array $items_label = [], |
|
809 | + string $button_size = 'small' |
|
810 | + ): string { |
|
811 | + $page_links = []; |
|
812 | + $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
813 | + |
|
814 | + // filter items_label |
|
815 | + $items_label = apply_filters( |
|
816 | + 'FHEE__EEH_Template__get_paging_html__items_label', |
|
817 | + $items_label |
|
818 | + ); |
|
819 | + |
|
820 | + if ( |
|
821 | + empty($items_label) |
|
822 | + || ! is_array($items_label) |
|
823 | + || ! isset($items_label['single']) |
|
824 | + || ! isset($items_label['plural']) |
|
825 | + ) { |
|
826 | + $items_label = [ |
|
827 | + 'single' => esc_html__('1 item', 'event_espresso'), |
|
828 | + 'plural' => esc_html__('%s items', 'event_espresso'), |
|
829 | + ]; |
|
830 | + } else { |
|
831 | + $items_label = [ |
|
832 | + 'single' => '1 ' . esc_html($items_label['single']), |
|
833 | + 'plural' => '%s ' . esc_html($items_label['plural']), |
|
834 | + ]; |
|
835 | + } |
|
836 | + |
|
837 | + $total_pages = (int) ceil($total_items / $per_page); |
|
838 | + |
|
839 | + if ($total_pages <= 1) { |
|
840 | + return ''; |
|
841 | + } |
|
842 | + |
|
843 | + $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
844 | + |
|
845 | + $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
846 | + |
|
847 | + $disable_first = $current === 1 ? 'disabled' : ''; |
|
848 | + $disable_last = $current === $total_pages ? 'disabled' : ''; |
|
849 | + |
|
850 | + $button_size = in_array($button_size, ['tiny', 'small', 'default', 'big']) ? $button_size : 'small'; |
|
851 | + $button_classes = "button button--secondary button--icon-only button--$button_size"; |
|
852 | + |
|
853 | + $page_links[] = sprintf( |
|
854 | + '<a class="%s" aria-label="%s" href="%s"><span class="ee-pagination-arrow">%s</span></a>', |
|
855 | + esc_attr("first-page $button_classes $disable_first"), |
|
856 | + esc_attr__('Go to the first page', 'event_espresso'), |
|
857 | + esc_url_raw(remove_query_arg($paged_arg_name, $url)), |
|
858 | + '«' |
|
859 | + ); |
|
860 | + |
|
861 | + $page_links[] = sprintf( |
|
862 | + '<a class="%s" aria-label="%s" href="%s"><span class="ee-pagination-arrow">%s</span></a>', |
|
863 | + esc_attr("prev-page $button_classes $disable_first"), |
|
864 | + esc_attr__('Go to the previous page', 'event_espresso'), |
|
865 | + esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
866 | + '‹' |
|
867 | + ); |
|
868 | + |
|
869 | + $html_current_page = $show_num_field |
|
870 | + ? sprintf( |
|
871 | + "<input class='current-page ee-input-size--small' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
872 | + esc_attr__('Current page', 'event_espresso'), |
|
873 | + esc_attr($current), |
|
874 | + strlen($total_pages) |
|
875 | + ) |
|
876 | + : $current; |
|
877 | + |
|
878 | + $html_total_pages = sprintf( |
|
879 | + '<span class="total-pages">%s</span>', |
|
880 | + number_format_i18n($total_pages) |
|
881 | + ); |
|
882 | + $page_links[] = sprintf( |
|
883 | + _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
|
884 | + "{$html_current_page}<span class='paging-input-of'>", |
|
885 | + "</span>{$html_total_pages}", |
|
886 | + '<span class="paging-input">', |
|
887 | + '</span>' |
|
888 | + ); |
|
889 | + |
|
890 | + $page_links[] = sprintf( |
|
891 | + '<a class="%s" aria-label="%s" href="%s"><span class="ee-pagination-arrow">%s</span></a>', |
|
892 | + esc_attr("next-page $button_classes $disable_last"), |
|
893 | + esc_attr__('Go to the next page', 'event_espresso'), |
|
894 | + esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
895 | + '›' |
|
896 | + ); |
|
897 | + |
|
898 | + $page_links[] = sprintf( |
|
899 | + '<a class="%s" aria-label="%s" href="%s"><span class="ee-pagination-arrow">%s</span></a>', |
|
900 | + esc_attr("last-page $button_classes $disable_last"), |
|
901 | + esc_attr__('Go to the last page', 'event_espresso'), |
|
902 | + esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
903 | + '»' |
|
904 | + ); |
|
905 | + |
|
906 | + $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
907 | + |
|
908 | + $page_class = ' no-pages'; |
|
909 | + if ($total_pages) { |
|
910 | + $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
911 | + } |
|
912 | + |
|
913 | + return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
914 | + } |
|
915 | + |
|
916 | + |
|
917 | + /** |
|
918 | + * @param string|null $wrap_class |
|
919 | + * @param string|null $wrap_id |
|
920 | + * @param array $query_args |
|
921 | + * @return string |
|
922 | + */ |
|
923 | + public static function powered_by_event_espresso( |
|
924 | + ?string $wrap_class = '', |
|
925 | + ?string $wrap_id = '', |
|
926 | + array $query_args = [] |
|
927 | + ): string { |
|
928 | + $request = LoaderFactory::getShared(RequestInterface::class); |
|
929 | + if ( |
|
930 | + $request->isActivation() |
|
931 | + || strpos($request->requestUri(true), 'wp-admin/update.php') !== false |
|
932 | + ) { |
|
933 | + return ''; |
|
934 | + } |
|
935 | + $cache_id = TemplateCache::generateCacheID(__FUNCTION__, func_get_args()); |
|
936 | + $cache = TemplateCache::get($cache_id); |
|
937 | + if ($cache) { |
|
938 | + return $cache; |
|
939 | + } |
|
940 | + |
|
941 | + $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
942 | + if ( |
|
943 | + ! $admin |
|
944 | + && ! apply_filters( |
|
945 | + 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
946 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
947 | + ) |
|
948 | + ) { |
|
949 | + return ''; |
|
950 | + } |
|
951 | + $tag = $admin ? 'span' : 'div'; |
|
952 | + $attributes = ! empty($wrap_id) ? " id='$wrap_id'" : ''; |
|
953 | + $wrap_class = $admin ? "$wrap_class ee-layout-row ee-layout-row--inline" : $wrap_class; |
|
954 | + $attributes .= ! empty($wrap_class) |
|
955 | + ? " class='$wrap_class powered-by-event-espresso-credit'" |
|
956 | + : ' class="powered-by-event-espresso-credit"'; |
|
957 | + $query_args = array_merge( |
|
958 | + [ |
|
959 | + 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
960 | + 'utm_source' => 'powered_by_event_espresso', |
|
961 | + 'utm_medium' => 'link', |
|
962 | + 'utm_campaign' => 'powered_by', |
|
963 | + ], |
|
964 | + $query_args |
|
965 | + ); |
|
966 | + $powered_by = apply_filters( |
|
967 | + 'FHEE__EEH_Template__powered_by_event_espresso_text', |
|
968 | + $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
969 | + ); |
|
970 | + $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
971 | + $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
972 | + $template = (string) apply_filters( |
|
973 | + 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
974 | + sprintf( |
|
975 | + esc_html_x( |
|
976 | + '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
977 | + 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
978 | + 'event_espresso' |
|
979 | + ), |
|
980 | + "<$tag$attributes style='margin-inline:.5rem;'>", |
|
981 | + " <a href='$url' target='_blank' rel='nofollow' style='margin-inline: .25rem;'>$powered_by</a></$tag> ", |
|
982 | + $admin ? '' : '<br />' |
|
983 | + ), |
|
984 | + $wrap_class, |
|
985 | + $wrap_id |
|
986 | + ); |
|
987 | + TemplateCache::set($cache_id, $template); |
|
988 | + return $template; |
|
989 | + } |
|
990 | + |
|
991 | + |
|
992 | + /** |
|
993 | + * @param string $image_name |
|
994 | + * @return string|null |
|
995 | + * @since 4.10.14.p |
|
996 | + */ |
|
997 | + public static function getScreenshotUrl($image_name) |
|
998 | + { |
|
999 | + return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg'); |
|
1000 | + } |
|
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | |
1004 | 1004 | if (! function_exists('espresso_pagination')) { |
1005 | - /** |
|
1006 | - * espresso_pagination |
|
1007 | - * |
|
1008 | - * @access public |
|
1009 | - * @return void |
|
1010 | - */ |
|
1011 | - function espresso_pagination() |
|
1012 | - { |
|
1013 | - global $wp_query; |
|
1014 | - $big = 999999999; // need an unlikely integer |
|
1015 | - $pagination = paginate_links( |
|
1016 | - [ |
|
1017 | - 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
1018 | - 'format' => '?paged=%#%', |
|
1019 | - 'current' => max(1, get_query_var('paged')), |
|
1020 | - 'total' => $wp_query->max_num_pages, |
|
1021 | - 'show_all' => true, |
|
1022 | - 'end_size' => 10, |
|
1023 | - 'mid_size' => 6, |
|
1024 | - 'prev_next' => true, |
|
1025 | - 'prev_text' => esc_html__('‹ PREV', 'event_espresso'), |
|
1026 | - 'next_text' => esc_html__('NEXT ›', 'event_espresso'), |
|
1027 | - 'type' => 'plain', |
|
1028 | - 'add_args' => false, |
|
1029 | - 'add_fragment' => '', |
|
1030 | - ] |
|
1031 | - ); |
|
1032 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
1033 | - } |
|
1005 | + /** |
|
1006 | + * espresso_pagination |
|
1007 | + * |
|
1008 | + * @access public |
|
1009 | + * @return void |
|
1010 | + */ |
|
1011 | + function espresso_pagination() |
|
1012 | + { |
|
1013 | + global $wp_query; |
|
1014 | + $big = 999999999; // need an unlikely integer |
|
1015 | + $pagination = paginate_links( |
|
1016 | + [ |
|
1017 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
1018 | + 'format' => '?paged=%#%', |
|
1019 | + 'current' => max(1, get_query_var('paged')), |
|
1020 | + 'total' => $wp_query->max_num_pages, |
|
1021 | + 'show_all' => true, |
|
1022 | + 'end_size' => 10, |
|
1023 | + 'mid_size' => 6, |
|
1024 | + 'prev_next' => true, |
|
1025 | + 'prev_text' => esc_html__('‹ PREV', 'event_espresso'), |
|
1026 | + 'next_text' => esc_html__('NEXT ›', 'event_espresso'), |
|
1027 | + 'type' => 'plain', |
|
1028 | + 'add_args' => false, |
|
1029 | + 'add_fragment' => '', |
|
1030 | + ] |
|
1031 | + ); |
|
1032 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
1033 | + } |
|
1034 | 1034 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | use EventEspresso\core\services\request\RequestInterface; |
9 | 9 | use EventEspresso\core\services\request\sanitizers\AllowedTags; |
10 | 10 | |
11 | -if (! function_exists('espresso_get_template_part')) { |
|
11 | +if ( ! function_exists('espresso_get_template_part')) { |
|
12 | 12 | /** |
13 | 13 | * espresso_get_template_part |
14 | 14 | * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | |
27 | -if (! function_exists('espresso_get_object_css_class')) { |
|
27 | +if ( ! function_exists('espresso_get_object_css_class')) { |
|
28 | 28 | /** |
29 | 29 | * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
30 | 30 | * |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public static function load_espresso_theme_functions() |
76 | 76 | { |
77 | - if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
78 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
79 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
77 | + if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
78 | + if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php')) { |
|
79 | + require_once(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php'); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | } |
@@ -90,16 +90,16 @@ discard block |
||
90 | 90 | public static function get_espresso_themes(): array |
91 | 91 | { |
92 | 92 | if (empty(EEH_Template::$_espresso_themes)) { |
93 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
93 | + $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR); |
|
94 | 94 | if (empty($espresso_themes)) { |
95 | 95 | return []; |
96 | 96 | } |
97 | 97 | if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
98 | - unset($espresso_themes[ $key ]); |
|
98 | + unset($espresso_themes[$key]); |
|
99 | 99 | } |
100 | 100 | EEH_Template::$_espresso_themes = []; |
101 | 101 | foreach ($espresso_themes as $espresso_theme) { |
102 | - EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
102 | + EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme; |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | return EEH_Template::$_espresso_themes; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | ) { |
127 | 127 | do_action("get_template_part_$slug-$name", $slug, $name); |
128 | 128 | $template = $slug; |
129 | - $name = (string) $name; |
|
129 | + $name = (string) $name; |
|
130 | 130 | if ($name != '') { |
131 | 131 | $template .= "-$name"; |
132 | 132 | } |
@@ -245,10 +245,10 @@ discard block |
||
245 | 245 | // get array of EE Custom Post Types |
246 | 246 | $EE_CPTs = $custom_post_types->getDefinitions(); |
247 | 247 | // build template name based on request |
248 | - if (isset($EE_CPTs[ $post_type ])) { |
|
248 | + if (isset($EE_CPTs[$post_type])) { |
|
249 | 249 | $archive_or_single = is_archive() ? 'archive' : ''; |
250 | 250 | $archive_or_single = is_single() ? 'single' : $archive_or_single; |
251 | - $templates[] = $archive_or_single . '-' . $post_type . '.php'; |
|
251 | + $templates[] = $archive_or_single.'-'.$post_type.'.php'; |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | // currently active EE template theme |
@@ -260,12 +260,12 @@ discard block |
||
260 | 260 | ]; |
261 | 261 | |
262 | 262 | // add core plugin folders for checking only if we're not $check_if_custom |
263 | - if (! $check_if_custom) { |
|
264 | - $core_paths = [ |
|
263 | + if ( ! $check_if_custom) { |
|
264 | + $core_paths = [ |
|
265 | 265 | // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
266 | - EE_PUBLIC . $current_theme, |
|
266 | + EE_PUBLIC.$current_theme, |
|
267 | 267 | // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
268 | - EE_TEMPLATES . $current_theme, |
|
268 | + EE_TEMPLATES.$current_theme, |
|
269 | 269 | // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
270 | 270 | EE_PLUGIN_DIR_PATH, |
271 | 271 | ]; |
@@ -298,10 +298,10 @@ discard block |
||
298 | 298 | ); |
299 | 299 | if ($common_base_path !== '') { |
300 | 300 | // both paths have a common base, so just tack the filename onto our search path |
301 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
301 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name; |
|
302 | 302 | } else { |
303 | 303 | // no common base path, so let's just concatenate |
304 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
304 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template; |
|
305 | 305 | } |
306 | 306 | // build up our template locations array by adding our resolved paths |
307 | 307 | $full_template_paths[] = $resolved_path; |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
310 | 310 | array_unshift($full_template_paths, $template); |
311 | 311 | // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
312 | - array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
312 | + array_unshift($full_template_paths, get_stylesheet_directory().'/'.$file_name); |
|
313 | 313 | } |
314 | 314 | // filter final array of full template paths |
315 | 315 | $full_template_paths = apply_filters( |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | } |
367 | 367 | } |
368 | 368 | $common_base_path .= $directory; |
369 | - $last_offset = $index + 1; |
|
369 | + $last_offset = $index + 1; |
|
370 | 370 | } |
371 | 371 | return substr($common_base_path, 0, -1); |
372 | 372 | } |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | ); |
408 | 408 | |
409 | 409 | // you gimme nuttin - YOU GET NUTTIN !! |
410 | - if (! $template_path || ! is_readable($template_path)) { |
|
410 | + if ( ! $template_path || ! is_readable($template_path)) { |
|
411 | 411 | // ignore whether template is accessible ? |
412 | 412 | if ($throw_exceptions) { |
413 | 413 | throw new DomainException( |
@@ -444,11 +444,11 @@ discard block |
||
444 | 444 | public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
445 | 445 | { |
446 | 446 | // in the beginning... |
447 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
447 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : ''; |
|
448 | 448 | // da muddle |
449 | 449 | $class = ''; |
450 | 450 | // the end |
451 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
451 | + $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : ''; |
|
452 | 452 | // is the passed object an EE object ? |
453 | 453 | if ($object instanceof EE_Base_Class) { |
454 | 454 | // grab the exact type of object |
@@ -456,9 +456,9 @@ discard block |
||
456 | 456 | // depending on the type of object... |
457 | 457 | // no specifics just yet... |
458 | 458 | $class = strtolower(str_replace('_', '-', $obj_class)); |
459 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
459 | + $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : ''; |
|
460 | 460 | } |
461 | - return $prefix . $class . $suffix; |
|
461 | + return $prefix.$class.$suffix; |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | // filter raw amount (allows 0.00 to be changed to "free" for example) |
494 | 494 | $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
495 | 495 | // still a number, or was amount converted to a string like "free" ? |
496 | - if (! is_float($amount_formatted)) { |
|
496 | + if ( ! is_float($amount_formatted)) { |
|
497 | 497 | return esc_html($amount_formatted); |
498 | 498 | } |
499 | 499 | try { |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | $mny = null; |
505 | 505 | } |
506 | 506 | // verify results |
507 | - if (! $mny instanceof EE_Currency_Config) { |
|
507 | + if ( ! $mny instanceof EE_Currency_Config) { |
|
508 | 508 | // set default config country currency settings |
509 | 509 | $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
510 | 510 | ? EE_Registry::instance()->CFG->currency |
@@ -513,16 +513,16 @@ discard block |
||
513 | 513 | // format float |
514 | 514 | $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
515 | 515 | // add formatting ? |
516 | - if (! $return_raw) { |
|
516 | + if ( ! $return_raw) { |
|
517 | 517 | // add currency sign |
518 | 518 | if ($mny->sign_b4) { |
519 | 519 | if ($amount >= 0) { |
520 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
520 | + $amount_formatted = $mny->sign.$amount_formatted; |
|
521 | 521 | } else { |
522 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
522 | + $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted); |
|
523 | 523 | } |
524 | 524 | } else { |
525 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
525 | + $amount_formatted = $amount_formatted.$mny->sign; |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | // filter to allow global setting of display_code |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | |
534 | 534 | // add currency code ? |
535 | 535 | $amount_formatted = $display_code |
536 | - ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">' . $mny->code . '</span>' |
|
536 | + ? $amount_formatted.' <span class="'.$cur_code_span_class.'">'.$mny->code.'</span>' |
|
537 | 537 | : $amount_formatted; |
538 | 538 | } |
539 | 539 | // filter results |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | $plural, |
570 | 570 | $schema |
571 | 571 | ); |
572 | - return $status[ $status_id ]; |
|
572 | + return $status[$status_id]; |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | |
@@ -586,14 +586,14 @@ discard block |
||
586 | 586 | public static function get_button_or_link($url, $label, $class = 'button button--primary', $icon = '', $title = '') |
587 | 587 | { |
588 | 588 | $icon_html = ''; |
589 | - if (! empty($icon)) { |
|
589 | + if ( ! empty($icon)) { |
|
590 | 590 | $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
591 | 591 | $dashicons = array_filter($dashicons); |
592 | 592 | $count = count($dashicons); |
593 | 593 | $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
594 | 594 | foreach ($dashicons as $dashicon) { |
595 | - $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
596 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
595 | + $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
596 | + $icon_html .= '<span class="'.$type.$dashicon.'"></span>'; |
|
597 | 597 | } |
598 | 598 | $icon_html .= $count > 1 ? '</span>' : ''; |
599 | 599 | } |
@@ -632,18 +632,18 @@ discard block |
||
632 | 632 | $action = $action ?: $request->getRequestParam('action', 'default', 'key'); |
633 | 633 | |
634 | 634 | |
635 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
635 | + $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id; |
|
636 | 636 | $icon = ! $icon_style ? 'dashicons-editor-help' : $icon_style; |
637 | 637 | $help_text = ! $help_text ? '' : $help_text; |
638 | 638 | return ' |
639 | - <a id="' . esc_attr($help_tab_lnk) . '" |
|
640 | - class="espresso-help-tab-lnk ee-help-btn ee-aria-tooltip dashicons ' . esc_attr($icon) . '" |
|
639 | + <a id="' . esc_attr($help_tab_lnk).'" |
|
640 | + class="espresso-help-tab-lnk ee-help-btn ee-aria-tooltip dashicons ' . esc_attr($icon).'" |
|
641 | 641 | aria-label="' . esc_attr__( |
642 | 642 | 'Click to open the \'Help\' tab for more information about this feature.', |
643 | 643 | 'event_espresso' |
644 | - ) . '" |
|
644 | + ).'" |
|
645 | 645 | > |
646 | - ' . wp_kses($help_text, AllowedTags::getAllowedTags()) . ' |
|
646 | + ' . wp_kses($help_text, AllowedTags::getAllowedTags()).' |
|
647 | 647 | </a>'; |
648 | 648 | } |
649 | 649 | |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | */ |
665 | 665 | public static function status_legend($status_array, $active_status = '') |
666 | 666 | { |
667 | - if (! is_array($status_array)) { |
|
667 | + if ( ! is_array($status_array)) { |
|
668 | 668 | throw new EE_Error( |
669 | 669 | esc_html__( |
670 | 670 | 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
@@ -676,17 +676,17 @@ discard block |
||
676 | 676 | $content = ' |
677 | 677 | <div class="ee-list-table-legend-container"> |
678 | 678 | <h4 class="status-legend-title"> |
679 | - ' . esc_html__('Status Legend', 'event_espresso') . ' |
|
679 | + ' . esc_html__('Status Legend', 'event_espresso').' |
|
680 | 680 | </h4> |
681 | 681 | <dl class="ee-list-table-legend">'; |
682 | 682 | |
683 | 683 | foreach ($status_array as $item => $status) { |
684 | 684 | $active_class = $active_status == $status ? 'class="ee-is-active-status"' : ''; |
685 | - $content .= ' |
|
686 | - <dt id="' . esc_attr('ee-legend-item-tooltip-' . $item) . '" ' . $active_class . '> |
|
687 | - <span class="' . esc_attr('ee-status-legend ee-status-bg--' . $status) . '"></span> |
|
685 | + $content .= ' |
|
686 | + <dt id="' . esc_attr('ee-legend-item-tooltip-'.$item).'" '.$active_class.'> |
|
687 | + <span class="' . esc_attr('ee-status-legend ee-status-bg--'.$status).'"></span> |
|
688 | 688 | <span class="ee-legend-description"> |
689 | - ' . EEH_Template::pretty_status($status, false, 'sentence') . ' |
|
689 | + ' . EEH_Template::pretty_status($status, false, 'sentence').' |
|
690 | 690 | </span> |
691 | 691 | </dt>'; |
692 | 692 | } |
@@ -829,8 +829,8 @@ discard block |
||
829 | 829 | ]; |
830 | 830 | } else { |
831 | 831 | $items_label = [ |
832 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
833 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
832 | + 'single' => '1 '.esc_html($items_label['single']), |
|
833 | + 'plural' => '%s '.esc_html($items_label['plural']), |
|
834 | 834 | ]; |
835 | 835 | } |
836 | 836 | |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | |
843 | 843 | $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
844 | 844 | |
845 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
845 | + $output = '<span class="displaying-num">'.$item_label.'</span>'; |
|
846 | 846 | |
847 | 847 | $disable_first = $current === 1 ? 'disabled' : ''; |
848 | 848 | $disable_last = $current === $total_pages ? 'disabled' : ''; |
@@ -879,7 +879,7 @@ discard block |
||
879 | 879 | '<span class="total-pages">%s</span>', |
880 | 880 | number_format_i18n($total_pages) |
881 | 881 | ); |
882 | - $page_links[] = sprintf( |
|
882 | + $page_links[] = sprintf( |
|
883 | 883 | _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
884 | 884 | "{$html_current_page}<span class='paging-input-of'>", |
885 | 885 | "</span>{$html_total_pages}", |
@@ -903,14 +903,14 @@ discard block |
||
903 | 903 | '»' |
904 | 904 | ); |
905 | 905 | |
906 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
906 | + $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>'; |
|
907 | 907 | |
908 | 908 | $page_class = ' no-pages'; |
909 | 909 | if ($total_pages) { |
910 | 910 | $page_class = $total_pages < 2 ? ' one-page' : ''; |
911 | 911 | } |
912 | 912 | |
913 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
913 | + return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>'; |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | |
@@ -965,7 +965,7 @@ discard block |
||
965 | 965 | ); |
966 | 966 | $powered_by = apply_filters( |
967 | 967 | 'FHEE__EEH_Template__powered_by_event_espresso_text', |
968 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
968 | + $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
969 | 969 | ); |
970 | 970 | $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
971 | 971 | $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
@@ -996,12 +996,12 @@ discard block |
||
996 | 996 | */ |
997 | 997 | public static function getScreenshotUrl($image_name) |
998 | 998 | { |
999 | - return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg'); |
|
999 | + return esc_url_raw(EE_GLOBAL_ASSETS_URL.'images/screenshots/'.$image_name.'.jpg'); |
|
1000 | 1000 | } |
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | |
1004 | -if (! function_exists('espresso_pagination')) { |
|
1004 | +if ( ! function_exists('espresso_pagination')) { |
|
1005 | 1005 | /** |
1006 | 1006 | * espresso_pagination |
1007 | 1007 | * |
@@ -1029,6 +1029,6 @@ discard block |
||
1029 | 1029 | 'add_fragment' => '', |
1030 | 1030 | ] |
1031 | 1031 | ); |
1032 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
1032 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : ''; |
|
1033 | 1033 | } |
1034 | 1034 | } |