Completed
Branch FET-10766-extract-activation-d... (2c1e01)
by
unknown
84:57 queued 73:57
created
core/libraries/plugin_api/EE_Register_Payment_Method.lib.php 1 patch
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -18,149 +18,149 @@
 block discarded – undo
18 18
 class EE_Register_Payment_Method implements EEI_Plugin_API
19 19
 {
20 20
 
21
-    /**
22
-     * Holds values for registered payment methods
23
-     *
24
-     * @var array
25
-     */
26
-    protected static $_settings = array();
27
-
28
-
29
-
30
-    /**
31
-     * Method for registering new EE_PMT_Base children
32
-     *
33
-     * @since    4.5.0
34
-     * @param string  $payment_method_id    a unique identifier for this set of modules Required.
35
-     * @param  array  $setup_args           an array of arguments provided for registering modules Required.{
36
-     * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class
37
-     *                                      (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains
38
-     *                                      the files EE_PMT_Payomatic.pm.php)
39
-     *                                      }
40
-     * @throws EE_Error
41
-     * @type array payment_method_paths    an array of full server paths to folders containing any EE_PMT_Base
42
-     *                                      children, or to the EED_Module files themselves
43
-     * @return void
44
-     * @throws DomainException
45
-     */
46
-    public static function register($payment_method_id = null, $setup_args = array())
47
-    {
48
-        //required fields MUST be present, so let's make sure they are.
49
-        if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) {
50
-            throw new EE_Error(
51
-                esc_html__(
52
-                    'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
53
-                    'event_espresso'
54
-                )
55
-            );
56
-        }
57
-        //make sure we don't register twice
58
-        if (isset(self::$_settings[$payment_method_id])) {
59
-            return;
60
-        }
61
-        //make sure this was called in the right place!
62
-        if (
63
-            ! did_action('AHEE__EE_System__load_espresso_addons')
64
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
65
-        ) {
66
-            EE_Error::doing_it_wrong(
67
-                __METHOD__,
68
-                esc_html__(
69
-                    'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
70
-                    'event_espresso'
71
-                ),
72
-                '4.3.0'
73
-            );
74
-        }
75
-        //setup $_settings array from incoming values.
76
-        self::$_settings[$payment_method_id] = array(
77
-            // array of full server paths to any EE_PMT_Base children used
78
-            'payment_method_paths' => isset($setup_args['payment_method_paths'])
79
-                ? (array)$setup_args['payment_method_paths']
80
-                : array(),
81
-        );
82
-        // add to list of modules to be registered
83
-        add_filter(
84
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
85
-            array('EE_Register_Payment_Method', 'add_payment_methods')
86
-        );
87
-        // If EE_Payment_Method_Manager::register_payment_methods has already been called,
88
-        // then we need to add our caps for this payment method manually
89
-        if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
90
-            // register payment methods directly
91
-            foreach (self::$_settings[$payment_method_id]['payment_method_paths'] as $payment_method_path) {
92
-                EE_Payment_Method_Manager::instance()->register_payment_method($payment_method_path);
93
-            }
94
-            EE_Capabilities::instance()->addCaps(
95
-                self::getPaymentMethodCapabilities(self::$_settings[$payment_method_id])
96
-            );
97
-        }
98
-    }
99
-
100
-
101
-
102
-    /**
103
-     * Filters the list of payment methods to add ours.
104
-     * and they're just full filepaths to FOLDERS containing a payment method class file. Eg.
105
-     *
106
-     * @param array $payment_method_folders array of paths to all payment methods that require registering
107
-     * @return array
108
-     */
109
-    public static function add_payment_methods($payment_method_folders)
110
-    {
111
-        foreach (self::$_settings as $settings) {
112
-            foreach ($settings['payment_method_paths'] as $payment_method_path) {
113
-                $payment_method_folders[] = $payment_method_path;
114
-            }
115
-        }
116
-        return $payment_method_folders;
117
-    }
118
-
119
-
120
-
121
-    /**
122
-     * This deregisters a module that was previously registered with a specific $module_id.
123
-     *
124
-     * @since    4.3.0
125
-     *
126
-     * @param string $module_id the name for the module that was previously registered
127
-     * @return void
128
-     * @throws DomainException
129
-     * @throws EE_Error
130
-     */
131
-    public static function deregister($module_id = null)
132
-    {
133
-        if (isset(self::$_settings[$module_id])) {
134
-            EE_Capabilities::instance()->removeCaps(
135
-                self::getPaymentMethodCapabilities(self::$_settings[$module_id])
136
-            );
137
-            unset(self::$_settings[$module_id]);
138
-        }
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * returns an array of the caps that get added when a Payment Method is registered
145
-     *
146
-     * @param array $settings
147
-     * @return array
148
-     * @throws DomainException
149
-     * @throws EE_Error
150
-     */
151
-    private static function getPaymentMethodCapabilities(array $settings)
152
-    {
153
-        $payment_method_caps = array('administrator' => array());
154
-        if (isset($settings['payment_method_paths'])) {
155
-            foreach ($settings['payment_method_paths'] as $payment_method_path) {
156
-                $payment_method_caps = EE_Payment_Method_Manager::instance()->addPaymentMethodCap(
157
-                    strtolower(basename($payment_method_path)),
158
-                    $payment_method_caps
159
-                );
160
-            }
161
-        }
162
-        return $payment_method_caps;
163
-    }
21
+	/**
22
+	 * Holds values for registered payment methods
23
+	 *
24
+	 * @var array
25
+	 */
26
+	protected static $_settings = array();
27
+
28
+
29
+
30
+	/**
31
+	 * Method for registering new EE_PMT_Base children
32
+	 *
33
+	 * @since    4.5.0
34
+	 * @param string  $payment_method_id    a unique identifier for this set of modules Required.
35
+	 * @param  array  $setup_args           an array of arguments provided for registering modules Required.{
36
+	 * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class
37
+	 *                                      (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains
38
+	 *                                      the files EE_PMT_Payomatic.pm.php)
39
+	 *                                      }
40
+	 * @throws EE_Error
41
+	 * @type array payment_method_paths    an array of full server paths to folders containing any EE_PMT_Base
42
+	 *                                      children, or to the EED_Module files themselves
43
+	 * @return void
44
+	 * @throws DomainException
45
+	 */
46
+	public static function register($payment_method_id = null, $setup_args = array())
47
+	{
48
+		//required fields MUST be present, so let's make sure they are.
49
+		if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) {
50
+			throw new EE_Error(
51
+				esc_html__(
52
+					'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
53
+					'event_espresso'
54
+				)
55
+			);
56
+		}
57
+		//make sure we don't register twice
58
+		if (isset(self::$_settings[$payment_method_id])) {
59
+			return;
60
+		}
61
+		//make sure this was called in the right place!
62
+		if (
63
+			! did_action('AHEE__EE_System__load_espresso_addons')
64
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
65
+		) {
66
+			EE_Error::doing_it_wrong(
67
+				__METHOD__,
68
+				esc_html__(
69
+					'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
70
+					'event_espresso'
71
+				),
72
+				'4.3.0'
73
+			);
74
+		}
75
+		//setup $_settings array from incoming values.
76
+		self::$_settings[$payment_method_id] = array(
77
+			// array of full server paths to any EE_PMT_Base children used
78
+			'payment_method_paths' => isset($setup_args['payment_method_paths'])
79
+				? (array)$setup_args['payment_method_paths']
80
+				: array(),
81
+		);
82
+		// add to list of modules to be registered
83
+		add_filter(
84
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
85
+			array('EE_Register_Payment_Method', 'add_payment_methods')
86
+		);
87
+		// If EE_Payment_Method_Manager::register_payment_methods has already been called,
88
+		// then we need to add our caps for this payment method manually
89
+		if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
90
+			// register payment methods directly
91
+			foreach (self::$_settings[$payment_method_id]['payment_method_paths'] as $payment_method_path) {
92
+				EE_Payment_Method_Manager::instance()->register_payment_method($payment_method_path);
93
+			}
94
+			EE_Capabilities::instance()->addCaps(
95
+				self::getPaymentMethodCapabilities(self::$_settings[$payment_method_id])
96
+			);
97
+		}
98
+	}
99
+
100
+
101
+
102
+	/**
103
+	 * Filters the list of payment methods to add ours.
104
+	 * and they're just full filepaths to FOLDERS containing a payment method class file. Eg.
105
+	 *
106
+	 * @param array $payment_method_folders array of paths to all payment methods that require registering
107
+	 * @return array
108
+	 */
109
+	public static function add_payment_methods($payment_method_folders)
110
+	{
111
+		foreach (self::$_settings as $settings) {
112
+			foreach ($settings['payment_method_paths'] as $payment_method_path) {
113
+				$payment_method_folders[] = $payment_method_path;
114
+			}
115
+		}
116
+		return $payment_method_folders;
117
+	}
118
+
119
+
120
+
121
+	/**
122
+	 * This deregisters a module that was previously registered with a specific $module_id.
123
+	 *
124
+	 * @since    4.3.0
125
+	 *
126
+	 * @param string $module_id the name for the module that was previously registered
127
+	 * @return void
128
+	 * @throws DomainException
129
+	 * @throws EE_Error
130
+	 */
131
+	public static function deregister($module_id = null)
132
+	{
133
+		if (isset(self::$_settings[$module_id])) {
134
+			EE_Capabilities::instance()->removeCaps(
135
+				self::getPaymentMethodCapabilities(self::$_settings[$module_id])
136
+			);
137
+			unset(self::$_settings[$module_id]);
138
+		}
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * returns an array of the caps that get added when a Payment Method is registered
145
+	 *
146
+	 * @param array $settings
147
+	 * @return array
148
+	 * @throws DomainException
149
+	 * @throws EE_Error
150
+	 */
151
+	private static function getPaymentMethodCapabilities(array $settings)
152
+	{
153
+		$payment_method_caps = array('administrator' => array());
154
+		if (isset($settings['payment_method_paths'])) {
155
+			foreach ($settings['payment_method_paths'] as $payment_method_path) {
156
+				$payment_method_caps = EE_Payment_Method_Manager::instance()->addPaymentMethodCap(
157
+					strtolower(basename($payment_method_path)),
158
+					$payment_method_caps
159
+				);
160
+			}
161
+		}
162
+		return $payment_method_caps;
163
+	}
164 164
 
165 165
 }
166 166
 // End of file EE_Register_Payment_Method.lib.php
Please login to merge, or discard this patch.
core/admin/EE_Admin_List_Table.core.php 2 patches
Indentation   +834 added lines, -834 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 defined('EVENT_ESPRESSO_VERSION') || exit('No direct access allowed.');
4 4
 
5 5
 if (! class_exists('WP_List_Table')) {
6
-    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
+	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
7 7
 }
8 8
 
9 9
 
@@ -22,847 +22,847 @@  discard block
 block discarded – undo
22 22
 abstract class EE_Admin_List_Table extends WP_List_Table
23 23
 {
24 24
 
25
-    /**
26
-     * holds the data that will be processed for the table
27
-     *
28
-     * @var array $_data
29
-     */
30
-    protected $_data;
31
-
32
-
33
-    /**
34
-     * This holds the value of all the data available for the given view (for all pages).
35
-     *
36
-     * @var int $_all_data_count
37
-     */
38
-    protected $_all_data_count;
39
-
40
-
41
-    /**
42
-     * Will contain the count of trashed items for the view label.
43
-     *
44
-     * @var int $_trashed_count
45
-     */
46
-    protected $_trashed_count;
47
-
48
-
49
-    /**
50
-     * This is what will be referenced as the slug for the current screen
51
-     *
52
-     * @var string $_screen
53
-     */
54
-    protected $_screen;
55
-
56
-
57
-    /**
58
-     * this is the EE_Admin_Page object
59
-     *
60
-     * @var EE_Admin_Page $_admin_page
61
-     */
62
-    protected $_admin_page;
63
-
64
-
65
-    /**
66
-     * The current view
67
-     *
68
-     * @var string $_view
69
-     */
70
-    protected $_view;
71
-
72
-
73
-    /**
74
-     * array of possible views for this table
75
-     *
76
-     * @var array $_views
77
-     */
78
-    protected $_views;
79
-
80
-
81
-    /**
82
-     * An array of key => value pairs containing information about the current table
83
-     * array(
84
-     *        'plural' => 'plural label',
85
-     *        'singular' => 'singular label',
86
-     *        'ajax' => false, //whether to use ajax or not
87
-     *        'screen' => null, //string used to reference what screen this is
88
-     *        (WP_List_table converts to screen object)
89
-     * )
90
-     *
91
-     * @var array $_wp_list_args
92
-     */
93
-    protected $_wp_list_args;
94
-
95
-    /**
96
-     * an array of column names
97
-     * array(
98
-     *    'internal-name' => 'Title'
99
-     * )
100
-     *
101
-     * @var array $_columns
102
-     */
103
-    protected $_columns;
104
-
105
-    /**
106
-     * An array of sortable columns
107
-     * array(
108
-     *    'internal-name' => 'orderby' //or
109
-     *    'internal-name' => array( 'orderby', true )
110
-     * )
111
-     *
112
-     * @var array $_sortable_columns
113
-     */
114
-    protected $_sortable_columns;
115
-
116
-    /**
117
-     * callback method used to perform AJAX row reordering
118
-     *
119
-     * @var string $_ajax_sorting_callback
120
-     */
121
-    protected $_ajax_sorting_callback;
122
-
123
-    /**
124
-     * An array of hidden columns (if needed)
125
-     * array('internal-name', 'internal-name')
126
-     *
127
-     * @var array $_hidden_columns
128
-     */
129
-    protected $_hidden_columns;
130
-
131
-    /**
132
-     * holds the per_page value
133
-     *
134
-     * @var int $_per_page
135
-     */
136
-    protected $_per_page;
137
-
138
-    /**
139
-     * holds what page number is currently being viewed
140
-     *
141
-     * @var int $_current_page
142
-     */
143
-    protected $_current_page;
144
-
145
-    /**
146
-     * the reference string for the nonce_action
147
-     *
148
-     * @var string $_nonce_action_ref
149
-     */
150
-    protected $_nonce_action_ref;
151
-
152
-    /**
153
-     * property to hold incoming request data (as set by the admin_page_core)
154
-     *
155
-     * @var array $_req_data
156
-     */
157
-    protected $_req_data;
158
-
159
-
160
-    /**
161
-     * yes / no array for admin form fields
162
-     *
163
-     * @var array $_yes_no
164
-     */
165
-    protected $_yes_no = array();
166
-
167
-    /**
168
-     * Array describing buttons that should appear at the bottom of the page
169
-     * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
170
-     * and the values are another array with the following keys
171
-     * array(
172
-     *    'route' => 'page_route',
173
-     *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
174
-     * )
175
-     *
176
-     * @var array $_bottom_buttons
177
-     */
178
-    protected $_bottom_buttons = array();
179
-
180
-
181
-    /**
182
-     * Used to indicate what should be the primary column for the list table.
183
-     * If not present then falls back to what WP calculates
184
-     * as the primary column.
185
-     *
186
-     * @type string $_primary_column
187
-     */
188
-    protected $_primary_column = '';
189
-
190
-
191
-    /**
192
-     * Used to indicate whether the table has a checkbox column or not.
193
-     *
194
-     * @type bool $_has_checkbox_column
195
-     */
196
-    protected $_has_checkbox_column = false;
197
-
198
-
199
-    /**
200
-     * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
201
-     */
202
-    public function __construct(EE_Admin_Page $admin_page)
203
-    {
204
-        $this->_admin_page   = $admin_page;
205
-        $this->_req_data     = $this->_admin_page->get_request_data();
206
-        $this->_view         = $this->_admin_page->get_view();
207
-        $this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
208
-        $this->_current_page = $this->get_pagenum();
209
-        $this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
210
-        $this->_yes_no       = array(__('No', 'event_espresso'), __('Yes', 'event_espresso'));
211
-
212
-        $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10);
213
-
214
-        $this->_setup_data();
215
-        $this->_add_view_counts();
216
-
217
-        $this->_nonce_action_ref = $this->_view;
218
-
219
-        $this->_set_properties();
220
-
221
-        //set primary column
222
-        add_filter('list_table_primary_column', array($this, 'set_primary_column'));
223
-
224
-        //set parent defaults
225
-        parent::__construct($this->_wp_list_args);
226
-
227
-        $this->prepare_items();
228
-    }
229
-
230
-
231
-    /**
232
-     * _setup_data
233
-     * this method is used to setup the $_data, $_all_data_count, and _per_page properties
234
-     *
235
-     * @uses $this->_admin_page
236
-     * @return void
237
-     */
238
-    abstract protected function _setup_data();
239
-
240
-
241
-    /**
242
-     * set the properties that this class needs to be able to execute wp_list_table properly
243
-     * properties set:
244
-     * _wp_list_args = what the arguments required for the parent _wp_list_table.
245
-     * _columns = set the columns in an array.
246
-     * _sortable_columns = columns that are sortable (array).
247
-     * _hidden_columns = columns that are hidden (array)
248
-     * _default_orderby = the default orderby for sorting.
249
-     *
250
-     * @abstract
251
-     * @access protected
252
-     * @return void
253
-     */
254
-    abstract protected function _set_properties();
255
-
256
-
257
-    /**
258
-     * _get_table_filters
259
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
260
-     * get's shown in the table.
261
-     *
262
-     * @abstract
263
-     * @access protected
264
-     * @return string
265
-     */
266
-    abstract protected function _get_table_filters();
267
-
268
-
269
-    /**
270
-     * this is a method that child class will do to add counts to the views array so when views are displayed the
271
-     * counts of the views is accurate.
272
-     *
273
-     * @abstract
274
-     * @access protected
275
-     * @return void
276
-     */
277
-    abstract protected function _add_view_counts();
278
-
279
-
280
-    /**
281
-     * _get_hidden_fields
282
-     * returns a html string of hidden fields so if any table filters are used the current view will be respected.
283
-     *
284
-     * @return string
285
-     */
286
-    protected function _get_hidden_fields()
287
-    {
288
-        $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
289
-        $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
290
-        //if action is STILL empty, then we set it to default
291
-        $action = empty($action) ? 'default' : $action;
292
-        $field  = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n";
293
-        $field  .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/
294
-        $field  .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n";
295
-
296
-        $bulk_actions = $this->_get_bulk_actions();
297
-        foreach ($bulk_actions as $bulk_action => $label) {
298
-            $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
299
-                . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
300
-        }
301
-
302
-        return $field;
303
-    }
304
-
305
-
306
-    /**
307
-     * _set_column_info
308
-     * we're using this to set the column headers property.
309
-     *
310
-     * @access protected
311
-     * @return void
312
-     */
313
-    protected function _set_column_info()
314
-    {
315
-        $columns   = $this->get_columns();
316
-        $hidden    = $this->get_hidden_columns();
317
-        $_sortable = $this->get_sortable_columns();
318
-
319
-        /**
320
-         * Dynamic hook allowing for adding sortable columns in this list table.
321
-         * Note that $this->screen->id is in the format
322
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
323
-         * table it is: event-espresso_page_espresso_messages.
324
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
325
-         * hook prefix ("event-espresso") will be different.
326
-         *
327
-         * @var array
328
-         */
329
-        $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
330
-
331
-        $sortable = array();
332
-        foreach ($_sortable as $id => $data) {
333
-            if (empty($data)) {
334
-                continue;
335
-            }
336
-            //fix for offset errors with WP_List_Table default get_columninfo()
337
-            if (is_array($data)) {
338
-                $_data[0] = key($data);
339
-                $_data[1] = isset($data[1]) ? $data[1] : false;
340
-            } else {
341
-                $_data[0] = $data;
342
-            }
343
-
344
-            $data = (array)$data;
345
-
346
-            if (! isset($data[1])) {
347
-                $_data[1] = false;
348
-            }
349
-
350
-            $sortable[$id] = $_data;
351
-        }
352
-        $primary               = $this->get_primary_column_name();
353
-        $this->_column_headers = array($columns, $hidden, $sortable, $primary);
354
-    }
355
-
356
-
357
-    /**
358
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
359
-     *
360
-     * @return string
361
-     */
362
-    protected function get_primary_column_name()
363
-    {
364
-        foreach (class_parents($this) as $parent) {
365
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
366
-                return parent::get_primary_column_name();
367
-            }
368
-        }
369
-        return $this->_primary_column;
370
-    }
371
-
372
-
373
-    /**
374
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
375
-     *
376
-     * @param EE_Base_Class $item
377
-     * @param string        $column_name
378
-     * @param string        $primary
379
-     * @return string
380
-     */
381
-    protected function handle_row_actions($item, $column_name, $primary)
382
-    {
383
-        foreach (class_parents($this) as $parent) {
384
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
385
-                return parent::handle_row_actions($item, $column_name, $primary);
386
-            }
387
-        }
388
-        return '';
389
-    }
390
-
391
-
392
-    /**
393
-     * _get_bulk_actions
394
-     * This is a wrapper called by WP_List_Table::get_bulk_actions()
395
-     *
396
-     * @access protected
397
-     * @return array bulk_actions
398
-     */
399
-    protected function _get_bulk_actions()
400
-    {
401
-        $actions = array();
402
-        //the _views property should have the bulk_actions, so let's go through and extract them into a properly
403
-        // formatted array for the wp_list_table();
404
-        foreach ($this->_views as $view => $args) {
405
-            if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
406
-                //each bulk action will correspond with a admin page route, so we can check whatever the capability is
407
-                // for that page route and skip adding the bulk action if no access for the current logged in user.
408
-                foreach ($args['bulk_action'] as $route => $label) {
409
-                    if ($this->_admin_page->check_user_access($route, true)) {
410
-                        $actions[$route] = $label;
411
-                    }
412
-                }
413
-            }
414
-        }
415
-        return $actions;
416
-    }
417
-
418
-
419
-    /**
420
-     * Generate the table navigation above or below the table.
421
-     * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
422
-     *
423
-     * @since 4.9.44.rc.001
424
-     */
425
-    public function display_tablenav($which)
426
-    {
427
-        if ('top' === $which) {
428
-            wp_nonce_field('bulk-' . $this->_args['plural']);
429
-        }
430
-        ?>
25
+	/**
26
+	 * holds the data that will be processed for the table
27
+	 *
28
+	 * @var array $_data
29
+	 */
30
+	protected $_data;
31
+
32
+
33
+	/**
34
+	 * This holds the value of all the data available for the given view (for all pages).
35
+	 *
36
+	 * @var int $_all_data_count
37
+	 */
38
+	protected $_all_data_count;
39
+
40
+
41
+	/**
42
+	 * Will contain the count of trashed items for the view label.
43
+	 *
44
+	 * @var int $_trashed_count
45
+	 */
46
+	protected $_trashed_count;
47
+
48
+
49
+	/**
50
+	 * This is what will be referenced as the slug for the current screen
51
+	 *
52
+	 * @var string $_screen
53
+	 */
54
+	protected $_screen;
55
+
56
+
57
+	/**
58
+	 * this is the EE_Admin_Page object
59
+	 *
60
+	 * @var EE_Admin_Page $_admin_page
61
+	 */
62
+	protected $_admin_page;
63
+
64
+
65
+	/**
66
+	 * The current view
67
+	 *
68
+	 * @var string $_view
69
+	 */
70
+	protected $_view;
71
+
72
+
73
+	/**
74
+	 * array of possible views for this table
75
+	 *
76
+	 * @var array $_views
77
+	 */
78
+	protected $_views;
79
+
80
+
81
+	/**
82
+	 * An array of key => value pairs containing information about the current table
83
+	 * array(
84
+	 *        'plural' => 'plural label',
85
+	 *        'singular' => 'singular label',
86
+	 *        'ajax' => false, //whether to use ajax or not
87
+	 *        'screen' => null, //string used to reference what screen this is
88
+	 *        (WP_List_table converts to screen object)
89
+	 * )
90
+	 *
91
+	 * @var array $_wp_list_args
92
+	 */
93
+	protected $_wp_list_args;
94
+
95
+	/**
96
+	 * an array of column names
97
+	 * array(
98
+	 *    'internal-name' => 'Title'
99
+	 * )
100
+	 *
101
+	 * @var array $_columns
102
+	 */
103
+	protected $_columns;
104
+
105
+	/**
106
+	 * An array of sortable columns
107
+	 * array(
108
+	 *    'internal-name' => 'orderby' //or
109
+	 *    'internal-name' => array( 'orderby', true )
110
+	 * )
111
+	 *
112
+	 * @var array $_sortable_columns
113
+	 */
114
+	protected $_sortable_columns;
115
+
116
+	/**
117
+	 * callback method used to perform AJAX row reordering
118
+	 *
119
+	 * @var string $_ajax_sorting_callback
120
+	 */
121
+	protected $_ajax_sorting_callback;
122
+
123
+	/**
124
+	 * An array of hidden columns (if needed)
125
+	 * array('internal-name', 'internal-name')
126
+	 *
127
+	 * @var array $_hidden_columns
128
+	 */
129
+	protected $_hidden_columns;
130
+
131
+	/**
132
+	 * holds the per_page value
133
+	 *
134
+	 * @var int $_per_page
135
+	 */
136
+	protected $_per_page;
137
+
138
+	/**
139
+	 * holds what page number is currently being viewed
140
+	 *
141
+	 * @var int $_current_page
142
+	 */
143
+	protected $_current_page;
144
+
145
+	/**
146
+	 * the reference string for the nonce_action
147
+	 *
148
+	 * @var string $_nonce_action_ref
149
+	 */
150
+	protected $_nonce_action_ref;
151
+
152
+	/**
153
+	 * property to hold incoming request data (as set by the admin_page_core)
154
+	 *
155
+	 * @var array $_req_data
156
+	 */
157
+	protected $_req_data;
158
+
159
+
160
+	/**
161
+	 * yes / no array for admin form fields
162
+	 *
163
+	 * @var array $_yes_no
164
+	 */
165
+	protected $_yes_no = array();
166
+
167
+	/**
168
+	 * Array describing buttons that should appear at the bottom of the page
169
+	 * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
170
+	 * and the values are another array with the following keys
171
+	 * array(
172
+	 *    'route' => 'page_route',
173
+	 *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
174
+	 * )
175
+	 *
176
+	 * @var array $_bottom_buttons
177
+	 */
178
+	protected $_bottom_buttons = array();
179
+
180
+
181
+	/**
182
+	 * Used to indicate what should be the primary column for the list table.
183
+	 * If not present then falls back to what WP calculates
184
+	 * as the primary column.
185
+	 *
186
+	 * @type string $_primary_column
187
+	 */
188
+	protected $_primary_column = '';
189
+
190
+
191
+	/**
192
+	 * Used to indicate whether the table has a checkbox column or not.
193
+	 *
194
+	 * @type bool $_has_checkbox_column
195
+	 */
196
+	protected $_has_checkbox_column = false;
197
+
198
+
199
+	/**
200
+	 * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
201
+	 */
202
+	public function __construct(EE_Admin_Page $admin_page)
203
+	{
204
+		$this->_admin_page   = $admin_page;
205
+		$this->_req_data     = $this->_admin_page->get_request_data();
206
+		$this->_view         = $this->_admin_page->get_view();
207
+		$this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
208
+		$this->_current_page = $this->get_pagenum();
209
+		$this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
210
+		$this->_yes_no       = array(__('No', 'event_espresso'), __('Yes', 'event_espresso'));
211
+
212
+		$this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10);
213
+
214
+		$this->_setup_data();
215
+		$this->_add_view_counts();
216
+
217
+		$this->_nonce_action_ref = $this->_view;
218
+
219
+		$this->_set_properties();
220
+
221
+		//set primary column
222
+		add_filter('list_table_primary_column', array($this, 'set_primary_column'));
223
+
224
+		//set parent defaults
225
+		parent::__construct($this->_wp_list_args);
226
+
227
+		$this->prepare_items();
228
+	}
229
+
230
+
231
+	/**
232
+	 * _setup_data
233
+	 * this method is used to setup the $_data, $_all_data_count, and _per_page properties
234
+	 *
235
+	 * @uses $this->_admin_page
236
+	 * @return void
237
+	 */
238
+	abstract protected function _setup_data();
239
+
240
+
241
+	/**
242
+	 * set the properties that this class needs to be able to execute wp_list_table properly
243
+	 * properties set:
244
+	 * _wp_list_args = what the arguments required for the parent _wp_list_table.
245
+	 * _columns = set the columns in an array.
246
+	 * _sortable_columns = columns that are sortable (array).
247
+	 * _hidden_columns = columns that are hidden (array)
248
+	 * _default_orderby = the default orderby for sorting.
249
+	 *
250
+	 * @abstract
251
+	 * @access protected
252
+	 * @return void
253
+	 */
254
+	abstract protected function _set_properties();
255
+
256
+
257
+	/**
258
+	 * _get_table_filters
259
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
260
+	 * get's shown in the table.
261
+	 *
262
+	 * @abstract
263
+	 * @access protected
264
+	 * @return string
265
+	 */
266
+	abstract protected function _get_table_filters();
267
+
268
+
269
+	/**
270
+	 * this is a method that child class will do to add counts to the views array so when views are displayed the
271
+	 * counts of the views is accurate.
272
+	 *
273
+	 * @abstract
274
+	 * @access protected
275
+	 * @return void
276
+	 */
277
+	abstract protected function _add_view_counts();
278
+
279
+
280
+	/**
281
+	 * _get_hidden_fields
282
+	 * returns a html string of hidden fields so if any table filters are used the current view will be respected.
283
+	 *
284
+	 * @return string
285
+	 */
286
+	protected function _get_hidden_fields()
287
+	{
288
+		$action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
289
+		$action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
290
+		//if action is STILL empty, then we set it to default
291
+		$action = empty($action) ? 'default' : $action;
292
+		$field  = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n";
293
+		$field  .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/
294
+		$field  .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n";
295
+
296
+		$bulk_actions = $this->_get_bulk_actions();
297
+		foreach ($bulk_actions as $bulk_action => $label) {
298
+			$field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
299
+				. ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
300
+		}
301
+
302
+		return $field;
303
+	}
304
+
305
+
306
+	/**
307
+	 * _set_column_info
308
+	 * we're using this to set the column headers property.
309
+	 *
310
+	 * @access protected
311
+	 * @return void
312
+	 */
313
+	protected function _set_column_info()
314
+	{
315
+		$columns   = $this->get_columns();
316
+		$hidden    = $this->get_hidden_columns();
317
+		$_sortable = $this->get_sortable_columns();
318
+
319
+		/**
320
+		 * Dynamic hook allowing for adding sortable columns in this list table.
321
+		 * Note that $this->screen->id is in the format
322
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
323
+		 * table it is: event-espresso_page_espresso_messages.
324
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
325
+		 * hook prefix ("event-espresso") will be different.
326
+		 *
327
+		 * @var array
328
+		 */
329
+		$_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
330
+
331
+		$sortable = array();
332
+		foreach ($_sortable as $id => $data) {
333
+			if (empty($data)) {
334
+				continue;
335
+			}
336
+			//fix for offset errors with WP_List_Table default get_columninfo()
337
+			if (is_array($data)) {
338
+				$_data[0] = key($data);
339
+				$_data[1] = isset($data[1]) ? $data[1] : false;
340
+			} else {
341
+				$_data[0] = $data;
342
+			}
343
+
344
+			$data = (array)$data;
345
+
346
+			if (! isset($data[1])) {
347
+				$_data[1] = false;
348
+			}
349
+
350
+			$sortable[$id] = $_data;
351
+		}
352
+		$primary               = $this->get_primary_column_name();
353
+		$this->_column_headers = array($columns, $hidden, $sortable, $primary);
354
+	}
355
+
356
+
357
+	/**
358
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
359
+	 *
360
+	 * @return string
361
+	 */
362
+	protected function get_primary_column_name()
363
+	{
364
+		foreach (class_parents($this) as $parent) {
365
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
366
+				return parent::get_primary_column_name();
367
+			}
368
+		}
369
+		return $this->_primary_column;
370
+	}
371
+
372
+
373
+	/**
374
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
375
+	 *
376
+	 * @param EE_Base_Class $item
377
+	 * @param string        $column_name
378
+	 * @param string        $primary
379
+	 * @return string
380
+	 */
381
+	protected function handle_row_actions($item, $column_name, $primary)
382
+	{
383
+		foreach (class_parents($this) as $parent) {
384
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
385
+				return parent::handle_row_actions($item, $column_name, $primary);
386
+			}
387
+		}
388
+		return '';
389
+	}
390
+
391
+
392
+	/**
393
+	 * _get_bulk_actions
394
+	 * This is a wrapper called by WP_List_Table::get_bulk_actions()
395
+	 *
396
+	 * @access protected
397
+	 * @return array bulk_actions
398
+	 */
399
+	protected function _get_bulk_actions()
400
+	{
401
+		$actions = array();
402
+		//the _views property should have the bulk_actions, so let's go through and extract them into a properly
403
+		// formatted array for the wp_list_table();
404
+		foreach ($this->_views as $view => $args) {
405
+			if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
406
+				//each bulk action will correspond with a admin page route, so we can check whatever the capability is
407
+				// for that page route and skip adding the bulk action if no access for the current logged in user.
408
+				foreach ($args['bulk_action'] as $route => $label) {
409
+					if ($this->_admin_page->check_user_access($route, true)) {
410
+						$actions[$route] = $label;
411
+					}
412
+				}
413
+			}
414
+		}
415
+		return $actions;
416
+	}
417
+
418
+
419
+	/**
420
+	 * Generate the table navigation above or below the table.
421
+	 * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
422
+	 *
423
+	 * @since 4.9.44.rc.001
424
+	 */
425
+	public function display_tablenav($which)
426
+	{
427
+		if ('top' === $which) {
428
+			wp_nonce_field('bulk-' . $this->_args['plural']);
429
+		}
430
+		?>
431 431
         <div class="tablenav <?php echo esc_attr($which); ?>">
432 432
             <?php if ($this->_get_bulk_actions()) { ?>
433 433
                 <div class="alignleft actions bulkactions">
434 434
                     <?php $this->bulk_actions(); ?>
435 435
                 </div>
436 436
             <?php }
437
-            $this->extra_tablenav($which);
438
-            $this->pagination($which);
439
-            ?>
437
+			$this->extra_tablenav($which);
438
+			$this->pagination($which);
439
+			?>
440 440
 
441 441
             <br class="clear"/>
442 442
         </div>
443 443
         <?php
444
-    }
445
-
446
-
447
-    /**
448
-     * _filters
449
-     * This receives the filters array from children _get_table_filters() and assembles the string including the filter
450
-     * button.
451
-     *
452
-     * @access private
453
-     * @return string html showing filters
454
-     */
455
-    private function _filters()
456
-    {
457
-        $classname = get_class($this);
458
-        $filters   = apply_filters(
459
-            "FHEE__{$classname}__filters",
460
-            (array) $this->_get_table_filters(),
461
-            $this,
462
-            $this->_screen
463
-        );
464
-
465
-        if (empty($filters)) {
466
-            return;
467
-        }
468
-        foreach ($filters as $filter) {
469
-            echo $filter;
470
-        }
471
-        //add filter button at end
472
-        echo '<input type="submit" class="button-secondary" value="'
473
-             . esc_html__('Filter', 'event_espresso')
474
-             . '" id="post-query-submit" />';
475
-        //add reset filters button at end
476
-        echo '<a class="button button-secondary"  href="'
477
-             . $this->_admin_page->get_current_page_view_url()
478
-             . '" style="display:inline-block">'
479
-             . esc_html__('Reset Filters', 'event_espresso')
480
-             . '</a>';
481
-    }
482
-
483
-
484
-    /**
485
-     * Callback for 'list_table_primary_column' WordPress filter
486
-     * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
487
-     * column when class is instantiated.
488
-     *
489
-     * @see WP_List_Table::get_primary_column_name
490
-     * @param string $column_name
491
-     * @return string
492
-     */
493
-    public function set_primary_column($column_name)
494
-    {
495
-        return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
496
-    }
497
-
498
-
499
-    /**
500
-     *
501
-     */
502
-    public function prepare_items()
503
-    {
504
-
505
-        $this->_set_column_info();
506
-        //$this->_column_headers = $this->get_column_info();
507
-        $total_items = $this->_all_data_count;
508
-        $this->process_bulk_action();
509
-
510
-        $this->items = $this->_data;
511
-        $this->set_pagination_args(
512
-            array(
513
-                'total_items' => $total_items,
514
-                'per_page'    => $this->_per_page,
515
-                'total_pages' => ceil($total_items / $this->_per_page),
516
-            )
517
-        );
518
-    }
519
-
520
-
521
-    /**
522
-     * This column is the default for when there is no defined column method for a registered column.
523
-     * This can be overridden by child classes, but allows for hooking in for custom columns.
524
-     *
525
-     * @param EE_Base_Class $item
526
-     * @param string        $column_name The column being called.
527
-     * @return string html content for the column
528
-     */
529
-    public function column_default($item, $column_name)
530
-    {
531
-        /**
532
-         * Dynamic hook allowing for adding additional column content in this list table.
533
-         * Note that $this->screen->id is in the format
534
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
535
-         * table it is: event-espresso_page_espresso_messages.
536
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
537
-         * hook prefix ("event-espresso") will be different.
538
-         */
539
-        do_action(
540
-            'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
541
-            $item,
542
-            $this->_screen
543
-        );
544
-    }
545
-
546
-
547
-    /**
548
-     * Get a list of columns. The format is:
549
-     * 'internal-name' => 'Title'
550
-     *
551
-     * @since  3.1.0
552
-     * @access public
553
-     * @abstract
554
-     * @return array
555
-     */
556
-    public function get_columns()
557
-    {
558
-        /**
559
-         * Dynamic hook allowing for adding additional columns in this list table.
560
-         * Note that $this->screen->id is in the format
561
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
562
-         * table it is: event-espresso_page_espresso_messages.
563
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
564
-         * hook prefix ("event-espresso") will be different.
565
-         *
566
-         * @var array
567
-         */
568
-        $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
569
-        return $columns;
570
-    }
571
-
572
-
573
-    /**
574
-     * Get an associative array ( id => link ) with the list
575
-     * of views available on this table.
576
-     *
577
-     * @since  3.1.0
578
-     * @access protected
579
-     * @return array
580
-     */
581
-    public function get_views()
582
-    {
583
-        return $this->_views;
584
-    }
585
-
586
-
587
-    /**
588
-     * Generate the views html.
589
-     */
590
-    public function display_views()
591
-    {
592
-        $views           = $this->get_views();
593
-        $assembled_views = array();
594
-
595
-        if (empty($views)) {
596
-            return;
597
-        }
598
-        echo "<ul class='subsubsub'>\n";
599
-        foreach ($views as $view) {
600
-            $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
601
-            if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
602
-                $assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>"
603
-                                                  . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>'
604
-                                                  . ' <span class="count">(' . $count . ')</span>';
605
-            }
606
-        }
607
-
608
-        echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : '';
609
-        echo "</ul>";
610
-    }
611
-
612
-
613
-    /**
614
-     * Generates content for a single row of the table
615
-     *
616
-     * @since  4.1
617
-     * @access public
618
-     * @param EE_Base_Class $item The current item
619
-     */
620
-    public function single_row($item)
621
-    {
622
-        $row_class = $this->_get_row_class($item);
623
-        echo '<tr class="' . esc_attr($row_class) . '">';
624
-        $this->single_row_columns($item);
625
-        echo '</tr>';
626
-    }
627
-
628
-
629
-    /**
630
-     * This simply sets up the row class for the table rows.
631
-     * Allows for easier overriding of child methods for setting up sorting.
632
-     *
633
-     * @param  EE_Base_Class $item the current item
634
-     * @return string
635
-     */
636
-    protected function _get_row_class($item)
637
-    {
638
-        static $row_class = '';
639
-        $row_class = ($row_class === '' ? 'alternate' : '');
640
-
641
-        $new_row_class = $row_class;
642
-
643
-        if (! empty($this->_ajax_sorting_callback)) {
644
-            $new_row_class .= ' rowsortable';
645
-        }
646
-
647
-        return $new_row_class;
648
-    }
649
-
650
-
651
-    /**
652
-     * @return array
653
-     */
654
-    public function get_sortable_columns()
655
-    {
656
-        return (array)$this->_sortable_columns;
657
-    }
658
-
659
-
660
-    /**
661
-     * @return string
662
-     */
663
-    public function get_ajax_sorting_callback()
664
-    {
665
-        return $this->_ajax_sorting_callback;
666
-    }
667
-
668
-
669
-    /**
670
-     * @return array
671
-     */
672
-    public function get_hidden_columns()
673
-    {
674
-        $user_id     = get_current_user_id();
675
-        $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
676
-        if (empty($has_default) && ! empty($this->_hidden_columns)) {
677
-            update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
678
-            update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
679
-        }
680
-        $ref = 'manage' . $this->screen->id . 'columnshidden';
681
-        return (array) get_user_option($ref, $user_id);
682
-    }
683
-
684
-
685
-    /**
686
-     * Generates the columns for a single row of the table.
687
-     * Overridden from wp_list_table so as to allow us to filter the column content for a given
688
-     * column.
689
-     *
690
-     * @since 3.1.0
691
-     * @param EE_Base_Class $item The current item
692
-     */
693
-    public function single_row_columns($item)
694
-    {
695
-        list($columns, $hidden, $sortable, $primary) = $this->get_column_info();
696
-
697
-        global $wp_version;
698
-        $use_hidden_class = version_compare($wp_version, '4.3-RC', '>=');
699
-
700
-        foreach ($columns as $column_name => $column_display_name) {
701
-
702
-            /**
703
-             * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
704
-             * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
705
-             */
706
-            $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : '';
707
-            $style        = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : '';
708
-
709
-            $classes = $column_name . ' column-' . $column_name . $hidden_class;
710
-            if ($primary === $column_name) {
711
-                $classes .= ' has-row-actions column-primary';
712
-            }
713
-
714
-            $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
715
-
716
-            $class = "class='$classes'";
717
-
718
-            $attributes = "$class$style$data";
719
-
720
-            if ($column_name === 'cb') {
721
-                echo '<th scope="row" class="check-column">';
722
-                echo apply_filters(
723
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
724
-                    $this->column_cb($item),
725
-                    $item,
726
-                    $this
727
-                );
728
-                echo '</th>';
729
-            } elseif (method_exists($this, 'column_' . $column_name)) {
730
-                echo "<td $attributes>";
731
-                echo apply_filters(
732
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
733
-                    call_user_func(array($this, 'column_' . $column_name), $item),
734
-                    $item,
735
-                    $this
736
-                );
737
-                echo $this->handle_row_actions($item, $column_name, $primary);
738
-                echo "</td>";
739
-            } else {
740
-                echo "<td $attributes>";
741
-                echo apply_filters(
742
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
743
-                    $this->column_default($item, $column_name),
744
-                    $item,
745
-                    $column_name,
746
-                    $this
747
-                );
748
-                echo $this->handle_row_actions($item, $column_name, $primary);
749
-                echo "</td>";
750
-            }
751
-        }
752
-    }
753
-
754
-
755
-    /**
756
-     * Extra controls to be displayed between bulk actions and pagination
757
-     *
758
-     * @access public
759
-     * @param string $which
760
-     * @throws \EE_Error
761
-     */
762
-    public function extra_tablenav($which)
763
-    {
764
-        if ($which === 'top') {
765
-            $this->_filters();
766
-            echo $this->_get_hidden_fields();
767
-        } else {
768
-            echo '<div class="list-table-bottom-buttons alignleft actions">';
769
-            foreach ($this->_bottom_buttons as $type => $action) {
770
-                $route         = isset($action['route']) ? $action['route'] : '';
771
-                $extra_request = isset($action['extra_request']) ? $action['extra_request'] : '';
772
-                echo $this->_admin_page->get_action_link_or_button(
773
-                    $route,
774
-                    $type,
775
-                    $extra_request,
776
-                    'button button-secondary',
777
-                    '',
778
-                    false
779
-                );
780
-            }
781
-            do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
782
-            echo '</div>';
783
-        }
784
-        //echo $this->_entries_per_page_dropdown;
785
-    }
786
-
787
-
788
-    /**
789
-     * Get an associative array ( option_name => option_title ) with the list
790
-     * of bulk actions available on this table.
791
-     *
792
-     * @since  3.1.0
793
-     * @access protected
794
-     * @return array
795
-     */
796
-    public function get_bulk_actions()
797
-    {
798
-        return (array) $this->_get_bulk_actions();
799
-    }
800
-
801
-    /**
802
-     * Processing bulk actions.
803
-     */
804
-    public function process_bulk_action()
805
-    {
806
-        //this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
807
-        //reference in case there is a case where it gets used.
808
-    }
809
-
810
-
811
-    /**
812
-     * returns the EE admin page this list table is associated with
813
-     *
814
-     * @return EE_Admin_Page
815
-     */
816
-    public function get_admin_page()
817
-    {
818
-        return $this->_admin_page;
819
-    }
820
-
821
-
822
-    /**
823
-     * A "helper" function for all children to provide an html string of
824
-     * actions to output in their content.  It is preferable for child classes
825
-     * to use this method for generating their actions content so that it's
826
-     * filterable by plugins
827
-     *
828
-     * @param string        $action_container           what are the html container
829
-     *                                                  elements for this actions string?
830
-     * @param string        $action_class               What class is for the container
831
-     *                                                  element.
832
-     * @param string        $action_items               The contents for the action items
833
-     *                                                  container.  This is filtered before
834
-     *                                                  returned.
835
-     * @param string        $action_id                  What id (optional) is used for the
836
-     *                                                  container element.
837
-     * @param EE_Base_Class $item                       The object for the column displaying
838
-     *                                                  the actions.
839
-     * @return string The assembled action elements container.
840
-     */
841
-    protected function _action_string(
842
-        $action_items,
843
-        $item,
844
-        $action_container = 'ul',
845
-        $action_class = '',
846
-        $action_id = ''
847
-    ) {
848
-        $content      = '';
849
-        $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : '';
850
-        $action_id    = ! empty($action_id) ? ' id="' . $action_id . '"' : '';
851
-        $content      .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
852
-        try {
853
-            $content .= apply_filters(
854
-                'FHEE__EE_Admin_List_Table___action_string__action_items',
855
-                $action_items,
856
-                $item,
857
-                $this
858
-            );
859
-        } catch (\Exception $e) {
860
-            if (WP_DEBUG) {
861
-                \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
862
-            }
863
-            $content .= $action_items;
864
-        }
865
-        $content .= ! empty($action_container) ? '</' . $action_container . '>' : '';
866
-        return $content;
867
-    }
444
+	}
445
+
446
+
447
+	/**
448
+	 * _filters
449
+	 * This receives the filters array from children _get_table_filters() and assembles the string including the filter
450
+	 * button.
451
+	 *
452
+	 * @access private
453
+	 * @return string html showing filters
454
+	 */
455
+	private function _filters()
456
+	{
457
+		$classname = get_class($this);
458
+		$filters   = apply_filters(
459
+			"FHEE__{$classname}__filters",
460
+			(array) $this->_get_table_filters(),
461
+			$this,
462
+			$this->_screen
463
+		);
464
+
465
+		if (empty($filters)) {
466
+			return;
467
+		}
468
+		foreach ($filters as $filter) {
469
+			echo $filter;
470
+		}
471
+		//add filter button at end
472
+		echo '<input type="submit" class="button-secondary" value="'
473
+			 . esc_html__('Filter', 'event_espresso')
474
+			 . '" id="post-query-submit" />';
475
+		//add reset filters button at end
476
+		echo '<a class="button button-secondary"  href="'
477
+			 . $this->_admin_page->get_current_page_view_url()
478
+			 . '" style="display:inline-block">'
479
+			 . esc_html__('Reset Filters', 'event_espresso')
480
+			 . '</a>';
481
+	}
482
+
483
+
484
+	/**
485
+	 * Callback for 'list_table_primary_column' WordPress filter
486
+	 * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
487
+	 * column when class is instantiated.
488
+	 *
489
+	 * @see WP_List_Table::get_primary_column_name
490
+	 * @param string $column_name
491
+	 * @return string
492
+	 */
493
+	public function set_primary_column($column_name)
494
+	{
495
+		return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
496
+	}
497
+
498
+
499
+	/**
500
+	 *
501
+	 */
502
+	public function prepare_items()
503
+	{
504
+
505
+		$this->_set_column_info();
506
+		//$this->_column_headers = $this->get_column_info();
507
+		$total_items = $this->_all_data_count;
508
+		$this->process_bulk_action();
509
+
510
+		$this->items = $this->_data;
511
+		$this->set_pagination_args(
512
+			array(
513
+				'total_items' => $total_items,
514
+				'per_page'    => $this->_per_page,
515
+				'total_pages' => ceil($total_items / $this->_per_page),
516
+			)
517
+		);
518
+	}
519
+
520
+
521
+	/**
522
+	 * This column is the default for when there is no defined column method for a registered column.
523
+	 * This can be overridden by child classes, but allows for hooking in for custom columns.
524
+	 *
525
+	 * @param EE_Base_Class $item
526
+	 * @param string        $column_name The column being called.
527
+	 * @return string html content for the column
528
+	 */
529
+	public function column_default($item, $column_name)
530
+	{
531
+		/**
532
+		 * Dynamic hook allowing for adding additional column content in this list table.
533
+		 * Note that $this->screen->id is in the format
534
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
535
+		 * table it is: event-espresso_page_espresso_messages.
536
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
537
+		 * hook prefix ("event-espresso") will be different.
538
+		 */
539
+		do_action(
540
+			'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
541
+			$item,
542
+			$this->_screen
543
+		);
544
+	}
545
+
546
+
547
+	/**
548
+	 * Get a list of columns. The format is:
549
+	 * 'internal-name' => 'Title'
550
+	 *
551
+	 * @since  3.1.0
552
+	 * @access public
553
+	 * @abstract
554
+	 * @return array
555
+	 */
556
+	public function get_columns()
557
+	{
558
+		/**
559
+		 * Dynamic hook allowing for adding additional columns in this list table.
560
+		 * Note that $this->screen->id is in the format
561
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
562
+		 * table it is: event-espresso_page_espresso_messages.
563
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
564
+		 * hook prefix ("event-espresso") will be different.
565
+		 *
566
+		 * @var array
567
+		 */
568
+		$columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
569
+		return $columns;
570
+	}
571
+
572
+
573
+	/**
574
+	 * Get an associative array ( id => link ) with the list
575
+	 * of views available on this table.
576
+	 *
577
+	 * @since  3.1.0
578
+	 * @access protected
579
+	 * @return array
580
+	 */
581
+	public function get_views()
582
+	{
583
+		return $this->_views;
584
+	}
585
+
586
+
587
+	/**
588
+	 * Generate the views html.
589
+	 */
590
+	public function display_views()
591
+	{
592
+		$views           = $this->get_views();
593
+		$assembled_views = array();
594
+
595
+		if (empty($views)) {
596
+			return;
597
+		}
598
+		echo "<ul class='subsubsub'>\n";
599
+		foreach ($views as $view) {
600
+			$count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
601
+			if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
602
+				$assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>"
603
+												  . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>'
604
+												  . ' <span class="count">(' . $count . ')</span>';
605
+			}
606
+		}
607
+
608
+		echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : '';
609
+		echo "</ul>";
610
+	}
611
+
612
+
613
+	/**
614
+	 * Generates content for a single row of the table
615
+	 *
616
+	 * @since  4.1
617
+	 * @access public
618
+	 * @param EE_Base_Class $item The current item
619
+	 */
620
+	public function single_row($item)
621
+	{
622
+		$row_class = $this->_get_row_class($item);
623
+		echo '<tr class="' . esc_attr($row_class) . '">';
624
+		$this->single_row_columns($item);
625
+		echo '</tr>';
626
+	}
627
+
628
+
629
+	/**
630
+	 * This simply sets up the row class for the table rows.
631
+	 * Allows for easier overriding of child methods for setting up sorting.
632
+	 *
633
+	 * @param  EE_Base_Class $item the current item
634
+	 * @return string
635
+	 */
636
+	protected function _get_row_class($item)
637
+	{
638
+		static $row_class = '';
639
+		$row_class = ($row_class === '' ? 'alternate' : '');
640
+
641
+		$new_row_class = $row_class;
642
+
643
+		if (! empty($this->_ajax_sorting_callback)) {
644
+			$new_row_class .= ' rowsortable';
645
+		}
646
+
647
+		return $new_row_class;
648
+	}
649
+
650
+
651
+	/**
652
+	 * @return array
653
+	 */
654
+	public function get_sortable_columns()
655
+	{
656
+		return (array)$this->_sortable_columns;
657
+	}
658
+
659
+
660
+	/**
661
+	 * @return string
662
+	 */
663
+	public function get_ajax_sorting_callback()
664
+	{
665
+		return $this->_ajax_sorting_callback;
666
+	}
667
+
668
+
669
+	/**
670
+	 * @return array
671
+	 */
672
+	public function get_hidden_columns()
673
+	{
674
+		$user_id     = get_current_user_id();
675
+		$has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
676
+		if (empty($has_default) && ! empty($this->_hidden_columns)) {
677
+			update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
678
+			update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
679
+		}
680
+		$ref = 'manage' . $this->screen->id . 'columnshidden';
681
+		return (array) get_user_option($ref, $user_id);
682
+	}
683
+
684
+
685
+	/**
686
+	 * Generates the columns for a single row of the table.
687
+	 * Overridden from wp_list_table so as to allow us to filter the column content for a given
688
+	 * column.
689
+	 *
690
+	 * @since 3.1.0
691
+	 * @param EE_Base_Class $item The current item
692
+	 */
693
+	public function single_row_columns($item)
694
+	{
695
+		list($columns, $hidden, $sortable, $primary) = $this->get_column_info();
696
+
697
+		global $wp_version;
698
+		$use_hidden_class = version_compare($wp_version, '4.3-RC', '>=');
699
+
700
+		foreach ($columns as $column_name => $column_display_name) {
701
+
702
+			/**
703
+			 * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
704
+			 * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
705
+			 */
706
+			$hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : '';
707
+			$style        = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : '';
708
+
709
+			$classes = $column_name . ' column-' . $column_name . $hidden_class;
710
+			if ($primary === $column_name) {
711
+				$classes .= ' has-row-actions column-primary';
712
+			}
713
+
714
+			$data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
715
+
716
+			$class = "class='$classes'";
717
+
718
+			$attributes = "$class$style$data";
719
+
720
+			if ($column_name === 'cb') {
721
+				echo '<th scope="row" class="check-column">';
722
+				echo apply_filters(
723
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
724
+					$this->column_cb($item),
725
+					$item,
726
+					$this
727
+				);
728
+				echo '</th>';
729
+			} elseif (method_exists($this, 'column_' . $column_name)) {
730
+				echo "<td $attributes>";
731
+				echo apply_filters(
732
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
733
+					call_user_func(array($this, 'column_' . $column_name), $item),
734
+					$item,
735
+					$this
736
+				);
737
+				echo $this->handle_row_actions($item, $column_name, $primary);
738
+				echo "</td>";
739
+			} else {
740
+				echo "<td $attributes>";
741
+				echo apply_filters(
742
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
743
+					$this->column_default($item, $column_name),
744
+					$item,
745
+					$column_name,
746
+					$this
747
+				);
748
+				echo $this->handle_row_actions($item, $column_name, $primary);
749
+				echo "</td>";
750
+			}
751
+		}
752
+	}
753
+
754
+
755
+	/**
756
+	 * Extra controls to be displayed between bulk actions and pagination
757
+	 *
758
+	 * @access public
759
+	 * @param string $which
760
+	 * @throws \EE_Error
761
+	 */
762
+	public function extra_tablenav($which)
763
+	{
764
+		if ($which === 'top') {
765
+			$this->_filters();
766
+			echo $this->_get_hidden_fields();
767
+		} else {
768
+			echo '<div class="list-table-bottom-buttons alignleft actions">';
769
+			foreach ($this->_bottom_buttons as $type => $action) {
770
+				$route         = isset($action['route']) ? $action['route'] : '';
771
+				$extra_request = isset($action['extra_request']) ? $action['extra_request'] : '';
772
+				echo $this->_admin_page->get_action_link_or_button(
773
+					$route,
774
+					$type,
775
+					$extra_request,
776
+					'button button-secondary',
777
+					'',
778
+					false
779
+				);
780
+			}
781
+			do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
782
+			echo '</div>';
783
+		}
784
+		//echo $this->_entries_per_page_dropdown;
785
+	}
786
+
787
+
788
+	/**
789
+	 * Get an associative array ( option_name => option_title ) with the list
790
+	 * of bulk actions available on this table.
791
+	 *
792
+	 * @since  3.1.0
793
+	 * @access protected
794
+	 * @return array
795
+	 */
796
+	public function get_bulk_actions()
797
+	{
798
+		return (array) $this->_get_bulk_actions();
799
+	}
800
+
801
+	/**
802
+	 * Processing bulk actions.
803
+	 */
804
+	public function process_bulk_action()
805
+	{
806
+		//this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
807
+		//reference in case there is a case where it gets used.
808
+	}
809
+
810
+
811
+	/**
812
+	 * returns the EE admin page this list table is associated with
813
+	 *
814
+	 * @return EE_Admin_Page
815
+	 */
816
+	public function get_admin_page()
817
+	{
818
+		return $this->_admin_page;
819
+	}
820
+
821
+
822
+	/**
823
+	 * A "helper" function for all children to provide an html string of
824
+	 * actions to output in their content.  It is preferable for child classes
825
+	 * to use this method for generating their actions content so that it's
826
+	 * filterable by plugins
827
+	 *
828
+	 * @param string        $action_container           what are the html container
829
+	 *                                                  elements for this actions string?
830
+	 * @param string        $action_class               What class is for the container
831
+	 *                                                  element.
832
+	 * @param string        $action_items               The contents for the action items
833
+	 *                                                  container.  This is filtered before
834
+	 *                                                  returned.
835
+	 * @param string        $action_id                  What id (optional) is used for the
836
+	 *                                                  container element.
837
+	 * @param EE_Base_Class $item                       The object for the column displaying
838
+	 *                                                  the actions.
839
+	 * @return string The assembled action elements container.
840
+	 */
841
+	protected function _action_string(
842
+		$action_items,
843
+		$item,
844
+		$action_container = 'ul',
845
+		$action_class = '',
846
+		$action_id = ''
847
+	) {
848
+		$content      = '';
849
+		$action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : '';
850
+		$action_id    = ! empty($action_id) ? ' id="' . $action_id . '"' : '';
851
+		$content      .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
852
+		try {
853
+			$content .= apply_filters(
854
+				'FHEE__EE_Admin_List_Table___action_string__action_items',
855
+				$action_items,
856
+				$item,
857
+				$this
858
+			);
859
+		} catch (\Exception $e) {
860
+			if (WP_DEBUG) {
861
+				\EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
862
+			}
863
+			$content .= $action_items;
864
+		}
865
+		$content .= ! empty($action_container) ? '</' . $action_container . '>' : '';
866
+		return $content;
867
+	}
868 868
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@  discard block
 block discarded – undo
2 2
 
3 3
 defined('EVENT_ESPRESSO_VERSION') || exit('No direct access allowed.');
4 4
 
5
-if (! class_exists('WP_List_Table')) {
6
-    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
+if ( ! class_exists('WP_List_Table')) {
6
+    require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php';
7 7
 }
8 8
 
9 9
 
@@ -206,10 +206,10 @@  discard block
 block discarded – undo
206 206
         $this->_view         = $this->_admin_page->get_view();
207 207
         $this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
208 208
         $this->_current_page = $this->get_pagenum();
209
-        $this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
209
+        $this->_screen       = $this->_admin_page->get_current_page().'_'.$this->_admin_page->get_current_view();
210 210
         $this->_yes_no       = array(__('No', 'event_espresso'), __('Yes', 'event_espresso'));
211 211
 
212
-        $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10);
212
+        $this->_per_page = $this->get_items_per_page($this->_screen.'_per_page', 10);
213 213
 
214 214
         $this->_setup_data();
215 215
         $this->_add_view_counts();
@@ -289,14 +289,14 @@  discard block
 block discarded – undo
289 289
         $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
290 290
         //if action is STILL empty, then we set it to default
291 291
         $action = empty($action) ? 'default' : $action;
292
-        $field  = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n";
293
-        $field  .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/
294
-        $field  .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n";
292
+        $field  = '<input type="hidden" name="page" value="'.$this->_req_data['page'].'" />'."\n";
293
+        $field  .= '<input type="hidden" name="route" value="'.$action.'" />'."\n"; /**/
294
+        $field  .= '<input type="hidden" name="perpage" value="'.$this->_per_page.'" />'."\n";
295 295
 
296 296
         $bulk_actions = $this->_get_bulk_actions();
297 297
         foreach ($bulk_actions as $bulk_action => $label) {
298
-            $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
299
-                . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
298
+            $field .= '<input type="hidden" name="'.$bulk_action.'_nonce"'
299
+                . ' value="'.wp_create_nonce($bulk_action.'_nonce').'" />'."\n";
300 300
         }
301 301
 
302 302
         return $field;
@@ -341,9 +341,9 @@  discard block
 block discarded – undo
341 341
                 $_data[0] = $data;
342 342
             }
343 343
 
344
-            $data = (array)$data;
344
+            $data = (array) $data;
345 345
 
346
-            if (! isset($data[1])) {
346
+            if ( ! isset($data[1])) {
347 347
                 $_data[1] = false;
348 348
             }
349 349
 
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
     public function display_tablenav($which)
426 426
     {
427 427
         if ('top' === $which) {
428
-            wp_nonce_field('bulk-' . $this->_args['plural']);
428
+            wp_nonce_field('bulk-'.$this->_args['plural']);
429 429
         }
430 430
         ?>
431 431
         <div class="tablenav <?php echo esc_attr($which); ?>">
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
          * hook prefix ("event-espresso") will be different.
538 538
          */
539 539
         do_action(
540
-            'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
540
+            'AHEE__EE_Admin_List_Table__column_'.$column_name.'__'.$this->screen->id,
541 541
             $item,
542 542
             $this->_screen
543 543
         );
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
          *
566 566
          * @var array
567 567
          */
568
-        $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
568
+        $columns = apply_filters('FHEE_manage_'.$this->screen->id.'_columns', $this->_columns, $this->_screen);
569 569
         return $columns;
570 570
     }
571 571
 
@@ -599,13 +599,13 @@  discard block
 block discarded – undo
599 599
         foreach ($views as $view) {
600 600
             $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
601 601
             if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
602
-                $assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>"
603
-                                                  . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>'
604
-                                                  . ' <span class="count">(' . $count . ')</span>';
602
+                $assembled_views[$view['slug']] = "\t<li class='".$view['class']."'>"
603
+                                                  . '<a href="'.$view['url'].'">'.$view['label'].'</a>'
604
+                                                  . ' <span class="count">('.$count.')</span>';
605 605
             }
606 606
         }
607 607
 
608
-        echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : '';
608
+        echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views)."</li>\n" : '';
609 609
         echo "</ul>";
610 610
     }
611 611
 
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
     public function single_row($item)
621 621
     {
622 622
         $row_class = $this->_get_row_class($item);
623
-        echo '<tr class="' . esc_attr($row_class) . '">';
623
+        echo '<tr class="'.esc_attr($row_class).'">';
624 624
         $this->single_row_columns($item);
625 625
         echo '</tr>';
626 626
     }
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 
641 641
         $new_row_class = $row_class;
642 642
 
643
-        if (! empty($this->_ajax_sorting_callback)) {
643
+        if ( ! empty($this->_ajax_sorting_callback)) {
644 644
             $new_row_class .= ' rowsortable';
645 645
         }
646 646
 
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
      */
654 654
     public function get_sortable_columns()
655 655
     {
656
-        return (array)$this->_sortable_columns;
656
+        return (array) $this->_sortable_columns;
657 657
     }
658 658
 
659 659
 
@@ -672,12 +672,12 @@  discard block
 block discarded – undo
672 672
     public function get_hidden_columns()
673 673
     {
674 674
         $user_id     = get_current_user_id();
675
-        $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
675
+        $has_default = get_user_option('default'.$this->screen->id.'columnshidden', $user_id);
676 676
         if (empty($has_default) && ! empty($this->_hidden_columns)) {
677
-            update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
678
-            update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
677
+            update_user_option($user_id, 'default'.$this->screen->id.'columnshidden', true);
678
+            update_user_option($user_id, 'manage'.$this->screen->id.'columnshidden', $this->_hidden_columns, true);
679 679
         }
680
-        $ref = 'manage' . $this->screen->id . 'columnshidden';
680
+        $ref = 'manage'.$this->screen->id.'columnshidden';
681 681
         return (array) get_user_option($ref, $user_id);
682 682
     }
683 683
 
@@ -706,12 +706,12 @@  discard block
 block discarded – undo
706 706
             $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : '';
707 707
             $style        = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : '';
708 708
 
709
-            $classes = $column_name . ' column-' . $column_name . $hidden_class;
709
+            $classes = $column_name.' column-'.$column_name.$hidden_class;
710 710
             if ($primary === $column_name) {
711 711
                 $classes .= ' has-row-actions column-primary';
712 712
             }
713 713
 
714
-            $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
714
+            $data = ' data-colname="'.wp_strip_all_tags($column_display_name).'"';
715 715
 
716 716
             $class = "class='$classes'";
717 717
 
@@ -726,11 +726,11 @@  discard block
 block discarded – undo
726 726
                     $this
727 727
                 );
728 728
                 echo '</th>';
729
-            } elseif (method_exists($this, 'column_' . $column_name)) {
729
+            } elseif (method_exists($this, 'column_'.$column_name)) {
730 730
                 echo "<td $attributes>";
731 731
                 echo apply_filters(
732
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
733
-                    call_user_func(array($this, 'column_' . $column_name), $item),
732
+                    'FHEE__EE_Admin_List_Table__single_row_columns__column_'.$column_name.'__column_content',
733
+                    call_user_func(array($this, 'column_'.$column_name), $item),
734 734
                     $item,
735 735
                     $this
736 736
                 );
@@ -846,9 +846,9 @@  discard block
 block discarded – undo
846 846
         $action_id = ''
847 847
     ) {
848 848
         $content      = '';
849
-        $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : '';
850
-        $action_id    = ! empty($action_id) ? ' id="' . $action_id . '"' : '';
851
-        $content      .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
849
+        $action_class = ! empty($action_class) ? ' class="'.$action_class.'"' : '';
850
+        $action_id    = ! empty($action_id) ? ' id="'.$action_id.'"' : '';
851
+        $content .= ! empty($action_container) ? '<'.$action_container.$action_class.$action_id.'>' : '';
852 852
         try {
853 853
             $content .= apply_filters(
854 854
                 'FHEE__EE_Admin_List_Table___action_string__action_items',
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
             }
863 863
             $content .= $action_items;
864 864
         }
865
-        $content .= ! empty($action_container) ? '</' . $action_container . '>' : '';
865
+        $content .= ! empty($action_container) ? '</'.$action_container.'>' : '';
866 866
         return $content;
867 867
     }
868 868
 }
Please login to merge, or discard this patch.
core/services/shortcodes/LegacyShortcodesManager.php 1 patch
Indentation   +423 added lines, -423 removed lines patch added patch discarded remove patch
@@ -25,429 +25,429 @@
 block discarded – undo
25 25
 class LegacyShortcodesManager
26 26
 {
27 27
 
28
-    /**
29
-     * @var EE_Registry $registry
30
-     */
31
-    private $registry;
32
-
33
-
34
-
35
-
36
-    /**
37
-     * LegacyShortcodesManager constructor.
38
-     *
39
-     * @param \EE_Registry $registry
40
-     */
41
-    public function __construct(EE_Registry $registry)
42
-    {
43
-        $this->registry = $registry;
44
-    }
45
-
46
-
47
-
48
-    /**
49
-     * @return EE_Registry
50
-     */
51
-    public function registry()
52
-    {
53
-        return $this->registry;
54
-    }
55
-
56
-
57
-
58
-    /**
59
-     * registerShortcodes
60
-     *
61
-     * @return void
62
-     */
63
-    public function registerShortcodes()
64
-    {
65
-        $this->registry->shortcodes = $this->getShortcodes();
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * getShortcodes
72
-     *
73
-     * @return array
74
-     */
75
-    public function getShortcodes()
76
-    {
77
-        // previously this method would glob the shortcodes directory
78
-        // then filter that list of shortcodes to register,
79
-        // but now we are going to just supply an empty array.
80
-        // this allows any shortcodes that have not yet been converted to the new system
81
-        // to still get loaded and processed, albeit using the same legacy logic as before
82
-        $shortcodes_to_register = apply_filters(
83
-            'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
84
-            array()
85
-        );
86
-        if ( ! empty($shortcodes_to_register)) {
87
-            // cycle thru shortcode folders
88
-            foreach ($shortcodes_to_register as $shortcode_path) {
89
-                // add to list of installed shortcode modules
90
-                $this->registerShortcode($shortcode_path);
91
-            }
92
-        }
93
-        // filter list of installed modules
94
-        return apply_filters(
95
-            'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
96
-            ! empty($this->registry->shortcodes)
97
-                ? $this->registry->shortcodes
98
-                : array()
99
-        );
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     *    register_shortcode - makes core aware of this shortcode
106
-     *
107
-     * @access    public
108
-     * @param    string $shortcode_path - full path up to and including shortcode folder
109
-     * @return    bool
110
-     */
111
-    public function registerShortcode($shortcode_path = null)
112
-    {
113
-        do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path);
114
-        $shortcode_ext = '.shortcode.php';
115
-        // make all separators match
116
-        $shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path);
117
-        // does the file path INCLUDE the actual file name as part of the path ?
118
-        if (strpos($shortcode_path, $shortcode_ext) !== false) {
119
-            // grab shortcode file name from directory name and break apart at dots
120
-            $shortcode_file = explode('.', basename($shortcode_path));
121
-            // take first segment from file name pieces and remove class prefix if it exists
122
-            $shortcode = strpos($shortcode_file[0], 'EES_') === 0
123
-                ? substr($shortcode_file[0], 4)
124
-                : $shortcode_file[0];
125
-            // sanitize shortcode directory name
126
-            $shortcode = sanitize_key($shortcode);
127
-            // now we need to rebuild the shortcode path
128
-            $shortcode_path = explode(DS, $shortcode_path);
129
-            // remove last segment
130
-            array_pop($shortcode_path);
131
-            // glue it back together
132
-            $shortcode_path = implode(DS, $shortcode_path) . DS;
133
-        } else {
134
-            // we need to generate the filename based off of the folder name
135
-            // grab and sanitize shortcode directory name
136
-            $shortcode = sanitize_key(basename($shortcode_path));
137
-            $shortcode_path = rtrim($shortcode_path, DS) . DS;
138
-        }
139
-        // create classname from shortcode directory or file name
140
-        $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
141
-        // add class prefix
142
-        $shortcode_class = 'EES_' . $shortcode;
143
-        // does the shortcode exist ?
144
-        if ( ! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) {
145
-            $msg = sprintf(
146
-                esc_html__(
147
-                    'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
148
-                    'event_espresso'
149
-                ),
150
-                $shortcode_class,
151
-                $shortcode_path . DS . $shortcode_class . $shortcode_ext
152
-            );
153
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
154
-            return false;
155
-        }
156
-        // load the shortcode class file
157
-        require_once($shortcode_path . $shortcode_class . $shortcode_ext);
158
-        // verify that class exists
159
-        if ( ! class_exists($shortcode_class)) {
160
-            $msg = sprintf(
161
-                esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'),
162
-                $shortcode_class
163
-            );
164
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
165
-            return false;
166
-        }
167
-        $shortcode = strtoupper($shortcode);
168
-        // add to array of registered shortcodes
169
-        $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
170
-        return true;
171
-    }
172
-
173
-
174
-
175
-    /**
176
-     *    _initialize_shortcodes
177
-     *    allow shortcodes to set hooks for the rest of the system
178
-     *
179
-     * @access private
180
-     * @return void
181
-     */
182
-    public function addShortcodes()
183
-    {
184
-        // cycle thru shortcode folders
185
-        foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) {
186
-            // add class prefix
187
-            $shortcode_class = 'EES_' . $shortcode;
188
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
189
-            // which set hooks ?
190
-            if (is_admin()) {
191
-                // fire immediately
192
-                call_user_func(array($shortcode_class, 'set_hooks_admin'));
193
-            } else {
194
-                // delay until other systems are online
195
-                add_action(
196
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
197
-                    array($shortcode_class, 'set_hooks')
198
-                );
199
-                // convert classname to UPPERCASE and create WP shortcode.
200
-                $shortcode_tag = strtoupper($shortcode);
201
-                // but first check if the shortcode has already
202
-                // been added before assigning 'fallback_shortcode_processor'
203
-                if ( ! shortcode_exists($shortcode_tag)) {
204
-                    // NOTE: this shortcode declaration will get overridden if the shortcode
205
-                    // is successfully detected in the post content in initializeShortcode()
206
-                    add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
207
-                }
208
-            }
209
-        }
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * callback for the WP "get_header" hook point
216
-     * checks posts for EE shortcodes, and initializes them,
217
-     * then toggles filter switch that loads core default assets
218
-     *
219
-     * @param \WP_Query $wp_query
220
-     * @return void
221
-     */
222
-    public function initializeShortcodes(WP_Query $wp_query)
223
-    {
224
-        if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) {
225
-            return;
226
-        }
227
-        global $wp;
228
-        /** @var EE_Front_controller $Front_Controller */
229
-        $Front_Controller = $this->registry->load_core('Front_Controller', array(), false);
230
-        do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller);
231
-        $Front_Controller->Request_Handler()->set_request_vars();
232
-        // grab post_name from request
233
-        $current_post = apply_filters(
234
-            'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name',
235
-            $Front_Controller->Request_Handler()->get('post_name')
236
-        );
237
-        $show_on_front = get_option('show_on_front');
238
-        // if it's not set, then check if frontpage is blog
239
-        if (empty($current_post)) {
240
-            // yup.. this is the posts page, prepare to load all shortcode modules
241
-            $current_post = 'posts';
242
-            // unless..
243
-            if ($show_on_front === 'page') {
244
-                // some other page is set as the homepage
245
-                $page_on_front = get_option('page_on_front');
246
-                if ($page_on_front) {
247
-                    // k now we need to find the post_name for this page
248
-                    global $wpdb;
249
-                    $page_on_front = $wpdb->get_var(
250
-                        $wpdb->prepare(
251
-                            "SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d",
252
-                            $page_on_front
253
-                        )
254
-                    );
255
-                    // set the current post slug to what it actually is
256
-                    $current_post = $page_on_front ? $page_on_front : $current_post;
257
-                }
258
-            }
259
-        }
260
-        // in case $current_post is hierarchical like: /parent-page/current-page
261
-        $current_post = basename($current_post);
262
-        if (
263
-            // is current page/post the "blog" page ?
264
-            $current_post === EE_Config::get_page_for_posts()
265
-            // or are we on a category page?
266
-            || (
267
-                is_array(term_exists($current_post, 'category'))
268
-                || array_key_exists('category_name', $wp->query_vars)
269
-            )
270
-        ) {
271
-            // initialize all legacy shortcodes
272
-            $load_assets = $this->parseContentForShortcodes('', true);
273
-        } else {
274
-            global $wpdb;
275
-            $post_content = $wpdb->get_var(
276
-                $wpdb->prepare(
277
-                    "SELECT post_content from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s",
278
-                    $current_post
279
-                )
280
-            );
281
-            $load_assets = $this->parseContentForShortcodes($post_content);
282
-        }
283
-        if ($load_assets) {
284
-            $this->registry->REQ->set_espresso_page(true);
285
-            add_filter('FHEE_load_css', '__return_true');
286
-            add_filter('FHEE_load_js', '__return_true');
287
-        }
288
-        do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller);
289
-    }
290
-
291
-
292
-
293
-    /**
294
-     * checks supplied content against list of legacy shortcodes,
295
-     * then initializes any found shortcodes, and returns true.
296
-     * returns false if no shortcodes found.
297
-     *
298
-     * @param string $content
299
-     * @param bool   $load_all if true, then ALL active legacy shortcodes will be initialized
300
-     * @return bool
301
-     */
302
-    public function parseContentForShortcodes($content = '', $load_all = false)
303
-    {
304
-        $has_shortcode = false;
305
-        foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) {
306
-            if ($load_all || has_shortcode($content, $shortcode_class) ) {
307
-                // load up the shortcode
308
-                $this->initializeShortcode($shortcode_class);
309
-                $has_shortcode = true;
310
-            }
311
-        }
312
-        return $has_shortcode;
313
-    }
314
-
315
-
316
-
317
-    /**
318
-     * given a shortcode name, will instantiate the shortcode and call it's run() method
319
-     *
320
-     * @param string $shortcode_class
321
-     * @param WP     $wp
322
-     */
323
-    public function initializeShortcode($shortcode_class = '', WP $wp = null)
324
-    {
325
-        // don't do anything if shortcode is already initialized
326
-        if (
327
-            empty($this->registry->shortcodes->{$shortcode_class})
328
-            || ! is_string($this->registry->shortcodes->{$shortcode_class})
329
-        ) {
330
-            return;
331
-        }
332
-        // let's pause to reflect on this...
333
-        $sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class));
334
-        // ensure that class is actually a shortcode
335
-        if (
336
-            defined('WP_DEBUG')
337
-            && WP_DEBUG === true
338
-            && ! $sc_reflector->isSubclassOf('EES_Shortcode')
339
-        ) {
340
-            EE_Error::add_error(
341
-                sprintf(
342
-                    esc_html__(
343
-                        'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
344
-                        'event_espresso'
345
-                    ),
346
-                    $shortcode_class
347
-                ),
348
-                __FILE__,
349
-                __FUNCTION__,
350
-                __LINE__
351
-            );
352
-            add_filter('FHEE_run_EE_the_content', '__return_true');
353
-            return;
354
-        }
355
-        global $wp;
356
-        // and pass the request object to the run method
357
-        $this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
358
-        // fire the shortcode class's run method, so that it can activate resources
359
-        $this->registry->shortcodes->{$shortcode_class}->run($wp);
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * get classname, remove EES_prefix, and convert to UPPERCASE
366
-     *
367
-     * @param string $class_name
368
-     * @return string
369
-     */
370
-    public static function generateShortcodeTagFromClassName($class_name)
371
-    {
372
-        return strtoupper(str_replace('EES_', '', $class_name));
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * add EES_prefix and Capitalize words
379
-     *
380
-     * @param string $tag
381
-     * @return string
382
-     */
383
-    public static function generateShortcodeClassNameFromTag($tag)
384
-    {
385
-        // order of operation runs from inside to out
386
-        // 5) maybe add prefix
387
-        return LegacyShortcodesManager::addShortcodeClassPrefix(
388
-        // 4) find spaces, replace with underscores
389
-            str_replace(
390
-                ' ',
391
-                '_',
392
-                // 3) capitalize first letter of each word
393
-                ucwords(
394
-                // 2) also change to lowercase so ucwords() will work
395
-                    strtolower(
396
-                    // 1) find underscores, replace with spaces so ucwords() will work
397
-                        str_replace(
398
-                            '_',
399
-                            ' ',
400
-                            $tag
401
-                        )
402
-                    )
403
-                )
404
-            )
405
-        );
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * maybe add EES_prefix
412
-     *
413
-     * @param string $class_name
414
-     * @return string
415
-     */
416
-    public static function addShortcodeClassPrefix($class_name)
417
-    {
418
-        return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name;
419
-    }
420
-
421
-
422
-
423
-    /**
424
-     * @return array
425
-     */
426
-    public function getEspressoShortcodeTags()
427
-    {
428
-        static $shortcode_tags = array();
429
-        if (empty($shortcode_tags)) {
430
-            $shortcode_tags = array_keys((array)$this->registry->shortcodes);
431
-        }
432
-        return $shortcode_tags;
433
-    }
434
-
435
-
436
-
437
-    /**
438
-     * @param string $content
439
-     * @return string
440
-     */
441
-    public function doShortcode($content)
442
-    {
443
-        foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) {
444
-            if (strpos($content, $shortcode_tag) !== false) {
445
-                $shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag);
446
-                $this->initializeShortcode($shortcode_class);
447
-            }
448
-        }
449
-        return do_shortcode($content);
450
-    }
28
+	/**
29
+	 * @var EE_Registry $registry
30
+	 */
31
+	private $registry;
32
+
33
+
34
+
35
+
36
+	/**
37
+	 * LegacyShortcodesManager constructor.
38
+	 *
39
+	 * @param \EE_Registry $registry
40
+	 */
41
+	public function __construct(EE_Registry $registry)
42
+	{
43
+		$this->registry = $registry;
44
+	}
45
+
46
+
47
+
48
+	/**
49
+	 * @return EE_Registry
50
+	 */
51
+	public function registry()
52
+	{
53
+		return $this->registry;
54
+	}
55
+
56
+
57
+
58
+	/**
59
+	 * registerShortcodes
60
+	 *
61
+	 * @return void
62
+	 */
63
+	public function registerShortcodes()
64
+	{
65
+		$this->registry->shortcodes = $this->getShortcodes();
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * getShortcodes
72
+	 *
73
+	 * @return array
74
+	 */
75
+	public function getShortcodes()
76
+	{
77
+		// previously this method would glob the shortcodes directory
78
+		// then filter that list of shortcodes to register,
79
+		// but now we are going to just supply an empty array.
80
+		// this allows any shortcodes that have not yet been converted to the new system
81
+		// to still get loaded and processed, albeit using the same legacy logic as before
82
+		$shortcodes_to_register = apply_filters(
83
+			'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
84
+			array()
85
+		);
86
+		if ( ! empty($shortcodes_to_register)) {
87
+			// cycle thru shortcode folders
88
+			foreach ($shortcodes_to_register as $shortcode_path) {
89
+				// add to list of installed shortcode modules
90
+				$this->registerShortcode($shortcode_path);
91
+			}
92
+		}
93
+		// filter list of installed modules
94
+		return apply_filters(
95
+			'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
96
+			! empty($this->registry->shortcodes)
97
+				? $this->registry->shortcodes
98
+				: array()
99
+		);
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 *    register_shortcode - makes core aware of this shortcode
106
+	 *
107
+	 * @access    public
108
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
109
+	 * @return    bool
110
+	 */
111
+	public function registerShortcode($shortcode_path = null)
112
+	{
113
+		do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path);
114
+		$shortcode_ext = '.shortcode.php';
115
+		// make all separators match
116
+		$shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path);
117
+		// does the file path INCLUDE the actual file name as part of the path ?
118
+		if (strpos($shortcode_path, $shortcode_ext) !== false) {
119
+			// grab shortcode file name from directory name and break apart at dots
120
+			$shortcode_file = explode('.', basename($shortcode_path));
121
+			// take first segment from file name pieces and remove class prefix if it exists
122
+			$shortcode = strpos($shortcode_file[0], 'EES_') === 0
123
+				? substr($shortcode_file[0], 4)
124
+				: $shortcode_file[0];
125
+			// sanitize shortcode directory name
126
+			$shortcode = sanitize_key($shortcode);
127
+			// now we need to rebuild the shortcode path
128
+			$shortcode_path = explode(DS, $shortcode_path);
129
+			// remove last segment
130
+			array_pop($shortcode_path);
131
+			// glue it back together
132
+			$shortcode_path = implode(DS, $shortcode_path) . DS;
133
+		} else {
134
+			// we need to generate the filename based off of the folder name
135
+			// grab and sanitize shortcode directory name
136
+			$shortcode = sanitize_key(basename($shortcode_path));
137
+			$shortcode_path = rtrim($shortcode_path, DS) . DS;
138
+		}
139
+		// create classname from shortcode directory or file name
140
+		$shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
141
+		// add class prefix
142
+		$shortcode_class = 'EES_' . $shortcode;
143
+		// does the shortcode exist ?
144
+		if ( ! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) {
145
+			$msg = sprintf(
146
+				esc_html__(
147
+					'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
148
+					'event_espresso'
149
+				),
150
+				$shortcode_class,
151
+				$shortcode_path . DS . $shortcode_class . $shortcode_ext
152
+			);
153
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
154
+			return false;
155
+		}
156
+		// load the shortcode class file
157
+		require_once($shortcode_path . $shortcode_class . $shortcode_ext);
158
+		// verify that class exists
159
+		if ( ! class_exists($shortcode_class)) {
160
+			$msg = sprintf(
161
+				esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'),
162
+				$shortcode_class
163
+			);
164
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
165
+			return false;
166
+		}
167
+		$shortcode = strtoupper($shortcode);
168
+		// add to array of registered shortcodes
169
+		$this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
170
+		return true;
171
+	}
172
+
173
+
174
+
175
+	/**
176
+	 *    _initialize_shortcodes
177
+	 *    allow shortcodes to set hooks for the rest of the system
178
+	 *
179
+	 * @access private
180
+	 * @return void
181
+	 */
182
+	public function addShortcodes()
183
+	{
184
+		// cycle thru shortcode folders
185
+		foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) {
186
+			// add class prefix
187
+			$shortcode_class = 'EES_' . $shortcode;
188
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
189
+			// which set hooks ?
190
+			if (is_admin()) {
191
+				// fire immediately
192
+				call_user_func(array($shortcode_class, 'set_hooks_admin'));
193
+			} else {
194
+				// delay until other systems are online
195
+				add_action(
196
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
197
+					array($shortcode_class, 'set_hooks')
198
+				);
199
+				// convert classname to UPPERCASE and create WP shortcode.
200
+				$shortcode_tag = strtoupper($shortcode);
201
+				// but first check if the shortcode has already
202
+				// been added before assigning 'fallback_shortcode_processor'
203
+				if ( ! shortcode_exists($shortcode_tag)) {
204
+					// NOTE: this shortcode declaration will get overridden if the shortcode
205
+					// is successfully detected in the post content in initializeShortcode()
206
+					add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
207
+				}
208
+			}
209
+		}
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * callback for the WP "get_header" hook point
216
+	 * checks posts for EE shortcodes, and initializes them,
217
+	 * then toggles filter switch that loads core default assets
218
+	 *
219
+	 * @param \WP_Query $wp_query
220
+	 * @return void
221
+	 */
222
+	public function initializeShortcodes(WP_Query $wp_query)
223
+	{
224
+		if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) {
225
+			return;
226
+		}
227
+		global $wp;
228
+		/** @var EE_Front_controller $Front_Controller */
229
+		$Front_Controller = $this->registry->load_core('Front_Controller', array(), false);
230
+		do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller);
231
+		$Front_Controller->Request_Handler()->set_request_vars();
232
+		// grab post_name from request
233
+		$current_post = apply_filters(
234
+			'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name',
235
+			$Front_Controller->Request_Handler()->get('post_name')
236
+		);
237
+		$show_on_front = get_option('show_on_front');
238
+		// if it's not set, then check if frontpage is blog
239
+		if (empty($current_post)) {
240
+			// yup.. this is the posts page, prepare to load all shortcode modules
241
+			$current_post = 'posts';
242
+			// unless..
243
+			if ($show_on_front === 'page') {
244
+				// some other page is set as the homepage
245
+				$page_on_front = get_option('page_on_front');
246
+				if ($page_on_front) {
247
+					// k now we need to find the post_name for this page
248
+					global $wpdb;
249
+					$page_on_front = $wpdb->get_var(
250
+						$wpdb->prepare(
251
+							"SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d",
252
+							$page_on_front
253
+						)
254
+					);
255
+					// set the current post slug to what it actually is
256
+					$current_post = $page_on_front ? $page_on_front : $current_post;
257
+				}
258
+			}
259
+		}
260
+		// in case $current_post is hierarchical like: /parent-page/current-page
261
+		$current_post = basename($current_post);
262
+		if (
263
+			// is current page/post the "blog" page ?
264
+			$current_post === EE_Config::get_page_for_posts()
265
+			// or are we on a category page?
266
+			|| (
267
+				is_array(term_exists($current_post, 'category'))
268
+				|| array_key_exists('category_name', $wp->query_vars)
269
+			)
270
+		) {
271
+			// initialize all legacy shortcodes
272
+			$load_assets = $this->parseContentForShortcodes('', true);
273
+		} else {
274
+			global $wpdb;
275
+			$post_content = $wpdb->get_var(
276
+				$wpdb->prepare(
277
+					"SELECT post_content from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s",
278
+					$current_post
279
+				)
280
+			);
281
+			$load_assets = $this->parseContentForShortcodes($post_content);
282
+		}
283
+		if ($load_assets) {
284
+			$this->registry->REQ->set_espresso_page(true);
285
+			add_filter('FHEE_load_css', '__return_true');
286
+			add_filter('FHEE_load_js', '__return_true');
287
+		}
288
+		do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller);
289
+	}
290
+
291
+
292
+
293
+	/**
294
+	 * checks supplied content against list of legacy shortcodes,
295
+	 * then initializes any found shortcodes, and returns true.
296
+	 * returns false if no shortcodes found.
297
+	 *
298
+	 * @param string $content
299
+	 * @param bool   $load_all if true, then ALL active legacy shortcodes will be initialized
300
+	 * @return bool
301
+	 */
302
+	public function parseContentForShortcodes($content = '', $load_all = false)
303
+	{
304
+		$has_shortcode = false;
305
+		foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) {
306
+			if ($load_all || has_shortcode($content, $shortcode_class) ) {
307
+				// load up the shortcode
308
+				$this->initializeShortcode($shortcode_class);
309
+				$has_shortcode = true;
310
+			}
311
+		}
312
+		return $has_shortcode;
313
+	}
314
+
315
+
316
+
317
+	/**
318
+	 * given a shortcode name, will instantiate the shortcode and call it's run() method
319
+	 *
320
+	 * @param string $shortcode_class
321
+	 * @param WP     $wp
322
+	 */
323
+	public function initializeShortcode($shortcode_class = '', WP $wp = null)
324
+	{
325
+		// don't do anything if shortcode is already initialized
326
+		if (
327
+			empty($this->registry->shortcodes->{$shortcode_class})
328
+			|| ! is_string($this->registry->shortcodes->{$shortcode_class})
329
+		) {
330
+			return;
331
+		}
332
+		// let's pause to reflect on this...
333
+		$sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class));
334
+		// ensure that class is actually a shortcode
335
+		if (
336
+			defined('WP_DEBUG')
337
+			&& WP_DEBUG === true
338
+			&& ! $sc_reflector->isSubclassOf('EES_Shortcode')
339
+		) {
340
+			EE_Error::add_error(
341
+				sprintf(
342
+					esc_html__(
343
+						'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
344
+						'event_espresso'
345
+					),
346
+					$shortcode_class
347
+				),
348
+				__FILE__,
349
+				__FUNCTION__,
350
+				__LINE__
351
+			);
352
+			add_filter('FHEE_run_EE_the_content', '__return_true');
353
+			return;
354
+		}
355
+		global $wp;
356
+		// and pass the request object to the run method
357
+		$this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
358
+		// fire the shortcode class's run method, so that it can activate resources
359
+		$this->registry->shortcodes->{$shortcode_class}->run($wp);
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * get classname, remove EES_prefix, and convert to UPPERCASE
366
+	 *
367
+	 * @param string $class_name
368
+	 * @return string
369
+	 */
370
+	public static function generateShortcodeTagFromClassName($class_name)
371
+	{
372
+		return strtoupper(str_replace('EES_', '', $class_name));
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * add EES_prefix and Capitalize words
379
+	 *
380
+	 * @param string $tag
381
+	 * @return string
382
+	 */
383
+	public static function generateShortcodeClassNameFromTag($tag)
384
+	{
385
+		// order of operation runs from inside to out
386
+		// 5) maybe add prefix
387
+		return LegacyShortcodesManager::addShortcodeClassPrefix(
388
+		// 4) find spaces, replace with underscores
389
+			str_replace(
390
+				' ',
391
+				'_',
392
+				// 3) capitalize first letter of each word
393
+				ucwords(
394
+				// 2) also change to lowercase so ucwords() will work
395
+					strtolower(
396
+					// 1) find underscores, replace with spaces so ucwords() will work
397
+						str_replace(
398
+							'_',
399
+							' ',
400
+							$tag
401
+						)
402
+					)
403
+				)
404
+			)
405
+		);
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * maybe add EES_prefix
412
+	 *
413
+	 * @param string $class_name
414
+	 * @return string
415
+	 */
416
+	public static function addShortcodeClassPrefix($class_name)
417
+	{
418
+		return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name;
419
+	}
420
+
421
+
422
+
423
+	/**
424
+	 * @return array
425
+	 */
426
+	public function getEspressoShortcodeTags()
427
+	{
428
+		static $shortcode_tags = array();
429
+		if (empty($shortcode_tags)) {
430
+			$shortcode_tags = array_keys((array)$this->registry->shortcodes);
431
+		}
432
+		return $shortcode_tags;
433
+	}
434
+
435
+
436
+
437
+	/**
438
+	 * @param string $content
439
+	 * @return string
440
+	 */
441
+	public function doShortcode($content)
442
+	{
443
+		foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) {
444
+			if (strpos($content, $shortcode_tag) !== false) {
445
+				$shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag);
446
+				$this->initializeShortcode($shortcode_class);
447
+			}
448
+		}
449
+		return do_shortcode($content);
450
+	}
451 451
 
452 452
 
453 453
 
Please login to merge, or discard this patch.
admin/extend/messages/espresso_events_Messages_Hooks_Extend.class.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@
 block discarded – undo
98 98
      *
99 99
      * @param  EE_Event $event EE event object
100 100
      * @param  array    $data  The request data from the form
101
-     * @return bool success or fail
101
+     * @return integer success or fail
102 102
      * @throws EE_Error
103 103
      */
104 104
     public function attach_evt_message_templates($event, $data)
Please login to merge, or discard this patch.
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -14,276 +14,276 @@
 block discarded – undo
14 14
  */
15 15
 class espresso_events_Messages_Hooks_Extend extends espresso_events_Messages_Hooks
16 16
 {
17
-    /**
18
-     * espresso_events_Messages_Hooks_Extend constructor.
19
-     *
20
-     * @param \EE_Admin_Page $admin_page
21
-     */
22
-    public function __construct(EE_Admin_Page $admin_page)
23
-    {
24
-        /**
25
-         * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
26
-         */
27
-        if (! EE_Registry::instance()->CAP->current_user_can(
28
-            'ee_edit_messages',
29
-            'messages_events_editor_metabox'
30
-        )) {
31
-            return;
32
-        }
33
-        add_filter(
34
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
35
-            array($this, 'caf_updates'),
36
-            10
37
-        );
38
-        add_action(
39
-            'AHEE__Extend_Events_Admin_Page___duplicate_event__after',
40
-            array($this, 'duplicate_custom_message_settings'),
41
-            10,
42
-            2
43
-        );
44
-        parent::__construct($admin_page);
45
-    }
46
-
47
-
48
-    /**
49
-     * extending the properties set in espresso_events_Messages_Hooks
50
-     *
51
-     * @access protected
52
-     * @return void
53
-     */
54
-    protected function _extend_properties()
55
-    {
56
-        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
57
-        $this->_ajax_func = array(
58
-            'ee_msgs_create_new_custom' => 'create_new_custom',
59
-        );
60
-        $this->_metaboxes = array(
61
-            0 => array(
62
-                'page_route' => array('edit', 'create_new'),
63
-                'func'       => 'messages_metabox',
64
-                'label'      => esc_html__('Notifications', 'event_espresso'),
65
-                'priority'   => 'high',
66
-            ),
67
-        );
68
-
69
-        //see explanation for layout in EE_Admin_Hooks
70
-        $this->_scripts_styles = array(
71
-            'registers' => array(
72
-                'events_msg_admin'     => array(
73
-                    'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
74
-                    'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'),
75
-                ),
76
-                'events_msg_admin_css' => array(
77
-                    'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
78
-                    'type' => 'css',
79
-                ),
80
-            ),
81
-            'enqueues'  => array(
82
-                'events_msg_admin'     => array('edit', 'create_new'),
83
-                'events_msg_admin_css' => array('edit', 'create_new'),
84
-            ),
85
-        );
86
-    }
87
-
88
-
89
-    public function caf_updates($update_callbacks)
90
-    {
91
-        $update_callbacks[] = array($this, 'attach_evt_message_templates');
92
-        return $update_callbacks;
93
-    }
94
-
95
-
96
-    /**
97
-     * Handles attaching Message Templates to the Event on save.
98
-     *
99
-     * @param  EE_Event $event EE event object
100
-     * @param  array    $data  The request data from the form
101
-     * @return bool success or fail
102
-     * @throws EE_Error
103
-     */
104
-    public function attach_evt_message_templates($event, $data)
105
-    {
106
-        //first we remove all existing relations on the Event for message types.
107
-        $event->_remove_relations('Message_Template_Group');
108
-        //now let's just loop through the selected templates and add relations!
109
-        if (isset($data['event_message_templates_relation'])) {
110
-            foreach ($data['event_message_templates_relation'] as $grp_ID) {
111
-                $event->_add_relation_to($grp_ID, 'Message_Template_Group');
112
-            }
113
-        }
114
-        //now save
115
-        return $event->save();
116
-    }
117
-
118
-
119
-    /**
120
-     * @param $event
121
-     * @param $callback_args
122
-     * @return string
123
-     * @throws \EE_Error
124
-     */
125
-    public function messages_metabox($event, $callback_args)
126
-    {
127
-        //let's get the active messengers (b/c messenger objects have the active message templates)
128
-        //convert 'evt_id' to 'EVT_ID'
129
-        $this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null;
130
-        $this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID'])
131
-            ? $this->_req_data['post']
132
-            : $this->_req_data['EVT_ID'];
133
-
134
-        $this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id'])
135
-            ? $this->_req_data['evt_id']
136
-            : $this->_req_data['EVT_ID'];
137
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
138
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
139
-        $active_messengers        = $message_resource_manager->active_messengers();
140
-        $tabs                     = array();
141
-
142
-        //empty messengers?
143
-        //Note message types will always have at least one available because every messenger has a default message type
144
-        // associated with it (payment) if no other message types are selected.
145
-        if (empty($active_messengers)) {
146
-            $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce(
147
-                array('action' => 'settings'),
148
-                EE_MSG_ADMIN_URL
149
-            );
150
-            $error_msg        = sprintf(
151
-                esc_html__(
152
-                    'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
153
-                    'event_espresso'
154
-                ),
155
-                '<strong>',
156
-                '</strong>',
157
-                '<a href="' . $msg_activate_url . '">',
158
-                '</a>'
159
-            );
160
-            $error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
161
-            $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
162
-
163
-            echo $error_content;
164
-            echo $internal_content;
165
-            return '';
166
-        }
167
-
168
-        $event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null;
169
-        //get content for active messengers
170
-        foreach ($active_messengers as $name => $messenger) {
171
-            //first check if there are any active message types for this messenger.
172
-            $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name);
173
-            if (empty($active_mts)) {
174
-                continue;
175
-            }
176
-
177
-            $tab_content = $messenger->get_messenger_admin_page_content(
178
-                'events',
179
-                'edit',
180
-                array('event' => $event_id)
181
-            );
182
-
183
-            if (! empty($tab_content)) {
184
-                $tabs[$name] = $tab_content;
185
-            }
186
-        }
187
-
188
-
189
-        //we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper.
190
-        $tabbed_content = EEH_Tabbed_Content::display($tabs);
191
-        if ($tabbed_content instanceof WP_Error) {
192
-            $tabbed_content = $tabbed_content->get_error_message();
193
-        }
194
-
195
-        $notices = '
17
+	/**
18
+	 * espresso_events_Messages_Hooks_Extend constructor.
19
+	 *
20
+	 * @param \EE_Admin_Page $admin_page
21
+	 */
22
+	public function __construct(EE_Admin_Page $admin_page)
23
+	{
24
+		/**
25
+		 * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
26
+		 */
27
+		if (! EE_Registry::instance()->CAP->current_user_can(
28
+			'ee_edit_messages',
29
+			'messages_events_editor_metabox'
30
+		)) {
31
+			return;
32
+		}
33
+		add_filter(
34
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
35
+			array($this, 'caf_updates'),
36
+			10
37
+		);
38
+		add_action(
39
+			'AHEE__Extend_Events_Admin_Page___duplicate_event__after',
40
+			array($this, 'duplicate_custom_message_settings'),
41
+			10,
42
+			2
43
+		);
44
+		parent::__construct($admin_page);
45
+	}
46
+
47
+
48
+	/**
49
+	 * extending the properties set in espresso_events_Messages_Hooks
50
+	 *
51
+	 * @access protected
52
+	 * @return void
53
+	 */
54
+	protected function _extend_properties()
55
+	{
56
+		define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
57
+		$this->_ajax_func = array(
58
+			'ee_msgs_create_new_custom' => 'create_new_custom',
59
+		);
60
+		$this->_metaboxes = array(
61
+			0 => array(
62
+				'page_route' => array('edit', 'create_new'),
63
+				'func'       => 'messages_metabox',
64
+				'label'      => esc_html__('Notifications', 'event_espresso'),
65
+				'priority'   => 'high',
66
+			),
67
+		);
68
+
69
+		//see explanation for layout in EE_Admin_Hooks
70
+		$this->_scripts_styles = array(
71
+			'registers' => array(
72
+				'events_msg_admin'     => array(
73
+					'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
74
+					'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'),
75
+				),
76
+				'events_msg_admin_css' => array(
77
+					'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
78
+					'type' => 'css',
79
+				),
80
+			),
81
+			'enqueues'  => array(
82
+				'events_msg_admin'     => array('edit', 'create_new'),
83
+				'events_msg_admin_css' => array('edit', 'create_new'),
84
+			),
85
+		);
86
+	}
87
+
88
+
89
+	public function caf_updates($update_callbacks)
90
+	{
91
+		$update_callbacks[] = array($this, 'attach_evt_message_templates');
92
+		return $update_callbacks;
93
+	}
94
+
95
+
96
+	/**
97
+	 * Handles attaching Message Templates to the Event on save.
98
+	 *
99
+	 * @param  EE_Event $event EE event object
100
+	 * @param  array    $data  The request data from the form
101
+	 * @return bool success or fail
102
+	 * @throws EE_Error
103
+	 */
104
+	public function attach_evt_message_templates($event, $data)
105
+	{
106
+		//first we remove all existing relations on the Event for message types.
107
+		$event->_remove_relations('Message_Template_Group');
108
+		//now let's just loop through the selected templates and add relations!
109
+		if (isset($data['event_message_templates_relation'])) {
110
+			foreach ($data['event_message_templates_relation'] as $grp_ID) {
111
+				$event->_add_relation_to($grp_ID, 'Message_Template_Group');
112
+			}
113
+		}
114
+		//now save
115
+		return $event->save();
116
+	}
117
+
118
+
119
+	/**
120
+	 * @param $event
121
+	 * @param $callback_args
122
+	 * @return string
123
+	 * @throws \EE_Error
124
+	 */
125
+	public function messages_metabox($event, $callback_args)
126
+	{
127
+		//let's get the active messengers (b/c messenger objects have the active message templates)
128
+		//convert 'evt_id' to 'EVT_ID'
129
+		$this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null;
130
+		$this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID'])
131
+			? $this->_req_data['post']
132
+			: $this->_req_data['EVT_ID'];
133
+
134
+		$this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id'])
135
+			? $this->_req_data['evt_id']
136
+			: $this->_req_data['EVT_ID'];
137
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
138
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
139
+		$active_messengers        = $message_resource_manager->active_messengers();
140
+		$tabs                     = array();
141
+
142
+		//empty messengers?
143
+		//Note message types will always have at least one available because every messenger has a default message type
144
+		// associated with it (payment) if no other message types are selected.
145
+		if (empty($active_messengers)) {
146
+			$msg_activate_url = EE_Admin_Page::add_query_args_and_nonce(
147
+				array('action' => 'settings'),
148
+				EE_MSG_ADMIN_URL
149
+			);
150
+			$error_msg        = sprintf(
151
+				esc_html__(
152
+					'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
153
+					'event_espresso'
154
+				),
155
+				'<strong>',
156
+				'</strong>',
157
+				'<a href="' . $msg_activate_url . '">',
158
+				'</a>'
159
+			);
160
+			$error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
161
+			$internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
162
+
163
+			echo $error_content;
164
+			echo $internal_content;
165
+			return '';
166
+		}
167
+
168
+		$event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null;
169
+		//get content for active messengers
170
+		foreach ($active_messengers as $name => $messenger) {
171
+			//first check if there are any active message types for this messenger.
172
+			$active_mts = $message_resource_manager->get_active_message_types_for_messenger($name);
173
+			if (empty($active_mts)) {
174
+				continue;
175
+			}
176
+
177
+			$tab_content = $messenger->get_messenger_admin_page_content(
178
+				'events',
179
+				'edit',
180
+				array('event' => $event_id)
181
+			);
182
+
183
+			if (! empty($tab_content)) {
184
+				$tabs[$name] = $tab_content;
185
+			}
186
+		}
187
+
188
+
189
+		//we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper.
190
+		$tabbed_content = EEH_Tabbed_Content::display($tabs);
191
+		if ($tabbed_content instanceof WP_Error) {
192
+			$tabbed_content = $tabbed_content->get_error_message();
193
+		}
194
+
195
+		$notices = '
196 196
 	<div id="espresso-ajax-loading" class="ajax-loader-grey">
197 197
 		<span class="ee-spinner ee-spin"></span><span class="hidden">'
198
-        . esc_html__('loading...', 'event_espresso')
199
-        . '</span>
198
+		. esc_html__('loading...', 'event_espresso')
199
+		. '</span>
200 200
 	</div>
201 201
 	<div class="ee-notices"></div>';
202 202
 
203
-        if (defined('DOING_AJAX')) {
204
-            return $tabbed_content;
205
-        }
206
-
207
-        do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
208
-        echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
209
-        do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
210
-    }
211
-
212
-
213
-    /**
214
-     * Ajax callback for ee_msgs_create_new_custom ajax request.
215
-     * Takes incoming GRP_ID and name and description values from ajax request
216
-     * to create a new custom template based off of the incoming GRP_ID.
217
-     *
218
-     * @access public
219
-     * @return string either an html string will be returned or a success message
220
-     * @throws EE_Error
221
-     */
222
-    public function create_new_custom()
223
-    {
224
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
225
-            wp_die(__('You don\'t have privileges to do this action', 'event_espresso'));
226
-        }
227
-
228
-        //let's clean up the _POST global a bit for downstream usage of name and description.
229
-        $_POST['templateName']        = ! empty($this->_req_data['custom_template_args']['MTP_name'])
230
-            ? $this->_req_data['custom_template_args']['MTP_name']
231
-            : '';
232
-        $_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description'])
233
-            ? $this->_req_data['custom_template_args']['MTP_description']
234
-            : '';
235
-
236
-
237
-        // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent
238
-        $this->_set_page_object();
239
-
240
-        // is this a template switch if so EE_Admin_Page child needs this object
241
-        $this->_page_object->set_hook_object($this);
242
-
243
-        $this->_page_object->add_message_template(
244
-            $this->_req_data['messageType'],
245
-            $this->_req_data['messenger'],
246
-            $this->_req_data['group_ID']
247
-        );
248
-    }
249
-
250
-
251
-    public function create_new_admin_footer()
252
-    {
253
-        $this->edit_admin_footer();
254
-    }
255
-
256
-
257
-    /**
258
-     * This is the dynamic method for this class
259
-     * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page.
260
-     *
261
-     * @return string
262
-     * @throws DomainException
263
-     */
264
-    public function edit_admin_footer()
265
-    {
266
-        EEH_Template::display_template(
267
-            EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
268
-        );
269
-    }
270
-
271
-
272
-    /**
273
-     * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate
274
-     * the assigned custom message templates.
275
-     *
276
-     * @param EE_Event $new_event
277
-     * @param EE_Event $original_event
278
-     * @throws EE_Error
279
-     */
280
-    public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event)
281
-    {
282
-        $message_template_groups = $original_event->get_many_related('Message_Template_Group');
283
-        foreach ($message_template_groups as $message_template_group) {
284
-            $new_event->_add_relation_to($message_template_group, 'Message_Template_Group');
285
-        }
286
-        //save new event
287
-        $new_event->save();
288
-    }
203
+		if (defined('DOING_AJAX')) {
204
+			return $tabbed_content;
205
+		}
206
+
207
+		do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
208
+		echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
209
+		do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
210
+	}
211
+
212
+
213
+	/**
214
+	 * Ajax callback for ee_msgs_create_new_custom ajax request.
215
+	 * Takes incoming GRP_ID and name and description values from ajax request
216
+	 * to create a new custom template based off of the incoming GRP_ID.
217
+	 *
218
+	 * @access public
219
+	 * @return string either an html string will be returned or a success message
220
+	 * @throws EE_Error
221
+	 */
222
+	public function create_new_custom()
223
+	{
224
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
225
+			wp_die(__('You don\'t have privileges to do this action', 'event_espresso'));
226
+		}
227
+
228
+		//let's clean up the _POST global a bit for downstream usage of name and description.
229
+		$_POST['templateName']        = ! empty($this->_req_data['custom_template_args']['MTP_name'])
230
+			? $this->_req_data['custom_template_args']['MTP_name']
231
+			: '';
232
+		$_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description'])
233
+			? $this->_req_data['custom_template_args']['MTP_description']
234
+			: '';
235
+
236
+
237
+		// set EE_Admin_Page object (see method details in EE_Admin_Hooks parent
238
+		$this->_set_page_object();
239
+
240
+		// is this a template switch if so EE_Admin_Page child needs this object
241
+		$this->_page_object->set_hook_object($this);
242
+
243
+		$this->_page_object->add_message_template(
244
+			$this->_req_data['messageType'],
245
+			$this->_req_data['messenger'],
246
+			$this->_req_data['group_ID']
247
+		);
248
+	}
249
+
250
+
251
+	public function create_new_admin_footer()
252
+	{
253
+		$this->edit_admin_footer();
254
+	}
255
+
256
+
257
+	/**
258
+	 * This is the dynamic method for this class
259
+	 * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page.
260
+	 *
261
+	 * @return string
262
+	 * @throws DomainException
263
+	 */
264
+	public function edit_admin_footer()
265
+	{
266
+		EEH_Template::display_template(
267
+			EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
268
+		);
269
+	}
270
+
271
+
272
+	/**
273
+	 * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate
274
+	 * the assigned custom message templates.
275
+	 *
276
+	 * @param EE_Event $new_event
277
+	 * @param EE_Event $original_event
278
+	 * @throws EE_Error
279
+	 */
280
+	public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event)
281
+	{
282
+		$message_template_groups = $original_event->get_many_related('Message_Template_Group');
283
+		foreach ($message_template_groups as $message_template_group) {
284
+			$new_event->_add_relation_to($message_template_group, 'Message_Template_Group');
285
+		}
286
+		//save new event
287
+		$new_event->save();
288
+	}
289 289
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
         /**
25 25
          * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
26 26
          */
27
-        if (! EE_Registry::instance()->CAP->current_user_can(
27
+        if ( ! EE_Registry::instance()->CAP->current_user_can(
28 28
             'ee_edit_messages',
29 29
             'messages_events_editor_metabox'
30 30
         )) {
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
      */
54 54
     protected function _extend_properties()
55 55
     {
56
-        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
56
+        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'messages/assets/');
57 57
         $this->_ajax_func = array(
58 58
             'ee_msgs_create_new_custom' => 'create_new_custom',
59 59
         );
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
         $this->_scripts_styles = array(
71 71
             'registers' => array(
72 72
                 'events_msg_admin'     => array(
73
-                    'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
73
+                    'url'     => EE_MSGS_EXTEND_ASSETS_URL.'events_messages_admin.js',
74 74
                     'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'),
75 75
                 ),
76 76
                 'events_msg_admin_css' => array(
77
-                    'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
77
+                    'url'  => EE_MSGS_EXTEND_ASSETS_URL.'ee_msg_events_admin.css',
78 78
                     'type' => 'css',
79 79
                 ),
80 80
             ),
@@ -147,18 +147,18 @@  discard block
 block discarded – undo
147 147
                 array('action' => 'settings'),
148 148
                 EE_MSG_ADMIN_URL
149 149
             );
150
-            $error_msg        = sprintf(
150
+            $error_msg = sprintf(
151 151
                 esc_html__(
152 152
                     'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
153 153
                     'event_espresso'
154 154
                 ),
155 155
                 '<strong>',
156 156
                 '</strong>',
157
-                '<a href="' . $msg_activate_url . '">',
157
+                '<a href="'.$msg_activate_url.'">',
158 158
                 '</a>'
159 159
             );
160
-            $error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
161
-            $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
160
+            $error_content    = '<div class="error"><p>'.$error_msg.'</p></div>';
161
+            $internal_content = '<div id="messages-error"><p>'.$error_msg.'</p></div>';
162 162
 
163 163
             echo $error_content;
164 164
             echo $internal_content;
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
                 array('event' => $event_id)
181 181
             );
182 182
 
183
-            if (! empty($tab_content)) {
183
+            if ( ! empty($tab_content)) {
184 184
                 $tabs[$name] = $tab_content;
185 185
             }
186 186
         }
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         }
206 206
 
207 207
         do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
208
-        echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
208
+        echo $notices.'<div class="messages-tabs-content">'.$tabbed_content.'</div>';
209 209
         do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
210 210
     }
211 211
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
      */
222 222
     public function create_new_custom()
223 223
     {
224
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
224
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
225 225
             wp_die(__('You don\'t have privileges to do this action', 'event_espresso'));
226 226
         }
227 227
 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
     public function edit_admin_footer()
265 265
     {
266 266
         EEH_Template::display_template(
267
-            EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
267
+            EE_CORE_CAF_ADMIN_EXTEND.'messages/templates/create_custom_template_form.template.php'
268 268
         );
269 269
     }
270 270
 
Please login to merge, or discard this patch.
core/helpers/EEH_Event_View.helper.php 2 patches
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -32,51 +32,51 @@  discard block
 block discarded – undo
32 32
 
33 33
 
34 34
 
35
-    /**
36
-     * get_event
37
-     * attempts to retrieve an EE_Event object any way it can
38
-     *
39
-     * @param int|WP_Post $EVT_ID
40
-     * @return EE_Event|null
41
-     * @throws \EE_Error
42
-     */
43
-    public static function get_event($EVT_ID = 0)
44
-    {
45
-        // international newspaper?
46
-        global $post;
47
-        $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
48
-            ? $EVT_ID->ID
49
-            : absint($EVT_ID);
50
-        // do we already have the Event  you are looking for?
51
-        if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
52
-            return EEH_Event_View::$_event;
53
-        }
54
-        //reset property so that the new event is cached.
55
-        EEH_Event_View::$_event = null;
56
-        if (! $EVT_ID && $post instanceof EE_Event) {
57
-            EEH_Event_View::$_event = $post;
58
-            return EEH_Event_View::$_event;
59
-        }
60
-        //if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
61
-        //then let's just use that cached event on the $post object.
62
-        if (
63
-            $post instanceof WP_Post
64
-            && $post->post_type === 'espresso_events'
65
-            && isset($post->EE_Event)
66
-            && (
67
-                $EVT_ID === 0
68
-                || $EVT_ID === $post->ID
69
-            )
70
-        ) {
71
-            EEH_Event_View::$_event = $post->EE_Event;
72
-            return EEH_Event_View::$_event;
73
-        }
74
-        //If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID.
75
-        if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
76
-            EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
77
-        }
78
-        return EEH_Event_View::$_event;
79
-    }
35
+	/**
36
+	 * get_event
37
+	 * attempts to retrieve an EE_Event object any way it can
38
+	 *
39
+	 * @param int|WP_Post $EVT_ID
40
+	 * @return EE_Event|null
41
+	 * @throws \EE_Error
42
+	 */
43
+	public static function get_event($EVT_ID = 0)
44
+	{
45
+		// international newspaper?
46
+		global $post;
47
+		$EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events'
48
+			? $EVT_ID->ID
49
+			: absint($EVT_ID);
50
+		// do we already have the Event  you are looking for?
51
+		if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) {
52
+			return EEH_Event_View::$_event;
53
+		}
54
+		//reset property so that the new event is cached.
55
+		EEH_Event_View::$_event = null;
56
+		if (! $EVT_ID && $post instanceof EE_Event) {
57
+			EEH_Event_View::$_event = $post;
58
+			return EEH_Event_View::$_event;
59
+		}
60
+		//if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID
61
+		//then let's just use that cached event on the $post object.
62
+		if (
63
+			$post instanceof WP_Post
64
+			&& $post->post_type === 'espresso_events'
65
+			&& isset($post->EE_Event)
66
+			&& (
67
+				$EVT_ID === 0
68
+				|| $EVT_ID === $post->ID
69
+			)
70
+		) {
71
+			EEH_Event_View::$_event = $post->EE_Event;
72
+			return EEH_Event_View::$_event;
73
+		}
74
+		//If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID.
75
+		if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
76
+			EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
77
+		}
78
+		return EEH_Event_View::$_event;
79
+	}
80 80
 
81 81
 
82 82
 
@@ -152,58 +152,58 @@  discard block
 block discarded – undo
152 152
 	 * @return    string
153 153
 	 */
154 154
 	public static function event_content_or_excerpt( $num_words = NULL, $more = NULL ) {
155
-        global $post;
155
+		global $post;
156 156
 		ob_start();
157 157
 		if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) {
158 158
 			// admin has chosen "full description"
159
-            // for the "Event Espresso - Events > Templates > Display Description" option
159
+			// for the "Event Espresso - Events > Templates > Display Description" option
160 160
 			the_content();
161 161
 		} else if (( is_archive() && espresso_display_excerpt_in_event_list() ) ) {
162
-            if ( has_excerpt( $post->ID )) {
163
-                // admin has chosen "excerpt (short desc)"
164
-                // for the "Event Espresso - Events > Templates > Display Description" option
165
-                // AND an excerpt actually exists
166
-                the_excerpt();
167
-            } else {
168
-                // admin has chosen "excerpt (short desc)"
169
-                // for the "Event Espresso - Events > Templates > Display Description" option
170
-                // but NO excerpt actually exists, so we need to create one
171
-                if ( ! empty( $num_words )) {
172
-                    if ( empty( $more )) {
173
-                        $more_link_text = __( '(more&hellip;)' );
174
-                        $more = ' <a href="' . get_permalink() . '"';
175
-                        $more .= ' class="more-link"';
176
-                        $more .= \EED_Events_Archive::link_target();
177
-                        $more .= '>' . $more_link_text . '</a>';
178
-                        $more = apply_filters( 'the_content_more_link', $more, $more_link_text );
179
-                    }
180
-                    $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' ));
181
-
182
-                    $content =  wp_trim_words( $content, $num_words, ' ' ) . $more;
183
-                } else {
184
-                    $content =  get_the_content();
185
-                }
186
-                global $allowedtags;
187
-                // make sure links are allowed
188
-                $allowedtags['a'] = isset($allowedtags['a'])
189
-                    ? $allowedtags['a']
190
-                    : array();
191
-                // as well as target attribute
192
-                $allowedtags['a']['target'] = isset($allowedtags['a']['target'])
193
-                    ? $allowedtags['a']['target']
194
-                    : false;
195
-                // but get previous value so we can reset it
196
-                $prev_value = $allowedtags['a']['target'];
197
-                $allowedtags['a']['target'] = true;
198
-                $content = wp_kses( $content, $allowedtags );
199
-                $content = strip_shortcodes( $content );
200
-                echo apply_filters( 'the_content', $content );
201
-                $allowedtags['a']['target'] = $prev_value;
202
-            }
203
-        } else {
204
-            // admin has chosen "none"
205
-            // for the "Event Espresso - Events > Templates > Display Description" option
206
-            echo apply_filters( 'the_content', '' );
162
+			if ( has_excerpt( $post->ID )) {
163
+				// admin has chosen "excerpt (short desc)"
164
+				// for the "Event Espresso - Events > Templates > Display Description" option
165
+				// AND an excerpt actually exists
166
+				the_excerpt();
167
+			} else {
168
+				// admin has chosen "excerpt (short desc)"
169
+				// for the "Event Espresso - Events > Templates > Display Description" option
170
+				// but NO excerpt actually exists, so we need to create one
171
+				if ( ! empty( $num_words )) {
172
+					if ( empty( $more )) {
173
+						$more_link_text = __( '(more&hellip;)' );
174
+						$more = ' <a href="' . get_permalink() . '"';
175
+						$more .= ' class="more-link"';
176
+						$more .= \EED_Events_Archive::link_target();
177
+						$more .= '>' . $more_link_text . '</a>';
178
+						$more = apply_filters( 'the_content_more_link', $more, $more_link_text );
179
+					}
180
+					$content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' ));
181
+
182
+					$content =  wp_trim_words( $content, $num_words, ' ' ) . $more;
183
+				} else {
184
+					$content =  get_the_content();
185
+				}
186
+				global $allowedtags;
187
+				// make sure links are allowed
188
+				$allowedtags['a'] = isset($allowedtags['a'])
189
+					? $allowedtags['a']
190
+					: array();
191
+				// as well as target attribute
192
+				$allowedtags['a']['target'] = isset($allowedtags['a']['target'])
193
+					? $allowedtags['a']['target']
194
+					: false;
195
+				// but get previous value so we can reset it
196
+				$prev_value = $allowedtags['a']['target'];
197
+				$allowedtags['a']['target'] = true;
198
+				$content = wp_kses( $content, $allowedtags );
199
+				$content = strip_shortcodes( $content );
200
+				echo apply_filters( 'the_content', $content );
201
+				$allowedtags['a']['target'] = $prev_value;
202
+			}
203
+		} else {
204
+			// admin has chosen "none"
205
+			// for the "Event Espresso - Events > Templates > Display Description" option
206
+			echo apply_filters( 'the_content', '' );
207 207
 		}
208 208
 		return ob_get_clean();
209 209
 	}
@@ -250,11 +250,11 @@  discard block
 block discarded – undo
250 250
 					$url = get_term_link( $term, 'espresso_venue_categories' );
251 251
 					if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) {
252 252
 						$category_links[] = '<a href="' . esc_url( $url )
253
-                                            . '" rel="tag"'
254
-                                            . \EED_Events_Archive::link_target()
255
-                                            .'>'
256
-                                            . $term->name
257
-                                            . '</a>';
253
+											. '" rel="tag"'
254
+											. \EED_Events_Archive::link_target()
255
+											.'>'
256
+											. $term->name
257
+											. '</a>';
258 258
 					}
259 259
 				}
260 260
 			}
Please login to merge, or discard this patch.
Spacing   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         }
54 54
         //reset property so that the new event is cached.
55 55
         EEH_Event_View::$_event = null;
56
-        if (! $EVT_ID && $post instanceof EE_Event) {
56
+        if ( ! $EVT_ID && $post instanceof EE_Event) {
57 57
             EEH_Event_View::$_event = $post;
58 58
             return EEH_Event_View::$_event;
59 59
         }
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
             return EEH_Event_View::$_event;
73 73
         }
74 74
         //If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID.
75
-        if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
75
+        if ( ! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) {
76 76
             EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
77 77
         }
78 78
         return EEH_Event_View::$_event;
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 	 * @param    int $EVT_ID
88 88
 	 * @return    boolean
89 89
 	 */
90
-	public static function display_ticket_selector( $EVT_ID = 0 ) {
91
-		$event = EEH_Event_View::get_event( $EVT_ID );
90
+	public static function display_ticket_selector($EVT_ID = 0) {
91
+		$event = EEH_Event_View::get_event($EVT_ID);
92 92
 		return $event instanceof EE_Event ? $event->display_ticket_selector() : FALSE;
93 93
 	}
94 94
 
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
 	 * @param    int $EVT_ID
102 102
 	 * @return    string
103 103
 	 */
104
-	public static function event_status( $EVT_ID = 0 ) {
105
-		$event = EEH_Event_View::get_event( $EVT_ID );
106
-		return $event instanceof EE_Event ? $event->pretty_active_status( FALSE ) : '';
104
+	public static function event_status($EVT_ID = 0) {
105
+		$event = EEH_Event_View::get_event($EVT_ID);
106
+		return $event instanceof EE_Event ? $event->pretty_active_status(FALSE) : '';
107 107
 	}
108 108
 
109 109
 
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 	 * @param    int $EVT_ID
116 116
 	 *  @return 	string
117 117
 	 */
118
-	public static function event_active_status( $EVT_ID = 0 ) {
119
-		$event = EEH_Event_View::get_event( $EVT_ID );
118
+	public static function event_active_status($EVT_ID = 0) {
119
+		$event = EEH_Event_View::get_event($EVT_ID);
120 120
 		return $event instanceof EE_Event ? $event->pretty_active_status() : 'inactive';
121 121
 	}
122 122
 
@@ -129,13 +129,13 @@  discard block
 block discarded – undo
129 129
 	 * @param    int $EVT_ID
130 130
 	 *  @return 	string
131 131
 	 */
132
-	public static function event_has_content_or_excerpt( $EVT_ID = 0 ) {
133
-		$event = EEH_Event_View::get_event( $EVT_ID );
132
+	public static function event_has_content_or_excerpt($EVT_ID = 0) {
133
+		$event = EEH_Event_View::get_event($EVT_ID);
134 134
 		$has_content_or_excerpt = FALSE;
135
-		if ( $event instanceof EE_Event ) {
136
-			$has_content_or_excerpt = $event->description() != '' || $event->short_description( NULL, NULL, TRUE ) != '' ? TRUE : FALSE;
135
+		if ($event instanceof EE_Event) {
136
+			$has_content_or_excerpt = $event->description() != '' || $event->short_description(NULL, NULL, TRUE) != '' ? TRUE : FALSE;
137 137
 		}
138
-		if ( is_archive() && ! ( espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list() )) {
138
+		if (is_archive() && ! (espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list())) {
139 139
 			$has_content_or_excerpt = FALSE;
140 140
 		}
141 141
 		return $has_content_or_excerpt;
@@ -151,15 +151,15 @@  discard block
 block discarded – undo
151 151
 	 * @param null $more
152 152
 	 * @return    string
153 153
 	 */
154
-	public static function event_content_or_excerpt( $num_words = NULL, $more = NULL ) {
154
+	public static function event_content_or_excerpt($num_words = NULL, $more = NULL) {
155 155
         global $post;
156 156
 		ob_start();
157
-		if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) {
157
+		if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) {
158 158
 			// admin has chosen "full description"
159 159
             // for the "Event Espresso - Events > Templates > Display Description" option
160 160
 			the_content();
161
-		} else if (( is_archive() && espresso_display_excerpt_in_event_list() ) ) {
162
-            if ( has_excerpt( $post->ID )) {
161
+		} else if ((is_archive() && espresso_display_excerpt_in_event_list())) {
162
+            if (has_excerpt($post->ID)) {
163 163
                 // admin has chosen "excerpt (short desc)"
164 164
                 // for the "Event Espresso - Events > Templates > Display Description" option
165 165
                 // AND an excerpt actually exists
@@ -168,20 +168,20 @@  discard block
 block discarded – undo
168 168
                 // admin has chosen "excerpt (short desc)"
169 169
                 // for the "Event Espresso - Events > Templates > Display Description" option
170 170
                 // but NO excerpt actually exists, so we need to create one
171
-                if ( ! empty( $num_words )) {
172
-                    if ( empty( $more )) {
173
-                        $more_link_text = __( '(more&hellip;)' );
174
-                        $more = ' <a href="' . get_permalink() . '"';
171
+                if ( ! empty($num_words)) {
172
+                    if (empty($more)) {
173
+                        $more_link_text = __('(more&hellip;)');
174
+                        $more = ' <a href="'.get_permalink().'"';
175 175
                         $more .= ' class="more-link"';
176 176
                         $more .= \EED_Events_Archive::link_target();
177
-                        $more .= '>' . $more_link_text . '</a>';
178
-                        $more = apply_filters( 'the_content_more_link', $more, $more_link_text );
177
+                        $more .= '>'.$more_link_text.'</a>';
178
+                        $more = apply_filters('the_content_more_link', $more, $more_link_text);
179 179
                     }
180
-                    $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' ));
180
+                    $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK'));
181 181
 
182
-                    $content =  wp_trim_words( $content, $num_words, ' ' ) . $more;
182
+                    $content = wp_trim_words($content, $num_words, ' ').$more;
183 183
                 } else {
184
-                    $content =  get_the_content();
184
+                    $content = get_the_content();
185 185
                 }
186 186
                 global $allowedtags;
187 187
                 // make sure links are allowed
@@ -195,15 +195,15 @@  discard block
 block discarded – undo
195 195
                 // but get previous value so we can reset it
196 196
                 $prev_value = $allowedtags['a']['target'];
197 197
                 $allowedtags['a']['target'] = true;
198
-                $content = wp_kses( $content, $allowedtags );
199
-                $content = strip_shortcodes( $content );
200
-                echo apply_filters( 'the_content', $content );
198
+                $content = wp_kses($content, $allowedtags);
199
+                $content = strip_shortcodes($content);
200
+                echo apply_filters('the_content', $content);
201 201
                 $allowedtags['a']['target'] = $prev_value;
202 202
             }
203 203
         } else {
204 204
             // admin has chosen "none"
205 205
             // for the "Event Espresso - Events > Templates > Display Description" option
206
-            echo apply_filters( 'the_content', '' );
206
+            echo apply_filters('the_content', '');
207 207
 		}
208 208
 		return ob_get_clean();
209 209
 	}
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
 	 * @param    int $EVT_ID
218 218
 	 *  @return 	EE_Ticket[]
219 219
 	 */
220
-	public static function event_tickets_available( $EVT_ID = 0 ) {
221
-		$event = EEH_Event_View::get_event( $EVT_ID );
220
+	public static function event_tickets_available($EVT_ID = 0) {
221
+		$event = EEH_Event_View::get_event($EVT_ID);
222 222
 		$tickets_available_for_purchase = array();
223
-		if( $event instanceof EE_Event ) {
224
-			$datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, FALSE );
225
-			foreach( $datetimes as $datetime ) {
226
-				$tickets_available_for_purchase = array_merge( $tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase() );
223
+		if ($event instanceof EE_Event) {
224
+			$datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, FALSE);
225
+			foreach ($datetimes as $datetime) {
226
+				$tickets_available_for_purchase = array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase());
227 227
 			}
228 228
 		}
229 229
 		return $tickets_available_for_purchase;
@@ -239,17 +239,17 @@  discard block
 block discarded – undo
239 239
 	 * @param 	  bool   $hide_uncategorized
240 240
 	 * @return    string
241 241
 	 */
242
-	public static function event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE ) {
242
+	public static function event_categories($EVT_ID = 0, $hide_uncategorized = TRUE) {
243 243
 		$category_links = array();
244
-		$event = EEH_Event_View::get_event( $EVT_ID );
245
-		if ( $event instanceof EE_Event ) {
246
-			$event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' );
247
-			if ( $event_categories ) {
244
+		$event = EEH_Event_View::get_event($EVT_ID);
245
+		if ($event instanceof EE_Event) {
246
+			$event_categories = get_the_terms($event->ID(), 'espresso_event_categories');
247
+			if ($event_categories) {
248 248
 				// loop thru terms and create links
249
-				foreach ( $event_categories as $term ) {
250
-					$url = get_term_link( $term, 'espresso_venue_categories' );
251
-					if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) {
252
-						$category_links[] = '<a href="' . esc_url( $url )
249
+				foreach ($event_categories as $term) {
250
+					$url = get_term_link($term, 'espresso_venue_categories');
251
+					if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) {
252
+						$category_links[] = '<a href="'.esc_url($url)
253 253
                                             . '" rel="tag"'
254 254
                                             . \EED_Events_Archive::link_target()
255 255
                                             .'>'
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 				}
260 260
 			}
261 261
 		}
262
-		return implode( ', ', $category_links );
262
+		return implode(', ', $category_links);
263 263
 	}
264 264
 
265 265
 
@@ -273,10 +273,10 @@  discard block
 block discarded – undo
273 273
 	 * @param int    $EVT_ID
274 274
 	 * @return    string
275 275
 	 */
276
-	public static function the_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) {
277
-		$datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID );
278
-		$format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
279
-		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) :  '';
276
+	public static function the_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) {
277
+		$datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
278
+		$format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt;
279
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
280 280
 	}
281 281
 
282 282
 
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
 	 * @param int    $EVT_ID
291 291
 	 * @return    string
292 292
 	 */
293
-	public static function the_event_end_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) {
294
-		$datetime = EEH_Event_View::get_last_date_obj( $EVT_ID );
295
-		$format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
296
-		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : '';
293
+	public static function the_event_end_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) {
294
+		$datetime = EEH_Event_View::get_last_date_obj($EVT_ID);
295
+		$format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt;
296
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
297 297
 	}
298 298
 
299 299
 
@@ -307,10 +307,10 @@  discard block
 block discarded – undo
307 307
 	 * @param int    $EVT_ID
308 308
 	 * @return    string
309 309
 	 */
310
-	public static function the_earliest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) {
311
-		$datetime = EEH_Event_View::get_earliest_date_obj( $EVT_ID );
312
-		$format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
313
-		return $datetime instanceof EE_Datetime ?  $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) : '';
310
+	public static function the_earliest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) {
311
+		$datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID);
312
+		$format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt;
313
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : '';
314 314
 	}
315 315
 
316 316
 
@@ -324,10 +324,10 @@  discard block
 block discarded – undo
324 324
 	 * @param int    $EVT_ID
325 325
 	 * @return    string
326 326
 	 */
327
-	public static function the_latest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) {
328
-		$datetime = EEH_Event_View::get_latest_date_obj( $EVT_ID );
329
-		$format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt;
330
-		return $datetime instanceof EE_Datetime ?  $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : '';
327
+	public static function the_latest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) {
328
+		$datetime = EEH_Event_View::get_latest_date_obj($EVT_ID);
329
+		$format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt;
330
+		return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : '';
331 331
 	}
332 332
 
333 333
 
@@ -339,13 +339,13 @@  discard block
 block discarded – undo
339 339
 	 * @param int $EVT_ID
340 340
 	 * @return    string
341 341
 	 */
342
-	public static function event_date_as_calendar_page( $EVT_ID = 0 ) {
343
-		$datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID );
344
-		if ( $datetime instanceof EE_Datetime ) {
342
+	public static function event_date_as_calendar_page($EVT_ID = 0) {
343
+		$datetime = EEH_Event_View::get_primary_date_obj($EVT_ID);
344
+		if ($datetime instanceof EE_Datetime) {
345 345
 	?>
346 346
 		<div class="event-date-calendar-page-dv">
347
-			<div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime( 'DTT_EVT_start', 'M' );?></div>
348
-			<div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date( 'd' );?></div>
347
+			<div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime('DTT_EVT_start', 'M'); ?></div>
348
+			<div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date('d'); ?></div>
349 349
 		</div>
350 350
 	<?php
351 351
 		}
@@ -360,17 +360,17 @@  discard block
 block discarded – undo
360 360
 	 * @param int $EVT_ID
361 361
 	 * @return    string
362 362
 	 */
363
-	public static function get_primary_date_obj( $EVT_ID = 0 ) {
364
-		$event = EEH_Event_View::get_event( $EVT_ID );
365
-		if ( $event instanceof EE_Event ) {
363
+	public static function get_primary_date_obj($EVT_ID = 0) {
364
+		$event = EEH_Event_View::get_event($EVT_ID);
365
+		if ($event instanceof EE_Event) {
366 366
 			$datetimes = $event->get_many_related(
367 367
 				'Datetime',
368 368
 				array(
369 369
 					'limit' => 1,
370
-					'order_by' => array( 'DTT_order' => 'ASC' )
370
+					'order_by' => array('DTT_order' => 'ASC')
371 371
 				)
372 372
 			);
373
-			return reset( $datetimes );
373
+			return reset($datetimes);
374 374
 		} else {
375 375
 			 return FALSE;
376 376
 		}
@@ -385,17 +385,17 @@  discard block
 block discarded – undo
385 385
 	 * @param int $EVT_ID
386 386
 	 * @return    string
387 387
 	 */
388
-	public static function get_last_date_obj( $EVT_ID = 0 ) {
389
-		$event = EEH_Event_View::get_event( $EVT_ID );
390
-		if ( $event instanceof EE_Event ) {
388
+	public static function get_last_date_obj($EVT_ID = 0) {
389
+		$event = EEH_Event_View::get_event($EVT_ID);
390
+		if ($event instanceof EE_Event) {
391 391
 			$datetimes = $event->get_many_related(
392 392
 				'Datetime',
393 393
 				array(
394 394
 					'limit' => 1,
395
-					'order_by' => array( 'DTT_order' => 'DESC' )
395
+					'order_by' => array('DTT_order' => 'DESC')
396 396
 				)
397 397
 			);
398
-			return end( $datetimes );
398
+			return end($datetimes);
399 399
 		} else {
400 400
 			return FALSE;
401 401
 		}
@@ -410,17 +410,17 @@  discard block
 block discarded – undo
410 410
 	 * @param int $EVT_ID
411 411
 	 * @return    string
412 412
 	 */
413
-	public static function get_earliest_date_obj( $EVT_ID = 0 ) {
414
-		$event = EEH_Event_View::get_event( $EVT_ID );
415
-		if ( $event instanceof EE_Event ) {
413
+	public static function get_earliest_date_obj($EVT_ID = 0) {
414
+		$event = EEH_Event_View::get_event($EVT_ID);
415
+		if ($event instanceof EE_Event) {
416 416
 			$datetimes = $event->get_many_related(
417 417
 				'Datetime',
418 418
 				array(
419 419
 					'limit' => 1,
420
-					'order_by' => array( 'DTT_EVT_start' => 'ASC' )
420
+					'order_by' => array('DTT_EVT_start' => 'ASC')
421 421
 				)
422 422
 			);
423
-			return reset( $datetimes );
423
+			return reset($datetimes);
424 424
 		} else {
425 425
 			 return FALSE;
426 426
 		}
@@ -435,17 +435,17 @@  discard block
 block discarded – undo
435 435
 	 * @param int $EVT_ID
436 436
 	 * @return    string
437 437
 	 */
438
-	public static function get_latest_date_obj( $EVT_ID = 0 ) {
439
-		$event = EEH_Event_View::get_event( $EVT_ID );
440
-		if ( $event instanceof EE_Event ) {
438
+	public static function get_latest_date_obj($EVT_ID = 0) {
439
+		$event = EEH_Event_View::get_event($EVT_ID);
440
+		if ($event instanceof EE_Event) {
441 441
 			$datetimes = $event->get_many_related(
442 442
 				'Datetime',
443 443
 				array(
444 444
 					'limit' => 1,
445
-					'order_by' => array( 'DTT_EVT_start' => 'DESC' )
445
+					'order_by' => array('DTT_EVT_start' => 'DESC')
446 446
 				)
447 447
 			);
448
-			return end( $datetimes );
448
+			return end($datetimes);
449 449
 		} else {
450 450
 			return FALSE;
451 451
 		}
@@ -463,17 +463,17 @@  discard block
 block discarded – undo
463 463
 	 * @param null $limit
464 464
 	 * @return EE_Datetime[]
465 465
 	 */
466
-	public static function get_all_date_obj( $EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL ) {
467
-		$event = EEH_Event_View::get_event( $EVT_ID );
468
-		if($include_expired === null){
469
-			if($event instanceof EE_Event && $event->is_expired()){
466
+	public static function get_all_date_obj($EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL) {
467
+		$event = EEH_Event_View::get_event($EVT_ID);
468
+		if ($include_expired === null) {
469
+			if ($event instanceof EE_Event && $event->is_expired()) {
470 470
 				$include_expired = true;
471
-			}else{
471
+			} else {
472 472
 				$include_expired = false;
473 473
 			}
474 474
 		}
475 475
 
476
-		if ( $event instanceof EE_Event ) {
476
+		if ($event instanceof EE_Event) {
477 477
 			return $event->datetimes_ordered($include_expired, $include_deleted, $limit);
478 478
 		} else {
479 479
 			 return array();
@@ -489,11 +489,11 @@  discard block
 block discarded – undo
489 489
 	 * @param int $EVT_ID
490 490
 	 * @return    string
491 491
 	 */
492
-	public static function event_link_url( $EVT_ID = 0 ) {
493
-		$event = EEH_Event_View::get_event( $EVT_ID );
494
-		if ( $event instanceof EE_Event ) {
495
-			$url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink( $event->ID() );
496
-			return preg_match( "~^(?:f|ht)tps?://~i", $url ) ? $url : 'http://' . $url;
492
+	public static function event_link_url($EVT_ID = 0) {
493
+		$event = EEH_Event_View::get_event($EVT_ID);
494
+		if ($event instanceof EE_Event) {
495
+			$url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink($event->ID());
496
+			return preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'http://'.$url;
497 497
 		}
498 498
 		return NULL;
499 499
 	}
@@ -507,10 +507,10 @@  discard block
 block discarded – undo
507 507
 	 * @param int $EVT_ID
508 508
 	 * @return    string
509 509
 	 */
510
-	public static function event_phone( $EVT_ID = 0 ) {
511
-		$event = EEH_Event_View::get_event( $EVT_ID );
512
-		if ( $event instanceof EE_Event ) {
513
-			return EEH_Schema::telephone( $event->phone() );
510
+	public static function event_phone($EVT_ID = 0) {
511
+		$event = EEH_Event_View::get_event($EVT_ID);
512
+		if ($event instanceof EE_Event) {
513
+			return EEH_Schema::telephone($event->phone());
514 514
 		}
515 515
 		return NULL;
516 516
 	}
@@ -527,26 +527,26 @@  discard block
 block discarded – undo
527 527
 	 * @param string $after
528 528
 	 * @return    string
529 529
 	 */
530
-	public static function edit_event_link( $EVT_ID = 0, $link = '', $before = '', $after = '' ) {
531
-		$event = EEH_Event_View::get_event( $EVT_ID );
532
-		if ( $event instanceof EE_Event ) {
530
+	public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '') {
531
+		$event = EEH_Event_View::get_event($EVT_ID);
532
+		if ($event instanceof EE_Event) {
533 533
 			// can the user edit this post ?
534
-			if ( current_user_can( 'edit_post', $event->ID() )) {
534
+			if (current_user_can('edit_post', $event->ID())) {
535 535
 				// set link text
536
-				$link_text = ! empty( $link ) ? $link : __('edit this event');
536
+				$link_text = ! empty($link) ? $link : __('edit this event');
537 537
 				// generate nonce
538
-				$nonce = wp_create_nonce( 'edit_nonce' );
538
+				$nonce = wp_create_nonce('edit_nonce');
539 539
 				// generate url to event editor for this event
540
-				$url = add_query_arg( array( 'page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce ), admin_url() );
540
+				$url = add_query_arg(array('page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce), admin_url());
541 541
 				// get edit CPT text
542
-				$post_type_obj = get_post_type_object( 'espresso_events' );
542
+				$post_type_obj = get_post_type_object('espresso_events');
543 543
 				// build final link html
544
-				$link = '<a class="post-edit-link" href="' . $url . '" ';
545
-				$link .= ' title="' . esc_attr( $post_type_obj->labels->edit_item ) . '"';
544
+				$link = '<a class="post-edit-link" href="'.$url.'" ';
545
+				$link .= ' title="'.esc_attr($post_type_obj->labels->edit_item).'"';
546 546
 				$link .= \EED_Events_Archive::link_target();
547
-				$link .='>' . $link_text . '</a>';
547
+				$link .= '>'.$link_text.'</a>';
548 548
 				// put it all together
549
-				return $before . apply_filters( 'edit_post_link', $link, $event->ID() ) . $after;
549
+				return $before.apply_filters('edit_post_link', $link, $event->ID()).$after;
550 550
 			}
551 551
 		}
552 552
 		return '';
Please login to merge, or discard this patch.
public/template_tags.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -206,7 +206,7 @@
 block discarded – undo
206 206
 	function espresso_ticket_selector( $event = NULL ) {
207 207
 		if (  ! apply_filters( 'FHEE_disable_espresso_ticket_selector', FALSE ) ) {
208 208
 			espresso_load_ticket_selector();
209
-            \EED_Ticket_Selector::set_definitions();
209
+			\EED_Ticket_Selector::set_definitions();
210 210
 			echo EED_Ticket_Selector::display_ticket_selector( $event );
211 211
 		}
212 212
 	}
Please login to merge, or discard this patch.
Spacing   +276 added lines, -276 removed lines patch added patch discarded remove patch
@@ -14,12 +14,12 @@  discard block
 block discarded – undo
14 14
  * @param int | \EE_Event $event
15 15
  * @return bool
16 16
  */
17
-function is_espresso_event( $event = NULL ) {
18
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
17
+function is_espresso_event($event = NULL) {
18
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
19 19
 		// extract EE_Event object from passed param regardless of what it is (within reason of course)
20
-		$event = EEH_Event_View::get_event( $event );
20
+		$event = EEH_Event_View::get_event($event);
21 21
 		// do we have a valid event ?
22
-		return $event instanceof EE_Event  ? TRUE : FALSE;
22
+		return $event instanceof EE_Event ? TRUE : FALSE;
23 23
 	}
24 24
 	return FALSE;
25 25
 }
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
  * @return bool
32 32
  */
33 33
 function is_espresso_event_single() {
34
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
34
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
35 35
 		global $wp_query;
36 36
 		// return conditionals set by CPTs
37 37
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_single : FALSE;
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
  * @return bool
47 47
  */
48 48
 function is_espresso_event_archive() {
49
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
49
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
50 50
 		global $wp_query;
51 51
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_archive : FALSE;
52 52
 	}
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
  * @return bool
61 61
  */
62 62
 function is_espresso_event_taxonomy() {
63
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
63
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
64 64
 		global $wp_query;
65 65
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_taxonomy : FALSE;
66 66
 	}
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
  * @param int | \EE_Venue $venue
75 75
  * @return bool
76 76
  */
77
-function is_espresso_venue( $venue = NULL ) {
78
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
77
+function is_espresso_venue($venue = NULL) {
78
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
79 79
 		// extract EE_Venue object from passed param regardless of what it is (within reason of course)
80
-		$venue = EEH_Venue_View::get_venue( $venue, FALSE );
80
+		$venue = EEH_Venue_View::get_venue($venue, FALSE);
81 81
 		// do we have a valid event ?
82 82
 		return $venue instanceof EE_Venue ? TRUE : FALSE;
83 83
 	}
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
  * @return bool
92 92
  */
93 93
 function is_espresso_venue_single() {
94
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
94
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
95 95
 		global $wp_query;
96 96
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_single : FALSE;
97 97
 	}
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
  * @return bool
106 106
  */
107 107
 function is_espresso_venue_archive() {
108
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
108
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
109 109
 		global $wp_query;
110 110
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_archive : FALSE;
111 111
 	}
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
  * @return bool
120 120
  */
121 121
 function is_espresso_venue_taxonomy() {
122
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
122
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
123 123
 		global $wp_query;
124 124
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_taxonomy : FALSE;
125 125
 	}
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
  * @param $conditional_tag
134 134
  * @return bool
135 135
  */
136
-function can_use_espresso_conditionals( $conditional_tag ) {
137
-	if ( ! did_action( 'AHEE__EE_System__initialize' )) {
136
+function can_use_espresso_conditionals($conditional_tag) {
137
+	if ( ! did_action('AHEE__EE_System__initialize')) {
138 138
 		EE_Error::doing_it_wrong(
139 139
 			__FUNCTION__,
140 140
 			sprintf(
141
-				__( 'The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.','event_espresso'),
141
+				__('The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.', 'event_espresso'),
142 142
 				$conditional_tag
143 143
 			),
144 144
 			'4.4.0'
@@ -153,13 +153,13 @@  discard block
 block discarded – undo
153 153
 
154 154
 /*************************** Event Queries ***************************/
155 155
 
156
-if ( ! function_exists( 'espresso_get_events' )) {
156
+if ( ! function_exists('espresso_get_events')) {
157 157
 	/**
158 158
 	 * 	espresso_get_events
159 159
 	 * @param array $params
160 160
 	 * @return array
161 161
 	 */
162
-	function espresso_get_events( $params = array() ) {
162
+	function espresso_get_events($params = array()) {
163 163
 		//set default params
164 164
 		$default_espresso_events_params = array(
165 165
 			'limit' => 10,
@@ -170,18 +170,18 @@  discard block
 block discarded – undo
170 170
 			'sort' => 'ASC'
171 171
 		);
172 172
 		// allow the defaults to be filtered
173
-		$default_espresso_events_params = apply_filters( 'espresso_get_events__default_espresso_events_params', $default_espresso_events_params );
173
+		$default_espresso_events_params = apply_filters('espresso_get_events__default_espresso_events_params', $default_espresso_events_params);
174 174
 		// grab params and merge with defaults, then extract
175
-		$params = array_merge( $default_espresso_events_params, $params );
175
+		$params = array_merge($default_espresso_events_params, $params);
176 176
 		// run the query
177
-		$events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $params );
177
+		$events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery($params);
178 178
 		// assign results to a variable so we can return it
179 179
 		$events = $events_query->have_posts() ? $events_query->posts : array();
180 180
 		// but first reset the query and postdata
181 181
 		wp_reset_query();
182 182
 		wp_reset_postdata();
183 183
 		EED_Events_Archive::remove_all_events_archive_filters();
184
-		unset( $events_query );
184
+		unset($events_query);
185 185
 		return $events;
186 186
 	}
187 187
 }
@@ -195,33 +195,33 @@  discard block
 block discarded – undo
195 195
  * espresso_load_ticket_selector
196 196
  */
197 197
 function espresso_load_ticket_selector() {
198
-	EE_Registry::instance()->load_file( EE_MODULES . 'ticket_selector', 'EED_Ticket_Selector', 'module' );
198
+	EE_Registry::instance()->load_file(EE_MODULES.'ticket_selector', 'EED_Ticket_Selector', 'module');
199 199
 }
200 200
 
201
-if ( ! function_exists( 'espresso_ticket_selector' )) {
201
+if ( ! function_exists('espresso_ticket_selector')) {
202 202
 	/**
203 203
 	 * espresso_ticket_selector
204 204
 	 * @param null $event
205 205
 	 */
206
-	function espresso_ticket_selector( $event = NULL ) {
207
-		if (  ! apply_filters( 'FHEE_disable_espresso_ticket_selector', FALSE ) ) {
206
+	function espresso_ticket_selector($event = NULL) {
207
+		if ( ! apply_filters('FHEE_disable_espresso_ticket_selector', FALSE)) {
208 208
 			espresso_load_ticket_selector();
209 209
             \EED_Ticket_Selector::set_definitions();
210
-			echo EED_Ticket_Selector::display_ticket_selector( $event );
210
+			echo EED_Ticket_Selector::display_ticket_selector($event);
211 211
 		}
212 212
 	}
213 213
 }
214 214
 
215 215
 
216
-	if ( ! function_exists( 'espresso_view_details_btn' )) {
216
+	if ( ! function_exists('espresso_view_details_btn')) {
217 217
 	/**
218 218
 	 * espresso_view_details_btn
219 219
 	 * @param null $event
220 220
 	 */
221
-	function espresso_view_details_btn( $event = NULL ) {
222
-		if (  ! apply_filters( 'FHEE_disable_espresso_view_details_btn', FALSE ) ) {
221
+	function espresso_view_details_btn($event = NULL) {
222
+		if ( ! apply_filters('FHEE_disable_espresso_view_details_btn', FALSE)) {
223 223
 			espresso_load_ticket_selector();
224
-			echo EED_Ticket_Selector::display_ticket_selector( $event, TRUE );
224
+			echo EED_Ticket_Selector::display_ticket_selector($event, TRUE);
225 225
 		}
226 226
 	}
227 227
 }
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 
232 232
 /*************************** EEH_Event_View ***************************/
233 233
 
234
-if ( ! function_exists( 'espresso_load_event_list_assets' )) {
234
+if ( ! function_exists('espresso_load_event_list_assets')) {
235 235
 	/**
236 236
 	 * espresso_load_event_list_assets
237 237
 	 * ensures that event list styles and scripts are loaded
@@ -240,13 +240,13 @@  discard block
 block discarded – undo
240 240
 	 */
241 241
 	function espresso_load_event_list_assets() {
242 242
 		$event_list = EED_Events_Archive::instance();
243
-		add_action( 'AHEE__EE_System__initialize_last', array( $event_list, 'load_event_list_assets' ), 10 );
244
-		add_filter( 'FHEE_enable_default_espresso_css', '__return_true' );
243
+		add_action('AHEE__EE_System__initialize_last', array($event_list, 'load_event_list_assets'), 10);
244
+		add_filter('FHEE_enable_default_espresso_css', '__return_true');
245 245
 	}
246 246
 }
247 247
 
248 248
 
249
-if ( ! function_exists( 'espresso_event_reg_button' )) {
249
+if ( ! function_exists('espresso_event_reg_button')) {
250 250
 	/**
251 251
 	 * espresso_event_reg_button
252 252
 	 * returns the "Register Now" button if event is active,
@@ -258,9 +258,9 @@  discard block
 block discarded – undo
258 258
 	 * @param bool $EVT_ID
259 259
 	 * @return string
260 260
 	 */
261
-	function espresso_event_reg_button( $btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE ) {
262
-		$event_status = EEH_Event_View::event_active_status( $EVT_ID );
263
-		switch ( $event_status ) {
261
+	function espresso_event_reg_button($btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE) {
262
+		$event_status = EEH_Event_View::event_active_status($EVT_ID);
263
+		switch ($event_status) {
264 264
 			case EE_Datetime::sold_out :
265 265
 				$btn_text = __('Sold Out', 'event_espresso');
266 266
 				$class = 'ee-pink';
@@ -276,10 +276,10 @@  discard block
 block discarded – undo
276 276
 			case EE_Datetime::upcoming :
277 277
 			case EE_Datetime::active :
278 278
 			default :
279
-				$btn_text =! empty( $btn_text_if_active ) ? $btn_text_if_active : __( 'Register Now', 'event_espresso' );
279
+				$btn_text = ! empty($btn_text_if_active) ? $btn_text_if_active : __('Register Now', 'event_espresso');
280 280
 				$class = 'ee-green';
281 281
 		}
282
-		if ( $event_status < 1 && ! empty( $btn_text_if_inactive )) {
282
+		if ($event_status < 1 && ! empty($btn_text_if_inactive)) {
283 283
 			$btn_text = $btn_text_if_inactive;
284 284
 			$class = 'ee-grey';
285 285
 		}
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 
294 294
 
295 295
 
296
-if ( ! function_exists( 'espresso_display_ticket_selector' )) {
296
+if ( ! function_exists('espresso_display_ticket_selector')) {
297 297
 	/**
298 298
 	 * espresso_display_ticket_selector
299 299
 	 * whether or not to display the Ticket Selector for an event
@@ -301,14 +301,14 @@  discard block
 block discarded – undo
301 301
 	 * @param bool $EVT_ID
302 302
 	 * @return boolean
303 303
 	 */
304
-	function espresso_display_ticket_selector( $EVT_ID = FALSE ) {
305
-		return EEH_Event_View::display_ticket_selector( $EVT_ID );
304
+	function espresso_display_ticket_selector($EVT_ID = FALSE) {
305
+		return EEH_Event_View::display_ticket_selector($EVT_ID);
306 306
 	}
307 307
 }
308 308
 
309 309
 
310 310
 
311
-if ( ! function_exists( 'espresso_event_status_banner' )) {
311
+if ( ! function_exists('espresso_event_status_banner')) {
312 312
 	/**
313 313
 	 * espresso_event_status
314 314
 	 * returns a banner showing the event status if it is sold out, expired, or inactive
@@ -316,13 +316,13 @@  discard block
 block discarded – undo
316 316
 	 * @param bool $EVT_ID
317 317
 	 * @return string
318 318
 	 */
319
-	function espresso_event_status_banner( $EVT_ID = FALSE ) {
320
-		return EEH_Event_View::event_status( $EVT_ID );
319
+	function espresso_event_status_banner($EVT_ID = FALSE) {
320
+		return EEH_Event_View::event_status($EVT_ID);
321 321
 	}
322 322
 }
323 323
 
324 324
 
325
-if ( ! function_exists( 'espresso_event_status' )) {
325
+if ( ! function_exists('espresso_event_status')) {
326 326
 	/**
327 327
 	 * espresso_event_status
328 328
 	 * returns the event status if it is sold out, expired, or inactive
@@ -331,17 +331,17 @@  discard block
 block discarded – undo
331 331
 	 * @param bool $echo
332 332
 	 * @return string
333 333
 	 */
334
-	function espresso_event_status( $EVT_ID = 0, $echo = TRUE ) {
335
-		if ( $echo ) {
336
-			echo EEH_Event_View::event_active_status( $EVT_ID );
334
+	function espresso_event_status($EVT_ID = 0, $echo = TRUE) {
335
+		if ($echo) {
336
+			echo EEH_Event_View::event_active_status($EVT_ID);
337 337
 			return '';
338 338
 		}
339
-		return EEH_Event_View::event_active_status( $EVT_ID );
339
+		return EEH_Event_View::event_active_status($EVT_ID);
340 340
 	}
341 341
 }
342 342
 
343 343
 
344
-if ( ! function_exists( 'espresso_event_categories' )) {
344
+if ( ! function_exists('espresso_event_categories')) {
345 345
 	/**
346 346
 	 * espresso_event_categories
347 347
 	 * returns the terms associated with an event
@@ -351,17 +351,17 @@  discard block
 block discarded – undo
351 351
 	 * @param bool $echo
352 352
 	 * @return string
353 353
 	 */
354
-	function espresso_event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE ) {
355
-		if ( $echo ) {
356
-			echo EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized );
354
+	function espresso_event_categories($EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) {
355
+		if ($echo) {
356
+			echo EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized);
357 357
 			return '';
358 358
 		}
359
-		return EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized );
359
+		return EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized);
360 360
 	}
361 361
 }
362 362
 
363 363
 
364
-if ( ! function_exists( 'espresso_event_tickets_available' )) {
364
+if ( ! function_exists('espresso_event_tickets_available')) {
365 365
 	/**
366 366
 	 * espresso_event_tickets_available
367 367
 	 * returns the ticket types available for purchase for an event
@@ -371,26 +371,26 @@  discard block
 block discarded – undo
371 371
 	 * @param bool $format
372 372
 	 * @return string
373 373
 	 */
374
-	function espresso_event_tickets_available( $EVT_ID = 0, $echo = TRUE, $format = TRUE ) {
375
-		$tickets = EEH_Event_View::event_tickets_available( $EVT_ID );
376
-		if ( is_array( $tickets ) && ! empty( $tickets )) {
374
+	function espresso_event_tickets_available($EVT_ID = 0, $echo = TRUE, $format = TRUE) {
375
+		$tickets = EEH_Event_View::event_tickets_available($EVT_ID);
376
+		if (is_array($tickets) && ! empty($tickets)) {
377 377
 			// if formatting then $html will be a string, else it will be an array of ticket objects
378
-			$html = $format ? '<ul id="ee-event-tickets-ul-' . $EVT_ID . '" class="ee-event-tickets-ul">' : array();
379
-			foreach ( $tickets as $ticket ) {
380
-				if ( $ticket instanceof EE_Ticket ) {
381
-					if ( $format ) {
382
-						$html .= '<li id="ee-event-tickets-li-' . $ticket->ID() . '" class="ee-event-tickets-li">';
383
-						$html .= $ticket->name() . ' ' . EEH_Template::format_currency( $ticket->get_ticket_total_with_taxes() );
378
+			$html = $format ? '<ul id="ee-event-tickets-ul-'.$EVT_ID.'" class="ee-event-tickets-ul">' : array();
379
+			foreach ($tickets as $ticket) {
380
+				if ($ticket instanceof EE_Ticket) {
381
+					if ($format) {
382
+						$html .= '<li id="ee-event-tickets-li-'.$ticket->ID().'" class="ee-event-tickets-li">';
383
+						$html .= $ticket->name().' '.EEH_Template::format_currency($ticket->get_ticket_total_with_taxes());
384 384
 						$html .= '</li>';
385 385
 					} else {
386 386
 						$html[] = $ticket;
387 387
 					}
388 388
 				}
389 389
 			}
390
-			if ( $format ) {
390
+			if ($format) {
391 391
 				$html .= '</ul>';
392 392
 			}
393
-			if ( $echo && ! $format ) {
393
+			if ($echo && ! $format) {
394 394
 				echo $html;
395 395
 				return '';
396 396
 			}
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	}
401 401
 }
402 402
 
403
-if ( ! function_exists( 'espresso_event_date_obj' )) {
403
+if ( ! function_exists('espresso_event_date_obj')) {
404 404
 	/**
405 405
 	 * espresso_event_date_obj
406 406
 	 * returns the primary date object for an event
@@ -408,13 +408,13 @@  discard block
 block discarded – undo
408 408
 	 * @param bool $EVT_ID
409 409
 	 * @return object
410 410
 	 */
411
-	function espresso_event_date_obj( $EVT_ID = FALSE ) {
412
-		return EEH_Event_View::get_primary_date_obj( $EVT_ID );
411
+	function espresso_event_date_obj($EVT_ID = FALSE) {
412
+		return EEH_Event_View::get_primary_date_obj($EVT_ID);
413 413
 	}
414 414
 }
415 415
 
416 416
 
417
-if ( ! function_exists( 'espresso_event_date' )) {
417
+if ( ! function_exists('espresso_event_date')) {
418 418
 	/**
419 419
 	 * espresso_event_date
420 420
 	 * returns the primary date for an event
@@ -425,22 +425,22 @@  discard block
 block discarded – undo
425 425
 	 * @param bool $echo
426 426
 	 * @return string
427 427
 	 */
428
-	function espresso_event_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) {
429
-		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
430
-		$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
431
-		$date_format = apply_filters( 'FHEE__espresso_event_date__date_format', $date_format );
432
-		$time_format = apply_filters( 'FHEE__espresso_event_date__time_format', $time_format );
433
-		if($echo){
434
-			echo EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID );
428
+	function espresso_event_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) {
429
+		$date_format = ! empty($date_format) ? $date_format : get_option('date_format');
430
+		$time_format = ! empty($time_format) ? $time_format : get_option('time_format');
431
+		$date_format = apply_filters('FHEE__espresso_event_date__date_format', $date_format);
432
+		$time_format = apply_filters('FHEE__espresso_event_date__time_format', $time_format);
433
+		if ($echo) {
434
+			echo EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID);
435 435
 			return '';
436 436
 		}
437
-		return EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID );
437
+		return EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID);
438 438
 
439 439
 	}
440 440
 }
441 441
 
442 442
 
443
-if ( ! function_exists( 'espresso_list_of_event_dates' )) {
443
+if ( ! function_exists('espresso_list_of_event_dates')) {
444 444
 	/**
445 445
 	 * espresso_list_of_event_dates
446 446
 	 * returns a unordered list of dates for an event
@@ -455,40 +455,40 @@  discard block
 block discarded – undo
455 455
 	 * @param null   $limit
456 456
 	 * @return string
457 457
 	 */
458
-	function espresso_list_of_event_dates( $EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL ) {
459
-		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
460
-		$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
461
-		$date_format = apply_filters( 'FHEE__espresso_list_of_event_dates__date_format', $date_format );
462
-		$time_format = apply_filters( 'FHEE__espresso_list_of_event_dates__time_format', $time_format );
463
-		$datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, $show_expired, FALSE, $limit );
464
-		if ( ! $format ) {
465
-			return apply_filters( 'FHEE__espresso_list_of_event_dates__datetimes', $datetimes );
458
+	function espresso_list_of_event_dates($EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL) {
459
+		$date_format = ! empty($date_format) ? $date_format : get_option('date_format');
460
+		$time_format = ! empty($time_format) ? $time_format : get_option('time_format');
461
+		$date_format = apply_filters('FHEE__espresso_list_of_event_dates__date_format', $date_format);
462
+		$time_format = apply_filters('FHEE__espresso_list_of_event_dates__time_format', $time_format);
463
+		$datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, $show_expired, FALSE, $limit);
464
+		if ( ! $format) {
465
+			return apply_filters('FHEE__espresso_list_of_event_dates__datetimes', $datetimes);
466 466
 		}
467 467
 		//d( $datetimes );
468
-		if ( is_array( $datetimes ) && ! empty( $datetimes )) {
468
+		if (is_array($datetimes) && ! empty($datetimes)) {
469 469
 			global $post;
470
-			$html = $format ? '<ul id="ee-event-datetimes-ul-' . $post->ID . '" class="ee-event-datetimes-ul ee-clearfix">' : '';
471
-			foreach ( $datetimes as $datetime ) {
472
-				if ( $datetime instanceof EE_Datetime ) {
473
-					$html .= '<li id="ee-event-datetimes-li-' . $datetime->ID();
474
-					$html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-' . $datetime->get_active_status() . '">';
470
+			$html = $format ? '<ul id="ee-event-datetimes-ul-'.$post->ID.'" class="ee-event-datetimes-ul ee-clearfix">' : '';
471
+			foreach ($datetimes as $datetime) {
472
+				if ($datetime instanceof EE_Datetime) {
473
+					$html .= '<li id="ee-event-datetimes-li-'.$datetime->ID();
474
+					$html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-'.$datetime->get_active_status().'">';
475 475
 					$datetime_name = $datetime->name();
476
-					$html .= ! empty( $datetime_name ) ? '<strong>' . $datetime_name . '</strong>' : '';
477
-					$html .= ! empty( $datetime_name )  && $add_breaks ? '<br />' : '';
478
-					$html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">' . $datetime->date_range( $date_format ) . '</span><br/>';
479
-					$html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">' . $datetime->time_range( $time_format ) . '</span>';
476
+					$html .= ! empty($datetime_name) ? '<strong>'.$datetime_name.'</strong>' : '';
477
+					$html .= ! empty($datetime_name) && $add_breaks ? '<br />' : '';
478
+					$html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">'.$datetime->date_range($date_format).'</span><br/>';
479
+					$html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">'.$datetime->time_range($time_format).'</span>';
480 480
 					$datetime_description = $datetime->description();
481
-					$html .= ! empty( $datetime_description )  && $add_breaks ? '<br />' : '';
482
-					$html .= ! empty( $datetime_description ) ? ' - ' . $datetime_description : '';
483
-					$html = apply_filters( 'FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime );
481
+					$html .= ! empty($datetime_description) && $add_breaks ? '<br />' : '';
482
+					$html .= ! empty($datetime_description) ? ' - '.$datetime_description : '';
483
+					$html = apply_filters('FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime);
484 484
 					$html .= '</li>';
485 485
 				}
486 486
 			}
487 487
 			$html .= $format ? '</ul>' : '';
488 488
 		} else {
489
-			$html = $format ?  '<p><span class="dashicons dashicons-marker pink-text"></span>' . __( 'There are no upcoming dates for this event.', 'event_espresso' ) . '</p><br/>' : '';
489
+			$html = $format ? '<p><span class="dashicons dashicons-marker pink-text"></span>'.__('There are no upcoming dates for this event.', 'event_espresso').'</p><br/>' : '';
490 490
 		}
491
-		if ( $echo ) {
491
+		if ($echo) {
492 492
 			echo $html;
493 493
 			return '';
494 494
 		}
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 }
498 498
 
499 499
 
500
-if ( ! function_exists( 'espresso_event_end_date' )) {
500
+if ( ! function_exists('espresso_event_end_date')) {
501 501
 	/**
502 502
 	 * espresso_event_end_date
503 503
 	 * returns the last date for an event
@@ -508,20 +508,20 @@  discard block
 block discarded – undo
508 508
 	 * @param bool   $echo
509 509
 	 * @return string
510 510
 	 */
511
-	function espresso_event_end_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) {
512
-		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
513
-		$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
514
-		$date_format = apply_filters( 'FHEE__espresso_event_end_date__date_format', $date_format );
515
-		$time_format = apply_filters( 'FHEE__espresso_event_end_date__time_format', $time_format );
516
-		if($echo){
517
-			echo EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID );
511
+	function espresso_event_end_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) {
512
+		$date_format = ! empty($date_format) ? $date_format : get_option('date_format');
513
+		$time_format = ! empty($time_format) ? $time_format : get_option('time_format');
514
+		$date_format = apply_filters('FHEE__espresso_event_end_date__date_format', $date_format);
515
+		$time_format = apply_filters('FHEE__espresso_event_end_date__time_format', $time_format);
516
+		if ($echo) {
517
+			echo EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID);
518 518
 			return '';
519 519
 		}
520
-		return EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID );
520
+		return EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID);
521 521
 	}
522 522
 }
523 523
 
524
-if ( ! function_exists( 'espresso_event_date_range' )) {
524
+if ( ! function_exists('espresso_event_date_range')) {
525 525
 	/**
526 526
 	 * espresso_event_date_range
527 527
 	 * returns the first and last chronologically ordered dates for an event (if different)
@@ -534,31 +534,31 @@  discard block
 block discarded – undo
534 534
 	 * @param bool   $echo
535 535
 	 * @return string
536 536
 	 */
537
-	function espresso_event_date_range( $date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE ) {
537
+	function espresso_event_date_range($date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE) {
538 538
 		// set and filter date and time formats when a range is returned
539
-		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
540
-		$date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', $date_format );
539
+		$date_format = ! empty($date_format) ? $date_format : get_option('date_format');
540
+		$date_format = apply_filters('FHEE__espresso_event_date_range__date_format', $date_format);
541 541
 		// get the start and end date with NO time portion
542
-		$the_event_date = EEH_Event_View::the_earliest_event_date( $date_format, '', $EVT_ID );
543
-		$the_event_end_date = EEH_Event_View::the_latest_event_date( $date_format, '', $EVT_ID );
542
+		$the_event_date = EEH_Event_View::the_earliest_event_date($date_format, '', $EVT_ID);
543
+		$the_event_end_date = EEH_Event_View::the_latest_event_date($date_format, '', $EVT_ID);
544 544
 		// now we can determine if date range spans more than one day
545
-		if ( $the_event_date != $the_event_end_date ) {
546
-			$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
547
-			$time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', $time_format );
545
+		if ($the_event_date != $the_event_end_date) {
546
+			$time_format = ! empty($time_format) ? $time_format : get_option('time_format');
547
+			$time_format = apply_filters('FHEE__espresso_event_date_range__time_format', $time_format);
548 548
 			$html = sprintf(
549
-				__( '%1$s - %2$s', 'event_espresso' ),
550
-				EEH_Event_View::the_earliest_event_date( $date_format, $time_format, $EVT_ID ),
551
-				EEH_Event_View::the_latest_event_date( $date_format, $time_format, $EVT_ID )
549
+				__('%1$s - %2$s', 'event_espresso'),
550
+				EEH_Event_View::the_earliest_event_date($date_format, $time_format, $EVT_ID),
551
+				EEH_Event_View::the_latest_event_date($date_format, $time_format, $EVT_ID)
552 552
 			);
553 553
 		} else {
554 554
 			// set and filter date and time formats when only a single datetime is returned
555
-			$single_date_format = ! empty( $single_date_format ) ? $single_date_format : get_option( 'date_format' );
556
-			$single_time_format = ! empty( $single_time_format ) ? $single_time_format : get_option( 'time_format' );
557
-			$single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', $single_date_format );
558
-			$single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', $single_time_format );
559
-			$html = EEH_Event_View::the_earliest_event_date( $single_date_format, $single_time_format, $EVT_ID );
555
+			$single_date_format = ! empty($single_date_format) ? $single_date_format : get_option('date_format');
556
+			$single_time_format = ! empty($single_time_format) ? $single_time_format : get_option('time_format');
557
+			$single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', $single_date_format);
558
+			$single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', $single_time_format);
559
+			$html = EEH_Event_View::the_earliest_event_date($single_date_format, $single_time_format, $EVT_ID);
560 560
 		}
561
-		if ( $echo ) {
561
+		if ($echo) {
562 562
 			echo $html;
563 563
 			return '';
564 564
 		}
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
 }
568 568
 
569 569
 
570
-if ( ! function_exists( 'espresso_event_date_as_calendar_page' )) {
570
+if ( ! function_exists('espresso_event_date_as_calendar_page')) {
571 571
 	/**
572 572
 	 * espresso_event_date_as_calendar_page
573 573
 	 * returns the primary date for an event, stylized to appear as the page of a calendar
@@ -575,15 +575,15 @@  discard block
 block discarded – undo
575 575
 	 * @param bool $EVT_ID
576 576
 	 * @return string
577 577
 	 */
578
-	function espresso_event_date_as_calendar_page( $EVT_ID = FALSE ) {
579
-		EEH_Event_View::event_date_as_calendar_page( $EVT_ID );
578
+	function espresso_event_date_as_calendar_page($EVT_ID = FALSE) {
579
+		EEH_Event_View::event_date_as_calendar_page($EVT_ID);
580 580
 	}
581 581
 }
582 582
 
583 583
 
584 584
 
585 585
 
586
-if ( ! function_exists( 'espresso_event_link_url' )) {
586
+if ( ! function_exists('espresso_event_link_url')) {
587 587
 	/**
588 588
 	 * espresso_event_link_url
589 589
 	 *
@@ -591,18 +591,18 @@  discard block
 block discarded – undo
591 591
 	 * @param bool $echo
592 592
 	 * @return string
593 593
 	 */
594
-	function espresso_event_link_url( $EVT_ID = 0, $echo = TRUE ) {
595
-		if ( $echo ) {
596
-			echo EEH_Event_View::event_link_url( $EVT_ID );
594
+	function espresso_event_link_url($EVT_ID = 0, $echo = TRUE) {
595
+		if ($echo) {
596
+			echo EEH_Event_View::event_link_url($EVT_ID);
597 597
 			return '';
598 598
 		}
599
-		return EEH_Event_View::event_link_url( $EVT_ID );
599
+		return EEH_Event_View::event_link_url($EVT_ID);
600 600
 	}
601 601
 }
602 602
 
603 603
 
604 604
 
605
-if ( ! function_exists( 'espresso_event_has_content_or_excerpt' )) {
605
+if ( ! function_exists('espresso_event_has_content_or_excerpt')) {
606 606
 	/**
607 607
 	 *    espresso_event_has_content_or_excerpt
608 608
 	 *
@@ -610,15 +610,15 @@  discard block
 block discarded – undo
610 610
 	 * @param bool $EVT_ID
611 611
 	 * @return    boolean
612 612
 	 */
613
-	function espresso_event_has_content_or_excerpt( $EVT_ID = FALSE ) {
614
-		return EEH_Event_View::event_has_content_or_excerpt( $EVT_ID );
613
+	function espresso_event_has_content_or_excerpt($EVT_ID = FALSE) {
614
+		return EEH_Event_View::event_has_content_or_excerpt($EVT_ID);
615 615
 	}
616 616
 }
617 617
 
618 618
 
619 619
 
620 620
 
621
-if ( ! function_exists( 'espresso_event_content_or_excerpt' )) {
621
+if ( ! function_exists('espresso_event_content_or_excerpt')) {
622 622
 	/**
623 623
 	 * espresso_event_content_or_excerpt
624 624
 	 *
@@ -627,18 +627,18 @@  discard block
 block discarded – undo
627 627
 	 * @param bool $echo
628 628
 	 * @return string
629 629
 	 */
630
-	function espresso_event_content_or_excerpt( $num_words = 55, $more = NULL, $echo = TRUE ) {
631
-		if ( $echo ) {
632
-			echo EEH_Event_View::event_content_or_excerpt( $num_words, $more );
630
+	function espresso_event_content_or_excerpt($num_words = 55, $more = NULL, $echo = TRUE) {
631
+		if ($echo) {
632
+			echo EEH_Event_View::event_content_or_excerpt($num_words, $more);
633 633
 			return '';
634 634
 		}
635
-		return EEH_Event_View::event_content_or_excerpt( $num_words, $more );
635
+		return EEH_Event_View::event_content_or_excerpt($num_words, $more);
636 636
 	}
637 637
 }
638 638
 
639 639
 
640 640
 
641
-if ( ! function_exists( 'espresso_event_phone' )) {
641
+if ( ! function_exists('espresso_event_phone')) {
642 642
 	/**
643 643
 	 * espresso_event_phone
644 644
 	 *
@@ -646,18 +646,18 @@  discard block
 block discarded – undo
646 646
 	 * @param bool $echo
647 647
 	 * @return string
648 648
 	 */
649
-	function espresso_event_phone( $EVT_ID = 0, $echo = TRUE ) {
650
-		if ( $echo ) {
651
-			echo EEH_Event_View::event_phone( $EVT_ID );
649
+	function espresso_event_phone($EVT_ID = 0, $echo = TRUE) {
650
+		if ($echo) {
651
+			echo EEH_Event_View::event_phone($EVT_ID);
652 652
 			return '';
653 653
 		}
654
-		return EEH_Event_View::event_phone( $EVT_ID );
654
+		return EEH_Event_View::event_phone($EVT_ID);
655 655
 	}
656 656
 }
657 657
 
658 658
 
659 659
 
660
-if ( ! function_exists( 'espresso_edit_event_link' )) {
660
+if ( ! function_exists('espresso_edit_event_link')) {
661 661
 	/**
662 662
 	 * espresso_edit_event_link
663 663
 	 * returns a link to edit an event
@@ -666,39 +666,39 @@  discard block
 block discarded – undo
666 666
 	 * @param bool $echo
667 667
 	 * @return string
668 668
 	 */
669
-	function espresso_edit_event_link( $EVT_ID = 0, $echo = TRUE ) {
670
-		if ( $echo ) {
671
-			echo EEH_Event_View::edit_event_link( $EVT_ID );
669
+	function espresso_edit_event_link($EVT_ID = 0, $echo = TRUE) {
670
+		if ($echo) {
671
+			echo EEH_Event_View::edit_event_link($EVT_ID);
672 672
 			return '';
673 673
 		}
674
-		return EEH_Event_View::edit_event_link( $EVT_ID );
674
+		return EEH_Event_View::edit_event_link($EVT_ID);
675 675
 	}
676 676
 }
677 677
 
678 678
 
679
-if ( ! function_exists( 'espresso_organization_name' )) {
679
+if ( ! function_exists('espresso_organization_name')) {
680 680
 	/**
681 681
 	 * espresso_organization_name
682 682
 	 * @param bool $echo
683 683
 	 * @return string
684 684
 	 */
685 685
 	function espresso_organization_name($echo = TRUE) {
686
-		if($echo){
687
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'name' );
686
+		if ($echo) {
687
+			echo EE_Registry::instance()->CFG->organization->get_pretty('name');
688 688
 			return '';
689 689
 		}
690
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'name' );
690
+		return EE_Registry::instance()->CFG->organization->get_pretty('name');
691 691
 	}
692 692
 }
693 693
 
694
-if ( ! function_exists( 'espresso_organization_address' )) {
694
+if ( ! function_exists('espresso_organization_address')) {
695 695
 	/**
696 696
 	 * espresso_organization_address
697 697
 	 * @param string $type
698 698
 	 * @return string
699 699
 	 */
700
-	function espresso_organization_address( $type = 'inline' ) {
701
-		if ( EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config ) {
700
+	function espresso_organization_address($type = 'inline') {
701
+		if (EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config) {
702 702
 			$address = new EventEspresso\core\domain\entities\GenericAddress(
703 703
 				EE_Registry::instance()->CFG->organization->address_1,
704 704
 				EE_Registry::instance()->CFG->organization->address_2,
@@ -707,129 +707,129 @@  discard block
 block discarded – undo
707 707
 				EE_Registry::instance()->CFG->organization->zip,
708 708
 				EE_Registry::instance()->CFG->organization->CNT_ISO
709 709
 			);
710
-			return EEH_Address::format( $address, $type );
710
+			return EEH_Address::format($address, $type);
711 711
 		}
712 712
 		return '';
713 713
 	}
714 714
 }
715 715
 
716
-if ( ! function_exists( 'espresso_organization_email' )) {
716
+if ( ! function_exists('espresso_organization_email')) {
717 717
 	/**
718 718
 	 * espresso_organization_email
719 719
 	 * @param bool $echo
720 720
 	 * @return string
721 721
 	 */
722
-	function espresso_organization_email( $echo = TRUE ) {
723
-		if($echo){
724
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'email' );
722
+	function espresso_organization_email($echo = TRUE) {
723
+		if ($echo) {
724
+			echo EE_Registry::instance()->CFG->organization->get_pretty('email');
725 725
 			return '';
726 726
 		}
727
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'email' );
727
+		return EE_Registry::instance()->CFG->organization->get_pretty('email');
728 728
 	}
729 729
 }
730 730
 
731
-if ( ! function_exists( 'espresso_organization_logo_url' )) {
731
+if ( ! function_exists('espresso_organization_logo_url')) {
732 732
 	/**
733 733
 	 * espresso_organization_logo_url
734 734
 	 * @param bool $echo
735 735
 	 * @return string
736 736
 	 */
737
-	function espresso_organization_logo_url( $echo = TRUE ) {
738
-		if($echo){
739
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' );
737
+	function espresso_organization_logo_url($echo = TRUE) {
738
+		if ($echo) {
739
+			echo EE_Registry::instance()->CFG->organization->get_pretty('logo_url');
740 740
 			return '';
741 741
 		}
742
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' );
742
+		return EE_Registry::instance()->CFG->organization->get_pretty('logo_url');
743 743
 	}
744 744
 }
745 745
 
746
-if ( ! function_exists( 'espresso_organization_facebook' )) {
746
+if ( ! function_exists('espresso_organization_facebook')) {
747 747
 	/**
748 748
 	 * espresso_organization_facebook
749 749
 	 * @param bool $echo
750 750
 	 * @return string
751 751
 	 */
752
-	function espresso_organization_facebook( $echo = TRUE ) {
753
-		if($echo){
754
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' );
752
+	function espresso_organization_facebook($echo = TRUE) {
753
+		if ($echo) {
754
+			echo EE_Registry::instance()->CFG->organization->get_pretty('facebook');
755 755
 			return '';
756 756
 		}
757
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' );
757
+		return EE_Registry::instance()->CFG->organization->get_pretty('facebook');
758 758
 	}
759 759
 }
760 760
 
761
-if ( ! function_exists( 'espresso_organization_twitter' )) {
761
+if ( ! function_exists('espresso_organization_twitter')) {
762 762
 	/**
763 763
 	 * espresso_organization_twitter
764 764
 	 * @param bool $echo
765 765
 	 * @return string
766 766
 	 */
767
-	function espresso_organization_twitter( $echo = TRUE ) {
768
-		if($echo){
769
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' );
767
+	function espresso_organization_twitter($echo = TRUE) {
768
+		if ($echo) {
769
+			echo EE_Registry::instance()->CFG->organization->get_pretty('twitter');
770 770
 			return '';
771 771
 		}
772
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' );
772
+		return EE_Registry::instance()->CFG->organization->get_pretty('twitter');
773 773
 	}
774 774
 }
775 775
 
776
-if ( ! function_exists( 'espresso_organization_linkedin' )) {
776
+if ( ! function_exists('espresso_organization_linkedin')) {
777 777
 	/**
778 778
 	 * espresso_organization_linkedin
779 779
 	 * @param bool $echo
780 780
 	 * @return string
781 781
 	 */
782
-	function espresso_organization_linkedin( $echo = TRUE ) {
783
-		if($echo){
784
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' );
782
+	function espresso_organization_linkedin($echo = TRUE) {
783
+		if ($echo) {
784
+			echo EE_Registry::instance()->CFG->organization->get_pretty('linkedin');
785 785
 			return '';
786 786
 		}
787
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' );
787
+		return EE_Registry::instance()->CFG->organization->get_pretty('linkedin');
788 788
 	}
789 789
 }
790 790
 
791
-if ( ! function_exists( 'espresso_organization_pinterest' )) {
791
+if ( ! function_exists('espresso_organization_pinterest')) {
792 792
 	/**
793 793
 	 * espresso_organization_pinterest
794 794
 	 * @param bool $echo
795 795
 	 * @return string
796 796
 	 */
797
-	function espresso_organization_pinterest( $echo = TRUE ) {
798
-		if($echo){
799
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' );
797
+	function espresso_organization_pinterest($echo = TRUE) {
798
+		if ($echo) {
799
+			echo EE_Registry::instance()->CFG->organization->get_pretty('pinterest');
800 800
 			return '';
801 801
 		}
802
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' );
802
+		return EE_Registry::instance()->CFG->organization->get_pretty('pinterest');
803 803
 	}
804 804
 }
805 805
 
806
-if ( ! function_exists( 'espresso_organization_google' )) {
806
+if ( ! function_exists('espresso_organization_google')) {
807 807
 	/**
808 808
 	 * espresso_organization_google
809 809
 	 * @param bool $echo
810 810
 	 * @return string
811 811
 	 */
812
-	function espresso_organization_google( $echo = TRUE ) {
813
-		if($echo){
814
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'google' );
812
+	function espresso_organization_google($echo = TRUE) {
813
+		if ($echo) {
814
+			echo EE_Registry::instance()->CFG->organization->get_pretty('google');
815 815
 			return '';
816 816
 		}
817
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'google' );
817
+		return EE_Registry::instance()->CFG->organization->get_pretty('google');
818 818
 	}
819 819
 }
820 820
 
821
-if ( ! function_exists( 'espresso_organization_instagram' )) {
821
+if ( ! function_exists('espresso_organization_instagram')) {
822 822
 	/**
823 823
 	 * espresso_organization_instagram
824 824
 	 * @param bool $echo
825 825
 	 * @return string
826 826
 	 */
827
-	function espresso_organization_instagram( $echo = TRUE ) {
828
-		if($echo){
829
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' );
827
+	function espresso_organization_instagram($echo = TRUE) {
828
+		if ($echo) {
829
+			echo EE_Registry::instance()->CFG->organization->get_pretty('instagram');
830 830
 			return '';
831 831
 		}
832
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' );
832
+		return EE_Registry::instance()->CFG->organization->get_pretty('instagram');
833 833
 	}
834 834
 }
835 835
 
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
 
840 840
 
841 841
 
842
-if ( ! function_exists( 'espresso_event_venues' )) {
842
+if ( ! function_exists('espresso_event_venues')) {
843 843
 	/**
844 844
 	 * espresso_event_venues
845 845
 	 *
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
 
854 854
 
855 855
 
856
-if ( ! function_exists( 'espresso_venue_id' )) {
856
+if ( ! function_exists('espresso_venue_id')) {
857 857
 	/**
858 858
 	 *    espresso_venue_name
859 859
 	 *
@@ -861,15 +861,15 @@  discard block
 block discarded – undo
861 861
 	 * @param     int $EVT_ID
862 862
 	 * @return    string
863 863
 	 */
864
-	function espresso_venue_id( $EVT_ID = 0 ) {
865
-		$venue = EEH_Venue_View::get_venue( $EVT_ID );
864
+	function espresso_venue_id($EVT_ID = 0) {
865
+		$venue = EEH_Venue_View::get_venue($EVT_ID);
866 866
 		return $venue instanceof EE_Venue ? $venue->ID() : 0;
867 867
 	}
868 868
 }
869 869
 
870 870
 
871 871
 
872
-if ( ! function_exists( 'espresso_is_venue_private' ) ) {
872
+if ( ! function_exists('espresso_is_venue_private')) {
873 873
 	/**
874 874
 	 * Return whether a venue is private or not.
875 875
 	 * @see EEH_Venue_View::get_venue() for more info on expected return results.
@@ -878,45 +878,45 @@  discard block
 block discarded – undo
878 878
 	 *
879 879
 	 * @return bool | null
880 880
 	 */
881
-	function espresso_is_venue_private( $VNU_ID = 0 ) {
882
-		return EEH_Venue_View::is_venue_private( $VNU_ID );
881
+	function espresso_is_venue_private($VNU_ID = 0) {
882
+		return EEH_Venue_View::is_venue_private($VNU_ID);
883 883
 	}
884 884
 }
885 885
 
886 886
 
887 887
 
888
-if ( ! function_exists( 'espresso_venue_is_password_protected' ) ) {
888
+if ( ! function_exists('espresso_venue_is_password_protected')) {
889 889
 	/**
890 890
 	 * returns true or false if a venue is password protected or not
891 891
 	 *
892 892
 	 * @param int     $VNU_ID optional, the venue id to check.
893 893
 	 * @return string
894 894
 	 */
895
-	function espresso_venue_is_password_protected( $VNU_ID = 0 ) {
896
-		EE_Registry::instance()->load_helper( 'Venue_View' );
897
-		return EEH_Venue_View::is_venue_password_protected( $VNU_ID );
895
+	function espresso_venue_is_password_protected($VNU_ID = 0) {
896
+		EE_Registry::instance()->load_helper('Venue_View');
897
+		return EEH_Venue_View::is_venue_password_protected($VNU_ID);
898 898
 	}
899 899
 }
900 900
 
901 901
 
902 902
 
903
-if ( ! function_exists( 'espresso_password_protected_venue_form' ) ) {
903
+if ( ! function_exists('espresso_password_protected_venue_form')) {
904 904
 	/**
905 905
 	 * Returns a password form if venue is password protected.
906 906
 	 *
907 907
 	 * @param int     $VNU_ID optional, the venue id to check.
908 908
 	 * @return string
909 909
 	 */
910
-	function espresso_password_protected_venue_form( $VNU_ID = 0 ) {
911
-		EE_Registry::instance()->load_helper( 'Venue_View' );
912
-		return EEH_Venue_View::password_protected_venue_form( $VNU_ID );
910
+	function espresso_password_protected_venue_form($VNU_ID = 0) {
911
+		EE_Registry::instance()->load_helper('Venue_View');
912
+		return EEH_Venue_View::password_protected_venue_form($VNU_ID);
913 913
 	}
914 914
 }
915 915
 
916 916
 
917 917
 
918 918
 
919
-if ( ! function_exists( 'espresso_venue_name' )) {
919
+if ( ! function_exists('espresso_venue_name')) {
920 920
 	/**
921 921
 	 *    espresso_venue_name
922 922
 	 *
@@ -926,19 +926,19 @@  discard block
 block discarded – undo
926 926
 	 * @param bool   $echo
927 927
 	 * @return    string
928 928
 	 */
929
-	function espresso_venue_name( $VNU_ID = 0, $link_to = 'details', $echo = TRUE ) {
930
-		if($echo){
931
-			echo EEH_Venue_View::venue_name( $link_to, $VNU_ID );
929
+	function espresso_venue_name($VNU_ID = 0, $link_to = 'details', $echo = TRUE) {
930
+		if ($echo) {
931
+			echo EEH_Venue_View::venue_name($link_to, $VNU_ID);
932 932
 			return '';
933 933
 		}
934
-		return EEH_Venue_View::venue_name( $link_to, $VNU_ID );
934
+		return EEH_Venue_View::venue_name($link_to, $VNU_ID);
935 935
 	}
936 936
 }
937 937
 
938 938
 
939 939
 
940 940
 
941
-if ( ! function_exists( 'espresso_venue_link' )) {
941
+if ( ! function_exists('espresso_venue_link')) {
942 942
 	/**
943 943
 	 * 	espresso_venue_link
944 944
 	 *
@@ -947,14 +947,14 @@  discard block
 block discarded – undo
947 947
 	 *  @param 	string 	$text
948 948
 	 *  @return 	string
949 949
 	 */
950
-	function espresso_venue_link( $VNU_ID = 0, $text = '' ) {
951
-		return EEH_Venue_View::venue_details_link( $VNU_ID, $text );
950
+	function espresso_venue_link($VNU_ID = 0, $text = '') {
951
+		return EEH_Venue_View::venue_details_link($VNU_ID, $text);
952 952
 	}
953 953
 }
954 954
 
955 955
 
956 956
 
957
-if ( ! function_exists( 'espresso_venue_description' )) {
957
+if ( ! function_exists('espresso_venue_description')) {
958 958
 	/**
959 959
 	 *    espresso_venue_description
960 960
 	 *
@@ -963,17 +963,17 @@  discard block
 block discarded – undo
963 963
 	 * @param bool $echo
964 964
 	 * @return    string
965 965
 	 */
966
-	function espresso_venue_description( $VNU_ID = FALSE, $echo = TRUE ) {
967
-		if($echo){
968
-			echo EEH_Venue_View::venue_description( $VNU_ID );
966
+	function espresso_venue_description($VNU_ID = FALSE, $echo = TRUE) {
967
+		if ($echo) {
968
+			echo EEH_Venue_View::venue_description($VNU_ID);
969 969
 			return '';
970 970
 		}
971
-		return EEH_Venue_View::venue_description( $VNU_ID );
971
+		return EEH_Venue_View::venue_description($VNU_ID);
972 972
 	}
973 973
 }
974 974
 
975 975
 
976
-if ( ! function_exists( 'espresso_venue_excerpt' )) {
976
+if ( ! function_exists('espresso_venue_excerpt')) {
977 977
 	/**
978 978
 	 *    espresso_venue_excerpt
979 979
 	 *
@@ -982,18 +982,18 @@  discard block
 block discarded – undo
982 982
 	 * @param bool $echo
983 983
 	 * @return    string
984 984
 	 */
985
-	function espresso_venue_excerpt( $VNU_ID = 0,  $echo = TRUE ) {
986
-		if ( $echo ) {
987
-			echo EEH_Venue_View::venue_excerpt( $VNU_ID );
985
+	function espresso_venue_excerpt($VNU_ID = 0, $echo = TRUE) {
986
+		if ($echo) {
987
+			echo EEH_Venue_View::venue_excerpt($VNU_ID);
988 988
 			return '';
989 989
 		}
990
-		return EEH_Venue_View::venue_excerpt( $VNU_ID );
990
+		return EEH_Venue_View::venue_excerpt($VNU_ID);
991 991
 	}
992 992
 }
993 993
 
994 994
 
995 995
 
996
-if ( ! function_exists( 'espresso_venue_categories' )) {
996
+if ( ! function_exists('espresso_venue_categories')) {
997 997
 	/**
998 998
 	 * espresso_venue_categories
999 999
 	 * returns the terms associated with a venue
@@ -1003,17 +1003,17 @@  discard block
 block discarded – undo
1003 1003
 	 * @param bool $echo
1004 1004
 	 * @return string
1005 1005
 	 */
1006
-	function espresso_venue_categories( $VNU_ID = 0, $hide_uncategorized = TRUE,  $echo = TRUE ) {
1007
-		if ( $echo ) {
1008
-			echo EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized );
1006
+	function espresso_venue_categories($VNU_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) {
1007
+		if ($echo) {
1008
+			echo EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized);
1009 1009
 			return '';
1010 1010
 		}
1011
-		return EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized );
1011
+		return EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized);
1012 1012
 	}
1013 1013
 }
1014 1014
 
1015 1015
 
1016
-if ( ! function_exists( 'espresso_venue_address' )) {
1016
+if ( ! function_exists('espresso_venue_address')) {
1017 1017
 	/**
1018 1018
 	 * espresso_venue_address
1019 1019
 	 * returns a formatted block of html  for displaying a venue's address
@@ -1023,17 +1023,17 @@  discard block
 block discarded – undo
1023 1023
 	 * @param bool   $echo
1024 1024
 	 * @return string
1025 1025
 	 */
1026
-	function espresso_venue_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) {
1027
-		if ( $echo ) {
1028
-			echo EEH_Venue_View::venue_address( $type, $VNU_ID );
1026
+	function espresso_venue_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) {
1027
+		if ($echo) {
1028
+			echo EEH_Venue_View::venue_address($type, $VNU_ID);
1029 1029
 			return '';
1030 1030
 		}
1031
-		return EEH_Venue_View::venue_address( $type, $VNU_ID );
1031
+		return EEH_Venue_View::venue_address($type, $VNU_ID);
1032 1032
 	}
1033 1033
 }
1034 1034
 
1035 1035
 
1036
-if ( ! function_exists( 'espresso_venue_raw_address' )) {
1036
+if ( ! function_exists('espresso_venue_raw_address')) {
1037 1037
 	/**
1038 1038
 	 * espresso_venue_address
1039 1039
 	 * returns an UN-formatted string containing a venue's address
@@ -1043,17 +1043,17 @@  discard block
 block discarded – undo
1043 1043
 	 * @param bool     $echo
1044 1044
 	 * @return string
1045 1045
 	 */
1046
-	function espresso_venue_raw_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) {
1047
-		if ( $echo ) {
1048
-			echo EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE );
1046
+	function espresso_venue_raw_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) {
1047
+		if ($echo) {
1048
+			echo EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE);
1049 1049
 			return '';
1050 1050
 		}
1051
-		return EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE );
1051
+		return EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE);
1052 1052
 	}
1053 1053
 }
1054 1054
 
1055 1055
 
1056
-if ( ! function_exists( 'espresso_venue_has_address' )) {
1056
+if ( ! function_exists('espresso_venue_has_address')) {
1057 1057
 	/**
1058 1058
 	 * espresso_venue_has_address
1059 1059
 	 * returns TRUE or FALSE if a Venue has address information
@@ -1061,13 +1061,13 @@  discard block
 block discarded – undo
1061 1061
 	 * @param int $VNU_ID
1062 1062
 	 * @return bool
1063 1063
 	 */
1064
-	function espresso_venue_has_address( $VNU_ID = 0 ) {
1065
-		return EEH_Venue_View::venue_has_address( $VNU_ID );
1064
+	function espresso_venue_has_address($VNU_ID = 0) {
1065
+		return EEH_Venue_View::venue_has_address($VNU_ID);
1066 1066
 	}
1067 1067
 }
1068 1068
 
1069 1069
 
1070
-if ( ! function_exists( 'espresso_venue_gmap' )) {
1070
+if ( ! function_exists('espresso_venue_gmap')) {
1071 1071
 	/**
1072 1072
 	 * espresso_venue_gmap
1073 1073
 	 * returns a google map for the venue address
@@ -1078,17 +1078,17 @@  discard block
 block discarded – undo
1078 1078
 	 * @param bool     $echo
1079 1079
 	 * @return string
1080 1080
 	 */
1081
-	function espresso_venue_gmap( $VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE  ) {
1082
-		if ( $echo ) {
1083
-			echo EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap );
1081
+	function espresso_venue_gmap($VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE) {
1082
+		if ($echo) {
1083
+			echo EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap);
1084 1084
 			return '';
1085 1085
 		}
1086
-		return EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap );
1086
+		return EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap);
1087 1087
 	}
1088 1088
 }
1089 1089
 
1090 1090
 
1091
-if ( ! function_exists( 'espresso_venue_phone' )) {
1091
+if ( ! function_exists('espresso_venue_phone')) {
1092 1092
 	/**
1093 1093
 	 * espresso_venue_phone
1094 1094
 	 *
@@ -1096,18 +1096,18 @@  discard block
 block discarded – undo
1096 1096
 	 * @param bool $echo
1097 1097
 	 * @return string
1098 1098
 	 */
1099
-	function espresso_venue_phone( $VNU_ID = 0, $echo = TRUE ) {
1100
-		if ( $echo ) {
1101
-			echo EEH_Venue_View::venue_phone( $VNU_ID );
1099
+	function espresso_venue_phone($VNU_ID = 0, $echo = TRUE) {
1100
+		if ($echo) {
1101
+			echo EEH_Venue_View::venue_phone($VNU_ID);
1102 1102
 			return '';
1103 1103
 		}
1104
-		return EEH_Venue_View::venue_phone( $VNU_ID );
1104
+		return EEH_Venue_View::venue_phone($VNU_ID);
1105 1105
 	}
1106 1106
 }
1107 1107
 
1108 1108
 
1109 1109
 
1110
-if ( ! function_exists( 'espresso_venue_website' )) {
1110
+if ( ! function_exists('espresso_venue_website')) {
1111 1111
 	/**
1112 1112
 	 * espresso_venue_website
1113 1113
 	 *
@@ -1115,18 +1115,18 @@  discard block
 block discarded – undo
1115 1115
 	 * @param bool $echo
1116 1116
 	 * @return string
1117 1117
 	 */
1118
-	function espresso_venue_website( $VNU_ID = 0, $echo = TRUE ) {
1119
-		if ( $echo ) {
1120
-			echo EEH_Venue_View::venue_website_link( $VNU_ID );
1118
+	function espresso_venue_website($VNU_ID = 0, $echo = TRUE) {
1119
+		if ($echo) {
1120
+			echo EEH_Venue_View::venue_website_link($VNU_ID);
1121 1121
 			return '';
1122 1122
 		}
1123
-		return EEH_Venue_View::venue_website_link( $VNU_ID );
1123
+		return EEH_Venue_View::venue_website_link($VNU_ID);
1124 1124
 	}
1125 1125
 }
1126 1126
 
1127 1127
 
1128 1128
 
1129
-if ( ! function_exists( 'espresso_edit_venue_link' )) {
1129
+if ( ! function_exists('espresso_edit_venue_link')) {
1130 1130
 	/**
1131 1131
 	 * espresso_edit_venue_link
1132 1132
 	 *
@@ -1134,12 +1134,12 @@  discard block
 block discarded – undo
1134 1134
 	 * @param bool $echo
1135 1135
 	 * @return string
1136 1136
 	 */
1137
-	function espresso_edit_venue_link( $VNU_ID = 0, $echo = TRUE ) {
1138
-		if($echo){
1139
-			echo EEH_Venue_View::edit_venue_link( $VNU_ID );
1137
+	function espresso_edit_venue_link($VNU_ID = 0, $echo = TRUE) {
1138
+		if ($echo) {
1139
+			echo EEH_Venue_View::edit_venue_link($VNU_ID);
1140 1140
 			return '';
1141 1141
 		}
1142
-		return EEH_Venue_View::edit_venue_link( $VNU_ID );
1142
+		return EEH_Venue_View::edit_venue_link($VNU_ID);
1143 1143
 	}
1144 1144
 }
1145 1145
 
Please login to merge, or discard this patch.
modules/ticket_selector/EED_Ticket_Selector.module.php 2 patches
Indentation   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -22,15 +22,15 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class EED_Ticket_Selector extends  EED_Module {
24 24
 
25
-    /**
26
-     * @var EventEspresso\modules\ticket_selector\DisplayTicketSelector $ticket_selector
27
-     */
28
-    private static $ticket_selector;
25
+	/**
26
+	 * @var EventEspresso\modules\ticket_selector\DisplayTicketSelector $ticket_selector
27
+	 */
28
+	private static $ticket_selector;
29 29
 
30
-    /**
31
-     * @var EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton $iframe_embed_button
32
-     */
33
-    private static $iframe_embed_button;
30
+	/**
31
+	 * @var EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton $iframe_embed_button
32
+	 */
33
+	private static $iframe_embed_button;
34 34
 
35 35
 
36 36
 
@@ -61,13 +61,13 @@  discard block
 block discarded – undo
61 61
 		// routing
62 62
 		EE_Config::register_route( 'iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector' );
63 63
 		EE_Config::register_route( 'process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections' );
64
-        EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections');
65
-        add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 );
64
+		EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections');
65
+		add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 );
66 66
 		add_action( 'AHEE_event_details_header_bottom', array( 'EED_Ticket_Selector', 'display_ticket_selector' ), 10, 1 );
67
-        add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 );
68
-        add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 );
69
-        EED_Ticket_Selector::loadIframeAssets();
70
-    }
67
+		add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 );
68
+		add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 );
69
+		EED_Ticket_Selector::loadIframeAssets();
70
+	}
71 71
 
72 72
 
73 73
 
@@ -86,16 +86,16 @@  discard block
 block discarded – undo
86 86
 			10
87 87
 		);
88 88
 
89
-        /**
90
-         * Make sure assets for the ticket selector are loaded on the espresso registrations route so  admin side
91
-         * registrations work.
92
-         */
89
+		/**
90
+		 * Make sure assets for the ticket selector are loaded on the espresso registrations route so  admin side
91
+		 * registrations work.
92
+		 */
93 93
 		add_action(
94
-		    'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration',
95
-            array('EED_Ticket_Selector', 'set_definitions'),
96
-            10
97
-        );
98
-    }
94
+			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration',
95
+			array('EED_Ticket_Selector', 'set_definitions'),
96
+			10
97
+		);
98
+	}
99 99
 
100 100
 
101 101
 
@@ -106,34 +106,34 @@  discard block
 block discarded – undo
106 106
 	 *  @return 	void
107 107
 	 */
108 108
 	public static function set_definitions() {
109
-	    // don't do this twice
110
-	    if(defined('TICKET_SELECTOR_ASSETS_URL')) {
111
-	        return;
112
-        }
109
+		// don't do this twice
110
+		if(defined('TICKET_SELECTOR_ASSETS_URL')) {
111
+			return;
112
+		}
113 113
 		define( 'TICKET_SELECTOR_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
114 114
 		define(
115
-		    'TICKET_SELECTOR_TEMPLATES_PATH',
116
-            str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS
117
-        );
115
+			'TICKET_SELECTOR_TEMPLATES_PATH',
116
+			str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS
117
+		);
118 118
 		//if config is not set, initialize
119 119
 		if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) {
120
-            \EED_Ticket_Selector::instance()->set_config();
121
-            \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config();
120
+			\EED_Ticket_Selector::instance()->set_config();
121
+			\EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config();
122 122
 		}
123 123
 	}
124 124
 
125 125
 
126 126
 
127 127
 	/**
128
-     * @return \EventEspresso\modules\ticket_selector\DisplayTicketSelector
129
-     */
130
-    public static function ticketSelector()
131
-    {
132
-        if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
133
-            EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector();
134
-        }
135
-        return EED_Ticket_Selector::$ticket_selector;
136
-    }
128
+	 * @return \EventEspresso\modules\ticket_selector\DisplayTicketSelector
129
+	 */
130
+	public static function ticketSelector()
131
+	{
132
+		if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
133
+			EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector();
134
+		}
135
+		return EED_Ticket_Selector::$ticket_selector;
136
+	}
137 137
 
138 138
 
139 139
 	/**
@@ -186,15 +186,15 @@  discard block
 block discarded – undo
186 186
 
187 187
 
188 188
 
189
-    /**
190
-     *    creates buttons for selecting number of attendees for an event
191
-     *
192
-     * @access    public
193
-     * @param    WP_Post|int $event
194
-     * @param    bool        $view_details
195
-     * @return    string
196
-     * @throws \EE_Error
197
-     */
189
+	/**
190
+	 *    creates buttons for selecting number of attendees for an event
191
+	 *
192
+	 * @access    public
193
+	 * @param    WP_Post|int $event
194
+	 * @param    bool        $view_details
195
+	 * @return    string
196
+	 * @throws \EE_Error
197
+	 */
198 198
 	public static function display_ticket_selector( $event = NULL, $view_details = FALSE ) {
199 199
 		return EED_Ticket_Selector::ticketSelector()->display( $event, $view_details );
200 200
 	}
@@ -215,244 +215,244 @@  discard block
 block discarded – undo
215 215
 
216 216
 
217 217
 
218
-    /**
219
-     * cancel_ticket_selections
220
-     *
221
-     * @access        public
222
-     * @return        string
223
-     */
224
-    public static function cancel_ticket_selections()
225
-    {
226
-        $form = new ProcessTicketSelector();
227
-        return $form->cancelTicketSelections();
228
-    }
218
+	/**
219
+	 * cancel_ticket_selections
220
+	 *
221
+	 * @access        public
222
+	 * @return        string
223
+	 */
224
+	public static function cancel_ticket_selections()
225
+	{
226
+		$form = new ProcessTicketSelector();
227
+		return $form->cancelTicketSelections();
228
+	}
229 229
 
230 230
 
231 231
 
232 232
 	/**
233
-	* @return void
234
-	*/
233
+	 * @return void
234
+	 */
235 235
 	public static function translate_js_strings() {
236
-        EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__(
237
-            'please select a datetime', 'event_espresso'
238
-        );
239
-    }
236
+		EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__(
237
+			'please select a datetime', 'event_espresso'
238
+		);
239
+	}
240 240
 
241 241
 
242 242
 
243 243
 	/**
244
-	* 	load js
245
-	*
246
-	* 	@access 		public
247
-	* 	@return 		void
248
-	*/
244
+	 * 	load js
245
+	 *
246
+	 * 	@access 		public
247
+	 * 	@return 		void
248
+	 */
249 249
 	public static function load_tckt_slctr_assets() {
250 250
 		if ( apply_filters( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE ) ) {
251
-            // add some style
252
-            wp_register_style(
253
-                'ticket_selector',
254
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css',
255
-                array(),
256
-                EVENT_ESPRESSO_VERSION
257
-            );
258
-            wp_enqueue_style('ticket_selector');
259
-            // make it dance
260
-            wp_register_script(
261
-                'ticket_selector',
262
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js',
263
-                array('espresso_core'),
264
-                EVENT_ESPRESSO_VERSION,
265
-                TRUE
266
-            );
251
+			// add some style
252
+			wp_register_style(
253
+				'ticket_selector',
254
+				TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css',
255
+				array(),
256
+				EVENT_ESPRESSO_VERSION
257
+			);
258
+			wp_enqueue_style('ticket_selector');
259
+			// make it dance
260
+			wp_register_script(
261
+				'ticket_selector',
262
+				TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js',
263
+				array('espresso_core'),
264
+				EVENT_ESPRESSO_VERSION,
265
+				TRUE
266
+			);
267 267
 			wp_enqueue_script('ticket_selector');
268
-            require_once( EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php');
269
-            \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
270
-        }
268
+			require_once( EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php');
269
+			\EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
270
+		}
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * @return void
277
+	 */
278
+	public static function loadIframeAssets()
279
+	{
280
+		// for event lists
281
+		add_filter(
282
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
283
+			array('EED_Ticket_Selector', 'iframeCss')
284
+		);
285
+		add_filter(
286
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
287
+			array('EED_Ticket_Selector', 'iframeJs')
288
+		);
289
+		// for ticket selectors
290
+		add_filter(
291
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
292
+			array('EED_Ticket_Selector', 'iframeCss')
293
+		);
294
+		add_filter(
295
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
296
+			array('EED_Ticket_Selector', 'iframeJs')
297
+		);
298
+	}
299
+
300
+
301
+
302
+	/**
303
+	 * Informs the rest of the forms system what CSS and JS is needed to display the input
304
+	 *
305
+	 * @param array $iframe_css
306
+	 * @return array
307
+	 */
308
+	public static function iframeCss(array $iframe_css)
309
+	{
310
+		$iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css';
311
+		return $iframe_css;
271 312
 	}
272 313
 
273 314
 
274 315
 
275
-    /**
276
-     * @return void
277
-     */
278
-    public static function loadIframeAssets()
279
-    {
280
-        // for event lists
281
-        add_filter(
282
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
283
-            array('EED_Ticket_Selector', 'iframeCss')
284
-        );
285
-        add_filter(
286
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
287
-            array('EED_Ticket_Selector', 'iframeJs')
288
-        );
289
-        // for ticket selectors
290
-        add_filter(
291
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
292
-            array('EED_Ticket_Selector', 'iframeCss')
293
-        );
294
-        add_filter(
295
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
296
-            array('EED_Ticket_Selector', 'iframeJs')
297
-        );
298
-    }
299
-
300
-
301
-
302
-    /**
303
-     * Informs the rest of the forms system what CSS and JS is needed to display the input
304
-     *
305
-     * @param array $iframe_css
306
-     * @return array
307
-     */
308
-    public static function iframeCss(array $iframe_css)
309
-    {
310
-        $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css';
311
-        return $iframe_css;
312
-    }
313
-
314
-
315
-
316
-    /**
317
-     * Informs the rest of the forms system what CSS and JS is needed to display the input
318
-     *
319
-     * @param array $iframe_js
320
-     * @return array
321
-     */
322
-    public static function iframeJs(array $iframe_js)
323
-    {
324
-        $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js';
325
-        return $iframe_js;
326
-    }
316
+	/**
317
+	 * Informs the rest of the forms system what CSS and JS is needed to display the input
318
+	 *
319
+	 * @param array $iframe_js
320
+	 * @return array
321
+	 */
322
+	public static function iframeJs(array $iframe_js)
323
+	{
324
+		$iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js';
325
+		return $iframe_js;
326
+	}
327 327
 
328 328
 
329 329
 	/****************************** DEPRECATED ******************************/
330 330
 
331 331
 
332 332
 
333
-    /**
334
-     * @deprecated
335
-     * @return string
336
-     * @throws \EE_Error
337
-     */
338
-    public static function display_view_details_btn()
339
-    {
340
-        // todo add doing_it_wrong() notice during next major version
341
-        return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton();
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * @deprecated
348
-     * @return string
349
-     * @throws \EE_Error
350
-     */
351
-    public static function display_ticket_selector_submit()
352
-    {
353
-        // todo add doing_it_wrong() notice during next major version
354
-        return EED_Ticket_Selector::ticketSelector()->displaySubmitButton();
355
-    }
356
-
357
-
358
-
359
-    /**
360
-     * @deprecated
361
-     * @param string $permalink_string
362
-     * @param int    $id
363
-     * @param string $new_title
364
-     * @param string $new_slug
365
-     * @return string
366
-     */
367
-    public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '')
368
-    {
369
-        // todo add doing_it_wrong() notice during next major version
370
-        if (
371
-        	\EE_Registry::instance()->REQ->get('page') === 'espresso_events'
372
-        	&& \EE_Registry::instance()->REQ->get('action') === 'edit'
373
-        ) {
374
-            $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
375
-            $iframe_embed_button->addEventEditorIframeEmbedButton();
376
-        }
377
-        return '';
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * @deprecated
384
-     * @param int    $ID
385
-     * @param string $external_url
386
-     * @return string
387
-     */
388
-    public static function ticket_selector_form_open($ID = 0, $external_url = '')
389
-    {
390
-        // todo add doing_it_wrong() notice during next major version
391
-        return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url);
392
-    }
393
-
394
-
395
-
396
-    /**
397
-     * @deprecated
398
-     * @return string
399
-     */
400
-    public static function ticket_selector_form_close()
401
-    {
402
-        // todo add doing_it_wrong() notice during next major version
403
-        return EED_Ticket_Selector::ticketSelector()->formClose();
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * @deprecated
410
-     * @return string
411
-     */
412
-    public static function no_tkt_slctr_end_dv()
413
-    {
414
-        // todo add doing_it_wrong() notice during next major version
415
-        return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv();
416
-    }
417
-
418
-
419
-
420
-    /**
421
-     * @deprecated 4.9.13
422
-     * @return string
423
-     */
424
-    public static function tkt_slctr_end_dv()
425
-    {
426
-        return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
427
-    }
428
-
429
-
430
-
431
-    /**
432
-     * @deprecated
433
-     * @return string
434
-     */
435
-    public static function clear_tkt_slctr()
436
-    {
437
-        return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
438
-    }
439
-
440
-
441
-
442
-    /**
443
-     * @deprecated
444
-     */
445
-    public static function load_tckt_slctr_assets_admin()
446
-    {
447
-        // todo add doing_it_wrong() notice during next major version
448
-	    if (
449
-		    \EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events'
450
-		    && \EE_Registry::instance()->REQ->get( 'action' ) === 'edit'
451
-	    ) {
452
-		    $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
453
-            $iframe_embed_button->embedButtonAssets();
454
-        }
455
-    }
333
+	/**
334
+	 * @deprecated
335
+	 * @return string
336
+	 * @throws \EE_Error
337
+	 */
338
+	public static function display_view_details_btn()
339
+	{
340
+		// todo add doing_it_wrong() notice during next major version
341
+		return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton();
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * @deprecated
348
+	 * @return string
349
+	 * @throws \EE_Error
350
+	 */
351
+	public static function display_ticket_selector_submit()
352
+	{
353
+		// todo add doing_it_wrong() notice during next major version
354
+		return EED_Ticket_Selector::ticketSelector()->displaySubmitButton();
355
+	}
356
+
357
+
358
+
359
+	/**
360
+	 * @deprecated
361
+	 * @param string $permalink_string
362
+	 * @param int    $id
363
+	 * @param string $new_title
364
+	 * @param string $new_slug
365
+	 * @return string
366
+	 */
367
+	public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '')
368
+	{
369
+		// todo add doing_it_wrong() notice during next major version
370
+		if (
371
+			\EE_Registry::instance()->REQ->get('page') === 'espresso_events'
372
+			&& \EE_Registry::instance()->REQ->get('action') === 'edit'
373
+		) {
374
+			$iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
375
+			$iframe_embed_button->addEventEditorIframeEmbedButton();
376
+		}
377
+		return '';
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * @deprecated
384
+	 * @param int    $ID
385
+	 * @param string $external_url
386
+	 * @return string
387
+	 */
388
+	public static function ticket_selector_form_open($ID = 0, $external_url = '')
389
+	{
390
+		// todo add doing_it_wrong() notice during next major version
391
+		return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url);
392
+	}
393
+
394
+
395
+
396
+	/**
397
+	 * @deprecated
398
+	 * @return string
399
+	 */
400
+	public static function ticket_selector_form_close()
401
+	{
402
+		// todo add doing_it_wrong() notice during next major version
403
+		return EED_Ticket_Selector::ticketSelector()->formClose();
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * @deprecated
410
+	 * @return string
411
+	 */
412
+	public static function no_tkt_slctr_end_dv()
413
+	{
414
+		// todo add doing_it_wrong() notice during next major version
415
+		return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv();
416
+	}
417
+
418
+
419
+
420
+	/**
421
+	 * @deprecated 4.9.13
422
+	 * @return string
423
+	 */
424
+	public static function tkt_slctr_end_dv()
425
+	{
426
+		return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
427
+	}
428
+
429
+
430
+
431
+	/**
432
+	 * @deprecated
433
+	 * @return string
434
+	 */
435
+	public static function clear_tkt_slctr()
436
+	{
437
+		return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
438
+	}
439
+
440
+
441
+
442
+	/**
443
+	 * @deprecated
444
+	 */
445
+	public static function load_tckt_slctr_assets_admin()
446
+	{
447
+		// todo add doing_it_wrong() notice during next major version
448
+		if (
449
+			\EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events'
450
+			&& \EE_Registry::instance()->REQ->get( 'action' ) === 'edit'
451
+		) {
452
+			$iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
453
+			$iframe_embed_button->embedButtonAssets();
454
+		}
455
+	}
456 456
 
457 457
 
458 458
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\modules\ticket_selector\TicketSelectorIframe;
4 4
 use EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton;
5 5
 
6
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
7
-	exit( 'No direct script access allowed' );
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
 	 * @return EED_Ticket_Selector
39 39
 	 */
40 40
 	public static function instance() {
41
-		return parent::get_instance( __CLASS__ );
41
+		return parent::get_instance(__CLASS__);
42 42
 	}
43 43
 
44 44
 
45 45
 
46
-	protected function set_config(){
47
-		$this->set_config_section( 'template_settings' );
48
-		$this->set_config_class( 'EE_Ticket_Selector_Config' );
49
-		$this->set_config_name( 'EED_Ticket_Selector' );
46
+	protected function set_config() {
47
+		$this->set_config_section('template_settings');
48
+		$this->set_config_class('EE_Ticket_Selector_Config');
49
+		$this->set_config_name('EED_Ticket_Selector');
50 50
 	}
51 51
 
52 52
 
@@ -59,13 +59,13 @@  discard block
 block discarded – undo
59 59
 	 */
60 60
 	public static function set_hooks() {
61 61
 		// routing
62
-		EE_Config::register_route( 'iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector' );
63
-		EE_Config::register_route( 'process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections' );
62
+		EE_Config::register_route('iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector');
63
+		EE_Config::register_route('process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections');
64 64
         EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections');
65
-        add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 );
66
-		add_action( 'AHEE_event_details_header_bottom', array( 'EED_Ticket_Selector', 'display_ticket_selector' ), 10, 1 );
67
-        add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 );
68
-        add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 );
65
+        add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2);
66
+		add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1);
67
+        add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'translate_js_strings'), 0);
68
+        add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10);
69 69
         EED_Ticket_Selector::loadIframeAssets();
70 70
     }
71 71
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 		// to load assets for "espresso_events" page on the "edit" route (action)
83 83
 		add_action(
84 84
 			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit',
85
-			array( 'EED_Ticket_Selector', 'ticket_selector_iframe_embed_button' ),
85
+			array('EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'),
86 86
 			10
87 87
 		);
88 88
 
@@ -107,16 +107,16 @@  discard block
 block discarded – undo
107 107
 	 */
108 108
 	public static function set_definitions() {
109 109
 	    // don't do this twice
110
-	    if(defined('TICKET_SELECTOR_ASSETS_URL')) {
110
+	    if (defined('TICKET_SELECTOR_ASSETS_URL')) {
111 111
 	        return;
112 112
         }
113
-		define( 'TICKET_SELECTOR_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
113
+		define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
114 114
 		define(
115 115
 		    'TICKET_SELECTOR_TEMPLATES_PATH',
116
-            str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS
116
+            str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS
117 117
         );
118 118
 		//if config is not set, initialize
119
-		if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) {
119
+		if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) {
120 120
             \EED_Ticket_Selector::instance()->set_config();
121 121
             \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config();
122 122
 		}
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	 * 	@param	WP $WP
144 144
 	 * 	@return void
145 145
 	 */
146
-	public function run( $WP ) {}
146
+	public function run($WP) {}
147 147
 
148 148
 
149 149
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 * @return \EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton
152 152
 	 */
153 153
 	public static function getIframeEmbedButton() {
154
-		if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton ) {
154
+		if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) {
155 155
 			self::$iframe_embed_button = new TicketSelectorIframeEmbedButton();
156 156
 		}
157 157
 		return self::$iframe_embed_button;
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
      * @return    string
196 196
      * @throws \EE_Error
197 197
      */
198
-	public static function display_ticket_selector( $event = NULL, $view_details = FALSE ) {
199
-		return EED_Ticket_Selector::ticketSelector()->display( $event, $view_details );
198
+	public static function display_ticket_selector($event = NULL, $view_details = FALSE) {
199
+		return EED_Ticket_Selector::ticketSelector()->display($event, $view_details);
200 200
 	}
201 201
 
202 202
 
@@ -247,11 +247,11 @@  discard block
 block discarded – undo
247 247
 	* 	@return 		void
248 248
 	*/
249 249
 	public static function load_tckt_slctr_assets() {
250
-		if ( apply_filters( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE ) ) {
250
+		if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE)) {
251 251
             // add some style
252 252
             wp_register_style(
253 253
                 'ticket_selector',
254
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css',
254
+                TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css',
255 255
                 array(),
256 256
                 EVENT_ESPRESSO_VERSION
257 257
             );
@@ -259,13 +259,13 @@  discard block
 block discarded – undo
259 259
             // make it dance
260 260
             wp_register_script(
261 261
                 'ticket_selector',
262
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js',
262
+                TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js',
263 263
                 array('espresso_core'),
264 264
                 EVENT_ESPRESSO_VERSION,
265 265
                 TRUE
266 266
             );
267 267
 			wp_enqueue_script('ticket_selector');
268
-            require_once( EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php');
268
+            require_once(EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php');
269 269
             \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
270 270
         }
271 271
 	}
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
      */
308 308
     public static function iframeCss(array $iframe_css)
309 309
     {
310
-        $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css';
310
+        $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css';
311 311
         return $iframe_css;
312 312
     }
313 313
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
      */
322 322
     public static function iframeJs(array $iframe_js)
323 323
     {
324
-        $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js';
324
+        $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js';
325 325
         return $iframe_js;
326 326
     }
327 327
 
@@ -446,8 +446,8 @@  discard block
 block discarded – undo
446 446
     {
447 447
         // todo add doing_it_wrong() notice during next major version
448 448
 	    if (
449
-		    \EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events'
450
-		    && \EE_Registry::instance()->REQ->get( 'action' ) === 'edit'
449
+		    \EE_Registry::instance()->REQ->get('page') === 'espresso_events'
450
+		    && \EE_Registry::instance()->REQ->get('action') === 'edit'
451 451
 	    ) {
452 452
 		    $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton();
453 453
             $iframe_embed_button->embedButtonAssets();
Please login to merge, or discard this patch.
admin/extend/registration_form/Extend_Registration_Form_Admin_Page.core.php 1 patch
Indentation   +1088 added lines, -1088 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -25,1093 +25,1093 @@  discard block
 block discarded – undo
25 25
 {
26 26
 
27 27
 
28
-    /**
29
-     * @Constructor
30
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
31
-     * @access public
32
-     */
33
-    public function __construct($routing = true)
34
-    {
35
-        define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS);
36
-        define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS);
37
-        define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/');
38
-        define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS);
39
-        define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/');
40
-        parent::__construct($routing);
41
-    }
42
-
43
-
44
-    protected function _extend_page_config()
45
-    {
46
-        $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN;
47
-        $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0;
48
-        $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) ? $this->_req_data['QSG_ID'] : 0;
49
-
50
-        $new_page_routes    = array(
51
-            'question_groups'    => array(
52
-                'func'       => '_question_groups_overview_list_table',
53
-                'capability' => 'ee_read_question_groups',
54
-            ),
55
-            'add_question'       => array(
56
-                'func'       => '_edit_question',
57
-                'capability' => 'ee_edit_questions',
58
-            ),
59
-            'insert_question'    => array(
60
-                'func'       => '_insert_or_update_question',
61
-                'args'       => array('new_question' => true),
62
-                'capability' => 'ee_edit_questions',
63
-                'noheader'   => true,
64
-            ),
65
-            'duplicate_question' => array(
66
-                'func'       => '_duplicate_question',
67
-                'capability' => 'ee_edit_questions',
68
-                'noheader'   => true,
69
-            ),
70
-            'trash_question'     => array(
71
-                'func'       => '_trash_question',
72
-                'capability' => 'ee_delete_question',
73
-                'obj_id'     => $qst_id,
74
-                'noheader'   => true,
75
-            ),
76
-
77
-            'restore_question' => array(
78
-                'func'       => '_trash_or_restore_questions',
79
-                'capability' => 'ee_delete_question',
80
-                'obj_id'     => $qst_id,
81
-                'args'       => array('trash' => false),
82
-                'noheader'   => true,
83
-            ),
84
-
85
-            'delete_question' => array(
86
-                'func'       => '_delete_question',
87
-                'capability' => 'ee_delete_question',
88
-                'obj_id'     => $qst_id,
89
-                'noheader'   => true,
90
-            ),
91
-
92
-            'trash_questions' => array(
93
-                'func'       => '_trash_or_restore_questions',
94
-                'capability' => 'ee_delete_questions',
95
-                'args'       => array('trash' => true),
96
-                'noheader'   => true,
97
-            ),
98
-
99
-            'restore_questions' => array(
100
-                'func'       => '_trash_or_restore_questions',
101
-                'capability' => 'ee_delete_questions',
102
-                'args'       => array('trash' => false),
103
-                'noheader'   => true,
104
-            ),
105
-
106
-            'delete_questions' => array(
107
-                'func'       => '_delete_questions',
108
-                'args'       => array(),
109
-                'capability' => 'ee_delete_questions',
110
-                'noheader'   => true,
111
-            ),
112
-
113
-            'add_question_group' => array(
114
-                'func'       => '_edit_question_group',
115
-                'capability' => 'ee_edit_question_groups',
116
-            ),
117
-
118
-            'edit_question_group' => array(
119
-                'func'       => '_edit_question_group',
120
-                'capability' => 'ee_edit_question_group',
121
-                'obj_id'     => $qsg_id,
122
-                'args'       => array('edit'),
123
-            ),
124
-
125
-            'delete_question_groups' => array(
126
-                'func'       => '_delete_question_groups',
127
-                'capability' => 'ee_delete_question_groups',
128
-                'noheader'   => true,
129
-            ),
130
-
131
-            'delete_question_group' => array(
132
-                'func'       => '_delete_question_groups',
133
-                'capability' => 'ee_delete_question_group',
134
-                'obj_id'     => $qsg_id,
135
-                'noheader'   => true,
136
-            ),
137
-
138
-            'trash_question_group' => array(
139
-                'func'       => '_trash_or_restore_question_groups',
140
-                'args'       => array('trash' => true),
141
-                'capability' => 'ee_delete_question_group',
142
-                'obj_id'     => $qsg_id,
143
-                'noheader'   => true,
144
-            ),
145
-
146
-            'restore_question_group' => array(
147
-                'func'       => '_trash_or_restore_question_groups',
148
-                'args'       => array('trash' => false),
149
-                'capability' => 'ee_delete_question_group',
150
-                'obj_id'     => $qsg_id,
151
-                'noheader'   => true,
152
-            ),
153
-
154
-            'insert_question_group' => array(
155
-                'func'       => '_insert_or_update_question_group',
156
-                'args'       => array('new_question_group' => true),
157
-                'capability' => 'ee_edit_question_groups',
158
-                'noheader'   => true,
159
-            ),
160
-
161
-            'update_question_group' => array(
162
-                'func'       => '_insert_or_update_question_group',
163
-                'args'       => array('new_question_group' => false),
164
-                'capability' => 'ee_edit_question_group',
165
-                'obj_id'     => $qsg_id,
166
-                'noheader'   => true,
167
-            ),
168
-
169
-            'trash_question_groups' => array(
170
-                'func'       => '_trash_or_restore_question_groups',
171
-                'args'       => array('trash' => true),
172
-                'capability' => 'ee_delete_question_groups',
173
-                'noheader'   => array('trash' => false),
174
-            ),
175
-
176
-            'restore_question_groups' => array(
177
-                'func'       => '_trash_or_restore_question_groups',
178
-                'args'       => array('trash' => false),
179
-                'capability' => 'ee_delete_question_groups',
180
-                'noheader'   => true,
181
-            ),
182
-
183
-
184
-            'espresso_update_question_group_order' => array(
185
-                'func'       => 'update_question_group_order',
186
-                'capability' => 'ee_edit_question_groups',
187
-                'noheader'   => true,
188
-            ),
189
-
190
-            'view_reg_form_settings' => array(
191
-                'func'       => '_reg_form_settings',
192
-                'capability' => 'manage_options',
193
-            ),
194
-
195
-            'update_reg_form_settings' => array(
196
-                'func'       => '_update_reg_form_settings',
197
-                'capability' => 'manage_options',
198
-                'noheader'   => true,
199
-            ),
200
-        );
201
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
202
-
203
-        $new_page_config    = array(
204
-
205
-            'question_groups' => array(
206
-                'nav'           => array(
207
-                    'label' => esc_html__('Question Groups', 'event_espresso'),
208
-                    'order' => 20,
209
-                ),
210
-                'list_table'    => 'Registration_Form_Question_Groups_Admin_List_Table',
211
-                'help_tabs'     => array(
212
-                    'registration_form_question_groups_help_tab'                           => array(
213
-                        'title'    => esc_html__('Question Groups', 'event_espresso'),
214
-                        'filename' => 'registration_form_question_groups',
215
-                    ),
216
-                    'registration_form_question_groups_table_column_headings_help_tab'     => array(
217
-                        'title'    => esc_html__('Question Groups Table Column Headings', 'event_espresso'),
218
-                        'filename' => 'registration_form_question_groups_table_column_headings',
219
-                    ),
220
-                    'registration_form_question_groups_views_bulk_actions_search_help_tab' => array(
221
-                        'title'    => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'),
222
-                        'filename' => 'registration_form_question_groups_views_bulk_actions_search',
223
-                    ),
224
-                ),
225
-                'help_tour'     => array('Registration_Form_Question_Groups_Help_Tour'),
226
-                'metaboxes'     => $this->_default_espresso_metaboxes,
227
-                'require_nonce' => false,
228
-                'qtips'         => array(
229
-                    'EE_Registration_Form_Tips',
230
-                ),
231
-            ),
232
-
233
-            'add_question' => array(
234
-                'nav'           => array(
235
-                    'label'      => esc_html__('Add Question', 'event_espresso'),
236
-                    'order'      => 5,
237
-                    'persistent' => false,
238
-                ),
239
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
240
-                'help_tabs'     => array(
241
-                    'registration_form_add_question_help_tab' => array(
242
-                        'title'    => esc_html__('Add Question', 'event_espresso'),
243
-                        'filename' => 'registration_form_add_question',
244
-                    ),
245
-                ),
246
-                'help_tour'     => array('Registration_Form_Add_Question_Help_Tour'),
247
-                'require_nonce' => false,
248
-            ),
249
-
250
-            'add_question_group' => array(
251
-                'nav'           => array(
252
-                    'label'      => esc_html__('Add Question Group', 'event_espresso'),
253
-                    'order'      => 5,
254
-                    'persistent' => false,
255
-                ),
256
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
257
-                'help_tabs'     => array(
258
-                    'registration_form_add_question_group_help_tab' => array(
259
-                        'title'    => esc_html__('Add Question Group', 'event_espresso'),
260
-                        'filename' => 'registration_form_add_question_group',
261
-                    ),
262
-                ),
263
-                'help_tour'     => array('Registration_Form_Add_Question_Group_Help_Tour'),
264
-                'require_nonce' => false,
265
-            ),
266
-
267
-            'edit_question_group' => array(
268
-                'nav'           => array(
269
-                    'label'      => esc_html__('Edit Question Group', 'event_espresso'),
270
-                    'order'      => 5,
271
-                    'persistent' => false,
272
-                    'url'        => isset($this->_req_data['question_group_id']) ? add_query_arg(array('question_group_id' => $this->_req_data['question_group_id']),
273
-                        $this->_current_page_view_url) : $this->_admin_base_url,
274
-                ),
275
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
276
-                'help_tabs'     => array(
277
-                    'registration_form_edit_question_group_help_tab' => array(
278
-                        'title'    => esc_html__('Edit Question Group', 'event_espresso'),
279
-                        'filename' => 'registration_form_edit_question_group',
280
-                    ),
281
-                ),
282
-                'help_tour'     => array('Registration_Form_Edit_Question_Group_Help_Tour'),
283
-                'require_nonce' => false,
284
-            ),
285
-
286
-            'view_reg_form_settings' => array(
287
-                'nav'           => array(
288
-                    'label' => esc_html__('Reg Form Settings', 'event_espresso'),
289
-                    'order' => 40,
290
-                ),
291
-                'labels'        => array(
292
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
293
-                ),
294
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
295
-                'help_tabs'     => array(
296
-                    'registration_form_reg_form_settings_help_tab' => array(
297
-                        'title'    => esc_html__('Registration Form Settings', 'event_espresso'),
298
-                        'filename' => 'registration_form_reg_form_settings',
299
-                    ),
300
-                ),
301
-                'help_tour'     => array('Registration_Form_Settings_Help_Tour'),
302
-                'require_nonce' => false,
303
-            ),
304
-
305
-        );
306
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
307
-
308
-        //change the list table we're going to use so it's the NEW list table!
309
-        $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table';
310
-
311
-
312
-        //additional labels
313
-        $new_labels               = array(
314
-            'add_question'          => esc_html__('Add New Question', 'event_espresso'),
315
-            'delete_question'       => esc_html__('Delete Question', 'event_espresso'),
316
-            'add_question_group'    => esc_html__('Add New Question Group', 'event_espresso'),
317
-            'edit_question_group'   => esc_html__('Edit Question Group', 'event_espresso'),
318
-            'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'),
319
-        );
320
-        $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels);
321
-
322
-    }
323
-
324
-
325
-    protected function _ajax_hooks()
326
-    {
327
-        add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order'));
328
-    }
329
-
330
-
331
-    public function load_scripts_styles_question_groups()
332
-    {
333
-        wp_enqueue_script('espresso_ajax_table_sorting');
334
-    }
335
-
336
-
337
-    public function load_scripts_styles_add_question_group()
338
-    {
339
-        $this->load_scripts_styles_forms();
340
-        $this->load_sortable_question_script();
341
-    }
342
-
343
-    public function load_scripts_styles_edit_question_group()
344
-    {
345
-        $this->load_scripts_styles_forms();
346
-        $this->load_sortable_question_script();
347
-    }
348
-
349
-
350
-    /**
351
-     * registers and enqueues script for questions
352
-     *
353
-     * @return void
354
-     */
355
-    public function load_sortable_question_script()
356
-    {
357
-        wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js',
358
-            array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
359
-        wp_enqueue_script('ee-question-sortable');
360
-    }
361
-
362
-
363
-    protected function _set_list_table_views_default()
364
-    {
365
-        $this->_views = array(
366
-            'all' => array(
367
-                'slug'        => 'all',
368
-                'label'       => esc_html__('View All Questions', 'event_espresso'),
369
-                'count'       => 0,
370
-                'bulk_action' => array(
371
-                    'trash_questions' => esc_html__('Trash', 'event_espresso'),
372
-                ),
373
-            ),
374
-        );
375
-
376
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions',
377
-            'espresso_registration_form_trash_questions')
378
-        ) {
379
-            $this->_views['trash'] = array(
380
-                'slug'        => 'trash',
381
-                'label'       => esc_html__('Trash', 'event_espresso'),
382
-                'count'       => 0,
383
-                'bulk_action' => array(
384
-                    'delete_questions'  => esc_html__('Delete Permanently', 'event_espresso'),
385
-                    'restore_questions' => esc_html__('Restore', 'event_espresso'),
386
-                ),
387
-            );
388
-        }
389
-    }
390
-
391
-
392
-    protected function _set_list_table_views_question_groups()
393
-    {
394
-        $this->_views = array(
395
-            'all' => array(
396
-                'slug'        => 'all',
397
-                'label'       => esc_html__('All', 'event_espresso'),
398
-                'count'       => 0,
399
-                'bulk_action' => array(
400
-                    'trash_question_groups' => esc_html__('Trash', 'event_espresso'),
401
-                ),
402
-            ),
403
-        );
404
-
405
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_question_groups',
406
-            'espresso_registration_form_trash_question_groups')
407
-        ) {
408
-            $this->_views['trash'] = array(
409
-                'slug'        => 'trash',
410
-                'label'       => esc_html__('Trash', 'event_espresso'),
411
-                'count'       => 0,
412
-                'bulk_action' => array(
413
-                    'delete_question_groups'  => esc_html__('Delete Permanently', 'event_espresso'),
414
-                    'restore_question_groups' => esc_html__('Restore', 'event_espresso'),
415
-                ),
416
-            );
417
-        }
418
-    }
419
-
420
-
421
-    protected function _questions_overview_list_table()
422
-    {
423
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
424
-                'add_question',
425
-                'add_question',
426
-                array(),
427
-                'add-new-h2'
428
-            );
429
-        parent::_questions_overview_list_table();
430
-    }
431
-
432
-
433
-    protected function _question_groups_overview_list_table()
434
-    {
435
-        $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso');
436
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
437
-                'add_question_group',
438
-                'add_question_group',
439
-                array(),
440
-                'add-new-h2'
441
-            );
442
-        $this->display_admin_list_table_page_with_sidebar();
443
-    }
444
-
445
-
446
-    protected function _delete_question()
447
-    {
448
-        $success = $this->_delete_items($this->_question_model);
449
-        $this->_redirect_after_action(
450
-            $success,
451
-            $this->_question_model->item_name($success),
452
-            'deleted',
453
-            array('action' => 'default', 'status' => 'all')
454
-        );
455
-    }
456
-
457
-
458
-    protected function _delete_questions()
459
-    {
460
-        $success = $this->_delete_items($this->_question_model);
461
-        $this->_redirect_after_action(
462
-            $success,
463
-            $this->_question_model->item_name($success),
464
-            'deleted permanently',
465
-            array('action' => 'default', 'status' => 'trash')
466
-        );
467
-    }
468
-
469
-
470
-    /**
471
-     * Performs the deletion of a single or multiple questions or question groups.
472
-     *
473
-     * @param EEM_Soft_Delete_Base $model
474
-     * @return int number of items deleted permanently
475
-     */
476
-    private function _delete_items(EEM_Soft_Delete_Base $model)
477
-    {
478
-        $success = 0;
479
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
480
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
481
-            // if array has more than one element than success message should be plural
482
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
483
-            // cycle thru bulk action checkboxes
484
-            while (list($ID, $value) = each($this->_req_data['checkbox'])) {
485
-                if (! $this->_delete_item($ID, $model)) {
486
-                    $success = 0;
487
-                }
488
-            }
489
-
490
-        } elseif (! empty($this->_req_data['QSG_ID'])) {
491
-            $success = $this->_delete_item($this->_req_data['QSG_ID'], $model);
492
-
493
-        } elseif (! empty($this->_req_data['QST_ID'])) {
494
-            $success = $this->_delete_item($this->_req_data['QST_ID'], $model);
495
-        } else {
496
-            EE_Error::add_error(sprintf(esc_html__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.",
497
-                "event_espresso")), __FILE__, __FUNCTION__, __LINE__);
498
-        }
499
-        return $success;
500
-    }
501
-
502
-    /**
503
-     * Deletes the specified question (and its associated question options) or question group
504
-     *
505
-     * @param int                  $id
506
-     * @param EEM_Soft_Delete_Base $model
507
-     * @return boolean
508
-     */
509
-    protected function _delete_item($id, $model)
510
-    {
511
-        if ($model instanceof EEM_Question) {
512
-            EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id))));
513
-        }
514
-        return $model->delete_permanently_by_ID(absint($id));
515
-    }
516
-
517
-
518
-    /******************************    QUESTION GROUPS    ******************************/
519
-
520
-
521
-    protected function _edit_question_group($type = 'add')
522
-    {
523
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
524
-        $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) ? absint($this->_req_data['QSG_ID']) : false;
525
-
526
-        switch ($this->_req_action) {
527
-            case 'add_question_group' :
528
-                $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso');
529
-                break;
530
-            case 'edit_question_group' :
531
-                $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso');
532
-                break;
533
-            default :
534
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
535
-        }
536
-        // add ID to title if editing
537
-        $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
538
-        if ($ID) {
539
-            /** @var EE_Question_Group $questionGroup */
540
-            $questionGroup            = $this->_question_group_model->get_one_by_ID($ID);
541
-            $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID));
542
-            $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields);
543
-        } else {
544
-            /** @var EE_Question_Group $questionGroup */
545
-            $questionGroup = EEM_Question_Group::instance()->create_default_object();
546
-            $questionGroup->set_order_to_latest();
547
-            $this->_set_add_edit_form_tags('insert_question_group');
548
-        }
549
-        $this->_template_args['values']         = $this->_yes_no_values;
550
-        $this->_template_args['all_questions']  = $questionGroup->questions_in_and_not_in_group();
551
-        $this->_template_args['QSG_ID']         = $ID ? $ID : true;
552
-        $this->_template_args['question_group'] = $questionGroup;
553
-
554
-        $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url);
555
-        $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL);
556
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php',
557
-            $this->_template_args, true);
558
-
559
-        // the details template wrapper
560
-        $this->display_admin_page_with_sidebar();
561
-    }
562
-
563
-
564
-    protected function _delete_question_groups()
565
-    {
566
-        $success = $this->_delete_items($this->_question_group_model);
567
-        $this->_redirect_after_action($success, $this->_question_group_model->item_name($success),
568
-            'deleted permanently', array('action' => 'question_groups', 'status' => 'trash'));
569
-    }
570
-
571
-
572
-    /**
573
-     * @param bool $new_question_group
574
-     */
575
-    protected function _insert_or_update_question_group($new_question_group = true)
576
-    {
577
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
578
-        $set_column_values = $this->_set_column_values_for($this->_question_group_model);
579
-        if ($new_question_group) {
580
-            $QSG_ID  = $this->_question_group_model->insert($set_column_values);
581
-            $success = $QSG_ID ? 1 : 0;
582
-        } else {
583
-            $QSG_ID = absint($this->_req_data['QSG_ID']);
584
-            unset($set_column_values['QSG_ID']);
585
-            $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID)));
586
-        }
587
-        $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(EEM_Attendee::system_question_phone);
588
-        // update the existing related questions
589
-        // BUT FIRST...  delete the phone question from the Question_Group_Question if it is being added to this question group (therefore removed from the existing group)
590
-        if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) {
591
-            // delete where QST ID = system phone question ID and Question Group ID is NOT this group
592
-            EEM_Question_Group_Question::instance()->delete(array(
593
-                array(
594
-                    'QST_ID' => $phone_question_id,
595
-                    'QSG_ID' => array('!=', $QSG_ID),
596
-                ),
597
-            ));
598
-        }
599
-        /** @type EE_Question_Group $question_group */
600
-        $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID);
601
-        $questions      = $question_group->questions();
602
-        // make sure system phone question is added to list of questions for this group
603
-        if (! isset($questions[$phone_question_id])) {
604
-            $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id);
605
-        }
606
-
607
-        foreach ($questions as $question_ID => $question) {
608
-            // first we always check for order.
609
-            if (! empty($this->_req_data['question_orders'][$question_ID])) {
610
-                //update question order
611
-                $question_group->update_question_order($question_ID, $this->_req_data['question_orders'][$question_ID]);
612
-            }
613
-
614
-            // then we always check if adding or removing.
615
-            if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) {
616
-                $question_group->add_question($question_ID);
617
-            } else {
618
-                // not found, remove it (but only if not a system question for the personal group with the exception of lname system question - we allow removal of it)
619
-                if (
620
-                in_array(
621
-                    $question->system_ID(),
622
-                    EEM_Question::instance()->required_system_questions_in_system_question_group($question_group->system_group())
623
-                )
624
-                ) {
625
-                    continue;
626
-                } else {
627
-                    $question_group->remove_question($question_ID);
628
-                }
629
-            }
630
-        }
631
-        // save new related questions
632
-        if (isset($this->_req_data['questions'])) {
633
-            foreach ($this->_req_data['questions'] as $QST_ID) {
634
-                $question_group->add_question($QST_ID);
635
-                if (isset($this->_req_data['question_orders'][$QST_ID])) {
636
-                    $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]);
637
-                }
638
-            }
639
-        }
640
-
641
-        if ($success !== false) {
642
-            $msg = $new_question_group ? sprintf(esc_html__('The %s has been created', 'event_espresso'),
643
-                $this->_question_group_model->item_name()) : sprintf(esc_html__('The %s has been updated',
644
-                'event_espresso'), $this->_question_group_model->item_name());
645
-            EE_Error::add_success($msg);
646
-        }
647
-        $this->_redirect_after_action(false, '', '', array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID),
648
-            true);
649
-
650
-    }
651
-
652
-    /**
653
-     * duplicates a question and all its question options and redirects to the new question.
654
-     */
655
-    public function _duplicate_question()
656
-    {
657
-        $question_ID = (int)$this->_req_data['QST_ID'];
658
-        $question    = EEM_Question::instance()->get_one_by_ID($question_ID);
659
-        if ($question instanceof EE_Question) {
660
-            $new_question = $question->duplicate();
661
-            if ($new_question instanceof EE_Question) {
662
-                $this->_redirect_after_action(true, esc_html__('Question', 'event_espresso'),
663
-                    esc_html__('Duplicated', 'event_espresso'),
664
-                    array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), true);
665
-            } else {
666
-                global $wpdb;
667
-                EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %1$d because: %2$s',
668
-                    'event_espresso'), $question_ID, $wpdb->last_error), __FILE__, __FUNCTION__, __LINE__);
669
-                $this->_redirect_after_action(false, '', '', array('action' => 'default'), false);
670
-            }
671
-        } else {
672
-            EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %d because it didn\'t exist!',
673
-                'event_espresso'), $question_ID), __FILE__, __FUNCTION__, __LINE__);
674
-            $this->_redirect_after_action(false, '', '', array('action' => 'default'), false);
675
-        }
676
-    }
677
-
678
-
679
-    /**
680
-     * @param bool $trash
681
-     */
682
-    protected function _trash_or_restore_question_groups($trash = true)
683
-    {
684
-        $this->_trash_or_restore_items($this->_question_group_model, $trash);
685
-    }
686
-
687
-
688
-    /**
689
-     *_trash_question
690
-     */
691
-    protected function _trash_question()
692
-    {
693
-        $success    = $this->_question_model->delete_by_ID((int)$this->_req_data['QST_ID']);
694
-        $query_args = array('action' => 'default', 'status' => 'all');
695
-        $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args);
696
-    }
697
-
698
-
699
-    /**
700
-     * @param bool $trash
701
-     */
702
-    protected function _trash_or_restore_questions($trash = true)
703
-    {
704
-        $this->_trash_or_restore_items($this->_question_model, $trash);
705
-    }
706
-
707
-
708
-    /**
709
-     * Internally used to delete or restore items, using the request data. Meant to be
710
-     * flexible between question or question groups
711
-     *
712
-     * @param EEM_Soft_Delete_Base $model
713
-     * @param boolean              $trash whether to trash or restore
714
-     */
715
-    private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true)
716
-    {
717
-
718
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
719
-
720
-        $success = 1;
721
-        //Checkboxes
722
-        //echo "trash $trash";
723
-        //var_dump($this->_req_data['checkbox']);die;
724
-        if (isset($this->_req_data['checkbox'])) {
725
-            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
726
-                // if array has more than one element than success message should be plural
727
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
728
-                // cycle thru bulk action checkboxes
729
-                while (list($ID, $value) = each($this->_req_data['checkbox'])) {
730
-                    if (! $model->delete_or_restore_by_ID($trash, absint($ID))) {
731
-                        $success = 0;
732
-                    }
733
-                }
734
-
735
-            } else {
736
-                // grab single id and delete
737
-                $ID = absint($this->_req_data['checkbox']);
738
-                if (! $model->delete_or_restore_by_ID($trash, $ID)) {
739
-                    $success = 0;
740
-                }
741
-            }
742
-
743
-        } else {
744
-            // delete via trash link
745
-            // grab single id and delete
746
-            $ID = absint($this->_req_data[$model->primary_key_name()]);
747
-            if (! $model->delete_or_restore_by_ID($trash, $ID)) {
748
-                $success = 0;
749
-            }
750
-
751
-        }
752
-
753
-
754
-        $action = $model instanceof EEM_Question ? 'default' : 'question_groups';//strtolower( $model->item_name(2) );
755
-        //echo "action :$action";
756
-        //$action = 'questions' ? 'default' : $action;
757
-        if ($trash) {
758
-            $action_desc = 'trashed';
759
-            $status      = 'trash';
760
-        } else {
761
-            $action_desc = 'restored';
762
-            $status      = 'all';
763
-        }
764
-        $this->_redirect_after_action($success, $model->item_name($success), $action_desc,
765
-            array('action' => $action, 'status' => $status));
766
-    }
767
-
768
-
769
-    /**
770
-     * @param            $per_page
771
-     * @param int        $current_page
772
-     * @param bool|false $count
773
-     * @return \EE_Soft_Delete_Base_Class[]|int
774
-     */
775
-    public function get_trashed_questions($per_page, $current_page = 1, $count = false)
776
-    {
777
-        $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
778
-
779
-        if ($count) {
780
-            //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
781
-            $where   = isset($query_params[0]) ? array($query_params[0]) : array();
782
-            $results = $this->_question_model->count_deleted($where);
783
-        } else {
784
-            //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
785
-            $results = $this->_question_model->get_all_deleted($query_params);
786
-        }
787
-        return $results;
788
-    }
789
-
790
-
791
-    /**
792
-     * @param            $per_page
793
-     * @param int        $current_page
794
-     * @param bool|false $count
795
-     * @return \EE_Soft_Delete_Base_Class[]
796
-     */
797
-    public function get_question_groups($per_page, $current_page = 1, $count = false)
798
-    {
799
-        $questionGroupModel = EEM_Question_Group::instance();
800
-        $query_params       = $this->get_query_params($questionGroupModel, $per_page, $current_page);
801
-        if ($count) {
802
-            $where   = isset($query_params[0]) ? array($query_params[0]) : array();
803
-            $results = $questionGroupModel->count($where);
804
-        } else {
805
-            $results = $questionGroupModel->get_all($query_params);
806
-        }
807
-        return $results;
808
-    }
809
-
810
-
811
-    /**
812
-     * @param      $per_page
813
-     * @param int  $current_page
814
-     * @param bool $count
815
-     * @return \EE_Soft_Delete_Base_Class[]|int
816
-     */
817
-    public function get_trashed_question_groups($per_page, $current_page = 1, $count = false)
818
-    {
819
-        $questionGroupModel = EEM_Question_Group::instance();
820
-        $query_params       = $this->get_query_params($questionGroupModel, $per_page, $current_page);
821
-        if ($count) {
822
-            $where                 = isset($query_params[0]) ? array($query_params[0]) : array();
823
-            $query_params['limit'] = null;
824
-            $results               = $questionGroupModel->count_deleted($where);
825
-        } else {
826
-            $results = $questionGroupModel->get_all_deleted($query_params);
827
-        }
828
-        return $results;
829
-    }
830
-
831
-
832
-    /**
833
-     * method for performing updates to question order
834
-     *
835
-     * @return array results array
836
-     */
837
-    public function update_question_group_order()
838
-    {
839
-
840
-        $success = esc_html__('Question group order was updated successfully.', 'event_espresso');
841
-
842
-        // grab our row IDs
843
-        $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids'])
844
-            ? explode(',', rtrim($this->_req_data['row_ids'], ','))
845
-            : array();
846
-
847
-        $perpage = ! empty($this->_req_data['perpage'])
848
-            ? (int)$this->_req_data['perpage']
849
-            : null;
850
-        $curpage = ! empty($this->_req_data['curpage'])
851
-            ? (int)$this->_req_data['curpage']
852
-            : null;
853
-
854
-        if (! empty($row_ids)) {
855
-            //figure out where we start the row_id count at for the current page.
856
-            $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage;
857
-
858
-            $row_count = count($row_ids);
859
-            for ($i = 0; $i < $row_count; $i++) {
860
-                //Update the questions when re-ordering
861
-                $updated = EEM_Question_Group::instance()->update(
862
-                    array('QSG_order' => $qsgcount),
863
-                    array(array('QSG_ID' => $row_ids[$i]))
864
-                );
865
-                if ($updated === false) {
866
-                    $success = false;
867
-                }
868
-                $qsgcount++;
869
-            }
870
-        } else {
871
-            $success = false;
872
-        }
873
-
874
-        $errors = ! $success
875
-            ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso')
876
-            : false;
877
-
878
-        echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors));
879
-        die();
880
-
881
-    }
882
-
883
-
884
-
885
-    /***************************************        REGISTRATION SETTINGS        ***************************************/
886
-
887
-
888
-    /**
889
-     * _reg_form_settings
890
-     *
891
-     * @throws \EE_Error
892
-     */
893
-    protected function _reg_form_settings()
894
-    {
895
-        $this->_template_args['values'] = $this->_yes_no_values;
896
-        add_action(
897
-            'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
898
-            array($this, 'email_validation_settings_form'),
899
-            2
900
-        );
901
-        $this->_template_args = (array)apply_filters(
902
-            'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args',
903
-            $this->_template_args
904
-        );
905
-        $this->_set_add_edit_form_tags('update_reg_form_settings');
906
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
907
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
908
-            REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php',
909
-            $this->_template_args,
910
-            true
911
-        );
912
-        $this->display_admin_page_with_sidebar();
913
-    }
914
-
915
-
916
-    /**
917
-     * _update_reg_form_settings
918
-     */
919
-    protected function _update_reg_form_settings()
920
-    {
921
-        EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form(
922
-            EE_Registry::instance()->CFG->registration
923
-        );
924
-        EE_Registry::instance()->CFG->registration = apply_filters(
925
-            'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
926
-            EE_Registry::instance()->CFG->registration
927
-        );
928
-        $success                                   = $this->_update_espresso_configuration(
929
-            esc_html__('Registration Form Options', 'event_espresso'),
930
-            EE_Registry::instance()->CFG,
931
-            __FILE__, __FUNCTION__, __LINE__
932
-        );
933
-        $this->_redirect_after_action($success, esc_html__('Registration Form Options', 'event_espresso'), 'updated',
934
-            array('action' => 'view_reg_form_settings'));
935
-    }
936
-
937
-
938
-    /**
939
-     * email_validation_settings_form
940
-     *
941
-     * @access    public
942
-     * @return    void
943
-     * @throws \EE_Error
944
-     */
945
-    public function email_validation_settings_form()
946
-    {
947
-        echo $this->_email_validation_settings_form()->get_html();
948
-    }
949
-
950
-
951
-    /**
952
-     * _email_validation_settings_form
953
-     *
954
-     * @access protected
955
-     * @return EE_Form_Section_Proper
956
-     * @throws \EE_Error
957
-     */
958
-    protected function _email_validation_settings_form()
959
-    {
960
-        return new EE_Form_Section_Proper(
961
-            array(
962
-                'name'            => 'email_validation_settings',
963
-                'html_id'         => 'email_validation_settings',
964
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
965
-                'subsections'     => apply_filters(
966
-                    'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections',
967
-                    array(
968
-                        'email_validation_hdr'   => new EE_Form_Section_HTML(
969
-                            EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso'))
970
-                        ),
971
-                        'email_validation_level' => new EE_Select_Input(
972
-                            array(
973
-                                'basic'      => esc_html__('Basic', 'event_espresso'),
974
-                                'wp_default' => esc_html__('WordPress Default', 'event_espresso'),
975
-                                'i18n'       => esc_html__('International', 'event_espresso'),
976
-                                'i18n_dns'   => esc_html__('International + DNS Check', 'event_espresso'),
977
-                            ),
978
-                            array(
979
-                                'html_label_text' => esc_html__('Email Validation Level', 'event_espresso')
980
-                                                     . EEH_Template::get_help_tab_link('email_validation_info'),
981
-                                'html_help_text'  => esc_html__('These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.',
982
-                                    'event_espresso'),
983
-                                'default'         => isset(EE_Registry::instance()->CFG->registration->email_validation_level)
984
-                                    ? EE_Registry::instance()->CFG->registration->email_validation_level
985
-                                    : 'wp_default',
986
-                                'required'        => false,
987
-                            )
988
-                        ),
989
-                    )
990
-                ),
991
-            )
992
-        );
993
-    }
994
-
995
-
996
-    /**
997
-     * update_email_validation_settings_form
998
-     *
999
-     * @access    public
1000
-     * @param \EE_Registration_Config $EE_Registration_Config
1001
-     * @return \EE_Registration_Config
1002
-     */
1003
-    public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config)
1004
-    {
1005
-        $prev_email_validation_level = $EE_Registration_Config->email_validation_level;
1006
-        try {
1007
-            $email_validation_settings_form = $this->_email_validation_settings_form();
1008
-            // if not displaying a form, then check for form submission
1009
-            if ($email_validation_settings_form->was_submitted()) {
1010
-                // capture form data
1011
-                $email_validation_settings_form->receive_form_submission();
1012
-                // validate form data
1013
-                if ($email_validation_settings_form->is_valid()) {
1014
-                    // grab validated data from form
1015
-                    $valid_data = $email_validation_settings_form->valid_data();
1016
-                    if (isset($valid_data['email_validation_level'])) {
1017
-                        $email_validation_level = $valid_data['email_validation_level'];
1018
-                        // now if they want to use international email addresses
1019
-                        if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') {
1020
-                            // in case we need to reset their email validation level,
1021
-                            // make sure that the previous value wasn't already set to one of the i18n options.
1022
-                            if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') {
1023
-                                // if so, then reset it back to "basic" since that is the only other option that,
1024
-                                // despite offering poor validation, supports i18n email addresses
1025
-                                $prev_email_validation_level = 'basic';
1026
-                            }
1027
-                            // confirm our i18n email validation will work on the server
1028
-                            if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) {
1029
-                                // or reset email validation level to previous value
1030
-                                $email_validation_level = $prev_email_validation_level;
1031
-                            }
1032
-                        }
1033
-                        $EE_Registration_Config->email_validation_level = $email_validation_level;
1034
-                    } else {
1035
-                        EE_Error::add_error(
1036
-                            esc_html__(
1037
-                                'Invalid or missing Email Validation settings. Please refresh the form and try again.',
1038
-                                'event_espresso'
1039
-                            ),
1040
-                            __FILE__, __FUNCTION__, __LINE__
1041
-                        );
1042
-                    }
1043
-                } else {
1044
-                    if ($email_validation_settings_form->submission_error_message() !== '') {
1045
-                        EE_Error::add_error(
1046
-                            $email_validation_settings_form->submission_error_message(),
1047
-                            __FILE__, __FUNCTION__, __LINE__
1048
-                        );
1049
-                    }
1050
-                }
1051
-            }
1052
-        } catch (EE_Error $e) {
1053
-            $e->get_error();
1054
-        }
1055
-        return $EE_Registration_Config;
1056
-    }
1057
-
1058
-
1059
-    /**
1060
-     * confirms that the server's PHP version has the PCRE module enabled,
1061
-     * and that the PCRE version works with our i18n email validation
1062
-     *
1063
-     * @param \EE_Registration_Config $EE_Registration_Config
1064
-     * @param string                  $email_validation_level
1065
-     * @return bool
1066
-     */
1067
-    private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level)
1068
-    {
1069
-        // first check that PCRE is enabled
1070
-        if (! defined('PREG_BAD_UTF8_ERROR')) {
1071
-            EE_Error::add_error(
1072
-                sprintf(
1073
-                    esc_html__(
1074
-                        'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.',
1075
-                        'event_espresso'
1076
-                    ),
1077
-                    '<br />'
1078
-                ),
1079
-                __FILE__,
1080
-                __FUNCTION__,
1081
-                __LINE__
1082
-            );
1083
-            return false;
1084
-        } else {
1085
-            // PCRE support is enabled, but let's still
1086
-            // perform a test to see if the server will support it.
1087
-            // but first, save the updated validation level to the config,
1088
-            // so that the validation strategy picks it up.
1089
-            // this will get bumped back down if it doesn't work
1090
-            $EE_Registration_Config->email_validation_level = $email_validation_level;
1091
-            try {
1092
-                $email_validator    = new EE_Email_Validation_Strategy();
1093
-                $i18n_email_address = apply_filters(
1094
-                    'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address',
1095
-                    'jägerjü[email protected]'
1096
-                );
1097
-                $email_validator->validate($i18n_email_address);
1098
-            } catch (Exception $e) {
1099
-                EE_Error::add_error(
1100
-                    sprintf(
1101
-                        esc_html__(
1102
-                            'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s',
1103
-                            'event_espresso'
1104
-                        ),
1105
-                        '<br />',
1106
-                        '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>'
1107
-                    ),
1108
-                    __FILE__, __FUNCTION__, __LINE__
1109
-                );
1110
-                return false;
1111
-            }
1112
-        }
1113
-        return true;
1114
-    }
28
+	/**
29
+	 * @Constructor
30
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
31
+	 * @access public
32
+	 */
33
+	public function __construct($routing = true)
34
+	{
35
+		define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS);
36
+		define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS);
37
+		define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/');
38
+		define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS);
39
+		define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/');
40
+		parent::__construct($routing);
41
+	}
42
+
43
+
44
+	protected function _extend_page_config()
45
+	{
46
+		$this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN;
47
+		$qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0;
48
+		$qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) ? $this->_req_data['QSG_ID'] : 0;
49
+
50
+		$new_page_routes    = array(
51
+			'question_groups'    => array(
52
+				'func'       => '_question_groups_overview_list_table',
53
+				'capability' => 'ee_read_question_groups',
54
+			),
55
+			'add_question'       => array(
56
+				'func'       => '_edit_question',
57
+				'capability' => 'ee_edit_questions',
58
+			),
59
+			'insert_question'    => array(
60
+				'func'       => '_insert_or_update_question',
61
+				'args'       => array('new_question' => true),
62
+				'capability' => 'ee_edit_questions',
63
+				'noheader'   => true,
64
+			),
65
+			'duplicate_question' => array(
66
+				'func'       => '_duplicate_question',
67
+				'capability' => 'ee_edit_questions',
68
+				'noheader'   => true,
69
+			),
70
+			'trash_question'     => array(
71
+				'func'       => '_trash_question',
72
+				'capability' => 'ee_delete_question',
73
+				'obj_id'     => $qst_id,
74
+				'noheader'   => true,
75
+			),
76
+
77
+			'restore_question' => array(
78
+				'func'       => '_trash_or_restore_questions',
79
+				'capability' => 'ee_delete_question',
80
+				'obj_id'     => $qst_id,
81
+				'args'       => array('trash' => false),
82
+				'noheader'   => true,
83
+			),
84
+
85
+			'delete_question' => array(
86
+				'func'       => '_delete_question',
87
+				'capability' => 'ee_delete_question',
88
+				'obj_id'     => $qst_id,
89
+				'noheader'   => true,
90
+			),
91
+
92
+			'trash_questions' => array(
93
+				'func'       => '_trash_or_restore_questions',
94
+				'capability' => 'ee_delete_questions',
95
+				'args'       => array('trash' => true),
96
+				'noheader'   => true,
97
+			),
98
+
99
+			'restore_questions' => array(
100
+				'func'       => '_trash_or_restore_questions',
101
+				'capability' => 'ee_delete_questions',
102
+				'args'       => array('trash' => false),
103
+				'noheader'   => true,
104
+			),
105
+
106
+			'delete_questions' => array(
107
+				'func'       => '_delete_questions',
108
+				'args'       => array(),
109
+				'capability' => 'ee_delete_questions',
110
+				'noheader'   => true,
111
+			),
112
+
113
+			'add_question_group' => array(
114
+				'func'       => '_edit_question_group',
115
+				'capability' => 'ee_edit_question_groups',
116
+			),
117
+
118
+			'edit_question_group' => array(
119
+				'func'       => '_edit_question_group',
120
+				'capability' => 'ee_edit_question_group',
121
+				'obj_id'     => $qsg_id,
122
+				'args'       => array('edit'),
123
+			),
124
+
125
+			'delete_question_groups' => array(
126
+				'func'       => '_delete_question_groups',
127
+				'capability' => 'ee_delete_question_groups',
128
+				'noheader'   => true,
129
+			),
130
+
131
+			'delete_question_group' => array(
132
+				'func'       => '_delete_question_groups',
133
+				'capability' => 'ee_delete_question_group',
134
+				'obj_id'     => $qsg_id,
135
+				'noheader'   => true,
136
+			),
137
+
138
+			'trash_question_group' => array(
139
+				'func'       => '_trash_or_restore_question_groups',
140
+				'args'       => array('trash' => true),
141
+				'capability' => 'ee_delete_question_group',
142
+				'obj_id'     => $qsg_id,
143
+				'noheader'   => true,
144
+			),
145
+
146
+			'restore_question_group' => array(
147
+				'func'       => '_trash_or_restore_question_groups',
148
+				'args'       => array('trash' => false),
149
+				'capability' => 'ee_delete_question_group',
150
+				'obj_id'     => $qsg_id,
151
+				'noheader'   => true,
152
+			),
153
+
154
+			'insert_question_group' => array(
155
+				'func'       => '_insert_or_update_question_group',
156
+				'args'       => array('new_question_group' => true),
157
+				'capability' => 'ee_edit_question_groups',
158
+				'noheader'   => true,
159
+			),
160
+
161
+			'update_question_group' => array(
162
+				'func'       => '_insert_or_update_question_group',
163
+				'args'       => array('new_question_group' => false),
164
+				'capability' => 'ee_edit_question_group',
165
+				'obj_id'     => $qsg_id,
166
+				'noheader'   => true,
167
+			),
168
+
169
+			'trash_question_groups' => array(
170
+				'func'       => '_trash_or_restore_question_groups',
171
+				'args'       => array('trash' => true),
172
+				'capability' => 'ee_delete_question_groups',
173
+				'noheader'   => array('trash' => false),
174
+			),
175
+
176
+			'restore_question_groups' => array(
177
+				'func'       => '_trash_or_restore_question_groups',
178
+				'args'       => array('trash' => false),
179
+				'capability' => 'ee_delete_question_groups',
180
+				'noheader'   => true,
181
+			),
182
+
183
+
184
+			'espresso_update_question_group_order' => array(
185
+				'func'       => 'update_question_group_order',
186
+				'capability' => 'ee_edit_question_groups',
187
+				'noheader'   => true,
188
+			),
189
+
190
+			'view_reg_form_settings' => array(
191
+				'func'       => '_reg_form_settings',
192
+				'capability' => 'manage_options',
193
+			),
194
+
195
+			'update_reg_form_settings' => array(
196
+				'func'       => '_update_reg_form_settings',
197
+				'capability' => 'manage_options',
198
+				'noheader'   => true,
199
+			),
200
+		);
201
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
202
+
203
+		$new_page_config    = array(
204
+
205
+			'question_groups' => array(
206
+				'nav'           => array(
207
+					'label' => esc_html__('Question Groups', 'event_espresso'),
208
+					'order' => 20,
209
+				),
210
+				'list_table'    => 'Registration_Form_Question_Groups_Admin_List_Table',
211
+				'help_tabs'     => array(
212
+					'registration_form_question_groups_help_tab'                           => array(
213
+						'title'    => esc_html__('Question Groups', 'event_espresso'),
214
+						'filename' => 'registration_form_question_groups',
215
+					),
216
+					'registration_form_question_groups_table_column_headings_help_tab'     => array(
217
+						'title'    => esc_html__('Question Groups Table Column Headings', 'event_espresso'),
218
+						'filename' => 'registration_form_question_groups_table_column_headings',
219
+					),
220
+					'registration_form_question_groups_views_bulk_actions_search_help_tab' => array(
221
+						'title'    => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'),
222
+						'filename' => 'registration_form_question_groups_views_bulk_actions_search',
223
+					),
224
+				),
225
+				'help_tour'     => array('Registration_Form_Question_Groups_Help_Tour'),
226
+				'metaboxes'     => $this->_default_espresso_metaboxes,
227
+				'require_nonce' => false,
228
+				'qtips'         => array(
229
+					'EE_Registration_Form_Tips',
230
+				),
231
+			),
232
+
233
+			'add_question' => array(
234
+				'nav'           => array(
235
+					'label'      => esc_html__('Add Question', 'event_espresso'),
236
+					'order'      => 5,
237
+					'persistent' => false,
238
+				),
239
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
240
+				'help_tabs'     => array(
241
+					'registration_form_add_question_help_tab' => array(
242
+						'title'    => esc_html__('Add Question', 'event_espresso'),
243
+						'filename' => 'registration_form_add_question',
244
+					),
245
+				),
246
+				'help_tour'     => array('Registration_Form_Add_Question_Help_Tour'),
247
+				'require_nonce' => false,
248
+			),
249
+
250
+			'add_question_group' => array(
251
+				'nav'           => array(
252
+					'label'      => esc_html__('Add Question Group', 'event_espresso'),
253
+					'order'      => 5,
254
+					'persistent' => false,
255
+				),
256
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
257
+				'help_tabs'     => array(
258
+					'registration_form_add_question_group_help_tab' => array(
259
+						'title'    => esc_html__('Add Question Group', 'event_espresso'),
260
+						'filename' => 'registration_form_add_question_group',
261
+					),
262
+				),
263
+				'help_tour'     => array('Registration_Form_Add_Question_Group_Help_Tour'),
264
+				'require_nonce' => false,
265
+			),
266
+
267
+			'edit_question_group' => array(
268
+				'nav'           => array(
269
+					'label'      => esc_html__('Edit Question Group', 'event_espresso'),
270
+					'order'      => 5,
271
+					'persistent' => false,
272
+					'url'        => isset($this->_req_data['question_group_id']) ? add_query_arg(array('question_group_id' => $this->_req_data['question_group_id']),
273
+						$this->_current_page_view_url) : $this->_admin_base_url,
274
+				),
275
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
276
+				'help_tabs'     => array(
277
+					'registration_form_edit_question_group_help_tab' => array(
278
+						'title'    => esc_html__('Edit Question Group', 'event_espresso'),
279
+						'filename' => 'registration_form_edit_question_group',
280
+					),
281
+				),
282
+				'help_tour'     => array('Registration_Form_Edit_Question_Group_Help_Tour'),
283
+				'require_nonce' => false,
284
+			),
285
+
286
+			'view_reg_form_settings' => array(
287
+				'nav'           => array(
288
+					'label' => esc_html__('Reg Form Settings', 'event_espresso'),
289
+					'order' => 40,
290
+				),
291
+				'labels'        => array(
292
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
293
+				),
294
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
295
+				'help_tabs'     => array(
296
+					'registration_form_reg_form_settings_help_tab' => array(
297
+						'title'    => esc_html__('Registration Form Settings', 'event_espresso'),
298
+						'filename' => 'registration_form_reg_form_settings',
299
+					),
300
+				),
301
+				'help_tour'     => array('Registration_Form_Settings_Help_Tour'),
302
+				'require_nonce' => false,
303
+			),
304
+
305
+		);
306
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
307
+
308
+		//change the list table we're going to use so it's the NEW list table!
309
+		$this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table';
310
+
311
+
312
+		//additional labels
313
+		$new_labels               = array(
314
+			'add_question'          => esc_html__('Add New Question', 'event_espresso'),
315
+			'delete_question'       => esc_html__('Delete Question', 'event_espresso'),
316
+			'add_question_group'    => esc_html__('Add New Question Group', 'event_espresso'),
317
+			'edit_question_group'   => esc_html__('Edit Question Group', 'event_espresso'),
318
+			'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'),
319
+		);
320
+		$this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels);
321
+
322
+	}
323
+
324
+
325
+	protected function _ajax_hooks()
326
+	{
327
+		add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order'));
328
+	}
329
+
330
+
331
+	public function load_scripts_styles_question_groups()
332
+	{
333
+		wp_enqueue_script('espresso_ajax_table_sorting');
334
+	}
335
+
336
+
337
+	public function load_scripts_styles_add_question_group()
338
+	{
339
+		$this->load_scripts_styles_forms();
340
+		$this->load_sortable_question_script();
341
+	}
342
+
343
+	public function load_scripts_styles_edit_question_group()
344
+	{
345
+		$this->load_scripts_styles_forms();
346
+		$this->load_sortable_question_script();
347
+	}
348
+
349
+
350
+	/**
351
+	 * registers and enqueues script for questions
352
+	 *
353
+	 * @return void
354
+	 */
355
+	public function load_sortable_question_script()
356
+	{
357
+		wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js',
358
+			array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
359
+		wp_enqueue_script('ee-question-sortable');
360
+	}
361
+
362
+
363
+	protected function _set_list_table_views_default()
364
+	{
365
+		$this->_views = array(
366
+			'all' => array(
367
+				'slug'        => 'all',
368
+				'label'       => esc_html__('View All Questions', 'event_espresso'),
369
+				'count'       => 0,
370
+				'bulk_action' => array(
371
+					'trash_questions' => esc_html__('Trash', 'event_espresso'),
372
+				),
373
+			),
374
+		);
375
+
376
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions',
377
+			'espresso_registration_form_trash_questions')
378
+		) {
379
+			$this->_views['trash'] = array(
380
+				'slug'        => 'trash',
381
+				'label'       => esc_html__('Trash', 'event_espresso'),
382
+				'count'       => 0,
383
+				'bulk_action' => array(
384
+					'delete_questions'  => esc_html__('Delete Permanently', 'event_espresso'),
385
+					'restore_questions' => esc_html__('Restore', 'event_espresso'),
386
+				),
387
+			);
388
+		}
389
+	}
390
+
391
+
392
+	protected function _set_list_table_views_question_groups()
393
+	{
394
+		$this->_views = array(
395
+			'all' => array(
396
+				'slug'        => 'all',
397
+				'label'       => esc_html__('All', 'event_espresso'),
398
+				'count'       => 0,
399
+				'bulk_action' => array(
400
+					'trash_question_groups' => esc_html__('Trash', 'event_espresso'),
401
+				),
402
+			),
403
+		);
404
+
405
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_question_groups',
406
+			'espresso_registration_form_trash_question_groups')
407
+		) {
408
+			$this->_views['trash'] = array(
409
+				'slug'        => 'trash',
410
+				'label'       => esc_html__('Trash', 'event_espresso'),
411
+				'count'       => 0,
412
+				'bulk_action' => array(
413
+					'delete_question_groups'  => esc_html__('Delete Permanently', 'event_espresso'),
414
+					'restore_question_groups' => esc_html__('Restore', 'event_espresso'),
415
+				),
416
+			);
417
+		}
418
+	}
419
+
420
+
421
+	protected function _questions_overview_list_table()
422
+	{
423
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
424
+				'add_question',
425
+				'add_question',
426
+				array(),
427
+				'add-new-h2'
428
+			);
429
+		parent::_questions_overview_list_table();
430
+	}
431
+
432
+
433
+	protected function _question_groups_overview_list_table()
434
+	{
435
+		$this->_search_btn_label = esc_html__('Question Groups', 'event_espresso');
436
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
437
+				'add_question_group',
438
+				'add_question_group',
439
+				array(),
440
+				'add-new-h2'
441
+			);
442
+		$this->display_admin_list_table_page_with_sidebar();
443
+	}
444
+
445
+
446
+	protected function _delete_question()
447
+	{
448
+		$success = $this->_delete_items($this->_question_model);
449
+		$this->_redirect_after_action(
450
+			$success,
451
+			$this->_question_model->item_name($success),
452
+			'deleted',
453
+			array('action' => 'default', 'status' => 'all')
454
+		);
455
+	}
456
+
457
+
458
+	protected function _delete_questions()
459
+	{
460
+		$success = $this->_delete_items($this->_question_model);
461
+		$this->_redirect_after_action(
462
+			$success,
463
+			$this->_question_model->item_name($success),
464
+			'deleted permanently',
465
+			array('action' => 'default', 'status' => 'trash')
466
+		);
467
+	}
468
+
469
+
470
+	/**
471
+	 * Performs the deletion of a single or multiple questions or question groups.
472
+	 *
473
+	 * @param EEM_Soft_Delete_Base $model
474
+	 * @return int number of items deleted permanently
475
+	 */
476
+	private function _delete_items(EEM_Soft_Delete_Base $model)
477
+	{
478
+		$success = 0;
479
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
480
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
481
+			// if array has more than one element than success message should be plural
482
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
483
+			// cycle thru bulk action checkboxes
484
+			while (list($ID, $value) = each($this->_req_data['checkbox'])) {
485
+				if (! $this->_delete_item($ID, $model)) {
486
+					$success = 0;
487
+				}
488
+			}
489
+
490
+		} elseif (! empty($this->_req_data['QSG_ID'])) {
491
+			$success = $this->_delete_item($this->_req_data['QSG_ID'], $model);
492
+
493
+		} elseif (! empty($this->_req_data['QST_ID'])) {
494
+			$success = $this->_delete_item($this->_req_data['QST_ID'], $model);
495
+		} else {
496
+			EE_Error::add_error(sprintf(esc_html__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.",
497
+				"event_espresso")), __FILE__, __FUNCTION__, __LINE__);
498
+		}
499
+		return $success;
500
+	}
501
+
502
+	/**
503
+	 * Deletes the specified question (and its associated question options) or question group
504
+	 *
505
+	 * @param int                  $id
506
+	 * @param EEM_Soft_Delete_Base $model
507
+	 * @return boolean
508
+	 */
509
+	protected function _delete_item($id, $model)
510
+	{
511
+		if ($model instanceof EEM_Question) {
512
+			EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id))));
513
+		}
514
+		return $model->delete_permanently_by_ID(absint($id));
515
+	}
516
+
517
+
518
+	/******************************    QUESTION GROUPS    ******************************/
519
+
520
+
521
+	protected function _edit_question_group($type = 'add')
522
+	{
523
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
524
+		$ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) ? absint($this->_req_data['QSG_ID']) : false;
525
+
526
+		switch ($this->_req_action) {
527
+			case 'add_question_group' :
528
+				$this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso');
529
+				break;
530
+			case 'edit_question_group' :
531
+				$this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso');
532
+				break;
533
+			default :
534
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
535
+		}
536
+		// add ID to title if editing
537
+		$this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
538
+		if ($ID) {
539
+			/** @var EE_Question_Group $questionGroup */
540
+			$questionGroup            = $this->_question_group_model->get_one_by_ID($ID);
541
+			$additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID));
542
+			$this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields);
543
+		} else {
544
+			/** @var EE_Question_Group $questionGroup */
545
+			$questionGroup = EEM_Question_Group::instance()->create_default_object();
546
+			$questionGroup->set_order_to_latest();
547
+			$this->_set_add_edit_form_tags('insert_question_group');
548
+		}
549
+		$this->_template_args['values']         = $this->_yes_no_values;
550
+		$this->_template_args['all_questions']  = $questionGroup->questions_in_and_not_in_group();
551
+		$this->_template_args['QSG_ID']         = $ID ? $ID : true;
552
+		$this->_template_args['question_group'] = $questionGroup;
553
+
554
+		$redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url);
555
+		$this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL);
556
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php',
557
+			$this->_template_args, true);
558
+
559
+		// the details template wrapper
560
+		$this->display_admin_page_with_sidebar();
561
+	}
562
+
563
+
564
+	protected function _delete_question_groups()
565
+	{
566
+		$success = $this->_delete_items($this->_question_group_model);
567
+		$this->_redirect_after_action($success, $this->_question_group_model->item_name($success),
568
+			'deleted permanently', array('action' => 'question_groups', 'status' => 'trash'));
569
+	}
570
+
571
+
572
+	/**
573
+	 * @param bool $new_question_group
574
+	 */
575
+	protected function _insert_or_update_question_group($new_question_group = true)
576
+	{
577
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
578
+		$set_column_values = $this->_set_column_values_for($this->_question_group_model);
579
+		if ($new_question_group) {
580
+			$QSG_ID  = $this->_question_group_model->insert($set_column_values);
581
+			$success = $QSG_ID ? 1 : 0;
582
+		} else {
583
+			$QSG_ID = absint($this->_req_data['QSG_ID']);
584
+			unset($set_column_values['QSG_ID']);
585
+			$success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID)));
586
+		}
587
+		$phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(EEM_Attendee::system_question_phone);
588
+		// update the existing related questions
589
+		// BUT FIRST...  delete the phone question from the Question_Group_Question if it is being added to this question group (therefore removed from the existing group)
590
+		if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) {
591
+			// delete where QST ID = system phone question ID and Question Group ID is NOT this group
592
+			EEM_Question_Group_Question::instance()->delete(array(
593
+				array(
594
+					'QST_ID' => $phone_question_id,
595
+					'QSG_ID' => array('!=', $QSG_ID),
596
+				),
597
+			));
598
+		}
599
+		/** @type EE_Question_Group $question_group */
600
+		$question_group = $this->_question_group_model->get_one_by_ID($QSG_ID);
601
+		$questions      = $question_group->questions();
602
+		// make sure system phone question is added to list of questions for this group
603
+		if (! isset($questions[$phone_question_id])) {
604
+			$questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id);
605
+		}
606
+
607
+		foreach ($questions as $question_ID => $question) {
608
+			// first we always check for order.
609
+			if (! empty($this->_req_data['question_orders'][$question_ID])) {
610
+				//update question order
611
+				$question_group->update_question_order($question_ID, $this->_req_data['question_orders'][$question_ID]);
612
+			}
613
+
614
+			// then we always check if adding or removing.
615
+			if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) {
616
+				$question_group->add_question($question_ID);
617
+			} else {
618
+				// not found, remove it (but only if not a system question for the personal group with the exception of lname system question - we allow removal of it)
619
+				if (
620
+				in_array(
621
+					$question->system_ID(),
622
+					EEM_Question::instance()->required_system_questions_in_system_question_group($question_group->system_group())
623
+				)
624
+				) {
625
+					continue;
626
+				} else {
627
+					$question_group->remove_question($question_ID);
628
+				}
629
+			}
630
+		}
631
+		// save new related questions
632
+		if (isset($this->_req_data['questions'])) {
633
+			foreach ($this->_req_data['questions'] as $QST_ID) {
634
+				$question_group->add_question($QST_ID);
635
+				if (isset($this->_req_data['question_orders'][$QST_ID])) {
636
+					$question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]);
637
+				}
638
+			}
639
+		}
640
+
641
+		if ($success !== false) {
642
+			$msg = $new_question_group ? sprintf(esc_html__('The %s has been created', 'event_espresso'),
643
+				$this->_question_group_model->item_name()) : sprintf(esc_html__('The %s has been updated',
644
+				'event_espresso'), $this->_question_group_model->item_name());
645
+			EE_Error::add_success($msg);
646
+		}
647
+		$this->_redirect_after_action(false, '', '', array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID),
648
+			true);
649
+
650
+	}
651
+
652
+	/**
653
+	 * duplicates a question and all its question options and redirects to the new question.
654
+	 */
655
+	public function _duplicate_question()
656
+	{
657
+		$question_ID = (int)$this->_req_data['QST_ID'];
658
+		$question    = EEM_Question::instance()->get_one_by_ID($question_ID);
659
+		if ($question instanceof EE_Question) {
660
+			$new_question = $question->duplicate();
661
+			if ($new_question instanceof EE_Question) {
662
+				$this->_redirect_after_action(true, esc_html__('Question', 'event_espresso'),
663
+					esc_html__('Duplicated', 'event_espresso'),
664
+					array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), true);
665
+			} else {
666
+				global $wpdb;
667
+				EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %1$d because: %2$s',
668
+					'event_espresso'), $question_ID, $wpdb->last_error), __FILE__, __FUNCTION__, __LINE__);
669
+				$this->_redirect_after_action(false, '', '', array('action' => 'default'), false);
670
+			}
671
+		} else {
672
+			EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %d because it didn\'t exist!',
673
+				'event_espresso'), $question_ID), __FILE__, __FUNCTION__, __LINE__);
674
+			$this->_redirect_after_action(false, '', '', array('action' => 'default'), false);
675
+		}
676
+	}
677
+
678
+
679
+	/**
680
+	 * @param bool $trash
681
+	 */
682
+	protected function _trash_or_restore_question_groups($trash = true)
683
+	{
684
+		$this->_trash_or_restore_items($this->_question_group_model, $trash);
685
+	}
686
+
687
+
688
+	/**
689
+	 *_trash_question
690
+	 */
691
+	protected function _trash_question()
692
+	{
693
+		$success    = $this->_question_model->delete_by_ID((int)$this->_req_data['QST_ID']);
694
+		$query_args = array('action' => 'default', 'status' => 'all');
695
+		$this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args);
696
+	}
697
+
698
+
699
+	/**
700
+	 * @param bool $trash
701
+	 */
702
+	protected function _trash_or_restore_questions($trash = true)
703
+	{
704
+		$this->_trash_or_restore_items($this->_question_model, $trash);
705
+	}
706
+
707
+
708
+	/**
709
+	 * Internally used to delete or restore items, using the request data. Meant to be
710
+	 * flexible between question or question groups
711
+	 *
712
+	 * @param EEM_Soft_Delete_Base $model
713
+	 * @param boolean              $trash whether to trash or restore
714
+	 */
715
+	private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true)
716
+	{
717
+
718
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
719
+
720
+		$success = 1;
721
+		//Checkboxes
722
+		//echo "trash $trash";
723
+		//var_dump($this->_req_data['checkbox']);die;
724
+		if (isset($this->_req_data['checkbox'])) {
725
+			if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
726
+				// if array has more than one element than success message should be plural
727
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
728
+				// cycle thru bulk action checkboxes
729
+				while (list($ID, $value) = each($this->_req_data['checkbox'])) {
730
+					if (! $model->delete_or_restore_by_ID($trash, absint($ID))) {
731
+						$success = 0;
732
+					}
733
+				}
734
+
735
+			} else {
736
+				// grab single id and delete
737
+				$ID = absint($this->_req_data['checkbox']);
738
+				if (! $model->delete_or_restore_by_ID($trash, $ID)) {
739
+					$success = 0;
740
+				}
741
+			}
742
+
743
+		} else {
744
+			// delete via trash link
745
+			// grab single id and delete
746
+			$ID = absint($this->_req_data[$model->primary_key_name()]);
747
+			if (! $model->delete_or_restore_by_ID($trash, $ID)) {
748
+				$success = 0;
749
+			}
750
+
751
+		}
752
+
753
+
754
+		$action = $model instanceof EEM_Question ? 'default' : 'question_groups';//strtolower( $model->item_name(2) );
755
+		//echo "action :$action";
756
+		//$action = 'questions' ? 'default' : $action;
757
+		if ($trash) {
758
+			$action_desc = 'trashed';
759
+			$status      = 'trash';
760
+		} else {
761
+			$action_desc = 'restored';
762
+			$status      = 'all';
763
+		}
764
+		$this->_redirect_after_action($success, $model->item_name($success), $action_desc,
765
+			array('action' => $action, 'status' => $status));
766
+	}
767
+
768
+
769
+	/**
770
+	 * @param            $per_page
771
+	 * @param int        $current_page
772
+	 * @param bool|false $count
773
+	 * @return \EE_Soft_Delete_Base_Class[]|int
774
+	 */
775
+	public function get_trashed_questions($per_page, $current_page = 1, $count = false)
776
+	{
777
+		$query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
778
+
779
+		if ($count) {
780
+			//note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
781
+			$where   = isset($query_params[0]) ? array($query_params[0]) : array();
782
+			$results = $this->_question_model->count_deleted($where);
783
+		} else {
784
+			//note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
785
+			$results = $this->_question_model->get_all_deleted($query_params);
786
+		}
787
+		return $results;
788
+	}
789
+
790
+
791
+	/**
792
+	 * @param            $per_page
793
+	 * @param int        $current_page
794
+	 * @param bool|false $count
795
+	 * @return \EE_Soft_Delete_Base_Class[]
796
+	 */
797
+	public function get_question_groups($per_page, $current_page = 1, $count = false)
798
+	{
799
+		$questionGroupModel = EEM_Question_Group::instance();
800
+		$query_params       = $this->get_query_params($questionGroupModel, $per_page, $current_page);
801
+		if ($count) {
802
+			$where   = isset($query_params[0]) ? array($query_params[0]) : array();
803
+			$results = $questionGroupModel->count($where);
804
+		} else {
805
+			$results = $questionGroupModel->get_all($query_params);
806
+		}
807
+		return $results;
808
+	}
809
+
810
+
811
+	/**
812
+	 * @param      $per_page
813
+	 * @param int  $current_page
814
+	 * @param bool $count
815
+	 * @return \EE_Soft_Delete_Base_Class[]|int
816
+	 */
817
+	public function get_trashed_question_groups($per_page, $current_page = 1, $count = false)
818
+	{
819
+		$questionGroupModel = EEM_Question_Group::instance();
820
+		$query_params       = $this->get_query_params($questionGroupModel, $per_page, $current_page);
821
+		if ($count) {
822
+			$where                 = isset($query_params[0]) ? array($query_params[0]) : array();
823
+			$query_params['limit'] = null;
824
+			$results               = $questionGroupModel->count_deleted($where);
825
+		} else {
826
+			$results = $questionGroupModel->get_all_deleted($query_params);
827
+		}
828
+		return $results;
829
+	}
830
+
831
+
832
+	/**
833
+	 * method for performing updates to question order
834
+	 *
835
+	 * @return array results array
836
+	 */
837
+	public function update_question_group_order()
838
+	{
839
+
840
+		$success = esc_html__('Question group order was updated successfully.', 'event_espresso');
841
+
842
+		// grab our row IDs
843
+		$row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids'])
844
+			? explode(',', rtrim($this->_req_data['row_ids'], ','))
845
+			: array();
846
+
847
+		$perpage = ! empty($this->_req_data['perpage'])
848
+			? (int)$this->_req_data['perpage']
849
+			: null;
850
+		$curpage = ! empty($this->_req_data['curpage'])
851
+			? (int)$this->_req_data['curpage']
852
+			: null;
853
+
854
+		if (! empty($row_ids)) {
855
+			//figure out where we start the row_id count at for the current page.
856
+			$qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage;
857
+
858
+			$row_count = count($row_ids);
859
+			for ($i = 0; $i < $row_count; $i++) {
860
+				//Update the questions when re-ordering
861
+				$updated = EEM_Question_Group::instance()->update(
862
+					array('QSG_order' => $qsgcount),
863
+					array(array('QSG_ID' => $row_ids[$i]))
864
+				);
865
+				if ($updated === false) {
866
+					$success = false;
867
+				}
868
+				$qsgcount++;
869
+			}
870
+		} else {
871
+			$success = false;
872
+		}
873
+
874
+		$errors = ! $success
875
+			? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso')
876
+			: false;
877
+
878
+		echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors));
879
+		die();
880
+
881
+	}
882
+
883
+
884
+
885
+	/***************************************        REGISTRATION SETTINGS        ***************************************/
886
+
887
+
888
+	/**
889
+	 * _reg_form_settings
890
+	 *
891
+	 * @throws \EE_Error
892
+	 */
893
+	protected function _reg_form_settings()
894
+	{
895
+		$this->_template_args['values'] = $this->_yes_no_values;
896
+		add_action(
897
+			'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
898
+			array($this, 'email_validation_settings_form'),
899
+			2
900
+		);
901
+		$this->_template_args = (array)apply_filters(
902
+			'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args',
903
+			$this->_template_args
904
+		);
905
+		$this->_set_add_edit_form_tags('update_reg_form_settings');
906
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
907
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
908
+			REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php',
909
+			$this->_template_args,
910
+			true
911
+		);
912
+		$this->display_admin_page_with_sidebar();
913
+	}
914
+
915
+
916
+	/**
917
+	 * _update_reg_form_settings
918
+	 */
919
+	protected function _update_reg_form_settings()
920
+	{
921
+		EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form(
922
+			EE_Registry::instance()->CFG->registration
923
+		);
924
+		EE_Registry::instance()->CFG->registration = apply_filters(
925
+			'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
926
+			EE_Registry::instance()->CFG->registration
927
+		);
928
+		$success                                   = $this->_update_espresso_configuration(
929
+			esc_html__('Registration Form Options', 'event_espresso'),
930
+			EE_Registry::instance()->CFG,
931
+			__FILE__, __FUNCTION__, __LINE__
932
+		);
933
+		$this->_redirect_after_action($success, esc_html__('Registration Form Options', 'event_espresso'), 'updated',
934
+			array('action' => 'view_reg_form_settings'));
935
+	}
936
+
937
+
938
+	/**
939
+	 * email_validation_settings_form
940
+	 *
941
+	 * @access    public
942
+	 * @return    void
943
+	 * @throws \EE_Error
944
+	 */
945
+	public function email_validation_settings_form()
946
+	{
947
+		echo $this->_email_validation_settings_form()->get_html();
948
+	}
949
+
950
+
951
+	/**
952
+	 * _email_validation_settings_form
953
+	 *
954
+	 * @access protected
955
+	 * @return EE_Form_Section_Proper
956
+	 * @throws \EE_Error
957
+	 */
958
+	protected function _email_validation_settings_form()
959
+	{
960
+		return new EE_Form_Section_Proper(
961
+			array(
962
+				'name'            => 'email_validation_settings',
963
+				'html_id'         => 'email_validation_settings',
964
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
965
+				'subsections'     => apply_filters(
966
+					'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections',
967
+					array(
968
+						'email_validation_hdr'   => new EE_Form_Section_HTML(
969
+							EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso'))
970
+						),
971
+						'email_validation_level' => new EE_Select_Input(
972
+							array(
973
+								'basic'      => esc_html__('Basic', 'event_espresso'),
974
+								'wp_default' => esc_html__('WordPress Default', 'event_espresso'),
975
+								'i18n'       => esc_html__('International', 'event_espresso'),
976
+								'i18n_dns'   => esc_html__('International + DNS Check', 'event_espresso'),
977
+							),
978
+							array(
979
+								'html_label_text' => esc_html__('Email Validation Level', 'event_espresso')
980
+													 . EEH_Template::get_help_tab_link('email_validation_info'),
981
+								'html_help_text'  => esc_html__('These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.',
982
+									'event_espresso'),
983
+								'default'         => isset(EE_Registry::instance()->CFG->registration->email_validation_level)
984
+									? EE_Registry::instance()->CFG->registration->email_validation_level
985
+									: 'wp_default',
986
+								'required'        => false,
987
+							)
988
+						),
989
+					)
990
+				),
991
+			)
992
+		);
993
+	}
994
+
995
+
996
+	/**
997
+	 * update_email_validation_settings_form
998
+	 *
999
+	 * @access    public
1000
+	 * @param \EE_Registration_Config $EE_Registration_Config
1001
+	 * @return \EE_Registration_Config
1002
+	 */
1003
+	public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config)
1004
+	{
1005
+		$prev_email_validation_level = $EE_Registration_Config->email_validation_level;
1006
+		try {
1007
+			$email_validation_settings_form = $this->_email_validation_settings_form();
1008
+			// if not displaying a form, then check for form submission
1009
+			if ($email_validation_settings_form->was_submitted()) {
1010
+				// capture form data
1011
+				$email_validation_settings_form->receive_form_submission();
1012
+				// validate form data
1013
+				if ($email_validation_settings_form->is_valid()) {
1014
+					// grab validated data from form
1015
+					$valid_data = $email_validation_settings_form->valid_data();
1016
+					if (isset($valid_data['email_validation_level'])) {
1017
+						$email_validation_level = $valid_data['email_validation_level'];
1018
+						// now if they want to use international email addresses
1019
+						if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') {
1020
+							// in case we need to reset their email validation level,
1021
+							// make sure that the previous value wasn't already set to one of the i18n options.
1022
+							if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') {
1023
+								// if so, then reset it back to "basic" since that is the only other option that,
1024
+								// despite offering poor validation, supports i18n email addresses
1025
+								$prev_email_validation_level = 'basic';
1026
+							}
1027
+							// confirm our i18n email validation will work on the server
1028
+							if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) {
1029
+								// or reset email validation level to previous value
1030
+								$email_validation_level = $prev_email_validation_level;
1031
+							}
1032
+						}
1033
+						$EE_Registration_Config->email_validation_level = $email_validation_level;
1034
+					} else {
1035
+						EE_Error::add_error(
1036
+							esc_html__(
1037
+								'Invalid or missing Email Validation settings. Please refresh the form and try again.',
1038
+								'event_espresso'
1039
+							),
1040
+							__FILE__, __FUNCTION__, __LINE__
1041
+						);
1042
+					}
1043
+				} else {
1044
+					if ($email_validation_settings_form->submission_error_message() !== '') {
1045
+						EE_Error::add_error(
1046
+							$email_validation_settings_form->submission_error_message(),
1047
+							__FILE__, __FUNCTION__, __LINE__
1048
+						);
1049
+					}
1050
+				}
1051
+			}
1052
+		} catch (EE_Error $e) {
1053
+			$e->get_error();
1054
+		}
1055
+		return $EE_Registration_Config;
1056
+	}
1057
+
1058
+
1059
+	/**
1060
+	 * confirms that the server's PHP version has the PCRE module enabled,
1061
+	 * and that the PCRE version works with our i18n email validation
1062
+	 *
1063
+	 * @param \EE_Registration_Config $EE_Registration_Config
1064
+	 * @param string                  $email_validation_level
1065
+	 * @return bool
1066
+	 */
1067
+	private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level)
1068
+	{
1069
+		// first check that PCRE is enabled
1070
+		if (! defined('PREG_BAD_UTF8_ERROR')) {
1071
+			EE_Error::add_error(
1072
+				sprintf(
1073
+					esc_html__(
1074
+						'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.',
1075
+						'event_espresso'
1076
+					),
1077
+					'<br />'
1078
+				),
1079
+				__FILE__,
1080
+				__FUNCTION__,
1081
+				__LINE__
1082
+			);
1083
+			return false;
1084
+		} else {
1085
+			// PCRE support is enabled, but let's still
1086
+			// perform a test to see if the server will support it.
1087
+			// but first, save the updated validation level to the config,
1088
+			// so that the validation strategy picks it up.
1089
+			// this will get bumped back down if it doesn't work
1090
+			$EE_Registration_Config->email_validation_level = $email_validation_level;
1091
+			try {
1092
+				$email_validator    = new EE_Email_Validation_Strategy();
1093
+				$i18n_email_address = apply_filters(
1094
+					'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address',
1095
+					'jägerjü[email protected]'
1096
+				);
1097
+				$email_validator->validate($i18n_email_address);
1098
+			} catch (Exception $e) {
1099
+				EE_Error::add_error(
1100
+					sprintf(
1101
+						esc_html__(
1102
+							'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s',
1103
+							'event_espresso'
1104
+						),
1105
+						'<br />',
1106
+						'<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>'
1107
+					),
1108
+					__FILE__, __FUNCTION__, __LINE__
1109
+				);
1110
+				return false;
1111
+			}
1112
+		}
1113
+		return true;
1114
+	}
1115 1115
 
1116 1116
 
1117 1117
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/Model_Data_Translator.php 2 patches
Indentation   +521 added lines, -521 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace EventEspresso\core\libraries\rest_api;
3 3
 
4 4
 if (! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -26,525 +26,525 @@  discard block
 block discarded – undo
26 26
 class Model_Data_Translator
27 27
 {
28 28
 
29
-    /**
30
-     * We used to use -1 for infinity in the rest api, but that's ambiguous for
31
-     * fields that COULD contain -1; so we use null
32
-     */
33
-    const ee_inf_in_rest = null;
34
-
35
-
36
-
37
-    /**
38
-     * Prepares a possible array of input values from JSON for use by the models
39
-     *
40
-     * @param \EE_Model_Field_Base $field_obj
41
-     * @param mixed                $original_value_maybe_array
42
-     * @param string               $requested_version
43
-     * @param string               $timezone_string treat values as being in this timezone
44
-     * @return mixed
45
-     * @throws \DomainException
46
-     */
47
-    public static function prepare_field_values_from_json(
48
-        $field_obj,
49
-        $original_value_maybe_array,
50
-        $requested_version,
51
-        $timezone_string = 'UTC'
52
-    ) {
53
-        if (is_array($original_value_maybe_array)) {
54
-            $new_value_maybe_array = array();
55
-            foreach ($original_value_maybe_array as $array_key => $array_item) {
56
-                $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json(
57
-                    $field_obj,
58
-                    $array_item,
59
-                    $requested_version,
60
-                    $timezone_string
61
-                );
62
-            }
63
-        } else {
64
-            $new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json(
65
-                $field_obj,
66
-                $original_value_maybe_array,
67
-                $requested_version,
68
-                $timezone_string
69
-            );
70
-        }
71
-        return $new_value_maybe_array;
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * Prepares an array of field values FOR use in JSON/REST API
78
-     *
79
-     * @param \EE_Model_Field_Base $field_obj
80
-     * @param mixed                $original_value_maybe_array
81
-     * @param string               $request_version (eg 4.8.36)
82
-     * @return array
83
-     */
84
-    public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version)
85
-    {
86
-        if (is_array($original_value_maybe_array)) {
87
-            $new_value_maybe_array = array();
88
-            foreach ($original_value_maybe_array as $array_key => $array_item) {
89
-                $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json(
90
-                    $field_obj,
91
-                    $array_item,
92
-                    $request_version
93
-                );
94
-            }
95
-        } else {
96
-            $new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json(
97
-                $field_obj,
98
-                $original_value_maybe_array,
99
-                $request_version
100
-            );
101
-        }
102
-        return $new_value_maybe_array;
103
-    }
104
-
105
-
106
-
107
-    /**
108
-     * Prepares incoming data from the json or $_REQUEST parameters for the models'
109
-     * "$query_params".
110
-     *
111
-     * @param \EE_Model_Field_Base $field_obj
112
-     * @param mixed                $original_value
113
-     * @param string               $requested_version
114
-     * @param string               $timezone_string treat values as being in this timezone
115
-     * @return mixed
116
-     * @throws \DomainException
117
-     */
118
-    public static function prepare_field_value_from_json(
119
-        $field_obj,
120
-        $original_value,
121
-        $requested_version,
122
-        $timezone_string = 'UTC' // UTC
123
-    )
124
-    {
125
-        $timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', '');
126
-        $new_value = null;
127
-        if ($field_obj instanceof \EE_Infinite_Integer_Field
128
-            && in_array($original_value, array(null, ''), true)
129
-        ) {
130
-            $new_value = EE_INF;
131
-        } elseif ($field_obj instanceof \EE_Datetime_Field) {
132
-            list($offset_sign, $offset_secs) = Model_Data_Translator::parse_timezone_offset(
133
-                $field_obj->get_timezone_offset(
134
-                    new \DateTimeZone($timezone_string)
135
-                )
136
-            );
137
-            $offset_string =
138
-                str_pad(
139
-                    floor($offset_secs / HOUR_IN_SECONDS),
140
-                    2,
141
-                    '0',
142
-                    STR_PAD_LEFT
143
-                )
144
-                . ':'
145
-                . str_pad(
146
-                    ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS,
147
-                    2,
148
-                    '0',
149
-                    STR_PAD_LEFT
150
-                );
151
-            $new_value = rest_parse_date($original_value . $offset_sign . $offset_string);
152
-        } else {
153
-            $new_value = $original_value;
154
-        }
155
-        return $new_value;
156
-    }
157
-
158
-
159
-
160
-    /**
161
-     * determines what's going on with them timezone strings
162
-     *
163
-     * @param int $timezone_offset
164
-     * @return array
165
-     */
166
-    private static function parse_timezone_offset($timezone_offset)
167
-    {
168
-        $first_char = substr((string)$timezone_offset, 0, 1);
169
-        if ($first_char === '+' || $first_char === '-') {
170
-            $offset_sign = $first_char;
171
-            $offset_secs = substr((string)$timezone_offset, 1);
172
-        } else {
173
-            $offset_sign = '+';
174
-            $offset_secs = $timezone_offset;
175
-        }
176
-        return array($offset_sign, $offset_secs);
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * Prepares a field's value for display in the API.
183
-     * The $original_value should be in the model object's domain of values, see the explanation at the top of EEM_Base.
184
-     * However, for backward compatibility, we also attempt to handle $original_values from the
185
-     * model client-code domain, and from the database domain.
186
-     * E.g., when working with EE_Datetime_Fields, $original_value should be a DateTime or DbSafeDateTime
187
-     * (model object domain). However, for backward compatibility, we also accept a unix timestamp
188
-     * (old model object domain), MySQL datetime string (database domain) or string formatted according to the
189
-     * WP Datetime format (model client-code domain)
190
-     *
191
-     * @param \EE_Model_Field_Base $field_obj
192
-     * @param mixed                $original_value
193
-     * @param string               $requested_version
194
-     * @return mixed
195
-     */
196
-    public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version)
197
-    {
198
-        if ($original_value === EE_INF) {
199
-            $new_value = Model_Data_Translator::ee_inf_in_rest;
200
-        } elseif ($field_obj instanceof \EE_Datetime_Field) {
201
-            if (is_string($original_value)) {
202
-                //did they submit a string of a unix timestamp?
203
-                if (is_numeric($original_value)) {
204
-                    $datetime_obj = new \DateTime();
205
-                    $datetime_obj->setTimestamp((int)$original_value);
206
-                } else {
207
-                    //first, check if its a MySQL timestamp in GMT
208
-                    $datetime_obj = \DateTime::createFromFormat('Y-m-d H:i:s', $original_value);
209
-                }
210
-                if (! $datetime_obj instanceof \DateTime) {
211
-                    //so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format?
212
-                    $datetime_obj = $field_obj->prepare_for_set($original_value);
213
-                }
214
-                $original_value = $datetime_obj;
215
-            }
216
-            if ($original_value instanceof \DateTime) {
217
-                $new_value = $original_value->format('Y-m-d H:i:s');
218
-            } elseif (is_int($original_value)) {
219
-                $new_value = date('Y-m-d H:i:s', $original_value);
220
-            } elseif($original_value === null || $original_value === '') {
221
-                $new_value = null;
222
-            } else {
223
-                //so it's not a datetime object, unix timestamp (as string or int),
224
-                //MySQL timestamp, or even a string in the field object's format. So no idea what it is
225
-                throw new \EE_Error(
226
-                    sprintf(
227
-                        esc_html__(
228
-                            // @codingStandardsIgnoreStart
229
-                            'The value "%1$s" for the field "%2$s" on model "%3$s" could not be understood. It should be a PHP DateTime, unix timestamp, MySQL date, or string in the format "%4$s".',
230
-                            // @codingStandardsIgnoreEnd
231
-                            'event_espressso'
232
-                        ),
233
-                        $original_value,
234
-                        $field_obj->get_name(),
235
-                        $field_obj->get_model_name(),
236
-                        $field_obj->get_time_format() . ' ' . $field_obj->get_time_format()
237
-                    )
238
-                );
239
-            }
240
-            $new_value = mysql_to_rfc3339($new_value);
241
-        } else {
242
-            $new_value = $original_value;
243
-        }
244
-        return apply_filters(
245
-            'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
246
-            $new_value,
247
-            $field_obj,
248
-            $original_value,
249
-            $requested_version
250
-        );
251
-    }
252
-
253
-
254
-
255
-    /**
256
-     * Prepares condition-query-parameters (like what's in where and having) from
257
-     * the format expected in the API to use in the models
258
-     *
259
-     * @param array     $inputted_query_params_of_this_type
260
-     * @param \EEM_Base $model
261
-     * @param string    $requested_version
262
-     * @return array
263
-     * @throws \DomainException
264
-     * @throws \EE_Error
265
-     */
266
-    public static function prepare_conditions_query_params_for_models(
267
-        $inputted_query_params_of_this_type,
268
-        \EEM_Base $model,
269
-        $requested_version
270
-    ) {
271
-        $query_param_for_models = array();
272
-        foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
273
-            $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key);
274
-            $field = Model_Data_Translator::deduce_field_from_query_param(
275
-                $query_param_sans_stars,
276
-                $model
277
-            );
278
-            //double-check is it a *_gmt field?
279
-            if (! $field instanceof \EE_Model_Field_Base
280
-                && Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars)
281
-            ) {
282
-                //yep, take off '_gmt', and find the field
283
-                $query_param_key = Model_Data_Translator::remove_gmt_from_field_name($query_param_sans_stars);
284
-                $field = Model_Data_Translator::deduce_field_from_query_param(
285
-                    $query_param_key,
286
-                    $model
287
-                );
288
-                $timezone = 'UTC';
289
-            } else {
290
-                //so it's not a GMT field. Set the timezone on the model to the default
291
-                $timezone = \EEH_DTT_Helper::get_valid_timezone_string();
292
-            }
293
-            if ($field instanceof \EE_Model_Field_Base) {
294
-                //did they specify an operator?
295
-                if (is_array($query_param_value)) {
296
-                    $op = $query_param_value[0];
297
-                    $translated_value = array($op);
298
-                    if (isset($query_param_value[1])) {
299
-                        $value = $query_param_value[1];
300
-                        $translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value,
301
-                            $requested_version, $timezone);
302
-                    }
303
-                } else {
304
-                    $translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value,
305
-                        $requested_version, $timezone);
306
-                }
307
-                $query_param_for_models[$query_param_key] = $translated_value;
308
-            } else {
309
-                //so it's not for a field, assume it's a logic query param key
310
-                $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value,
311
-                    $model, $requested_version);
312
-            }
313
-        }
314
-        return $query_param_for_models;
315
-    }
316
-
317
-
318
-
319
-    /**
320
-     * Mostly checks if the last 4 characters are "_gmt", indicating its a
321
-     * gmt date field name
322
-     *
323
-     * @param string $field_name
324
-     * @return boolean
325
-     */
326
-    public static function is_gmt_date_field_name($field_name)
327
-    {
328
-        return substr(
329
-                   Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name),
330
-                   -4,
331
-                   4
332
-               ) === '_gmt';
333
-    }
334
-
335
-
336
-
337
-    /**
338
-     * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone)
339
-     *
340
-     * @param string $field_name
341
-     * @return string
342
-     */
343
-    public static function remove_gmt_from_field_name($field_name)
344
-    {
345
-        if (! Model_Data_Translator::is_gmt_date_field_name($field_name)) {
346
-            return $field_name;
347
-        }
348
-        $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name);
349
-        $query_param_sans_gmt_and_sans_stars = substr(
350
-            $query_param_sans_stars,
351
-            0,
352
-            strrpos(
353
-                $field_name,
354
-                '_gmt'
355
-            )
356
-        );
357
-        return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name);
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * Takes a field name from the REST API and prepares it for the model querying
364
-     *
365
-     * @param string $field_name
366
-     * @return string
367
-     */
368
-    public static function prepare_field_name_from_json($field_name)
369
-    {
370
-        if (Model_Data_Translator::is_gmt_date_field_name($field_name)) {
371
-            return Model_Data_Translator::remove_gmt_from_field_name($field_name);
372
-        }
373
-        return $field_name;
374
-    }
375
-
376
-
377
-
378
-    /**
379
-     * Takes array of field names from REST API and prepares for models
380
-     *
381
-     * @param array $field_names
382
-     * @return array of field names (possibly include model prefixes)
383
-     */
384
-    public static function prepare_field_names_from_json(array $field_names)
385
-    {
386
-        $new_array = array();
387
-        foreach ($field_names as $key => $field_name) {
388
-            $new_array[$key] = Model_Data_Translator::prepare_field_name_from_json($field_name);
389
-        }
390
-        return $new_array;
391
-    }
392
-
393
-
394
-
395
-    /**
396
-     * Takes array where array keys are field names (possibly with model path prefixes)
397
-     * from the REST API and prepares them for model querying
398
-     *
399
-     * @param array $field_names_as_keys
400
-     * @return array
401
-     */
402
-    public static function prepare_field_names_in_array_keys_from_json(array $field_names_as_keys)
403
-    {
404
-        $new_array = array();
405
-        foreach ($field_names_as_keys as $field_name => $value) {
406
-            $new_array[Model_Data_Translator::prepare_field_name_from_json($field_name)] = $value;
407
-        }
408
-        return $new_array;
409
-    }
410
-
411
-
412
-
413
-    /**
414
-     * Prepares an array of model query params for use in the REST API
415
-     *
416
-     * @param array     $model_query_params
417
-     * @param \EEM_Base $model
418
-     * @param string    $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4
419
-     *                                     REST API
420
-     * @return array which can be passed into the EE4 REST API when querying a model resource
421
-     * @throws \EE_Error
422
-     */
423
-    public static function prepare_query_params_for_rest_api(
424
-        array $model_query_params,
425
-        \EEM_Base $model,
426
-        $requested_version = null
427
-    ) {
428
-        if ($requested_version === null) {
429
-            $requested_version = \EED_Core_Rest_Api::latest_rest_api_version();
430
-        }
431
-        $rest_query_params = $model_query_params;
432
-        if (isset($model_query_params[0])) {
433
-            $rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api(
434
-                $model_query_params[0],
435
-                $model,
436
-                $requested_version
437
-            );
438
-            unset($rest_query_params[0]);
439
-        }
440
-        if (isset($model_query_params['having'])) {
441
-            $rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api(
442
-                $model_query_params['having'],
443
-                $model,
444
-                $requested_version
445
-            );
446
-        }
447
-        return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api',
448
-            $rest_query_params, $model_query_params, $model, $requested_version);
449
-    }
450
-
451
-
452
-
453
-    /**
454
-     * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api
455
-     *
456
-     * @param array     $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params
457
-     *                                                      passed into EEM_Base::get_all()
458
-     * @param \EEM_Base $model
459
-     * @param string    $requested_version                  eg "4.8.36"
460
-     * @return array ready for use in the rest api query params
461
-     * @throws \EE_Error
462
-     */
463
-    public static function prepare_conditions_query_params_for_rest_api(
464
-        $inputted_query_params_of_this_type,
465
-        \EEM_Base $model,
466
-        $requested_version
467
-    ) {
468
-        $query_param_for_models = array();
469
-        foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
470
-            $field = Model_Data_Translator::deduce_field_from_query_param(
471
-                Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key),
472
-                $model
473
-            );
474
-            if ($field instanceof \EE_Model_Field_Base) {
475
-                //did they specify an operator?
476
-                if (is_array($query_param_value)) {
477
-                    $op = $query_param_value[0];
478
-                    $translated_value = array($op);
479
-                    if (isset($query_param_value[1])) {
480
-                        $value = $query_param_value[1];
481
-                        $translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value,
482
-                            $requested_version);
483
-                    }
484
-                } else {
485
-                    $translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value,
486
-                        $requested_version);
487
-                }
488
-                $query_param_for_models[$query_param_key] = $translated_value;
489
-            } else {
490
-                //so it's not for a field, assume it's a logic query param key
491
-                $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value,
492
-                    $model, $requested_version);
493
-            }
494
-        }
495
-        return $query_param_for_models;
496
-    }
497
-
498
-
499
-
500
-    /**
501
-     * @param $condition_query_param_key
502
-     * @return string
503
-     */
504
-    public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key)
505
-    {
506
-        $pos_of_star = strpos($condition_query_param_key, '*');
507
-        if ($pos_of_star === false) {
508
-            return $condition_query_param_key;
509
-        } else {
510
-            $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
511
-            return $condition_query_param_sans_star;
512
-        }
513
-    }
514
-
515
-
516
-
517
-    /**
518
-     * Takes the input parameter and finds the model field that it indicates.
519
-     *
520
-     * @param string    $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID
521
-     * @param \EEM_Base $model
522
-     * @return \EE_Model_Field_Base
523
-     * @throws \EE_Error
524
-     */
525
-    public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model)
526
-    {
527
-        //ok, now proceed with deducing which part is the model's name, and which is the field's name
528
-        //which will help us find the database table and column
529
-        $query_param_parts = explode('.', $query_param_name);
530
-        if (empty($query_param_parts)) {
531
-            throw new \EE_Error(sprintf(__('_extract_column_name is empty when trying to extract column and table name from %s',
532
-                'event_espresso'), $query_param_name));
533
-        }
534
-        $number_of_parts = count($query_param_parts);
535
-        $last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
536
-        if ($number_of_parts === 1) {
537
-            $field_name = $last_query_param_part;
538
-        } else {// $number_of_parts >= 2
539
-            //the last part is the column name, and there are only 2parts. therefore...
540
-            $field_name = $last_query_param_part;
541
-            $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]);
542
-        }
543
-        try {
544
-            return $model->field_settings_for($field_name);
545
-        } catch (\EE_Error $e) {
546
-            return null;
547
-        }
548
-    }
29
+	/**
30
+	 * We used to use -1 for infinity in the rest api, but that's ambiguous for
31
+	 * fields that COULD contain -1; so we use null
32
+	 */
33
+	const ee_inf_in_rest = null;
34
+
35
+
36
+
37
+	/**
38
+	 * Prepares a possible array of input values from JSON for use by the models
39
+	 *
40
+	 * @param \EE_Model_Field_Base $field_obj
41
+	 * @param mixed                $original_value_maybe_array
42
+	 * @param string               $requested_version
43
+	 * @param string               $timezone_string treat values as being in this timezone
44
+	 * @return mixed
45
+	 * @throws \DomainException
46
+	 */
47
+	public static function prepare_field_values_from_json(
48
+		$field_obj,
49
+		$original_value_maybe_array,
50
+		$requested_version,
51
+		$timezone_string = 'UTC'
52
+	) {
53
+		if (is_array($original_value_maybe_array)) {
54
+			$new_value_maybe_array = array();
55
+			foreach ($original_value_maybe_array as $array_key => $array_item) {
56
+				$new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json(
57
+					$field_obj,
58
+					$array_item,
59
+					$requested_version,
60
+					$timezone_string
61
+				);
62
+			}
63
+		} else {
64
+			$new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json(
65
+				$field_obj,
66
+				$original_value_maybe_array,
67
+				$requested_version,
68
+				$timezone_string
69
+			);
70
+		}
71
+		return $new_value_maybe_array;
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * Prepares an array of field values FOR use in JSON/REST API
78
+	 *
79
+	 * @param \EE_Model_Field_Base $field_obj
80
+	 * @param mixed                $original_value_maybe_array
81
+	 * @param string               $request_version (eg 4.8.36)
82
+	 * @return array
83
+	 */
84
+	public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version)
85
+	{
86
+		if (is_array($original_value_maybe_array)) {
87
+			$new_value_maybe_array = array();
88
+			foreach ($original_value_maybe_array as $array_key => $array_item) {
89
+				$new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json(
90
+					$field_obj,
91
+					$array_item,
92
+					$request_version
93
+				);
94
+			}
95
+		} else {
96
+			$new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json(
97
+				$field_obj,
98
+				$original_value_maybe_array,
99
+				$request_version
100
+			);
101
+		}
102
+		return $new_value_maybe_array;
103
+	}
104
+
105
+
106
+
107
+	/**
108
+	 * Prepares incoming data from the json or $_REQUEST parameters for the models'
109
+	 * "$query_params".
110
+	 *
111
+	 * @param \EE_Model_Field_Base $field_obj
112
+	 * @param mixed                $original_value
113
+	 * @param string               $requested_version
114
+	 * @param string               $timezone_string treat values as being in this timezone
115
+	 * @return mixed
116
+	 * @throws \DomainException
117
+	 */
118
+	public static function prepare_field_value_from_json(
119
+		$field_obj,
120
+		$original_value,
121
+		$requested_version,
122
+		$timezone_string = 'UTC' // UTC
123
+	)
124
+	{
125
+		$timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', '');
126
+		$new_value = null;
127
+		if ($field_obj instanceof \EE_Infinite_Integer_Field
128
+			&& in_array($original_value, array(null, ''), true)
129
+		) {
130
+			$new_value = EE_INF;
131
+		} elseif ($field_obj instanceof \EE_Datetime_Field) {
132
+			list($offset_sign, $offset_secs) = Model_Data_Translator::parse_timezone_offset(
133
+				$field_obj->get_timezone_offset(
134
+					new \DateTimeZone($timezone_string)
135
+				)
136
+			);
137
+			$offset_string =
138
+				str_pad(
139
+					floor($offset_secs / HOUR_IN_SECONDS),
140
+					2,
141
+					'0',
142
+					STR_PAD_LEFT
143
+				)
144
+				. ':'
145
+				. str_pad(
146
+					($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS,
147
+					2,
148
+					'0',
149
+					STR_PAD_LEFT
150
+				);
151
+			$new_value = rest_parse_date($original_value . $offset_sign . $offset_string);
152
+		} else {
153
+			$new_value = $original_value;
154
+		}
155
+		return $new_value;
156
+	}
157
+
158
+
159
+
160
+	/**
161
+	 * determines what's going on with them timezone strings
162
+	 *
163
+	 * @param int $timezone_offset
164
+	 * @return array
165
+	 */
166
+	private static function parse_timezone_offset($timezone_offset)
167
+	{
168
+		$first_char = substr((string)$timezone_offset, 0, 1);
169
+		if ($first_char === '+' || $first_char === '-') {
170
+			$offset_sign = $first_char;
171
+			$offset_secs = substr((string)$timezone_offset, 1);
172
+		} else {
173
+			$offset_sign = '+';
174
+			$offset_secs = $timezone_offset;
175
+		}
176
+		return array($offset_sign, $offset_secs);
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * Prepares a field's value for display in the API.
183
+	 * The $original_value should be in the model object's domain of values, see the explanation at the top of EEM_Base.
184
+	 * However, for backward compatibility, we also attempt to handle $original_values from the
185
+	 * model client-code domain, and from the database domain.
186
+	 * E.g., when working with EE_Datetime_Fields, $original_value should be a DateTime or DbSafeDateTime
187
+	 * (model object domain). However, for backward compatibility, we also accept a unix timestamp
188
+	 * (old model object domain), MySQL datetime string (database domain) or string formatted according to the
189
+	 * WP Datetime format (model client-code domain)
190
+	 *
191
+	 * @param \EE_Model_Field_Base $field_obj
192
+	 * @param mixed                $original_value
193
+	 * @param string               $requested_version
194
+	 * @return mixed
195
+	 */
196
+	public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version)
197
+	{
198
+		if ($original_value === EE_INF) {
199
+			$new_value = Model_Data_Translator::ee_inf_in_rest;
200
+		} elseif ($field_obj instanceof \EE_Datetime_Field) {
201
+			if (is_string($original_value)) {
202
+				//did they submit a string of a unix timestamp?
203
+				if (is_numeric($original_value)) {
204
+					$datetime_obj = new \DateTime();
205
+					$datetime_obj->setTimestamp((int)$original_value);
206
+				} else {
207
+					//first, check if its a MySQL timestamp in GMT
208
+					$datetime_obj = \DateTime::createFromFormat('Y-m-d H:i:s', $original_value);
209
+				}
210
+				if (! $datetime_obj instanceof \DateTime) {
211
+					//so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format?
212
+					$datetime_obj = $field_obj->prepare_for_set($original_value);
213
+				}
214
+				$original_value = $datetime_obj;
215
+			}
216
+			if ($original_value instanceof \DateTime) {
217
+				$new_value = $original_value->format('Y-m-d H:i:s');
218
+			} elseif (is_int($original_value)) {
219
+				$new_value = date('Y-m-d H:i:s', $original_value);
220
+			} elseif($original_value === null || $original_value === '') {
221
+				$new_value = null;
222
+			} else {
223
+				//so it's not a datetime object, unix timestamp (as string or int),
224
+				//MySQL timestamp, or even a string in the field object's format. So no idea what it is
225
+				throw new \EE_Error(
226
+					sprintf(
227
+						esc_html__(
228
+							// @codingStandardsIgnoreStart
229
+							'The value "%1$s" for the field "%2$s" on model "%3$s" could not be understood. It should be a PHP DateTime, unix timestamp, MySQL date, or string in the format "%4$s".',
230
+							// @codingStandardsIgnoreEnd
231
+							'event_espressso'
232
+						),
233
+						$original_value,
234
+						$field_obj->get_name(),
235
+						$field_obj->get_model_name(),
236
+						$field_obj->get_time_format() . ' ' . $field_obj->get_time_format()
237
+					)
238
+				);
239
+			}
240
+			$new_value = mysql_to_rfc3339($new_value);
241
+		} else {
242
+			$new_value = $original_value;
243
+		}
244
+		return apply_filters(
245
+			'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
246
+			$new_value,
247
+			$field_obj,
248
+			$original_value,
249
+			$requested_version
250
+		);
251
+	}
252
+
253
+
254
+
255
+	/**
256
+	 * Prepares condition-query-parameters (like what's in where and having) from
257
+	 * the format expected in the API to use in the models
258
+	 *
259
+	 * @param array     $inputted_query_params_of_this_type
260
+	 * @param \EEM_Base $model
261
+	 * @param string    $requested_version
262
+	 * @return array
263
+	 * @throws \DomainException
264
+	 * @throws \EE_Error
265
+	 */
266
+	public static function prepare_conditions_query_params_for_models(
267
+		$inputted_query_params_of_this_type,
268
+		\EEM_Base $model,
269
+		$requested_version
270
+	) {
271
+		$query_param_for_models = array();
272
+		foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
273
+			$query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key);
274
+			$field = Model_Data_Translator::deduce_field_from_query_param(
275
+				$query_param_sans_stars,
276
+				$model
277
+			);
278
+			//double-check is it a *_gmt field?
279
+			if (! $field instanceof \EE_Model_Field_Base
280
+				&& Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars)
281
+			) {
282
+				//yep, take off '_gmt', and find the field
283
+				$query_param_key = Model_Data_Translator::remove_gmt_from_field_name($query_param_sans_stars);
284
+				$field = Model_Data_Translator::deduce_field_from_query_param(
285
+					$query_param_key,
286
+					$model
287
+				);
288
+				$timezone = 'UTC';
289
+			} else {
290
+				//so it's not a GMT field. Set the timezone on the model to the default
291
+				$timezone = \EEH_DTT_Helper::get_valid_timezone_string();
292
+			}
293
+			if ($field instanceof \EE_Model_Field_Base) {
294
+				//did they specify an operator?
295
+				if (is_array($query_param_value)) {
296
+					$op = $query_param_value[0];
297
+					$translated_value = array($op);
298
+					if (isset($query_param_value[1])) {
299
+						$value = $query_param_value[1];
300
+						$translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value,
301
+							$requested_version, $timezone);
302
+					}
303
+				} else {
304
+					$translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value,
305
+						$requested_version, $timezone);
306
+				}
307
+				$query_param_for_models[$query_param_key] = $translated_value;
308
+			} else {
309
+				//so it's not for a field, assume it's a logic query param key
310
+				$query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value,
311
+					$model, $requested_version);
312
+			}
313
+		}
314
+		return $query_param_for_models;
315
+	}
316
+
317
+
318
+
319
+	/**
320
+	 * Mostly checks if the last 4 characters are "_gmt", indicating its a
321
+	 * gmt date field name
322
+	 *
323
+	 * @param string $field_name
324
+	 * @return boolean
325
+	 */
326
+	public static function is_gmt_date_field_name($field_name)
327
+	{
328
+		return substr(
329
+				   Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name),
330
+				   -4,
331
+				   4
332
+			   ) === '_gmt';
333
+	}
334
+
335
+
336
+
337
+	/**
338
+	 * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone)
339
+	 *
340
+	 * @param string $field_name
341
+	 * @return string
342
+	 */
343
+	public static function remove_gmt_from_field_name($field_name)
344
+	{
345
+		if (! Model_Data_Translator::is_gmt_date_field_name($field_name)) {
346
+			return $field_name;
347
+		}
348
+		$query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name);
349
+		$query_param_sans_gmt_and_sans_stars = substr(
350
+			$query_param_sans_stars,
351
+			0,
352
+			strrpos(
353
+				$field_name,
354
+				'_gmt'
355
+			)
356
+		);
357
+		return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name);
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * Takes a field name from the REST API and prepares it for the model querying
364
+	 *
365
+	 * @param string $field_name
366
+	 * @return string
367
+	 */
368
+	public static function prepare_field_name_from_json($field_name)
369
+	{
370
+		if (Model_Data_Translator::is_gmt_date_field_name($field_name)) {
371
+			return Model_Data_Translator::remove_gmt_from_field_name($field_name);
372
+		}
373
+		return $field_name;
374
+	}
375
+
376
+
377
+
378
+	/**
379
+	 * Takes array of field names from REST API and prepares for models
380
+	 *
381
+	 * @param array $field_names
382
+	 * @return array of field names (possibly include model prefixes)
383
+	 */
384
+	public static function prepare_field_names_from_json(array $field_names)
385
+	{
386
+		$new_array = array();
387
+		foreach ($field_names as $key => $field_name) {
388
+			$new_array[$key] = Model_Data_Translator::prepare_field_name_from_json($field_name);
389
+		}
390
+		return $new_array;
391
+	}
392
+
393
+
394
+
395
+	/**
396
+	 * Takes array where array keys are field names (possibly with model path prefixes)
397
+	 * from the REST API and prepares them for model querying
398
+	 *
399
+	 * @param array $field_names_as_keys
400
+	 * @return array
401
+	 */
402
+	public static function prepare_field_names_in_array_keys_from_json(array $field_names_as_keys)
403
+	{
404
+		$new_array = array();
405
+		foreach ($field_names_as_keys as $field_name => $value) {
406
+			$new_array[Model_Data_Translator::prepare_field_name_from_json($field_name)] = $value;
407
+		}
408
+		return $new_array;
409
+	}
410
+
411
+
412
+
413
+	/**
414
+	 * Prepares an array of model query params for use in the REST API
415
+	 *
416
+	 * @param array     $model_query_params
417
+	 * @param \EEM_Base $model
418
+	 * @param string    $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4
419
+	 *                                     REST API
420
+	 * @return array which can be passed into the EE4 REST API when querying a model resource
421
+	 * @throws \EE_Error
422
+	 */
423
+	public static function prepare_query_params_for_rest_api(
424
+		array $model_query_params,
425
+		\EEM_Base $model,
426
+		$requested_version = null
427
+	) {
428
+		if ($requested_version === null) {
429
+			$requested_version = \EED_Core_Rest_Api::latest_rest_api_version();
430
+		}
431
+		$rest_query_params = $model_query_params;
432
+		if (isset($model_query_params[0])) {
433
+			$rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api(
434
+				$model_query_params[0],
435
+				$model,
436
+				$requested_version
437
+			);
438
+			unset($rest_query_params[0]);
439
+		}
440
+		if (isset($model_query_params['having'])) {
441
+			$rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api(
442
+				$model_query_params['having'],
443
+				$model,
444
+				$requested_version
445
+			);
446
+		}
447
+		return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api',
448
+			$rest_query_params, $model_query_params, $model, $requested_version);
449
+	}
450
+
451
+
452
+
453
+	/**
454
+	 * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api
455
+	 *
456
+	 * @param array     $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params
457
+	 *                                                      passed into EEM_Base::get_all()
458
+	 * @param \EEM_Base $model
459
+	 * @param string    $requested_version                  eg "4.8.36"
460
+	 * @return array ready for use in the rest api query params
461
+	 * @throws \EE_Error
462
+	 */
463
+	public static function prepare_conditions_query_params_for_rest_api(
464
+		$inputted_query_params_of_this_type,
465
+		\EEM_Base $model,
466
+		$requested_version
467
+	) {
468
+		$query_param_for_models = array();
469
+		foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
470
+			$field = Model_Data_Translator::deduce_field_from_query_param(
471
+				Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key),
472
+				$model
473
+			);
474
+			if ($field instanceof \EE_Model_Field_Base) {
475
+				//did they specify an operator?
476
+				if (is_array($query_param_value)) {
477
+					$op = $query_param_value[0];
478
+					$translated_value = array($op);
479
+					if (isset($query_param_value[1])) {
480
+						$value = $query_param_value[1];
481
+						$translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value,
482
+							$requested_version);
483
+					}
484
+				} else {
485
+					$translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value,
486
+						$requested_version);
487
+				}
488
+				$query_param_for_models[$query_param_key] = $translated_value;
489
+			} else {
490
+				//so it's not for a field, assume it's a logic query param key
491
+				$query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value,
492
+					$model, $requested_version);
493
+			}
494
+		}
495
+		return $query_param_for_models;
496
+	}
497
+
498
+
499
+
500
+	/**
501
+	 * @param $condition_query_param_key
502
+	 * @return string
503
+	 */
504
+	public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key)
505
+	{
506
+		$pos_of_star = strpos($condition_query_param_key, '*');
507
+		if ($pos_of_star === false) {
508
+			return $condition_query_param_key;
509
+		} else {
510
+			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
511
+			return $condition_query_param_sans_star;
512
+		}
513
+	}
514
+
515
+
516
+
517
+	/**
518
+	 * Takes the input parameter and finds the model field that it indicates.
519
+	 *
520
+	 * @param string    $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID
521
+	 * @param \EEM_Base $model
522
+	 * @return \EE_Model_Field_Base
523
+	 * @throws \EE_Error
524
+	 */
525
+	public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model)
526
+	{
527
+		//ok, now proceed with deducing which part is the model's name, and which is the field's name
528
+		//which will help us find the database table and column
529
+		$query_param_parts = explode('.', $query_param_name);
530
+		if (empty($query_param_parts)) {
531
+			throw new \EE_Error(sprintf(__('_extract_column_name is empty when trying to extract column and table name from %s',
532
+				'event_espresso'), $query_param_name));
533
+		}
534
+		$number_of_parts = count($query_param_parts);
535
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
536
+		if ($number_of_parts === 1) {
537
+			$field_name = $last_query_param_part;
538
+		} else {// $number_of_parts >= 2
539
+			//the last part is the column name, and there are only 2parts. therefore...
540
+			$field_name = $last_query_param_part;
541
+			$model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]);
542
+		}
543
+		try {
544
+			return $model->field_settings_for($field_name);
545
+		} catch (\EE_Error $e) {
546
+			return null;
547
+		}
548
+	}
549 549
 
550 550
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\libraries\rest_api;
3 3
 
4
-if (! defined('EVENT_ESPRESSO_VERSION')) {
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5 5
     exit('No direct script access allowed');
6 6
 }
7 7
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
                     '0',
149 149
                     STR_PAD_LEFT
150 150
                 );
151
-            $new_value = rest_parse_date($original_value . $offset_sign . $offset_string);
151
+            $new_value = rest_parse_date($original_value.$offset_sign.$offset_string);
152 152
         } else {
153 153
             $new_value = $original_value;
154 154
         }
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
      */
166 166
     private static function parse_timezone_offset($timezone_offset)
167 167
     {
168
-        $first_char = substr((string)$timezone_offset, 0, 1);
168
+        $first_char = substr((string) $timezone_offset, 0, 1);
169 169
         if ($first_char === '+' || $first_char === '-') {
170 170
             $offset_sign = $first_char;
171
-            $offset_secs = substr((string)$timezone_offset, 1);
171
+            $offset_secs = substr((string) $timezone_offset, 1);
172 172
         } else {
173 173
             $offset_sign = '+';
174 174
             $offset_secs = $timezone_offset;
@@ -202,12 +202,12 @@  discard block
 block discarded – undo
202 202
                 //did they submit a string of a unix timestamp?
203 203
                 if (is_numeric($original_value)) {
204 204
                     $datetime_obj = new \DateTime();
205
-                    $datetime_obj->setTimestamp((int)$original_value);
205
+                    $datetime_obj->setTimestamp((int) $original_value);
206 206
                 } else {
207 207
                     //first, check if its a MySQL timestamp in GMT
208 208
                     $datetime_obj = \DateTime::createFromFormat('Y-m-d H:i:s', $original_value);
209 209
                 }
210
-                if (! $datetime_obj instanceof \DateTime) {
210
+                if ( ! $datetime_obj instanceof \DateTime) {
211 211
                     //so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format?
212 212
                     $datetime_obj = $field_obj->prepare_for_set($original_value);
213 213
                 }
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
                 $new_value = $original_value->format('Y-m-d H:i:s');
218 218
             } elseif (is_int($original_value)) {
219 219
                 $new_value = date('Y-m-d H:i:s', $original_value);
220
-            } elseif($original_value === null || $original_value === '') {
220
+            } elseif ($original_value === null || $original_value === '') {
221 221
                 $new_value = null;
222 222
             } else {
223 223
                 //so it's not a datetime object, unix timestamp (as string or int),
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
                         $original_value,
234 234
                         $field_obj->get_name(),
235 235
                         $field_obj->get_model_name(),
236
-                        $field_obj->get_time_format() . ' ' . $field_obj->get_time_format()
236
+                        $field_obj->get_time_format().' '.$field_obj->get_time_format()
237 237
                     )
238 238
                 );
239 239
             }
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
                 $model
277 277
             );
278 278
             //double-check is it a *_gmt field?
279
-            if (! $field instanceof \EE_Model_Field_Base
279
+            if ( ! $field instanceof \EE_Model_Field_Base
280 280
                 && Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars)
281 281
             ) {
282 282
                 //yep, take off '_gmt', and find the field
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
      */
343 343
     public static function remove_gmt_from_field_name($field_name)
344 344
     {
345
-        if (! Model_Data_Translator::is_gmt_date_field_name($field_name)) {
345
+        if ( ! Model_Data_Translator::is_gmt_date_field_name($field_name)) {
346 346
             return $field_name;
347 347
         }
348 348
         $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name);
Please login to merge, or discard this patch.