Completed
Branch dev (6c2f79)
by
unknown
21:10 queued 18:58
created
admin/extend/messages/espresso_events_Messages_Hooks_Extend.class.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      */
64 64
     protected function _extend_properties()
65 65
     {
66
-        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
66
+        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'messages/assets/');
67 67
         $this->_ajax_func = ['ee_msgs_create_new_custom' => 'create_new_custom'];
68 68
         $this->_metaboxes = [
69 69
             0 => [
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
         $this->_scripts_styles = [
79 79
             'registers' => [
80 80
                 'events_msg_admin'     => [
81
-                    'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
81
+                    'url'     => EE_MSGS_EXTEND_ASSETS_URL.'events_messages_admin.js',
82 82
                     'depends' => ['ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'],
83 83
                 ],
84 84
                 'events_msg_admin_css' => [
85
-                    'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
85
+                    'url'  => EE_MSGS_EXTEND_ASSETS_URL.'ee_msg_events_admin.css',
86 86
                     'type' => 'css',
87 87
                 ],
88 88
             ],
@@ -154,18 +154,18 @@  discard block
 block discarded – undo
154 154
                 ['action' => 'settings'],
155 155
                 EE_MSG_ADMIN_URL
156 156
             );
157
-            $error_msg        = sprintf(
157
+            $error_msg = sprintf(
158 158
                 esc_html__(
159 159
                     'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
160 160
                     'event_espresso'
161 161
                 ),
162 162
                 '<strong>',
163 163
                 '</strong>',
164
-                '<a href="' . $msg_activate_url . '">',
164
+                '<a href="'.$msg_activate_url.'">',
165 165
                 '</a>'
166 166
             );
167
-            $error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
168
-            $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
167
+            $error_content    = '<div class="error"><p>'.$error_msg.'</p></div>';
168
+            $internal_content = '<div id="messages-error"><p>'.$error_msg.'</p></div>';
169 169
 
170 170
             echo $error_content;
171 171
             echo $internal_content;
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
                 ['event' => $EVT_ID]
187 187
             );
188 188
 
189
-            if (! empty($tab_content)) {
190
-                $tabs[ $name ] = $tab_content;
189
+            if ( ! empty($tab_content)) {
190
+                $tabs[$name] = $tab_content;
191 191
             }
192 192
         }
193 193
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
         $notices = '
202 202
 	<div id="espresso-ajax-loading" class="ajax-loader-grey">
203 203
 		<span class="ee-spinner ee-spin"></span>
204
-		<span class="hidden">' . esc_html__('loading...', 'event_espresso') . '</span>
204
+		<span class="hidden">' . esc_html__('loading...', 'event_espresso').'</span>
205 205
 	</div>
206 206
 	<div class="ee-notices"></div>';
207 207
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         }
211 211
 
212 212
         do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
213
-        echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
213
+        echo $notices.'<div class="messages-tabs-content">'.$tabbed_content.'</div>';
214 214
         do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
215 215
         return '';
216 216
     }
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
      */
228 228
     public function create_new_custom()
229 229
     {
230
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
230
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
231 231
             wp_die(esc_html__('You don\'t have privileges to do this action', 'event_espresso'));
232 232
         }
233 233
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
     public function edit_admin_footer()
271 271
     {
272 272
         EEH_Template::display_template(
273
-            EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
273
+            EE_CORE_CAF_ADMIN_EXTEND.'messages/templates/create_custom_template_form.template.php'
274 274
         );
275 275
     }
276 276
 
Please login to merge, or discard this patch.
Indentation   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -15,294 +15,294 @@
 block discarded – undo
15 15
 class espresso_events_Messages_Hooks_Extend extends espresso_events_Messages_Hooks
16 16
 {
17 17
 
18
-    /**
19
-     * @var Messages_Admin_Page
20
-     */
21
-    protected $_page_object;
22
-
23
-
24
-    /**
25
-     * espresso_events_Messages_Hooks_Extend constructor.
26
-     *
27
-     * @param EE_Admin_Page $admin_page
28
-     * @throws EE_Error
29
-     */
30
-    public function __construct(EE_Admin_Page $admin_page)
31
-    {
32
-        /**
33
-         * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
34
-         */
35
-        if (
36
-            ! EE_Registry::instance()->CAP->current_user_can(
37
-                'ee_edit_messages',
38
-                'messages_events_editor_metabox'
39
-            )
40
-        ) {
41
-            return;
42
-        }
43
-        add_filter(
44
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
45
-            [$this, 'caf_updates'],
46
-            10
47
-        );
48
-        add_action(
49
-            'AHEE__Extend_Events_Admin_Page___duplicate_event__after',
50
-            [$this, 'duplicate_custom_message_settings'],
51
-            10,
52
-            2
53
-        );
54
-        parent::__construct($admin_page);
55
-    }
56
-
57
-
58
-    /**
59
-     * extending the properties set in espresso_events_Messages_Hooks
60
-     *
61
-     * @access protected
62
-     * @return void
63
-     */
64
-    protected function _extend_properties()
65
-    {
66
-        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
67
-        $this->_ajax_func = ['ee_msgs_create_new_custom' => 'create_new_custom'];
68
-        $this->_metaboxes = [
69
-            0 => [
70
-                'page_route' => ['edit', 'create_new'],
71
-                'func'       => 'messages_metabox',
72
-                'label'      => esc_html__('Notifications', 'event_espresso'),
73
-                'priority'   => 'high',
74
-            ],
75
-        ];
76
-
77
-        // see explanation for layout in EE_Admin_Hooks
78
-        $this->_scripts_styles = [
79
-            'registers' => [
80
-                'events_msg_admin'     => [
81
-                    'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
82
-                    'depends' => ['ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'],
83
-                ],
84
-                'events_msg_admin_css' => [
85
-                    'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
86
-                    'type' => 'css',
87
-                ],
88
-            ],
89
-            'enqueues'  => [
90
-                'events_msg_admin'     => ['edit', 'create_new'],
91
-                'events_msg_admin_css' => ['edit', 'create_new'],
92
-            ],
93
-        ];
94
-    }
95
-
96
-
97
-    public function caf_updates($update_callbacks)
98
-    {
99
-        $update_callbacks[] = [$this, 'attach_evt_message_templates'];
100
-        return $update_callbacks;
101
-    }
102
-
103
-
104
-    /**
105
-     * Handles attaching Message Templates to the Event on save.
106
-     *
107
-     * @param EE_Event $event EE event object
108
-     * @param array    $data  The request data from the form
109
-     * @return bool success or fail
110
-     * @throws EE_Error
111
-     * @throws ReflectionException
112
-     */
113
-    public function attach_evt_message_templates(EE_Event $event, array $data): bool
114
-    {
115
-        $success = true;
116
-        if (isset($data['event_message_templates_relation'])) {
117
-            // first get all existing relations on the Event for message types.
118
-            $existing_templates = EEM_Event_Message_Template::instance()->messageTemplateGroupIDsForEvent($event);
119
-            $current_templates  = $data['event_message_templates_relation'];
120
-            // new templates are those in the $current_templates array that don't exist in $existing_templates
121
-            $templates_to_add = array_diff($current_templates, $existing_templates);
122
-            foreach ($templates_to_add as $template_to_add) {
123
-                $added_template = $event->_add_relation_to($template_to_add, 'Message_Template_Group');
124
-                // toggle success to false if we don't get back a template group object
125
-                $success = $added_template instanceof EE_Message_Template_Group ? $success : false;
126
-            }
127
-            // templates to remove are those in the $existing_templates array that don't exist in $current_templates
128
-            $templates_to_remove = array_diff($existing_templates, $current_templates);
129
-            foreach ($templates_to_remove as $template_to_remove) {
130
-                $removed_template = $event->_remove_relation_to($template_to_remove, 'Message_Template_Group');
131
-                // toggle success to false if we don't get back a template group object
132
-                $success = $removed_template instanceof EE_Message_Template_Group ? $success : false;
133
-            }
134
-        }
135
-        return $success;
136
-    }
137
-
138
-
139
-    /**
140
-     * @param $event
141
-     * @param $callback_args
142
-     * @return string
143
-     * @throws EE_Error
144
-     * @throws ReflectionException
145
-     */
146
-    public function messages_metabox($event, $callback_args)
147
-    {
148
-        // convert 'evt_id' to 'EVT_ID'
149
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
150
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
151
-        $EVT_ID = $this->request->getRequestParam('evt_id', $EVT_ID, 'int');
152
-        $this->request->setRequestParam('EVT_ID', $EVT_ID);
153
-
154
-        // get the active messengers (b/c messenger objects have the active message templates)
155
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
156
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
157
-        $active_messengers        = $message_resource_manager->active_messengers();
158
-        $tabs                     = [];
159
-
160
-        // empty messengers?
161
-        // Note message types will always have at least one available because every messenger has a default message type
162
-        // associated with it (payment) if no other message types are selected.
163
-        if (empty($active_messengers)) {
164
-            $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce(
165
-                ['action' => 'settings'],
166
-                EE_MSG_ADMIN_URL
167
-            );
168
-            $error_msg        = sprintf(
169
-                esc_html__(
170
-                    '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.',
171
-                    'event_espresso'
172
-                ),
173
-                '<strong>',
174
-                '</strong>',
175
-                '<a href="' . $msg_activate_url . '">',
176
-                '</a>'
177
-            );
178
-            $error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
179
-            $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
180
-
181
-            echo $error_content;
182
-            echo $internal_content;
183
-            return '';
184
-        }
185
-
186
-        // get content for active messengers
187
-        foreach ($active_messengers as $name => $messenger) {
188
-            // first check if there are any active message types for this messenger.
189
-            $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name);
190
-            if (empty($active_mts)) {
191
-                continue;
192
-            }
193
-
194
-            $tab_content = $messenger->get_messenger_admin_page_content(
195
-                'events',
196
-                'edit',
197
-                ['event' => $EVT_ID]
198
-            );
199
-
200
-            if (! empty($tab_content)) {
201
-                $tabs[ $name ] = $tab_content;
202
-            }
203
-        }
204
-
205
-
206
-        // we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper.
207
-        $tabbed_content = EEH_Tabbed_Content::display($tabs);
208
-        if ($tabbed_content instanceof WP_Error) {
209
-            $tabbed_content = $tabbed_content->get_error_message();
210
-        }
211
-
212
-        $notices = '
18
+	/**
19
+	 * @var Messages_Admin_Page
20
+	 */
21
+	protected $_page_object;
22
+
23
+
24
+	/**
25
+	 * espresso_events_Messages_Hooks_Extend constructor.
26
+	 *
27
+	 * @param EE_Admin_Page $admin_page
28
+	 * @throws EE_Error
29
+	 */
30
+	public function __construct(EE_Admin_Page $admin_page)
31
+	{
32
+		/**
33
+		 * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
34
+		 */
35
+		if (
36
+			! EE_Registry::instance()->CAP->current_user_can(
37
+				'ee_edit_messages',
38
+				'messages_events_editor_metabox'
39
+			)
40
+		) {
41
+			return;
42
+		}
43
+		add_filter(
44
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
45
+			[$this, 'caf_updates'],
46
+			10
47
+		);
48
+		add_action(
49
+			'AHEE__Extend_Events_Admin_Page___duplicate_event__after',
50
+			[$this, 'duplicate_custom_message_settings'],
51
+			10,
52
+			2
53
+		);
54
+		parent::__construct($admin_page);
55
+	}
56
+
57
+
58
+	/**
59
+	 * extending the properties set in espresso_events_Messages_Hooks
60
+	 *
61
+	 * @access protected
62
+	 * @return void
63
+	 */
64
+	protected function _extend_properties()
65
+	{
66
+		define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
67
+		$this->_ajax_func = ['ee_msgs_create_new_custom' => 'create_new_custom'];
68
+		$this->_metaboxes = [
69
+			0 => [
70
+				'page_route' => ['edit', 'create_new'],
71
+				'func'       => 'messages_metabox',
72
+				'label'      => esc_html__('Notifications', 'event_espresso'),
73
+				'priority'   => 'high',
74
+			],
75
+		];
76
+
77
+		// see explanation for layout in EE_Admin_Hooks
78
+		$this->_scripts_styles = [
79
+			'registers' => [
80
+				'events_msg_admin'     => [
81
+					'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
82
+					'depends' => ['ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'],
83
+				],
84
+				'events_msg_admin_css' => [
85
+					'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
86
+					'type' => 'css',
87
+				],
88
+			],
89
+			'enqueues'  => [
90
+				'events_msg_admin'     => ['edit', 'create_new'],
91
+				'events_msg_admin_css' => ['edit', 'create_new'],
92
+			],
93
+		];
94
+	}
95
+
96
+
97
+	public function caf_updates($update_callbacks)
98
+	{
99
+		$update_callbacks[] = [$this, 'attach_evt_message_templates'];
100
+		return $update_callbacks;
101
+	}
102
+
103
+
104
+	/**
105
+	 * Handles attaching Message Templates to the Event on save.
106
+	 *
107
+	 * @param EE_Event $event EE event object
108
+	 * @param array    $data  The request data from the form
109
+	 * @return bool success or fail
110
+	 * @throws EE_Error
111
+	 * @throws ReflectionException
112
+	 */
113
+	public function attach_evt_message_templates(EE_Event $event, array $data): bool
114
+	{
115
+		$success = true;
116
+		if (isset($data['event_message_templates_relation'])) {
117
+			// first get all existing relations on the Event for message types.
118
+			$existing_templates = EEM_Event_Message_Template::instance()->messageTemplateGroupIDsForEvent($event);
119
+			$current_templates  = $data['event_message_templates_relation'];
120
+			// new templates are those in the $current_templates array that don't exist in $existing_templates
121
+			$templates_to_add = array_diff($current_templates, $existing_templates);
122
+			foreach ($templates_to_add as $template_to_add) {
123
+				$added_template = $event->_add_relation_to($template_to_add, 'Message_Template_Group');
124
+				// toggle success to false if we don't get back a template group object
125
+				$success = $added_template instanceof EE_Message_Template_Group ? $success : false;
126
+			}
127
+			// templates to remove are those in the $existing_templates array that don't exist in $current_templates
128
+			$templates_to_remove = array_diff($existing_templates, $current_templates);
129
+			foreach ($templates_to_remove as $template_to_remove) {
130
+				$removed_template = $event->_remove_relation_to($template_to_remove, 'Message_Template_Group');
131
+				// toggle success to false if we don't get back a template group object
132
+				$success = $removed_template instanceof EE_Message_Template_Group ? $success : false;
133
+			}
134
+		}
135
+		return $success;
136
+	}
137
+
138
+
139
+	/**
140
+	 * @param $event
141
+	 * @param $callback_args
142
+	 * @return string
143
+	 * @throws EE_Error
144
+	 * @throws ReflectionException
145
+	 */
146
+	public function messages_metabox($event, $callback_args)
147
+	{
148
+		// convert 'evt_id' to 'EVT_ID'
149
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
150
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
151
+		$EVT_ID = $this->request->getRequestParam('evt_id', $EVT_ID, 'int');
152
+		$this->request->setRequestParam('EVT_ID', $EVT_ID);
153
+
154
+		// get the active messengers (b/c messenger objects have the active message templates)
155
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
156
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
157
+		$active_messengers        = $message_resource_manager->active_messengers();
158
+		$tabs                     = [];
159
+
160
+		// empty messengers?
161
+		// Note message types will always have at least one available because every messenger has a default message type
162
+		// associated with it (payment) if no other message types are selected.
163
+		if (empty($active_messengers)) {
164
+			$msg_activate_url = EE_Admin_Page::add_query_args_and_nonce(
165
+				['action' => 'settings'],
166
+				EE_MSG_ADMIN_URL
167
+			);
168
+			$error_msg        = sprintf(
169
+				esc_html__(
170
+					'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.',
171
+					'event_espresso'
172
+				),
173
+				'<strong>',
174
+				'</strong>',
175
+				'<a href="' . $msg_activate_url . '">',
176
+				'</a>'
177
+			);
178
+			$error_content    = '<div class="error"><p>' . $error_msg . '</p></div>';
179
+			$internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
180
+
181
+			echo $error_content;
182
+			echo $internal_content;
183
+			return '';
184
+		}
185
+
186
+		// get content for active messengers
187
+		foreach ($active_messengers as $name => $messenger) {
188
+			// first check if there are any active message types for this messenger.
189
+			$active_mts = $message_resource_manager->get_active_message_types_for_messenger($name);
190
+			if (empty($active_mts)) {
191
+				continue;
192
+			}
193
+
194
+			$tab_content = $messenger->get_messenger_admin_page_content(
195
+				'events',
196
+				'edit',
197
+				['event' => $EVT_ID]
198
+			);
199
+
200
+			if (! empty($tab_content)) {
201
+				$tabs[ $name ] = $tab_content;
202
+			}
203
+		}
204
+
205
+
206
+		// we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper.
207
+		$tabbed_content = EEH_Tabbed_Content::display($tabs);
208
+		if ($tabbed_content instanceof WP_Error) {
209
+			$tabbed_content = $tabbed_content->get_error_message();
210
+		}
211
+
212
+		$notices = '
213 213
 	<div id="espresso-ajax-loading" class="ajax-loader-grey">
214 214
 		<span class="ee-spinner ee-spin"></span>
215 215
 		<span class="hidden">' . esc_html__('loading...', 'event_espresso') . '</span>
216 216
 	</div>
217 217
 	<div class="ee-notices"></div>';
218 218
 
219
-        if (defined('DOING_AJAX')) {
220
-            return $tabbed_content;
221
-        }
222
-
223
-        do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
224
-        echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
225
-        do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
226
-        return '';
227
-    }
228
-
229
-
230
-    /**
231
-     * Ajax callback for ee_msgs_create_new_custom ajax request.
232
-     * Takes incoming GRP_ID and name and description values from ajax request
233
-     * to create a new custom template based off of the incoming GRP_ID.
234
-     *
235
-     * @access public
236
-     * @return void
237
-     * @throws EE_Error
238
-     * @throws ReflectionException
239
-     */
240
-    public function create_new_custom()
241
-    {
242
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
243
-            wp_die(esc_html__('You don\'t have privileges to do this action', 'event_espresso'));
244
-        }
245
-
246
-        /** @var RequestInterface $request */
247
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
248
-
249
-        // let's clean up the request data a bit for downstream usage of name and description.
250
-        $templateName = $this->request->getRequestParam('custom_template_args[MTP_name]', '');
251
-        $request->setRequestParam('templateName', $templateName);
252
-        $templateDescription = $this->request->getRequestParam('custom_template_args[MTP_description]', '');
253
-        $request->setRequestParam('templateDescription', $templateDescription);
254
-
255
-        // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent
256
-        $this->_set_page_object();
257
-
258
-        // is this a template switch if so EE_Admin_Page child needs this object
259
-        $this->_page_object->set_hook_object($this);
260
-
261
-        $this->_page_object->add_message_template(
262
-            $this->request->getRequestParam('messageType', ''),
263
-            $this->request->getRequestParam('messenger', ''),
264
-            $this->request->getRequestParam('group_ID', 0, 'int')
265
-        );
266
-    }
267
-
268
-
269
-    public function create_new_admin_footer()
270
-    {
271
-        $this->edit_admin_footer();
272
-    }
273
-
274
-
275
-    /**
276
-     * This is the dynamic method for this class
277
-     * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page.
278
-     *
279
-     * @return void
280
-     * @throws DomainException
281
-     */
282
-    public function edit_admin_footer()
283
-    {
284
-        EEH_Template::display_template(
285
-            EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
286
-        );
287
-    }
288
-
289
-
290
-    /**
291
-     * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate
292
-     * the assigned custom message templates.
293
-     *
294
-     * @param EE_Event $new_event
295
-     * @param EE_Event $original_event
296
-     * @throws EE_Error
297
-     * @throws ReflectionException
298
-     */
299
-    public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event)
300
-    {
301
-        $message_template_groups = $original_event->get_many_related('Message_Template_Group');
302
-        foreach ($message_template_groups as $message_template_group) {
303
-            $new_event->_add_relation_to($message_template_group, 'Message_Template_Group');
304
-        }
305
-        // save new event
306
-        $new_event->save();
307
-    }
219
+		if (defined('DOING_AJAX')) {
220
+			return $tabbed_content;
221
+		}
222
+
223
+		do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
224
+		echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
225
+		do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
226
+		return '';
227
+	}
228
+
229
+
230
+	/**
231
+	 * Ajax callback for ee_msgs_create_new_custom ajax request.
232
+	 * Takes incoming GRP_ID and name and description values from ajax request
233
+	 * to create a new custom template based off of the incoming GRP_ID.
234
+	 *
235
+	 * @access public
236
+	 * @return void
237
+	 * @throws EE_Error
238
+	 * @throws ReflectionException
239
+	 */
240
+	public function create_new_custom()
241
+	{
242
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
243
+			wp_die(esc_html__('You don\'t have privileges to do this action', 'event_espresso'));
244
+		}
245
+
246
+		/** @var RequestInterface $request */
247
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
248
+
249
+		// let's clean up the request data a bit for downstream usage of name and description.
250
+		$templateName = $this->request->getRequestParam('custom_template_args[MTP_name]', '');
251
+		$request->setRequestParam('templateName', $templateName);
252
+		$templateDescription = $this->request->getRequestParam('custom_template_args[MTP_description]', '');
253
+		$request->setRequestParam('templateDescription', $templateDescription);
254
+
255
+		// set EE_Admin_Page object (see method details in EE_Admin_Hooks parent
256
+		$this->_set_page_object();
257
+
258
+		// is this a template switch if so EE_Admin_Page child needs this object
259
+		$this->_page_object->set_hook_object($this);
260
+
261
+		$this->_page_object->add_message_template(
262
+			$this->request->getRequestParam('messageType', ''),
263
+			$this->request->getRequestParam('messenger', ''),
264
+			$this->request->getRequestParam('group_ID', 0, 'int')
265
+		);
266
+	}
267
+
268
+
269
+	public function create_new_admin_footer()
270
+	{
271
+		$this->edit_admin_footer();
272
+	}
273
+
274
+
275
+	/**
276
+	 * This is the dynamic method for this class
277
+	 * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page.
278
+	 *
279
+	 * @return void
280
+	 * @throws DomainException
281
+	 */
282
+	public function edit_admin_footer()
283
+	{
284
+		EEH_Template::display_template(
285
+			EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
286
+		);
287
+	}
288
+
289
+
290
+	/**
291
+	 * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate
292
+	 * the assigned custom message templates.
293
+	 *
294
+	 * @param EE_Event $new_event
295
+	 * @param EE_Event $original_event
296
+	 * @throws EE_Error
297
+	 * @throws ReflectionException
298
+	 */
299
+	public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event)
300
+	{
301
+		$message_template_groups = $original_event->get_many_related('Message_Template_Group');
302
+		foreach ($message_template_groups as $message_template_group) {
303
+			$new_event->_add_relation_to($message_template_group, 'Message_Template_Group');
304
+		}
305
+		// save new event
306
+		$new_event->save();
307
+	}
308 308
 }
Please login to merge, or discard this patch.
core/services/request/sanitizers/RequestSanitizer.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -6,67 +6,67 @@
 block discarded – undo
6 6
 
7 7
 class RequestSanitizer
8 8
 {
9
-    /**
10
-     * Will sanitize the supplied request parameter based on the specified data type
11
-     *
12
-     * @param mixed  $param     the supplied request parameter
13
-     * @param string $type      the specified data type (default: "string")
14
-     *                          valid values: "bool", "float", "int", "key", "url", or "string"
15
-     * @param bool   $is_array  if true, then $param will be treated as an array of $type
16
-     * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator
17
-     * @return array|bool|float|int|string
18
-     * @since 4.10.14.p
19
-     */
20
-    public function clean($param, $type = DataType::STRING, $is_array = false, $delimiter = '')
21
-    {
22
-        if ($delimiter !== '' && is_string($param)) {
23
-            $param = explode($delimiter, $param);
24
-            $is_array = is_array($param);
25
-            // unset the delimiter else this function will recurse forever when we loop over the array of results
26
-            $delimiter = '';
27
-        }
28
-        // check if we are getting an improperly typed array and correct
29
-        $is_array = $is_array && is_array($param);
30
-        if ($is_array) {
31
-            $values = [];
32
-            foreach ((array) $param as $key => $value) {
33
-                $values[ $key ] = $this->clean($value, $type, is_array($value), $delimiter);
34
-            }
35
-            return $values;
36
-        }
37
-        return $this->sanitizeParam($param, $type);
38
-    }
9
+	/**
10
+	 * Will sanitize the supplied request parameter based on the specified data type
11
+	 *
12
+	 * @param mixed  $param     the supplied request parameter
13
+	 * @param string $type      the specified data type (default: "string")
14
+	 *                          valid values: "bool", "float", "int", "key", "url", or "string"
15
+	 * @param bool   $is_array  if true, then $param will be treated as an array of $type
16
+	 * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator
17
+	 * @return array|bool|float|int|string
18
+	 * @since 4.10.14.p
19
+	 */
20
+	public function clean($param, $type = DataType::STRING, $is_array = false, $delimiter = '')
21
+	{
22
+		if ($delimiter !== '' && is_string($param)) {
23
+			$param = explode($delimiter, $param);
24
+			$is_array = is_array($param);
25
+			// unset the delimiter else this function will recurse forever when we loop over the array of results
26
+			$delimiter = '';
27
+		}
28
+		// check if we are getting an improperly typed array and correct
29
+		$is_array = $is_array && is_array($param);
30
+		if ($is_array) {
31
+			$values = [];
32
+			foreach ((array) $param as $key => $value) {
33
+				$values[ $key ] = $this->clean($value, $type, is_array($value), $delimiter);
34
+			}
35
+			return $values;
36
+		}
37
+		return $this->sanitizeParam($param, $type);
38
+	}
39 39
 
40 40
 
41
-    /**
42
-     * @param mixed  $param
43
-     * @param string $type
44
-     * @return array|float|int|mixed|string|string[]|null
45
-     * @since   4.10.20.p
46
-     */
47
-    public function sanitizeParam($param, $type = DataType::STRING)
48
-    {
49
-        switch ($type) {
50
-            case DataType::BOOL:
51
-                return filter_var($param, FILTER_VALIDATE_BOOLEAN);
52
-            case DataType::FLOAT:
53
-                return (float) $param;
54
-            case DataType::FQCN:
55
-                return preg_replace('[^\\\w\d]', '', $param);
56
-            case DataType::HTML:
57
-                $allowed_tags = AllowedTags::getAllowedTags();
58
-                return wp_kses($param, $allowed_tags);
59
-            case DataType::INT:
60
-                return (int) $param;
61
-            case DataType::KEY:
62
-                return sanitize_key($param);
63
-            case DataType::TITLE:
64
-                return sanitize_title($param);
65
-            case DataType::URL:
66
-                return esc_url_raw($param);
67
-            case DataType::STRING:
68
-            default:
69
-                return sanitize_text_field($param);
70
-        }
71
-    }
41
+	/**
42
+	 * @param mixed  $param
43
+	 * @param string $type
44
+	 * @return array|float|int|mixed|string|string[]|null
45
+	 * @since   4.10.20.p
46
+	 */
47
+	public function sanitizeParam($param, $type = DataType::STRING)
48
+	{
49
+		switch ($type) {
50
+			case DataType::BOOL:
51
+				return filter_var($param, FILTER_VALIDATE_BOOLEAN);
52
+			case DataType::FLOAT:
53
+				return (float) $param;
54
+			case DataType::FQCN:
55
+				return preg_replace('[^\\\w\d]', '', $param);
56
+			case DataType::HTML:
57
+				$allowed_tags = AllowedTags::getAllowedTags();
58
+				return wp_kses($param, $allowed_tags);
59
+			case DataType::INT:
60
+				return (int) $param;
61
+			case DataType::KEY:
62
+				return sanitize_key($param);
63
+			case DataType::TITLE:
64
+				return sanitize_title($param);
65
+			case DataType::URL:
66
+				return esc_url_raw($param);
67
+			case DataType::STRING:
68
+			default:
69
+				return sanitize_text_field($param);
70
+		}
71
+	}
72 72
 }
Please login to merge, or discard this patch.
core/services/request/sanitizers/AllowedTags.php 2 patches
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -13,102 +13,102 @@
 block discarded – undo
13 13
 class AllowedTags
14 14
 {
15 15
 
16
-    /**
17
-     * @var array[]
18
-     */
19
-    private static $attributes = [
20
-        'action'     => [],
21
-        'align'      => [],
22
-        'alt'        => [],
23
-        'class'      => [],
24
-        'data'       => [],
25
-        'for'        => [],
26
-        'height'     => [],
27
-        'href'       => [],
28
-        'id'         => [],
29
-        'method'     => [],
30
-        'name'       => [],
31
-        'novalidate' => [],
32
-        'rel'        => [],
33
-        'src'        => [],
34
-        'style'      => [],
35
-        'tabindex'   => [],
36
-        'target'     => [],
37
-        'title'      => [],
38
-        'type'       => [],
39
-        'value'      => [],
40
-        'width'      => [],
41
-    ];
16
+	/**
17
+	 * @var array[]
18
+	 */
19
+	private static $attributes = [
20
+		'action'     => [],
21
+		'align'      => [],
22
+		'alt'        => [],
23
+		'class'      => [],
24
+		'data'       => [],
25
+		'for'        => [],
26
+		'height'     => [],
27
+		'href'       => [],
28
+		'id'         => [],
29
+		'method'     => [],
30
+		'name'       => [],
31
+		'novalidate' => [],
32
+		'rel'        => [],
33
+		'src'        => [],
34
+		'style'      => [],
35
+		'tabindex'   => [],
36
+		'target'     => [],
37
+		'title'      => [],
38
+		'type'       => [],
39
+		'value'      => [],
40
+		'width'      => [],
41
+	];
42 42
 
43 43
 
44
-    /**
45
-     * @var array
46
-     */
47
-    private static $tags = [
48
-        'a',
49
-        'abbr',
50
-        'b',
51
-        'br',
52
-        'code',
53
-        'div',
54
-        'em',
55
-        'form',
56
-        'h1',
57
-        'h2',
58
-        'h3',
59
-        'h4',
60
-        'h5',
61
-        'h6',
62
-        'hr',
63
-        'i',
64
-        'iframe',
65
-        'img',
66
-        'input',
67
-        'label',
68
-        'li',
69
-        'ol',
70
-        'p',
71
-        'pre',
72
-        'script',
73
-        'small',
74
-        'span',
75
-        'strong',
76
-        'style',
77
-        'table',
78
-        'td',
79
-        'textarea',
80
-        'tr',
81
-        'ul',
82
-    ];
44
+	/**
45
+	 * @var array
46
+	 */
47
+	private static $tags = [
48
+		'a',
49
+		'abbr',
50
+		'b',
51
+		'br',
52
+		'code',
53
+		'div',
54
+		'em',
55
+		'form',
56
+		'h1',
57
+		'h2',
58
+		'h3',
59
+		'h4',
60
+		'h5',
61
+		'h6',
62
+		'hr',
63
+		'i',
64
+		'iframe',
65
+		'img',
66
+		'input',
67
+		'label',
68
+		'li',
69
+		'ol',
70
+		'p',
71
+		'pre',
72
+		'script',
73
+		'small',
74
+		'span',
75
+		'strong',
76
+		'style',
77
+		'table',
78
+		'td',
79
+		'textarea',
80
+		'tr',
81
+		'ul',
82
+	];
83 83
 
84
-    /**
85
-     * @var array
86
-     */
87
-    private static $allowed_tags;
84
+	/**
85
+	 * @var array
86
+	 */
87
+	private static $allowed_tags;
88 88
 
89 89
 
90
-    /**
91
-     * merges additional tags and attributes into the WP global $allowedposttags
92
-     */
93
-    private static function initializeAllowedTags()
94
-    {
95
-        global $allowedposttags;
96
-        $allowed_tags = [];
97
-        foreach (AllowedTags::$tags as $tag) {
98
-            $allowed_tags[ $tag ] = AllowedTags::$attributes;
99
-        }
100
-        AllowedTags::$allowed_tags = array_merge_recursive($allowedposttags, $allowed_tags);
101
-    }
90
+	/**
91
+	 * merges additional tags and attributes into the WP global $allowedposttags
92
+	 */
93
+	private static function initializeAllowedTags()
94
+	{
95
+		global $allowedposttags;
96
+		$allowed_tags = [];
97
+		foreach (AllowedTags::$tags as $tag) {
98
+			$allowed_tags[ $tag ] = AllowedTags::$attributes;
99
+		}
100
+		AllowedTags::$allowed_tags = array_merge_recursive($allowedposttags, $allowed_tags);
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * @return array[]
106
-     */
107
-    public static function getAllowedTags()
108
-    {
109
-        if (empty(AllowedTags::$allowed_tags)) {
110
-            AllowedTags::initializeAllowedTags();
111
-        }
112
-        return AllowedTags::$allowed_tags;
113
-    }
104
+	/**
105
+	 * @return array[]
106
+	 */
107
+	public static function getAllowedTags()
108
+	{
109
+		if (empty(AllowedTags::$allowed_tags)) {
110
+			AllowedTags::initializeAllowedTags();
111
+		}
112
+		return AllowedTags::$allowed_tags;
113
+	}
114 114
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@
 block discarded – undo
95 95
         global $allowedposttags;
96 96
         $allowed_tags = [];
97 97
         foreach (AllowedTags::$tags as $tag) {
98
-            $allowed_tags[ $tag ] = AllowedTags::$attributes;
98
+            $allowed_tags[$tag] = AllowedTags::$attributes;
99 99
         }
100 100
         AllowedTags::$allowed_tags = array_merge_recursive($allowedposttags, $allowed_tags);
101 101
     }
Please login to merge, or discard this patch.
core/services/request/DataType.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -12,58 +12,58 @@
 block discarded – undo
12 12
  */
13 13
 class DataType
14 14
 {
15
-    // can't use ARRAY as name until we switch to PHP 7+
16
-    // const ARRAY   = 'array';
15
+	// can't use ARRAY as name until we switch to PHP 7+
16
+	// const ARRAY   = 'array';
17 17
 
18
-    const BOOL    = 'bool';
19
-    const BOOLEAN = 'bool';
18
+	const BOOL    = 'bool';
19
+	const BOOLEAN = 'bool';
20 20
 
21
-    const DOUBLE  = 'float';
22
-    const FLOAT   = 'float';
21
+	const DOUBLE  = 'float';
22
+	const FLOAT   = 'float';
23 23
 
24
-    const FQCN    = 'fqcn';
24
+	const FQCN    = 'fqcn';
25 25
 
26
-    const HTML    = 'html';
26
+	const HTML    = 'html';
27 27
 
28
-    const INT     = 'int';
29
-    const INTEGER = 'int';
28
+	const INT     = 'int';
29
+	const INTEGER = 'int';
30 30
 
31
-    const KEY     = 'key';
31
+	const KEY     = 'key';
32 32
 
33
-    const OBJECT  = 'object';
33
+	const OBJECT  = 'object';
34 34
 
35
-    const NULL    = 'null';
35
+	const NULL    = 'null';
36 36
 
37
-    const TITLE   = 'title';
37
+	const TITLE   = 'title';
38 38
 
39
-    const URL     = 'url';
39
+	const URL     = 'url';
40 40
 
41
-    const STRING  = 'string';
41
+	const STRING  = 'string';
42 42
 
43 43
 
44
-    /**
45
-     * @param mixed  $param
46
-     * @param string $type
47
-     * @return mixed
48
-     */
49
-    public static function setDataType($param, $type)
50
-    {
51
-        switch ($type) {
52
-            case DataType::NULL:
53
-                return null;
54
-            case DataType::OBJECT:
55
-                return $param;
56
-            case DataType::FQCN:
57
-            case DataType::HTML:
58
-            case DataType::KEY:
59
-            case DataType::STRING:
60
-            case DataType::TITLE:
61
-            case DataType::URL:
62
-                settype($param, DataType::STRING);
63
-                break;
64
-            default:
65
-                settype($param, $type);
66
-        }
67
-        return $param;
68
-    }
44
+	/**
45
+	 * @param mixed  $param
46
+	 * @param string $type
47
+	 * @return mixed
48
+	 */
49
+	public static function setDataType($param, $type)
50
+	{
51
+		switch ($type) {
52
+			case DataType::NULL:
53
+				return null;
54
+			case DataType::OBJECT:
55
+				return $param;
56
+			case DataType::FQCN:
57
+			case DataType::HTML:
58
+			case DataType::KEY:
59
+			case DataType::STRING:
60
+			case DataType::TITLE:
61
+			case DataType::URL:
62
+				settype($param, DataType::STRING);
63
+				break;
64
+			default:
65
+				settype($param, $type);
66
+		}
67
+		return $param;
68
+	}
69 69
 }
Please login to merge, or discard this patch.
core/services/request/RequestParams.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  discard block
 block discarded – undo
17 17
      * Used for matches() and parameterDrillDown()
18 18
      * 'bool' will return true or false if match is found or not
19 19
      */
20
-    const RETURN_BOOL  = 'bool';
20
+    const RETURN_BOOL = 'bool';
21 21
 
22 22
     /**
23 23
      * Used for matches() and parameterDrillDown()
24 24
      * 'key' will return the first key found that matches the supplied pattern
25 25
      */
26
-    const RETURN_KEY   = 'key';
26
+    const RETURN_KEY = 'key';
27 27
 
28 28
     /**
29 29
      * Used for matches() and parameterDrillDown()
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     {
114 114
         // don't allow "ee" to be overwritten unless explicitly instructed to do so
115 115
         if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
116
-            $this->request[ $key ] = $value;
116
+            $this->request[$key] = $value;
117 117
         }
118 118
     }
119 119
 
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
             preg_quote($pattern, '/')
238 238
         );
239 239
         foreach ($request_params as $key => $request_param) {
240
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
240
+            if (preg_match('/^'.$pattern.'$/is', $key)) {
241 241
                 // return value for request param
242 242
                 if ($return === self::RETURN_VALUE) {
243 243
                     return $request_param;
@@ -299,30 +299,30 @@  discard block
 block discarded – undo
299 299
                 $key      = $real_key ?: $key;
300 300
             }
301 301
             // check if top level key exists
302
-            if (isset($request_params[ $key ])) {
302
+            if (isset($request_params[$key])) {
303 303
                 // build a new key to pass along like: 'second[third]'
304 304
                 // or just 'second' depending on depth of keys
305 305
                 $key_string = array_shift($keys);
306
-                if (! empty($keys)) {
307
-                    $key_string .= '[' . implode('][', $keys) . ']';
306
+                if ( ! empty($keys)) {
307
+                    $key_string .= '['.implode('][', $keys).']';
308 308
                 }
309 309
                 return $this->parameterDrillDown(
310 310
                     $key_string,
311 311
                     $default,
312 312
                     $callback,
313 313
                     $return,
314
-                    $request_params[ $key ]
314
+                    $request_params[$key]
315 315
                 );
316 316
             }
317 317
         }
318 318
         if ($callback === 'is_set') {
319
-            return isset($request_params[ $key ]);
319
+            return isset($request_params[$key]);
320 320
         }
321 321
         if ($callback === 'match') {
322 322
             return $this->match($key, $request_params, $default, $return);
323 323
         }
324
-        return isset($request_params[ $key ])
325
-            ? $request_params[ $key ]
324
+        return isset($request_params[$key])
325
+            ? $request_params[$key]
326 326
             : $default;
327 327
     }
328 328
 
@@ -336,12 +336,12 @@  discard block
 block discarded – undo
336 336
     public function unSetRequestParam($key, $unset_from_global_too = false)
337 337
     {
338 338
         // because unset may not actually remove var
339
-        $this->get[ $key ]     = null;
340
-        $this->post[ $key ]    = null;
341
-        $this->request[ $key ] = null;
342
-        unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]);
339
+        $this->get[$key]     = null;
340
+        $this->post[$key]    = null;
341
+        $this->request[$key] = null;
342
+        unset($this->get[$key], $this->post[$key], $this->request[$key]);
343 343
         if ($unset_from_global_too) {
344
-            unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]);
344
+            unset($_GET[$key], $_POST[$key], $_REQUEST[$key]);
345 345
         }
346 346
     }
347 347
 
Please login to merge, or discard this patch.
Indentation   +345 added lines, -345 removed lines patch added patch discarded remove patch
@@ -13,349 +13,349 @@
 block discarded – undo
13 13
  */
14 14
 class RequestParams
15 15
 {
16
-    /**
17
-     * Used for matches() and parameterDrillDown()
18
-     * 'bool' will return true or false if match is found or not
19
-     */
20
-    const RETURN_BOOL  = 'bool';
21
-
22
-    /**
23
-     * Used for matches() and parameterDrillDown()
24
-     * 'key' will return the first key found that matches the supplied pattern
25
-     */
26
-    const RETURN_KEY   = 'key';
27
-
28
-    /**
29
-     * Used for matches() and parameterDrillDown()
30
-     * 'value' will return the value for the first request parameter
31
-     */
32
-    const RETURN_VALUE = 'value';
33
-
34
-    /**
35
-     * $_GET parameters
36
-     *
37
-     * @var array
38
-     */
39
-    protected $get;
40
-
41
-    /**
42
-     * $_POST parameters
43
-     *
44
-     * @var array
45
-     */
46
-    protected $post;
47
-
48
-    /**
49
-     * $_REQUEST parameters
50
-     *
51
-     * @var array
52
-     */
53
-    protected $request;
54
-
55
-    /**
56
-     * @var RequestSanitizer
57
-     */
58
-    protected $sanitizer;
59
-
60
-
61
-    /**
62
-     * RequestParams constructor.
63
-     *
64
-     * @param RequestSanitizer $sanitizer
65
-     * @param array            $get
66
-     * @param array            $post
67
-     */
68
-    public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = [])
69
-    {
70
-        $this->sanitizer = $sanitizer;
71
-        $this->get       = ! empty($get) ? $get : $_GET;
72
-        $this->post      = ! empty($post) ? $post : $_POST;
73
-        $this->request   = array_merge($this->get, $this->post);
74
-    }
75
-
76
-
77
-    /**
78
-     * @return array
79
-     */
80
-    public function getParams()
81
-    {
82
-        return $this->get;
83
-    }
84
-
85
-
86
-    /**
87
-     * @return array
88
-     */
89
-    public function postParams()
90
-    {
91
-        return $this->post;
92
-    }
93
-
94
-
95
-    /**
96
-     * returns contents of $_REQUEST
97
-     *
98
-     * @return array
99
-     */
100
-    public function requestParams()
101
-    {
102
-        return $this->request;
103
-    }
104
-
105
-
106
-    /**
107
-     * @param string     $key
108
-     * @param mixed|null $value
109
-     * @param bool       $override_ee
110
-     * @return    void
111
-     */
112
-    public function setRequestParam($key, $value, $override_ee = false)
113
-    {
114
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
115
-        if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
116
-            $this->request[ $key ] = $value;
117
-        }
118
-    }
119
-
120
-
121
-    /**
122
-     * merges the incoming array of parameters into the existing request parameters
123
-     *
124
-     * @param array $request_params
125
-     * @return void
126
-     * @since   4.10.24.p
127
-     */
128
-    public function mergeRequestParams(array $request_params)
129
-    {
130
-        $this->request = array_merge($this->request, $request_params);
131
-    }
132
-
133
-
134
-    /**
135
-     * returns   the value for a request param if the given key exists
136
-     *
137
-     * @param string     $key
138
-     * @param mixed|null $default
139
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
140
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
141
-     * @param string     $delimiter for CSV type strings that should be returned as an array
142
-     * @return array|bool|float|int|string
143
-     */
144
-    public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
145
-    {
146
-        $param = $this->sanitizer->clean(
147
-            $this->parameterDrillDown($key, $default, 'get'),
148
-            $type,
149
-            $is_array,
150
-            $delimiter
151
-        );
152
-        $type = $is_array ? 'array' : $type;
153
-        return DataType::setDataType($param, $type);
154
-    }
155
-
156
-
157
-    /**
158
-     * check if param exists
159
-     *
160
-     * @param string $key
161
-     * @return bool
162
-     */
163
-    public function requestParamIsSet($key)
164
-    {
165
-        return (bool) $this->parameterDrillDown($key);
166
-    }
167
-
168
-
169
-    /**
170
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
171
-     * and return the value for the first match found
172
-     * wildcards can be either of the following:
173
-     *      ? to represent a single character of any type
174
-     *      * to represent one or more characters of any type
175
-     *
176
-     * @param string     $pattern
177
-     * @param mixed|null $default
178
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
179
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
180
-     * @param string     $delimiter for CSV type strings that should be returned as an array
181
-     * @return array|bool|float|int|string
182
-     */
183
-    public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
184
-    {
185
-        $param = $this->sanitizer->clean(
186
-            $this->parameterDrillDown($pattern, $default, 'match'),
187
-            $type,
188
-            $is_array,
189
-            $delimiter
190
-        );
191
-        $type = $is_array ? 'array' : $type;
192
-        return DataType::setDataType($param, $type);
193
-    }
194
-
195
-
196
-    /**
197
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
198
-     * wildcards can be either of the following:
199
-     *      ? to represent a single character of any type
200
-     *      * to represent one or more characters of any type
201
-     * returns true if a match is found or false if not
202
-     *
203
-     * @param string $pattern
204
-     * @return bool
205
-     */
206
-    public function matches($pattern)
207
-    {
208
-        return (bool) $this->parameterDrillDown($pattern, false, 'match', self::RETURN_BOOL);
209
-    }
210
-
211
-
212
-    /**
213
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
214
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
215
-     *                                      and used to search through the current request's parameter keys
216
-     * @param array  $request_params        The array of request parameters to search through
217
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
218
-     *                                      Default is null
219
-     * @param string $return                [optional] Controls what kind of value is returned.
220
-     *                                      Options are the RETURN_* constants:
221
-     *                                      RETURN_BOOL will return true or false if match is found or not
222
-     *                                      RETURN_KEY will return the first key found that matches the supplied pattern
223
-     *                                      RETURN_VALUE will return the value for the first request parameter
224
-     *                                      whose key matches the supplied pattern
225
-     *                                      Default is 'value'
226
-     * @return boolean|string
227
-     */
228
-    private function match($pattern, array $request_params, $default = null, $return = self::RETURN_VALUE)
229
-    {
230
-        $return = in_array($return, [self::RETURN_BOOL, self::RETURN_KEY, self::RETURN_VALUE], true)
231
-            ? $return
232
-            : 'is_set';
233
-        // replace wildcard chars with regex chars
234
-        $pattern = str_replace(
235
-            ['\*', '\?'],
236
-            ['.*', '.'],
237
-            preg_quote($pattern, '/')
238
-        );
239
-        foreach ($request_params as $key => $request_param) {
240
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
241
-                // return value for request param
242
-                if ($return === self::RETURN_VALUE) {
243
-                    return $request_param;
244
-                }
245
-                // or actual key or true just to indicate it was found
246
-                return $return === self::RETURN_KEY ? $key : true;
247
-            }
248
-        }
249
-        // match not found so return default value or false
250
-        return $return === self::RETURN_VALUE ? $default : false;
251
-    }
252
-
253
-
254
-    /**
255
-     * the supplied key can be a simple string to represent a "top-level" request parameter
256
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
257
-     * by using square brackets to surround keys for deeper array elements.
258
-     * For example :
259
-     * if the supplied $key was: "first[second][third]"
260
-     * then this will attempt to drill down into the request parameter array to find a value.
261
-     * Given the following request parameters:
262
-     *  array(
263
-     *      'first' => array(
264
-     *          'second' => array(
265
-     *              'third' => 'has a value'
266
-     *          )
267
-     *      )
268
-     *  )
269
-     * would return true if default parameters were set
270
-     *
271
-     * @param string $callback
272
-     * @param        $key
273
-     * @param null   $default
274
-     * @param string $return
275
-     * @param mixed  $request_params
276
-     * @return bool|mixed|null
277
-     */
278
-    private function parameterDrillDown(
279
-        $key,
280
-        $default = null,
281
-        $callback = 'is_set',
282
-        $return = self::RETURN_VALUE,
283
-        $request_params = []
284
-    ) {
285
-        $callback       = in_array($callback, ['is_set', 'get', 'match'], true)
286
-            ? $callback
287
-            : 'is_set';
288
-        $request_params = ! empty($request_params)
289
-            ? $request_params
290
-            : $this->request;
291
-        // does incoming key represent an array like 'first[second][third]'  ?
292
-        if (strpos($key, '[') !== false) {
293
-            // turn it into an actual array
294
-            $key  = str_replace(']', '', $key);
295
-            $keys = explode('[', $key);
296
-            $key  = array_shift($keys);
297
-            if ($callback === 'match') {
298
-                $real_key = $this->match($key, $request_params, $default, self::RETURN_KEY);
299
-                $key      = $real_key ?: $key;
300
-            }
301
-            // check if top level key exists
302
-            if (isset($request_params[ $key ])) {
303
-                // build a new key to pass along like: 'second[third]'
304
-                // or just 'second' depending on depth of keys
305
-                $key_string = array_shift($keys);
306
-                if (! empty($keys)) {
307
-                    $key_string .= '[' . implode('][', $keys) . ']';
308
-                }
309
-                return $this->parameterDrillDown(
310
-                    $key_string,
311
-                    $default,
312
-                    $callback,
313
-                    $return,
314
-                    $request_params[ $key ]
315
-                );
316
-            }
317
-        }
318
-        if ($callback === 'is_set') {
319
-            return isset($request_params[ $key ]);
320
-        }
321
-        if ($callback === 'match') {
322
-            return $this->match($key, $request_params, $default, $return);
323
-        }
324
-        return isset($request_params[ $key ])
325
-            ? $request_params[ $key ]
326
-            : $default;
327
-    }
328
-
329
-
330
-    /**
331
-     * remove param
332
-     *
333
-     * @param      $key
334
-     * @param bool $unset_from_global_too
335
-     */
336
-    public function unSetRequestParam($key, $unset_from_global_too = false)
337
-    {
338
-        // because unset may not actually remove var
339
-        $this->get[ $key ]     = null;
340
-        $this->post[ $key ]    = null;
341
-        $this->request[ $key ] = null;
342
-        unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]);
343
-        if ($unset_from_global_too) {
344
-            unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]);
345
-        }
346
-    }
347
-
348
-
349
-    /**
350
-     * remove params
351
-     *
352
-     * @param array $keys
353
-     * @param bool  $unset_from_global_too
354
-     */
355
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false)
356
-    {
357
-        foreach ($keys as $key) {
358
-            $this->unSetRequestParam($key, $unset_from_global_too);
359
-        }
360
-    }
16
+	/**
17
+	 * Used for matches() and parameterDrillDown()
18
+	 * 'bool' will return true or false if match is found or not
19
+	 */
20
+	const RETURN_BOOL  = 'bool';
21
+
22
+	/**
23
+	 * Used for matches() and parameterDrillDown()
24
+	 * 'key' will return the first key found that matches the supplied pattern
25
+	 */
26
+	const RETURN_KEY   = 'key';
27
+
28
+	/**
29
+	 * Used for matches() and parameterDrillDown()
30
+	 * 'value' will return the value for the first request parameter
31
+	 */
32
+	const RETURN_VALUE = 'value';
33
+
34
+	/**
35
+	 * $_GET parameters
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected $get;
40
+
41
+	/**
42
+	 * $_POST parameters
43
+	 *
44
+	 * @var array
45
+	 */
46
+	protected $post;
47
+
48
+	/**
49
+	 * $_REQUEST parameters
50
+	 *
51
+	 * @var array
52
+	 */
53
+	protected $request;
54
+
55
+	/**
56
+	 * @var RequestSanitizer
57
+	 */
58
+	protected $sanitizer;
59
+
60
+
61
+	/**
62
+	 * RequestParams constructor.
63
+	 *
64
+	 * @param RequestSanitizer $sanitizer
65
+	 * @param array            $get
66
+	 * @param array            $post
67
+	 */
68
+	public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = [])
69
+	{
70
+		$this->sanitizer = $sanitizer;
71
+		$this->get       = ! empty($get) ? $get : $_GET;
72
+		$this->post      = ! empty($post) ? $post : $_POST;
73
+		$this->request   = array_merge($this->get, $this->post);
74
+	}
75
+
76
+
77
+	/**
78
+	 * @return array
79
+	 */
80
+	public function getParams()
81
+	{
82
+		return $this->get;
83
+	}
84
+
85
+
86
+	/**
87
+	 * @return array
88
+	 */
89
+	public function postParams()
90
+	{
91
+		return $this->post;
92
+	}
93
+
94
+
95
+	/**
96
+	 * returns contents of $_REQUEST
97
+	 *
98
+	 * @return array
99
+	 */
100
+	public function requestParams()
101
+	{
102
+		return $this->request;
103
+	}
104
+
105
+
106
+	/**
107
+	 * @param string     $key
108
+	 * @param mixed|null $value
109
+	 * @param bool       $override_ee
110
+	 * @return    void
111
+	 */
112
+	public function setRequestParam($key, $value, $override_ee = false)
113
+	{
114
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
115
+		if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
116
+			$this->request[ $key ] = $value;
117
+		}
118
+	}
119
+
120
+
121
+	/**
122
+	 * merges the incoming array of parameters into the existing request parameters
123
+	 *
124
+	 * @param array $request_params
125
+	 * @return void
126
+	 * @since   4.10.24.p
127
+	 */
128
+	public function mergeRequestParams(array $request_params)
129
+	{
130
+		$this->request = array_merge($this->request, $request_params);
131
+	}
132
+
133
+
134
+	/**
135
+	 * returns   the value for a request param if the given key exists
136
+	 *
137
+	 * @param string     $key
138
+	 * @param mixed|null $default
139
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
140
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
141
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
142
+	 * @return array|bool|float|int|string
143
+	 */
144
+	public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
145
+	{
146
+		$param = $this->sanitizer->clean(
147
+			$this->parameterDrillDown($key, $default, 'get'),
148
+			$type,
149
+			$is_array,
150
+			$delimiter
151
+		);
152
+		$type = $is_array ? 'array' : $type;
153
+		return DataType::setDataType($param, $type);
154
+	}
155
+
156
+
157
+	/**
158
+	 * check if param exists
159
+	 *
160
+	 * @param string $key
161
+	 * @return bool
162
+	 */
163
+	public function requestParamIsSet($key)
164
+	{
165
+		return (bool) $this->parameterDrillDown($key);
166
+	}
167
+
168
+
169
+	/**
170
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
171
+	 * and return the value for the first match found
172
+	 * wildcards can be either of the following:
173
+	 *      ? to represent a single character of any type
174
+	 *      * to represent one or more characters of any type
175
+	 *
176
+	 * @param string     $pattern
177
+	 * @param mixed|null $default
178
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
179
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
180
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
181
+	 * @return array|bool|float|int|string
182
+	 */
183
+	public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
184
+	{
185
+		$param = $this->sanitizer->clean(
186
+			$this->parameterDrillDown($pattern, $default, 'match'),
187
+			$type,
188
+			$is_array,
189
+			$delimiter
190
+		);
191
+		$type = $is_array ? 'array' : $type;
192
+		return DataType::setDataType($param, $type);
193
+	}
194
+
195
+
196
+	/**
197
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
198
+	 * wildcards can be either of the following:
199
+	 *      ? to represent a single character of any type
200
+	 *      * to represent one or more characters of any type
201
+	 * returns true if a match is found or false if not
202
+	 *
203
+	 * @param string $pattern
204
+	 * @return bool
205
+	 */
206
+	public function matches($pattern)
207
+	{
208
+		return (bool) $this->parameterDrillDown($pattern, false, 'match', self::RETURN_BOOL);
209
+	}
210
+
211
+
212
+	/**
213
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
214
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
215
+	 *                                      and used to search through the current request's parameter keys
216
+	 * @param array  $request_params        The array of request parameters to search through
217
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
218
+	 *                                      Default is null
219
+	 * @param string $return                [optional] Controls what kind of value is returned.
220
+	 *                                      Options are the RETURN_* constants:
221
+	 *                                      RETURN_BOOL will return true or false if match is found or not
222
+	 *                                      RETURN_KEY will return the first key found that matches the supplied pattern
223
+	 *                                      RETURN_VALUE will return the value for the first request parameter
224
+	 *                                      whose key matches the supplied pattern
225
+	 *                                      Default is 'value'
226
+	 * @return boolean|string
227
+	 */
228
+	private function match($pattern, array $request_params, $default = null, $return = self::RETURN_VALUE)
229
+	{
230
+		$return = in_array($return, [self::RETURN_BOOL, self::RETURN_KEY, self::RETURN_VALUE], true)
231
+			? $return
232
+			: 'is_set';
233
+		// replace wildcard chars with regex chars
234
+		$pattern = str_replace(
235
+			['\*', '\?'],
236
+			['.*', '.'],
237
+			preg_quote($pattern, '/')
238
+		);
239
+		foreach ($request_params as $key => $request_param) {
240
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
241
+				// return value for request param
242
+				if ($return === self::RETURN_VALUE) {
243
+					return $request_param;
244
+				}
245
+				// or actual key or true just to indicate it was found
246
+				return $return === self::RETURN_KEY ? $key : true;
247
+			}
248
+		}
249
+		// match not found so return default value or false
250
+		return $return === self::RETURN_VALUE ? $default : false;
251
+	}
252
+
253
+
254
+	/**
255
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
256
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
257
+	 * by using square brackets to surround keys for deeper array elements.
258
+	 * For example :
259
+	 * if the supplied $key was: "first[second][third]"
260
+	 * then this will attempt to drill down into the request parameter array to find a value.
261
+	 * Given the following request parameters:
262
+	 *  array(
263
+	 *      'first' => array(
264
+	 *          'second' => array(
265
+	 *              'third' => 'has a value'
266
+	 *          )
267
+	 *      )
268
+	 *  )
269
+	 * would return true if default parameters were set
270
+	 *
271
+	 * @param string $callback
272
+	 * @param        $key
273
+	 * @param null   $default
274
+	 * @param string $return
275
+	 * @param mixed  $request_params
276
+	 * @return bool|mixed|null
277
+	 */
278
+	private function parameterDrillDown(
279
+		$key,
280
+		$default = null,
281
+		$callback = 'is_set',
282
+		$return = self::RETURN_VALUE,
283
+		$request_params = []
284
+	) {
285
+		$callback       = in_array($callback, ['is_set', 'get', 'match'], true)
286
+			? $callback
287
+			: 'is_set';
288
+		$request_params = ! empty($request_params)
289
+			? $request_params
290
+			: $this->request;
291
+		// does incoming key represent an array like 'first[second][third]'  ?
292
+		if (strpos($key, '[') !== false) {
293
+			// turn it into an actual array
294
+			$key  = str_replace(']', '', $key);
295
+			$keys = explode('[', $key);
296
+			$key  = array_shift($keys);
297
+			if ($callback === 'match') {
298
+				$real_key = $this->match($key, $request_params, $default, self::RETURN_KEY);
299
+				$key      = $real_key ?: $key;
300
+			}
301
+			// check if top level key exists
302
+			if (isset($request_params[ $key ])) {
303
+				// build a new key to pass along like: 'second[third]'
304
+				// or just 'second' depending on depth of keys
305
+				$key_string = array_shift($keys);
306
+				if (! empty($keys)) {
307
+					$key_string .= '[' . implode('][', $keys) . ']';
308
+				}
309
+				return $this->parameterDrillDown(
310
+					$key_string,
311
+					$default,
312
+					$callback,
313
+					$return,
314
+					$request_params[ $key ]
315
+				);
316
+			}
317
+		}
318
+		if ($callback === 'is_set') {
319
+			return isset($request_params[ $key ]);
320
+		}
321
+		if ($callback === 'match') {
322
+			return $this->match($key, $request_params, $default, $return);
323
+		}
324
+		return isset($request_params[ $key ])
325
+			? $request_params[ $key ]
326
+			: $default;
327
+	}
328
+
329
+
330
+	/**
331
+	 * remove param
332
+	 *
333
+	 * @param      $key
334
+	 * @param bool $unset_from_global_too
335
+	 */
336
+	public function unSetRequestParam($key, $unset_from_global_too = false)
337
+	{
338
+		// because unset may not actually remove var
339
+		$this->get[ $key ]     = null;
340
+		$this->post[ $key ]    = null;
341
+		$this->request[ $key ] = null;
342
+		unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]);
343
+		if ($unset_from_global_too) {
344
+			unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]);
345
+		}
346
+	}
347
+
348
+
349
+	/**
350
+	 * remove params
351
+	 *
352
+	 * @param array $keys
353
+	 * @param bool  $unset_from_global_too
354
+	 */
355
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false)
356
+	{
357
+		foreach ($keys as $key) {
358
+			$this->unSetRequestParam($key, $unset_from_global_too);
359
+		}
360
+	}
361 361
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Array.helper.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public static function is_set($arr, $index, $default)
84 84
     {
85
-        return isset($arr[ $index ]) ? $arr[ $index ] : $default;
85
+        return isset($arr[$index]) ? $arr[$index] : $default;
86 86
     }
87 87
 
88 88
     /**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
     public static function merge_arrays_and_overwrite_keys(array $array1, array $array2)
171 171
     {
172 172
         foreach ($array2 as $key => $value) {
173
-            $array1[ $key ] = $value;
173
+            $array1[$key] = $value;
174 174
         }
175 175
         return $array1;
176 176
     }
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
         $multidimensional = array();
193 193
         $reference = &$multidimensional;
194 194
         foreach ($flat_array as $key) {
195
-            $reference[ $key ] = array();
196
-            $reference = &$reference[ $key ];
195
+            $reference[$key] = array();
196
+            $reference = &$reference[$key];
197 197
         }
198 198
         if ($final_value !== null) {
199 199
             $reference = $final_value;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
     {
225 225
         if (is_array($element)) {
226 226
             foreach ($element as $key => $value) {
227
-                $element[ $key ] = EEH_Array::addSlashesRecursively($value);
227
+                $element[$key] = EEH_Array::addSlashesRecursively($value);
228 228
             }
229 229
             return $element;
230 230
         }
Please login to merge, or discard this patch.
Indentation   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -13,221 +13,221 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays
18
-     * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects
19
-     *
20
-     * @uses array_udiff core php function for setting up our own array comparison
21
-     * @uses self::_compare_objects as the custom method for array_udiff
22
-     * @param  array $array1 an array of objects
23
-     * @param  array $array2 an array of objects
24
-     * @return array         an array of objects found in array 1 that aren't found in array 2.
25
-     */
26
-    public static function object_array_diff($array1, $array2)
27
-    {
28
-        return array_udiff($array1, $array2, array('self', '_compare_objects'));
29
-    }
30
-
31
-    /**
32
-     * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed
33
-     *
34
-     * @param array $array
35
-     * @return boolean
36
-     */
37
-    public static function is_associative_array(array $array): bool
38
-    {
39
-        return ! empty($array) && array_keys($array) !== range(0, count($array) - 1);
40
-    }
41
-
42
-    /**
43
-     * Gets an item from the array and leave the array intact. Use in place of end()
44
-     * when you don't want to change the array
45
-     *
46
-     * @param array $arr
47
-     * @return mixed what ever is in the array
48
-     */
49
-    public static function get_one_item_from_array($arr)
50
-    {
51
-        $item = end($arr);
52
-        reset($arr);
53
-        return $item;
54
-    }
55
-
56
-    /**
57
-     * Detects if this is a multi-dimensional array
58
-     * meaning that at least one top-level value is an array. Eg [ [], ...]
59
-     *
60
-     * @param mixed $arr
61
-     * @return boolean
62
-     */
63
-    public static function is_multi_dimensional_array($arr)
64
-    {
65
-        if (is_array($arr)) {
66
-            foreach ($arr as $item) {
67
-                if (is_array($item)) {
68
-                    return true; // yep, there's at least 2 levels to this array
69
-                }
70
-            }
71
-        }
72
-        return false; // there's only 1 level, or it's not an array at all!
73
-    }
74
-
75
-    /**
76
-     * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default
77
-     *
78
-     * @param array $arr
79
-     * @param mixed $index
80
-     * @param mixed $default
81
-     * @return mixed
82
-     */
83
-    public static function is_set($arr, $index, $default)
84
-    {
85
-        return isset($arr[ $index ]) ? $arr[ $index ] : $default;
86
-    }
87
-
88
-    /**
89
-     * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118
90
-     *
91
-     * @param mixed $value usually a string, but could be an array or object
92
-     * @return mixed the UN-serialized data
93
-     */
94
-    public static function maybe_unserialize($value)
95
-    {
96
-        $data = maybe_unserialize($value);
97
-        // it's possible that this still has serialized data if it's the session.
98
-        //  WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesn't unserialize this automatically.
99
-        $token = 'C';
100
-        $data = is_string($data) ? trim($data) : $data;
101
-        if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) {
102
-            return unserialize($data);
103
-        } else {
104
-            return $data;
105
-        }
106
-    }
107
-
108
-
109
-    /**
110
-     * insert_into_array
111
-     *
112
-     * @param array        $target_array the array to insert new data into
113
-     * @param array        $array_to_insert the new data to be inserted
114
-     * @param int | string $offset a known key within $target_array where new data will be inserted
115
-     * @param bool         $add_before whether to add new data before or after the offset key
116
-     * @param bool         $preserve_keys whether or not to reset numerically indexed arrays
117
-     * @return array
118
-     */
119
-    public static function insert_into_array(
120
-        $target_array = array(),
121
-        $array_to_insert = array(),
122
-        $offset = null,
123
-        $add_before = true,
124
-        $preserve_keys = true
125
-    ) {
126
-        // ensure incoming arrays are actually arrays
127
-        $target_array = (array) $target_array;
128
-        $array_to_insert = (array) $array_to_insert;
129
-        // if no offset key was supplied
130
-        if (empty($offset)) {
131
-            // use start or end of $target_array based on whether we are adding before or not
132
-            $offset = $add_before ? 0 : count($target_array);
133
-        }
134
-        // if offset key is a string, then find the corresponding numeric location for that element
135
-        $offset = is_int($offset) ? $offset : array_search($offset, array_keys($target_array));
136
-        // add one to the offset if adding after
137
-        $offset = $add_before ? $offset : $offset + 1;
138
-        // but ensure offset does not exceed the length of the array
139
-        $offset = $offset > count($target_array) ? count($target_array) : $offset;
140
-        // reindex array ???
141
-        if ($preserve_keys) {
142
-            // take a slice of the target array from the beginning till the offset,
143
-            // then add the new data
144
-            // then add another slice that starts at the offset and goes till the end
145
-            return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice(
146
-                $target_array,
147
-                $offset,
148
-                null,
149
-                true
150
-            );
151
-        } else {
152
-            // since we don't want to preserve keys, we can use array_splice
153
-            array_splice($target_array, $offset, 0, $array_to_insert);
154
-            return $target_array;
155
-        }
156
-    }
157
-
158
-
159
-    /**
160
-     * array_merge() is slow and should never be used while looping over data
161
-     * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster
162
-     * so really this acts more like array_replace( $array1, $array2 )
163
-     * or a union with the arrays flipped ( $array2 + $array1 )
164
-     * this saves a few lines of code and improves readability
165
-     *
166
-     * @param array $array1
167
-     * @param array $array2
168
-     * @return array
169
-     */
170
-    public static function merge_arrays_and_overwrite_keys(array $array1, array $array2)
171
-    {
172
-        foreach ($array2 as $key => $value) {
173
-            $array1[ $key ] = $value;
174
-        }
175
-        return $array1;
176
-    }
177
-
178
-
179
-    /**
180
-     * given a flat array like $array = array('A', 'B', 'C')
181
-     * will convert into a multidimensional array like $array[A][B][C]
182
-     * if $final_value is provided and is anything other than null,
183
-     * then that will be set as the value for the innermost array key
184
-     * like so: $array[A][B][C] = $final_value
185
-     *
186
-     * @param array $flat_array
187
-     * @param mixed $final_value
188
-     * @return array
189
-     */
190
-    public static function convert_array_values_to_keys(array $flat_array, $final_value = null)
191
-    {
192
-        $multidimensional = array();
193
-        $reference = &$multidimensional;
194
-        foreach ($flat_array as $key) {
195
-            $reference[ $key ] = array();
196
-            $reference = &$reference[ $key ];
197
-        }
198
-        if ($final_value !== null) {
199
-            $reference = $final_value;
200
-        }
201
-        return $multidimensional;
202
-    }
203
-
204
-
205
-    /**
206
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
207
-     * @param array $array
208
-     * @return bool
209
-     */
210
-    public static function is_array_numerically_and_sequentially_indexed(array $array)
211
-    {
212
-        return empty($array) || array_keys($array) === range(0, count($array) - 1);
213
-    }
214
-
215
-
216
-    /**
217
-     * recursively walks through an array and adds slashes to all no array elements
218
-     *
219
-     * @param mixed $element
220
-     * @return array|string
221
-     * @since   $VID:$
222
-     */
223
-    public static function addSlashesRecursively($element)
224
-    {
225
-        if (is_array($element)) {
226
-            foreach ($element as $key => $value) {
227
-                $element[ $key ] = EEH_Array::addSlashesRecursively($value);
228
-            }
229
-            return $element;
230
-        }
231
-        return is_string($element) ? addslashes($element) : $element;
232
-    }
16
+	/**
17
+	 * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays
18
+	 * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects
19
+	 *
20
+	 * @uses array_udiff core php function for setting up our own array comparison
21
+	 * @uses self::_compare_objects as the custom method for array_udiff
22
+	 * @param  array $array1 an array of objects
23
+	 * @param  array $array2 an array of objects
24
+	 * @return array         an array of objects found in array 1 that aren't found in array 2.
25
+	 */
26
+	public static function object_array_diff($array1, $array2)
27
+	{
28
+		return array_udiff($array1, $array2, array('self', '_compare_objects'));
29
+	}
30
+
31
+	/**
32
+	 * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed
33
+	 *
34
+	 * @param array $array
35
+	 * @return boolean
36
+	 */
37
+	public static function is_associative_array(array $array): bool
38
+	{
39
+		return ! empty($array) && array_keys($array) !== range(0, count($array) - 1);
40
+	}
41
+
42
+	/**
43
+	 * Gets an item from the array and leave the array intact. Use in place of end()
44
+	 * when you don't want to change the array
45
+	 *
46
+	 * @param array $arr
47
+	 * @return mixed what ever is in the array
48
+	 */
49
+	public static function get_one_item_from_array($arr)
50
+	{
51
+		$item = end($arr);
52
+		reset($arr);
53
+		return $item;
54
+	}
55
+
56
+	/**
57
+	 * Detects if this is a multi-dimensional array
58
+	 * meaning that at least one top-level value is an array. Eg [ [], ...]
59
+	 *
60
+	 * @param mixed $arr
61
+	 * @return boolean
62
+	 */
63
+	public static function is_multi_dimensional_array($arr)
64
+	{
65
+		if (is_array($arr)) {
66
+			foreach ($arr as $item) {
67
+				if (is_array($item)) {
68
+					return true; // yep, there's at least 2 levels to this array
69
+				}
70
+			}
71
+		}
72
+		return false; // there's only 1 level, or it's not an array at all!
73
+	}
74
+
75
+	/**
76
+	 * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default
77
+	 *
78
+	 * @param array $arr
79
+	 * @param mixed $index
80
+	 * @param mixed $default
81
+	 * @return mixed
82
+	 */
83
+	public static function is_set($arr, $index, $default)
84
+	{
85
+		return isset($arr[ $index ]) ? $arr[ $index ] : $default;
86
+	}
87
+
88
+	/**
89
+	 * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118
90
+	 *
91
+	 * @param mixed $value usually a string, but could be an array or object
92
+	 * @return mixed the UN-serialized data
93
+	 */
94
+	public static function maybe_unserialize($value)
95
+	{
96
+		$data = maybe_unserialize($value);
97
+		// it's possible that this still has serialized data if it's the session.
98
+		//  WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesn't unserialize this automatically.
99
+		$token = 'C';
100
+		$data = is_string($data) ? trim($data) : $data;
101
+		if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) {
102
+			return unserialize($data);
103
+		} else {
104
+			return $data;
105
+		}
106
+	}
107
+
108
+
109
+	/**
110
+	 * insert_into_array
111
+	 *
112
+	 * @param array        $target_array the array to insert new data into
113
+	 * @param array        $array_to_insert the new data to be inserted
114
+	 * @param int | string $offset a known key within $target_array where new data will be inserted
115
+	 * @param bool         $add_before whether to add new data before or after the offset key
116
+	 * @param bool         $preserve_keys whether or not to reset numerically indexed arrays
117
+	 * @return array
118
+	 */
119
+	public static function insert_into_array(
120
+		$target_array = array(),
121
+		$array_to_insert = array(),
122
+		$offset = null,
123
+		$add_before = true,
124
+		$preserve_keys = true
125
+	) {
126
+		// ensure incoming arrays are actually arrays
127
+		$target_array = (array) $target_array;
128
+		$array_to_insert = (array) $array_to_insert;
129
+		// if no offset key was supplied
130
+		if (empty($offset)) {
131
+			// use start or end of $target_array based on whether we are adding before or not
132
+			$offset = $add_before ? 0 : count($target_array);
133
+		}
134
+		// if offset key is a string, then find the corresponding numeric location for that element
135
+		$offset = is_int($offset) ? $offset : array_search($offset, array_keys($target_array));
136
+		// add one to the offset if adding after
137
+		$offset = $add_before ? $offset : $offset + 1;
138
+		// but ensure offset does not exceed the length of the array
139
+		$offset = $offset > count($target_array) ? count($target_array) : $offset;
140
+		// reindex array ???
141
+		if ($preserve_keys) {
142
+			// take a slice of the target array from the beginning till the offset,
143
+			// then add the new data
144
+			// then add another slice that starts at the offset and goes till the end
145
+			return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice(
146
+				$target_array,
147
+				$offset,
148
+				null,
149
+				true
150
+			);
151
+		} else {
152
+			// since we don't want to preserve keys, we can use array_splice
153
+			array_splice($target_array, $offset, 0, $array_to_insert);
154
+			return $target_array;
155
+		}
156
+	}
157
+
158
+
159
+	/**
160
+	 * array_merge() is slow and should never be used while looping over data
161
+	 * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster
162
+	 * so really this acts more like array_replace( $array1, $array2 )
163
+	 * or a union with the arrays flipped ( $array2 + $array1 )
164
+	 * this saves a few lines of code and improves readability
165
+	 *
166
+	 * @param array $array1
167
+	 * @param array $array2
168
+	 * @return array
169
+	 */
170
+	public static function merge_arrays_and_overwrite_keys(array $array1, array $array2)
171
+	{
172
+		foreach ($array2 as $key => $value) {
173
+			$array1[ $key ] = $value;
174
+		}
175
+		return $array1;
176
+	}
177
+
178
+
179
+	/**
180
+	 * given a flat array like $array = array('A', 'B', 'C')
181
+	 * will convert into a multidimensional array like $array[A][B][C]
182
+	 * if $final_value is provided and is anything other than null,
183
+	 * then that will be set as the value for the innermost array key
184
+	 * like so: $array[A][B][C] = $final_value
185
+	 *
186
+	 * @param array $flat_array
187
+	 * @param mixed $final_value
188
+	 * @return array
189
+	 */
190
+	public static function convert_array_values_to_keys(array $flat_array, $final_value = null)
191
+	{
192
+		$multidimensional = array();
193
+		$reference = &$multidimensional;
194
+		foreach ($flat_array as $key) {
195
+			$reference[ $key ] = array();
196
+			$reference = &$reference[ $key ];
197
+		}
198
+		if ($final_value !== null) {
199
+			$reference = $final_value;
200
+		}
201
+		return $multidimensional;
202
+	}
203
+
204
+
205
+	/**
206
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
207
+	 * @param array $array
208
+	 * @return bool
209
+	 */
210
+	public static function is_array_numerically_and_sequentially_indexed(array $array)
211
+	{
212
+		return empty($array) || array_keys($array) === range(0, count($array) - 1);
213
+	}
214
+
215
+
216
+	/**
217
+	 * recursively walks through an array and adds slashes to all no array elements
218
+	 *
219
+	 * @param mixed $element
220
+	 * @return array|string
221
+	 * @since   $VID:$
222
+	 */
223
+	public static function addSlashesRecursively($element)
224
+	{
225
+		if (is_array($element)) {
226
+			foreach ($element as $key => $value) {
227
+				$element[ $key ] = EEH_Array::addSlashesRecursively($value);
228
+			}
229
+			return $element;
230
+		}
231
+		return is_string($element) ? addslashes($element) : $element;
232
+	}
233 233
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Form_Fields.helper.php 2 patches
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
             $type           = $input_value['input'];
111 111
             $value          = $input_value['value'];
112 112
 
113
-            $id    = $form_id ? $form_id . '-' . $input_key : $input_key;
114
-            $class = $required ? 'required ' . $css_class : $css_class;
113
+            $id    = $form_id ? $form_id.'-'.$input_key : $input_key;
114
+            $class = $required ? 'required '.$css_class : $css_class;
115 115
 
116 116
             // what type of input are we dealing with ?
117 117
             switch ($type) {
@@ -163,8 +163,8 @@  discard block
 block discarded – undo
163 163
             }
164 164
         } // end foreach( $input_vars as $input_key => $input_value )
165 165
 
166
-        if (! empty($inputs)) {
167
-            $glue   = "
166
+        if ( ! empty($inputs)) {
167
+            $glue = "
168 168
                 </li>
169 169
                 <li>
170 170
                     ";
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
             </ul>
178 178
             ";
179 179
         }
180
-        return $output . implode("\n", $hidden_inputs);
180
+        return $output.implode("\n", $hidden_inputs);
181 181
     }
182 182
 
183 183
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
             // generate label
259 259
             $label = ! empty($label) ? self::adminLabel($id, $label, $required) : '';
260 260
             // generate field name
261
-            $name = ! empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name;
261
+            $name = ! empty($unique_id) ? $field_name.'['.$unique_id.']' : $field_name;
262 262
 
263 263
             // we determine what we're building based on the type
264 264
             switch ($type) {
@@ -269,14 +269,14 @@  discard block
 block discarded – undo
269 269
                         foreach ($value as $key => $val) {
270 270
                             $c_input .= self::adminMulti(
271 271
                                 $default,
272
-                                isset($classes[ $key ]) ? $classes[ $key ] : '',
273
-                                $field_name . '_' . $value,
272
+                                isset($classes[$key]) ? $classes[$key] : '',
273
+                                $field_name.'_'.$value,
274 274
                                 $name,
275 275
                                 $required,
276 276
                                 $tab_index,
277 277
                                 $type,
278 278
                                 $val,
279
-                                isset($labels[ $key ]) ? $labels[ $key ] : ''
279
+                                isset($labels[$key]) ? $labels[$key] : ''
280 280
                             );
281 281
                         }
282 282
                         $field = $c_input;
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
                 case 'select':
303 303
                     $options = [];
304 304
                     foreach ($value as $key => $val) {
305
-                        $options[ $val ] = isset($labels[ $key ]) ? $labels[ $key ] : '';
305
+                        $options[$val] = isset($labels[$key]) ? $labels[$key] : '';
306 306
                     }
307 307
                     $field = self::adminSelect($default, $class, $id, $name, $required, $tab_index, $options);
308 308
                     break;
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
                     $field = self::adminText($class, $id, $name, $required, $tab_index, $value);
329 329
             }
330 330
 
331
-            $form_fields[ $field_name ] = ['label' => $label, 'field' => $field . $extra_desc];
331
+            $form_fields[$field_name] = ['label' => $label, 'field' => $field.$extra_desc];
332 332
         }
333 333
 
334 334
         return $form_fields;
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
     public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true)
537 537
     {
538 538
         // if $values was submitted in the wrong format, convert it over
539
-        if (! empty($values) && (! array_key_exists(0, $values) || ! is_array($values[0]))) {
539
+        if ( ! empty($values) && ( ! array_key_exists(0, $values) || ! is_array($values[0]))) {
540 540
             $converted_values = [];
541 541
             foreach ($values as $id => $text) {
542 542
                 $converted_values[] = ['id' => $id, 'text' => $text];
@@ -545,18 +545,18 @@  discard block
 block discarded – undo
545 545
         }
546 546
 
547 547
         $field =
548
-            '<select id="' . EEH_Formatter::ee_tep_output_string($name)
549
-            . '" name="' . EEH_Formatter::ee_tep_output_string($name)
548
+            '<select id="'.EEH_Formatter::ee_tep_output_string($name)
549
+            . '" name="'.EEH_Formatter::ee_tep_output_string($name)
550 550
             . '"';
551 551
 
552 552
         if (EEH_Formatter::ee_tep_not_null($parameters)) {
553
-            $field .= ' ' . $parameters;
553
+            $field .= ' '.$parameters;
554 554
         }
555 555
         if ($autosize) {
556 556
             $size = 'med';
557 557
             for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) {
558
-                if ($values[ $ii ]['text']) {
559
-                    if (strlen($values[ $ii ]['text']) > 5) {
558
+                if ($values[$ii]['text']) {
559
+                    if (strlen($values[$ii]['text']) > 5) {
560 560
                         $size = 'wide';
561 561
                     }
562 562
                 }
@@ -565,22 +565,22 @@  discard block
 block discarded – undo
565 565
             $size = '';
566 566
         }
567 567
 
568
-        $field .= ' class="' . $class . ' ' . $size . '">';
568
+        $field .= ' class="'.$class.' '.$size.'">';
569 569
 
570
-        if (empty($default) && isset($GLOBALS[ $name ])) {
571
-            $default = stripslashes($GLOBALS[ $name ]);
570
+        if (empty($default) && isset($GLOBALS[$name])) {
571
+            $default = stripslashes($GLOBALS[$name]);
572 572
         }
573 573
 
574 574
 
575 575
         for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
576
-            $field .= '<option value="' . $values[ $i ]['id'] . '"';
577
-            if ($default == $values[ $i ]['id']) {
576
+            $field .= '<option value="'.$values[$i]['id'].'"';
577
+            if ($default == $values[$i]['id']) {
578 578
                 $field .= ' selected = "selected"';
579 579
             }
580
-            if (isset($values[ $i ]['class'])) {
581
-                $field .= ' class="' . $values[ $i ]['class'] . '"';
580
+            if (isset($values[$i]['class'])) {
581
+                $field .= ' class="'.$values[$i]['class'].'"';
582 582
             }
583
-            $field .= '>' . $values[ $i ]['text'] . '</option>';
583
+            $field .= '>'.$values[$i]['text'].'</option>';
584 584
         }
585 585
         $field .= '</select>';
586 586
 
@@ -606,11 +606,11 @@  discard block
 block discarded – undo
606 606
         $after_question_group_questions  =
607 607
             apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
608 608
 
609
-        if (! empty($question_groups)) {
609
+        if ( ! empty($question_groups)) {
610 610
             // loop thru question groups
611 611
             foreach ($question_groups as $QSG) {
612 612
                 // check that questions exist
613
-                if (! empty($QSG['QSG_questions'])) {
613
+                if ( ! empty($QSG['QSG_questions'])) {
614 614
                     // use fieldsets
615 615
                     $html .= "\n\t"
616 616
                              . '<'
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
                     $html .= $before_question_group_questions;
636 636
                     // loop thru questions
637 637
                     foreach ($QSG['QSG_questions'] as $question) {
638
-                        $QFI  = new EE_Question_Form_Input(
638
+                        $QFI = new EE_Question_Form_Input(
639 639
                             $question['qst_obj'],
640 640
                             $question['ans_obj'],
641 641
                             $question
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
                         $html .= self::generate_form_input($QFI);
644 644
                     }
645 645
                     $html .= $after_question_group_questions;
646
-                    $html .= "\n\t" . '</' . $group_wrapper . '>';
646
+                    $html .= "\n\t".'</'.$group_wrapper.'>';
647 647
                 }
648 648
             }
649 649
         }
@@ -683,25 +683,25 @@  discard block
 block discarded – undo
683 683
             'input_id'    => '',
684 684
             'input_class' => '',
685 685
         ];
686
-        $q_meta         = array_merge($default_q_meta, $q_meta);
686
+        $q_meta = array_merge($default_q_meta, $q_meta);
687 687
 
688
-        if (! empty($question_groups)) {
688
+        if ( ! empty($question_groups)) {
689 689
             // loop thru question groups
690 690
             foreach ($question_groups as $QSG) {
691 691
                 if ($QSG instanceof EE_Question_Group) {
692 692
                     // check that questions exist
693 693
 
694 694
                     $where = ['QST_deleted' => 0];
695
-                    if (! $from_admin) {
695
+                    if ( ! $from_admin) {
696 696
                         $where['QST_admin_only'] = 0;
697 697
                     }
698 698
                     $questions =
699 699
                         $QSG->questions([$where, 'order_by' => ['Question_Group_Question.QGQ_order' => 'ASC']]);
700
-                    if (! empty($questions)) {
700
+                    if ( ! empty($questions)) {
701 701
                         // use fieldsets
702 702
                         $html .= "\n\t"
703
-                                 . '<' . $group_wrapper . ' class="espresso-question-group-wrap" '
704
-                                 . 'id="' . $QSG->get('QSG_identifier') . '">';
703
+                                 . '<'.$group_wrapper.' class="espresso-question-group-wrap" '
704
+                                 . 'id="'.$QSG->get('QSG_identifier').'">';
705 705
                         // group_name
706 706
                         if ($QSG->show_group_name()) {
707 707
                             $html .= "\n\t\t"
@@ -726,21 +726,21 @@  discard block
 block discarded – undo
726 726
                             /** @var RequestInterface $request */
727 727
                             $request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
728 728
                             $request_qstn = $request->getRequestParam('qstn', [], 'string', true);
729
-                            if (! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
729
+                            if ( ! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
730 730
                                 // check for answer in $request_qstn in case we are reprocessing a form after an error
731
-                                if (isset($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])) {
732
-                                    $answer = is_array($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])
733
-                                        ? $request_qstn[ $q_meta['input_id'] ][ $qstn_id ]
734
-                                        : sanitize_text_field($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]);
731
+                                if (isset($request_qstn[$q_meta['input_id']][$qstn_id])) {
732
+                                    $answer = is_array($request_qstn[$q_meta['input_id']][$qstn_id])
733
+                                        ? $request_qstn[$q_meta['input_id']][$qstn_id]
734
+                                        : sanitize_text_field($request_qstn[$q_meta['input_id']][$qstn_id]);
735 735
                                 }
736 736
                             } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) {
737 737
                                 // attendee data from the session
738 738
                                 $answer =
739
-                                    isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null;
739
+                                    isset($q_meta['attendee'][$qstn_id]) ? $q_meta['attendee'][$qstn_id] : null;
740 740
                             }
741 741
 
742 742
 
743
-                            $QFI  = new EE_Question_Form_Input(
743
+                            $QFI = new EE_Question_Form_Input(
744 744
                                 $QST,
745 745
                                 EE_Answer::new_instance(
746 746
                                     [
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
                             $html .= self::generate_form_input($QFI);
756 756
                         }
757 757
                         $html .= $after_question_group_questions;
758
-                        $html .= "\n\t" . '</' . $group_wrapper . '>';
758
+                        $html .= "\n\t".'</'.$group_wrapper.'>';
759 759
                     }
760 760
                 }
761 761
             }
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
             $QFI->get('QST_required_text') != ''
804 804
                 ? $QFI->get('QST_required_text')
805 805
                 : esc_html__('This field is required', 'event_espresso');
806
-        $required_text     = $QST_required
806
+        $required_text = $QST_required
807 807
             ? "\n\t\t\t"
808 808
               . '<div class="required-text hidden">'
809 809
               . self::prep_answer($required_text, $use_html_entities)
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
         $use_html_entities = true
950 950
     ) {
951 951
         // need these
952
-        if (! $question || ! $name) {
952
+        if ( ! $question || ! $name) {
953 953
             return null;
954 954
         }
955 955
         // prep the answer
@@ -961,13 +961,13 @@  discard block
 block discarded – undo
961 961
         // ya gots ta have style man!!!
962 962
         $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp';
963 963
         $class     = empty($class) ? $txt_class : $class;
964
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
964
+        $class     .= ! empty($system_ID) ? ' '.$system_ID : '';
965 965
         $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
966 966
 
967 967
         $label_html =
968 968
             $required_text
969 969
             . "\n\t\t\t"
970
-            . '<label for="' . $name . '" class="' . $label_class . '">'
970
+            . '<label for="'.$name.'" class="'.$label_class.'">'
971 971
             . self::prep_question($question)
972 972
             . $required['label']
973 973
             . '</label><br/>';
@@ -976,12 +976,12 @@  discard block
 block discarded – undo
976 976
 
977 977
         $input_html =
978 978
             "\n\t\t\t"
979
-            . '<input type="text" name="' . $name . '" id="' . $id . '" '
980
-            . 'class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '"  '
981
-            . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
979
+            . '<input type="text" name="'.$name.'" id="'.$id.'" '
980
+            . 'class="'.$class.' '.$required['class'].'" value="'.esc_attr($answer).'"  '
981
+            . 'title="'.esc_attr($required['msg']).'" '.$disabled.' '.$extra.'/>';
982 982
 
983 983
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
984
-        return $label_html . $input_html;
984
+        return $label_html.$input_html;
985 985
     }
986 986
 
987 987
 
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
         $use_html_entities = true
1016 1016
     ) {
1017 1017
         // need these
1018
-        if (! $question || ! $name) {
1018
+        if ( ! $question || ! $name) {
1019 1019
             return null;
1020 1020
         }
1021 1021
         // prep the answer
@@ -1031,13 +1031,13 @@  discard block
 block discarded – undo
1031 1031
         // ya gots ta have style man!!!
1032 1032
         $txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp';
1033 1033
         $class     = empty($class) ? $txt_class : $class;
1034
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1034
+        $class     .= ! empty($system_ID) ? ' '.$system_ID : '';
1035 1035
         $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1036 1036
 
1037 1037
         $label_html =
1038 1038
             $required_text
1039 1039
             . "\n\t\t\t"
1040
-            . '<label for="' . $name . '" class="' . $label_class . '">'
1040
+            . '<label for="'.$name.'" class="'.$label_class.'">'
1041 1041
             . self::prep_question($question)
1042 1042
             . $required['label']
1043 1043
             . '</label><br/>';
@@ -1046,14 +1046,14 @@  discard block
 block discarded – undo
1046 1046
 
1047 1047
         $input_html =
1048 1048
             "\n\t\t\t"
1049
-            . '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" '
1050
-            . 'rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '"  '
1051
-            . 'title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>'
1049
+            . '<textarea name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].'" '
1050
+            . 'rows="'.$dimensions['rows'].'" cols="'.$dimensions['cols'].'"  '
1051
+            . 'title="'.$required['msg'].'" '.$disabled.' '.$extra.'>'
1052 1052
             . $answer
1053 1053
             . '</textarea>';
1054 1054
 
1055 1055
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1056
-        return $label_html . $input_html;
1056
+        return $label_html.$input_html;
1057 1057
     }
1058 1058
 
1059 1059
 
@@ -1090,7 +1090,7 @@  discard block
 block discarded – undo
1090 1090
     ) {
1091 1091
 
1092 1092
         // need these
1093
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1093
+        if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1094 1094
             return null;
1095 1095
         }
1096 1096
         // prep the answer
@@ -1108,13 +1108,13 @@  discard block
 block discarded – undo
1108 1108
         // ya gots ta have style man!!!
1109 1109
         $txt_class = is_admin() ? 'wide' : 'espresso-select-inp';
1110 1110
         $class     = empty($class) ? $txt_class : $class;
1111
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1111
+        $class     .= ! empty($system_ID) ? ' '.$system_ID : '';
1112 1112
         $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1113 1113
 
1114 1114
         $label_html =
1115 1115
             $required_text
1116 1116
             . "\n\t\t\t"
1117
-            . '<label for="' . $name . '" class="' . $label_class . '">'
1117
+            . '<label for="'.$name.'" class="'.$label_class.'">'
1118 1118
             . self::prep_question($question)
1119 1119
             . $required['label']
1120 1120
             . '</label><br/>';
@@ -1123,16 +1123,16 @@  discard block
 block discarded – undo
1123 1123
 
1124 1124
         $input_html =
1125 1125
             "\n\t\t\t"
1126
-            . '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" '
1127
-            . 'title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>';
1126
+            . '<select name="'.$name.'" id="'.$id.'" class="'.$class.' '.$required['class'].'" '
1127
+            . 'title="'.esc_attr($required['msg']).'"'.$disabled.' '.$extra.'>';
1128 1128
         // recursively count array elements, to determine total number of options
1129 1129
         $only_option = count($options, 1) == 1;
1130
-        if (! $only_option) {
1130
+        if ( ! $only_option) {
1131 1131
             // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected
1132
-            $selected   = $answer === null ? ' selected="selected"' : '';
1132
+            $selected = $answer === null ? ' selected="selected"' : '';
1133 1133
             $input_html .= $add_please_select_option
1134 1134
                 ? "\n\t\t\t\t"
1135
-                  . '<option value=""' . $selected . '>'
1135
+                  . '<option value=""'.$selected.'>'
1136 1136
                   . esc_html__(' - please select - ', 'event_espresso')
1137 1137
                   . '</option>'
1138 1138
                 : '';
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
                 );
1156 1156
         }
1157 1157
 
1158
-        $input_html .= "\n\t\t\t" . '</select>';
1158
+        $input_html .= "\n\t\t\t".'</select>';
1159 1159
 
1160 1160
         $input_html =
1161 1161
             apply_filters(
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
             );
1171 1171
 
1172 1172
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1173
-        return $label_html . $input_html;
1173
+        return $label_html.$input_html;
1174 1174
     }
1175 1175
 
1176 1176
 
@@ -1188,11 +1188,11 @@  discard block
 block discarded – undo
1188 1188
      */
1189 1189
     private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true)
1190 1190
     {
1191
-        $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">';
1191
+        $html = "\n\t\t\t\t".'<optgroup label="'.self::prep_option_value($opt_group).'">';
1192 1192
         foreach ($QSOs as $QSO) {
1193 1193
             $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities);
1194 1194
         }
1195
-        $html .= "\n\t\t\t\t" . '</optgroup>';
1195
+        $html .= "\n\t\t\t\t".'</optgroup>';
1196 1196
         return $html;
1197 1197
     }
1198 1198
 
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
         $value    = ! empty($value) ? $value : $key;
1220 1220
         $selected = ($answer == $key || $only_option) ? 'selected="selected"' : '';
1221 1221
         return "\n\t\t\t\t"
1222
-               . '<option value="' . self::prep_option_value($key) . '" ' . $selected . '> '
1222
+               . '<option value="'.self::prep_option_value($key).'" '.$selected.'> '
1223 1223
                . $value
1224 1224
                . '&nbsp;&nbsp;&nbsp;</option>';
1225 1225
     }
@@ -1263,7 +1263,7 @@  discard block
 block discarded – undo
1263 1263
         $use_desc_4_label = false
1264 1264
     ) {
1265 1265
         // need these
1266
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1266
+        if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1267 1267
             return null;
1268 1268
         }
1269 1269
         // prep the answer
@@ -1280,7 +1280,7 @@  discard block
 block discarded – undo
1280 1280
         $label_html =
1281 1281
             $required_text
1282 1282
             . "\n\t\t\t"
1283
-            . '<label class="' . $label_class . '">'
1283
+            . '<label class="'.$label_class.'">'
1284 1284
             . self::prep_question($question)
1285 1285
             . $required['label']
1286 1286
             . '</label> ';
@@ -1289,49 +1289,49 @@  discard block
 block discarded – undo
1289 1289
 
1290 1290
         $input_html =
1291 1291
             "\n\t\t\t"
1292
-            . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">';
1292
+            . '<ul id="'.$id.'-ul" class="espresso-radio-btn-options-ul '.$label_class.' '.$class.'-ul">';
1293 1293
 
1294
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1295
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1294
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
1295
+        $class .= ! empty($required['class']) ? ' '.$required['class'] : '';
1296 1296
 
1297 1297
         foreach ($options as $OPT) {
1298 1298
             if ($OPT instanceof EE_Question_Option) {
1299 1299
                 $value   = self::prep_option_value($OPT->value());
1300 1300
                 $label   = $use_desc_4_label ? $OPT->desc() : $OPT->value();
1301 1301
                 $size    = $use_desc_4_label
1302
-                    ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc())
1302
+                    ? self::get_label_size_class($OPT->value().' '.$OPT->desc())
1303 1303
                     : self::get_label_size_class($OPT->value());
1304
-                $desc    = $OPT->desc();// no self::prep_answer
1304
+                $desc    = $OPT->desc(); // no self::prep_answer
1305 1305
                 $answer  = is_numeric($value) && empty($answer) ? 0 : $answer;
1306 1306
                 $checked = (string) $value == (string) $answer ? ' checked="checked"' : '';
1307
-                $opt     = '-' . sanitize_key($value);
1307
+                $opt     = '-'.sanitize_key($value);
1308 1308
 
1309
-                $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1310
-                $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">';
1311
-                $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : '';
1309
+                $input_html .= "\n\t\t\t\t".'<li'.$size.'>';
1310
+                $input_html .= "\n\t\t\t\t\t".'<label class="'.$radio_class.' espresso-radio-btn-lbl">';
1311
+                $input_html .= $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$label.'</span>' : '';
1312 1312
                 $input_html .= "\n\t\t\t\t\t\t"
1313
-                               . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" '
1314
-                               . 'class="' . $class . '" value="' . $value . '" '
1315
-                               . 'title="' . esc_attr($required['msg']) . '" ' . $disabled
1316
-                               . $checked . ' ' . $extra . '/>';
1313
+                               . '<input type="radio" name="'.$name.'" id="'.$id.$opt.'" '
1314
+                               . 'class="'.$class.'" value="'.$value.'" '
1315
+                               . 'title="'.esc_attr($required['msg']).'" '.$disabled
1316
+                               . $checked.' '.$extra.'/>';
1317 1317
                 $input_html .= ! $label_b4
1318 1318
                     ? "\n\t\t\t\t\t\t"
1319 1319
                       . '<span class="espresso-radio-btn-desc">'
1320 1320
                       . $label
1321 1321
                       . '</span>'
1322 1322
                     : '';
1323
-                $input_html .= "\n\t\t\t\t\t" . '</label>';
1323
+                $input_html .= "\n\t\t\t\t\t".'</label>';
1324 1324
                 $input_html .= $use_desc_4_label
1325 1325
                     ? ''
1326
-                    : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>';
1327
-                $input_html .= "\n\t\t\t\t" . '</li>';
1326
+                    : '<span class="espresso-radio-btn-option-desc small-text grey-text">'.$desc.'</span>';
1327
+                $input_html .= "\n\t\t\t\t".'</li>';
1328 1328
             }
1329 1329
         }
1330 1330
 
1331
-        $input_html .= "\n\t\t\t" . '</ul>';
1331
+        $input_html .= "\n\t\t\t".'</ul>';
1332 1332
 
1333 1333
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1334
-        return $label_html . $input_html;
1334
+        return $label_html.$input_html;
1335 1335
     }
1336 1336
 
1337 1337
 
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
         $use_html_entities = true
1367 1367
     ) {
1368 1368
         // need these
1369
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1369
+        if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1370 1370
             return null;
1371 1371
         }
1372 1372
         $answer = maybe_unserialize($answer);
@@ -1376,7 +1376,7 @@  discard block
 block discarded – undo
1376 1376
 
1377 1377
         foreach ($answer as $key => $value) {
1378 1378
             $key            = self::prep_option_value($key);
1379
-            $answer[ $key ] = self::prep_answer($value, $use_html_entities);
1379
+            $answer[$key] = self::prep_answer($value, $use_html_entities);
1380 1380
         }
1381 1381
 
1382 1382
         // prep the required array
@@ -1391,7 +1391,7 @@  discard block
 block discarded – undo
1391 1391
         $label_html =
1392 1392
             $required_text
1393 1393
             . "\n\t\t\t"
1394
-            . '<label class="' . $label_class . '">'
1394
+            . '<label class="'.$label_class.'">'
1395 1395
             . self::prep_question($question)
1396 1396
             . $required['label']
1397 1397
             . '</label> ';
@@ -1400,42 +1400,42 @@  discard block
 block discarded – undo
1400 1400
 
1401 1401
         $input_html =
1402 1402
             "\n\t\t\t"
1403
-            . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">';
1403
+            . '<ul id="'.$id.'-ul" class="espresso-checkbox-options-ul '.$label_class.' '.$class.'-ul">';
1404 1404
 
1405
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1406
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1405
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
1406
+        $class .= ! empty($required['class']) ? ' '.$required['class'] : '';
1407 1407
 
1408 1408
         foreach ($options as $OPT) {
1409
-            $value = $OPT->value();// self::prep_option_value( $OPT->value() );
1410
-            $size  = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc());
1409
+            $value = $OPT->value(); // self::prep_option_value( $OPT->value() );
1410
+            $size  = self::get_label_size_class($OPT->value().' '.$OPT->desc());
1411 1411
             $text  = self::prep_answer($OPT->value());
1412 1412
             $desc  = $OPT->desc();
1413
-            $opt   = '-' . sanitize_key($value);
1413
+            $opt   = '-'.sanitize_key($value);
1414 1414
 
1415 1415
             $checked = is_array($answer) && in_array($text, $answer) ? ' checked="checked"' : '';
1416 1416
 
1417
-            $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1418
-            $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">';
1419
-            $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
1417
+            $input_html .= "\n\t\t\t\t".'<li'.$size.'>';
1418
+            $input_html .= "\n\t\t\t\t\t".'<label class="'.$radio_class.' espresso-checkbox-lbl">';
1419
+            $input_html .= $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$text.'</span>' : '';
1420 1420
             $input_html .= "\n\t\t\t\t\t\t"
1421
-                           . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" '
1422
-                           . 'id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" '
1423
-                           . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
1424
-            $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
1425
-            $input_html .= "\n\t\t\t\t\t" . '</label>';
1426
-            if (! empty($desc) && $desc != $text) {
1421
+                           . '<input type="checkbox" name="'.$name.'['.$OPT->ID().']" '
1422
+                           . 'id="'.$id.$opt.'" class="'.$class.'" value="'.$value.'" '
1423
+                           . 'title="'.esc_attr($required['msg']).'" '.$disabled.$checked.' '.$extra.'/>';
1424
+            $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$text.'</span>' : '';
1425
+            $input_html .= "\n\t\t\t\t\t".'</label>';
1426
+            if ( ! empty($desc) && $desc != $text) {
1427 1427
                 $input_html .= "\n\t\t\t\t\t"
1428 1428
                                . ' &nbsp; <br/><div class="espresso-checkbox-option-desc small-text grey-text">'
1429 1429
                                . $desc
1430 1430
                                . '</div>';
1431 1431
             }
1432
-            $input_html .= "\n\t\t\t\t" . '</li>';
1432
+            $input_html .= "\n\t\t\t\t".'</li>';
1433 1433
         }
1434 1434
 
1435
-        $input_html .= "\n\t\t\t" . '</ul>';
1435
+        $input_html .= "\n\t\t\t".'</ul>';
1436 1436
 
1437 1437
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1438
-        return $label_html . $input_html;
1438
+        return $label_html.$input_html;
1439 1439
     }
1440 1440
 
1441 1441
 
@@ -1467,7 +1467,7 @@  discard block
 block discarded – undo
1467 1467
         $use_html_entities = true
1468 1468
     ) {
1469 1469
         // need these
1470
-        if (! $question || ! $name) {
1470
+        if ( ! $question || ! $name) {
1471 1471
             return null;
1472 1472
         }
1473 1473
         // prep the answer
@@ -1479,13 +1479,13 @@  discard block
 block discarded – undo
1479 1479
         // ya gots ta have style man!!!
1480 1480
         $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp';
1481 1481
         $class     = empty($class) ? $txt_class : $class;
1482
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1482
+        $class     .= ! empty($system_ID) ? ' '.$system_ID : '';
1483 1483
         $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1484 1484
 
1485 1485
         $label_html =
1486 1486
             $required_text
1487 1487
             . "\n\t\t\t"
1488
-            . '<label for="' . $name . '" class="' . $label_class . '">'
1488
+            . '<label for="'.$name.'" class="'.$label_class.'">'
1489 1489
             . self::prep_question($question)
1490 1490
             . $required['label']
1491 1491
             . '</label><br/>';
@@ -1494,14 +1494,14 @@  discard block
 block discarded – undo
1494 1494
 
1495 1495
         $input_html =
1496 1496
             "\n\t\t\t"
1497
-            . '<input type="text" name="' . $name . '" id="' . $id . '" '
1498
-            . 'class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '"  '
1499
-            . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
1497
+            . '<input type="text" name="'.$name.'" id="'.$id.'" '
1498
+            . 'class="'.$class.' '.$required['class'].' datepicker" value="'.$answer.'"  '
1499
+            . 'title="'.esc_attr($required['msg']).'" '.$disabled.' '.$extra.'/>';
1500 1500
 
1501 1501
         // enqueue scripts
1502 1502
         wp_register_style(
1503 1503
             'espresso-ui-theme',
1504
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1504
+            EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1505 1505
             [],
1506 1506
             EVENT_ESPRESSO_VERSION
1507 1507
         );
@@ -1509,7 +1509,7 @@  discard block
 block discarded – undo
1509 1509
         wp_enqueue_script('jquery-ui-datepicker');
1510 1510
 
1511 1511
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1512
-        return $label_html . $input_html;
1512
+        return $label_html.$input_html;
1513 1513
     }
1514 1514
 
1515 1515
 
@@ -1536,7 +1536,7 @@  discard block
 block discarded – undo
1536 1536
     public static function hidden_input($name, $value, $id = '')
1537 1537
     {
1538 1538
         $id = ! empty($id) ? $id : $name;
1539
-        return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>';
1539
+        return '<input id="'.$id.'" type="hidden" name="'.$name.'" value="'.$value.'"/>';
1540 1540
     }
1541 1541
 
1542 1542
 
@@ -1581,7 +1581,7 @@  discard block
 block discarded – undo
1581 1581
         $prepped_answer_options = [];
1582 1582
         if (is_array($QSOs) && ! empty($QSOs)) {
1583 1583
             foreach ($QSOs as $key => $QSO) {
1584
-                if (! $QSO instanceof EE_Question_Option) {
1584
+                if ( ! $QSO instanceof EE_Question_Option) {
1585 1585
                     $QSO = EE_Question_Option::new_instance(
1586 1586
                         [
1587 1587
                             'QSO_value' => is_array($QSO) && isset($QSO['id'])
@@ -1594,7 +1594,7 @@  discard block
 block discarded – undo
1594 1594
                     );
1595 1595
                 }
1596 1596
                 if ($QSO->opt_group()) {
1597
-                    $prepped_answer_options[ $QSO->opt_group() ][] = $QSO;
1597
+                    $prepped_answer_options[$QSO->opt_group()][] = $QSO;
1598 1598
                 } else {
1599 1599
                     $prepped_answer_options[] = $QSO;
1600 1600
                 }
@@ -1806,7 +1806,7 @@  discard block
 block discarded – undo
1806 1806
         $options = [];
1807 1807
         for ($x = 1; $x <= 12; $x++) {
1808 1808
             $mm             = str_pad($x, 2, '0', STR_PAD_LEFT);
1809
-            $options[ $mm ] = $mm;
1809
+            $options[$mm] = $mm;
1810 1810
         }
1811 1811
         return EEH_Form_Fields::prep_answer_options($options);
1812 1812
     }
@@ -1824,7 +1824,7 @@  discard block
 block discarded – undo
1824 1824
         $next_decade  = $current_year + 10;
1825 1825
         for ($x = $current_year; $x <= $next_decade; $x++) {
1826 1826
             $yy             = str_pad($x, 2, '0', STR_PAD_LEFT);
1827
-            $options[ $yy ] = $yy;
1827
+            $options[$yy] = $yy;
1828 1828
         }
1829 1829
         return EEH_Form_Fields::prep_answer_options($options);
1830 1830
     }
@@ -1843,7 +1843,7 @@  discard block
 block discarded – undo
1843 1843
     public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1844 1844
     {
1845 1845
         $_where = [];
1846
-        if (! empty($status)) {
1846
+        if ( ! empty($status)) {
1847 1847
             $_where['STS_ID'] = $status;
1848 1848
         }
1849 1849
 
@@ -1862,7 +1862,7 @@  discard block
 block discarded – undo
1862 1862
         ];
1863 1863
 
1864 1864
         foreach ($regdtts as $regdtt) {
1865
-            $date      = $regdtt->reg_month . ' ' . $regdtt->reg_year;
1865
+            $date      = $regdtt->reg_month.' '.$regdtt->reg_year;
1866 1866
             $options[] = [
1867 1867
                 'text' => $date,
1868 1868
                 'id'   => $date,
@@ -1911,7 +1911,7 @@  discard block
 block discarded – undo
1911 1911
         // categories?
1912 1912
 
1913 1913
 
1914
-        if (! empty($evt_category)) {
1914
+        if ( ! empty($evt_category)) {
1915 1915
             $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1916 1916
             $where['Event.Term_Taxonomy.term_id']  = $evt_category;
1917 1917
         }
@@ -1934,8 +1934,8 @@  discard block
 block discarded – undo
1934 1934
         global $wp_locale;
1935 1935
 
1936 1936
         foreach ($DTTS as $DTT) {
1937
-            $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
1938
-            $id             = $DTT->dtt_month . ' ' . $DTT->dtt_year;
1937
+            $localized_date = $wp_locale->get_month($DTT->dtt_month_num).' '.$DTT->dtt_year;
1938
+            $id             = $DTT->dtt_month.' '.$DTT->dtt_year;
1939 1939
             $options[]      = [
1940 1940
                 'text' => $localized_date,
1941 1941
                 'id'   => $id,
@@ -2008,16 +2008,16 @@  discard block
 block discarded – undo
2008 2008
             return $btn;
2009 2009
         }
2010 2010
         $text = ! empty($text) ? $text : esc_html__('Submit', 'event_espresso');
2011
-        $btn  .= '<input id="' . $ID . '-btn" class="' . $class . '" '
2012
-                 . 'type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
2013
-        if (! $input_only) {
2014
-            $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
2011
+        $btn .= '<input id="'.$ID.'-btn" class="'.$class.'" '
2012
+                 . 'type="submit" value="'.$text.'" '.$extra_attributes.'/>';
2013
+        if ( ! $input_only) {
2014
+            $btn_frm = '<form id="'.$ID.'-frm" method="POST" action="'.$url.'">';
2015 2015
             $btn_frm .= ! empty($nonce_action)
2016
-                ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false)
2016
+                ? wp_nonce_field($nonce_action, $nonce_action.'_nonce', true, false)
2017 2017
                 : '';
2018 2018
             $btn_frm .= $btn;
2019 2019
             $btn_frm .= '</form>';
2020
-            $btn     = $btn_frm;
2020
+            $btn = $btn_frm;
2021 2021
             unset($btn_frm);
2022 2022
         }
2023 2023
         return $btn;
Please login to merge, or discard this patch.
Indentation   +1971 added lines, -1971 removed lines patch added patch discarded remove patch
@@ -29,1997 +29,1997 @@
 block discarded – undo
29 29
 {
30 30
 
31 31
 
32
-    /**
33
-     *  Generates HTML for the forms used on admin pages
34
-     *
35
-     *
36
-     * @static
37
-     * @access public
38
-     * @param array $input_vars - array of input field details
39
-     *                          format:
40
-     *                          $template_form_fields['field-id'] = array(
41
-     *                          'name' => 'name_attribute',
42
-     *                          'label' => esc_html__('Field Label', 'event_espresso'), //or false
43
-     *                          'input' => 'hidden', //field input type can be 'text', 'select', 'textarea', 'hidden',
44
-     *                          'checkbox', 'wp_editor'
45
-     *                          'type' => 'int', //what "type" the value is (i.e. string, int etc)
46
-     *                          'required' => false, //boolean for whether the field is required
47
-     *                          'validation' => true, //boolean, whether to validate the field (todo)
48
-     *                          'value' => 'some_value_for_field', //what value is used for field
49
-     *                          'format' => '%d', //what format the value is (%d, %f, or %s)
50
-     *                          'db-col' => 'column_in_db' //used to indicate which column the field corresponds with
51
-     *                          in the db
52
-     *                          'options' => optiona, optionb || array('value' => 'label', '') //if the input type is
53
-     *                          "select", this allows you to set the args for the different <option> tags.
54
-     *                          'tabindex' => 1 //this allows you to set the tabindex for the field.
55
-     *                          'append_content' => '' //this allows you to send in html content to append to the
56
-     *                          field.
57
-     *                          )
58
-     * @param array $form_id    - used for defining unique identifiers for the form.
59
-     * @return string
60
-     * @todo   : at some point we can break this down into other static methods to abstract it a bit better.
61
-     */
62
-    public static function get_form_fields($input_vars = [], $form_id = false)
63
-    {
64
-
65
-        if (empty($input_vars)) {
66
-            EE_Error::add_error(
67
-                esc_html__('missing required variables for the form field generator', 'event_espresso'),
68
-                __FILE__,
69
-                __FUNCTION__,
70
-                __LINE__
71
-            );
72
-            return false;
73
-        }
74
-
75
-        $output        = "";
76
-        $inputs        = [];
77
-        $hidden_inputs = [];
78
-
79
-        // cycle thru inputs
80
-        foreach ($input_vars as $input_key => $input_value) {
81
-            $defaults = [
82
-                'append_content' => '',
83
-                'css_class'      => '',
84
-                'cols'           => 80,
85
-                'db-col'         => 'column_in_db',
86
-                'format'         => '%d',
87
-                'input'          => 'hidden',
88
-                'label'          => esc_html__('No label', 'event_espresso'),
89
-                'name'           => $input_key,
90
-                'options'        => [],
91
-                'required'       => false,
92
-                'tabindex'       => 0,
93
-                'rows'           => 10,
94
-                'type'           => 'int',
95
-                'validation'     => true,
96
-                'value'          => 'some_value_for_field',
97
-            ];
98
-
99
-            $input_value = wp_parse_args($input_value, $defaults);
100
-
101
-            $append_content = $input_value['append_content'];
102
-            $css_class      = $input_value['css_class'];
103
-            $cols           = $input_value['cols'];
104
-            $label          = $input_value['label'];
105
-            $name           = $input_value['name'];
106
-            $options        = $input_value['options'];
107
-            $required       = $input_value['required'];
108
-            $tab_index      = $input_value['tabindex'];
109
-            $rows           = $input_value['rows'];
110
-            $type           = $input_value['input'];
111
-            $value          = $input_value['value'];
112
-
113
-            $id    = $form_id ? $form_id . '-' . $input_key : $input_key;
114
-            $class = $required ? 'required ' . $css_class : $css_class;
115
-
116
-            // what type of input are we dealing with ?
117
-            switch ($type) {
118
-                case 'checkbox':
119
-                case 'radio':
120
-                    $field = self::adminMulti($value, $class, $id, $name, $required, $tab_index, $type, 1, $label);
121
-                    $field .= $append_content ?: '';
122
-                    break;
123
-
124
-                case 'hidden':
125
-                    $field           = null;
126
-                    $hidden_inputs[] = self::adminHidden($css_class, $id, $name, $value);
127
-                    break;
128
-
129
-                case 'select':
130
-                    $options = is_array($options) ? $options : explode(',', $options);
131
-                    $field   = self::adminLabel($id, $label, $required);
132
-                    $field   .= self::adminSelect($value, $class, $id, $name, $required, $tab_index, $options);
133
-                    $field   .= $append_content ?: '';
134
-                    break;
135
-
136
-                case 'textarea':
137
-                    $field = self::adminLabel($id, $label, $required);
138
-                    $field .= self::adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value);
139
-                    $field .= $append_content ?: '';
140
-                    break;
141
-
142
-                case 'wp_editor':
143
-                    $label = esc_html($label);
144
-                    $field = "<h4>{$label}</h4>";
145
-                    $field .= $append_content ?: '';
146
-                    $field .= self::adminWpEditor(
147
-                        $class,
148
-                        $id,
149
-                        $name,
150
-                        $rows,
151
-                        $tab_index,
152
-                        $value
153
-                    );
154
-                    break;
155
-
156
-                default:
157
-                    $field = self::adminLabel($id, $label, $required);
158
-                    $field .= self::adminText($class, $id, $name, $required, $tab_index, $value);
159
-                    $field .= $append_content ?: '';
160
-            }
161
-            if ($field) {
162
-                $inputs[] = $field;
163
-            }
164
-        } // end foreach( $input_vars as $input_key => $input_value )
165
-
166
-        if (! empty($inputs)) {
167
-            $glue   = "
32
+	/**
33
+	 *  Generates HTML for the forms used on admin pages
34
+	 *
35
+	 *
36
+	 * @static
37
+	 * @access public
38
+	 * @param array $input_vars - array of input field details
39
+	 *                          format:
40
+	 *                          $template_form_fields['field-id'] = array(
41
+	 *                          'name' => 'name_attribute',
42
+	 *                          'label' => esc_html__('Field Label', 'event_espresso'), //or false
43
+	 *                          'input' => 'hidden', //field input type can be 'text', 'select', 'textarea', 'hidden',
44
+	 *                          'checkbox', 'wp_editor'
45
+	 *                          'type' => 'int', //what "type" the value is (i.e. string, int etc)
46
+	 *                          'required' => false, //boolean for whether the field is required
47
+	 *                          'validation' => true, //boolean, whether to validate the field (todo)
48
+	 *                          'value' => 'some_value_for_field', //what value is used for field
49
+	 *                          'format' => '%d', //what format the value is (%d, %f, or %s)
50
+	 *                          'db-col' => 'column_in_db' //used to indicate which column the field corresponds with
51
+	 *                          in the db
52
+	 *                          'options' => optiona, optionb || array('value' => 'label', '') //if the input type is
53
+	 *                          "select", this allows you to set the args for the different <option> tags.
54
+	 *                          'tabindex' => 1 //this allows you to set the tabindex for the field.
55
+	 *                          'append_content' => '' //this allows you to send in html content to append to the
56
+	 *                          field.
57
+	 *                          )
58
+	 * @param array $form_id    - used for defining unique identifiers for the form.
59
+	 * @return string
60
+	 * @todo   : at some point we can break this down into other static methods to abstract it a bit better.
61
+	 */
62
+	public static function get_form_fields($input_vars = [], $form_id = false)
63
+	{
64
+
65
+		if (empty($input_vars)) {
66
+			EE_Error::add_error(
67
+				esc_html__('missing required variables for the form field generator', 'event_espresso'),
68
+				__FILE__,
69
+				__FUNCTION__,
70
+				__LINE__
71
+			);
72
+			return false;
73
+		}
74
+
75
+		$output        = "";
76
+		$inputs        = [];
77
+		$hidden_inputs = [];
78
+
79
+		// cycle thru inputs
80
+		foreach ($input_vars as $input_key => $input_value) {
81
+			$defaults = [
82
+				'append_content' => '',
83
+				'css_class'      => '',
84
+				'cols'           => 80,
85
+				'db-col'         => 'column_in_db',
86
+				'format'         => '%d',
87
+				'input'          => 'hidden',
88
+				'label'          => esc_html__('No label', 'event_espresso'),
89
+				'name'           => $input_key,
90
+				'options'        => [],
91
+				'required'       => false,
92
+				'tabindex'       => 0,
93
+				'rows'           => 10,
94
+				'type'           => 'int',
95
+				'validation'     => true,
96
+				'value'          => 'some_value_for_field',
97
+			];
98
+
99
+			$input_value = wp_parse_args($input_value, $defaults);
100
+
101
+			$append_content = $input_value['append_content'];
102
+			$css_class      = $input_value['css_class'];
103
+			$cols           = $input_value['cols'];
104
+			$label          = $input_value['label'];
105
+			$name           = $input_value['name'];
106
+			$options        = $input_value['options'];
107
+			$required       = $input_value['required'];
108
+			$tab_index      = $input_value['tabindex'];
109
+			$rows           = $input_value['rows'];
110
+			$type           = $input_value['input'];
111
+			$value          = $input_value['value'];
112
+
113
+			$id    = $form_id ? $form_id . '-' . $input_key : $input_key;
114
+			$class = $required ? 'required ' . $css_class : $css_class;
115
+
116
+			// what type of input are we dealing with ?
117
+			switch ($type) {
118
+				case 'checkbox':
119
+				case 'radio':
120
+					$field = self::adminMulti($value, $class, $id, $name, $required, $tab_index, $type, 1, $label);
121
+					$field .= $append_content ?: '';
122
+					break;
123
+
124
+				case 'hidden':
125
+					$field           = null;
126
+					$hidden_inputs[] = self::adminHidden($css_class, $id, $name, $value);
127
+					break;
128
+
129
+				case 'select':
130
+					$options = is_array($options) ? $options : explode(',', $options);
131
+					$field   = self::adminLabel($id, $label, $required);
132
+					$field   .= self::adminSelect($value, $class, $id, $name, $required, $tab_index, $options);
133
+					$field   .= $append_content ?: '';
134
+					break;
135
+
136
+				case 'textarea':
137
+					$field = self::adminLabel($id, $label, $required);
138
+					$field .= self::adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value);
139
+					$field .= $append_content ?: '';
140
+					break;
141
+
142
+				case 'wp_editor':
143
+					$label = esc_html($label);
144
+					$field = "<h4>{$label}</h4>";
145
+					$field .= $append_content ?: '';
146
+					$field .= self::adminWpEditor(
147
+						$class,
148
+						$id,
149
+						$name,
150
+						$rows,
151
+						$tab_index,
152
+						$value
153
+					);
154
+					break;
155
+
156
+				default:
157
+					$field = self::adminLabel($id, $label, $required);
158
+					$field .= self::adminText($class, $id, $name, $required, $tab_index, $value);
159
+					$field .= $append_content ?: '';
160
+			}
161
+			if ($field) {
162
+				$inputs[] = $field;
163
+			}
164
+		} // end foreach( $input_vars as $input_key => $input_value )
165
+
166
+		if (! empty($inputs)) {
167
+			$glue   = "
168 168
                 </li>
169 169
                 <li>
170 170
                     ";
171
-            $inputs = implode($glue, $inputs);
172
-            $output = "
171
+			$inputs = implode($glue, $inputs);
172
+			$output = "
173 173
             <ul>
174 174
                 <li>
175 175
                 {$inputs}
176 176
                 </li>
177 177
             </ul>
178 178
             ";
179
-        }
180
-        return $output . implode("\n", $hidden_inputs);
181
-    }
182
-
183
-
184
-    /**
185
-     * form_fields_array
186
-     * This utility function assembles form fields from a given structured array with field information.
187
-     * //TODO: This is an alternate generator that we may want to use instead.
188
-     *
189
-     * @param array $fields structured array of fields to assemble in the following format:
190
-     *                      [field_name] => array(
191
-     *                      ['label'] => 'label for field',
192
-     *                      ['labels'] => array('label_1', 'label_2'); //optional - if the field type is a multi select
193
-     *                      type of field you can indicated the labels for each option via this index
194
-     *                      ['extra_desc'] => 'extra description for the field', //optional
195
-     *                      ['type'] => 'textarea'|'text'|'wp_editor'|'checkbox'|'radio'|'hidden'|'select', //defaults
196
-     *                      to text
197
-     *                      ['value'] => 'value that goes in the field', //(if multi then this is an array of values
198
-     *                      and the 'default' paramater will be used for what is selected)
199
-     *                      ['default'] => 'default if the field type is multi (i.e. select or radios or checkboxes)',
200
-     *                      ['class'] => 'name-of-class(es)-for-input',
201
-     *                      ['classes'] => array('class_1', 'class_2'); //optional - if the field type is a multi
202
-     *                      select type of field you can indicate the css class for each option via this index.
203
-     *                      ['id'] => 'css-id-for-input') //defaults to 'field_name'
204
-     *                      ['unique_id'] => 1 //defaults to empty string.  This is useful for when the fields
205
-     *                      generated are going to be used in a loop and you want to make sure that the field
206
-     *                      identifiers are unique from each other.
207
-     *                      ['dimensions'] => array(100,300), //defaults to empty array.  This is used by field types
208
-     *                      such as textarea to indicate cols/rows.
209
-     *                      ['tabindex'] => '' //this allows you to set the tabindex for the field.
210
-     *                      ['wpeditor_args'] => array() //if the type of field is wpeditor then this can optionally
211
-     *                      contain an array of arguments for the editor setup.
212
-     *
213
-     * @return array         an array of inputs for form indexed by field name, and in the following structure:
214
-     *     [field_name] => array( 'label' => '{label_html}', 'field' => '{input_html}'
215
-     */
216
-    public static function get_form_fields_array($fields)
217
-    {
218
-
219
-        $form_fields = [];
220
-        $fields      = (array) $fields;
221
-
222
-        foreach ($fields as $field_name => $field_atts) {
223
-            // defaults:
224
-            $defaults = [
225
-                'class'         => '',
226
-                'classes'       => '',
227
-                'default'       => '',
228
-                'dimensions'    => ['10', '5'],
229
-                'extra_desc'    => '',
230
-                'id'            => $field_name,
231
-                'label'         => '',
232
-                'labels'        => '',
233
-                'required'      => false,
234
-                'tabindex'      => 0,
235
-                'type'          => 'text',
236
-                'unique_id'     => '',
237
-                'value'         => '',
238
-                'wpeditor_args' => [],
239
-            ];
240
-            // merge defaults with passed arguments
241
-            $_fields = wp_parse_args($field_atts, $defaults);
242
-
243
-            $class          = $_fields['class'];
244
-            $classes        = $_fields['classes'];
245
-            $default        = $_fields['default'];
246
-            $dims           = $_fields['dimensions'];
247
-            $extra_desc     = $_fields['extra_desc'];
248
-            $id             = $_fields['id'];
249
-            $label          = $_fields['label'];
250
-            $labels         = $_fields['labels'];
251
-            $required       = $_fields['required'];
252
-            $tab_index      = $_fields['tabindex'];
253
-            $type           = $_fields['type'];
254
-            $unique_id      = $_fields['unique_id'];
255
-            $value          = $_fields['value'];
256
-            $wp_editor_args = $_fields['wpeditor_args'];
257
-
258
-            // generate label
259
-            $label = ! empty($label) ? self::adminLabel($id, $label, $required) : '';
260
-            // generate field name
261
-            $name = ! empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name;
262
-
263
-            // we determine what we're building based on the type
264
-            switch ($type) {
265
-                case 'checkbox':
266
-                case 'radio':
267
-                    if (is_array($value)) {
268
-                        $c_input = '';
269
-                        foreach ($value as $key => $val) {
270
-                            $c_input .= self::adminMulti(
271
-                                $default,
272
-                                isset($classes[ $key ]) ? $classes[ $key ] : '',
273
-                                $field_name . '_' . $value,
274
-                                $name,
275
-                                $required,
276
-                                $tab_index,
277
-                                $type,
278
-                                $val,
279
-                                isset($labels[ $key ]) ? $labels[ $key ] : ''
280
-                            );
281
-                        }
282
-                        $field = $c_input;
283
-                    } else {
284
-                        $field = self::adminMulti(
285
-                            $default,
286
-                            $class,
287
-                            $id,
288
-                            $name,
289
-                            $required,
290
-                            $tab_index,
291
-                            $type,
292
-                            $value,
293
-                            $_fields['label']
294
-                        );
295
-                    }
296
-                    break;
297
-
298
-                case 'hidden':
299
-                    $field = self::adminHidden($class, $id, $name, $value);
300
-                    break;
301
-
302
-                case 'select':
303
-                    $options = [];
304
-                    foreach ($value as $key => $val) {
305
-                        $options[ $val ] = isset($labels[ $key ]) ? $labels[ $key ] : '';
306
-                    }
307
-                    $field = self::adminSelect($default, $class, $id, $name, $required, $tab_index, $options);
308
-                    break;
309
-
310
-                case 'textarea':
311
-                    $field =
312
-                        self::adminTextarea($class, $dims[0], $id, $name, $required, $dims[1], $tab_index, $value);
313
-                    break;
314
-
315
-                case 'wp_editor':
316
-                    $field = self::adminWpEditor(
317
-                        $class,
318
-                        $_fields['id'],
319
-                        $name,
320
-                        $dims[1],
321
-                        $tab_index,
322
-                        $value,
323
-                        $wp_editor_args
324
-                    );
325
-                    break;
326
-
327
-                default:
328
-                    $field = self::adminText($class, $id, $name, $required, $tab_index, $value);
329
-            }
330
-
331
-            $form_fields[ $field_name ] = ['label' => $label, 'field' => $field . $extra_desc];
332
-        }
333
-
334
-        return $form_fields;
335
-    }
336
-
337
-
338
-    /**
339
-     * @param string $class
340
-     * @param string $id
341
-     * @param string $name
342
-     * @param string $value
343
-     * @return string
344
-     * @since   4.10.14.p
345
-     */
346
-    private static function adminHidden($class, $id, $name, $value)
347
-    {
348
-        $id    = esc_attr($id);
349
-        $name  = esc_attr($name);
350
-        $class = esc_attr($class);
351
-        return "
179
+		}
180
+		return $output . implode("\n", $hidden_inputs);
181
+	}
182
+
183
+
184
+	/**
185
+	 * form_fields_array
186
+	 * This utility function assembles form fields from a given structured array with field information.
187
+	 * //TODO: This is an alternate generator that we may want to use instead.
188
+	 *
189
+	 * @param array $fields structured array of fields to assemble in the following format:
190
+	 *                      [field_name] => array(
191
+	 *                      ['label'] => 'label for field',
192
+	 *                      ['labels'] => array('label_1', 'label_2'); //optional - if the field type is a multi select
193
+	 *                      type of field you can indicated the labels for each option via this index
194
+	 *                      ['extra_desc'] => 'extra description for the field', //optional
195
+	 *                      ['type'] => 'textarea'|'text'|'wp_editor'|'checkbox'|'radio'|'hidden'|'select', //defaults
196
+	 *                      to text
197
+	 *                      ['value'] => 'value that goes in the field', //(if multi then this is an array of values
198
+	 *                      and the 'default' paramater will be used for what is selected)
199
+	 *                      ['default'] => 'default if the field type is multi (i.e. select or radios or checkboxes)',
200
+	 *                      ['class'] => 'name-of-class(es)-for-input',
201
+	 *                      ['classes'] => array('class_1', 'class_2'); //optional - if the field type is a multi
202
+	 *                      select type of field you can indicate the css class for each option via this index.
203
+	 *                      ['id'] => 'css-id-for-input') //defaults to 'field_name'
204
+	 *                      ['unique_id'] => 1 //defaults to empty string.  This is useful for when the fields
205
+	 *                      generated are going to be used in a loop and you want to make sure that the field
206
+	 *                      identifiers are unique from each other.
207
+	 *                      ['dimensions'] => array(100,300), //defaults to empty array.  This is used by field types
208
+	 *                      such as textarea to indicate cols/rows.
209
+	 *                      ['tabindex'] => '' //this allows you to set the tabindex for the field.
210
+	 *                      ['wpeditor_args'] => array() //if the type of field is wpeditor then this can optionally
211
+	 *                      contain an array of arguments for the editor setup.
212
+	 *
213
+	 * @return array         an array of inputs for form indexed by field name, and in the following structure:
214
+	 *     [field_name] => array( 'label' => '{label_html}', 'field' => '{input_html}'
215
+	 */
216
+	public static function get_form_fields_array($fields)
217
+	{
218
+
219
+		$form_fields = [];
220
+		$fields      = (array) $fields;
221
+
222
+		foreach ($fields as $field_name => $field_atts) {
223
+			// defaults:
224
+			$defaults = [
225
+				'class'         => '',
226
+				'classes'       => '',
227
+				'default'       => '',
228
+				'dimensions'    => ['10', '5'],
229
+				'extra_desc'    => '',
230
+				'id'            => $field_name,
231
+				'label'         => '',
232
+				'labels'        => '',
233
+				'required'      => false,
234
+				'tabindex'      => 0,
235
+				'type'          => 'text',
236
+				'unique_id'     => '',
237
+				'value'         => '',
238
+				'wpeditor_args' => [],
239
+			];
240
+			// merge defaults with passed arguments
241
+			$_fields = wp_parse_args($field_atts, $defaults);
242
+
243
+			$class          = $_fields['class'];
244
+			$classes        = $_fields['classes'];
245
+			$default        = $_fields['default'];
246
+			$dims           = $_fields['dimensions'];
247
+			$extra_desc     = $_fields['extra_desc'];
248
+			$id             = $_fields['id'];
249
+			$label          = $_fields['label'];
250
+			$labels         = $_fields['labels'];
251
+			$required       = $_fields['required'];
252
+			$tab_index      = $_fields['tabindex'];
253
+			$type           = $_fields['type'];
254
+			$unique_id      = $_fields['unique_id'];
255
+			$value          = $_fields['value'];
256
+			$wp_editor_args = $_fields['wpeditor_args'];
257
+
258
+			// generate label
259
+			$label = ! empty($label) ? self::adminLabel($id, $label, $required) : '';
260
+			// generate field name
261
+			$name = ! empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name;
262
+
263
+			// we determine what we're building based on the type
264
+			switch ($type) {
265
+				case 'checkbox':
266
+				case 'radio':
267
+					if (is_array($value)) {
268
+						$c_input = '';
269
+						foreach ($value as $key => $val) {
270
+							$c_input .= self::adminMulti(
271
+								$default,
272
+								isset($classes[ $key ]) ? $classes[ $key ] : '',
273
+								$field_name . '_' . $value,
274
+								$name,
275
+								$required,
276
+								$tab_index,
277
+								$type,
278
+								$val,
279
+								isset($labels[ $key ]) ? $labels[ $key ] : ''
280
+							);
281
+						}
282
+						$field = $c_input;
283
+					} else {
284
+						$field = self::adminMulti(
285
+							$default,
286
+							$class,
287
+							$id,
288
+							$name,
289
+							$required,
290
+							$tab_index,
291
+							$type,
292
+							$value,
293
+							$_fields['label']
294
+						);
295
+					}
296
+					break;
297
+
298
+				case 'hidden':
299
+					$field = self::adminHidden($class, $id, $name, $value);
300
+					break;
301
+
302
+				case 'select':
303
+					$options = [];
304
+					foreach ($value as $key => $val) {
305
+						$options[ $val ] = isset($labels[ $key ]) ? $labels[ $key ] : '';
306
+					}
307
+					$field = self::adminSelect($default, $class, $id, $name, $required, $tab_index, $options);
308
+					break;
309
+
310
+				case 'textarea':
311
+					$field =
312
+						self::adminTextarea($class, $dims[0], $id, $name, $required, $dims[1], $tab_index, $value);
313
+					break;
314
+
315
+				case 'wp_editor':
316
+					$field = self::adminWpEditor(
317
+						$class,
318
+						$_fields['id'],
319
+						$name,
320
+						$dims[1],
321
+						$tab_index,
322
+						$value,
323
+						$wp_editor_args
324
+					);
325
+					break;
326
+
327
+				default:
328
+					$field = self::adminText($class, $id, $name, $required, $tab_index, $value);
329
+			}
330
+
331
+			$form_fields[ $field_name ] = ['label' => $label, 'field' => $field . $extra_desc];
332
+		}
333
+
334
+		return $form_fields;
335
+	}
336
+
337
+
338
+	/**
339
+	 * @param string $class
340
+	 * @param string $id
341
+	 * @param string $name
342
+	 * @param string $value
343
+	 * @return string
344
+	 * @since   4.10.14.p
345
+	 */
346
+	private static function adminHidden($class, $id, $name, $value)
347
+	{
348
+		$id    = esc_attr($id);
349
+		$name  = esc_attr($name);
350
+		$class = esc_attr($class);
351
+		return "
352 352
         <input name='{$name}' type='hidden' id='{$id}' class='{$class}' value='{$value}' />";
353
-    }
354
-
355
-
356
-    /**
357
-     * @param string $id
358
-     * @param string $label
359
-     * @param string $required
360
-     * @return string
361
-     * @since   4.10.14.p
362
-     */
363
-    private static function adminLabel($id, $label, $required)
364
-    {
365
-        $id       = esc_attr($id);
366
-        $label    = esc_html($label);
367
-        $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? " <span>*</span>" : '';
368
-        return "<label for='{$id}'>{$label}{$required}</label>";
369
-    }
370
-
371
-
372
-    /**
373
-     * @param string $default
374
-     * @param string $class
375
-     * @param string $id
376
-     * @param string $name
377
-     * @param string $required
378
-     * @param int    $tab_index
379
-     * @param string $type
380
-     * @param string $value
381
-     * @param string $label
382
-     * @return string
383
-     * @since   4.10.14.p
384
-     */
385
-    private static function adminMulti($default, $class, $id, $name, $required, $tab_index, $type, $value, $label = '')
386
-    {
387
-        $id        = esc_attr($id);
388
-        $name      = esc_attr($name);
389
-        $class     = esc_attr($class);
390
-        $tab_index = absint($tab_index);
391
-        $checked   = ! empty($default) && $default == $value ? 'checked="checked" ' : '';
392
-        $required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
393
-        $input     = "
353
+	}
354
+
355
+
356
+	/**
357
+	 * @param string $id
358
+	 * @param string $label
359
+	 * @param string $required
360
+	 * @return string
361
+	 * @since   4.10.14.p
362
+	 */
363
+	private static function adminLabel($id, $label, $required)
364
+	{
365
+		$id       = esc_attr($id);
366
+		$label    = esc_html($label);
367
+		$required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? " <span>*</span>" : '';
368
+		return "<label for='{$id}'>{$label}{$required}</label>";
369
+	}
370
+
371
+
372
+	/**
373
+	 * @param string $default
374
+	 * @param string $class
375
+	 * @param string $id
376
+	 * @param string $name
377
+	 * @param string $required
378
+	 * @param int    $tab_index
379
+	 * @param string $type
380
+	 * @param string $value
381
+	 * @param string $label
382
+	 * @return string
383
+	 * @since   4.10.14.p
384
+	 */
385
+	private static function adminMulti($default, $class, $id, $name, $required, $tab_index, $type, $value, $label = '')
386
+	{
387
+		$id        = esc_attr($id);
388
+		$name      = esc_attr($name);
389
+		$class     = esc_attr($class);
390
+		$tab_index = absint($tab_index);
391
+		$checked   = ! empty($default) && $default == $value ? 'checked="checked" ' : '';
392
+		$required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
393
+		$input     = "
394 394
         <input name='{$name}[]' type='{$type}' id='{$id}' class='{$class}' value='{$value}' {$checked} {$required} tabindex='{$tab_index}'/>";
395
-        if ($label === '') {
396
-            return $input;
397
-        }
398
-        $label = esc_html($label);
399
-        return "
395
+		if ($label === '') {
396
+			return $input;
397
+		}
398
+		$label = esc_html($label);
399
+		return "
400 400
         <label for='$id'>
401 401
             {$input}
402 402
             {$label}
403 403
         </label>";
404
-    }
405
-
406
-
407
-    /**
408
-     * @param string $default
409
-     * @param string $class
410
-     * @param string $id
411
-     * @param string $name
412
-     * @param string $required
413
-     * @param int    $tab_index
414
-     * @param array  $options
415
-     * @return string
416
-     * @since   4.10.14.p
417
-     */
418
-    private static function adminSelect($default, $class, $id, $name, $required, $tab_index, $options = [])
419
-    {
420
-        $options_array = [];
421
-        foreach ($options as $value => $label) {
422
-            $selected        = ! empty($default) && $default == $value ? 'selected="selected"' : '';
423
-            $value           = esc_attr($value);
424
-            $label           = wp_strip_all_tags($label);
425
-            $options_array[] = "<option value='{$value}' {$selected}>{$label}</option>";
426
-        }
427
-        $options_html = implode($options_array, "\n");
428
-        $id           = esc_attr($id);
429
-        $name         = esc_attr($name);
430
-        $class        = esc_attr($class);
431
-        $tab_index    = absint($tab_index);
432
-        $required     = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
433
-        return "
404
+	}
405
+
406
+
407
+	/**
408
+	 * @param string $default
409
+	 * @param string $class
410
+	 * @param string $id
411
+	 * @param string $name
412
+	 * @param string $required
413
+	 * @param int    $tab_index
414
+	 * @param array  $options
415
+	 * @return string
416
+	 * @since   4.10.14.p
417
+	 */
418
+	private static function adminSelect($default, $class, $id, $name, $required, $tab_index, $options = [])
419
+	{
420
+		$options_array = [];
421
+		foreach ($options as $value => $label) {
422
+			$selected        = ! empty($default) && $default == $value ? 'selected="selected"' : '';
423
+			$value           = esc_attr($value);
424
+			$label           = wp_strip_all_tags($label);
425
+			$options_array[] = "<option value='{$value}' {$selected}>{$label}</option>";
426
+		}
427
+		$options_html = implode($options_array, "\n");
428
+		$id           = esc_attr($id);
429
+		$name         = esc_attr($name);
430
+		$class        = esc_attr($class);
431
+		$tab_index    = absint($tab_index);
432
+		$required     = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
433
+		return "
434 434
         <select name='{$name}' id='{$id}' class='{$class}' {$required} tabindex='{$tab_index}'>
435 435
             {$options_html}
436 436
         </select>";
437
-    }
438
-
439
-
440
-    /**
441
-     * @param string $class
442
-     * @param string $id
443
-     * @param string $name
444
-     * @param string $required
445
-     * @param int    $tab_index
446
-     * @param string $value
447
-     * @return string
448
-     * @since   4.10.14.p
449
-     */
450
-    private static function adminText($class, $id, $name, $required, $tab_index, $value)
451
-    {
452
-        $id        = esc_attr($id);
453
-        $name      = esc_attr($name);
454
-        $class     = esc_attr($class);
455
-        $tab_index = absint($tab_index);
456
-        $required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
457
-        return "
437
+	}
438
+
439
+
440
+	/**
441
+	 * @param string $class
442
+	 * @param string $id
443
+	 * @param string $name
444
+	 * @param string $required
445
+	 * @param int    $tab_index
446
+	 * @param string $value
447
+	 * @return string
448
+	 * @since   4.10.14.p
449
+	 */
450
+	private static function adminText($class, $id, $name, $required, $tab_index, $value)
451
+	{
452
+		$id        = esc_attr($id);
453
+		$name      = esc_attr($name);
454
+		$class     = esc_attr($class);
455
+		$tab_index = absint($tab_index);
456
+		$required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
457
+		return "
458 458
         <input name='{$name}' type='text' id='{$id}' class='{$class}' value='{$value}' {$required} tabindex='{$tab_index}'/>";
459
-    }
460
-
461
-
462
-    /**
463
-     * @param string $class
464
-     * @param int    $cols
465
-     * @param string $id
466
-     * @param string $name
467
-     * @param string $required
468
-     * @param int    $rows
469
-     * @param int    $tab_index
470
-     * @param string $value
471
-     * @return string
472
-     * @since   4.10.14.p
473
-     */
474
-    private static function adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value)
475
-    {
476
-        $id        = esc_attr($id);
477
-        $name      = esc_attr($name);
478
-        $class     = esc_attr($class);
479
-        $cols      = absint($cols);
480
-        $rows      = absint($rows);
481
-        $value     = esc_textarea($value);
482
-        $tab_index = absint($tab_index);
483
-        $required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
484
-        return "
459
+	}
460
+
461
+
462
+	/**
463
+	 * @param string $class
464
+	 * @param int    $cols
465
+	 * @param string $id
466
+	 * @param string $name
467
+	 * @param string $required
468
+	 * @param int    $rows
469
+	 * @param int    $tab_index
470
+	 * @param string $value
471
+	 * @return string
472
+	 * @since   4.10.14.p
473
+	 */
474
+	private static function adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value)
475
+	{
476
+		$id        = esc_attr($id);
477
+		$name      = esc_attr($name);
478
+		$class     = esc_attr($class);
479
+		$cols      = absint($cols);
480
+		$rows      = absint($rows);
481
+		$value     = esc_textarea($value);
482
+		$tab_index = absint($tab_index);
483
+		$required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
484
+		return "
485 485
         <textarea name='{$name}' id='{$id}' class='{$class}' rows='{$rows}' cols='{$cols}' {$required} tabindex='{$tab_index}'>
486 486
             {$value}
487 487
         </textarea>";
488
-    }
489
-
490
-
491
-    /**
492
-     * @param string $class
493
-     * @param string $id
494
-     * @param string $name
495
-     * @param int    $rows
496
-     * @param int    $tab_index
497
-     * @param string $value
498
-     * @param array  $wp_editor_args
499
-     * @return false|string
500
-     * @since   4.10.14.p
501
-     */
502
-    private static function adminWpEditor($class, $id, $name, $rows, $tab_index, $value, $wp_editor_args = [])
503
-    {
504
-        $editor_settings = $wp_editor_args + [
505
-                'textarea_name' => esc_attr($name),
506
-                'textarea_rows' => absint($rows),
507
-                'editor_class'  => esc_attr($class),
508
-                'tabindex'      => absint($tab_index),
509
-            ];
510
-        ob_start();
511
-        wp_editor($value, esc_attr($id), $editor_settings);
512
-        return ob_get_clean();
513
-    }
514
-
515
-
516
-    /**
517
-     * espresso admin page select_input
518
-     * Turns an array into a select fields
519
-     *
520
-     * @static
521
-     * @access public
522
-     * @param string  $name       field name
523
-     * @param array   $values     option values, numbered array starting at 0, where each value is an array with a key
524
-     *                            'text' (meaning text to display' and 'id' (meaning the internal value) eg:
525
-     *                            array(1=>array('text'=>'Monday','id'=>1),2=>array('text'=>'Tuesday','id'=>2)...). or
526
-     *                            as an array of key-value pairs, where the key is to be used for the select input's
527
-     *                            name, and the value will be the text shown to the user.  Optionally you can also
528
-     *                            include an additional key of "class" which will add a specific class to the option
529
-     *                            for that value.
530
-     * @param string  $default    default value
531
-     * @param string  $parameters extra parameters
532
-     * @param string  $class      css class
533
-     * @param boolean $autosize   whether to autosize the select or not
534
-     * @return string              html string for the select input
535
-     */
536
-    public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true)
537
-    {
538
-        // if $values was submitted in the wrong format, convert it over
539
-        if (! empty($values) && (! array_key_exists(0, $values) || ! is_array($values[0]))) {
540
-            $converted_values = [];
541
-            foreach ($values as $id => $text) {
542
-                $converted_values[] = ['id' => $id, 'text' => $text];
543
-            }
544
-            $values = $converted_values;
545
-        }
546
-
547
-        $field =
548
-            '<select id="' . EEH_Formatter::ee_tep_output_string($name)
549
-            . '" name="' . EEH_Formatter::ee_tep_output_string($name)
550
-            . '"';
551
-
552
-        if (EEH_Formatter::ee_tep_not_null($parameters)) {
553
-            $field .= ' ' . $parameters;
554
-        }
555
-        if ($autosize) {
556
-            $size = 'med';
557
-            for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) {
558
-                if ($values[ $ii ]['text']) {
559
-                    if (strlen($values[ $ii ]['text']) > 5) {
560
-                        $size = 'wide';
561
-                    }
562
-                }
563
-            }
564
-        } else {
565
-            $size = '';
566
-        }
567
-
568
-        $field .= ' class="' . $class . ' ' . $size . '">';
569
-
570
-        if (empty($default) && isset($GLOBALS[ $name ])) {
571
-            $default = stripslashes($GLOBALS[ $name ]);
572
-        }
573
-
574
-
575
-        for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
576
-            $field .= '<option value="' . $values[ $i ]['id'] . '"';
577
-            if ($default == $values[ $i ]['id']) {
578
-                $field .= ' selected = "selected"';
579
-            }
580
-            if (isset($values[ $i ]['class'])) {
581
-                $field .= ' class="' . $values[ $i ]['class'] . '"';
582
-            }
583
-            $field .= '>' . $values[ $i ]['text'] . '</option>';
584
-        }
585
-        $field .= '</select>';
586
-
587
-        return $field;
588
-    }
589
-
590
-
591
-    /**
592
-     * generate_question_groups_html
593
-     *
594
-     * @param array  $question_groups
595
-     * @param string $group_wrapper
596
-     * @return string HTML
597
-     * @throws EE_Error
598
-     * @throws ReflectionException
599
-     */
600
-    public static function generate_question_groups_html($question_groups = [], $group_wrapper = 'fieldset')
601
-    {
602
-
603
-        $html                            = '';
604
-        $before_question_group_questions =
605
-            apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
606
-        $after_question_group_questions  =
607
-            apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
608
-
609
-        if (! empty($question_groups)) {
610
-            // loop thru question groups
611
-            foreach ($question_groups as $QSG) {
612
-                // check that questions exist
613
-                if (! empty($QSG['QSG_questions'])) {
614
-                    // use fieldsets
615
-                    $html .= "\n\t"
616
-                             . '<'
617
-                             . $group_wrapper
618
-                             . ' class="espresso-question-group-wrap" id="'
619
-                             . $QSG['QSG_identifier']
620
-                             . '">';
621
-                    // group_name
622
-                    $html .= $QSG['QSG_show_group_name']
623
-                        ? "\n\t\t"
624
-                          . '<h5 class="espresso-question-group-title-h5 section-title">'
625
-                          . self::prep_answer($QSG['QSG_name'])
626
-                          . '</h5>'
627
-                        : '';
628
-                    // group_desc
629
-                    $html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc'])
630
-                        ? '<div class="espresso-question-group-desc-pg">'
631
-                          . self::prep_answer($QSG['QSG_desc'])
632
-                          . '</div>'
633
-                        : '';
634
-
635
-                    $html .= $before_question_group_questions;
636
-                    // loop thru questions
637
-                    foreach ($QSG['QSG_questions'] as $question) {
638
-                        $QFI  = new EE_Question_Form_Input(
639
-                            $question['qst_obj'],
640
-                            $question['ans_obj'],
641
-                            $question
642
-                        );
643
-                        $html .= self::generate_form_input($QFI);
644
-                    }
645
-                    $html .= $after_question_group_questions;
646
-                    $html .= "\n\t" . '</' . $group_wrapper . '>';
647
-                }
648
-            }
649
-        }
650
-
651
-        return $html;
652
-    }
653
-
654
-
655
-    /**
656
-     * generate_question_groups_html
657
-     *
658
-     * @param array  $question_groups
659
-     * @param array  $q_meta
660
-     * @param bool   $from_admin
661
-     * @param string $group_wrapper
662
-     * @return string HTML
663
-     * @throws EE_Error
664
-     * @throws ReflectionException
665
-     */
666
-    public static function generate_question_groups_html2(
667
-        $question_groups = [],
668
-        $q_meta = [],
669
-        $from_admin = false,
670
-        $group_wrapper = 'fieldset'
671
-    ) {
672
-
673
-        $html                            = '';
674
-        $before_question_group_questions =
675
-            apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
676
-        $after_question_group_questions  =
677
-            apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
678
-
679
-        $default_q_meta = [
680
-            'att_nmbr'    => 1,
681
-            'ticket_id'   => '',
682
-            'input_name'  => '',
683
-            'input_id'    => '',
684
-            'input_class' => '',
685
-        ];
686
-        $q_meta         = array_merge($default_q_meta, $q_meta);
687
-
688
-        if (! empty($question_groups)) {
689
-            // loop thru question groups
690
-            foreach ($question_groups as $QSG) {
691
-                if ($QSG instanceof EE_Question_Group) {
692
-                    // check that questions exist
693
-
694
-                    $where = ['QST_deleted' => 0];
695
-                    if (! $from_admin) {
696
-                        $where['QST_admin_only'] = 0;
697
-                    }
698
-                    $questions =
699
-                        $QSG->questions([$where, 'order_by' => ['Question_Group_Question.QGQ_order' => 'ASC']]);
700
-                    if (! empty($questions)) {
701
-                        // use fieldsets
702
-                        $html .= "\n\t"
703
-                                 . '<' . $group_wrapper . ' class="espresso-question-group-wrap" '
704
-                                 . 'id="' . $QSG->get('QSG_identifier') . '">';
705
-                        // group_name
706
-                        if ($QSG->show_group_name()) {
707
-                            $html .= "\n\t\t"
708
-                                     . '<h5 class="espresso-question-group-title-h5 section-title">'
709
-                                     . $QSG->get_pretty('QSG_name')
710
-                                     . '</h5>';
711
-                        }
712
-                        // group_desc
713
-                        if ($QSG->show_group_desc()) {
714
-                            $html .= '<div class="espresso-question-group-desc-pg">'
715
-                                     . $QSG->get_pretty('QSG_desc')
716
-                                     . '</div>';
717
-                        }
718
-
719
-                        $html .= $before_question_group_questions;
720
-                        // loop thru questions
721
-                        foreach ($questions as $QST) {
722
-                            $qstn_id = $QST->is_system_question() ? $QST->system_ID() : $QST->ID();
723
-
724
-                            $answer = null;
725
-
726
-                            /** @var RequestInterface $request */
727
-                            $request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
728
-                            $request_qstn = $request->getRequestParam('qstn', [], 'string', true);
729
-                            if (! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
730
-                                // check for answer in $request_qstn in case we are reprocessing a form after an error
731
-                                if (isset($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])) {
732
-                                    $answer = is_array($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])
733
-                                        ? $request_qstn[ $q_meta['input_id'] ][ $qstn_id ]
734
-                                        : sanitize_text_field($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]);
735
-                                }
736
-                            } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) {
737
-                                // attendee data from the session
738
-                                $answer =
739
-                                    isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null;
740
-                            }
741
-
742
-
743
-                            $QFI  = new EE_Question_Form_Input(
744
-                                $QST,
745
-                                EE_Answer::new_instance(
746
-                                    [
747
-                                        'ANS_ID'    => 0,
748
-                                        'QST_ID'    => 0,
749
-                                        'REG_ID'    => 0,
750
-                                        'ANS_value' => $answer,
751
-                                    ]
752
-                                ),
753
-                                $q_meta
754
-                            );
755
-                            $html .= self::generate_form_input($QFI);
756
-                        }
757
-                        $html .= $after_question_group_questions;
758
-                        $html .= "\n\t" . '</' . $group_wrapper . '>';
759
-                    }
760
-                }
761
-            }
762
-        }
763
-        return $html;
764
-    }
765
-
766
-
767
-    /**
768
-     * generate_form_input
769
-     *
770
-     * @param EE_Question_Form_Input $QFI
771
-     * @return string HTML
772
-     * @throws EE_Error
773
-     * @throws ReflectionException
774
-     */
775
-    public static function generate_form_input(EE_Question_Form_Input $QFI)
776
-    {
777
-        if (isset($QFI->QST_admin_only) && $QFI->QST_admin_only && ! is_admin()) {
778
-            return '';
779
-        }
780
-        /** @var RequestInterface $request */
781
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
782
-
783
-        $QFI = self::_load_system_dropdowns($QFI);
784
-        $QFI = self::_load_specialized_dropdowns($QFI);
785
-
786
-        // we also need to verify
787
-
788
-        $display_text = $QFI->get('QST_display_text');
789
-        $input_name   = $QFI->get('QST_input_name');
790
-        $answer       = $request->getRequestParam($input_name, $QFI->get('ANS_value'));
791
-        $input_id     = $QFI->get('QST_input_id');
792
-        $input_class  = $QFI->get('QST_input_class');
793
-        //      $disabled = $QFI->get('QST_disabled') ? ' disabled="disabled"' : '';
794
-        $disabled          = $QFI->get('QST_disabled');
795
-        $required_label    = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>');
796
-        $QST_required      = $QFI->get('QST_required');
797
-        $required          =
798
-            $QST_required
799
-                ? ['label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required]
800
-                : [];
801
-        $use_html_entities = $QFI->get_meta('htmlentities');
802
-        $required_text     =
803
-            $QFI->get('QST_required_text') != ''
804
-                ? $QFI->get('QST_required_text')
805
-                : esc_html__('This field is required', 'event_espresso');
806
-        $required_text     = $QST_required
807
-            ? "\n\t\t\t"
808
-              . '<div class="required-text hidden">'
809
-              . self::prep_answer($required_text, $use_html_entities)
810
-              . '</div>'
811
-            : '';
812
-        $label_class       = 'espresso-form-input-lbl';
813
-        $QST_options       = $QFI->options(true, $answer);
814
-        $options           = is_array($QST_options) ? self::prep_answer_options($QST_options) : [];
815
-        $system_ID         = $QFI->get('QST_system');
816
-        $label_b4          = $QFI->get_meta('label_b4');
817
-        $use_desc_4_label  = $QFI->get_meta('use_desc_4_label');
818
-
819
-
820
-        switch ($QFI->get('QST_type')) {
821
-            case 'TEXTAREA':
822
-                return EEH_Form_Fields::textarea(
823
-                    $display_text,
824
-                    $answer,
825
-                    $input_name,
826
-                    $input_id,
827
-                    $input_class,
828
-                    [],
829
-                    $required,
830
-                    $required_text,
831
-                    $label_class,
832
-                    $disabled,
833
-                    $system_ID,
834
-                    $use_html_entities
835
-                );
836
-
837
-            case 'DROPDOWN':
838
-                return EEH_Form_Fields::select(
839
-                    $display_text,
840
-                    $answer,
841
-                    $options,
842
-                    $input_name,
843
-                    $input_id,
844
-                    $input_class,
845
-                    $required,
846
-                    $required_text,
847
-                    $label_class,
848
-                    $disabled,
849
-                    $system_ID,
850
-                    $use_html_entities,
851
-                    true
852
-                );
853
-
854
-
855
-            case 'RADIO_BTN':
856
-                return EEH_Form_Fields::radio(
857
-                    $display_text,
858
-                    $answer,
859
-                    $options,
860
-                    $input_name,
861
-                    $input_id,
862
-                    $input_class,
863
-                    $required,
864
-                    $required_text,
865
-                    $label_class,
866
-                    $disabled,
867
-                    $system_ID,
868
-                    $use_html_entities,
869
-                    $label_b4,
870
-                    $use_desc_4_label
871
-                );
872
-
873
-            case 'CHECKBOX':
874
-                return EEH_Form_Fields::checkbox(
875
-                    $display_text,
876
-                    $answer,
877
-                    $options,
878
-                    $input_name,
879
-                    $input_id,
880
-                    $input_class,
881
-                    $required,
882
-                    $required_text,
883
-                    $label_class,
884
-                    $disabled,
885
-                    $label_b4,
886
-                    $system_ID,
887
-                    $use_html_entities
888
-                );
889
-
890
-            case 'DATE':
891
-                return EEH_Form_Fields::datepicker(
892
-                    $display_text,
893
-                    $answer,
894
-                    $input_name,
895
-                    $input_id,
896
-                    $input_class,
897
-                    $required,
898
-                    $required_text,
899
-                    $label_class,
900
-                    $disabled,
901
-                    $system_ID,
902
-                    $use_html_entities
903
-                );
904
-
905
-            case 'TEXT':
906
-            default:
907
-                return EEH_Form_Fields::text(
908
-                    $display_text,
909
-                    $answer,
910
-                    $input_name,
911
-                    $input_id,
912
-                    $input_class,
913
-                    $required,
914
-                    $required_text,
915
-                    $label_class,
916
-                    $disabled,
917
-                    $system_ID,
918
-                    $use_html_entities
919
-                );
920
-        }
921
-    }
922
-
923
-
924
-    /**
925
-     * generates HTML for a form text input
926
-     *
927
-     * @param string $question    label content
928
-     * @param string $answer      form input value attribute
929
-     * @param string $name        form input name attribute
930
-     * @param string $id          form input css id attribute
931
-     * @param string $class       form input css class attribute
932
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
933
-     *                            required 'class', and required 'msg' attribute
934
-     * @param string $label_class css class attribute for the label
935
-     * @param string $disabled    disabled="disabled" or null
936
-     * @return string HTML
937
-     */
938
-    public static function text(
939
-        $question = false,
940
-        $answer = null,
941
-        $name = false,
942
-        $id = '',
943
-        $class = '',
944
-        $required = false,
945
-        $required_text = '',
946
-        $label_class = '',
947
-        $disabled = false,
948
-        $system_ID = false,
949
-        $use_html_entities = true
950
-    ) {
951
-        // need these
952
-        if (! $question || ! $name) {
953
-            return null;
954
-        }
955
-        // prep the answer
956
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
957
-        // prep the required array
958
-        $required = self::prep_required($required);
959
-        // set disabled tag
960
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
961
-        // ya gots ta have style man!!!
962
-        $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp';
963
-        $class     = empty($class) ? $txt_class : $class;
964
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
965
-        $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
966
-
967
-        $label_html =
968
-            $required_text
969
-            . "\n\t\t\t"
970
-            . '<label for="' . $name . '" class="' . $label_class . '">'
971
-            . self::prep_question($question)
972
-            . $required['label']
973
-            . '</label><br/>';
974
-        // filter label but ensure required text comes before it
975
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
976
-
977
-        $input_html =
978
-            "\n\t\t\t"
979
-            . '<input type="text" name="' . $name . '" id="' . $id . '" '
980
-            . 'class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '"  '
981
-            . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
982
-
983
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
984
-        return $label_html . $input_html;
985
-    }
986
-
987
-
988
-    /**
989
-     * generates HTML for a form textarea
990
-     *
991
-     * @param string $question    label content
992
-     * @param string $answer      form input value attribute
993
-     * @param string $name        form input name attribute
994
-     * @param string $id          form input css id attribute
995
-     * @param string $class       form input css class attribute
996
-     * @param array  $dimensions  array of form input rows and cols attributes : array( 'rows' => 3, 'cols' => 40 )
997
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
998
-     *                            required 'class', and required 'msg' attribute
999
-     * @param string $label_class css class attribute for the label
1000
-     * @param string $disabled    disabled="disabled" or null
1001
-     * @return string HTML
1002
-     */
1003
-    public static function textarea(
1004
-        $question = false,
1005
-        $answer = null,
1006
-        $name = false,
1007
-        $id = '',
1008
-        $class = '',
1009
-        $dimensions = false,
1010
-        $required = false,
1011
-        $required_text = '',
1012
-        $label_class = '',
1013
-        $disabled = false,
1014
-        $system_ID = false,
1015
-        $use_html_entities = true
1016
-    ) {
1017
-        // need these
1018
-        if (! $question || ! $name) {
1019
-            return null;
1020
-        }
1021
-        // prep the answer
1022
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1023
-        // prep the required array
1024
-        $required = self::prep_required($required);
1025
-        // make sure $dimensions is an array
1026
-        $dimensions = is_array($dimensions) ? $dimensions : [];
1027
-        // and set some defaults
1028
-        $dimensions = array_merge(['rows' => 3, 'cols' => 40], $dimensions);
1029
-        // set disabled tag
1030
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1031
-        // ya gots ta have style man!!!
1032
-        $txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp';
1033
-        $class     = empty($class) ? $txt_class : $class;
1034
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1035
-        $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1036
-
1037
-        $label_html =
1038
-            $required_text
1039
-            . "\n\t\t\t"
1040
-            . '<label for="' . $name . '" class="' . $label_class . '">'
1041
-            . self::prep_question($question)
1042
-            . $required['label']
1043
-            . '</label><br/>';
1044
-        // filter label but ensure required text comes before it
1045
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1046
-
1047
-        $input_html =
1048
-            "\n\t\t\t"
1049
-            . '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" '
1050
-            . 'rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '"  '
1051
-            . 'title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>'
1052
-            . $answer
1053
-            . '</textarea>';
1054
-
1055
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1056
-        return $label_html . $input_html;
1057
-    }
1058
-
1059
-
1060
-    /**
1061
-     * generates HTML for a form select input
1062
-     *
1063
-     * @param string $question    label content
1064
-     * @param string $answer      form input value attribute
1065
-     * @param array  $options     array of answer options where array key = option value and array value = option
1066
-     *                            display text
1067
-     * @param string $name        form input name attribute
1068
-     * @param string $id          form input css id attribute
1069
-     * @param string $class       form input css class attribute
1070
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1071
-     *                            required 'class', and required 'msg' attribute
1072
-     * @param string $label_class css class attribute for the label
1073
-     * @param string $disabled    disabled="disabled" or null
1074
-     * @return string HTML
1075
-     */
1076
-    public static function select(
1077
-        $question = false,
1078
-        $answer = null,
1079
-        $options = false,
1080
-        $name = false,
1081
-        $id = '',
1082
-        $class = '',
1083
-        $required = false,
1084
-        $required_text = '',
1085
-        $label_class = '',
1086
-        $disabled = false,
1087
-        $system_ID = false,
1088
-        $use_html_entities = true,
1089
-        $add_please_select_option = false
1090
-    ) {
1091
-
1092
-        // need these
1093
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1094
-            return null;
1095
-        }
1096
-        // prep the answer
1097
-        $answer =
1098
-            is_array($answer)
1099
-                ? self::prep_answer(array_shift($answer), $use_html_entities)
1100
-                : self::prep_answer(
1101
-                    $answer,
1102
-                    $use_html_entities
1103
-                );
1104
-        // prep the required array
1105
-        $required = self::prep_required($required);
1106
-        // set disabled tag
1107
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1108
-        // ya gots ta have style man!!!
1109
-        $txt_class = is_admin() ? 'wide' : 'espresso-select-inp';
1110
-        $class     = empty($class) ? $txt_class : $class;
1111
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1112
-        $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1113
-
1114
-        $label_html =
1115
-            $required_text
1116
-            . "\n\t\t\t"
1117
-            . '<label for="' . $name . '" class="' . $label_class . '">'
1118
-            . self::prep_question($question)
1119
-            . $required['label']
1120
-            . '</label><br/>';
1121
-        // filter label but ensure required text comes before it
1122
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1123
-
1124
-        $input_html =
1125
-            "\n\t\t\t"
1126
-            . '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" '
1127
-            . 'title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>';
1128
-        // recursively count array elements, to determine total number of options
1129
-        $only_option = count($options, 1) == 1;
1130
-        if (! $only_option) {
1131
-            // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected
1132
-            $selected   = $answer === null ? ' selected="selected"' : '';
1133
-            $input_html .= $add_please_select_option
1134
-                ? "\n\t\t\t\t"
1135
-                  . '<option value=""' . $selected . '>'
1136
-                  . esc_html__(' - please select - ', 'event_espresso')
1137
-                  . '</option>'
1138
-                : '';
1139
-        }
1140
-        foreach ($options as $key => $value) {
1141
-            // if value is an array, then create option groups, else create regular ol' options
1142
-            $input_html .= is_array($value)
1143
-                ? self::_generate_select_option_group(
1144
-                    $key,
1145
-                    $value,
1146
-                    $answer,
1147
-                    $use_html_entities
1148
-                )
1149
-                : self::_generate_select_option(
1150
-                    $value->value(),
1151
-                    $value->desc(),
1152
-                    $answer,
1153
-                    $only_option,
1154
-                    $use_html_entities
1155
-                );
1156
-        }
1157
-
1158
-        $input_html .= "\n\t\t\t" . '</select>';
1159
-
1160
-        $input_html =
1161
-            apply_filters(
1162
-                'FHEE__EEH_Form_Fields__select__before_end_wrapper',
1163
-                $input_html,
1164
-                $question,
1165
-                $answer,
1166
-                $name,
1167
-                $id,
1168
-                $class,
1169
-                $system_ID
1170
-            );
1171
-
1172
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1173
-        return $label_html . $input_html;
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     *  _generate_select_option_group
1179
-     *
1180
-     *  if  $value for a select box is an array, then the key will be used as the optgroup label
1181
-     *  and the value array will be looped thru and the elements sent to _generate_select_option
1182
-     *
1183
-     * @param mixed   $opt_group
1184
-     * @param mixed   $QSOs
1185
-     * @param mixed   $answer
1186
-     * @param boolean $use_html_entities
1187
-     * @return string
1188
-     */
1189
-    private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true)
1190
-    {
1191
-        $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">';
1192
-        foreach ($QSOs as $QSO) {
1193
-            $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities);
1194
-        }
1195
-        $html .= "\n\t\t\t\t" . '</optgroup>';
1196
-        return $html;
1197
-    }
1198
-
1199
-
1200
-    /**
1201
-     *  _generate_select_option
1202
-     *
1203
-     * @param mixed   $key
1204
-     * @param mixed   $value
1205
-     * @param mixed   $answer
1206
-     * @param int     $only_option
1207
-     * @param boolean $use_html_entities
1208
-     * @return string
1209
-     */
1210
-    private static function _generate_select_option(
1211
-        $key,
1212
-        $value,
1213
-        $answer,
1214
-        $only_option = false,
1215
-        $use_html_entities = true
1216
-    ) {
1217
-        $key      = self::prep_answer($key, $use_html_entities);
1218
-        $value    = self::prep_answer($value, $use_html_entities);
1219
-        $value    = ! empty($value) ? $value : $key;
1220
-        $selected = ($answer == $key || $only_option) ? 'selected="selected"' : '';
1221
-        return "\n\t\t\t\t"
1222
-               . '<option value="' . self::prep_option_value($key) . '" ' . $selected . '> '
1223
-               . $value
1224
-               . '&nbsp;&nbsp;&nbsp;</option>';
1225
-    }
1226
-
1227
-
1228
-    /**
1229
-     * generates HTML for form radio button inputs
1230
-     *
1231
-     * @param bool|string $question    label content
1232
-     * @param string      $answer      form input value attribute
1233
-     * @param array|bool  $options     array of answer options where array key = option value and array value = option
1234
-     *                                 display text
1235
-     * @param bool|string $name        form input name attribute
1236
-     * @param string      $id          form input css id attribute
1237
-     * @param string      $class       form input css class attribute
1238
-     * @param array|bool  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1239
-     *                                 required 'class', and required 'msg' attribute
1240
-     * @param string      $required_text
1241
-     * @param string      $label_class css class attribute for the label
1242
-     * @param bool|string $disabled    disabled="disabled" or null
1243
-     * @param bool        $system_ID
1244
-     * @param bool        $use_html_entities
1245
-     * @param bool        $label_b4
1246
-     * @param bool        $use_desc_4_label
1247
-     * @return string HTML
1248
-     */
1249
-    public static function radio(
1250
-        $question = false,
1251
-        $answer = null,
1252
-        $options = false,
1253
-        $name = false,
1254
-        $id = '',
1255
-        $class = '',
1256
-        $required = false,
1257
-        $required_text = '',
1258
-        $label_class = '',
1259
-        $disabled = false,
1260
-        $system_ID = false,
1261
-        $use_html_entities = true,
1262
-        $label_b4 = false,
1263
-        $use_desc_4_label = false
1264
-    ) {
1265
-        // need these
1266
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1267
-            return null;
1268
-        }
1269
-        // prep the answer
1270
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1271
-        // prep the required array
1272
-        $required = self::prep_required($required);
1273
-        // set disabled tag
1274
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1275
-        // ya gots ta have style man!!!
1276
-        $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
1277
-        $class       = ! empty($class) ? $class : 'espresso-radio-btn-inp';
1278
-        $extra       = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1279
-
1280
-        $label_html =
1281
-            $required_text
1282
-            . "\n\t\t\t"
1283
-            . '<label class="' . $label_class . '">'
1284
-            . self::prep_question($question)
1285
-            . $required['label']
1286
-            . '</label> ';
1287
-        // filter label but ensure required text comes before it
1288
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1289
-
1290
-        $input_html =
1291
-            "\n\t\t\t"
1292
-            . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">';
1293
-
1294
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1295
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1296
-
1297
-        foreach ($options as $OPT) {
1298
-            if ($OPT instanceof EE_Question_Option) {
1299
-                $value   = self::prep_option_value($OPT->value());
1300
-                $label   = $use_desc_4_label ? $OPT->desc() : $OPT->value();
1301
-                $size    = $use_desc_4_label
1302
-                    ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc())
1303
-                    : self::get_label_size_class($OPT->value());
1304
-                $desc    = $OPT->desc();// no self::prep_answer
1305
-                $answer  = is_numeric($value) && empty($answer) ? 0 : $answer;
1306
-                $checked = (string) $value == (string) $answer ? ' checked="checked"' : '';
1307
-                $opt     = '-' . sanitize_key($value);
1308
-
1309
-                $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1310
-                $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">';
1311
-                $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : '';
1312
-                $input_html .= "\n\t\t\t\t\t\t"
1313
-                               . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" '
1314
-                               . 'class="' . $class . '" value="' . $value . '" '
1315
-                               . 'title="' . esc_attr($required['msg']) . '" ' . $disabled
1316
-                               . $checked . ' ' . $extra . '/>';
1317
-                $input_html .= ! $label_b4
1318
-                    ? "\n\t\t\t\t\t\t"
1319
-                      . '<span class="espresso-radio-btn-desc">'
1320
-                      . $label
1321
-                      . '</span>'
1322
-                    : '';
1323
-                $input_html .= "\n\t\t\t\t\t" . '</label>';
1324
-                $input_html .= $use_desc_4_label
1325
-                    ? ''
1326
-                    : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>';
1327
-                $input_html .= "\n\t\t\t\t" . '</li>';
1328
-            }
1329
-        }
1330
-
1331
-        $input_html .= "\n\t\t\t" . '</ul>';
1332
-
1333
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1334
-        return $label_html . $input_html;
1335
-    }
1336
-
1337
-
1338
-    /**
1339
-     * generates HTML for form checkbox inputs
1340
-     *
1341
-     * @param string $question    label content
1342
-     * @param string $answer      form input value attribute
1343
-     * @param array  $options     array of options where array key = option value and array value = option display text
1344
-     * @param string $name        form input name attribute
1345
-     * @param string $id          form input css id attribute
1346
-     * @param string $class       form input css class attribute
1347
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1348
-     *                            required 'class', and required 'msg' attribute
1349
-     * @param string $label_class css class attribute for the label
1350
-     * @param string $disabled    disabled="disabled" or null
1351
-     * @return string HTML
1352
-     */
1353
-    public static function checkbox(
1354
-        $question = false,
1355
-        $answer = null,
1356
-        $options = false,
1357
-        $name = false,
1358
-        $id = '',
1359
-        $class = '',
1360
-        $required = false,
1361
-        $required_text = '',
1362
-        $label_class = '',
1363
-        $disabled = false,
1364
-        $label_b4 = false,
1365
-        $system_ID = false,
1366
-        $use_html_entities = true
1367
-    ) {
1368
-        // need these
1369
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1370
-            return null;
1371
-        }
1372
-        $answer = maybe_unserialize($answer);
1373
-
1374
-        // prep the answer(s)
1375
-        $answer = is_array($answer) ? $answer : [sanitize_key($answer) => $answer];
1376
-
1377
-        foreach ($answer as $key => $value) {
1378
-            $key            = self::prep_option_value($key);
1379
-            $answer[ $key ] = self::prep_answer($value, $use_html_entities);
1380
-        }
1381
-
1382
-        // prep the required array
1383
-        $required = self::prep_required($required);
1384
-        // set disabled tag
1385
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1386
-        // ya gots ta have style man!!!
1387
-        $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
1388
-        $class       = empty($class) ? 'espresso-radio-btn-inp' : $class;
1389
-        $extra       = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1390
-
1391
-        $label_html =
1392
-            $required_text
1393
-            . "\n\t\t\t"
1394
-            . '<label class="' . $label_class . '">'
1395
-            . self::prep_question($question)
1396
-            . $required['label']
1397
-            . '</label> ';
1398
-        // filter label but ensure required text comes before it
1399
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1400
-
1401
-        $input_html =
1402
-            "\n\t\t\t"
1403
-            . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">';
1404
-
1405
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1406
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1407
-
1408
-        foreach ($options as $OPT) {
1409
-            $value = $OPT->value();// self::prep_option_value( $OPT->value() );
1410
-            $size  = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc());
1411
-            $text  = self::prep_answer($OPT->value());
1412
-            $desc  = $OPT->desc();
1413
-            $opt   = '-' . sanitize_key($value);
1414
-
1415
-            $checked = is_array($answer) && in_array($text, $answer) ? ' checked="checked"' : '';
1416
-
1417
-            $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1418
-            $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">';
1419
-            $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
1420
-            $input_html .= "\n\t\t\t\t\t\t"
1421
-                           . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" '
1422
-                           . 'id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" '
1423
-                           . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
1424
-            $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
1425
-            $input_html .= "\n\t\t\t\t\t" . '</label>';
1426
-            if (! empty($desc) && $desc != $text) {
1427
-                $input_html .= "\n\t\t\t\t\t"
1428
-                               . ' &nbsp; <br/><div class="espresso-checkbox-option-desc small-text grey-text">'
1429
-                               . $desc
1430
-                               . '</div>';
1431
-            }
1432
-            $input_html .= "\n\t\t\t\t" . '</li>';
1433
-        }
1434
-
1435
-        $input_html .= "\n\t\t\t" . '</ul>';
1436
-
1437
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1438
-        return $label_html . $input_html;
1439
-    }
1440
-
1441
-
1442
-    /**
1443
-     * generates HTML for a form datepicker input
1444
-     *
1445
-     * @param string $question    label content
1446
-     * @param string $answer      form input value attribute
1447
-     * @param string $name        form input name attribute
1448
-     * @param string $id          form input css id attribute
1449
-     * @param string $class       form input css class attribute
1450
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1451
-     *                            required 'class', and required 'msg' attribute
1452
-     * @param string $label_class css class attribute for the label
1453
-     * @param string $disabled    disabled="disabled" or null
1454
-     * @return string HTML
1455
-     */
1456
-    public static function datepicker(
1457
-        $question = false,
1458
-        $answer = null,
1459
-        $name = false,
1460
-        $id = '',
1461
-        $class = '',
1462
-        $required = false,
1463
-        $required_text = '',
1464
-        $label_class = '',
1465
-        $disabled = false,
1466
-        $system_ID = false,
1467
-        $use_html_entities = true
1468
-    ) {
1469
-        // need these
1470
-        if (! $question || ! $name) {
1471
-            return null;
1472
-        }
1473
-        // prep the answer
1474
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1475
-        // prep the required array
1476
-        $required = self::prep_required($required);
1477
-        // set disabled tag
1478
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1479
-        // ya gots ta have style man!!!
1480
-        $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp';
1481
-        $class     = empty($class) ? $txt_class : $class;
1482
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1483
-        $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1484
-
1485
-        $label_html =
1486
-            $required_text
1487
-            . "\n\t\t\t"
1488
-            . '<label for="' . $name . '" class="' . $label_class . '">'
1489
-            . self::prep_question($question)
1490
-            . $required['label']
1491
-            . '</label><br/>';
1492
-        // filter label but ensure required text comes before it
1493
-        $label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1494
-
1495
-        $input_html =
1496
-            "\n\t\t\t"
1497
-            . '<input type="text" name="' . $name . '" id="' . $id . '" '
1498
-            . 'class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '"  '
1499
-            . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
1500
-
1501
-        // enqueue scripts
1502
-        wp_register_style(
1503
-            'espresso-ui-theme',
1504
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1505
-            [],
1506
-            EVENT_ESPRESSO_VERSION
1507
-        );
1508
-        wp_enqueue_style('espresso-ui-theme');
1509
-        wp_enqueue_script('jquery-ui-datepicker');
1510
-
1511
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1512
-        return $label_html . $input_html;
1513
-    }
1514
-
1515
-
1516
-    /**
1517
-     *  remove_label_keep_required_msg
1518
-     *  this will strip out a form input's label HTML while keeping the required text HTML that MUST be before the label
1519
-     *
1520
-     * @access public
1521
-     * @return     string
1522
-     */
1523
-    public static function remove_label_keep_required_msg($label_html, $required_text)
1524
-    {
1525
-        return $required_text;
1526
-    }
1527
-
1528
-
1529
-    /**
1530
-     * Simply returns the HTML for a hidden input of the given name and value.
1531
-     *
1532
-     * @param string $name
1533
-     * @param string $value
1534
-     * @return string HTML
1535
-     */
1536
-    public static function hidden_input($name, $value, $id = '')
1537
-    {
1538
-        $id = ! empty($id) ? $id : $name;
1539
-        return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>';
1540
-    }
1541
-
1542
-
1543
-    /**
1544
-     * prep_question
1545
-     *
1546
-     * @param string $question
1547
-     * @return string
1548
-     */
1549
-    public static function prep_question($question)
1550
-    {
1551
-        return $question;
1552
-    }
1553
-
1554
-
1555
-    /**
1556
-     *  prep_answer
1557
-     *
1558
-     * @param mixed $answer
1559
-     * @return string
1560
-     */
1561
-    public static function prep_answer($answer, $use_html_entities = true)
1562
-    {
1563
-        // make sure we convert bools first.  Otherwise (bool) false becomes an empty string which is NOT desired,
1564
-        // we want "0".
1565
-        if (is_bool($answer)) {
1566
-            $answer = $answer ? 1 : 0;
1567
-        }
1568
-        $answer = trim(stripslashes(str_replace('&#039;', "'", $answer)));
1569
-        return $use_html_entities ? htmlentities($answer, ENT_QUOTES, 'UTF-8') : $answer;
1570
-    }
1571
-
1572
-
1573
-    /**
1574
-     *  prep_answer_options
1575
-     *
1576
-     * @param array $QSOs array of EE_Question_Option objects
1577
-     * @return array
1578
-     */
1579
-    public static function prep_answer_options($QSOs = [])
1580
-    {
1581
-        $prepped_answer_options = [];
1582
-        if (is_array($QSOs) && ! empty($QSOs)) {
1583
-            foreach ($QSOs as $key => $QSO) {
1584
-                if (! $QSO instanceof EE_Question_Option) {
1585
-                    $QSO = EE_Question_Option::new_instance(
1586
-                        [
1587
-                            'QSO_value' => is_array($QSO) && isset($QSO['id'])
1588
-                                ? (string) $QSO['id']
1589
-                                : (string) $key,
1590
-                            'QSO_desc'  => is_array($QSO) && isset($QSO['text'])
1591
-                                ? (string) $QSO['text']
1592
-                                : (string) $QSO,
1593
-                        ]
1594
-                    );
1595
-                }
1596
-                if ($QSO->opt_group()) {
1597
-                    $prepped_answer_options[ $QSO->opt_group() ][] = $QSO;
1598
-                } else {
1599
-                    $prepped_answer_options[] = $QSO;
1600
-                }
1601
-            }
1602
-        }
1603
-        //      d( $prepped_answer_options );
1604
-        return $prepped_answer_options;
1605
-    }
1606
-
1607
-
1608
-    /**
1609
-     *  prep_option_value
1610
-     *
1611
-     * @param string $option_value
1612
-     * @return string
1613
-     */
1614
-    public static function prep_option_value($option_value)
1615
-    {
1616
-        return esc_attr(trim(stripslashes($option_value)));
1617
-    }
1618
-
1619
-
1620
-    /**
1621
-     *  prep_required
1622
-     *
1623
-     * @param string|array $required
1624
-     * @return array
1625
-     */
1626
-    public static function prep_required($required = [])
1627
-    {
1628
-        // make sure required is an array
1629
-        $required = is_array($required) ? $required : [];
1630
-        // and set some defaults
1631
-        return array_merge(['label' => '', 'class' => '', 'msg' => ''], $required);
1632
-    }
1633
-
1634
-
1635
-    /**
1636
-     *  get_label_size_class
1637
-     *
1638
-     * @param string $value
1639
-     * @return string
1640
-     */
1641
-    public static function get_label_size_class($value = false)
1642
-    {
1643
-        if ($value === false || $value === '') {
1644
-            return ' class="medium-lbl"';
1645
-        }
1646
-        // determine length of option value
1647
-        $val_size = strlen($value);
1648
-        switch ($val_size) {
1649
-            case $val_size < 3:
1650
-                $size = ' class="nano-lbl"';
1651
-                break;
1652
-            case $val_size < 6:
1653
-                $size = ' class="micro-lbl"';
1654
-                break;
1655
-            case $val_size < 12:
1656
-                $size = ' class="tiny-lbl"';
1657
-                break;
1658
-            case $val_size < 25:
1659
-                $size = ' class="small-lbl"';
1660
-                break;
1661
-            case $val_size > 100:
1662
-                $size = ' class="big-lbl"';
1663
-                break;
1664
-            default:
1665
-                $size = ' class="medium-lbl"';
1666
-                break;
1667
-        }
1668
-        return $size;
1669
-    }
1670
-
1671
-
1672
-    /**
1673
-     *  _load_system_dropdowns
1674
-     *
1675
-     * @param EE_Question_Form_Input $QFI
1676
-     * @return array
1677
-     * @throws EE_Error
1678
-     * @throws ReflectionException
1679
-     */
1680
-    private static function _load_system_dropdowns($QFI)
1681
-    {
1682
-        $QST_system = $QFI->get('QST_system');
1683
-        switch ($QST_system) {
1684
-            case 'state':
1685
-                $QFI = self::generate_state_dropdown($QFI);
1686
-                break;
1687
-            case 'country':
1688
-                $QFI = self::generate_country_dropdown($QFI);
1689
-                break;
1690
-            case 'admin-state':
1691
-                $QFI = self::generate_state_dropdown($QFI, true);
1692
-                break;
1693
-            case 'admin-country':
1694
-                $QFI = self::generate_country_dropdown($QFI, true);
1695
-                break;
1696
-        }
1697
-        return $QFI;
1698
-    }
1699
-
1700
-
1701
-    /**
1702
-     * This preps dropdowns that are specialized.
1703
-     *
1704
-     * @param EE_Question_Form_Input $QFI
1705
-     *
1706
-     * @return EE_Question_Form_Input
1707
-     * @throws EE_Error
1708
-     * @throws ReflectionException
1709
-     * @since  4.6.0
1710
-     */
1711
-    protected static function _load_specialized_dropdowns($QFI)
1712
-    {
1713
-        switch ($QFI->get('QST_type')) {
1714
-            case 'STATE':
1715
-                $QFI = self::generate_state_dropdown($QFI);
1716
-                break;
1717
-            case 'COUNTRY':
1718
-                $QFI = self::generate_country_dropdown($QFI);
1719
-                break;
1720
-        }
1721
-        return $QFI;
1722
-    }
1723
-
1724
-
1725
-    /**
1726
-     *    generate_state_dropdown
1727
-     *
1728
-     * @param EE_Question_Form_Input $QST
1729
-     * @param bool                   $get_all
1730
-     * @return EE_Question_Form_Input
1731
-     * @throws EE_Error
1732
-     * @throws ReflectionException
1733
-     */
1734
-    public static function generate_state_dropdown($QST, $get_all = false)
1735
-    {
1736
-        $states = $get_all
1737
-            ? EEM_State::instance()->get_all_states()
1738
-            : EEM_State::instance()->get_all_states_of_active_countries();
1739
-        if ($states && count($states) != count($QST->options())) {
1740
-            $QST->set('QST_type', 'DROPDOWN');
1741
-            // if multiple countries, we'll create option groups within the dropdown
1742
-            foreach ($states as $state) {
1743
-                if ($state instanceof EE_State) {
1744
-                    $QSO = EE_Question_Option::new_instance(
1745
-                        [
1746
-                            'QSO_value'   => $state->ID(),
1747
-                            'QSO_desc'    => $state->name(),
1748
-                            'QST_ID'      => $QST->get('QST_ID'),
1749
-                            'QSO_deleted' => false,
1750
-                        ]
1751
-                    );
1752
-                    // set option group
1753
-                    $QSO->set_opt_group($state->country()->name());
1754
-                    // add option to question
1755
-                    $QST->add_temp_option($QSO);
1756
-                }
1757
-            }
1758
-        }
1759
-        return $QST;
1760
-    }
1761
-
1762
-
1763
-    /**
1764
-     *    generate_country_dropdown
1765
-     *
1766
-     * @param      $QST
1767
-     * @param bool $get_all
1768
-     * @return array
1769
-     * @throws EE_Error
1770
-     * @throws ReflectionException
1771
-     * @internal param array $question
1772
-     */
1773
-    public static function generate_country_dropdown($QST, $get_all = false)
1774
-    {
1775
-        $countries = $get_all
1776
-            ? EEM_Country::instance()->get_all_countries()
1777
-            : EEM_Country::instance()->get_all_active_countries();
1778
-        if ($countries && count($countries) != count($QST->options())) {
1779
-            $QST->set('QST_type', 'DROPDOWN');
1780
-            // now add countries
1781
-            foreach ($countries as $country) {
1782
-                if ($country instanceof EE_Country) {
1783
-                    $QSO = EE_Question_Option::new_instance(
1784
-                        [
1785
-                            'QSO_value'   => $country->ID(),
1786
-                            'QSO_desc'    => $country->name(),
1787
-                            'QST_ID'      => $QST->get('QST_ID'),
1788
-                            'QSO_deleted' => false,
1789
-                        ]
1790
-                    );
1791
-                    $QST->add_temp_option($QSO);
1792
-                }
1793
-            }
1794
-        }
1795
-        return $QST;
1796
-    }
1797
-
1798
-
1799
-    /**
1800
-     *  generates options for a month dropdown selector with numbers from 01 to 12
1801
-     *
1802
-     * @return array()
1803
-     */
1804
-    public static function two_digit_months_dropdown_options()
1805
-    {
1806
-        $options = [];
1807
-        for ($x = 1; $x <= 12; $x++) {
1808
-            $mm             = str_pad($x, 2, '0', STR_PAD_LEFT);
1809
-            $options[ $mm ] = $mm;
1810
-        }
1811
-        return EEH_Form_Fields::prep_answer_options($options);
1812
-    }
1813
-
1814
-
1815
-    /**
1816
-     *  generates a year dropdown selector with numbers for the next ten years
1817
-     *
1818
-     * @return array
1819
-     */
1820
-    public static function next_decade_two_digit_year_dropdown_options()
1821
-    {
1822
-        $options      = [];
1823
-        $current_year = date('y');
1824
-        $next_decade  = $current_year + 10;
1825
-        for ($x = $current_year; $x <= $next_decade; $x++) {
1826
-            $yy             = str_pad($x, 2, '0', STR_PAD_LEFT);
1827
-            $options[ $yy ] = $yy;
1828
-        }
1829
-        return EEH_Form_Fields::prep_answer_options($options);
1830
-    }
1831
-
1832
-
1833
-    /**
1834
-     * generates a month/year dropdown selector for all registrations matching the given criteria.  Typically used for
1835
-     * list table filter.
1836
-     *
1837
-     * @param string  $cur_date     any currently selected date can be entered here.
1838
-     * @param string  $status       Registration status
1839
-     * @param integer $evt_category Event Category ID if the Event Category filter is selected
1840
-     * @return string                html
1841
-     * @throws EE_Error
1842
-     */
1843
-    public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1844
-    {
1845
-        $_where = [];
1846
-        if (! empty($status)) {
1847
-            $_where['STS_ID'] = $status;
1848
-        }
1849
-
1850
-        if ($evt_category > 0) {
1851
-            $_where['Event.Term_Taxonomy.term_id'] = $evt_category;
1852
-        }
1853
-
1854
-        $regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where);
1855
-
1856
-        // setup vals for select input helper
1857
-        $options = [
1858
-            0 => [
1859
-                'text' => esc_html__('Select a Month/Year', 'event_espresso'),
1860
-                'id'   => '',
1861
-            ],
1862
-        ];
1863
-
1864
-        foreach ($regdtts as $regdtt) {
1865
-            $date      = $regdtt->reg_month . ' ' . $regdtt->reg_year;
1866
-            $options[] = [
1867
-                'text' => $date,
1868
-                'id'   => $date,
1869
-            ];
1870
-        }
1871
-
1872
-        return self::select_input('month_range', $options, $cur_date, '', 'wide');
1873
-    }
1874
-
1875
-
1876
-    /**
1877
-     * generates a month/year dropdown selector for all events matching the given criteria
1878
-     * Typically used for list table filter
1879
-     *
1880
-     * @param string $cur_date          any currently selected date can be entered here.
1881
-     * @param string $status            "view" (i.e. all, today, month, draft)
1882
-     * @param int    $evt_category      category event belongs to
1883
-     * @param string $evt_active_status "upcoming", "expired", "active", or "inactive"
1884
-     * @return string                    html
1885
-     * @throws EE_Error
1886
-     */
1887
-    public static function generate_event_months_dropdown(
1888
-        $cur_date = '',
1889
-        $status = null,
1890
-        $evt_category = null,
1891
-        $evt_active_status = null
1892
-    ) {
1893
-        // determine what post_status our condition will have for the query.
1894
-        // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
1895
-        switch ($status) {
1896
-            case 'month':
1897
-            case 'today':
1898
-            case null:
1899
-            case 'all':
1900
-                $where['Event.status'] = ['NOT IN', ['trash']];
1901
-                break;
1902
-            case 'draft':
1903
-                $where['Event.status'] = ['IN', ['draft', 'auto-draft']];
1904
-                break;
1905
-            default:
1906
-                $where['Event.status'] = $status;
1907
-        }
1908
-
1909
-        // phpcs:enable
1910
-
1911
-        // categories?
1912
-
1913
-
1914
-        if (! empty($evt_category)) {
1915
-            $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1916
-            $where['Event.Term_Taxonomy.term_id']  = $evt_category;
1917
-        }
1918
-
1919
-
1920
-        //      $where['DTT_is_primary'] = 1;
1921
-
1922
-        $DTTS = EEM_Datetime::instance()->get_dtt_months_and_years($where, $evt_active_status);
1923
-
1924
-        // let's setup vals for select input helper
1925
-        $options = [
1926
-            0 => [
1927
-                'text' => esc_html__('Select a Month/Year', 'event_espresso'),
1928
-                'id'   => "",
1929
-            ],
1930
-        ];
1931
-
1932
-
1933
-        // translate month and date
1934
-        global $wp_locale;
1935
-
1936
-        foreach ($DTTS as $DTT) {
1937
-            $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
1938
-            $id             = $DTT->dtt_month . ' ' . $DTT->dtt_year;
1939
-            $options[]      = [
1940
-                'text' => $localized_date,
1941
-                'id'   => $id,
1942
-            ];
1943
-        }
1944
-
1945
-
1946
-        return self::select_input('month_range', $options, $cur_date, '', 'wide');
1947
-    }
1948
-
1949
-
1950
-    /**
1951
-     * generates the dropdown selector for event categories
1952
-     * typically used as a filter on list tables.
1953
-     *
1954
-     * @param integer $current_cat currently selected category
1955
-     * @return string               html for dropdown
1956
-     * @throws EE_Error
1957
-     * @throws ReflectionException
1958
-     */
1959
-    public static function generate_event_category_dropdown($current_cat = -1)
1960
-    {
1961
-        $categories = EEM_Term::instance()->get_all_ee_categories(true);
1962
-        $options    = [
1963
-            '0' => [
1964
-                'text' => esc_html__('All Categories', 'event_espresso'),
1965
-                'id'   => -1,
1966
-            ],
1967
-        ];
1968
-
1969
-        // setup categories for dropdown
1970
-        foreach ($categories as $category) {
1971
-            $options[] = [
1972
-                'text' => $category->get('name'),
1973
-                'id'   => $category->ID(),
1974
-            ];
1975
-        }
1976
-
1977
-        return self::select_input('EVT_CAT', $options, $current_cat);
1978
-    }
1979
-
1980
-
1981
-    /**
1982
-     *    generate a submit button with or without it's own microform
1983
-     *    this is the only way to create buttons that are compatible across all themes
1984
-     *
1985
-     * @access    public
1986
-     * @param string      $url              - the form action
1987
-     * @param string      $ID               - some kind of unique ID, appended with "-sbmt" for the input and "-frm"
1988
-     *                                      for the form
1989
-     * @param string      $class            - css classes (separated by spaces if more than one)
1990
-     * @param string      $text             - what appears on the button
1991
-     * @param string      $nonce_action     - if using nonces
1992
-     * @param bool|string $input_only       - whether to print form header and footer. TRUE returns the input without
1993
-     *                                      the form
1994
-     * @param string      $extra_attributes - any extra attributes that need to be attached to the form input
1995
-     * @return    string
1996
-     */
1997
-    public static function submit_button(
1998
-        $url = '',
1999
-        $ID = '',
2000
-        $class = '',
2001
-        $text = '',
2002
-        $nonce_action = '',
2003
-        $input_only = false,
2004
-        $extra_attributes = ''
2005
-    ) {
2006
-        $btn = '';
2007
-        if (empty($url) || empty($ID)) {
2008
-            return $btn;
2009
-        }
2010
-        $text = ! empty($text) ? $text : esc_html__('Submit', 'event_espresso');
2011
-        $btn  .= '<input id="' . $ID . '-btn" class="' . $class . '" '
2012
-                 . 'type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
2013
-        if (! $input_only) {
2014
-            $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
2015
-            $btn_frm .= ! empty($nonce_action)
2016
-                ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false)
2017
-                : '';
2018
-            $btn_frm .= $btn;
2019
-            $btn_frm .= '</form>';
2020
-            $btn     = $btn_frm;
2021
-            unset($btn_frm);
2022
-        }
2023
-        return $btn;
2024
-    }
488
+	}
489
+
490
+
491
+	/**
492
+	 * @param string $class
493
+	 * @param string $id
494
+	 * @param string $name
495
+	 * @param int    $rows
496
+	 * @param int    $tab_index
497
+	 * @param string $value
498
+	 * @param array  $wp_editor_args
499
+	 * @return false|string
500
+	 * @since   4.10.14.p
501
+	 */
502
+	private static function adminWpEditor($class, $id, $name, $rows, $tab_index, $value, $wp_editor_args = [])
503
+	{
504
+		$editor_settings = $wp_editor_args + [
505
+				'textarea_name' => esc_attr($name),
506
+				'textarea_rows' => absint($rows),
507
+				'editor_class'  => esc_attr($class),
508
+				'tabindex'      => absint($tab_index),
509
+			];
510
+		ob_start();
511
+		wp_editor($value, esc_attr($id), $editor_settings);
512
+		return ob_get_clean();
513
+	}
514
+
515
+
516
+	/**
517
+	 * espresso admin page select_input
518
+	 * Turns an array into a select fields
519
+	 *
520
+	 * @static
521
+	 * @access public
522
+	 * @param string  $name       field name
523
+	 * @param array   $values     option values, numbered array starting at 0, where each value is an array with a key
524
+	 *                            'text' (meaning text to display' and 'id' (meaning the internal value) eg:
525
+	 *                            array(1=>array('text'=>'Monday','id'=>1),2=>array('text'=>'Tuesday','id'=>2)...). or
526
+	 *                            as an array of key-value pairs, where the key is to be used for the select input's
527
+	 *                            name, and the value will be the text shown to the user.  Optionally you can also
528
+	 *                            include an additional key of "class" which will add a specific class to the option
529
+	 *                            for that value.
530
+	 * @param string  $default    default value
531
+	 * @param string  $parameters extra parameters
532
+	 * @param string  $class      css class
533
+	 * @param boolean $autosize   whether to autosize the select or not
534
+	 * @return string              html string for the select input
535
+	 */
536
+	public static function select_input($name, $values, $default = '', $parameters = '', $class = '', $autosize = true)
537
+	{
538
+		// if $values was submitted in the wrong format, convert it over
539
+		if (! empty($values) && (! array_key_exists(0, $values) || ! is_array($values[0]))) {
540
+			$converted_values = [];
541
+			foreach ($values as $id => $text) {
542
+				$converted_values[] = ['id' => $id, 'text' => $text];
543
+			}
544
+			$values = $converted_values;
545
+		}
546
+
547
+		$field =
548
+			'<select id="' . EEH_Formatter::ee_tep_output_string($name)
549
+			. '" name="' . EEH_Formatter::ee_tep_output_string($name)
550
+			. '"';
551
+
552
+		if (EEH_Formatter::ee_tep_not_null($parameters)) {
553
+			$field .= ' ' . $parameters;
554
+		}
555
+		if ($autosize) {
556
+			$size = 'med';
557
+			for ($ii = 0, $ni = sizeof($values); $ii < $ni; $ii++) {
558
+				if ($values[ $ii ]['text']) {
559
+					if (strlen($values[ $ii ]['text']) > 5) {
560
+						$size = 'wide';
561
+					}
562
+				}
563
+			}
564
+		} else {
565
+			$size = '';
566
+		}
567
+
568
+		$field .= ' class="' . $class . ' ' . $size . '">';
569
+
570
+		if (empty($default) && isset($GLOBALS[ $name ])) {
571
+			$default = stripslashes($GLOBALS[ $name ]);
572
+		}
573
+
574
+
575
+		for ($i = 0, $n = sizeof($values); $i < $n; $i++) {
576
+			$field .= '<option value="' . $values[ $i ]['id'] . '"';
577
+			if ($default == $values[ $i ]['id']) {
578
+				$field .= ' selected = "selected"';
579
+			}
580
+			if (isset($values[ $i ]['class'])) {
581
+				$field .= ' class="' . $values[ $i ]['class'] . '"';
582
+			}
583
+			$field .= '>' . $values[ $i ]['text'] . '</option>';
584
+		}
585
+		$field .= '</select>';
586
+
587
+		return $field;
588
+	}
589
+
590
+
591
+	/**
592
+	 * generate_question_groups_html
593
+	 *
594
+	 * @param array  $question_groups
595
+	 * @param string $group_wrapper
596
+	 * @return string HTML
597
+	 * @throws EE_Error
598
+	 * @throws ReflectionException
599
+	 */
600
+	public static function generate_question_groups_html($question_groups = [], $group_wrapper = 'fieldset')
601
+	{
602
+
603
+		$html                            = '';
604
+		$before_question_group_questions =
605
+			apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
606
+		$after_question_group_questions  =
607
+			apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
608
+
609
+		if (! empty($question_groups)) {
610
+			// loop thru question groups
611
+			foreach ($question_groups as $QSG) {
612
+				// check that questions exist
613
+				if (! empty($QSG['QSG_questions'])) {
614
+					// use fieldsets
615
+					$html .= "\n\t"
616
+							 . '<'
617
+							 . $group_wrapper
618
+							 . ' class="espresso-question-group-wrap" id="'
619
+							 . $QSG['QSG_identifier']
620
+							 . '">';
621
+					// group_name
622
+					$html .= $QSG['QSG_show_group_name']
623
+						? "\n\t\t"
624
+						  . '<h5 class="espresso-question-group-title-h5 section-title">'
625
+						  . self::prep_answer($QSG['QSG_name'])
626
+						  . '</h5>'
627
+						: '';
628
+					// group_desc
629
+					$html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc'])
630
+						? '<div class="espresso-question-group-desc-pg">'
631
+						  . self::prep_answer($QSG['QSG_desc'])
632
+						  . '</div>'
633
+						: '';
634
+
635
+					$html .= $before_question_group_questions;
636
+					// loop thru questions
637
+					foreach ($QSG['QSG_questions'] as $question) {
638
+						$QFI  = new EE_Question_Form_Input(
639
+							$question['qst_obj'],
640
+							$question['ans_obj'],
641
+							$question
642
+						);
643
+						$html .= self::generate_form_input($QFI);
644
+					}
645
+					$html .= $after_question_group_questions;
646
+					$html .= "\n\t" . '</' . $group_wrapper . '>';
647
+				}
648
+			}
649
+		}
650
+
651
+		return $html;
652
+	}
653
+
654
+
655
+	/**
656
+	 * generate_question_groups_html
657
+	 *
658
+	 * @param array  $question_groups
659
+	 * @param array  $q_meta
660
+	 * @param bool   $from_admin
661
+	 * @param string $group_wrapper
662
+	 * @return string HTML
663
+	 * @throws EE_Error
664
+	 * @throws ReflectionException
665
+	 */
666
+	public static function generate_question_groups_html2(
667
+		$question_groups = [],
668
+		$q_meta = [],
669
+		$from_admin = false,
670
+		$group_wrapper = 'fieldset'
671
+	) {
672
+
673
+		$html                            = '';
674
+		$before_question_group_questions =
675
+			apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
676
+		$after_question_group_questions  =
677
+			apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
678
+
679
+		$default_q_meta = [
680
+			'att_nmbr'    => 1,
681
+			'ticket_id'   => '',
682
+			'input_name'  => '',
683
+			'input_id'    => '',
684
+			'input_class' => '',
685
+		];
686
+		$q_meta         = array_merge($default_q_meta, $q_meta);
687
+
688
+		if (! empty($question_groups)) {
689
+			// loop thru question groups
690
+			foreach ($question_groups as $QSG) {
691
+				if ($QSG instanceof EE_Question_Group) {
692
+					// check that questions exist
693
+
694
+					$where = ['QST_deleted' => 0];
695
+					if (! $from_admin) {
696
+						$where['QST_admin_only'] = 0;
697
+					}
698
+					$questions =
699
+						$QSG->questions([$where, 'order_by' => ['Question_Group_Question.QGQ_order' => 'ASC']]);
700
+					if (! empty($questions)) {
701
+						// use fieldsets
702
+						$html .= "\n\t"
703
+								 . '<' . $group_wrapper . ' class="espresso-question-group-wrap" '
704
+								 . 'id="' . $QSG->get('QSG_identifier') . '">';
705
+						// group_name
706
+						if ($QSG->show_group_name()) {
707
+							$html .= "\n\t\t"
708
+									 . '<h5 class="espresso-question-group-title-h5 section-title">'
709
+									 . $QSG->get_pretty('QSG_name')
710
+									 . '</h5>';
711
+						}
712
+						// group_desc
713
+						if ($QSG->show_group_desc()) {
714
+							$html .= '<div class="espresso-question-group-desc-pg">'
715
+									 . $QSG->get_pretty('QSG_desc')
716
+									 . '</div>';
717
+						}
718
+
719
+						$html .= $before_question_group_questions;
720
+						// loop thru questions
721
+						foreach ($questions as $QST) {
722
+							$qstn_id = $QST->is_system_question() ? $QST->system_ID() : $QST->ID();
723
+
724
+							$answer = null;
725
+
726
+							/** @var RequestInterface $request */
727
+							$request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
728
+							$request_qstn = $request->getRequestParam('qstn', [], 'string', true);
729
+							if (! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
730
+								// check for answer in $request_qstn in case we are reprocessing a form after an error
731
+								if (isset($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])) {
732
+									$answer = is_array($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])
733
+										? $request_qstn[ $q_meta['input_id'] ][ $qstn_id ]
734
+										: sanitize_text_field($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]);
735
+								}
736
+							} elseif (isset($q_meta['attendee']) && $q_meta['attendee']) {
737
+								// attendee data from the session
738
+								$answer =
739
+									isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null;
740
+							}
741
+
742
+
743
+							$QFI  = new EE_Question_Form_Input(
744
+								$QST,
745
+								EE_Answer::new_instance(
746
+									[
747
+										'ANS_ID'    => 0,
748
+										'QST_ID'    => 0,
749
+										'REG_ID'    => 0,
750
+										'ANS_value' => $answer,
751
+									]
752
+								),
753
+								$q_meta
754
+							);
755
+							$html .= self::generate_form_input($QFI);
756
+						}
757
+						$html .= $after_question_group_questions;
758
+						$html .= "\n\t" . '</' . $group_wrapper . '>';
759
+					}
760
+				}
761
+			}
762
+		}
763
+		return $html;
764
+	}
765
+
766
+
767
+	/**
768
+	 * generate_form_input
769
+	 *
770
+	 * @param EE_Question_Form_Input $QFI
771
+	 * @return string HTML
772
+	 * @throws EE_Error
773
+	 * @throws ReflectionException
774
+	 */
775
+	public static function generate_form_input(EE_Question_Form_Input $QFI)
776
+	{
777
+		if (isset($QFI->QST_admin_only) && $QFI->QST_admin_only && ! is_admin()) {
778
+			return '';
779
+		}
780
+		/** @var RequestInterface $request */
781
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
782
+
783
+		$QFI = self::_load_system_dropdowns($QFI);
784
+		$QFI = self::_load_specialized_dropdowns($QFI);
785
+
786
+		// we also need to verify
787
+
788
+		$display_text = $QFI->get('QST_display_text');
789
+		$input_name   = $QFI->get('QST_input_name');
790
+		$answer       = $request->getRequestParam($input_name, $QFI->get('ANS_value'));
791
+		$input_id     = $QFI->get('QST_input_id');
792
+		$input_class  = $QFI->get('QST_input_class');
793
+		//      $disabled = $QFI->get('QST_disabled') ? ' disabled="disabled"' : '';
794
+		$disabled          = $QFI->get('QST_disabled');
795
+		$required_label    = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>');
796
+		$QST_required      = $QFI->get('QST_required');
797
+		$required          =
798
+			$QST_required
799
+				? ['label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required]
800
+				: [];
801
+		$use_html_entities = $QFI->get_meta('htmlentities');
802
+		$required_text     =
803
+			$QFI->get('QST_required_text') != ''
804
+				? $QFI->get('QST_required_text')
805
+				: esc_html__('This field is required', 'event_espresso');
806
+		$required_text     = $QST_required
807
+			? "\n\t\t\t"
808
+			  . '<div class="required-text hidden">'
809
+			  . self::prep_answer($required_text, $use_html_entities)
810
+			  . '</div>'
811
+			: '';
812
+		$label_class       = 'espresso-form-input-lbl';
813
+		$QST_options       = $QFI->options(true, $answer);
814
+		$options           = is_array($QST_options) ? self::prep_answer_options($QST_options) : [];
815
+		$system_ID         = $QFI->get('QST_system');
816
+		$label_b4          = $QFI->get_meta('label_b4');
817
+		$use_desc_4_label  = $QFI->get_meta('use_desc_4_label');
818
+
819
+
820
+		switch ($QFI->get('QST_type')) {
821
+			case 'TEXTAREA':
822
+				return EEH_Form_Fields::textarea(
823
+					$display_text,
824
+					$answer,
825
+					$input_name,
826
+					$input_id,
827
+					$input_class,
828
+					[],
829
+					$required,
830
+					$required_text,
831
+					$label_class,
832
+					$disabled,
833
+					$system_ID,
834
+					$use_html_entities
835
+				);
836
+
837
+			case 'DROPDOWN':
838
+				return EEH_Form_Fields::select(
839
+					$display_text,
840
+					$answer,
841
+					$options,
842
+					$input_name,
843
+					$input_id,
844
+					$input_class,
845
+					$required,
846
+					$required_text,
847
+					$label_class,
848
+					$disabled,
849
+					$system_ID,
850
+					$use_html_entities,
851
+					true
852
+				);
853
+
854
+
855
+			case 'RADIO_BTN':
856
+				return EEH_Form_Fields::radio(
857
+					$display_text,
858
+					$answer,
859
+					$options,
860
+					$input_name,
861
+					$input_id,
862
+					$input_class,
863
+					$required,
864
+					$required_text,
865
+					$label_class,
866
+					$disabled,
867
+					$system_ID,
868
+					$use_html_entities,
869
+					$label_b4,
870
+					$use_desc_4_label
871
+				);
872
+
873
+			case 'CHECKBOX':
874
+				return EEH_Form_Fields::checkbox(
875
+					$display_text,
876
+					$answer,
877
+					$options,
878
+					$input_name,
879
+					$input_id,
880
+					$input_class,
881
+					$required,
882
+					$required_text,
883
+					$label_class,
884
+					$disabled,
885
+					$label_b4,
886
+					$system_ID,
887
+					$use_html_entities
888
+				);
889
+
890
+			case 'DATE':
891
+				return EEH_Form_Fields::datepicker(
892
+					$display_text,
893
+					$answer,
894
+					$input_name,
895
+					$input_id,
896
+					$input_class,
897
+					$required,
898
+					$required_text,
899
+					$label_class,
900
+					$disabled,
901
+					$system_ID,
902
+					$use_html_entities
903
+				);
904
+
905
+			case 'TEXT':
906
+			default:
907
+				return EEH_Form_Fields::text(
908
+					$display_text,
909
+					$answer,
910
+					$input_name,
911
+					$input_id,
912
+					$input_class,
913
+					$required,
914
+					$required_text,
915
+					$label_class,
916
+					$disabled,
917
+					$system_ID,
918
+					$use_html_entities
919
+				);
920
+		}
921
+	}
922
+
923
+
924
+	/**
925
+	 * generates HTML for a form text input
926
+	 *
927
+	 * @param string $question    label content
928
+	 * @param string $answer      form input value attribute
929
+	 * @param string $name        form input name attribute
930
+	 * @param string $id          form input css id attribute
931
+	 * @param string $class       form input css class attribute
932
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
933
+	 *                            required 'class', and required 'msg' attribute
934
+	 * @param string $label_class css class attribute for the label
935
+	 * @param string $disabled    disabled="disabled" or null
936
+	 * @return string HTML
937
+	 */
938
+	public static function text(
939
+		$question = false,
940
+		$answer = null,
941
+		$name = false,
942
+		$id = '',
943
+		$class = '',
944
+		$required = false,
945
+		$required_text = '',
946
+		$label_class = '',
947
+		$disabled = false,
948
+		$system_ID = false,
949
+		$use_html_entities = true
950
+	) {
951
+		// need these
952
+		if (! $question || ! $name) {
953
+			return null;
954
+		}
955
+		// prep the answer
956
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
957
+		// prep the required array
958
+		$required = self::prep_required($required);
959
+		// set disabled tag
960
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
961
+		// ya gots ta have style man!!!
962
+		$txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp';
963
+		$class     = empty($class) ? $txt_class : $class;
964
+		$class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
965
+		$extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
966
+
967
+		$label_html =
968
+			$required_text
969
+			. "\n\t\t\t"
970
+			. '<label for="' . $name . '" class="' . $label_class . '">'
971
+			. self::prep_question($question)
972
+			. $required['label']
973
+			. '</label><br/>';
974
+		// filter label but ensure required text comes before it
975
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
976
+
977
+		$input_html =
978
+			"\n\t\t\t"
979
+			. '<input type="text" name="' . $name . '" id="' . $id . '" '
980
+			. 'class="' . $class . ' ' . $required['class'] . '" value="' . esc_attr($answer) . '"  '
981
+			. 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
982
+
983
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
984
+		return $label_html . $input_html;
985
+	}
986
+
987
+
988
+	/**
989
+	 * generates HTML for a form textarea
990
+	 *
991
+	 * @param string $question    label content
992
+	 * @param string $answer      form input value attribute
993
+	 * @param string $name        form input name attribute
994
+	 * @param string $id          form input css id attribute
995
+	 * @param string $class       form input css class attribute
996
+	 * @param array  $dimensions  array of form input rows and cols attributes : array( 'rows' => 3, 'cols' => 40 )
997
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
998
+	 *                            required 'class', and required 'msg' attribute
999
+	 * @param string $label_class css class attribute for the label
1000
+	 * @param string $disabled    disabled="disabled" or null
1001
+	 * @return string HTML
1002
+	 */
1003
+	public static function textarea(
1004
+		$question = false,
1005
+		$answer = null,
1006
+		$name = false,
1007
+		$id = '',
1008
+		$class = '',
1009
+		$dimensions = false,
1010
+		$required = false,
1011
+		$required_text = '',
1012
+		$label_class = '',
1013
+		$disabled = false,
1014
+		$system_ID = false,
1015
+		$use_html_entities = true
1016
+	) {
1017
+		// need these
1018
+		if (! $question || ! $name) {
1019
+			return null;
1020
+		}
1021
+		// prep the answer
1022
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1023
+		// prep the required array
1024
+		$required = self::prep_required($required);
1025
+		// make sure $dimensions is an array
1026
+		$dimensions = is_array($dimensions) ? $dimensions : [];
1027
+		// and set some defaults
1028
+		$dimensions = array_merge(['rows' => 3, 'cols' => 40], $dimensions);
1029
+		// set disabled tag
1030
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1031
+		// ya gots ta have style man!!!
1032
+		$txt_class = is_admin() ? 'regular-text' : 'espresso-textarea-inp';
1033
+		$class     = empty($class) ? $txt_class : $class;
1034
+		$class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1035
+		$extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1036
+
1037
+		$label_html =
1038
+			$required_text
1039
+			. "\n\t\t\t"
1040
+			. '<label for="' . $name . '" class="' . $label_class . '">'
1041
+			. self::prep_question($question)
1042
+			. $required['label']
1043
+			. '</label><br/>';
1044
+		// filter label but ensure required text comes before it
1045
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1046
+
1047
+		$input_html =
1048
+			"\n\t\t\t"
1049
+			. '<textarea name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" '
1050
+			. 'rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '"  '
1051
+			. 'title="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>'
1052
+			. $answer
1053
+			. '</textarea>';
1054
+
1055
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1056
+		return $label_html . $input_html;
1057
+	}
1058
+
1059
+
1060
+	/**
1061
+	 * generates HTML for a form select input
1062
+	 *
1063
+	 * @param string $question    label content
1064
+	 * @param string $answer      form input value attribute
1065
+	 * @param array  $options     array of answer options where array key = option value and array value = option
1066
+	 *                            display text
1067
+	 * @param string $name        form input name attribute
1068
+	 * @param string $id          form input css id attribute
1069
+	 * @param string $class       form input css class attribute
1070
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1071
+	 *                            required 'class', and required 'msg' attribute
1072
+	 * @param string $label_class css class attribute for the label
1073
+	 * @param string $disabled    disabled="disabled" or null
1074
+	 * @return string HTML
1075
+	 */
1076
+	public static function select(
1077
+		$question = false,
1078
+		$answer = null,
1079
+		$options = false,
1080
+		$name = false,
1081
+		$id = '',
1082
+		$class = '',
1083
+		$required = false,
1084
+		$required_text = '',
1085
+		$label_class = '',
1086
+		$disabled = false,
1087
+		$system_ID = false,
1088
+		$use_html_entities = true,
1089
+		$add_please_select_option = false
1090
+	) {
1091
+
1092
+		// need these
1093
+		if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1094
+			return null;
1095
+		}
1096
+		// prep the answer
1097
+		$answer =
1098
+			is_array($answer)
1099
+				? self::prep_answer(array_shift($answer), $use_html_entities)
1100
+				: self::prep_answer(
1101
+					$answer,
1102
+					$use_html_entities
1103
+				);
1104
+		// prep the required array
1105
+		$required = self::prep_required($required);
1106
+		// set disabled tag
1107
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1108
+		// ya gots ta have style man!!!
1109
+		$txt_class = is_admin() ? 'wide' : 'espresso-select-inp';
1110
+		$class     = empty($class) ? $txt_class : $class;
1111
+		$class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1112
+		$extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1113
+
1114
+		$label_html =
1115
+			$required_text
1116
+			. "\n\t\t\t"
1117
+			. '<label for="' . $name . '" class="' . $label_class . '">'
1118
+			. self::prep_question($question)
1119
+			. $required['label']
1120
+			. '</label><br/>';
1121
+		// filter label but ensure required text comes before it
1122
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1123
+
1124
+		$input_html =
1125
+			"\n\t\t\t"
1126
+			. '<select name="' . $name . '" id="' . $id . '" class="' . $class . ' ' . $required['class'] . '" '
1127
+			. 'title="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>';
1128
+		// recursively count array elements, to determine total number of options
1129
+		$only_option = count($options, 1) == 1;
1130
+		if (! $only_option) {
1131
+			// if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected
1132
+			$selected   = $answer === null ? ' selected="selected"' : '';
1133
+			$input_html .= $add_please_select_option
1134
+				? "\n\t\t\t\t"
1135
+				  . '<option value=""' . $selected . '>'
1136
+				  . esc_html__(' - please select - ', 'event_espresso')
1137
+				  . '</option>'
1138
+				: '';
1139
+		}
1140
+		foreach ($options as $key => $value) {
1141
+			// if value is an array, then create option groups, else create regular ol' options
1142
+			$input_html .= is_array($value)
1143
+				? self::_generate_select_option_group(
1144
+					$key,
1145
+					$value,
1146
+					$answer,
1147
+					$use_html_entities
1148
+				)
1149
+				: self::_generate_select_option(
1150
+					$value->value(),
1151
+					$value->desc(),
1152
+					$answer,
1153
+					$only_option,
1154
+					$use_html_entities
1155
+				);
1156
+		}
1157
+
1158
+		$input_html .= "\n\t\t\t" . '</select>';
1159
+
1160
+		$input_html =
1161
+			apply_filters(
1162
+				'FHEE__EEH_Form_Fields__select__before_end_wrapper',
1163
+				$input_html,
1164
+				$question,
1165
+				$answer,
1166
+				$name,
1167
+				$id,
1168
+				$class,
1169
+				$system_ID
1170
+			);
1171
+
1172
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1173
+		return $label_html . $input_html;
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 *  _generate_select_option_group
1179
+	 *
1180
+	 *  if  $value for a select box is an array, then the key will be used as the optgroup label
1181
+	 *  and the value array will be looped thru and the elements sent to _generate_select_option
1182
+	 *
1183
+	 * @param mixed   $opt_group
1184
+	 * @param mixed   $QSOs
1185
+	 * @param mixed   $answer
1186
+	 * @param boolean $use_html_entities
1187
+	 * @return string
1188
+	 */
1189
+	private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true)
1190
+	{
1191
+		$html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">';
1192
+		foreach ($QSOs as $QSO) {
1193
+			$html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities);
1194
+		}
1195
+		$html .= "\n\t\t\t\t" . '</optgroup>';
1196
+		return $html;
1197
+	}
1198
+
1199
+
1200
+	/**
1201
+	 *  _generate_select_option
1202
+	 *
1203
+	 * @param mixed   $key
1204
+	 * @param mixed   $value
1205
+	 * @param mixed   $answer
1206
+	 * @param int     $only_option
1207
+	 * @param boolean $use_html_entities
1208
+	 * @return string
1209
+	 */
1210
+	private static function _generate_select_option(
1211
+		$key,
1212
+		$value,
1213
+		$answer,
1214
+		$only_option = false,
1215
+		$use_html_entities = true
1216
+	) {
1217
+		$key      = self::prep_answer($key, $use_html_entities);
1218
+		$value    = self::prep_answer($value, $use_html_entities);
1219
+		$value    = ! empty($value) ? $value : $key;
1220
+		$selected = ($answer == $key || $only_option) ? 'selected="selected"' : '';
1221
+		return "\n\t\t\t\t"
1222
+			   . '<option value="' . self::prep_option_value($key) . '" ' . $selected . '> '
1223
+			   . $value
1224
+			   . '&nbsp;&nbsp;&nbsp;</option>';
1225
+	}
1226
+
1227
+
1228
+	/**
1229
+	 * generates HTML for form radio button inputs
1230
+	 *
1231
+	 * @param bool|string $question    label content
1232
+	 * @param string      $answer      form input value attribute
1233
+	 * @param array|bool  $options     array of answer options where array key = option value and array value = option
1234
+	 *                                 display text
1235
+	 * @param bool|string $name        form input name attribute
1236
+	 * @param string      $id          form input css id attribute
1237
+	 * @param string      $class       form input css class attribute
1238
+	 * @param array|bool  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1239
+	 *                                 required 'class', and required 'msg' attribute
1240
+	 * @param string      $required_text
1241
+	 * @param string      $label_class css class attribute for the label
1242
+	 * @param bool|string $disabled    disabled="disabled" or null
1243
+	 * @param bool        $system_ID
1244
+	 * @param bool        $use_html_entities
1245
+	 * @param bool        $label_b4
1246
+	 * @param bool        $use_desc_4_label
1247
+	 * @return string HTML
1248
+	 */
1249
+	public static function radio(
1250
+		$question = false,
1251
+		$answer = null,
1252
+		$options = false,
1253
+		$name = false,
1254
+		$id = '',
1255
+		$class = '',
1256
+		$required = false,
1257
+		$required_text = '',
1258
+		$label_class = '',
1259
+		$disabled = false,
1260
+		$system_ID = false,
1261
+		$use_html_entities = true,
1262
+		$label_b4 = false,
1263
+		$use_desc_4_label = false
1264
+	) {
1265
+		// need these
1266
+		if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1267
+			return null;
1268
+		}
1269
+		// prep the answer
1270
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1271
+		// prep the required array
1272
+		$required = self::prep_required($required);
1273
+		// set disabled tag
1274
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1275
+		// ya gots ta have style man!!!
1276
+		$radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
1277
+		$class       = ! empty($class) ? $class : 'espresso-radio-btn-inp';
1278
+		$extra       = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1279
+
1280
+		$label_html =
1281
+			$required_text
1282
+			. "\n\t\t\t"
1283
+			. '<label class="' . $label_class . '">'
1284
+			. self::prep_question($question)
1285
+			. $required['label']
1286
+			. '</label> ';
1287
+		// filter label but ensure required text comes before it
1288
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1289
+
1290
+		$input_html =
1291
+			"\n\t\t\t"
1292
+			. '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $label_class . ' ' . $class . '-ul">';
1293
+
1294
+		$class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1295
+		$class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1296
+
1297
+		foreach ($options as $OPT) {
1298
+			if ($OPT instanceof EE_Question_Option) {
1299
+				$value   = self::prep_option_value($OPT->value());
1300
+				$label   = $use_desc_4_label ? $OPT->desc() : $OPT->value();
1301
+				$size    = $use_desc_4_label
1302
+					? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc())
1303
+					: self::get_label_size_class($OPT->value());
1304
+				$desc    = $OPT->desc();// no self::prep_answer
1305
+				$answer  = is_numeric($value) && empty($answer) ? 0 : $answer;
1306
+				$checked = (string) $value == (string) $answer ? ' checked="checked"' : '';
1307
+				$opt     = '-' . sanitize_key($value);
1308
+
1309
+				$input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1310
+				$input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">';
1311
+				$input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>' : '';
1312
+				$input_html .= "\n\t\t\t\t\t\t"
1313
+							   . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" '
1314
+							   . 'class="' . $class . '" value="' . $value . '" '
1315
+							   . 'title="' . esc_attr($required['msg']) . '" ' . $disabled
1316
+							   . $checked . ' ' . $extra . '/>';
1317
+				$input_html .= ! $label_b4
1318
+					? "\n\t\t\t\t\t\t"
1319
+					  . '<span class="espresso-radio-btn-desc">'
1320
+					  . $label
1321
+					  . '</span>'
1322
+					: '';
1323
+				$input_html .= "\n\t\t\t\t\t" . '</label>';
1324
+				$input_html .= $use_desc_4_label
1325
+					? ''
1326
+					: '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>';
1327
+				$input_html .= "\n\t\t\t\t" . '</li>';
1328
+			}
1329
+		}
1330
+
1331
+		$input_html .= "\n\t\t\t" . '</ul>';
1332
+
1333
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1334
+		return $label_html . $input_html;
1335
+	}
1336
+
1337
+
1338
+	/**
1339
+	 * generates HTML for form checkbox inputs
1340
+	 *
1341
+	 * @param string $question    label content
1342
+	 * @param string $answer      form input value attribute
1343
+	 * @param array  $options     array of options where array key = option value and array value = option display text
1344
+	 * @param string $name        form input name attribute
1345
+	 * @param string $id          form input css id attribute
1346
+	 * @param string $class       form input css class attribute
1347
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1348
+	 *                            required 'class', and required 'msg' attribute
1349
+	 * @param string $label_class css class attribute for the label
1350
+	 * @param string $disabled    disabled="disabled" or null
1351
+	 * @return string HTML
1352
+	 */
1353
+	public static function checkbox(
1354
+		$question = false,
1355
+		$answer = null,
1356
+		$options = false,
1357
+		$name = false,
1358
+		$id = '',
1359
+		$class = '',
1360
+		$required = false,
1361
+		$required_text = '',
1362
+		$label_class = '',
1363
+		$disabled = false,
1364
+		$label_b4 = false,
1365
+		$system_ID = false,
1366
+		$use_html_entities = true
1367
+	) {
1368
+		// need these
1369
+		if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1370
+			return null;
1371
+		}
1372
+		$answer = maybe_unserialize($answer);
1373
+
1374
+		// prep the answer(s)
1375
+		$answer = is_array($answer) ? $answer : [sanitize_key($answer) => $answer];
1376
+
1377
+		foreach ($answer as $key => $value) {
1378
+			$key            = self::prep_option_value($key);
1379
+			$answer[ $key ] = self::prep_answer($value, $use_html_entities);
1380
+		}
1381
+
1382
+		// prep the required array
1383
+		$required = self::prep_required($required);
1384
+		// set disabled tag
1385
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1386
+		// ya gots ta have style man!!!
1387
+		$radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
1388
+		$class       = empty($class) ? 'espresso-radio-btn-inp' : $class;
1389
+		$extra       = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1390
+
1391
+		$label_html =
1392
+			$required_text
1393
+			. "\n\t\t\t"
1394
+			. '<label class="' . $label_class . '">'
1395
+			. self::prep_question($question)
1396
+			. $required['label']
1397
+			. '</label> ';
1398
+		// filter label but ensure required text comes before it
1399
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1400
+
1401
+		$input_html =
1402
+			"\n\t\t\t"
1403
+			. '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $label_class . ' ' . $class . '-ul">';
1404
+
1405
+		$class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1406
+		$class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1407
+
1408
+		foreach ($options as $OPT) {
1409
+			$value = $OPT->value();// self::prep_option_value( $OPT->value() );
1410
+			$size  = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc());
1411
+			$text  = self::prep_answer($OPT->value());
1412
+			$desc  = $OPT->desc();
1413
+			$opt   = '-' . sanitize_key($value);
1414
+
1415
+			$checked = is_array($answer) && in_array($text, $answer) ? ' checked="checked"' : '';
1416
+
1417
+			$input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1418
+			$input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">';
1419
+			$input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
1420
+			$input_html .= "\n\t\t\t\t\t\t"
1421
+						   . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" '
1422
+						   . 'id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" '
1423
+						   . 'title="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
1424
+			$input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>' : '';
1425
+			$input_html .= "\n\t\t\t\t\t" . '</label>';
1426
+			if (! empty($desc) && $desc != $text) {
1427
+				$input_html .= "\n\t\t\t\t\t"
1428
+							   . ' &nbsp; <br/><div class="espresso-checkbox-option-desc small-text grey-text">'
1429
+							   . $desc
1430
+							   . '</div>';
1431
+			}
1432
+			$input_html .= "\n\t\t\t\t" . '</li>';
1433
+		}
1434
+
1435
+		$input_html .= "\n\t\t\t" . '</ul>';
1436
+
1437
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1438
+		return $label_html . $input_html;
1439
+	}
1440
+
1441
+
1442
+	/**
1443
+	 * generates HTML for a form datepicker input
1444
+	 *
1445
+	 * @param string $question    label content
1446
+	 * @param string $answer      form input value attribute
1447
+	 * @param string $name        form input name attribute
1448
+	 * @param string $id          form input css id attribute
1449
+	 * @param string $class       form input css class attribute
1450
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1451
+	 *                            required 'class', and required 'msg' attribute
1452
+	 * @param string $label_class css class attribute for the label
1453
+	 * @param string $disabled    disabled="disabled" or null
1454
+	 * @return string HTML
1455
+	 */
1456
+	public static function datepicker(
1457
+		$question = false,
1458
+		$answer = null,
1459
+		$name = false,
1460
+		$id = '',
1461
+		$class = '',
1462
+		$required = false,
1463
+		$required_text = '',
1464
+		$label_class = '',
1465
+		$disabled = false,
1466
+		$system_ID = false,
1467
+		$use_html_entities = true
1468
+	) {
1469
+		// need these
1470
+		if (! $question || ! $name) {
1471
+			return null;
1472
+		}
1473
+		// prep the answer
1474
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1475
+		// prep the required array
1476
+		$required = self::prep_required($required);
1477
+		// set disabled tag
1478
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1479
+		// ya gots ta have style man!!!
1480
+		$txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp';
1481
+		$class     = empty($class) ? $txt_class : $class;
1482
+		$class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1483
+		$extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1484
+
1485
+		$label_html =
1486
+			$required_text
1487
+			. "\n\t\t\t"
1488
+			. '<label for="' . $name . '" class="' . $label_class . '">'
1489
+			. self::prep_question($question)
1490
+			. $required['label']
1491
+			. '</label><br/>';
1492
+		// filter label but ensure required text comes before it
1493
+		$label_html = apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text);
1494
+
1495
+		$input_html =
1496
+			"\n\t\t\t"
1497
+			. '<input type="text" name="' . $name . '" id="' . $id . '" '
1498
+			. 'class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '"  '
1499
+			. 'title="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
1500
+
1501
+		// enqueue scripts
1502
+		wp_register_style(
1503
+			'espresso-ui-theme',
1504
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1505
+			[],
1506
+			EVENT_ESPRESSO_VERSION
1507
+		);
1508
+		wp_enqueue_style('espresso-ui-theme');
1509
+		wp_enqueue_script('jquery-ui-datepicker');
1510
+
1511
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1512
+		return $label_html . $input_html;
1513
+	}
1514
+
1515
+
1516
+	/**
1517
+	 *  remove_label_keep_required_msg
1518
+	 *  this will strip out a form input's label HTML while keeping the required text HTML that MUST be before the label
1519
+	 *
1520
+	 * @access public
1521
+	 * @return     string
1522
+	 */
1523
+	public static function remove_label_keep_required_msg($label_html, $required_text)
1524
+	{
1525
+		return $required_text;
1526
+	}
1527
+
1528
+
1529
+	/**
1530
+	 * Simply returns the HTML for a hidden input of the given name and value.
1531
+	 *
1532
+	 * @param string $name
1533
+	 * @param string $value
1534
+	 * @return string HTML
1535
+	 */
1536
+	public static function hidden_input($name, $value, $id = '')
1537
+	{
1538
+		$id = ! empty($id) ? $id : $name;
1539
+		return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>';
1540
+	}
1541
+
1542
+
1543
+	/**
1544
+	 * prep_question
1545
+	 *
1546
+	 * @param string $question
1547
+	 * @return string
1548
+	 */
1549
+	public static function prep_question($question)
1550
+	{
1551
+		return $question;
1552
+	}
1553
+
1554
+
1555
+	/**
1556
+	 *  prep_answer
1557
+	 *
1558
+	 * @param mixed $answer
1559
+	 * @return string
1560
+	 */
1561
+	public static function prep_answer($answer, $use_html_entities = true)
1562
+	{
1563
+		// make sure we convert bools first.  Otherwise (bool) false becomes an empty string which is NOT desired,
1564
+		// we want "0".
1565
+		if (is_bool($answer)) {
1566
+			$answer = $answer ? 1 : 0;
1567
+		}
1568
+		$answer = trim(stripslashes(str_replace('&#039;', "'", $answer)));
1569
+		return $use_html_entities ? htmlentities($answer, ENT_QUOTES, 'UTF-8') : $answer;
1570
+	}
1571
+
1572
+
1573
+	/**
1574
+	 *  prep_answer_options
1575
+	 *
1576
+	 * @param array $QSOs array of EE_Question_Option objects
1577
+	 * @return array
1578
+	 */
1579
+	public static function prep_answer_options($QSOs = [])
1580
+	{
1581
+		$prepped_answer_options = [];
1582
+		if (is_array($QSOs) && ! empty($QSOs)) {
1583
+			foreach ($QSOs as $key => $QSO) {
1584
+				if (! $QSO instanceof EE_Question_Option) {
1585
+					$QSO = EE_Question_Option::new_instance(
1586
+						[
1587
+							'QSO_value' => is_array($QSO) && isset($QSO['id'])
1588
+								? (string) $QSO['id']
1589
+								: (string) $key,
1590
+							'QSO_desc'  => is_array($QSO) && isset($QSO['text'])
1591
+								? (string) $QSO['text']
1592
+								: (string) $QSO,
1593
+						]
1594
+					);
1595
+				}
1596
+				if ($QSO->opt_group()) {
1597
+					$prepped_answer_options[ $QSO->opt_group() ][] = $QSO;
1598
+				} else {
1599
+					$prepped_answer_options[] = $QSO;
1600
+				}
1601
+			}
1602
+		}
1603
+		//      d( $prepped_answer_options );
1604
+		return $prepped_answer_options;
1605
+	}
1606
+
1607
+
1608
+	/**
1609
+	 *  prep_option_value
1610
+	 *
1611
+	 * @param string $option_value
1612
+	 * @return string
1613
+	 */
1614
+	public static function prep_option_value($option_value)
1615
+	{
1616
+		return esc_attr(trim(stripslashes($option_value)));
1617
+	}
1618
+
1619
+
1620
+	/**
1621
+	 *  prep_required
1622
+	 *
1623
+	 * @param string|array $required
1624
+	 * @return array
1625
+	 */
1626
+	public static function prep_required($required = [])
1627
+	{
1628
+		// make sure required is an array
1629
+		$required = is_array($required) ? $required : [];
1630
+		// and set some defaults
1631
+		return array_merge(['label' => '', 'class' => '', 'msg' => ''], $required);
1632
+	}
1633
+
1634
+
1635
+	/**
1636
+	 *  get_label_size_class
1637
+	 *
1638
+	 * @param string $value
1639
+	 * @return string
1640
+	 */
1641
+	public static function get_label_size_class($value = false)
1642
+	{
1643
+		if ($value === false || $value === '') {
1644
+			return ' class="medium-lbl"';
1645
+		}
1646
+		// determine length of option value
1647
+		$val_size = strlen($value);
1648
+		switch ($val_size) {
1649
+			case $val_size < 3:
1650
+				$size = ' class="nano-lbl"';
1651
+				break;
1652
+			case $val_size < 6:
1653
+				$size = ' class="micro-lbl"';
1654
+				break;
1655
+			case $val_size < 12:
1656
+				$size = ' class="tiny-lbl"';
1657
+				break;
1658
+			case $val_size < 25:
1659
+				$size = ' class="small-lbl"';
1660
+				break;
1661
+			case $val_size > 100:
1662
+				$size = ' class="big-lbl"';
1663
+				break;
1664
+			default:
1665
+				$size = ' class="medium-lbl"';
1666
+				break;
1667
+		}
1668
+		return $size;
1669
+	}
1670
+
1671
+
1672
+	/**
1673
+	 *  _load_system_dropdowns
1674
+	 *
1675
+	 * @param EE_Question_Form_Input $QFI
1676
+	 * @return array
1677
+	 * @throws EE_Error
1678
+	 * @throws ReflectionException
1679
+	 */
1680
+	private static function _load_system_dropdowns($QFI)
1681
+	{
1682
+		$QST_system = $QFI->get('QST_system');
1683
+		switch ($QST_system) {
1684
+			case 'state':
1685
+				$QFI = self::generate_state_dropdown($QFI);
1686
+				break;
1687
+			case 'country':
1688
+				$QFI = self::generate_country_dropdown($QFI);
1689
+				break;
1690
+			case 'admin-state':
1691
+				$QFI = self::generate_state_dropdown($QFI, true);
1692
+				break;
1693
+			case 'admin-country':
1694
+				$QFI = self::generate_country_dropdown($QFI, true);
1695
+				break;
1696
+		}
1697
+		return $QFI;
1698
+	}
1699
+
1700
+
1701
+	/**
1702
+	 * This preps dropdowns that are specialized.
1703
+	 *
1704
+	 * @param EE_Question_Form_Input $QFI
1705
+	 *
1706
+	 * @return EE_Question_Form_Input
1707
+	 * @throws EE_Error
1708
+	 * @throws ReflectionException
1709
+	 * @since  4.6.0
1710
+	 */
1711
+	protected static function _load_specialized_dropdowns($QFI)
1712
+	{
1713
+		switch ($QFI->get('QST_type')) {
1714
+			case 'STATE':
1715
+				$QFI = self::generate_state_dropdown($QFI);
1716
+				break;
1717
+			case 'COUNTRY':
1718
+				$QFI = self::generate_country_dropdown($QFI);
1719
+				break;
1720
+		}
1721
+		return $QFI;
1722
+	}
1723
+
1724
+
1725
+	/**
1726
+	 *    generate_state_dropdown
1727
+	 *
1728
+	 * @param EE_Question_Form_Input $QST
1729
+	 * @param bool                   $get_all
1730
+	 * @return EE_Question_Form_Input
1731
+	 * @throws EE_Error
1732
+	 * @throws ReflectionException
1733
+	 */
1734
+	public static function generate_state_dropdown($QST, $get_all = false)
1735
+	{
1736
+		$states = $get_all
1737
+			? EEM_State::instance()->get_all_states()
1738
+			: EEM_State::instance()->get_all_states_of_active_countries();
1739
+		if ($states && count($states) != count($QST->options())) {
1740
+			$QST->set('QST_type', 'DROPDOWN');
1741
+			// if multiple countries, we'll create option groups within the dropdown
1742
+			foreach ($states as $state) {
1743
+				if ($state instanceof EE_State) {
1744
+					$QSO = EE_Question_Option::new_instance(
1745
+						[
1746
+							'QSO_value'   => $state->ID(),
1747
+							'QSO_desc'    => $state->name(),
1748
+							'QST_ID'      => $QST->get('QST_ID'),
1749
+							'QSO_deleted' => false,
1750
+						]
1751
+					);
1752
+					// set option group
1753
+					$QSO->set_opt_group($state->country()->name());
1754
+					// add option to question
1755
+					$QST->add_temp_option($QSO);
1756
+				}
1757
+			}
1758
+		}
1759
+		return $QST;
1760
+	}
1761
+
1762
+
1763
+	/**
1764
+	 *    generate_country_dropdown
1765
+	 *
1766
+	 * @param      $QST
1767
+	 * @param bool $get_all
1768
+	 * @return array
1769
+	 * @throws EE_Error
1770
+	 * @throws ReflectionException
1771
+	 * @internal param array $question
1772
+	 */
1773
+	public static function generate_country_dropdown($QST, $get_all = false)
1774
+	{
1775
+		$countries = $get_all
1776
+			? EEM_Country::instance()->get_all_countries()
1777
+			: EEM_Country::instance()->get_all_active_countries();
1778
+		if ($countries && count($countries) != count($QST->options())) {
1779
+			$QST->set('QST_type', 'DROPDOWN');
1780
+			// now add countries
1781
+			foreach ($countries as $country) {
1782
+				if ($country instanceof EE_Country) {
1783
+					$QSO = EE_Question_Option::new_instance(
1784
+						[
1785
+							'QSO_value'   => $country->ID(),
1786
+							'QSO_desc'    => $country->name(),
1787
+							'QST_ID'      => $QST->get('QST_ID'),
1788
+							'QSO_deleted' => false,
1789
+						]
1790
+					);
1791
+					$QST->add_temp_option($QSO);
1792
+				}
1793
+			}
1794
+		}
1795
+		return $QST;
1796
+	}
1797
+
1798
+
1799
+	/**
1800
+	 *  generates options for a month dropdown selector with numbers from 01 to 12
1801
+	 *
1802
+	 * @return array()
1803
+	 */
1804
+	public static function two_digit_months_dropdown_options()
1805
+	{
1806
+		$options = [];
1807
+		for ($x = 1; $x <= 12; $x++) {
1808
+			$mm             = str_pad($x, 2, '0', STR_PAD_LEFT);
1809
+			$options[ $mm ] = $mm;
1810
+		}
1811
+		return EEH_Form_Fields::prep_answer_options($options);
1812
+	}
1813
+
1814
+
1815
+	/**
1816
+	 *  generates a year dropdown selector with numbers for the next ten years
1817
+	 *
1818
+	 * @return array
1819
+	 */
1820
+	public static function next_decade_two_digit_year_dropdown_options()
1821
+	{
1822
+		$options      = [];
1823
+		$current_year = date('y');
1824
+		$next_decade  = $current_year + 10;
1825
+		for ($x = $current_year; $x <= $next_decade; $x++) {
1826
+			$yy             = str_pad($x, 2, '0', STR_PAD_LEFT);
1827
+			$options[ $yy ] = $yy;
1828
+		}
1829
+		return EEH_Form_Fields::prep_answer_options($options);
1830
+	}
1831
+
1832
+
1833
+	/**
1834
+	 * generates a month/year dropdown selector for all registrations matching the given criteria.  Typically used for
1835
+	 * list table filter.
1836
+	 *
1837
+	 * @param string  $cur_date     any currently selected date can be entered here.
1838
+	 * @param string  $status       Registration status
1839
+	 * @param integer $evt_category Event Category ID if the Event Category filter is selected
1840
+	 * @return string                html
1841
+	 * @throws EE_Error
1842
+	 */
1843
+	public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1844
+	{
1845
+		$_where = [];
1846
+		if (! empty($status)) {
1847
+			$_where['STS_ID'] = $status;
1848
+		}
1849
+
1850
+		if ($evt_category > 0) {
1851
+			$_where['Event.Term_Taxonomy.term_id'] = $evt_category;
1852
+		}
1853
+
1854
+		$regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where);
1855
+
1856
+		// setup vals for select input helper
1857
+		$options = [
1858
+			0 => [
1859
+				'text' => esc_html__('Select a Month/Year', 'event_espresso'),
1860
+				'id'   => '',
1861
+			],
1862
+		];
1863
+
1864
+		foreach ($regdtts as $regdtt) {
1865
+			$date      = $regdtt->reg_month . ' ' . $regdtt->reg_year;
1866
+			$options[] = [
1867
+				'text' => $date,
1868
+				'id'   => $date,
1869
+			];
1870
+		}
1871
+
1872
+		return self::select_input('month_range', $options, $cur_date, '', 'wide');
1873
+	}
1874
+
1875
+
1876
+	/**
1877
+	 * generates a month/year dropdown selector for all events matching the given criteria
1878
+	 * Typically used for list table filter
1879
+	 *
1880
+	 * @param string $cur_date          any currently selected date can be entered here.
1881
+	 * @param string $status            "view" (i.e. all, today, month, draft)
1882
+	 * @param int    $evt_category      category event belongs to
1883
+	 * @param string $evt_active_status "upcoming", "expired", "active", or "inactive"
1884
+	 * @return string                    html
1885
+	 * @throws EE_Error
1886
+	 */
1887
+	public static function generate_event_months_dropdown(
1888
+		$cur_date = '',
1889
+		$status = null,
1890
+		$evt_category = null,
1891
+		$evt_active_status = null
1892
+	) {
1893
+		// determine what post_status our condition will have for the query.
1894
+		// phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
1895
+		switch ($status) {
1896
+			case 'month':
1897
+			case 'today':
1898
+			case null:
1899
+			case 'all':
1900
+				$where['Event.status'] = ['NOT IN', ['trash']];
1901
+				break;
1902
+			case 'draft':
1903
+				$where['Event.status'] = ['IN', ['draft', 'auto-draft']];
1904
+				break;
1905
+			default:
1906
+				$where['Event.status'] = $status;
1907
+		}
1908
+
1909
+		// phpcs:enable
1910
+
1911
+		// categories?
1912
+
1913
+
1914
+		if (! empty($evt_category)) {
1915
+			$where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1916
+			$where['Event.Term_Taxonomy.term_id']  = $evt_category;
1917
+		}
1918
+
1919
+
1920
+		//      $where['DTT_is_primary'] = 1;
1921
+
1922
+		$DTTS = EEM_Datetime::instance()->get_dtt_months_and_years($where, $evt_active_status);
1923
+
1924
+		// let's setup vals for select input helper
1925
+		$options = [
1926
+			0 => [
1927
+				'text' => esc_html__('Select a Month/Year', 'event_espresso'),
1928
+				'id'   => "",
1929
+			],
1930
+		];
1931
+
1932
+
1933
+		// translate month and date
1934
+		global $wp_locale;
1935
+
1936
+		foreach ($DTTS as $DTT) {
1937
+			$localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
1938
+			$id             = $DTT->dtt_month . ' ' . $DTT->dtt_year;
1939
+			$options[]      = [
1940
+				'text' => $localized_date,
1941
+				'id'   => $id,
1942
+			];
1943
+		}
1944
+
1945
+
1946
+		return self::select_input('month_range', $options, $cur_date, '', 'wide');
1947
+	}
1948
+
1949
+
1950
+	/**
1951
+	 * generates the dropdown selector for event categories
1952
+	 * typically used as a filter on list tables.
1953
+	 *
1954
+	 * @param integer $current_cat currently selected category
1955
+	 * @return string               html for dropdown
1956
+	 * @throws EE_Error
1957
+	 * @throws ReflectionException
1958
+	 */
1959
+	public static function generate_event_category_dropdown($current_cat = -1)
1960
+	{
1961
+		$categories = EEM_Term::instance()->get_all_ee_categories(true);
1962
+		$options    = [
1963
+			'0' => [
1964
+				'text' => esc_html__('All Categories', 'event_espresso'),
1965
+				'id'   => -1,
1966
+			],
1967
+		];
1968
+
1969
+		// setup categories for dropdown
1970
+		foreach ($categories as $category) {
1971
+			$options[] = [
1972
+				'text' => $category->get('name'),
1973
+				'id'   => $category->ID(),
1974
+			];
1975
+		}
1976
+
1977
+		return self::select_input('EVT_CAT', $options, $current_cat);
1978
+	}
1979
+
1980
+
1981
+	/**
1982
+	 *    generate a submit button with or without it's own microform
1983
+	 *    this is the only way to create buttons that are compatible across all themes
1984
+	 *
1985
+	 * @access    public
1986
+	 * @param string      $url              - the form action
1987
+	 * @param string      $ID               - some kind of unique ID, appended with "-sbmt" for the input and "-frm"
1988
+	 *                                      for the form
1989
+	 * @param string      $class            - css classes (separated by spaces if more than one)
1990
+	 * @param string      $text             - what appears on the button
1991
+	 * @param string      $nonce_action     - if using nonces
1992
+	 * @param bool|string $input_only       - whether to print form header and footer. TRUE returns the input without
1993
+	 *                                      the form
1994
+	 * @param string      $extra_attributes - any extra attributes that need to be attached to the form input
1995
+	 * @return    string
1996
+	 */
1997
+	public static function submit_button(
1998
+		$url = '',
1999
+		$ID = '',
2000
+		$class = '',
2001
+		$text = '',
2002
+		$nonce_action = '',
2003
+		$input_only = false,
2004
+		$extra_attributes = ''
2005
+	) {
2006
+		$btn = '';
2007
+		if (empty($url) || empty($ID)) {
2008
+			return $btn;
2009
+		}
2010
+		$text = ! empty($text) ? $text : esc_html__('Submit', 'event_espresso');
2011
+		$btn  .= '<input id="' . $ID . '-btn" class="' . $class . '" '
2012
+				 . 'type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
2013
+		if (! $input_only) {
2014
+			$btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
2015
+			$btn_frm .= ! empty($nonce_action)
2016
+				? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false)
2017
+				: '';
2018
+			$btn_frm .= $btn;
2019
+			$btn_frm .= '</form>';
2020
+			$btn     = $btn_frm;
2021
+			unset($btn_frm);
2022
+		}
2023
+		return $btn;
2024
+	}
2025 2025
 }
Please login to merge, or discard this patch.
core/helpers/EEH_MSG_Template.helper.php 1 patch
Indentation   +1249 added lines, -1249 removed lines patch added patch discarded remove patch
@@ -15,1253 +15,1253 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Holds a collection of EE_Message_Template_Pack objects.
20
-     * @type EE_Messages_Template_Pack_Collection
21
-     */
22
-    protected static $_template_pack_collection;
23
-
24
-
25
-    /**
26
-     * @throws EE_Error
27
-     */
28
-    private static function _set_autoloader()
29
-    {
30
-        EED_Messages::set_autoloaders();
31
-    }
32
-
33
-
34
-    /**
35
-     * generate_new_templates
36
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
37
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
38
-     * for the event.
39
-     *
40
-     * @access protected
41
-     * @param string $messenger     the messenger we are generating templates for
42
-     * @param array  $message_types array of message types that the templates are generated for.
43
-     * @param int    $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID
44
-     *                              to use as the base for the new generated template.
45
-     * @param bool   $global        true indicates generating templates on messenger activation. false requires GRP_ID
46
-     *                              for event specific template generation.
47
-     * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array
48
-     *                for templates that are generated.  If this is an empty array then it means no templates were
49
-     *                generated which usually means there was an error.  Anything in the array with an empty value for
50
-     *                `MTP_context` means that it was not a new generated template but just reactivated (which only
51
-     *                happens for global templates that already exist in the database.
52
-     * @throws EE_Error
53
-     * @throws ReflectionException
54
-     */
55
-    public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
56
-    {
57
-        // make sure message_type is an array.
58
-        $message_types = (array) $message_types;
59
-        $templates = array();
60
-
61
-        if (empty($messenger)) {
62
-            throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso'));
63
-        }
64
-
65
-        // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
66
-        if (empty($message_types)) {
67
-            throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso'));
68
-        }
69
-
70
-        EEH_MSG_Template::_set_autoloader();
71
-        foreach ($message_types as $message_type) {
72
-            // if this is global template generation.
73
-            if ($global) {
74
-                // let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
75
-                if (empty($GRP_ID)) {
76
-                    $GRP_ID = EEM_Message_Template_Group::instance()->get_one(
77
-                        array(
78
-                            array(
79
-                                'MTP_messenger'    => $messenger,
80
-                                'MTP_message_type' => $message_type,
81
-                                'MTP_is_global'    => true,
82
-                            ),
83
-                        )
84
-                    );
85
-                    $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
86
-                }
87
-                // First let's determine if we already HAVE global templates for this messenger and message_type combination.
88
-                //  If we do then NO generation!!
89
-                if (EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
90
-                    $templates[] = array(
91
-                        'GRP_ID' => $GRP_ID,
92
-                        'MTP_context' => '',
93
-                    );
94
-                    // we already have generated templates for this so let's go to the next message type.
95
-                    continue;
96
-                }
97
-            }
98
-            $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
99
-
100
-            if (! $new_message_template_group) {
101
-                continue;
102
-            }
103
-            $templates[] = $new_message_template_group;
104
-        }
105
-
106
-        return $templates;
107
-    }
108
-
109
-
110
-    /**
111
-     * The purpose of this method is to determine if there are already generated templates in the database for the
112
-     * given variables.
113
-     *
114
-     * @param string $messenger    messenger
115
-     * @param string $message_type message type
116
-     * @param int    $GRP_ID       GRP ID ( if a custom template) (if not provided then we're just doing global
117
-     *                             template check)
118
-     * @return bool                true = generated, false = hasn't been generated.
119
-     * @throws EE_Error
120
-     */
121
-    public static function already_generated($messenger, $message_type, $GRP_ID = 0)
122
-    {
123
-        EEH_MSG_Template::_set_autoloader();
124
-        // what method we use depends on whether we have an GRP_ID or not
125
-        $count = empty($GRP_ID)
126
-            ? EEM_Message_Template::instance()->count(
127
-                array(
128
-                    array(
129
-                        'Message_Template_Group.MTP_messenger'    => $messenger,
130
-                        'Message_Template_Group.MTP_message_type' => $message_type,
131
-                        'Message_Template_Group.MTP_is_global'    => true
132
-                    )
133
-                )
134
-            )
135
-            : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
136
-
137
-        return $count > 0;
138
-    }
139
-
140
-
141
-    /**
142
-     * Updates all message templates matching the incoming messengers and message types to active status.
143
-     *
144
-     * @static
145
-     * @param array $messenger_names    Messenger slug
146
-     * @param array $message_type_names Message type slug
147
-     * @return  int                         count of updated records.
148
-     * @throws EE_Error
149
-     */
150
-    public static function update_to_active($messenger_names, $message_type_names)
151
-    {
152
-        $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
153
-        $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
154
-        return EEM_Message_Template_Group::instance()->update(
155
-            array( 'MTP_is_active' => 1 ),
156
-            array(
157
-                array(
158
-                    'MTP_messenger'     => array( 'IN', $messenger_names ),
159
-                    'MTP_message_type'  => array( 'IN', $message_type_names )
160
-                )
161
-            )
162
-        );
163
-    }
164
-
165
-
166
-    /**
167
-     * Updates all message template groups matching the incoming arguments to inactive status.
168
-     *
169
-     * @static
170
-     * @param array $messenger_names    The messenger slugs.
171
-     *                                  If empty then all templates matching the message types are marked inactive.
172
-     *                                  Otherwise only templates matching the messengers and message types.
173
-     * @param array $message_type_names The message type slugs.
174
-     *                                  If empty then all templates matching the messengers are marked inactive.
175
-     *                                  Otherwise only templates matching the messengers and message types.
176
-     *
177
-     * @return int  count of updated records.
178
-     * @throws EE_Error
179
-     */
180
-    public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
181
-    {
182
-        return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
183
-            $messenger_names,
184
-            $message_type_names
185
-        );
186
-    }
187
-
188
-
189
-    /**
190
-     * The purpose of this function is to return all installed message objects
191
-     * (messengers and message type regardless of whether they are ACTIVE or not)
192
-     *
193
-     * @param string $type
194
-     * @return array array consisting of installed messenger objects and installed message type objects.
195
-     * @throws EE_Error
196
-     * @throws ReflectionException
197
-     * @deprecated 4.9.0
198
-     * @static
199
-     */
200
-    public static function get_installed_message_objects($type = 'all')
201
-    {
202
-        self::_set_autoloader();
203
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
204
-        return array(
205
-            'messenger' => $message_resource_manager->installed_messengers(),
206
-            'message_type' => $message_resource_manager->installed_message_types()
207
-        );
208
-    }
209
-
210
-
211
-    /**
212
-     * This will return an array of shortcodes => labels from the
213
-     * messenger and message_type objects associated with this
214
-     * template.
215
-     *
216
-     * @param string $message_type
217
-     * @param string $messenger
218
-     * @param array  $fields                        What fields we're returning valid shortcodes for.
219
-     *                                              If empty then we assume all fields are to be returned. Optional.
220
-     * @param string $context                       What context we're going to return shortcodes for. Optional.
221
-     * @param bool   $merged                        If TRUE then we don't return shortcodes indexed by field,
222
-     *                                              but instead an array of the unique shortcodes for all the given (
223
-     *                                              or all) fields. Optional.
224
-     * @return array                                an array of shortcodes in the format
225
-     *                                              array( '[shortcode] => 'label')
226
-     *                                              OR
227
-     *                                              FALSE if no shortcodes found.
228
-     * @throws ReflectionException
229
-     * @throws EE_Error*@since 4.3.0
230
-     *
231
-     */
232
-    public static function get_shortcodes(
233
-        $message_type,
234
-        $messenger,
235
-        $fields = array(),
236
-        $context = 'admin',
237
-        $merged = false
238
-    ) {
239
-        $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
240
-        $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
241
-        /** @var EE_Message_Resource_Manager $message_resource_manager */
242
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
243
-        // convert slug to object
244
-        $messenger = $message_resource_manager->get_messenger($messenger);
245
-
246
-        // if messenger isn't a EE_messenger resource then bail.
247
-        if (! $messenger instanceof EE_messenger) {
248
-            return array();
249
-        }
250
-
251
-        // validate class for getting our list of shortcodes
252
-        $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
253
-        if (! class_exists($classname)) {
254
-            $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
255
-            $msg[] = sprintf(
256
-                esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
257
-                $classname
258
-            );
259
-            throw new EE_Error(implode('||', $msg));
260
-        }
261
-
262
-        /** @type EE_Messages_Validator $_VLD */
263
-        $_VLD = new $classname(array(), $context);
264
-        $valid_shortcodes = $_VLD->get_validators();
265
-
266
-        // let's make sure we're only getting the shortcode part of the validators
267
-        $shortcodes = array();
268
-        foreach ($valid_shortcodes as $field => $validators) {
269
-            $shortcodes[ $field ] = $validators['shortcodes'];
270
-        }
271
-        $valid_shortcodes = $shortcodes;
272
-
273
-        // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
274
-        if (! empty($fields)) {
275
-            $specified_shortcodes = array();
276
-            foreach ($fields as $field) {
277
-                if (isset($valid_shortcodes[ $field ])) {
278
-                    $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
279
-                }
280
-            }
281
-            $valid_shortcodes = $specified_shortcodes;
282
-        }
283
-
284
-        // if not merged then let's replace the fields with the localized fields
285
-        if (! $merged) {
286
-            // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
287
-            $field_settings = $messenger->get_template_fields();
288
-            $localized = array();
289
-            foreach ($valid_shortcodes as $field => $shortcodes) {
290
-                // get localized field label
291
-                if (isset($field_settings[ $field ])) {
292
-                    // possible that this is used as a main field.
293
-                    if (empty($field_settings[ $field ])) {
294
-                        if (isset($field_settings['extra'][ $field ])) {
295
-                            $_field = $field_settings['extra'][ $field ]['main']['label'];
296
-                        } else {
297
-                            $_field = $field;
298
-                        }
299
-                    } else {
300
-                        $_field = $field_settings[ $field ]['label'];
301
-                    }
302
-                } elseif (isset($field_settings['extra'])) {
303
-                    // loop through extra "main fields" and see if any of their children have our field
304
-                    foreach ($field_settings['extra'] as $fields) {
305
-                        if (isset($fields[ $field ])) {
306
-                            $_field = $fields[ $field ]['label'];
307
-                        } else {
308
-                            $_field = $field;
309
-                        }
310
-                    }
311
-                } else {
312
-                    $_field = $field;
313
-                }
314
-                if (isset($_field)) {
315
-                    $localized[ (string) $_field ] = $shortcodes;
316
-                }
317
-            }
318
-            $valid_shortcodes = $localized;
319
-        }
320
-
321
-        // if $merged then let's merge all the shortcodes into one list NOT indexed by field.
322
-        if ($merged) {
323
-            $merged_codes = array();
324
-            foreach ($valid_shortcodes as $shortcode) {
325
-                foreach ($shortcode as $code => $label) {
326
-                    if (isset($merged_codes[ $code ])) {
327
-                        continue;
328
-                    } else {
329
-                        $merged_codes[ $code ] = $label;
330
-                    }
331
-                }
332
-            }
333
-            $valid_shortcodes = $merged_codes;
334
-        }
335
-
336
-        return $valid_shortcodes;
337
-    }
338
-
339
-
340
-    /**
341
-     * Get Messenger object.
342
-     *
343
-     * @param string $messenger messenger slug for the messenger object we want to retrieve.
344
-     * @return EE_messenger
345
-     * @throws ReflectionException
346
-     * @throws EE_Error*@since 4.3.0
347
-     * @deprecated 4.9.0
348
-     */
349
-    public static function messenger_obj($messenger)
350
-    {
351
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
352
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
353
-        return $Message_Resource_Manager->get_messenger($messenger);
354
-    }
355
-
356
-
357
-    /**
358
-     * get Message type object
359
-     *
360
-     * @param string $message_type the slug for the message type object to retrieve
361
-     * @return EE_message_type
362
-     * @throws ReflectionException
363
-     * @throws EE_Error*@since 4.3.0
364
-     * @deprecated 4.9.0
365
-     */
366
-    public static function message_type_obj($message_type)
367
-    {
368
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
369
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
370
-        return $Message_Resource_Manager->get_message_type($message_type);
371
-    }
372
-
373
-
374
-    /**
375
-     * Given a message_type slug, will return whether that message type is active in the system or not.
376
-     *
377
-     * @since    4.3.0
378
-     * @param string $message_type message type to check for.
379
-     * @return boolean
380
-     * @throws EE_Error
381
-     * @throws ReflectionException
382
-     */
383
-    public static function is_mt_active($message_type)
384
-    {
385
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
386
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
387
-        $active_mts = $Message_Resource_Manager->list_of_active_message_types();
388
-        return in_array($message_type, $active_mts);
389
-    }
390
-
391
-
392
-    /**
393
-     * Given a messenger slug, will return whether that messenger is active in the system or not.
394
-     *
395
-     * @since    4.3.0
396
-     *
397
-     * @param string $messenger slug for messenger to check.
398
-     * @return boolean
399
-     * @throws EE_Error
400
-     * @throws ReflectionException
401
-     */
402
-    public static function is_messenger_active($messenger)
403
-    {
404
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
405
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
406
-        $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
407
-        return $active_messenger instanceof EE_messenger;
408
-    }
409
-
410
-
411
-    /**
412
-     * Used to return active messengers array stored in the wp options table.
413
-     * If no value is present in the option then an empty array is returned.
414
-     *
415
-     * @deprecated 4.9
416
-     * @since      4.3.1
417
-     *
418
-     * @return array
419
-     * @throws EE_Error
420
-     * @throws ReflectionException
421
-     */
422
-    public static function get_active_messengers_in_db()
423
-    {
424
-        EE_Error::doing_it_wrong(
425
-            __METHOD__,
426
-            esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
427
-            '4.9.0'
428
-        );
429
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
430
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
431
-        return $Message_Resource_Manager->get_active_messengers_option();
432
-    }
433
-
434
-
435
-    /**
436
-     * Used to update the active messengers array stored in the wp options table.
437
-     *
438
-     * @since      4.3.1
439
-     * @deprecated 4.9.0
440
-     *
441
-     * @param array $data_to_save Incoming data to save.
442
-     *
443
-     * @return bool FALSE if not updated, TRUE if updated.
444
-     * @throws EE_Error
445
-     * @throws ReflectionException
446
-     */
447
-    public static function update_active_messengers_in_db($data_to_save)
448
-    {
449
-        EE_Error::doing_it_wrong(
450
-            __METHOD__,
451
-            esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
452
-            '4.9.0'
453
-        );
454
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
455
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
456
-        return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
457
-    }
458
-
459
-
460
-    /**
461
-     * This does some validation of incoming params, determines what type of url is being prepped and returns the
462
-     * appropriate url trigger
463
-     *
464
-     * @param EE_message_type $message_type
465
-     * @param EE_Message $message
466
-     * @param EE_Registration | null $registration  The registration object must be included if this
467
-     *                                              is going to be a registration trigger url.
468
-     * @param string $sending_messenger             The (optional) sending messenger for the url.
469
-     *
470
-     * @return string
471
-     * @throws EE_Error
472
-     */
473
-    public static function get_url_trigger(
474
-        EE_message_type $message_type,
475
-        EE_Message $message,
476
-        $registration = null,
477
-        $sending_messenger = ''
478
-    ) {
479
-        // first determine if the url can be to the EE_Message object.
480
-        if (! $message_type->always_generate()) {
481
-            return EEH_MSG_Template::generate_browser_trigger($message);
482
-        }
483
-
484
-        // if $registration object is not valid then exit early because there's nothing that can be generated.
485
-        if (! $registration instanceof EE_Registration) {
486
-            throw new EE_Error(
487
-                esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
488
-            );
489
-        }
490
-
491
-        // validate given context
492
-        $contexts = $message_type->get_contexts();
493
-        if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
494
-            throw new EE_Error(
495
-                sprintf(
496
-                    esc_html__('The context %s is not a valid context for %s.', 'event_espresso'),
497
-                    $message->context(),
498
-                    get_class($message_type)
499
-                )
500
-            );
501
-        }
502
-
503
-        // valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
504
-        if (! empty($sending_messenger)) {
505
-            $with_messengers = $message_type->with_messengers();
506
-            if (
507
-                ! isset($with_messengers[ $message->messenger() ])
508
-                 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
509
-            ) {
510
-                throw new EE_Error(
511
-                    sprintf(
512
-                        esc_html__(
513
-                            'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
514
-                            'event_espresso'
515
-                        ),
516
-                        $sending_messenger,
517
-                        get_class($message_type)
518
-                    )
519
-                );
520
-            }
521
-        } else {
522
-            $sending_messenger = $message->messenger();
523
-        }
524
-        return EEH_MSG_Template::generate_url_trigger(
525
-            $sending_messenger,
526
-            $message->messenger(),
527
-            $message->context(),
528
-            $message->message_type(),
529
-            $registration,
530
-            $message->GRP_ID()
531
-        );
532
-    }
533
-
534
-
535
-    /**
536
-     * This returns the url for triggering a in browser view of a specific EE_Message object.
537
-     * @param EE_Message $message
538
-     * @return string.
539
-     */
540
-    public static function generate_browser_trigger(EE_Message $message)
541
-    {
542
-        $query_args = array(
543
-            'ee' => 'msg_browser_trigger',
544
-            'token' => $message->MSG_token()
545
-        );
546
-        return apply_filters(
547
-            'FHEE__EEH_MSG_Template__generate_browser_trigger',
548
-            add_query_arg($query_args, site_url()),
549
-            $message
550
-        );
551
-    }
552
-
553
-
554
-
555
-
556
-
557
-
558
-    /**
559
-     * This returns the url for triggering an in browser view of the error saved on the incoming message object.
560
-     * @param EE_Message $message
561
-     * @return string
562
-     */
563
-    public static function generate_error_display_trigger(EE_Message $message)
564
-    {
565
-        return apply_filters(
566
-            'FHEE__EEH_MSG_Template__generate_error_display_trigger',
567
-            add_query_arg(
568
-                array(
569
-                    'ee' => 'msg_browser_error_trigger',
570
-                    'token' => $message->MSG_token()
571
-                ),
572
-                site_url()
573
-            ),
574
-            $message
575
-        );
576
-    }
577
-
578
-
579
-    /**
580
-     * This generates a url trigger for the msg_url_trigger route using the given arguments
581
-     *
582
-     * @param string          $sending_messenger      The sending messenger slug.
583
-     * @param string          $generating_messenger   The generating messenger slug.
584
-     * @param string          $context                The context for the template.
585
-     * @param string          $message_type           The message type slug
586
-     * @param EE_Registration $registration
587
-     * @param integer         $message_template_group id   The EE_Message_Template_Group ID for the template.
588
-     * @param integer         $data_id                The id to the EE_Base_Class for getting the data used by the
589
-     *                                                trigger.
590
-     * @return string          The generated url.
591
-     * @throws EE_Error
592
-     */
593
-    public static function generate_url_trigger(
594
-        $sending_messenger,
595
-        $generating_messenger,
596
-        $context,
597
-        $message_type,
598
-        EE_Registration $registration,
599
-        $message_template_group,
600
-        $data_id = 0
601
-    ) {
602
-        $query_args = array(
603
-            'ee' => 'msg_url_trigger',
604
-            'snd_msgr' => $sending_messenger,
605
-            'gen_msgr' => $generating_messenger,
606
-            'message_type' => $message_type,
607
-            'context' => $context,
608
-            'token' => $registration->reg_url_link(),
609
-            'GRP_ID' => $message_template_group,
610
-            'id' => $data_id
611
-            );
612
-        $url = add_query_arg($query_args, get_home_url());
613
-
614
-        // made it here so now we can just get the url and filter it.  Filtered globally and by message type.
615
-        return apply_filters(
616
-            'FHEE__EEH_MSG_Template__generate_url_trigger',
617
-            $url,
618
-            $sending_messenger,
619
-            $generating_messenger,
620
-            $context,
621
-            $message_type,
622
-            $registration,
623
-            $message_template_group,
624
-            $data_id
625
-        );
626
-    }
627
-
628
-
629
-
630
-
631
-    /**
632
-     * Return the specific css for the action icon given.
633
-     *
634
-     * @param string $type  What action to return.
635
-     * @return string[]
636
-     * @since 4.9.0
637
-     */
638
-    public static function get_message_action_icon($type)
639
-    {
640
-        $action_icons = self::get_message_action_icons();
641
-        return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];
642
-    }
643
-
644
-
645
-    /**
646
-     * This is used for retrieving the css classes used for the icons representing message actions.
647
-     *
648
-     * @since 4.9.0
649
-     *
650
-     * @return array
651
-     */
652
-    public static function get_message_action_icons()
653
-    {
654
-        return apply_filters(
655
-            'FHEE__EEH_MSG_Template__message_action_icons',
656
-            array(
657
-                'view' => array(
658
-                    'label' => esc_html__('View Message', 'event_espresso'),
659
-                    'css_class' => 'dashicons dashicons-welcome-view-site',
660
-                ),
661
-                'error' => array(
662
-                    'label' => esc_html__('View Error Message', 'event_espresso'),
663
-                    'css_class' => 'dashicons dashicons-info',
664
-                ),
665
-                'see_notifications_for' => array(
666
-                    'label' => esc_html__('View Related Messages', 'event_espresso'),
667
-                    'css_class' => 'dashicons dashicons-megaphone',
668
-                ),
669
-                'generate_now' => array(
670
-                    'label' => esc_html__('Generate the message now.', 'event_espresso'),
671
-                    'css_class' => 'dashicons dashicons-admin-tools',
672
-                ),
673
-                'send_now' => array(
674
-                    'label' => esc_html__('Send Immediately', 'event_espresso'),
675
-                    'css_class' => 'dashicons dashicons-controls-forward',
676
-                ),
677
-                'queue_for_resending' => array(
678
-                    'label' => esc_html__('Queue for Resending', 'event_espresso'),
679
-                    'css_class' => 'dashicons dashicons-controls-repeat',
680
-                ),
681
-                'view_transaction' => array(
682
-                    'label' => esc_html__('View related Transaction', 'event_espresso'),
683
-                    'css_class' => 'dashicons dashicons-cart',
684
-                )
685
-            )
686
-        );
687
-    }
688
-
689
-
690
-    /**
691
-     * This returns the url for a given action related to EE_Message.
692
-     *
693
-     * @param string     $type         What type of action to return the url for.
694
-     * @param EE_Message $message      Required for generating the correct url for some types.
695
-     * @param array      $query_params Any additional query params to be included with the generated url.
696
-     *
697
-     * @return string
698
-     * @throws EE_Error
699
-     * @throws ReflectionException
700
-     * @since 4.9.0
701
-     *
702
-     */
703
-    public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
704
-    {
705
-        $action_urls = self::get_message_action_urls($message, $query_params);
706
-        return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
707
-    }
708
-
709
-
710
-    /**
711
-     * This returns all the current urls for EE_Message actions.
712
-     *
713
-     * @since 4.9.0
714
-     *
715
-     * @param EE_Message $message      The EE_Message object required to generate correct urls for some types.
716
-     * @param array      $query_params Any additional query_params to be included with the generated url.
717
-     *
718
-     * @return array
719
-     * @throws EE_Error
720
-     * @throws ReflectionException
721
-     */
722
-    public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
723
-    {
724
-        EE_Registry::instance()->load_helper('URL');
725
-        // if $message is not an instance of EE_Message then let's just do a dummy.
726
-        $message = empty($message) ? EE_Message_Factory::create() : $message;
727
-        $action_urls =  apply_filters(
728
-            'FHEE__EEH_MSG_Template__get_message_action_url',
729
-            array(
730
-                'view' => EEH_MSG_Template::generate_browser_trigger($message),
731
-                'error' => EEH_MSG_Template::generate_error_display_trigger($message),
732
-                'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
733
-                    array_merge(
734
-                        array(
735
-                            'page' => 'espresso_messages',
736
-                            'action' => 'default',
737
-                            'filterby' => 1,
738
-                        ),
739
-                        $query_params
740
-                    ),
741
-                    admin_url('admin.php')
742
-                ),
743
-                'generate_now' => EEH_URL::add_query_args_and_nonce(
744
-                    array(
745
-                        'page' => 'espresso_messages',
746
-                        'action' => 'generate_now',
747
-                        'MSG_ID' => $message->ID()
748
-                    ),
749
-                    admin_url('admin.php')
750
-                ),
751
-                'send_now' => EEH_URL::add_query_args_and_nonce(
752
-                    array(
753
-                        'page' => 'espresso_messages',
754
-                        'action' => 'send_now',
755
-                        'MSG_ID' => $message->ID()
756
-                    ),
757
-                    admin_url('admin.php')
758
-                ),
759
-                'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
760
-                    array(
761
-                        'page' => 'espresso_messages',
762
-                        'action' => 'queue_for_resending',
763
-                        'MSG_ID' => $message->ID()
764
-                    ),
765
-                    admin_url('admin.php')
766
-                ),
767
-            )
768
-        );
769
-        if (
770
-            $message->TXN_ID() > 0
771
-            && EE_Registry::instance()->CAP->current_user_can(
772
-                'ee_read_transaction',
773
-                'espresso_transactions_default',
774
-                $message->TXN_ID()
775
-            )
776
-        ) {
777
-            $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
778
-                array(
779
-                    'page' => 'espresso_transactions',
780
-                    'action' => 'view_transaction',
781
-                    'TXN_ID' => $message->TXN_ID()
782
-                ),
783
-                admin_url('admin.php')
784
-            );
785
-        } else {
786
-            $action_urls['view_transaction'] = '';
787
-        }
788
-        return $action_urls;
789
-    }
790
-
791
-
792
-    /**
793
-     * This returns a generated link html including the icon used for the action link for EE_Message actions.
794
-     *
795
-     * @param string          $type         What type of action the link is for (if invalid type is passed in then an
796
-     *                                      empty string is returned)
797
-     * @param EE_Message|null $message      The EE_Message object (required for some actions to generate correctly)
798
-     * @param array           $query_params Any extra query params to include in the generated link.
799
-     *
800
-     * @return string
801
-     * @throws EE_Error
802
-     * @throws ReflectionException
803
-     * @since 4.9.0
804
-     *
805
-     */
806
-    public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
807
-    {
808
-        $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
809
-        $icon_css = EEH_MSG_Template::get_message_action_icon($type);
810
-        $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
811
-
812
-        if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
813
-            return '';
814
-        }
815
-
816
-        $icon_css['css_class'] .= esc_attr(
817
-            apply_filters(
818
-                'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
819
-                ' js-ee-message-action-link ee-message-action-link-' . $type,
820
-                $type,
821
-                $message,
822
-                $query_params
823
-            )
824
-        );
825
-
826
-        return '<a href="' . $url . '" ' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
827
-    }
828
-
829
-
830
-
831
-
832
-
833
-    /**
834
-     * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
835
-     *
836
-     * @since 4.9.0
837
-     * @return array
838
-     */
839
-    public static function reg_status_to_message_type_array()
840
-    {
841
-        return (array) apply_filters(
842
-            'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
843
-            array(
844
-                EEM_Registration::status_id_approved => 'registration',
845
-                EEM_Registration::status_id_pending_payment => 'pending_approval',
846
-                EEM_Registration::status_id_not_approved => 'not_approved_registration',
847
-                EEM_Registration::status_id_cancelled => 'cancelled_registration',
848
-                EEM_Registration::status_id_declined => 'declined_registration'
849
-            )
850
-        );
851
-    }
852
-
853
-
854
-
855
-
856
-    /**
857
-     * This returns the corresponding registration message type slug to the given reg status. If there isn't a
858
-     * match, then returns an empty string.
859
-     *
860
-     * @since 4.9.0
861
-     * @param $reg_status
862
-     * @return string
863
-     */
864
-    public static function convert_reg_status_to_message_type($reg_status)
865
-    {
866
-        $reg_status_array = self::reg_status_to_message_type_array();
867
-        return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
868
-    }
869
-
870
-
871
-    /**
872
-     * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
873
-     *
874
-     * @since 4.9.0
875
-     * @return array
876
-     */
877
-    public static function payment_status_to_message_type_array()
878
-    {
879
-        return (array) apply_filters(
880
-            'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
881
-            array(
882
-                EEM_Payment::status_id_approved => 'payment',
883
-                EEM_Payment::status_id_pending => 'payment_pending',
884
-                EEM_Payment::status_id_cancelled => 'payment_cancelled',
885
-                EEM_Payment::status_id_declined => 'payment_declined',
886
-                EEM_Payment::status_id_failed => 'payment_failed'
887
-            )
888
-        );
889
-    }
890
-
891
-
892
-
893
-
894
-    /**
895
-     * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
896
-     * an empty string is returned
897
-     *
898
-     * @since 4.9.0
899
-     * @param $payment_status
900
-     * @return string
901
-     */
902
-    public static function convert_payment_status_to_message_type($payment_status)
903
-    {
904
-        $payment_status_array = self::payment_status_to_message_type_array();
905
-        return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
906
-    }
907
-
908
-
909
-    /**
910
-     * This is used to retrieve the template pack for the given name.
911
-     *
912
-     * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
913
-     *
914
-     * @return EE_Messages_Template_Pack
915
-     */
916
-    public static function get_template_pack($template_pack_name)
917
-    {
918
-        if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
919
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
920
-        }
921
-
922
-        // first see if in collection already
923
-        $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
924
-
925
-        if ($template_pack instanceof EE_Messages_Template_Pack) {
926
-            return $template_pack;
927
-        }
928
-
929
-        // nope...let's get it.
930
-        // not set yet so let's attempt to get it.
931
-        $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
932
-            ' ',
933
-            '_',
934
-            ucwords(
935
-                str_replace('_', ' ', $template_pack_name)
936
-            )
937
-        );
938
-        if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
939
-            return self::get_template_pack('default');
940
-        } else {
941
-            $template_pack = new $pack_class_name();
942
-            self::$_template_pack_collection->add($template_pack);
943
-            return $template_pack;
944
-        }
945
-    }
946
-
947
-
948
-
949
-
950
-    /**
951
-     * Globs template packs installed in core and returns the template pack collection with all installed template packs
952
-     * in it.
953
-     *
954
-     * @since 4.9.0
955
-     *
956
-     * @return EE_Messages_Template_Pack_Collection
957
-     */
958
-    public static function get_template_pack_collection()
959
-    {
960
-        $new_collection = false;
961
-        if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
962
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
963
-            $new_collection = true;
964
-        }
965
-
966
-        // glob the defaults directory for messages
967
-        $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
968
-        foreach ($templates as $template_path) {
969
-            // grab folder name
970
-            $template = basename($template_path);
971
-
972
-            if (! $new_collection) {
973
-                // already have it?
974
-                if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
975
-                    continue;
976
-                }
977
-            }
978
-
979
-            // setup classname.
980
-            $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
981
-                ' ',
982
-                '_',
983
-                ucwords(
984
-                    str_replace(
985
-                        '_',
986
-                        ' ',
987
-                        $template
988
-                    )
989
-                )
990
-            );
991
-            if (! class_exists($template_pack_class_name)) {
992
-                continue;
993
-            }
994
-            self::$_template_pack_collection->add(new $template_pack_class_name());
995
-        }
996
-
997
-        /**
998
-         * Filter for plugins to add in any additional template packs
999
-         * Note the filter name here is for backward compat, this used to be found in EED_Messages.
1000
-         */
1001
-        $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
1002
-        foreach ((array) $additional_template_packs as $template_pack) {
1003
-            if (
1004
-                self::$_template_pack_collection->get_by_name(
1005
-                    $template_pack->dbref
1006
-                ) instanceof EE_Messages_Template_Pack
1007
-            ) {
1008
-                continue;
1009
-            }
1010
-            self::$_template_pack_collection->add($template_pack);
1011
-        }
1012
-        return self::$_template_pack_collection;
1013
-    }
1014
-
1015
-
1016
-    /**
1017
-     * This is a wrapper for the protected _create_new_templates function
1018
-     *
1019
-     * @param string $messenger_name
1020
-     * @param string $message_type_name message type that the templates are being created for
1021
-     * @param int    $GRP_ID
1022
-     * @param bool   $global
1023
-     * @return array
1024
-     * @throws EE_Error
1025
-     * @throws ReflectionException
1026
-     */
1027
-    public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1028
-    {
1029
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1030
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1031
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1032
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1033
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1034
-            return array();
1035
-        }
1036
-        // whew made it this far!  Okay, let's go ahead and create the templates then
1037
-        return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1038
-    }
1039
-
1040
-
1041
-    /**
1042
-     * @param EE_messenger     $messenger
1043
-     * @param EE_message_type  $message_type
1044
-     * @param                  $GRP_ID
1045
-     * @param                  $global
1046
-     * @return array|mixed
1047
-     * @throws EE_Error
1048
-     * @throws ReflectionException
1049
-     */
1050
-    protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1051
-    {
1052
-        // if we're creating a custom template then we don't need to use the defaults class
1053
-        if (! $global) {
1054
-            return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1055
-        }
1056
-        /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1057
-        $Message_Template_Defaults = EE_Registry::factory(
1058
-            'EE_Messages_Template_Defaults',
1059
-            array( $messenger, $message_type, $GRP_ID )
1060
-        );
1061
-        // generate templates
1062
-        $success = $Message_Template_Defaults->create_new_templates();
1063
-
1064
-        // if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1065
-        // its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1066
-        // attempts.
1067
-        if (! $success) {
1068
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
1069
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1070
-            $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1071
-        }
1072
-
1073
-        /**
1074
-         * $success is in an array in the following format
1075
-         * array(
1076
-         *    'GRP_ID' => $new_grp_id,
1077
-         *    'MTP_context' => $first_context_in_new_templates,
1078
-         * )
1079
-         */
1080
-        return $success;
1081
-    }
1082
-
1083
-
1084
-    /**
1085
-     * This creates a custom template using the incoming GRP_ID
1086
-     *
1087
-     * @param EE_messenger    $messenger
1088
-     * @param EE_message_type $message_type
1089
-     * @param int             $GRP_ID           GRP_ID for the template_group being used as the base
1090
-     * @return  array $success              This will be an array in the format:
1091
-     *                                          array(
1092
-     *                                          'GRP_ID' => $new_grp_id,
1093
-     *                                          'MTP_context' => $first_context_in_created_template
1094
-     *                                          )
1095
-     * @throws EE_Error
1096
-     * @throws ReflectionException
1097
-     * @access private
1098
-     */
1099
-    private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1100
-    {
1101
-        // defaults
1102
-        $success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1103
-        // get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1104
-        $Message_Template_Group = empty($GRP_ID)
1105
-            ? EEM_Message_Template_Group::instance()->get_one(
1106
-                array(
1107
-                    array(
1108
-                        'MTP_messenger'    => $messenger->name,
1109
-                        'MTP_message_type' => $message_type->name,
1110
-                        'MTP_is_global'    => true
1111
-                    )
1112
-                )
1113
-            )
1114
-            : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1115
-        // if we don't have a mtg at this point then we need to bail.
1116
-        if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1117
-            EE_Error::add_error(
1118
-                sprintf(
1119
-                    esc_html__(
1120
-                        'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1121
-                        'event_espresso'
1122
-                    ),
1123
-                    $GRP_ID
1124
-                ),
1125
-                __FILE__,
1126
-                __FUNCTION__,
1127
-                __LINE__
1128
-            );
1129
-            return $success;
1130
-        }
1131
-        // let's get all the related message_template objects for this group.
1132
-        $message_templates = $Message_Template_Group->message_templates();
1133
-        // now we have what we need to setup the new template
1134
-        $new_mtg = clone $Message_Template_Group;
1135
-        $new_mtg->set('GRP_ID', 0);
1136
-        $new_mtg->set('MTP_is_global', false);
1137
-
1138
-        /** @var RequestInterface $request */
1139
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1140
-        $template_name = $request->isAjax() && $request->requestParamIsSet('templateName')
1141
-            ? $request->getRequestParam('templateName')
1142
-            : esc_html__('New Custom Template', 'event_espresso');
1143
-        $template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription')
1144
-            ? $request->getRequestParam('templateDescription')
1145
-            : sprintf(
1146
-                esc_html__(
1147
-                    'This is a custom template that was created for the %s messenger and %s message type.',
1148
-                    'event_espresso'
1149
-                ),
1150
-                $new_mtg->messenger_obj()->label['singular'],
1151
-                $new_mtg->message_type_obj()->label['singular']
1152
-            );
1153
-        $new_mtg->set('MTP_name', $template_name);
1154
-        $new_mtg->set('MTP_description', $template_description);
1155
-        // remove ALL relations on this template group so they don't get saved!
1156
-        $new_mtg->_remove_relations('Message_Template');
1157
-        $new_mtg->save();
1158
-        $success['GRP_ID'] = $new_mtg->ID();
1159
-        $success['template_name'] = $template_name;
1160
-        // add new message templates and add relation to.
1161
-        foreach ($message_templates as $message_template) {
1162
-            if (! $message_template instanceof EE_Message_Template) {
1163
-                continue;
1164
-            }
1165
-            $new_message_template = clone $message_template;
1166
-            $new_message_template->set('MTP_ID', 0);
1167
-            $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1168
-            $new_message_template->save();
1169
-            if (empty($success['MTP_context'])) {
1170
-                $success['MTP_context'] = $new_message_template->get('MTP_context');
1171
-            }
1172
-        }
1173
-        return $success;
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * message_type_has_active_templates_for_messenger
1179
-     *
1180
-     * @param EE_messenger    $messenger
1181
-     * @param EE_message_type $message_type
1182
-     * @param bool            $global
1183
-     * @return bool
1184
-     * @throws EE_Error
1185
-     */
1186
-    public static function message_type_has_active_templates_for_messenger(
1187
-        EE_messenger $messenger,
1188
-        EE_message_type $message_type,
1189
-        $global = false
1190
-    ) {
1191
-        // is given message_type valid for given messenger (if this is not a global save)
1192
-        if ($global) {
1193
-            return true;
1194
-        }
1195
-        $active_templates = EEM_Message_Template_Group::instance()->count(
1196
-            array(
1197
-                array(
1198
-                    'MTP_is_active'    => true,
1199
-                    'MTP_messenger'    => $messenger->name,
1200
-                    'MTP_message_type' => $message_type->name
1201
-                )
1202
-            )
1203
-        );
1204
-        if ($active_templates > 0) {
1205
-            return true;
1206
-        }
1207
-        EE_Error::add_error(
1208
-            sprintf(
1209
-                esc_html__(
1210
-                    'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1211
-                    'event_espresso'
1212
-                ),
1213
-                $message_type->name,
1214
-                $messenger->name
1215
-            ),
1216
-            __FILE__,
1217
-            __FUNCTION__,
1218
-            __LINE__
1219
-        );
1220
-        return false;
1221
-    }
1222
-
1223
-
1224
-    /**
1225
-     * get_fields
1226
-     * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1227
-     *
1228
-     * @param string $messenger_name    name of EE_messenger
1229
-     * @param string $message_type_name name of EE_message_type
1230
-     * @return array
1231
-     * @throws EE_Error
1232
-     * @throws ReflectionException
1233
-     */
1234
-    public static function get_fields($messenger_name, $message_type_name)
1235
-    {
1236
-        $template_fields = array();
1237
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1238
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1239
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1240
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1241
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1242
-            return array();
1243
-        }
1244
-
1245
-        $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1246
-
1247
-        // okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1248
-        foreach ($message_type->get_contexts() as $context => $details) {
1249
-            foreach ($messenger->get_template_fields() as $field => $value) {
1250
-                if (in_array($field, $excluded_fields_for_messenger, true)) {
1251
-                    continue;
1252
-                }
1253
-                $template_fields[ $context ][ $field ] = $value;
1254
-            }
1255
-        }
1256
-        if (empty($template_fields)) {
1257
-            EE_Error::add_error(
1258
-                esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1259
-                __FILE__,
1260
-                __FUNCTION__,
1261
-                __LINE__
1262
-            );
1263
-            return array();
1264
-        }
1265
-        return $template_fields;
1266
-    }
18
+	/**
19
+	 * Holds a collection of EE_Message_Template_Pack objects.
20
+	 * @type EE_Messages_Template_Pack_Collection
21
+	 */
22
+	protected static $_template_pack_collection;
23
+
24
+
25
+	/**
26
+	 * @throws EE_Error
27
+	 */
28
+	private static function _set_autoloader()
29
+	{
30
+		EED_Messages::set_autoloaders();
31
+	}
32
+
33
+
34
+	/**
35
+	 * generate_new_templates
36
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
37
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
38
+	 * for the event.
39
+	 *
40
+	 * @access protected
41
+	 * @param string $messenger     the messenger we are generating templates for
42
+	 * @param array  $message_types array of message types that the templates are generated for.
43
+	 * @param int    $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID
44
+	 *                              to use as the base for the new generated template.
45
+	 * @param bool   $global        true indicates generating templates on messenger activation. false requires GRP_ID
46
+	 *                              for event specific template generation.
47
+	 * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array
48
+	 *                for templates that are generated.  If this is an empty array then it means no templates were
49
+	 *                generated which usually means there was an error.  Anything in the array with an empty value for
50
+	 *                `MTP_context` means that it was not a new generated template but just reactivated (which only
51
+	 *                happens for global templates that already exist in the database.
52
+	 * @throws EE_Error
53
+	 * @throws ReflectionException
54
+	 */
55
+	public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
56
+	{
57
+		// make sure message_type is an array.
58
+		$message_types = (array) $message_types;
59
+		$templates = array();
60
+
61
+		if (empty($messenger)) {
62
+			throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso'));
63
+		}
64
+
65
+		// if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
66
+		if (empty($message_types)) {
67
+			throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso'));
68
+		}
69
+
70
+		EEH_MSG_Template::_set_autoloader();
71
+		foreach ($message_types as $message_type) {
72
+			// if this is global template generation.
73
+			if ($global) {
74
+				// let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
75
+				if (empty($GRP_ID)) {
76
+					$GRP_ID = EEM_Message_Template_Group::instance()->get_one(
77
+						array(
78
+							array(
79
+								'MTP_messenger'    => $messenger,
80
+								'MTP_message_type' => $message_type,
81
+								'MTP_is_global'    => true,
82
+							),
83
+						)
84
+					);
85
+					$GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
86
+				}
87
+				// First let's determine if we already HAVE global templates for this messenger and message_type combination.
88
+				//  If we do then NO generation!!
89
+				if (EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
90
+					$templates[] = array(
91
+						'GRP_ID' => $GRP_ID,
92
+						'MTP_context' => '',
93
+					);
94
+					// we already have generated templates for this so let's go to the next message type.
95
+					continue;
96
+				}
97
+			}
98
+			$new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
99
+
100
+			if (! $new_message_template_group) {
101
+				continue;
102
+			}
103
+			$templates[] = $new_message_template_group;
104
+		}
105
+
106
+		return $templates;
107
+	}
108
+
109
+
110
+	/**
111
+	 * The purpose of this method is to determine if there are already generated templates in the database for the
112
+	 * given variables.
113
+	 *
114
+	 * @param string $messenger    messenger
115
+	 * @param string $message_type message type
116
+	 * @param int    $GRP_ID       GRP ID ( if a custom template) (if not provided then we're just doing global
117
+	 *                             template check)
118
+	 * @return bool                true = generated, false = hasn't been generated.
119
+	 * @throws EE_Error
120
+	 */
121
+	public static function already_generated($messenger, $message_type, $GRP_ID = 0)
122
+	{
123
+		EEH_MSG_Template::_set_autoloader();
124
+		// what method we use depends on whether we have an GRP_ID or not
125
+		$count = empty($GRP_ID)
126
+			? EEM_Message_Template::instance()->count(
127
+				array(
128
+					array(
129
+						'Message_Template_Group.MTP_messenger'    => $messenger,
130
+						'Message_Template_Group.MTP_message_type' => $message_type,
131
+						'Message_Template_Group.MTP_is_global'    => true
132
+					)
133
+				)
134
+			)
135
+			: EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
136
+
137
+		return $count > 0;
138
+	}
139
+
140
+
141
+	/**
142
+	 * Updates all message templates matching the incoming messengers and message types to active status.
143
+	 *
144
+	 * @static
145
+	 * @param array $messenger_names    Messenger slug
146
+	 * @param array $message_type_names Message type slug
147
+	 * @return  int                         count of updated records.
148
+	 * @throws EE_Error
149
+	 */
150
+	public static function update_to_active($messenger_names, $message_type_names)
151
+	{
152
+		$messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
153
+		$message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
154
+		return EEM_Message_Template_Group::instance()->update(
155
+			array( 'MTP_is_active' => 1 ),
156
+			array(
157
+				array(
158
+					'MTP_messenger'     => array( 'IN', $messenger_names ),
159
+					'MTP_message_type'  => array( 'IN', $message_type_names )
160
+				)
161
+			)
162
+		);
163
+	}
164
+
165
+
166
+	/**
167
+	 * Updates all message template groups matching the incoming arguments to inactive status.
168
+	 *
169
+	 * @static
170
+	 * @param array $messenger_names    The messenger slugs.
171
+	 *                                  If empty then all templates matching the message types are marked inactive.
172
+	 *                                  Otherwise only templates matching the messengers and message types.
173
+	 * @param array $message_type_names The message type slugs.
174
+	 *                                  If empty then all templates matching the messengers are marked inactive.
175
+	 *                                  Otherwise only templates matching the messengers and message types.
176
+	 *
177
+	 * @return int  count of updated records.
178
+	 * @throws EE_Error
179
+	 */
180
+	public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
181
+	{
182
+		return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
183
+			$messenger_names,
184
+			$message_type_names
185
+		);
186
+	}
187
+
188
+
189
+	/**
190
+	 * The purpose of this function is to return all installed message objects
191
+	 * (messengers and message type regardless of whether they are ACTIVE or not)
192
+	 *
193
+	 * @param string $type
194
+	 * @return array array consisting of installed messenger objects and installed message type objects.
195
+	 * @throws EE_Error
196
+	 * @throws ReflectionException
197
+	 * @deprecated 4.9.0
198
+	 * @static
199
+	 */
200
+	public static function get_installed_message_objects($type = 'all')
201
+	{
202
+		self::_set_autoloader();
203
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
204
+		return array(
205
+			'messenger' => $message_resource_manager->installed_messengers(),
206
+			'message_type' => $message_resource_manager->installed_message_types()
207
+		);
208
+	}
209
+
210
+
211
+	/**
212
+	 * This will return an array of shortcodes => labels from the
213
+	 * messenger and message_type objects associated with this
214
+	 * template.
215
+	 *
216
+	 * @param string $message_type
217
+	 * @param string $messenger
218
+	 * @param array  $fields                        What fields we're returning valid shortcodes for.
219
+	 *                                              If empty then we assume all fields are to be returned. Optional.
220
+	 * @param string $context                       What context we're going to return shortcodes for. Optional.
221
+	 * @param bool   $merged                        If TRUE then we don't return shortcodes indexed by field,
222
+	 *                                              but instead an array of the unique shortcodes for all the given (
223
+	 *                                              or all) fields. Optional.
224
+	 * @return array                                an array of shortcodes in the format
225
+	 *                                              array( '[shortcode] => 'label')
226
+	 *                                              OR
227
+	 *                                              FALSE if no shortcodes found.
228
+	 * @throws ReflectionException
229
+	 * @throws EE_Error*@since 4.3.0
230
+	 *
231
+	 */
232
+	public static function get_shortcodes(
233
+		$message_type,
234
+		$messenger,
235
+		$fields = array(),
236
+		$context = 'admin',
237
+		$merged = false
238
+	) {
239
+		$messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
240
+		$mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
241
+		/** @var EE_Message_Resource_Manager $message_resource_manager */
242
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
243
+		// convert slug to object
244
+		$messenger = $message_resource_manager->get_messenger($messenger);
245
+
246
+		// if messenger isn't a EE_messenger resource then bail.
247
+		if (! $messenger instanceof EE_messenger) {
248
+			return array();
249
+		}
250
+
251
+		// validate class for getting our list of shortcodes
252
+		$classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
253
+		if (! class_exists($classname)) {
254
+			$msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
255
+			$msg[] = sprintf(
256
+				esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
257
+				$classname
258
+			);
259
+			throw new EE_Error(implode('||', $msg));
260
+		}
261
+
262
+		/** @type EE_Messages_Validator $_VLD */
263
+		$_VLD = new $classname(array(), $context);
264
+		$valid_shortcodes = $_VLD->get_validators();
265
+
266
+		// let's make sure we're only getting the shortcode part of the validators
267
+		$shortcodes = array();
268
+		foreach ($valid_shortcodes as $field => $validators) {
269
+			$shortcodes[ $field ] = $validators['shortcodes'];
270
+		}
271
+		$valid_shortcodes = $shortcodes;
272
+
273
+		// if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
274
+		if (! empty($fields)) {
275
+			$specified_shortcodes = array();
276
+			foreach ($fields as $field) {
277
+				if (isset($valid_shortcodes[ $field ])) {
278
+					$specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
279
+				}
280
+			}
281
+			$valid_shortcodes = $specified_shortcodes;
282
+		}
283
+
284
+		// if not merged then let's replace the fields with the localized fields
285
+		if (! $merged) {
286
+			// let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
287
+			$field_settings = $messenger->get_template_fields();
288
+			$localized = array();
289
+			foreach ($valid_shortcodes as $field => $shortcodes) {
290
+				// get localized field label
291
+				if (isset($field_settings[ $field ])) {
292
+					// possible that this is used as a main field.
293
+					if (empty($field_settings[ $field ])) {
294
+						if (isset($field_settings['extra'][ $field ])) {
295
+							$_field = $field_settings['extra'][ $field ]['main']['label'];
296
+						} else {
297
+							$_field = $field;
298
+						}
299
+					} else {
300
+						$_field = $field_settings[ $field ]['label'];
301
+					}
302
+				} elseif (isset($field_settings['extra'])) {
303
+					// loop through extra "main fields" and see if any of their children have our field
304
+					foreach ($field_settings['extra'] as $fields) {
305
+						if (isset($fields[ $field ])) {
306
+							$_field = $fields[ $field ]['label'];
307
+						} else {
308
+							$_field = $field;
309
+						}
310
+					}
311
+				} else {
312
+					$_field = $field;
313
+				}
314
+				if (isset($_field)) {
315
+					$localized[ (string) $_field ] = $shortcodes;
316
+				}
317
+			}
318
+			$valid_shortcodes = $localized;
319
+		}
320
+
321
+		// if $merged then let's merge all the shortcodes into one list NOT indexed by field.
322
+		if ($merged) {
323
+			$merged_codes = array();
324
+			foreach ($valid_shortcodes as $shortcode) {
325
+				foreach ($shortcode as $code => $label) {
326
+					if (isset($merged_codes[ $code ])) {
327
+						continue;
328
+					} else {
329
+						$merged_codes[ $code ] = $label;
330
+					}
331
+				}
332
+			}
333
+			$valid_shortcodes = $merged_codes;
334
+		}
335
+
336
+		return $valid_shortcodes;
337
+	}
338
+
339
+
340
+	/**
341
+	 * Get Messenger object.
342
+	 *
343
+	 * @param string $messenger messenger slug for the messenger object we want to retrieve.
344
+	 * @return EE_messenger
345
+	 * @throws ReflectionException
346
+	 * @throws EE_Error*@since 4.3.0
347
+	 * @deprecated 4.9.0
348
+	 */
349
+	public static function messenger_obj($messenger)
350
+	{
351
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
352
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
353
+		return $Message_Resource_Manager->get_messenger($messenger);
354
+	}
355
+
356
+
357
+	/**
358
+	 * get Message type object
359
+	 *
360
+	 * @param string $message_type the slug for the message type object to retrieve
361
+	 * @return EE_message_type
362
+	 * @throws ReflectionException
363
+	 * @throws EE_Error*@since 4.3.0
364
+	 * @deprecated 4.9.0
365
+	 */
366
+	public static function message_type_obj($message_type)
367
+	{
368
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
369
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
370
+		return $Message_Resource_Manager->get_message_type($message_type);
371
+	}
372
+
373
+
374
+	/**
375
+	 * Given a message_type slug, will return whether that message type is active in the system or not.
376
+	 *
377
+	 * @since    4.3.0
378
+	 * @param string $message_type message type to check for.
379
+	 * @return boolean
380
+	 * @throws EE_Error
381
+	 * @throws ReflectionException
382
+	 */
383
+	public static function is_mt_active($message_type)
384
+	{
385
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
386
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
387
+		$active_mts = $Message_Resource_Manager->list_of_active_message_types();
388
+		return in_array($message_type, $active_mts);
389
+	}
390
+
391
+
392
+	/**
393
+	 * Given a messenger slug, will return whether that messenger is active in the system or not.
394
+	 *
395
+	 * @since    4.3.0
396
+	 *
397
+	 * @param string $messenger slug for messenger to check.
398
+	 * @return boolean
399
+	 * @throws EE_Error
400
+	 * @throws ReflectionException
401
+	 */
402
+	public static function is_messenger_active($messenger)
403
+	{
404
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
405
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
406
+		$active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
407
+		return $active_messenger instanceof EE_messenger;
408
+	}
409
+
410
+
411
+	/**
412
+	 * Used to return active messengers array stored in the wp options table.
413
+	 * If no value is present in the option then an empty array is returned.
414
+	 *
415
+	 * @deprecated 4.9
416
+	 * @since      4.3.1
417
+	 *
418
+	 * @return array
419
+	 * @throws EE_Error
420
+	 * @throws ReflectionException
421
+	 */
422
+	public static function get_active_messengers_in_db()
423
+	{
424
+		EE_Error::doing_it_wrong(
425
+			__METHOD__,
426
+			esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
427
+			'4.9.0'
428
+		);
429
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
430
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
431
+		return $Message_Resource_Manager->get_active_messengers_option();
432
+	}
433
+
434
+
435
+	/**
436
+	 * Used to update the active messengers array stored in the wp options table.
437
+	 *
438
+	 * @since      4.3.1
439
+	 * @deprecated 4.9.0
440
+	 *
441
+	 * @param array $data_to_save Incoming data to save.
442
+	 *
443
+	 * @return bool FALSE if not updated, TRUE if updated.
444
+	 * @throws EE_Error
445
+	 * @throws ReflectionException
446
+	 */
447
+	public static function update_active_messengers_in_db($data_to_save)
448
+	{
449
+		EE_Error::doing_it_wrong(
450
+			__METHOD__,
451
+			esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
452
+			'4.9.0'
453
+		);
454
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
455
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
456
+		return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
457
+	}
458
+
459
+
460
+	/**
461
+	 * This does some validation of incoming params, determines what type of url is being prepped and returns the
462
+	 * appropriate url trigger
463
+	 *
464
+	 * @param EE_message_type $message_type
465
+	 * @param EE_Message $message
466
+	 * @param EE_Registration | null $registration  The registration object must be included if this
467
+	 *                                              is going to be a registration trigger url.
468
+	 * @param string $sending_messenger             The (optional) sending messenger for the url.
469
+	 *
470
+	 * @return string
471
+	 * @throws EE_Error
472
+	 */
473
+	public static function get_url_trigger(
474
+		EE_message_type $message_type,
475
+		EE_Message $message,
476
+		$registration = null,
477
+		$sending_messenger = ''
478
+	) {
479
+		// first determine if the url can be to the EE_Message object.
480
+		if (! $message_type->always_generate()) {
481
+			return EEH_MSG_Template::generate_browser_trigger($message);
482
+		}
483
+
484
+		// if $registration object is not valid then exit early because there's nothing that can be generated.
485
+		if (! $registration instanceof EE_Registration) {
486
+			throw new EE_Error(
487
+				esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
488
+			);
489
+		}
490
+
491
+		// validate given context
492
+		$contexts = $message_type->get_contexts();
493
+		if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
494
+			throw new EE_Error(
495
+				sprintf(
496
+					esc_html__('The context %s is not a valid context for %s.', 'event_espresso'),
497
+					$message->context(),
498
+					get_class($message_type)
499
+				)
500
+			);
501
+		}
502
+
503
+		// valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
504
+		if (! empty($sending_messenger)) {
505
+			$with_messengers = $message_type->with_messengers();
506
+			if (
507
+				! isset($with_messengers[ $message->messenger() ])
508
+				 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
509
+			) {
510
+				throw new EE_Error(
511
+					sprintf(
512
+						esc_html__(
513
+							'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
514
+							'event_espresso'
515
+						),
516
+						$sending_messenger,
517
+						get_class($message_type)
518
+					)
519
+				);
520
+			}
521
+		} else {
522
+			$sending_messenger = $message->messenger();
523
+		}
524
+		return EEH_MSG_Template::generate_url_trigger(
525
+			$sending_messenger,
526
+			$message->messenger(),
527
+			$message->context(),
528
+			$message->message_type(),
529
+			$registration,
530
+			$message->GRP_ID()
531
+		);
532
+	}
533
+
534
+
535
+	/**
536
+	 * This returns the url for triggering a in browser view of a specific EE_Message object.
537
+	 * @param EE_Message $message
538
+	 * @return string.
539
+	 */
540
+	public static function generate_browser_trigger(EE_Message $message)
541
+	{
542
+		$query_args = array(
543
+			'ee' => 'msg_browser_trigger',
544
+			'token' => $message->MSG_token()
545
+		);
546
+		return apply_filters(
547
+			'FHEE__EEH_MSG_Template__generate_browser_trigger',
548
+			add_query_arg($query_args, site_url()),
549
+			$message
550
+		);
551
+	}
552
+
553
+
554
+
555
+
556
+
557
+
558
+	/**
559
+	 * This returns the url for triggering an in browser view of the error saved on the incoming message object.
560
+	 * @param EE_Message $message
561
+	 * @return string
562
+	 */
563
+	public static function generate_error_display_trigger(EE_Message $message)
564
+	{
565
+		return apply_filters(
566
+			'FHEE__EEH_MSG_Template__generate_error_display_trigger',
567
+			add_query_arg(
568
+				array(
569
+					'ee' => 'msg_browser_error_trigger',
570
+					'token' => $message->MSG_token()
571
+				),
572
+				site_url()
573
+			),
574
+			$message
575
+		);
576
+	}
577
+
578
+
579
+	/**
580
+	 * This generates a url trigger for the msg_url_trigger route using the given arguments
581
+	 *
582
+	 * @param string          $sending_messenger      The sending messenger slug.
583
+	 * @param string          $generating_messenger   The generating messenger slug.
584
+	 * @param string          $context                The context for the template.
585
+	 * @param string          $message_type           The message type slug
586
+	 * @param EE_Registration $registration
587
+	 * @param integer         $message_template_group id   The EE_Message_Template_Group ID for the template.
588
+	 * @param integer         $data_id                The id to the EE_Base_Class for getting the data used by the
589
+	 *                                                trigger.
590
+	 * @return string          The generated url.
591
+	 * @throws EE_Error
592
+	 */
593
+	public static function generate_url_trigger(
594
+		$sending_messenger,
595
+		$generating_messenger,
596
+		$context,
597
+		$message_type,
598
+		EE_Registration $registration,
599
+		$message_template_group,
600
+		$data_id = 0
601
+	) {
602
+		$query_args = array(
603
+			'ee' => 'msg_url_trigger',
604
+			'snd_msgr' => $sending_messenger,
605
+			'gen_msgr' => $generating_messenger,
606
+			'message_type' => $message_type,
607
+			'context' => $context,
608
+			'token' => $registration->reg_url_link(),
609
+			'GRP_ID' => $message_template_group,
610
+			'id' => $data_id
611
+			);
612
+		$url = add_query_arg($query_args, get_home_url());
613
+
614
+		// made it here so now we can just get the url and filter it.  Filtered globally and by message type.
615
+		return apply_filters(
616
+			'FHEE__EEH_MSG_Template__generate_url_trigger',
617
+			$url,
618
+			$sending_messenger,
619
+			$generating_messenger,
620
+			$context,
621
+			$message_type,
622
+			$registration,
623
+			$message_template_group,
624
+			$data_id
625
+		);
626
+	}
627
+
628
+
629
+
630
+
631
+	/**
632
+	 * Return the specific css for the action icon given.
633
+	 *
634
+	 * @param string $type  What action to return.
635
+	 * @return string[]
636
+	 * @since 4.9.0
637
+	 */
638
+	public static function get_message_action_icon($type)
639
+	{
640
+		$action_icons = self::get_message_action_icons();
641
+		return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];
642
+	}
643
+
644
+
645
+	/**
646
+	 * This is used for retrieving the css classes used for the icons representing message actions.
647
+	 *
648
+	 * @since 4.9.0
649
+	 *
650
+	 * @return array
651
+	 */
652
+	public static function get_message_action_icons()
653
+	{
654
+		return apply_filters(
655
+			'FHEE__EEH_MSG_Template__message_action_icons',
656
+			array(
657
+				'view' => array(
658
+					'label' => esc_html__('View Message', 'event_espresso'),
659
+					'css_class' => 'dashicons dashicons-welcome-view-site',
660
+				),
661
+				'error' => array(
662
+					'label' => esc_html__('View Error Message', 'event_espresso'),
663
+					'css_class' => 'dashicons dashicons-info',
664
+				),
665
+				'see_notifications_for' => array(
666
+					'label' => esc_html__('View Related Messages', 'event_espresso'),
667
+					'css_class' => 'dashicons dashicons-megaphone',
668
+				),
669
+				'generate_now' => array(
670
+					'label' => esc_html__('Generate the message now.', 'event_espresso'),
671
+					'css_class' => 'dashicons dashicons-admin-tools',
672
+				),
673
+				'send_now' => array(
674
+					'label' => esc_html__('Send Immediately', 'event_espresso'),
675
+					'css_class' => 'dashicons dashicons-controls-forward',
676
+				),
677
+				'queue_for_resending' => array(
678
+					'label' => esc_html__('Queue for Resending', 'event_espresso'),
679
+					'css_class' => 'dashicons dashicons-controls-repeat',
680
+				),
681
+				'view_transaction' => array(
682
+					'label' => esc_html__('View related Transaction', 'event_espresso'),
683
+					'css_class' => 'dashicons dashicons-cart',
684
+				)
685
+			)
686
+		);
687
+	}
688
+
689
+
690
+	/**
691
+	 * This returns the url for a given action related to EE_Message.
692
+	 *
693
+	 * @param string     $type         What type of action to return the url for.
694
+	 * @param EE_Message $message      Required for generating the correct url for some types.
695
+	 * @param array      $query_params Any additional query params to be included with the generated url.
696
+	 *
697
+	 * @return string
698
+	 * @throws EE_Error
699
+	 * @throws ReflectionException
700
+	 * @since 4.9.0
701
+	 *
702
+	 */
703
+	public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
704
+	{
705
+		$action_urls = self::get_message_action_urls($message, $query_params);
706
+		return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
707
+	}
708
+
709
+
710
+	/**
711
+	 * This returns all the current urls for EE_Message actions.
712
+	 *
713
+	 * @since 4.9.0
714
+	 *
715
+	 * @param EE_Message $message      The EE_Message object required to generate correct urls for some types.
716
+	 * @param array      $query_params Any additional query_params to be included with the generated url.
717
+	 *
718
+	 * @return array
719
+	 * @throws EE_Error
720
+	 * @throws ReflectionException
721
+	 */
722
+	public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
723
+	{
724
+		EE_Registry::instance()->load_helper('URL');
725
+		// if $message is not an instance of EE_Message then let's just do a dummy.
726
+		$message = empty($message) ? EE_Message_Factory::create() : $message;
727
+		$action_urls =  apply_filters(
728
+			'FHEE__EEH_MSG_Template__get_message_action_url',
729
+			array(
730
+				'view' => EEH_MSG_Template::generate_browser_trigger($message),
731
+				'error' => EEH_MSG_Template::generate_error_display_trigger($message),
732
+				'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
733
+					array_merge(
734
+						array(
735
+							'page' => 'espresso_messages',
736
+							'action' => 'default',
737
+							'filterby' => 1,
738
+						),
739
+						$query_params
740
+					),
741
+					admin_url('admin.php')
742
+				),
743
+				'generate_now' => EEH_URL::add_query_args_and_nonce(
744
+					array(
745
+						'page' => 'espresso_messages',
746
+						'action' => 'generate_now',
747
+						'MSG_ID' => $message->ID()
748
+					),
749
+					admin_url('admin.php')
750
+				),
751
+				'send_now' => EEH_URL::add_query_args_and_nonce(
752
+					array(
753
+						'page' => 'espresso_messages',
754
+						'action' => 'send_now',
755
+						'MSG_ID' => $message->ID()
756
+					),
757
+					admin_url('admin.php')
758
+				),
759
+				'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
760
+					array(
761
+						'page' => 'espresso_messages',
762
+						'action' => 'queue_for_resending',
763
+						'MSG_ID' => $message->ID()
764
+					),
765
+					admin_url('admin.php')
766
+				),
767
+			)
768
+		);
769
+		if (
770
+			$message->TXN_ID() > 0
771
+			&& EE_Registry::instance()->CAP->current_user_can(
772
+				'ee_read_transaction',
773
+				'espresso_transactions_default',
774
+				$message->TXN_ID()
775
+			)
776
+		) {
777
+			$action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
778
+				array(
779
+					'page' => 'espresso_transactions',
780
+					'action' => 'view_transaction',
781
+					'TXN_ID' => $message->TXN_ID()
782
+				),
783
+				admin_url('admin.php')
784
+			);
785
+		} else {
786
+			$action_urls['view_transaction'] = '';
787
+		}
788
+		return $action_urls;
789
+	}
790
+
791
+
792
+	/**
793
+	 * This returns a generated link html including the icon used for the action link for EE_Message actions.
794
+	 *
795
+	 * @param string          $type         What type of action the link is for (if invalid type is passed in then an
796
+	 *                                      empty string is returned)
797
+	 * @param EE_Message|null $message      The EE_Message object (required for some actions to generate correctly)
798
+	 * @param array           $query_params Any extra query params to include in the generated link.
799
+	 *
800
+	 * @return string
801
+	 * @throws EE_Error
802
+	 * @throws ReflectionException
803
+	 * @since 4.9.0
804
+	 *
805
+	 */
806
+	public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
807
+	{
808
+		$url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
809
+		$icon_css = EEH_MSG_Template::get_message_action_icon($type);
810
+		$title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
811
+
812
+		if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
813
+			return '';
814
+		}
815
+
816
+		$icon_css['css_class'] .= esc_attr(
817
+			apply_filters(
818
+				'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
819
+				' js-ee-message-action-link ee-message-action-link-' . $type,
820
+				$type,
821
+				$message,
822
+				$query_params
823
+			)
824
+		);
825
+
826
+		return '<a href="' . $url . '" ' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
827
+	}
828
+
829
+
830
+
831
+
832
+
833
+	/**
834
+	 * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
835
+	 *
836
+	 * @since 4.9.0
837
+	 * @return array
838
+	 */
839
+	public static function reg_status_to_message_type_array()
840
+	{
841
+		return (array) apply_filters(
842
+			'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
843
+			array(
844
+				EEM_Registration::status_id_approved => 'registration',
845
+				EEM_Registration::status_id_pending_payment => 'pending_approval',
846
+				EEM_Registration::status_id_not_approved => 'not_approved_registration',
847
+				EEM_Registration::status_id_cancelled => 'cancelled_registration',
848
+				EEM_Registration::status_id_declined => 'declined_registration'
849
+			)
850
+		);
851
+	}
852
+
853
+
854
+
855
+
856
+	/**
857
+	 * This returns the corresponding registration message type slug to the given reg status. If there isn't a
858
+	 * match, then returns an empty string.
859
+	 *
860
+	 * @since 4.9.0
861
+	 * @param $reg_status
862
+	 * @return string
863
+	 */
864
+	public static function convert_reg_status_to_message_type($reg_status)
865
+	{
866
+		$reg_status_array = self::reg_status_to_message_type_array();
867
+		return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
868
+	}
869
+
870
+
871
+	/**
872
+	 * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
873
+	 *
874
+	 * @since 4.9.0
875
+	 * @return array
876
+	 */
877
+	public static function payment_status_to_message_type_array()
878
+	{
879
+		return (array) apply_filters(
880
+			'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
881
+			array(
882
+				EEM_Payment::status_id_approved => 'payment',
883
+				EEM_Payment::status_id_pending => 'payment_pending',
884
+				EEM_Payment::status_id_cancelled => 'payment_cancelled',
885
+				EEM_Payment::status_id_declined => 'payment_declined',
886
+				EEM_Payment::status_id_failed => 'payment_failed'
887
+			)
888
+		);
889
+	}
890
+
891
+
892
+
893
+
894
+	/**
895
+	 * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
896
+	 * an empty string is returned
897
+	 *
898
+	 * @since 4.9.0
899
+	 * @param $payment_status
900
+	 * @return string
901
+	 */
902
+	public static function convert_payment_status_to_message_type($payment_status)
903
+	{
904
+		$payment_status_array = self::payment_status_to_message_type_array();
905
+		return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
906
+	}
907
+
908
+
909
+	/**
910
+	 * This is used to retrieve the template pack for the given name.
911
+	 *
912
+	 * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
913
+	 *
914
+	 * @return EE_Messages_Template_Pack
915
+	 */
916
+	public static function get_template_pack($template_pack_name)
917
+	{
918
+		if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
919
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
920
+		}
921
+
922
+		// first see if in collection already
923
+		$template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
924
+
925
+		if ($template_pack instanceof EE_Messages_Template_Pack) {
926
+			return $template_pack;
927
+		}
928
+
929
+		// nope...let's get it.
930
+		// not set yet so let's attempt to get it.
931
+		$pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
932
+			' ',
933
+			'_',
934
+			ucwords(
935
+				str_replace('_', ' ', $template_pack_name)
936
+			)
937
+		);
938
+		if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
939
+			return self::get_template_pack('default');
940
+		} else {
941
+			$template_pack = new $pack_class_name();
942
+			self::$_template_pack_collection->add($template_pack);
943
+			return $template_pack;
944
+		}
945
+	}
946
+
947
+
948
+
949
+
950
+	/**
951
+	 * Globs template packs installed in core and returns the template pack collection with all installed template packs
952
+	 * in it.
953
+	 *
954
+	 * @since 4.9.0
955
+	 *
956
+	 * @return EE_Messages_Template_Pack_Collection
957
+	 */
958
+	public static function get_template_pack_collection()
959
+	{
960
+		$new_collection = false;
961
+		if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
962
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
963
+			$new_collection = true;
964
+		}
965
+
966
+		// glob the defaults directory for messages
967
+		$templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
968
+		foreach ($templates as $template_path) {
969
+			// grab folder name
970
+			$template = basename($template_path);
971
+
972
+			if (! $new_collection) {
973
+				// already have it?
974
+				if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
975
+					continue;
976
+				}
977
+			}
978
+
979
+			// setup classname.
980
+			$template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
981
+				' ',
982
+				'_',
983
+				ucwords(
984
+					str_replace(
985
+						'_',
986
+						' ',
987
+						$template
988
+					)
989
+				)
990
+			);
991
+			if (! class_exists($template_pack_class_name)) {
992
+				continue;
993
+			}
994
+			self::$_template_pack_collection->add(new $template_pack_class_name());
995
+		}
996
+
997
+		/**
998
+		 * Filter for plugins to add in any additional template packs
999
+		 * Note the filter name here is for backward compat, this used to be found in EED_Messages.
1000
+		 */
1001
+		$additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
1002
+		foreach ((array) $additional_template_packs as $template_pack) {
1003
+			if (
1004
+				self::$_template_pack_collection->get_by_name(
1005
+					$template_pack->dbref
1006
+				) instanceof EE_Messages_Template_Pack
1007
+			) {
1008
+				continue;
1009
+			}
1010
+			self::$_template_pack_collection->add($template_pack);
1011
+		}
1012
+		return self::$_template_pack_collection;
1013
+	}
1014
+
1015
+
1016
+	/**
1017
+	 * This is a wrapper for the protected _create_new_templates function
1018
+	 *
1019
+	 * @param string $messenger_name
1020
+	 * @param string $message_type_name message type that the templates are being created for
1021
+	 * @param int    $GRP_ID
1022
+	 * @param bool   $global
1023
+	 * @return array
1024
+	 * @throws EE_Error
1025
+	 * @throws ReflectionException
1026
+	 */
1027
+	public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1028
+	{
1029
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1030
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1031
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1032
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1033
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1034
+			return array();
1035
+		}
1036
+		// whew made it this far!  Okay, let's go ahead and create the templates then
1037
+		return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1038
+	}
1039
+
1040
+
1041
+	/**
1042
+	 * @param EE_messenger     $messenger
1043
+	 * @param EE_message_type  $message_type
1044
+	 * @param                  $GRP_ID
1045
+	 * @param                  $global
1046
+	 * @return array|mixed
1047
+	 * @throws EE_Error
1048
+	 * @throws ReflectionException
1049
+	 */
1050
+	protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1051
+	{
1052
+		// if we're creating a custom template then we don't need to use the defaults class
1053
+		if (! $global) {
1054
+			return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1055
+		}
1056
+		/** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1057
+		$Message_Template_Defaults = EE_Registry::factory(
1058
+			'EE_Messages_Template_Defaults',
1059
+			array( $messenger, $message_type, $GRP_ID )
1060
+		);
1061
+		// generate templates
1062
+		$success = $Message_Template_Defaults->create_new_templates();
1063
+
1064
+		// if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1065
+		// its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1066
+		// attempts.
1067
+		if (! $success) {
1068
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
1069
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1070
+			$message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1071
+		}
1072
+
1073
+		/**
1074
+		 * $success is in an array in the following format
1075
+		 * array(
1076
+		 *    'GRP_ID' => $new_grp_id,
1077
+		 *    'MTP_context' => $first_context_in_new_templates,
1078
+		 * )
1079
+		 */
1080
+		return $success;
1081
+	}
1082
+
1083
+
1084
+	/**
1085
+	 * This creates a custom template using the incoming GRP_ID
1086
+	 *
1087
+	 * @param EE_messenger    $messenger
1088
+	 * @param EE_message_type $message_type
1089
+	 * @param int             $GRP_ID           GRP_ID for the template_group being used as the base
1090
+	 * @return  array $success              This will be an array in the format:
1091
+	 *                                          array(
1092
+	 *                                          'GRP_ID' => $new_grp_id,
1093
+	 *                                          'MTP_context' => $first_context_in_created_template
1094
+	 *                                          )
1095
+	 * @throws EE_Error
1096
+	 * @throws ReflectionException
1097
+	 * @access private
1098
+	 */
1099
+	private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1100
+	{
1101
+		// defaults
1102
+		$success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1103
+		// get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1104
+		$Message_Template_Group = empty($GRP_ID)
1105
+			? EEM_Message_Template_Group::instance()->get_one(
1106
+				array(
1107
+					array(
1108
+						'MTP_messenger'    => $messenger->name,
1109
+						'MTP_message_type' => $message_type->name,
1110
+						'MTP_is_global'    => true
1111
+					)
1112
+				)
1113
+			)
1114
+			: EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1115
+		// if we don't have a mtg at this point then we need to bail.
1116
+		if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1117
+			EE_Error::add_error(
1118
+				sprintf(
1119
+					esc_html__(
1120
+						'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1121
+						'event_espresso'
1122
+					),
1123
+					$GRP_ID
1124
+				),
1125
+				__FILE__,
1126
+				__FUNCTION__,
1127
+				__LINE__
1128
+			);
1129
+			return $success;
1130
+		}
1131
+		// let's get all the related message_template objects for this group.
1132
+		$message_templates = $Message_Template_Group->message_templates();
1133
+		// now we have what we need to setup the new template
1134
+		$new_mtg = clone $Message_Template_Group;
1135
+		$new_mtg->set('GRP_ID', 0);
1136
+		$new_mtg->set('MTP_is_global', false);
1137
+
1138
+		/** @var RequestInterface $request */
1139
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1140
+		$template_name = $request->isAjax() && $request->requestParamIsSet('templateName')
1141
+			? $request->getRequestParam('templateName')
1142
+			: esc_html__('New Custom Template', 'event_espresso');
1143
+		$template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription')
1144
+			? $request->getRequestParam('templateDescription')
1145
+			: sprintf(
1146
+				esc_html__(
1147
+					'This is a custom template that was created for the %s messenger and %s message type.',
1148
+					'event_espresso'
1149
+				),
1150
+				$new_mtg->messenger_obj()->label['singular'],
1151
+				$new_mtg->message_type_obj()->label['singular']
1152
+			);
1153
+		$new_mtg->set('MTP_name', $template_name);
1154
+		$new_mtg->set('MTP_description', $template_description);
1155
+		// remove ALL relations on this template group so they don't get saved!
1156
+		$new_mtg->_remove_relations('Message_Template');
1157
+		$new_mtg->save();
1158
+		$success['GRP_ID'] = $new_mtg->ID();
1159
+		$success['template_name'] = $template_name;
1160
+		// add new message templates and add relation to.
1161
+		foreach ($message_templates as $message_template) {
1162
+			if (! $message_template instanceof EE_Message_Template) {
1163
+				continue;
1164
+			}
1165
+			$new_message_template = clone $message_template;
1166
+			$new_message_template->set('MTP_ID', 0);
1167
+			$new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1168
+			$new_message_template->save();
1169
+			if (empty($success['MTP_context'])) {
1170
+				$success['MTP_context'] = $new_message_template->get('MTP_context');
1171
+			}
1172
+		}
1173
+		return $success;
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * message_type_has_active_templates_for_messenger
1179
+	 *
1180
+	 * @param EE_messenger    $messenger
1181
+	 * @param EE_message_type $message_type
1182
+	 * @param bool            $global
1183
+	 * @return bool
1184
+	 * @throws EE_Error
1185
+	 */
1186
+	public static function message_type_has_active_templates_for_messenger(
1187
+		EE_messenger $messenger,
1188
+		EE_message_type $message_type,
1189
+		$global = false
1190
+	) {
1191
+		// is given message_type valid for given messenger (if this is not a global save)
1192
+		if ($global) {
1193
+			return true;
1194
+		}
1195
+		$active_templates = EEM_Message_Template_Group::instance()->count(
1196
+			array(
1197
+				array(
1198
+					'MTP_is_active'    => true,
1199
+					'MTP_messenger'    => $messenger->name,
1200
+					'MTP_message_type' => $message_type->name
1201
+				)
1202
+			)
1203
+		);
1204
+		if ($active_templates > 0) {
1205
+			return true;
1206
+		}
1207
+		EE_Error::add_error(
1208
+			sprintf(
1209
+				esc_html__(
1210
+					'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1211
+					'event_espresso'
1212
+				),
1213
+				$message_type->name,
1214
+				$messenger->name
1215
+			),
1216
+			__FILE__,
1217
+			__FUNCTION__,
1218
+			__LINE__
1219
+		);
1220
+		return false;
1221
+	}
1222
+
1223
+
1224
+	/**
1225
+	 * get_fields
1226
+	 * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1227
+	 *
1228
+	 * @param string $messenger_name    name of EE_messenger
1229
+	 * @param string $message_type_name name of EE_message_type
1230
+	 * @return array
1231
+	 * @throws EE_Error
1232
+	 * @throws ReflectionException
1233
+	 */
1234
+	public static function get_fields($messenger_name, $message_type_name)
1235
+	{
1236
+		$template_fields = array();
1237
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1238
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1239
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1240
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1241
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1242
+			return array();
1243
+		}
1244
+
1245
+		$excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1246
+
1247
+		// okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1248
+		foreach ($message_type->get_contexts() as $context => $details) {
1249
+			foreach ($messenger->get_template_fields() as $field => $value) {
1250
+				if (in_array($field, $excluded_fields_for_messenger, true)) {
1251
+					continue;
1252
+				}
1253
+				$template_fields[ $context ][ $field ] = $value;
1254
+			}
1255
+		}
1256
+		if (empty($template_fields)) {
1257
+			EE_Error::add_error(
1258
+				esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1259
+				__FILE__,
1260
+				__FUNCTION__,
1261
+				__LINE__
1262
+			);
1263
+			return array();
1264
+		}
1265
+		return $template_fields;
1266
+	}
1267 1267
 }
Please login to merge, or discard this patch.
admin_pages/messages/templates/shortcode_selector_skeleton.template.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -28,14 +28,14 @@
 block discarded – undo
28 28
         </h6>
29 29
         <h4>
30 30
             <?php
31
-            printf(
32
-                esc_html__('"%1$s" field', 'event_espresso'),
33
-                esc_attr($fieldname)
34
-            ); ?>
31
+			printf(
32
+				esc_html__('"%1$s" field', 'event_espresso'),
33
+				esc_attr($fieldname)
34
+			); ?>
35 35
         </h4>
36 36
         <ul>
37 37
         <?php
38
-        foreach (array_keys($shortcodes) as $shortcode) : ?>
38
+		foreach (array_keys($shortcodes) as $shortcode) : ?>
39 39
             <li>
40 40
                 <span class="js-shortcode-selection"
41 41
                       data-linked-input-id="<?php echo esc_attr($linked_input_id); ?>"
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
  * @type    string $linked_input_id The name of the input that the shortcode gets inserted to.
11 11
  */
12 12
 
13
-if (! empty($shortcodes)) : ?>
13
+if ( ! empty($shortcodes)) : ?>
14 14
 <div class="ee-messages-shortcodes-chooser-wrap">
15 15
     <button class="ee-messages-shortcodes-chooser js-open-list-trigger button button-secondary"
16 16
             aria-label="<?php echo esc_html__('open shortcode selector', 'event_espresso'); ?>"
Please login to merge, or discard this patch.