Completed
Branch FET/9575/invisible-recaptcha (a1de93)
by
unknown
80:39 queued 68:16
created
acceptance_tests/Helpers/EventsAdmin.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -14,133 +14,133 @@
 block discarded – undo
14 14
 trait EventsAdmin
15 15
 {
16 16
 
17
-    /**
18
-     * @param string $additional_params
19
-     */
20
-    public function amOnDefaultEventsListTablePage($additional_params = '')
21
-    {
22
-        $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params));
23
-    }
24
-
25
-
26
-    /**
27
-     * Triggers the publishing of the Event.
28
-     */
29
-    public function publishEvent()
30
-    {
31
-        $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR);
32
-        $this->actor()->wait(3);
33
-        $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR);
34
-        $this->actor()->waitForText('Event published.', 30);
35
-    }
36
-
37
-
38
-    /**
39
-     * Triggers saving the Event.
40
-     */
41
-    public function saveEvent()
42
-    {
43
-        $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR);
44
-        $this->actor()->wait(2);
45
-        $this->actor()->click(EventsPage::EVENT_EDITOR_SAVE_BUTTON_SELECTOR);
46
-    }
47
-
48
-
49
-    /**
50
-     * Navigates the actor to the event list table page and will attempt to edit the event for the given title.
51
-     * First this will search using the given title and then attempt to edit from the results of the search.
52
-     *
53
-     * Assumes actor is already logged in.
54
-     * @param $event_title
55
-     */
56
-    public function amEditingTheEventWithTitle($event_title)
57
-    {
58
-        $this->amOnDefaultEventsListTablePage();
59
-        $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title);
60
-        $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR);
61
-        $this->actor()->waitForText($event_title, 15);
62
-        $this->actor()->click(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title));
63
-    }
64
-
65
-
66
-    /**
67
-     * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View"
68
-     * link for the event in the event list table.
69
-     * Assumes the actor is already logged in and on the Event list table page.
70
-     *
71
-     * @param string $event_title
72
-     */
73
-    public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title)
74
-    {
75
-        $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title));
76
-        $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title));
77
-    }
78
-
79
-
80
-    /**
81
-     * Used to retrieve the event id for the event via the list table and for the given event.
82
-     * @param string $event_title
83
-     */
84
-    public function observeEventIdInListTableForEvent($event_title)
85
-    {
86
-        return $this->actor()->observeValueFromInputAt(EventsPage::eventListTableEventIdSelectorForTitle($event_title));
87
-    }
88
-
89
-
90
-    /**
91
-     * This performs the click action on the gear icon that triggers the advanced settings view state.
92
-     * Assumes the actor is already logged in and editing an event.
93
-     *
94
-     * @param int $row_number  What ticket row to toggle open/close.
95
-     */
96
-    public function toggleAdvancedSettingsViewForTicketRow($row_number = 1)
97
-    {
98
-        $this->actor()->click(EventsPage::eventEditorTicketAdvancedDetailsSelector($row_number));
99
-    }
100
-
101
-
102
-    /**
103
-     * Toggles the TKT_is_taxable checkbox for the ticket in the given row.
104
-     * Assumes the actor is already logged in and editing an event and that the advanced settings view state for that
105
-     * ticket is "open".
106
-     *
107
-     * @param int $row_number  What ticket row to toggle the checkbox for.
108
-     */
109
-    public function toggleTicketIsTaxableForTicketRow($row_number = 1)
110
-    {
111
-        $this->actor()->click(EventsPage::eventEditorTicketTaxableCheckboxSelector($row_number));
112
-    }
113
-
114
-
115
-    /**
116
-     * Use to change the default registration status for the event.
117
-     * Assumes the view is already on the event editor.
118
-     * @param $registration_status
119
-     */
120
-    public function changeDefaultRegistrationStatusTo($registration_status)
121
-    {
122
-        $this->actor()->selectOption(
123
-            EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR,
124
-            $registration_status
125
-        );
126
-    }
127
-
128
-
129
-    /**
130
-     * Use this from the context of the event editor to select the given custom template for a given message type and
131
-     * messenger.
132
-     *
133
-     * @param string $message_type_label  The visible label for the message type (eg Registration Approved)
134
-     * @param string $messenger_slug      The slug for the messenger (eg 'email')
135
-     * @param string $custom_template_label The visible label in the select input for the custom template you want
136
-     *                                      selected.
137
-     */
138
-    public function selectCustomTemplateFor($message_type_label, $messenger_slug, $custom_template_label)
139
-    {
140
-        $this->actor()->click(EventsPage::eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug));
141
-        $this->actor()->selectOption(
142
-            EventsPage::eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label),
143
-            $custom_template_label
144
-        );
145
-    }
17
+	/**
18
+	 * @param string $additional_params
19
+	 */
20
+	public function amOnDefaultEventsListTablePage($additional_params = '')
21
+	{
22
+		$this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params));
23
+	}
24
+
25
+
26
+	/**
27
+	 * Triggers the publishing of the Event.
28
+	 */
29
+	public function publishEvent()
30
+	{
31
+		$this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR);
32
+		$this->actor()->wait(3);
33
+		$this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR);
34
+		$this->actor()->waitForText('Event published.', 30);
35
+	}
36
+
37
+
38
+	/**
39
+	 * Triggers saving the Event.
40
+	 */
41
+	public function saveEvent()
42
+	{
43
+		$this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR);
44
+		$this->actor()->wait(2);
45
+		$this->actor()->click(EventsPage::EVENT_EDITOR_SAVE_BUTTON_SELECTOR);
46
+	}
47
+
48
+
49
+	/**
50
+	 * Navigates the actor to the event list table page and will attempt to edit the event for the given title.
51
+	 * First this will search using the given title and then attempt to edit from the results of the search.
52
+	 *
53
+	 * Assumes actor is already logged in.
54
+	 * @param $event_title
55
+	 */
56
+	public function amEditingTheEventWithTitle($event_title)
57
+	{
58
+		$this->amOnDefaultEventsListTablePage();
59
+		$this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title);
60
+		$this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR);
61
+		$this->actor()->waitForText($event_title, 15);
62
+		$this->actor()->click(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title));
63
+	}
64
+
65
+
66
+	/**
67
+	 * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View"
68
+	 * link for the event in the event list table.
69
+	 * Assumes the actor is already logged in and on the Event list table page.
70
+	 *
71
+	 * @param string $event_title
72
+	 */
73
+	public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title)
74
+	{
75
+		$this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title));
76
+		$this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title));
77
+	}
78
+
79
+
80
+	/**
81
+	 * Used to retrieve the event id for the event via the list table and for the given event.
82
+	 * @param string $event_title
83
+	 */
84
+	public function observeEventIdInListTableForEvent($event_title)
85
+	{
86
+		return $this->actor()->observeValueFromInputAt(EventsPage::eventListTableEventIdSelectorForTitle($event_title));
87
+	}
88
+
89
+
90
+	/**
91
+	 * This performs the click action on the gear icon that triggers the advanced settings view state.
92
+	 * Assumes the actor is already logged in and editing an event.
93
+	 *
94
+	 * @param int $row_number  What ticket row to toggle open/close.
95
+	 */
96
+	public function toggleAdvancedSettingsViewForTicketRow($row_number = 1)
97
+	{
98
+		$this->actor()->click(EventsPage::eventEditorTicketAdvancedDetailsSelector($row_number));
99
+	}
100
+
101
+
102
+	/**
103
+	 * Toggles the TKT_is_taxable checkbox for the ticket in the given row.
104
+	 * Assumes the actor is already logged in and editing an event and that the advanced settings view state for that
105
+	 * ticket is "open".
106
+	 *
107
+	 * @param int $row_number  What ticket row to toggle the checkbox for.
108
+	 */
109
+	public function toggleTicketIsTaxableForTicketRow($row_number = 1)
110
+	{
111
+		$this->actor()->click(EventsPage::eventEditorTicketTaxableCheckboxSelector($row_number));
112
+	}
113
+
114
+
115
+	/**
116
+	 * Use to change the default registration status for the event.
117
+	 * Assumes the view is already on the event editor.
118
+	 * @param $registration_status
119
+	 */
120
+	public function changeDefaultRegistrationStatusTo($registration_status)
121
+	{
122
+		$this->actor()->selectOption(
123
+			EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR,
124
+			$registration_status
125
+		);
126
+	}
127
+
128
+
129
+	/**
130
+	 * Use this from the context of the event editor to select the given custom template for a given message type and
131
+	 * messenger.
132
+	 *
133
+	 * @param string $message_type_label  The visible label for the message type (eg Registration Approved)
134
+	 * @param string $messenger_slug      The slug for the messenger (eg 'email')
135
+	 * @param string $custom_template_label The visible label in the select input for the custom template you want
136
+	 *                                      selected.
137
+	 */
138
+	public function selectCustomTemplateFor($message_type_label, $messenger_slug, $custom_template_label)
139
+	{
140
+		$this->actor()->click(EventsPage::eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug));
141
+		$this->actor()->selectOption(
142
+			EventsPage::eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label),
143
+			$custom_template_label
144
+		);
145
+	}
146 146
 }
147 147
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/Helpers/MessagesAdmin.php 1 patch
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -10,293 +10,293 @@
 block discarded – undo
10 10
  */
11 11
 trait MessagesAdmin
12 12
 {
13
-    /**
14
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
15
-     *                                  a string.
16
-     */
17
-    public function amOnMessagesActivityListTablePage($additional_params = '')
18
-    {
19
-        $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params));
20
-    }
21
-
22
-    /**
23
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
24
-     *                                  a string.
25
-     */
26
-    public function amOnDefaultMessageTemplateListTablePage($additional_params = '')
27
-    {
28
-        $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params));
29
-    }
30
-
31
-
32
-    /**
33
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
34
-     *                                  a string.
35
-     */
36
-    public function amOnCustomMessageTemplateListTablePage($additional_params = '')
37
-    {
38
-        $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params));
39
-    }
40
-
41
-
42
-    /**
43
-     * Directs to message settings page
44
-     */
45
-    public function amOnMessageSettingsPage()
46
-    {
47
-        $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl());
48
-    }
49
-
50
-
51
-    public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email')
52
-    {
53
-        $this->actor()->dragAndDrop(
54
-            MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug),
55
-            MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR
56
-        );
57
-    }
58
-
59
-
60
-    /**
61
-     * Assumes you are already on the list table page that has the ui for editing the template.
62
-     * @param string $message_type_slug
63
-     * @param string $context [optional] if you want to click directly to the given context in the editor
64
-     */
65
-    public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '')
66
-    {
67
-        $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context));
68
-    }
69
-
70
-
71
-    /**
72
-     * Use this action to verify that the count for the given text in the specified field is as expected.  For example
73
-     * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column.
74
-     *
75
-     * @param int    $expected_occurence_count
76
-     * @param string $text_to_check_for
77
-     * @param string $field
78
-     * @param string $message_type_label
79
-     * @param string $message_status
80
-     * @param string $messenger
81
-     * @param string $context
82
-     */
83
-    public function verifyMatchingCountofTextInMessageActivityListTableFor(
84
-        $expected_occurence_count,
85
-        $text_to_check_for,
86
-        $field,
87
-        $message_type_label,
88
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
89
-        $messenger = 'Email',
90
-        $context = 'Event Admin'
91
-    ) {
92
-        $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor(
93
-            $field,
94
-            $message_type_label,
95
-            $message_status,
96
-            $messenger,
97
-            $context,
98
-            $text_to_check_for,
99
-            0
100
-        ));
101
-        $actual_count = count($elements);
102
-        $this->actor()->assertEquals(
103
-            $expected_occurence_count,
104
-            $actual_count,
105
-            sprintf(
106
-                'Expected %s of the %s text for the %s field but there were actually %s counted.',
107
-                $expected_occurence_count,
108
-                $text_to_check_for,
109
-                $field,
110
-                $actual_count
111
-            )
112
-        );
113
-    }
114
-
115
-
116
-    /**
117
-     * This will create a custom message template for the given messenger and message type from the context of the
118
-     * default (global) message template list table.
119
-     * Also takes care of verifying the template was created.
120
-     * @param string $message_type_label
121
-     * @param string $messenger_label
122
-     */
123
-    public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label)
124
-    {
125
-        $this->amOnDefaultMessageTemplateListTablePage();
126
-        $this->actor()->click(
127
-            MessagesPage::createCustomButtonForMessageTypeAndMessenger(
128
-                $message_type_label,
129
-                $messenger_label
130
-            )
131
-        );
132
-        $this->actor()->seeInField('#title', 'New Custom Template');
133
-    }
134
-
135
-
136
-    /**
137
-     * This switches the context of the current messages template to the given reference.
138
-     * @param string $context_reference  This should be the visible label for the option.
139
-     */
140
-    public function switchContextTo($context_reference)
141
-    {
142
-        $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference);
143
-        $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR);
144
-        $this->actor()->waitForText($context_reference, 10, 'h1');
145
-    }
146
-
147
-
148
-    /**
149
-     * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after
150
-     * toggling.
151
-     *
152
-     * @param string $context_string           What context is being switched (used for the expected state text)
153
-     * @param bool   $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive
154
-     *                                         (false)
155
-     */
156
-    public function toggleContextState($context_string, $expected_state_is_active = true)
157
-    {
158
-        $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE);
159
-        if ($expected_state_is_active) {
160
-            $this->actor()->waitForText("The template for $context_string is currently active.");
161
-        } else {
162
-            $this->actor()->waitForText("The template for $context_string is currently inactive");
163
-        }
164
-    }
165
-
166
-
167
-    /**
168
-     * Triggers saving the message template.
169
-     * @param bool $and_close   Use to indicate to click the Save and Close button.
170
-     */
171
-    public function saveMessageTemplate($and_close = false)
172
-    {
173
-        $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR);
174
-        if ($and_close) {
175
-            $this->actor()->click('Save and Close');
176
-        } else {
177
-            $this->actor()->click('Save');
178
-        }
179
-        $this->actor()->waitForText('successfully updated');
180
-    }
181
-
182
-
183
-    /**
184
-     * This takes care of clicking the View Message icon for the given parameters.
185
-     * Assumes you are already viewing the messages activity list table.
186
-     * @param        $message_type_label
187
-     * @param        $message_status
188
-     * @param string $messenger
189
-     * @param string $context
190
-     * @param int    $number_in_set
191
-     */
192
-    public function viewMessageInMessagesListTableFor(
193
-        $message_type_label,
194
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
195
-        $messenger = 'Email',
196
-        $context = 'Event Admin',
197
-        $number_in_set = 1
198
-    ) {
199
-        $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor(
200
-            $message_type_label,
201
-            $message_status,
202
-            $messenger,
203
-            $context,
204
-            $number_in_set
205
-        ));
206
-    }
207
-
208
-
209
-    /**
210
-     * Takes care of deleting a message matching the given parameters via the message activity list table.
211
-     * Assumes you are already viewing the messages activity list table.
212
-     * @param        $message_type_label
213
-     * @param        $message_status
214
-     * @param string $messenger
215
-     * @param string $context
216
-     * @param int    $number_in_set
217
-     */
218
-    public function deleteMessageInMessagesListTableFor(
219
-        $message_type_label,
220
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
221
-        $messenger = 'Email',
222
-        $context = 'Event Admin',
223
-        $number_in_set = 1
224
-    ) {
225
-        $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor(
226
-            $message_type_label,
227
-            $message_status,
228
-            $messenger,
229
-            $context,
230
-            $number_in_set
231
-        );
232
-        $cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor(
233
-            'to',
234
-            $message_type_label,
235
-            $message_status,
236
-            $messenger,
237
-            $context,
238
-            '',
239
-            $number_in_set
240
-        );
241
-        $this->actor()->scrollTo($cell_selector, 0, -30);
242
-        $this->actor()->moveMouseOver(
243
-            $cell_selector,
244
-            5,
245
-            5
246
-        );
247
-        $this->actor()->waitForElementVisible(
248
-            $delete_action_selector
249
-        );
250
-        $this->actor()->click(
251
-            $delete_action_selector
252
-        );
253
-        $this->actor()->waitForText('successfully deleted', 20);
254
-    }
255
-
256
-
257
-    /**
258
-     * Assuming you have already triggered the view modal for a single message from the context of the message activity
259
-     * list table, this will take care of validating the given text is in that window.
260
-     * @param string $text_to_view
261
-     */
262
-    public function seeTextInViewMessageModal($text_to_view, $should_not_see = false)
263
-    {
264
-        $this->actor()->wait(2);
265
-        $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content');
266
-        $this->actor()->switchToIframe('message-view-window');
267
-        $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view);
268
-        $this->actor()->switchToIframe();
269
-    }
270
-
271
-
272
-    /**
273
-     * This returns the value for the link at the given selector in the message modal.
274
-     * @param string $selector (any selector string accepted by WebDriver)
275
-     */
276
-    public function observeLinkAtSelectorInMessageModal($selector)
277
-    {
278
-        $this->actor()->wait(2);
279
-        $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content');
280
-        $this->actor()->switchToIframe('message-view-window');
281
-        $link = $this->actor()->observeLinkUrlAt($selector);
282
-        $this->actor()->switchToIframe();
283
-        return $link;
284
-    }
285
-
286
-
287
-    /**
288
-     * Assuming you have already triggered the view modal for a single message from the context of the message activity
289
-     * list table, this will take care of validating the given text is NOT that window.
290
-     * @param string $text_to_view
291
-     */
292
-    public function dontSeeTextInViewMessageModal($text_to_view)
293
-    {
294
-        $this->seeTextInViewMessageModal($text_to_view, true);
295
-    }
296
-
297
-
298
-    public function dismissMessageModal()
299
-    {
300
-        $this->actor()->executeJs('window.dialogHelper.closeModal()');
301
-    }
13
+	/**
14
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
15
+	 *                                  a string.
16
+	 */
17
+	public function amOnMessagesActivityListTablePage($additional_params = '')
18
+	{
19
+		$this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params));
20
+	}
21
+
22
+	/**
23
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
24
+	 *                                  a string.
25
+	 */
26
+	public function amOnDefaultMessageTemplateListTablePage($additional_params = '')
27
+	{
28
+		$this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params));
29
+	}
30
+
31
+
32
+	/**
33
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
34
+	 *                                  a string.
35
+	 */
36
+	public function amOnCustomMessageTemplateListTablePage($additional_params = '')
37
+	{
38
+		$this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params));
39
+	}
40
+
41
+
42
+	/**
43
+	 * Directs to message settings page
44
+	 */
45
+	public function amOnMessageSettingsPage()
46
+	{
47
+		$this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl());
48
+	}
49
+
50
+
51
+	public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email')
52
+	{
53
+		$this->actor()->dragAndDrop(
54
+			MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug),
55
+			MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR
56
+		);
57
+	}
58
+
59
+
60
+	/**
61
+	 * Assumes you are already on the list table page that has the ui for editing the template.
62
+	 * @param string $message_type_slug
63
+	 * @param string $context [optional] if you want to click directly to the given context in the editor
64
+	 */
65
+	public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '')
66
+	{
67
+		$this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context));
68
+	}
69
+
70
+
71
+	/**
72
+	 * Use this action to verify that the count for the given text in the specified field is as expected.  For example
73
+	 * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column.
74
+	 *
75
+	 * @param int    $expected_occurence_count
76
+	 * @param string $text_to_check_for
77
+	 * @param string $field
78
+	 * @param string $message_type_label
79
+	 * @param string $message_status
80
+	 * @param string $messenger
81
+	 * @param string $context
82
+	 */
83
+	public function verifyMatchingCountofTextInMessageActivityListTableFor(
84
+		$expected_occurence_count,
85
+		$text_to_check_for,
86
+		$field,
87
+		$message_type_label,
88
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
89
+		$messenger = 'Email',
90
+		$context = 'Event Admin'
91
+	) {
92
+		$elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor(
93
+			$field,
94
+			$message_type_label,
95
+			$message_status,
96
+			$messenger,
97
+			$context,
98
+			$text_to_check_for,
99
+			0
100
+		));
101
+		$actual_count = count($elements);
102
+		$this->actor()->assertEquals(
103
+			$expected_occurence_count,
104
+			$actual_count,
105
+			sprintf(
106
+				'Expected %s of the %s text for the %s field but there were actually %s counted.',
107
+				$expected_occurence_count,
108
+				$text_to_check_for,
109
+				$field,
110
+				$actual_count
111
+			)
112
+		);
113
+	}
114
+
115
+
116
+	/**
117
+	 * This will create a custom message template for the given messenger and message type from the context of the
118
+	 * default (global) message template list table.
119
+	 * Also takes care of verifying the template was created.
120
+	 * @param string $message_type_label
121
+	 * @param string $messenger_label
122
+	 */
123
+	public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label)
124
+	{
125
+		$this->amOnDefaultMessageTemplateListTablePage();
126
+		$this->actor()->click(
127
+			MessagesPage::createCustomButtonForMessageTypeAndMessenger(
128
+				$message_type_label,
129
+				$messenger_label
130
+			)
131
+		);
132
+		$this->actor()->seeInField('#title', 'New Custom Template');
133
+	}
134
+
135
+
136
+	/**
137
+	 * This switches the context of the current messages template to the given reference.
138
+	 * @param string $context_reference  This should be the visible label for the option.
139
+	 */
140
+	public function switchContextTo($context_reference)
141
+	{
142
+		$this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference);
143
+		$this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR);
144
+		$this->actor()->waitForText($context_reference, 10, 'h1');
145
+	}
146
+
147
+
148
+	/**
149
+	 * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after
150
+	 * toggling.
151
+	 *
152
+	 * @param string $context_string           What context is being switched (used for the expected state text)
153
+	 * @param bool   $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive
154
+	 *                                         (false)
155
+	 */
156
+	public function toggleContextState($context_string, $expected_state_is_active = true)
157
+	{
158
+		$this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE);
159
+		if ($expected_state_is_active) {
160
+			$this->actor()->waitForText("The template for $context_string is currently active.");
161
+		} else {
162
+			$this->actor()->waitForText("The template for $context_string is currently inactive");
163
+		}
164
+	}
165
+
166
+
167
+	/**
168
+	 * Triggers saving the message template.
169
+	 * @param bool $and_close   Use to indicate to click the Save and Close button.
170
+	 */
171
+	public function saveMessageTemplate($and_close = false)
172
+	{
173
+		$this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR);
174
+		if ($and_close) {
175
+			$this->actor()->click('Save and Close');
176
+		} else {
177
+			$this->actor()->click('Save');
178
+		}
179
+		$this->actor()->waitForText('successfully updated');
180
+	}
181
+
182
+
183
+	/**
184
+	 * This takes care of clicking the View Message icon for the given parameters.
185
+	 * Assumes you are already viewing the messages activity list table.
186
+	 * @param        $message_type_label
187
+	 * @param        $message_status
188
+	 * @param string $messenger
189
+	 * @param string $context
190
+	 * @param int    $number_in_set
191
+	 */
192
+	public function viewMessageInMessagesListTableFor(
193
+		$message_type_label,
194
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
195
+		$messenger = 'Email',
196
+		$context = 'Event Admin',
197
+		$number_in_set = 1
198
+	) {
199
+		$this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor(
200
+			$message_type_label,
201
+			$message_status,
202
+			$messenger,
203
+			$context,
204
+			$number_in_set
205
+		));
206
+	}
207
+
208
+
209
+	/**
210
+	 * Takes care of deleting a message matching the given parameters via the message activity list table.
211
+	 * Assumes you are already viewing the messages activity list table.
212
+	 * @param        $message_type_label
213
+	 * @param        $message_status
214
+	 * @param string $messenger
215
+	 * @param string $context
216
+	 * @param int    $number_in_set
217
+	 */
218
+	public function deleteMessageInMessagesListTableFor(
219
+		$message_type_label,
220
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
221
+		$messenger = 'Email',
222
+		$context = 'Event Admin',
223
+		$number_in_set = 1
224
+	) {
225
+		$delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor(
226
+			$message_type_label,
227
+			$message_status,
228
+			$messenger,
229
+			$context,
230
+			$number_in_set
231
+		);
232
+		$cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor(
233
+			'to',
234
+			$message_type_label,
235
+			$message_status,
236
+			$messenger,
237
+			$context,
238
+			'',
239
+			$number_in_set
240
+		);
241
+		$this->actor()->scrollTo($cell_selector, 0, -30);
242
+		$this->actor()->moveMouseOver(
243
+			$cell_selector,
244
+			5,
245
+			5
246
+		);
247
+		$this->actor()->waitForElementVisible(
248
+			$delete_action_selector
249
+		);
250
+		$this->actor()->click(
251
+			$delete_action_selector
252
+		);
253
+		$this->actor()->waitForText('successfully deleted', 20);
254
+	}
255
+
256
+
257
+	/**
258
+	 * Assuming you have already triggered the view modal for a single message from the context of the message activity
259
+	 * list table, this will take care of validating the given text is in that window.
260
+	 * @param string $text_to_view
261
+	 */
262
+	public function seeTextInViewMessageModal($text_to_view, $should_not_see = false)
263
+	{
264
+		$this->actor()->wait(2);
265
+		$this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content');
266
+		$this->actor()->switchToIframe('message-view-window');
267
+		$should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view);
268
+		$this->actor()->switchToIframe();
269
+	}
270
+
271
+
272
+	/**
273
+	 * This returns the value for the link at the given selector in the message modal.
274
+	 * @param string $selector (any selector string accepted by WebDriver)
275
+	 */
276
+	public function observeLinkAtSelectorInMessageModal($selector)
277
+	{
278
+		$this->actor()->wait(2);
279
+		$this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content');
280
+		$this->actor()->switchToIframe('message-view-window');
281
+		$link = $this->actor()->observeLinkUrlAt($selector);
282
+		$this->actor()->switchToIframe();
283
+		return $link;
284
+	}
285
+
286
+
287
+	/**
288
+	 * Assuming you have already triggered the view modal for a single message from the context of the message activity
289
+	 * list table, this will take care of validating the given text is NOT that window.
290
+	 * @param string $text_to_view
291
+	 */
292
+	public function dontSeeTextInViewMessageModal($text_to_view)
293
+	{
294
+		$this->seeTextInViewMessageModal($text_to_view, true);
295
+	}
296
+
297
+
298
+	public function dismissMessageModal()
299
+	{
300
+		$this->actor()->executeJs('window.dialogHelper.closeModal()');
301
+	}
302 302
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -38,216 +38,216 @@
 block discarded – undo
38 38
  * @since       4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.58.rc.001');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.58.rc.001');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118
-        /**
119
-         *    espresso_load_error_handling
120
-         *    this function loads EE's class for handling exceptions and errors
121
-         */
122
-        function espresso_load_error_handling()
123
-        {
124
-            static $error_handling_loaded = false;
125
-            if ($error_handling_loaded) {
126
-                return;
127
-            }
128
-            // load debugging tools
129
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
130
-                require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
131
-                \EEH_Debug_Tools::instance();
132
-            }
133
-            // load error handling
134
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
135
-                require_once EE_CORE . 'EE_Error.core.php';
136
-            } else {
137
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
138
-            }
139
-            $error_handling_loaded = true;
140
-        }
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118
+		/**
119
+		 *    espresso_load_error_handling
120
+		 *    this function loads EE's class for handling exceptions and errors
121
+		 */
122
+		function espresso_load_error_handling()
123
+		{
124
+			static $error_handling_loaded = false;
125
+			if ($error_handling_loaded) {
126
+				return;
127
+			}
128
+			// load debugging tools
129
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
130
+				require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
131
+				\EEH_Debug_Tools::instance();
132
+			}
133
+			// load error handling
134
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
135
+				require_once EE_CORE . 'EE_Error.core.php';
136
+			} else {
137
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
138
+			}
139
+			$error_handling_loaded = true;
140
+		}
141 141
 
142
-        /**
143
-         *    espresso_load_required
144
-         *    given a class name and path, this function will load that file or throw an exception
145
-         *
146
-         * @param    string $classname
147
-         * @param    string $full_path_to_file
148
-         * @throws    EE_Error
149
-         */
150
-        function espresso_load_required($classname, $full_path_to_file)
151
-        {
152
-            if (is_readable($full_path_to_file)) {
153
-                require_once $full_path_to_file;
154
-            } else {
155
-                throw new \EE_Error (
156
-                    sprintf(
157
-                        esc_html__(
158
-                            'The %s class file could not be located or is not readable due to file permissions.',
159
-                            'event_espresso'
160
-                        ),
161
-                        $classname
162
-                    )
163
-                );
164
-            }
165
-        }
142
+		/**
143
+		 *    espresso_load_required
144
+		 *    given a class name and path, this function will load that file or throw an exception
145
+		 *
146
+		 * @param    string $classname
147
+		 * @param    string $full_path_to_file
148
+		 * @throws    EE_Error
149
+		 */
150
+		function espresso_load_required($classname, $full_path_to_file)
151
+		{
152
+			if (is_readable($full_path_to_file)) {
153
+				require_once $full_path_to_file;
154
+			} else {
155
+				throw new \EE_Error (
156
+					sprintf(
157
+						esc_html__(
158
+							'The %s class file could not be located or is not readable due to file permissions.',
159
+							'event_espresso'
160
+						),
161
+						$classname
162
+					)
163
+				);
164
+			}
165
+		}
166 166
 
167
-        /**
168
-         * @since 4.9.27
169
-         * @throws \EE_Error
170
-         * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
171
-         * @throws \EventEspresso\core\exceptions\InvalidEntityException
172
-         * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
173
-         * @throws \EventEspresso\core\exceptions\InvalidClassException
174
-         * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
175
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
176
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
177
-         * @throws \OutOfBoundsException
178
-         */
179
-        function bootstrap_espresso()
180
-        {
181
-            require_once __DIR__ . '/core/espresso_definitions.php';
182
-            try {
183
-                espresso_load_error_handling();
184
-                espresso_load_required(
185
-                    'EEH_Base',
186
-                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
187
-                );
188
-                espresso_load_required(
189
-                    'EEH_File',
190
-                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
191
-                );
192
-                espresso_load_required(
193
-                    'EEH_File',
194
-                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
195
-                );
196
-                espresso_load_required(
197
-                    'EEH_Array',
198
-                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
199
-                );
200
-                // instantiate and configure PSR4 autoloader
201
-                espresso_load_required(
202
-                    'Psr4Autoloader',
203
-                    EE_CORE . 'Psr4Autoloader.php'
204
-                );
205
-                espresso_load_required(
206
-                    'EE_Psr4AutoloaderInit',
207
-                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
208
-                );
209
-                $AutoloaderInit = new EE_Psr4AutoloaderInit();
210
-                $AutoloaderInit->initializeAutoloader();
211
-                espresso_load_required(
212
-                    'EE_Request',
213
-                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
214
-                );
215
-                espresso_load_required(
216
-                    'EE_Response',
217
-                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
218
-                );
219
-                espresso_load_required(
220
-                    'EE_Bootstrap',
221
-                    EE_CORE . 'EE_Bootstrap.core.php'
222
-                );
223
-                // bootstrap EE and the request stack
224
-                new EE_Bootstrap(
225
-                    new EE_Request($_GET, $_POST, $_COOKIE),
226
-                    new EE_Response()
227
-                );
228
-            } catch (Exception $e) {
229
-                require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
230
-                new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
231
-            }
232
-        }
233
-        bootstrap_espresso();
234
-    }
167
+		/**
168
+		 * @since 4.9.27
169
+		 * @throws \EE_Error
170
+		 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
171
+		 * @throws \EventEspresso\core\exceptions\InvalidEntityException
172
+		 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
173
+		 * @throws \EventEspresso\core\exceptions\InvalidClassException
174
+		 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
175
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
176
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
177
+		 * @throws \OutOfBoundsException
178
+		 */
179
+		function bootstrap_espresso()
180
+		{
181
+			require_once __DIR__ . '/core/espresso_definitions.php';
182
+			try {
183
+				espresso_load_error_handling();
184
+				espresso_load_required(
185
+					'EEH_Base',
186
+					EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
187
+				);
188
+				espresso_load_required(
189
+					'EEH_File',
190
+					EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
191
+				);
192
+				espresso_load_required(
193
+					'EEH_File',
194
+					EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
195
+				);
196
+				espresso_load_required(
197
+					'EEH_Array',
198
+					EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
199
+				);
200
+				// instantiate and configure PSR4 autoloader
201
+				espresso_load_required(
202
+					'Psr4Autoloader',
203
+					EE_CORE . 'Psr4Autoloader.php'
204
+				);
205
+				espresso_load_required(
206
+					'EE_Psr4AutoloaderInit',
207
+					EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
208
+				);
209
+				$AutoloaderInit = new EE_Psr4AutoloaderInit();
210
+				$AutoloaderInit->initializeAutoloader();
211
+				espresso_load_required(
212
+					'EE_Request',
213
+					EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
214
+				);
215
+				espresso_load_required(
216
+					'EE_Response',
217
+					EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
218
+				);
219
+				espresso_load_required(
220
+					'EE_Bootstrap',
221
+					EE_CORE . 'EE_Bootstrap.core.php'
222
+				);
223
+				// bootstrap EE and the request stack
224
+				new EE_Bootstrap(
225
+					new EE_Request($_GET, $_POST, $_COOKIE),
226
+					new EE_Response()
227
+				);
228
+			} catch (Exception $e) {
229
+				require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
230
+				new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
231
+			}
232
+		}
233
+		bootstrap_espresso();
234
+	}
235 235
 }
236 236
 if (! function_exists('espresso_deactivate_plugin')) {
237
-    /**
238
-     *    deactivate_plugin
239
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
240
-     *
241
-     * @access public
242
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
243
-     * @return    void
244
-     */
245
-    function espresso_deactivate_plugin($plugin_basename = '')
246
-    {
247
-        if (! function_exists('deactivate_plugins')) {
248
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
249
-        }
250
-        unset($_GET['activate'], $_REQUEST['activate']);
251
-        deactivate_plugins($plugin_basename);
252
-    }
237
+	/**
238
+	 *    deactivate_plugin
239
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
240
+	 *
241
+	 * @access public
242
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
243
+	 * @return    void
244
+	 */
245
+	function espresso_deactivate_plugin($plugin_basename = '')
246
+	{
247
+		if (! function_exists('deactivate_plugins')) {
248
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
249
+		}
250
+		unset($_GET['activate'], $_REQUEST['activate']);
251
+		deactivate_plugins($plugin_basename);
252
+	}
253 253
 }
Please login to merge, or discard this patch.
core/request_stack/EE_Request.core.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
      * returns   the value for a request param if the given key exists
168 168
      *
169 169
      * @param       $key
170
-     * @param null|mixed  $default
170
+     * @param null|string  $default
171 171
      * @return mixed
172 172
      */
173 173
     public function get($key, $default = null)
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
      * returns true if a match is found or false if not
215 215
      *
216 216
      * @param string $pattern
217
-     * @return false|int
217
+     * @return boolean
218 218
      */
219 219
     public function matches($pattern)
220 220
     {
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 
373 373
 
374 374
     /**
375
-     * @return mixed
375
+     * @return boolean
376 376
      */
377 377
     public function isAjax()
378 378
     {
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 
382 382
 
383 383
     /**
384
-     * @return mixed
384
+     * @return boolean
385 385
      */
386 386
     public function isFrontAjax()
387 387
     {
Please login to merge, or discard this patch.
Indentation   +405 added lines, -405 removed lines patch added patch discarded remove patch
@@ -16,411 +16,411 @@
 block discarded – undo
16 16
 class EE_Request implements InterminableInterface
17 17
 {
18 18
 
19
-    /**
20
-     * $_GET parameters
21
-     *
22
-     * @var array $_get
23
-     */
24
-    private $_get;
25
-
26
-    /**
27
-     * $_POST parameters
28
-     *
29
-     * @var    array $_post
30
-     */
31
-    private $_post;
32
-
33
-    /**
34
-     * $_COOKIE parameters
35
-     *
36
-     * @var array $_cookie
37
-     */
38
-    private $_cookie;
39
-
40
-    /**
41
-     * $_REQUEST parameters
42
-     *
43
-     * @var array $_params
44
-     */
45
-    private $_params;
46
-
47
-    /**
48
-     * whether current request is for the admin but NOT via AJAX
49
-     *
50
-     * @var boolean $admin
51
-     */
52
-    public $admin = false;
53
-
54
-    /**
55
-     * whether current request is via AJAX
56
-     *
57
-     * @var boolean $ajax
58
-     */
59
-    public $ajax = false;
60
-
61
-    /**
62
-     * whether current request is via AJAX from the frontend of the site
63
-     *
64
-     * @var boolean $front_ajax
65
-     */
66
-    public $front_ajax = false;
67
-
68
-    /**
69
-     * IP address for request
70
-     *
71
-     * @var string $_ip_address
72
-     */
73
-    private $_ip_address;
74
-
75
-
76
-
77
-    /**
78
-     * class constructor
79
-     *
80
-     * @access    public
81
-     * @param array $get
82
-     * @param array $post
83
-     * @param array $cookie
84
-     */
85
-    public function __construct(array $get, array $post, array $cookie)
86
-    {
87
-        // grab request vars
88
-        $this->_get    = $get;
89
-        $this->_post   = $post;
90
-        $this->_cookie = $cookie;
91
-        $this->_params = array_merge($this->_get, $this->_post);
92
-        // AJAX ???
93
-        $this->ajax       = defined('DOING_AJAX') && DOING_AJAX;
94
-        $this->front_ajax = $this->ajax
95
-                            && $this->is_set('ee_front_ajax')
96
-                            && filter_var($this->get('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN);
97
-        $this->admin      = is_admin() && ! $this->ajax;
98
-        // grab user IP
99
-        $this->_ip_address = $this->_visitor_ip();
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     * @return array
106
-     */
107
-    public function get_params()
108
-    {
109
-        return $this->_get;
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * @return array
116
-     */
117
-    public function post_params()
118
-    {
119
-        return $this->_post;
120
-    }
121
-
122
-
123
-
124
-    /**
125
-     * @return array
126
-     */
127
-    public function cookie_params()
128
-    {
129
-        return $this->_cookie;
130
-    }
131
-
132
-
133
-
134
-    /**
135
-     * returns contents of $_REQUEST
136
-     *
137
-     * @return array
138
-     */
139
-    public function params()
140
-    {
141
-        return $this->_params;
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     * @param      $key
148
-     * @param      $value
149
-     * @param bool $override_ee
150
-     * @return    void
151
-     */
152
-    public function set($key, $value, $override_ee = false)
153
-    {
154
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
155
-        if (
156
-            $key !== 'ee'
157
-            || ($key === 'ee' && empty($this->_params['ee']))
158
-            || ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee)
159
-        ) {
160
-            $this->_params[$key] = $value;
161
-        }
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     * returns   the value for a request param if the given key exists
168
-     *
169
-     * @param       $key
170
-     * @param null|mixed  $default
171
-     * @return mixed
172
-     */
173
-    public function get($key, $default = null)
174
-    {
175
-        return $this->request_parameter_drill_down($key, $default, 'get');
176
-    }
177
-
178
-
179
-
180
-    /**
181
-     * check if param exists
182
-     *
183
-     * @param       $key
184
-     * @return bool
185
-     */
186
-    public function is_set($key)
187
-    {
188
-        return $this->request_parameter_drill_down($key);
189
-    }
190
-
191
-
192
-    /**
193
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
194
-     * and return the value for the first match found
195
-     * wildcards can be either of the following:
196
-     *      ? to represent a single character of any type
197
-     *      * to represent one or more characters of any type
198
-     *
199
-     * @param string $pattern
200
-     * @param null|mixed $default
201
-     * @return false|int
202
-     */
203
-    public function getMatch($pattern, $default = null)
204
-    {
205
-        return $this->request_parameter_drill_down($pattern, $default, 'match');
206
-    }
207
-
208
-
209
-    /**
210
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
211
-     * wildcards can be either of the following:
212
-     *      ? to represent a single character of any type
213
-     *      * to represent one or more characters of any type
214
-     * returns true if a match is found or false if not
215
-     *
216
-     * @param string $pattern
217
-     * @return false|int
218
-     */
219
-    public function matches($pattern)
220
-    {
221
-        return $this->request_parameter_drill_down($pattern, null, 'match') !== null;
222
-    }
223
-
224
-
225
-    /**
226
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
227
-     * @param string $pattern           A string including wildcards to be converted to a regex pattern
228
-     *                                  and used to search through the current request's parameter keys
229
-     * @param array  $request_params    The array of request parameters to search through
230
-     * @param mixed  $default           [optional] The value to be returned if no match is found.
231
-     *                                  Default is null
232
-     * @param string $return            [optional] Controls what kind of value is returned.
233
-     *                                  Options are:
234
-     *                                      'bool' will return true or false if match is found or not
235
-     *                                      'key' will return the first key found that matches the supplied pattern
236
-     *                                      'value' will return the value for the first request parameter
237
-     *                                      whose key matches the supplied pattern
238
-     *                                  Default is 'value'
239
-     * @return boolean|string
240
-     */
241
-    private function match($pattern, array $request_params, $default = null, $return = 'value')
242
-    {
243
-        $return = in_array($return, array('bool', 'key', 'value'), true)
244
-            ? $return
245
-            : 'is_set';
246
-        // replace wildcard chars with regex chars
247
-        $pattern = str_replace(
248
-            array("\*", "\?"),
249
-            array('.*', '.'),
250
-            preg_quote($pattern, '/')
251
-        );
252
-        foreach ($request_params as $key => $request_param) {
253
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
254
-                // return value for request param
255
-                if ($return === 'value'){
256
-                    return $request_params[ $key ];
257
-                }
258
-                // or actual key or true just to indicate it was found
259
-                return $return === 'key' ? $key : true;
260
-            }
261
-        }
262
-        // match not found so return default value or false
263
-        return $return === 'value' ? $default : false;
264
-    }
265
-
266
-    /**
267
-     * the supplied key can be a simple string to represent a "top-level" request parameter
268
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
269
-     * by using square brackets to surround keys for deeper array elements.
270
-     * For example :
271
-     * if the supplied $key was: "first[second][third]"
272
-     * then this will attempt to drill down into the request parameter array to find a value.
273
-     * Given the following request parameters:
274
-     *  array(
275
-     *      'first' => array(
276
-     *          'second' => array(
277
-     *              'third' => 'has a value'
278
-     *          )
279
-     *      )
280
-     *  )
281
-     * would return true if default parameters were set
282
-     *
283
-     * @param string $callback
284
-     * @param        $key
285
-     * @param null   $default
286
-     * @param array  $request_params
287
-     * @return bool|mixed|null
288
-     */
289
-    private function request_parameter_drill_down(
290
-        $key,
291
-        $default = null,
292
-        $callback = 'is_set',
293
-        array $request_params = array()
294
-    ) {
295
-        $callback = in_array($callback, array('is_set', 'get', 'match'), true)
296
-            ? $callback
297
-            : 'is_set';
298
-        $request_params = ! empty($request_params)
299
-            ? $request_params
300
-            : $this->_params;
301
-        // does incoming key represent an array like 'first[second][third]'  ?
302
-        if (strpos($key, '[') !== false) {
303
-            // turn it into an actual array
304
-            $key  = str_replace(']', '', $key);
305
-            $keys = explode('[', $key);
306
-            $key  = array_shift($keys);
307
-            if ($callback === 'match') {
308
-                $real_key = $this->match($key, $request_params, $default, 'key');
309
-                $key = $real_key ? $real_key : $key;
310
-            }
311
-            // check if top level key exists
312
-            if (isset($request_params[ $key ])) {
313
-                // build a new key to pass along like: 'second[third]'
314
-                // or just 'second' depending on depth of keys
315
-                $key_string = array_shift($keys);
316
-                if (! empty($keys)) {
317
-                    $key_string .= '[' . implode('][', $keys) . ']';
318
-                }
319
-                return $this->request_parameter_drill_down(
320
-                    $key_string,
321
-                    $default,
322
-                    $callback,
323
-                    $request_params[ $key ]
324
-                );
325
-            }
326
-        }
327
-        if ($callback === 'is_set') {
328
-            return isset($request_params[$key]);
329
-        }
330
-        if ($callback === 'match') {
331
-            return $this->match($key, $request_params, $default);
332
-        }
333
-        return isset($request_params[$key])
334
-            ? $request_params[$key]
335
-            : $default;
336
-    }
337
-
338
-
339
-
340
-    /**
341
-     * remove param
342
-     *
343
-     * @param      $key
344
-     * @param bool $unset_from_global_too
345
-     */
346
-    public function un_set($key, $unset_from_global_too = false)
347
-    {
348
-        unset($this->_params[$key]);
349
-        if ($unset_from_global_too) {
350
-            unset($_REQUEST[$key]);
351
-        }
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * @return string
358
-     */
359
-    public function ip_address()
360
-    {
361
-        return $this->_ip_address;
362
-    }
363
-
364
-
365
-    /**
366
-     * @return bool
367
-     */
368
-    public function isAdmin()
369
-    {
370
-        return $this->admin;
371
-    }
372
-
373
-
374
-    /**
375
-     * @return mixed
376
-     */
377
-    public function isAjax()
378
-    {
379
-        return $this->ajax;
380
-    }
381
-
382
-
383
-    /**
384
-     * @return mixed
385
-     */
386
-    public function isFrontAjax()
387
-    {
388
-        return $this->front_ajax;
389
-    }
390
-
391
-
392
-
393
-    /**
394
-     * _visitor_ip
395
-     *    attempt to get IP address of current visitor from server
396
-     * plz see: http://stackoverflow.com/a/2031935/1475279
397
-     *
398
-     * @access public
399
-     * @return string
400
-     */
401
-    private function _visitor_ip()
402
-    {
403
-        $visitor_ip  = '0.0.0.0';
404
-        $server_keys = array(
405
-            'HTTP_CLIENT_IP',
406
-            'HTTP_X_FORWARDED_FOR',
407
-            'HTTP_X_FORWARDED',
408
-            'HTTP_X_CLUSTER_CLIENT_IP',
409
-            'HTTP_FORWARDED_FOR',
410
-            'HTTP_FORWARDED',
411
-            'REMOTE_ADDR',
412
-        );
413
-        foreach ($server_keys as $key) {
414
-            if (isset($_SERVER[$key])) {
415
-                foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
416
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
417
-                        $visitor_ip = $ip;
418
-                    }
419
-                }
420
-            }
421
-        }
422
-        return $visitor_ip;
423
-    }
19
+	/**
20
+	 * $_GET parameters
21
+	 *
22
+	 * @var array $_get
23
+	 */
24
+	private $_get;
25
+
26
+	/**
27
+	 * $_POST parameters
28
+	 *
29
+	 * @var    array $_post
30
+	 */
31
+	private $_post;
32
+
33
+	/**
34
+	 * $_COOKIE parameters
35
+	 *
36
+	 * @var array $_cookie
37
+	 */
38
+	private $_cookie;
39
+
40
+	/**
41
+	 * $_REQUEST parameters
42
+	 *
43
+	 * @var array $_params
44
+	 */
45
+	private $_params;
46
+
47
+	/**
48
+	 * whether current request is for the admin but NOT via AJAX
49
+	 *
50
+	 * @var boolean $admin
51
+	 */
52
+	public $admin = false;
53
+
54
+	/**
55
+	 * whether current request is via AJAX
56
+	 *
57
+	 * @var boolean $ajax
58
+	 */
59
+	public $ajax = false;
60
+
61
+	/**
62
+	 * whether current request is via AJAX from the frontend of the site
63
+	 *
64
+	 * @var boolean $front_ajax
65
+	 */
66
+	public $front_ajax = false;
67
+
68
+	/**
69
+	 * IP address for request
70
+	 *
71
+	 * @var string $_ip_address
72
+	 */
73
+	private $_ip_address;
74
+
75
+
76
+
77
+	/**
78
+	 * class constructor
79
+	 *
80
+	 * @access    public
81
+	 * @param array $get
82
+	 * @param array $post
83
+	 * @param array $cookie
84
+	 */
85
+	public function __construct(array $get, array $post, array $cookie)
86
+	{
87
+		// grab request vars
88
+		$this->_get    = $get;
89
+		$this->_post   = $post;
90
+		$this->_cookie = $cookie;
91
+		$this->_params = array_merge($this->_get, $this->_post);
92
+		// AJAX ???
93
+		$this->ajax       = defined('DOING_AJAX') && DOING_AJAX;
94
+		$this->front_ajax = $this->ajax
95
+							&& $this->is_set('ee_front_ajax')
96
+							&& filter_var($this->get('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN);
97
+		$this->admin      = is_admin() && ! $this->ajax;
98
+		// grab user IP
99
+		$this->_ip_address = $this->_visitor_ip();
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 * @return array
106
+	 */
107
+	public function get_params()
108
+	{
109
+		return $this->_get;
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * @return array
116
+	 */
117
+	public function post_params()
118
+	{
119
+		return $this->_post;
120
+	}
121
+
122
+
123
+
124
+	/**
125
+	 * @return array
126
+	 */
127
+	public function cookie_params()
128
+	{
129
+		return $this->_cookie;
130
+	}
131
+
132
+
133
+
134
+	/**
135
+	 * returns contents of $_REQUEST
136
+	 *
137
+	 * @return array
138
+	 */
139
+	public function params()
140
+	{
141
+		return $this->_params;
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 * @param      $key
148
+	 * @param      $value
149
+	 * @param bool $override_ee
150
+	 * @return    void
151
+	 */
152
+	public function set($key, $value, $override_ee = false)
153
+	{
154
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
155
+		if (
156
+			$key !== 'ee'
157
+			|| ($key === 'ee' && empty($this->_params['ee']))
158
+			|| ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee)
159
+		) {
160
+			$this->_params[$key] = $value;
161
+		}
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 * returns   the value for a request param if the given key exists
168
+	 *
169
+	 * @param       $key
170
+	 * @param null|mixed  $default
171
+	 * @return mixed
172
+	 */
173
+	public function get($key, $default = null)
174
+	{
175
+		return $this->request_parameter_drill_down($key, $default, 'get');
176
+	}
177
+
178
+
179
+
180
+	/**
181
+	 * check if param exists
182
+	 *
183
+	 * @param       $key
184
+	 * @return bool
185
+	 */
186
+	public function is_set($key)
187
+	{
188
+		return $this->request_parameter_drill_down($key);
189
+	}
190
+
191
+
192
+	/**
193
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
194
+	 * and return the value for the first match found
195
+	 * wildcards can be either of the following:
196
+	 *      ? to represent a single character of any type
197
+	 *      * to represent one or more characters of any type
198
+	 *
199
+	 * @param string $pattern
200
+	 * @param null|mixed $default
201
+	 * @return false|int
202
+	 */
203
+	public function getMatch($pattern, $default = null)
204
+	{
205
+		return $this->request_parameter_drill_down($pattern, $default, 'match');
206
+	}
207
+
208
+
209
+	/**
210
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
211
+	 * wildcards can be either of the following:
212
+	 *      ? to represent a single character of any type
213
+	 *      * to represent one or more characters of any type
214
+	 * returns true if a match is found or false if not
215
+	 *
216
+	 * @param string $pattern
217
+	 * @return false|int
218
+	 */
219
+	public function matches($pattern)
220
+	{
221
+		return $this->request_parameter_drill_down($pattern, null, 'match') !== null;
222
+	}
223
+
224
+
225
+	/**
226
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
227
+	 * @param string $pattern           A string including wildcards to be converted to a regex pattern
228
+	 *                                  and used to search through the current request's parameter keys
229
+	 * @param array  $request_params    The array of request parameters to search through
230
+	 * @param mixed  $default           [optional] The value to be returned if no match is found.
231
+	 *                                  Default is null
232
+	 * @param string $return            [optional] Controls what kind of value is returned.
233
+	 *                                  Options are:
234
+	 *                                      'bool' will return true or false if match is found or not
235
+	 *                                      'key' will return the first key found that matches the supplied pattern
236
+	 *                                      'value' will return the value for the first request parameter
237
+	 *                                      whose key matches the supplied pattern
238
+	 *                                  Default is 'value'
239
+	 * @return boolean|string
240
+	 */
241
+	private function match($pattern, array $request_params, $default = null, $return = 'value')
242
+	{
243
+		$return = in_array($return, array('bool', 'key', 'value'), true)
244
+			? $return
245
+			: 'is_set';
246
+		// replace wildcard chars with regex chars
247
+		$pattern = str_replace(
248
+			array("\*", "\?"),
249
+			array('.*', '.'),
250
+			preg_quote($pattern, '/')
251
+		);
252
+		foreach ($request_params as $key => $request_param) {
253
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
254
+				// return value for request param
255
+				if ($return === 'value'){
256
+					return $request_params[ $key ];
257
+				}
258
+				// or actual key or true just to indicate it was found
259
+				return $return === 'key' ? $key : true;
260
+			}
261
+		}
262
+		// match not found so return default value or false
263
+		return $return === 'value' ? $default : false;
264
+	}
265
+
266
+	/**
267
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
268
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
269
+	 * by using square brackets to surround keys for deeper array elements.
270
+	 * For example :
271
+	 * if the supplied $key was: "first[second][third]"
272
+	 * then this will attempt to drill down into the request parameter array to find a value.
273
+	 * Given the following request parameters:
274
+	 *  array(
275
+	 *      'first' => array(
276
+	 *          'second' => array(
277
+	 *              'third' => 'has a value'
278
+	 *          )
279
+	 *      )
280
+	 *  )
281
+	 * would return true if default parameters were set
282
+	 *
283
+	 * @param string $callback
284
+	 * @param        $key
285
+	 * @param null   $default
286
+	 * @param array  $request_params
287
+	 * @return bool|mixed|null
288
+	 */
289
+	private function request_parameter_drill_down(
290
+		$key,
291
+		$default = null,
292
+		$callback = 'is_set',
293
+		array $request_params = array()
294
+	) {
295
+		$callback = in_array($callback, array('is_set', 'get', 'match'), true)
296
+			? $callback
297
+			: 'is_set';
298
+		$request_params = ! empty($request_params)
299
+			? $request_params
300
+			: $this->_params;
301
+		// does incoming key represent an array like 'first[second][third]'  ?
302
+		if (strpos($key, '[') !== false) {
303
+			// turn it into an actual array
304
+			$key  = str_replace(']', '', $key);
305
+			$keys = explode('[', $key);
306
+			$key  = array_shift($keys);
307
+			if ($callback === 'match') {
308
+				$real_key = $this->match($key, $request_params, $default, 'key');
309
+				$key = $real_key ? $real_key : $key;
310
+			}
311
+			// check if top level key exists
312
+			if (isset($request_params[ $key ])) {
313
+				// build a new key to pass along like: 'second[third]'
314
+				// or just 'second' depending on depth of keys
315
+				$key_string = array_shift($keys);
316
+				if (! empty($keys)) {
317
+					$key_string .= '[' . implode('][', $keys) . ']';
318
+				}
319
+				return $this->request_parameter_drill_down(
320
+					$key_string,
321
+					$default,
322
+					$callback,
323
+					$request_params[ $key ]
324
+				);
325
+			}
326
+		}
327
+		if ($callback === 'is_set') {
328
+			return isset($request_params[$key]);
329
+		}
330
+		if ($callback === 'match') {
331
+			return $this->match($key, $request_params, $default);
332
+		}
333
+		return isset($request_params[$key])
334
+			? $request_params[$key]
335
+			: $default;
336
+	}
337
+
338
+
339
+
340
+	/**
341
+	 * remove param
342
+	 *
343
+	 * @param      $key
344
+	 * @param bool $unset_from_global_too
345
+	 */
346
+	public function un_set($key, $unset_from_global_too = false)
347
+	{
348
+		unset($this->_params[$key]);
349
+		if ($unset_from_global_too) {
350
+			unset($_REQUEST[$key]);
351
+		}
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * @return string
358
+	 */
359
+	public function ip_address()
360
+	{
361
+		return $this->_ip_address;
362
+	}
363
+
364
+
365
+	/**
366
+	 * @return bool
367
+	 */
368
+	public function isAdmin()
369
+	{
370
+		return $this->admin;
371
+	}
372
+
373
+
374
+	/**
375
+	 * @return mixed
376
+	 */
377
+	public function isAjax()
378
+	{
379
+		return $this->ajax;
380
+	}
381
+
382
+
383
+	/**
384
+	 * @return mixed
385
+	 */
386
+	public function isFrontAjax()
387
+	{
388
+		return $this->front_ajax;
389
+	}
390
+
391
+
392
+
393
+	/**
394
+	 * _visitor_ip
395
+	 *    attempt to get IP address of current visitor from server
396
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
397
+	 *
398
+	 * @access public
399
+	 * @return string
400
+	 */
401
+	private function _visitor_ip()
402
+	{
403
+		$visitor_ip  = '0.0.0.0';
404
+		$server_keys = array(
405
+			'HTTP_CLIENT_IP',
406
+			'HTTP_X_FORWARDED_FOR',
407
+			'HTTP_X_FORWARDED',
408
+			'HTTP_X_CLUSTER_CLIENT_IP',
409
+			'HTTP_FORWARDED_FOR',
410
+			'HTTP_FORWARDED',
411
+			'REMOTE_ADDR',
412
+		);
413
+		foreach ($server_keys as $key) {
414
+			if (isset($_SERVER[$key])) {
415
+				foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
416
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
417
+						$visitor_ip = $ip;
418
+					}
419
+				}
420
+			}
421
+		}
422
+		return $visitor_ip;
423
+	}
424 424
 
425 425
 
426 426
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -250,10 +250,10 @@  discard block
 block discarded – undo
250 250
             preg_quote($pattern, '/')
251 251
         );
252 252
         foreach ($request_params as $key => $request_param) {
253
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
253
+            if (preg_match('/^'.$pattern.'$/is', $key)) {
254 254
                 // return value for request param
255
-                if ($return === 'value'){
256
-                    return $request_params[ $key ];
255
+                if ($return === 'value') {
256
+                    return $request_params[$key];
257 257
                 }
258 258
                 // or actual key or true just to indicate it was found
259 259
                 return $return === 'key' ? $key : true;
@@ -309,18 +309,18 @@  discard block
 block discarded – undo
309 309
                 $key = $real_key ? $real_key : $key;
310 310
             }
311 311
             // check if top level key exists
312
-            if (isset($request_params[ $key ])) {
312
+            if (isset($request_params[$key])) {
313 313
                 // build a new key to pass along like: 'second[third]'
314 314
                 // or just 'second' depending on depth of keys
315 315
                 $key_string = array_shift($keys);
316
-                if (! empty($keys)) {
317
-                    $key_string .= '[' . implode('][', $keys) . ']';
316
+                if ( ! empty($keys)) {
317
+                    $key_string .= '['.implode('][', $keys).']';
318 318
                 }
319 319
                 return $this->request_parameter_drill_down(
320 320
                     $key_string,
321 321
                     $default,
322 322
                     $callback,
323
-                    $request_params[ $key ]
323
+                    $request_params[$key]
324 324
                 );
325 325
             }
326 326
         }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Invisible_Recaptcha_Input.input.php 2 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -19,160 +19,160 @@
 block discarded – undo
19 19
 class EE_Invisible_Recaptcha_Input extends EE_Form_Input_Base
20 20
 {
21 21
 
22
-    const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA   = 'google_invisible_recaptcha';
23
-
24
-    const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha';
25
-
26
-    /**
27
-     * @var EE_Registration_Config $config
28
-     */
29
-    private $config;
30
-
31
-    /**
32
-     * @var string $recaptcha_id
33
-     */
34
-    private $recaptcha_id;
35
-
36
-    /**
37
-     * @var string $submit_button_id
38
-     */
39
-    private $submit_button_id;
40
-
41
-
42
-    /**
43
-     * @param array                  $input_settings
44
-     * @param EE_Registration_Config $registration_config
45
-     * @throws InvalidArgumentException
46
-     * @throws InvalidDataTypeException
47
-     * @throws InvalidInterfaceException
48
-     */
49
-    public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null)
50
-    {
51
-        $this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy());
52
-        parent::__construct($input_settings);
53
-        $registration_config    = $registration_config instanceof EE_Registration_Config
54
-            ? $registration_config
55
-            : EE_Registry::instance()->CFG->registration;
56
-        $this->config           = $registration_config;
57
-        $this->recaptcha_id     = isset($input_settings['recaptcha_id'])
58
-            ? $input_settings['recaptcha_id']
59
-            : substr(spl_object_hash($this), 8, 8);
60
-        $this->submit_button_id = isset($input_settings['submit_button_id'])
61
-            ? $input_settings['submit_button_id']
62
-            : '';
63
-        $this->registerScripts();
64
-    }
65
-
66
-
67
-    /**
68
-     * @return bool
69
-     */
70
-    public function useCaptcha()
71
-    {
72
-        return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
73
-    }
74
-
75
-
76
-    /**
77
-     * @return string
78
-     */
79
-    public function language()
80
-    {
81
-        return $this->config->recaptcha_language;
82
-    }
83
-
84
-
85
-    /**
86
-     * @return string
87
-     */
88
-    public function siteKey()
89
-    {
90
-        return $this->config->recaptcha_publickey;
91
-    }
92
-
93
-
94
-    /**
95
-     * @return string
96
-     */
97
-    public function secretKey()
98
-    {
99
-        return $this->config->recaptcha_privatekey;
100
-    }
101
-
102
-
103
-    /**
104
-     * @return string
105
-     */
106
-    public function recaptchaId()
107
-    {
108
-        return $this->recaptcha_id;
109
-    }
110
-
111
-
112
-    /**
113
-     * @return void
114
-     */
115
-    public function registerScripts()
116
-    {
117
-        if (! $this->useCaptcha()) {
118
-            return;
119
-        }
120
-        add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2);
121
-        wp_register_script(
122
-            EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA,
123
-            EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js',
124
-            array('espresso_core'),
125
-            EVENT_ESPRESSO_VERSION,
126
-            true
127
-        );
128
-        wp_register_script(
129
-            EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA,
130
-            add_query_arg(
131
-                array(
132
-                    'onload' => 'espressoLoadRecaptcha',
133
-                    'render' => 'explicit',
134
-                    'hl'     => $this->language(),
135
-                ),
136
-                'https://www.google.com/recaptcha/api.js?'
137
-            ),
138
-            array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA),
139
-            false,
140
-            true
141
-        );
142
-        wp_localize_script(
143
-            EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA,
144
-            'eeRecaptcha',
145
-            array(
146
-                'siteKey'          => $this->siteKey(),
147
-                'submit_button_id' => $this->submit_button_id,
148
-                'wp_debug'         => WP_DEBUG,
149
-            )
150
-        );
151
-    }
152
-
153
-
154
-    /**
155
-     * @param string $tag
156
-     * @param string $handle
157
-     * @return string
158
-     */
159
-    public function addScriptAttributes($tag, $handle)
160
-    {
161
-        if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) {
162
-            $tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag);
163
-        }
164
-        return $tag;
165
-    }
166
-
167
-
168
-    /**
169
-     * Gets the HTML for displaying the label for this form input
170
-     * according to the form section's layout strategy
171
-     *
172
-     * @return string
173
-     */
174
-    public function get_html_for_label()
175
-    {
176
-        return '';
177
-    }
22
+	const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA   = 'google_invisible_recaptcha';
23
+
24
+	const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha';
25
+
26
+	/**
27
+	 * @var EE_Registration_Config $config
28
+	 */
29
+	private $config;
30
+
31
+	/**
32
+	 * @var string $recaptcha_id
33
+	 */
34
+	private $recaptcha_id;
35
+
36
+	/**
37
+	 * @var string $submit_button_id
38
+	 */
39
+	private $submit_button_id;
40
+
41
+
42
+	/**
43
+	 * @param array                  $input_settings
44
+	 * @param EE_Registration_Config $registration_config
45
+	 * @throws InvalidArgumentException
46
+	 * @throws InvalidDataTypeException
47
+	 * @throws InvalidInterfaceException
48
+	 */
49
+	public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null)
50
+	{
51
+		$this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy());
52
+		parent::__construct($input_settings);
53
+		$registration_config    = $registration_config instanceof EE_Registration_Config
54
+			? $registration_config
55
+			: EE_Registry::instance()->CFG->registration;
56
+		$this->config           = $registration_config;
57
+		$this->recaptcha_id     = isset($input_settings['recaptcha_id'])
58
+			? $input_settings['recaptcha_id']
59
+			: substr(spl_object_hash($this), 8, 8);
60
+		$this->submit_button_id = isset($input_settings['submit_button_id'])
61
+			? $input_settings['submit_button_id']
62
+			: '';
63
+		$this->registerScripts();
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return bool
69
+	 */
70
+	public function useCaptcha()
71
+	{
72
+		return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
73
+	}
74
+
75
+
76
+	/**
77
+	 * @return string
78
+	 */
79
+	public function language()
80
+	{
81
+		return $this->config->recaptcha_language;
82
+	}
83
+
84
+
85
+	/**
86
+	 * @return string
87
+	 */
88
+	public function siteKey()
89
+	{
90
+		return $this->config->recaptcha_publickey;
91
+	}
92
+
93
+
94
+	/**
95
+	 * @return string
96
+	 */
97
+	public function secretKey()
98
+	{
99
+		return $this->config->recaptcha_privatekey;
100
+	}
101
+
102
+
103
+	/**
104
+	 * @return string
105
+	 */
106
+	public function recaptchaId()
107
+	{
108
+		return $this->recaptcha_id;
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return void
114
+	 */
115
+	public function registerScripts()
116
+	{
117
+		if (! $this->useCaptcha()) {
118
+			return;
119
+		}
120
+		add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2);
121
+		wp_register_script(
122
+			EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA,
123
+			EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js',
124
+			array('espresso_core'),
125
+			EVENT_ESPRESSO_VERSION,
126
+			true
127
+		);
128
+		wp_register_script(
129
+			EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA,
130
+			add_query_arg(
131
+				array(
132
+					'onload' => 'espressoLoadRecaptcha',
133
+					'render' => 'explicit',
134
+					'hl'     => $this->language(),
135
+				),
136
+				'https://www.google.com/recaptcha/api.js?'
137
+			),
138
+			array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA),
139
+			false,
140
+			true
141
+		);
142
+		wp_localize_script(
143
+			EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA,
144
+			'eeRecaptcha',
145
+			array(
146
+				'siteKey'          => $this->siteKey(),
147
+				'submit_button_id' => $this->submit_button_id,
148
+				'wp_debug'         => WP_DEBUG,
149
+			)
150
+		);
151
+	}
152
+
153
+
154
+	/**
155
+	 * @param string $tag
156
+	 * @param string $handle
157
+	 * @return string
158
+	 */
159
+	public function addScriptAttributes($tag, $handle)
160
+	{
161
+		if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) {
162
+			$tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag);
163
+		}
164
+		return $tag;
165
+	}
166
+
167
+
168
+	/**
169
+	 * Gets the HTML for displaying the label for this form input
170
+	 * according to the form section's layout strategy
171
+	 *
172
+	 * @return string
173
+	 */
174
+	public function get_html_for_label()
175
+	{
176
+		return '';
177
+	}
178 178
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -114,13 +114,13 @@
 block discarded – undo
114 114
      */
115 115
     public function registerScripts()
116 116
     {
117
-        if (! $this->useCaptcha()) {
117
+        if ( ! $this->useCaptcha()) {
118 118
             return;
119 119
         }
120 120
         add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2);
121 121
         wp_register_script(
122 122
             EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA,
123
-            EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js',
123
+            EED_Recaptcha_Invisible::assetsUrl().'espresso_invisible_recaptcha.js',
124 124
             array('espresso_core'),
125 125
             EVENT_ESPRESSO_VERSION,
126 126
             true
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Base.form.php 2 patches
Indentation   +474 added lines, -474 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter;
5 5
 
6 6
 if (! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -21,485 +21,485 @@  discard block
 block discarded – undo
21 21
 abstract class EE_Form_Section_Base
22 22
 {
23 23
 
24
-    /**
25
-     * the URL the form is submitted to
26
-     *
27
-     * @var string
28
-     */
29
-    protected $_action;
30
-
31
-    /**
32
-     * POST (default) or GET
33
-     *
34
-     * @var string
35
-     */
36
-    protected $_method;
37
-
38
-    /**
39
-     * html_id and html_name are derived from this by default
40
-     *
41
-     * @var string
42
-     */
43
-    protected $_name;
44
-
45
-    /**
46
-     * $_html_id
47
-     * @var string
48
-     */
49
-    protected $_html_id;
50
-
51
-    /**
52
-     * $_html_class
53
-     * @var string
54
-     */
55
-    protected $_html_class;
56
-
57
-    /**
58
-     * $_html_style
59
-     * @var string
60
-     */
61
-    protected $_html_style;
62
-
63
-    /**
64
-     * $_other_html_attributes
65
-     * @var string
66
-     */
67
-    protected $_other_html_attributes;
68
-
69
-    /**
70
-     * The form section of which this form section is a part
71
-     *
72
-     * @var EE_Form_Section_Proper
73
-     */
74
-    protected $_parent_section;
75
-
76
-    /**
77
-     * flag indicating that _construct_finalize has been called.
78
-     * If it has not been called and we try to use functions which require it, we call it
79
-     * with no parameters. But normally, _construct_finalize should be called by the instantiating class
80
-     *
81
-     * @var boolean
82
-     */
83
-    protected $_construction_finalized;
84
-
85
-    /**
86
-     * Strategy for parsing the form HTML upon display
87
-     *
88
-     * @var FormHtmlFilter
89
-     */
90
-    protected $_form_html_filter;
91
-
92
-
93
-    /**
94
-     * @param array $options_array {
95
-     * @type        $name          string the name for this form section, if you want to explicitly define it
96
-     *                             }
97
-     * @throws InvalidDataTypeException
98
-     */
99
-    public function __construct($options_array = array())
100
-    {
101
-        // used by display strategies
102
-        // assign incoming values to properties
103
-        foreach ($options_array as $key => $value) {
104
-            $key = '_' . $key;
105
-            if (property_exists($this, $key) && empty($this->{$key})) {
106
-                $this->{$key} = $value;
107
-                if($key === '_subsections' && ! is_array($value)) {
108
-                    throw new InvalidDataTypeException($key, $value, 'array');
109
-                }
110
-            }
111
-        }
112
-        // set parser which allows the form section's rendered HTML to be filtered
113
-        if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
114
-            $this->_form_html_filter = $options_array['form_html_filter'];
115
-        }
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     * @param $parent_form_section
122
-     * @param $name
123
-     * @throws \EE_Error
124
-     */
125
-    protected function _construct_finalize($parent_form_section, $name)
126
-    {
127
-        $this->_construction_finalized = true;
128
-        $this->_parent_section = $parent_form_section;
129
-        if ($name !== null) {
130
-            $this->_name = $name;
131
-        }
132
-    }
133
-
134
-
135
-
136
-    /**
137
-     * make sure construction finalized was called, otherwise children might not be ready
138
-     *
139
-     * @return void
140
-     * @throws \EE_Error
141
-     */
142
-    public function ensure_construct_finalized_called()
143
-    {
144
-        if (! $this->_construction_finalized) {
145
-            $this->_construct_finalize($this->_parent_section, $this->_name);
146
-        }
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * @return string
153
-     */
154
-    public function action()
155
-    {
156
-        return $this->_action;
157
-    }
158
-
159
-
160
-
161
-    /**
162
-     * @param string $action
163
-     */
164
-    public function set_action($action)
165
-    {
166
-        $this->_action = $action;
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * @return string
173
-     */
174
-    public function method()
175
-    {
176
-        return ! empty($this->_method) ? $this->_method : 'POST';
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * @param string $method
183
-     */
184
-    public function set_method($method)
185
-    {
186
-        switch ($method) {
187
-            case 'get' :
188
-            case 'GET' :
189
-                $this->_method = 'GET';
190
-                break;
191
-            default :
192
-                $this->_method = 'POST';
193
-        }
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * Sets the html_id to its default value, if none was specified in the constructor.
200
-     * Calculation involves using the name and the parent's html id
201
-     * return void
202
-     *
203
-     * @throws \EE_Error
204
-     */
205
-    protected function _set_default_html_id_if_empty()
206
-    {
207
-        if (! $this->_html_id) {
208
-            if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
209
-                $this->_html_id = $this->_parent_section->html_id()
210
-                                  . '-'
211
-                                  . $this->_prep_name_for_html_id($this->name());
212
-            } else {
213
-                $this->_html_id = $this->_prep_name_for_html_id($this->name());
214
-            }
215
-        }
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     * _prep_name_for_html_id
222
-     *
223
-     * @param $name
224
-     * @return string
225
-     */
226
-    private function _prep_name_for_html_id($name)
227
-    {
228
-        return sanitize_key(str_replace(array('&nbsp;', ' ', '_'), '-', $name));
229
-    }
24
+	/**
25
+	 * the URL the form is submitted to
26
+	 *
27
+	 * @var string
28
+	 */
29
+	protected $_action;
30
+
31
+	/**
32
+	 * POST (default) or GET
33
+	 *
34
+	 * @var string
35
+	 */
36
+	protected $_method;
37
+
38
+	/**
39
+	 * html_id and html_name are derived from this by default
40
+	 *
41
+	 * @var string
42
+	 */
43
+	protected $_name;
44
+
45
+	/**
46
+	 * $_html_id
47
+	 * @var string
48
+	 */
49
+	protected $_html_id;
50
+
51
+	/**
52
+	 * $_html_class
53
+	 * @var string
54
+	 */
55
+	protected $_html_class;
56
+
57
+	/**
58
+	 * $_html_style
59
+	 * @var string
60
+	 */
61
+	protected $_html_style;
62
+
63
+	/**
64
+	 * $_other_html_attributes
65
+	 * @var string
66
+	 */
67
+	protected $_other_html_attributes;
68
+
69
+	/**
70
+	 * The form section of which this form section is a part
71
+	 *
72
+	 * @var EE_Form_Section_Proper
73
+	 */
74
+	protected $_parent_section;
75
+
76
+	/**
77
+	 * flag indicating that _construct_finalize has been called.
78
+	 * If it has not been called and we try to use functions which require it, we call it
79
+	 * with no parameters. But normally, _construct_finalize should be called by the instantiating class
80
+	 *
81
+	 * @var boolean
82
+	 */
83
+	protected $_construction_finalized;
84
+
85
+	/**
86
+	 * Strategy for parsing the form HTML upon display
87
+	 *
88
+	 * @var FormHtmlFilter
89
+	 */
90
+	protected $_form_html_filter;
91
+
92
+
93
+	/**
94
+	 * @param array $options_array {
95
+	 * @type        $name          string the name for this form section, if you want to explicitly define it
96
+	 *                             }
97
+	 * @throws InvalidDataTypeException
98
+	 */
99
+	public function __construct($options_array = array())
100
+	{
101
+		// used by display strategies
102
+		// assign incoming values to properties
103
+		foreach ($options_array as $key => $value) {
104
+			$key = '_' . $key;
105
+			if (property_exists($this, $key) && empty($this->{$key})) {
106
+				$this->{$key} = $value;
107
+				if($key === '_subsections' && ! is_array($value)) {
108
+					throw new InvalidDataTypeException($key, $value, 'array');
109
+				}
110
+			}
111
+		}
112
+		// set parser which allows the form section's rendered HTML to be filtered
113
+		if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
114
+			$this->_form_html_filter = $options_array['form_html_filter'];
115
+		}
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 * @param $parent_form_section
122
+	 * @param $name
123
+	 * @throws \EE_Error
124
+	 */
125
+	protected function _construct_finalize($parent_form_section, $name)
126
+	{
127
+		$this->_construction_finalized = true;
128
+		$this->_parent_section = $parent_form_section;
129
+		if ($name !== null) {
130
+			$this->_name = $name;
131
+		}
132
+	}
133
+
134
+
135
+
136
+	/**
137
+	 * make sure construction finalized was called, otherwise children might not be ready
138
+	 *
139
+	 * @return void
140
+	 * @throws \EE_Error
141
+	 */
142
+	public function ensure_construct_finalized_called()
143
+	{
144
+		if (! $this->_construction_finalized) {
145
+			$this->_construct_finalize($this->_parent_section, $this->_name);
146
+		}
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * @return string
153
+	 */
154
+	public function action()
155
+	{
156
+		return $this->_action;
157
+	}
158
+
159
+
160
+
161
+	/**
162
+	 * @param string $action
163
+	 */
164
+	public function set_action($action)
165
+	{
166
+		$this->_action = $action;
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * @return string
173
+	 */
174
+	public function method()
175
+	{
176
+		return ! empty($this->_method) ? $this->_method : 'POST';
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * @param string $method
183
+	 */
184
+	public function set_method($method)
185
+	{
186
+		switch ($method) {
187
+			case 'get' :
188
+			case 'GET' :
189
+				$this->_method = 'GET';
190
+				break;
191
+			default :
192
+				$this->_method = 'POST';
193
+		}
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * Sets the html_id to its default value, if none was specified in the constructor.
200
+	 * Calculation involves using the name and the parent's html id
201
+	 * return void
202
+	 *
203
+	 * @throws \EE_Error
204
+	 */
205
+	protected function _set_default_html_id_if_empty()
206
+	{
207
+		if (! $this->_html_id) {
208
+			if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
209
+				$this->_html_id = $this->_parent_section->html_id()
210
+								  . '-'
211
+								  . $this->_prep_name_for_html_id($this->name());
212
+			} else {
213
+				$this->_html_id = $this->_prep_name_for_html_id($this->name());
214
+			}
215
+		}
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 * _prep_name_for_html_id
222
+	 *
223
+	 * @param $name
224
+	 * @return string
225
+	 */
226
+	private function _prep_name_for_html_id($name)
227
+	{
228
+		return sanitize_key(str_replace(array('&nbsp;', ' ', '_'), '-', $name));
229
+	}
230 230
 
231 231
 
232 232
 
233
-    /**
234
-     * Returns the HTML, JS, and CSS necessary to display this form section on a page.
235
-     * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
236
-     * and call get_html when you want to output the html. Calling get_html_and_js after
237
-     * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
238
-     * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
239
-     * and so might stop working anytime.
240
-     *
241
-     * @return string
242
-     */
243
-    public function get_html_and_js()
244
-    {
245
-        return $this->get_html();
246
-    }
233
+	/**
234
+	 * Returns the HTML, JS, and CSS necessary to display this form section on a page.
235
+	 * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
236
+	 * and call get_html when you want to output the html. Calling get_html_and_js after
237
+	 * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
238
+	 * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
239
+	 * and so might stop working anytime.
240
+	 *
241
+	 * @return string
242
+	 */
243
+	public function get_html_and_js()
244
+	{
245
+		return $this->get_html();
246
+	}
247 247
 
248 248
 
249 249
 
250
-    /**
251
-     * Gets the HTML for displaying this form section
252
-     *
253
-     * @return string
254
-     */
255
-    abstract public function get_html();
256
-
257
-
258
-    /**
259
-     * @param bool $add_pound_sign
260
-     * @return string
261
-     * @throws EE_Error
262
-     */
263
-    public function html_id($add_pound_sign = false)
264
-    {
265
-        $this->_set_default_html_id_if_empty();
266
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * @return string
273
-     */
274
-    public function html_class()
275
-    {
276
-        return $this->_html_class;
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * @return string
283
-     */
284
-    public function html_style()
285
-    {
286
-        return $this->_html_style;
287
-    }
288
-
289
-
290
-
291
-    /**
292
-     * @param mixed $html_class
293
-     */
294
-    public function set_html_class($html_class)
295
-    {
296
-        $this->_html_class = $html_class;
297
-    }
298
-
299
-
300
-
301
-    /**
302
-     * @param mixed $html_id
303
-     */
304
-    public function set_html_id($html_id)
305
-    {
306
-        $this->_html_id = $html_id;
307
-    }
308
-
309
-
310
-
311
-    /**
312
-     * @param mixed $html_style
313
-     */
314
-    public function set_html_style($html_style)
315
-    {
316
-        $this->_html_style = $html_style;
317
-    }
318
-
319
-
320
-
321
-    /**
322
-     * @param string $other_html_attributes
323
-     */
324
-    public function set_other_html_attributes($other_html_attributes)
325
-    {
326
-        $this->_other_html_attributes = $other_html_attributes;
327
-    }
328
-
329
-
330
-
331
-    /**
332
-     * @return string
333
-     */
334
-    public function other_html_attributes()
335
-    {
336
-        return $this->_other_html_attributes;
337
-    }
338
-
339
-
340
-
341
-    /**
342
-     * Gets the name of the form section. This is not the same as the HTML name.
343
-     *
344
-     * @throws EE_Error
345
-     * @return string
346
-     */
347
-    public function name()
348
-    {
349
-        if (! $this->_construction_finalized) {
350
-            throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
351
-                'event_espresso'), get_class($this)));
352
-        }
353
-        return $this->_name;
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * Gets the parent section
360
-     *
361
-     * @return EE_Form_Section_Proper
362
-     */
363
-    public function parent_section()
364
-    {
365
-        return $this->_parent_section;
366
-    }
367
-
368
-
369
-    /**
370
-     * returns HTML for generating the opening form HTML tag (<form>)
371
-     *
372
-     * @param string $action           the URL the form is submitted to
373
-     * @param string $method           POST (default) or GET
374
-     * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
375
-     * @return string
376
-     * @throws EE_Error
377
-     */
378
-    public function form_open($action = '', $method = '', $other_attributes = '')
379
-    {
380
-        if (! empty($action)) {
381
-            $this->set_action($action);
382
-        }
383
-        if (! empty($method)) {
384
-            $this->set_method($method);
385
-        }
386
-        $html = EEH_HTML::nl(1, 'form') . '<form';
387
-        $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
388
-        $html .= ' action="' . $this->action() . '"';
389
-        $html .= ' method="' . $this->method() . '"';
390
-        $html .= ' name="' . $this->name() . '"';
391
-        $html .= $other_attributes . '>';
392
-        return $html;
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     * ensures that html id for form either ends in "-form" or "-frm"
399
-     * so that id doesn't conflict/collide with other elements
400
-     *
401
-     * @param string $html_id
402
-     * @return string
403
-     */
404
-    protected function get_html_id_for_form($html_id)
405
-    {
406
-        $strlen = strlen($html_id);
407
-        $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4
408
-            ? $html_id
409
-            : $html_id . '-frm';
410
-        return $html_id;
411
-    }
412
-
413
-
414
-    /**
415
-     * returns HTML for generating the closing form HTML tag (</form>)
416
-     *
417
-     * @return string
418
-     * @throws EE_Error
419
-     */
420
-    public function form_close()
421
-    {
422
-        return EEH_HTML::nl(-1, 'form')
423
-               . '</form>'
424
-               . EEH_HTML::nl()
425
-               . '<!-- end of ee-'
426
-               . $this->html_id()
427
-               . '-form -->'
428
-               . EEH_HTML::nl();
429
-    }
430
-
431
-
432
-
433
-    /**
434
-     * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
435
-     * wp_enqueue_style; the scripts could have optionally been registered earlier)
436
-     * Default does nothing, but child classes can override
437
-     *
438
-     * @return void
439
-     */
440
-    public function enqueue_js()
441
-    {
442
-        //defaults to enqueue NO js or css
443
-    }
444
-
445
-
446
-
447
-    /**
448
-     * Adds any extra data needed by js. Eventually we'll call wp_localize_script
449
-     * with it, and it will be on each form section's 'other_data' property.
450
-     * By default nothing is added, but child classes can extend this method to add something.
451
-     * Eg, if you have an input that will cause a modal dialog to appear,
452
-     * here you could add an entry like 'modal_dialog_inputs' to this array
453
-     * to map between the input's html ID and the modal dialogue's ID, so that
454
-     * your JS code will know where to find the modal dialog when the input is pressed.
455
-     * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
456
-     *
457
-     * @param array $form_other_js_data
458
-     * @return array
459
-     */
460
-    public function get_other_js_data($form_other_js_data = array())
461
-    {
462
-        return $form_other_js_data;
463
-    }
464
-
465
-
466
-
467
-    /**
468
-     * This isn't just the name of an input, it's a path pointing to an input. The
469
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
470
-     * dot-dot-slash (../) means to ascend into the parent section.
471
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
472
-     * which will be returned.
473
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
474
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
475
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
476
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
477
-     * Etc
478
-     *
479
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
480
-     * @return EE_Form_Section_Base
481
-     */
482
-    public function find_section_from_path($form_section_path)
483
-    {
484
-        if (strpos($form_section_path, '/') === 0) {
485
-            $form_section_path = substr($form_section_path, strlen('/'));
486
-        }
487
-        if (empty($form_section_path)) {
488
-            return $this;
489
-        }
490
-        if (strpos($form_section_path, '../') === 0) {
491
-            $parent = $this->parent_section();
492
-            $form_section_path = substr($form_section_path, strlen('../'));
493
-            if ($parent instanceof EE_Form_Section_Base) {
494
-                return $parent->find_section_from_path($form_section_path);
495
-            }
496
-            if (empty($form_section_path)) {
497
-                return $this;
498
-            }
499
-        }
500
-        //couldn't find it using simple parent following
501
-        return null;
502
-    }
250
+	/**
251
+	 * Gets the HTML for displaying this form section
252
+	 *
253
+	 * @return string
254
+	 */
255
+	abstract public function get_html();
256
+
257
+
258
+	/**
259
+	 * @param bool $add_pound_sign
260
+	 * @return string
261
+	 * @throws EE_Error
262
+	 */
263
+	public function html_id($add_pound_sign = false)
264
+	{
265
+		$this->_set_default_html_id_if_empty();
266
+		return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * @return string
273
+	 */
274
+	public function html_class()
275
+	{
276
+		return $this->_html_class;
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * @return string
283
+	 */
284
+	public function html_style()
285
+	{
286
+		return $this->_html_style;
287
+	}
288
+
289
+
290
+
291
+	/**
292
+	 * @param mixed $html_class
293
+	 */
294
+	public function set_html_class($html_class)
295
+	{
296
+		$this->_html_class = $html_class;
297
+	}
298
+
299
+
300
+
301
+	/**
302
+	 * @param mixed $html_id
303
+	 */
304
+	public function set_html_id($html_id)
305
+	{
306
+		$this->_html_id = $html_id;
307
+	}
308
+
309
+
310
+
311
+	/**
312
+	 * @param mixed $html_style
313
+	 */
314
+	public function set_html_style($html_style)
315
+	{
316
+		$this->_html_style = $html_style;
317
+	}
318
+
319
+
320
+
321
+	/**
322
+	 * @param string $other_html_attributes
323
+	 */
324
+	public function set_other_html_attributes($other_html_attributes)
325
+	{
326
+		$this->_other_html_attributes = $other_html_attributes;
327
+	}
328
+
329
+
330
+
331
+	/**
332
+	 * @return string
333
+	 */
334
+	public function other_html_attributes()
335
+	{
336
+		return $this->_other_html_attributes;
337
+	}
338
+
339
+
340
+
341
+	/**
342
+	 * Gets the name of the form section. This is not the same as the HTML name.
343
+	 *
344
+	 * @throws EE_Error
345
+	 * @return string
346
+	 */
347
+	public function name()
348
+	{
349
+		if (! $this->_construction_finalized) {
350
+			throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
351
+				'event_espresso'), get_class($this)));
352
+		}
353
+		return $this->_name;
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * Gets the parent section
360
+	 *
361
+	 * @return EE_Form_Section_Proper
362
+	 */
363
+	public function parent_section()
364
+	{
365
+		return $this->_parent_section;
366
+	}
367
+
368
+
369
+	/**
370
+	 * returns HTML for generating the opening form HTML tag (<form>)
371
+	 *
372
+	 * @param string $action           the URL the form is submitted to
373
+	 * @param string $method           POST (default) or GET
374
+	 * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
375
+	 * @return string
376
+	 * @throws EE_Error
377
+	 */
378
+	public function form_open($action = '', $method = '', $other_attributes = '')
379
+	{
380
+		if (! empty($action)) {
381
+			$this->set_action($action);
382
+		}
383
+		if (! empty($method)) {
384
+			$this->set_method($method);
385
+		}
386
+		$html = EEH_HTML::nl(1, 'form') . '<form';
387
+		$html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
388
+		$html .= ' action="' . $this->action() . '"';
389
+		$html .= ' method="' . $this->method() . '"';
390
+		$html .= ' name="' . $this->name() . '"';
391
+		$html .= $other_attributes . '>';
392
+		return $html;
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 * ensures that html id for form either ends in "-form" or "-frm"
399
+	 * so that id doesn't conflict/collide with other elements
400
+	 *
401
+	 * @param string $html_id
402
+	 * @return string
403
+	 */
404
+	protected function get_html_id_for_form($html_id)
405
+	{
406
+		$strlen = strlen($html_id);
407
+		$html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4
408
+			? $html_id
409
+			: $html_id . '-frm';
410
+		return $html_id;
411
+	}
412
+
413
+
414
+	/**
415
+	 * returns HTML for generating the closing form HTML tag (</form>)
416
+	 *
417
+	 * @return string
418
+	 * @throws EE_Error
419
+	 */
420
+	public function form_close()
421
+	{
422
+		return EEH_HTML::nl(-1, 'form')
423
+			   . '</form>'
424
+			   . EEH_HTML::nl()
425
+			   . '<!-- end of ee-'
426
+			   . $this->html_id()
427
+			   . '-form -->'
428
+			   . EEH_HTML::nl();
429
+	}
430
+
431
+
432
+
433
+	/**
434
+	 * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
435
+	 * wp_enqueue_style; the scripts could have optionally been registered earlier)
436
+	 * Default does nothing, but child classes can override
437
+	 *
438
+	 * @return void
439
+	 */
440
+	public function enqueue_js()
441
+	{
442
+		//defaults to enqueue NO js or css
443
+	}
444
+
445
+
446
+
447
+	/**
448
+	 * Adds any extra data needed by js. Eventually we'll call wp_localize_script
449
+	 * with it, and it will be on each form section's 'other_data' property.
450
+	 * By default nothing is added, but child classes can extend this method to add something.
451
+	 * Eg, if you have an input that will cause a modal dialog to appear,
452
+	 * here you could add an entry like 'modal_dialog_inputs' to this array
453
+	 * to map between the input's html ID and the modal dialogue's ID, so that
454
+	 * your JS code will know where to find the modal dialog when the input is pressed.
455
+	 * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
456
+	 *
457
+	 * @param array $form_other_js_data
458
+	 * @return array
459
+	 */
460
+	public function get_other_js_data($form_other_js_data = array())
461
+	{
462
+		return $form_other_js_data;
463
+	}
464
+
465
+
466
+
467
+	/**
468
+	 * This isn't just the name of an input, it's a path pointing to an input. The
469
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
470
+	 * dot-dot-slash (../) means to ascend into the parent section.
471
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
472
+	 * which will be returned.
473
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
474
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
475
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
476
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
477
+	 * Etc
478
+	 *
479
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
480
+	 * @return EE_Form_Section_Base
481
+	 */
482
+	public function find_section_from_path($form_section_path)
483
+	{
484
+		if (strpos($form_section_path, '/') === 0) {
485
+			$form_section_path = substr($form_section_path, strlen('/'));
486
+		}
487
+		if (empty($form_section_path)) {
488
+			return $this;
489
+		}
490
+		if (strpos($form_section_path, '../') === 0) {
491
+			$parent = $this->parent_section();
492
+			$form_section_path = substr($form_section_path, strlen('../'));
493
+			if ($parent instanceof EE_Form_Section_Base) {
494
+				return $parent->find_section_from_path($form_section_path);
495
+			}
496
+			if (empty($form_section_path)) {
497
+				return $this;
498
+			}
499
+		}
500
+		//couldn't find it using simple parent following
501
+		return null;
502
+	}
503 503
 
504 504
 
505 505
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\exceptions\InvalidDataTypeException;
4 4
 use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter;
5 5
 
6
-if (! defined('EVENT_ESPRESSO_VERSION')) {
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7 7
     exit('No direct script access allowed');
8 8
 }
9 9
 
@@ -101,10 +101,10 @@  discard block
 block discarded – undo
101 101
         // used by display strategies
102 102
         // assign incoming values to properties
103 103
         foreach ($options_array as $key => $value) {
104
-            $key = '_' . $key;
104
+            $key = '_'.$key;
105 105
             if (property_exists($this, $key) && empty($this->{$key})) {
106 106
                 $this->{$key} = $value;
107
-                if($key === '_subsections' && ! is_array($value)) {
107
+                if ($key === '_subsections' && ! is_array($value)) {
108 108
                     throw new InvalidDataTypeException($key, $value, 'array');
109 109
                 }
110 110
             }
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function ensure_construct_finalized_called()
143 143
     {
144
-        if (! $this->_construction_finalized) {
144
+        if ( ! $this->_construction_finalized) {
145 145
             $this->_construct_finalize($this->_parent_section, $this->_name);
146 146
         }
147 147
     }
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
      */
205 205
     protected function _set_default_html_id_if_empty()
206 206
     {
207
-        if (! $this->_html_id) {
207
+        if ( ! $this->_html_id) {
208 208
             if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
209 209
                 $this->_html_id = $this->_parent_section->html_id()
210 210
                                   . '-'
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
     public function html_id($add_pound_sign = false)
264 264
     {
265 265
         $this->_set_default_html_id_if_empty();
266
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
266
+        return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id;
267 267
     }
268 268
 
269 269
 
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
      */
347 347
     public function name()
348 348
     {
349
-        if (! $this->_construction_finalized) {
349
+        if ( ! $this->_construction_finalized) {
350 350
             throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
351 351
                 'event_espresso'), get_class($this)));
352 352
         }
@@ -377,18 +377,18 @@  discard block
 block discarded – undo
377 377
      */
378 378
     public function form_open($action = '', $method = '', $other_attributes = '')
379 379
     {
380
-        if (! empty($action)) {
380
+        if ( ! empty($action)) {
381 381
             $this->set_action($action);
382 382
         }
383
-        if (! empty($method)) {
383
+        if ( ! empty($method)) {
384 384
             $this->set_method($method);
385 385
         }
386
-        $html = EEH_HTML::nl(1, 'form') . '<form';
387
-        $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
388
-        $html .= ' action="' . $this->action() . '"';
389
-        $html .= ' method="' . $this->method() . '"';
390
-        $html .= ' name="' . $this->name() . '"';
391
-        $html .= $other_attributes . '>';
386
+        $html = EEH_HTML::nl(1, 'form').'<form';
387
+        $html .= $this->html_id() !== '' ? ' id="'.$this->get_html_id_for_form($this->html_id()).'"' : '';
388
+        $html .= ' action="'.$this->action().'"';
389
+        $html .= ' method="'.$this->method().'"';
390
+        $html .= ' name="'.$this->name().'"';
391
+        $html .= $other_attributes.'>';
392 392
         return $html;
393 393
     }
394 394
 
@@ -404,9 +404,9 @@  discard block
 block discarded – undo
404 404
     protected function get_html_id_for_form($html_id)
405 405
     {
406 406
         $strlen = strlen($html_id);
407
-        $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4
407
+        $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4
408 408
             ? $html_id
409
-            : $html_id . '-frm';
409
+            : $html_id.'-frm';
410 410
         return $html_id;
411 411
     }
412 412
 
Please login to merge, or discard this patch.
core/EE_Module_Request_Router.core.php 1 patch
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -17,256 +17,256 @@
 block discarded – undo
17 17
 final class EE_Module_Request_Router implements InterminableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @var EE_Request $request
22
-     */
23
-    private $request;
20
+	/**
21
+	 * @var EE_Request $request
22
+	 */
23
+	private $request;
24 24
 
25
-    /**
26
-     * @var array $_previous_routes
27
-     */
28
-    private static $_previous_routes = array();
25
+	/**
26
+	 * @var array $_previous_routes
27
+	 */
28
+	private static $_previous_routes = array();
29 29
 
30
-    /**
31
-     * @var WP_Query $WP_Query
32
-     */
33
-    public $WP_Query;
30
+	/**
31
+	 * @var WP_Query $WP_Query
32
+	 */
33
+	public $WP_Query;
34 34
 
35 35
 
36 36
 
37
-    /**
38
-     * EE_Module_Request_Router constructor.
39
-     *
40
-     * @param EE_Request $request
41
-     */
42
-    public function __construct(EE_Request $request)
43
-    {
44
-        $this->request = $request;
45
-    }
37
+	/**
38
+	 * EE_Module_Request_Router constructor.
39
+	 *
40
+	 * @param EE_Request $request
41
+	 */
42
+	public function __construct(EE_Request $request)
43
+	{
44
+		$this->request = $request;
45
+	}
46 46
 
47 47
 
48 48
 
49
-    /**
50
-     * on the first call  to this method, it checks the EE_Request_Handler for a "route"
51
-     * on subsequent calls to this method,
52
-     * instead of checking the EE_Request_Handler for a route, it checks the previous routes array,
53
-     * and checks if the last called route has any forwarding routes registered for it
54
-     *
55
-     * @param WP_Query $WP_Query
56
-     * @return NULL|string
57
-     * @throws EE_Error
58
-     * @throws ReflectionException
59
-     */
60
-    public function get_route(WP_Query $WP_Query)
61
-    {
62
-        $this->WP_Query = $WP_Query;
63
-        // assume this if first route being called
64
-        $previous_route = false;
65
-        // but is it really ???
66
-        if (! empty(self::$_previous_routes)) {
67
-            // get last run route
68
-            $previous_routes = array_values(self::$_previous_routes);
69
-            $previous_route = array_pop($previous_routes);
70
-        }
71
-        //  has another route already been run ?
72
-        if ($previous_route) {
73
-            // check if  forwarding has been set
74
-            $current_route = $this->get_forward($previous_route);
75
-            try {
76
-                //check for recursive forwarding
77
-                if (isset(self::$_previous_routes[$current_route])) {
78
-                    throw new EE_Error(
79
-                        sprintf(
80
-                            __(
81
-                                'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.',
82
-                                'event_espresso'
83
-                            ),
84
-                            $current_route
85
-                        )
86
-                    );
87
-                }
88
-            } catch (EE_Error $e) {
89
-                $e->get_error();
90
-                return null;
91
-            }
92
-        } else {
93
-            // first route called
94
-            $current_route = null;
95
-            // grab all routes
96
-            $routes = EE_Config::get_routes();
97
-            foreach ($routes as $key => $route) {
98
-                // first determine if route key uses w?ldc*rds
99
-                $uses_wildcards = strpos($key, '?') !== false
100
-                                  || strpos($key, '*') !== false;
101
-                // check request for module route
102
-                $route_found = $uses_wildcards
103
-                    ? $this->request->matches($key)
104
-                    : $this->request->is_set($key);
105
-                if ($route_found) {
106
-                    $current_route = $uses_wildcards
107
-                        ? $this->request->getMatch($key)
108
-                        : $this->request->get($key);
109
-                    $current_route = sanitize_text_field($current_route);
110
-                    if ($current_route) {
111
-                        $current_route = array($key, $current_route);
112
-                        break;
113
-                    }
114
-                }
115
-            }
116
-        }
117
-        // sorry, but I can't read what you route !
118
-        if (empty($current_route)) {
119
-            return null;
120
-        }
121
-        //add route to previous routes array
122
-        self::$_previous_routes[] = $current_route;
123
-        return $current_route;
124
-    }
49
+	/**
50
+	 * on the first call  to this method, it checks the EE_Request_Handler for a "route"
51
+	 * on subsequent calls to this method,
52
+	 * instead of checking the EE_Request_Handler for a route, it checks the previous routes array,
53
+	 * and checks if the last called route has any forwarding routes registered for it
54
+	 *
55
+	 * @param WP_Query $WP_Query
56
+	 * @return NULL|string
57
+	 * @throws EE_Error
58
+	 * @throws ReflectionException
59
+	 */
60
+	public function get_route(WP_Query $WP_Query)
61
+	{
62
+		$this->WP_Query = $WP_Query;
63
+		// assume this if first route being called
64
+		$previous_route = false;
65
+		// but is it really ???
66
+		if (! empty(self::$_previous_routes)) {
67
+			// get last run route
68
+			$previous_routes = array_values(self::$_previous_routes);
69
+			$previous_route = array_pop($previous_routes);
70
+		}
71
+		//  has another route already been run ?
72
+		if ($previous_route) {
73
+			// check if  forwarding has been set
74
+			$current_route = $this->get_forward($previous_route);
75
+			try {
76
+				//check for recursive forwarding
77
+				if (isset(self::$_previous_routes[$current_route])) {
78
+					throw new EE_Error(
79
+						sprintf(
80
+							__(
81
+								'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.',
82
+								'event_espresso'
83
+							),
84
+							$current_route
85
+						)
86
+					);
87
+				}
88
+			} catch (EE_Error $e) {
89
+				$e->get_error();
90
+				return null;
91
+			}
92
+		} else {
93
+			// first route called
94
+			$current_route = null;
95
+			// grab all routes
96
+			$routes = EE_Config::get_routes();
97
+			foreach ($routes as $key => $route) {
98
+				// first determine if route key uses w?ldc*rds
99
+				$uses_wildcards = strpos($key, '?') !== false
100
+								  || strpos($key, '*') !== false;
101
+				// check request for module route
102
+				$route_found = $uses_wildcards
103
+					? $this->request->matches($key)
104
+					: $this->request->is_set($key);
105
+				if ($route_found) {
106
+					$current_route = $uses_wildcards
107
+						? $this->request->getMatch($key)
108
+						: $this->request->get($key);
109
+					$current_route = sanitize_text_field($current_route);
110
+					if ($current_route) {
111
+						$current_route = array($key, $current_route);
112
+						break;
113
+					}
114
+				}
115
+			}
116
+		}
117
+		// sorry, but I can't read what you route !
118
+		if (empty($current_route)) {
119
+			return null;
120
+		}
121
+		//add route to previous routes array
122
+		self::$_previous_routes[] = $current_route;
123
+		return $current_route;
124
+	}
125 125
 
126 126
 
127 127
 
128
-    /**
129
-     * this method simply takes a valid route, and resolves what module class method the route points to
130
-     *
131
-     * @param string $key
132
-     * @param string $current_route
133
-     * @return mixed EED_Module | boolean
134
-     * @throws EE_Error
135
-     * @throws ReflectionException
136
-     */
137
-    public function resolve_route($key, $current_route)
138
-    {
139
-        // get module method that route has been mapped to
140
-        $module_method = EE_Config::get_route($current_route, $key);
141
-        // verify result was returned
142
-        if (empty($module_method)) {
143
-            $msg = sprintf(
144
-                __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'),
145
-                $current_route
146
-            );
147
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
148
-            return false;
149
-        }
150
-        // verify that result is an array
151
-        if (! is_array($module_method)) {
152
-            $msg = sprintf(__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
153
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
154
-            return false;
155
-        }
156
-        // grab module name
157
-        $module_name = $module_method[0];
158
-        // verify that a class method was registered properly
159
-        if (! isset($module_method[1])) {
160
-            $msg = sprintf(
161
-                __('A class method for the %s  route has not been properly registered.', 'event_espresso'),
162
-                $current_route
163
-            );
164
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
165
-            return false;
166
-        }
167
-        // grab method
168
-        $method = $module_method[1];
169
-        // verify that class exists
170
-        if (! class_exists($module_name)) {
171
-            $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name);
172
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
173
-            return false;
174
-        }
175
-        // verify that method exists
176
-        if (! method_exists($module_name, $method)) {
177
-            $msg = sprintf(
178
-                __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route
179
-            );
180
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
181
-            return false;
182
-        }
183
-        // instantiate module and call route method
184
-        return $this->_module_router($module_name, $method);
185
-    }
128
+	/**
129
+	 * this method simply takes a valid route, and resolves what module class method the route points to
130
+	 *
131
+	 * @param string $key
132
+	 * @param string $current_route
133
+	 * @return mixed EED_Module | boolean
134
+	 * @throws EE_Error
135
+	 * @throws ReflectionException
136
+	 */
137
+	public function resolve_route($key, $current_route)
138
+	{
139
+		// get module method that route has been mapped to
140
+		$module_method = EE_Config::get_route($current_route, $key);
141
+		// verify result was returned
142
+		if (empty($module_method)) {
143
+			$msg = sprintf(
144
+				__('The requested route %s could not be mapped to any registered modules.', 'event_espresso'),
145
+				$current_route
146
+			);
147
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
148
+			return false;
149
+		}
150
+		// verify that result is an array
151
+		if (! is_array($module_method)) {
152
+			$msg = sprintf(__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
153
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
154
+			return false;
155
+		}
156
+		// grab module name
157
+		$module_name = $module_method[0];
158
+		// verify that a class method was registered properly
159
+		if (! isset($module_method[1])) {
160
+			$msg = sprintf(
161
+				__('A class method for the %s  route has not been properly registered.', 'event_espresso'),
162
+				$current_route
163
+			);
164
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
165
+			return false;
166
+		}
167
+		// grab method
168
+		$method = $module_method[1];
169
+		// verify that class exists
170
+		if (! class_exists($module_name)) {
171
+			$msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name);
172
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
173
+			return false;
174
+		}
175
+		// verify that method exists
176
+		if (! method_exists($module_name, $method)) {
177
+			$msg = sprintf(
178
+				__('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route
179
+			);
180
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
181
+			return false;
182
+		}
183
+		// instantiate module and call route method
184
+		return $this->_module_router($module_name, $method);
185
+	}
186 186
 
187 187
 
188 188
 
189
-    /**
190
-     * this method instantiates modules and calls the method that was defined when the route was registered
191
-     *
192
-     * @param string $module_name
193
-     * @return EED_Module|object|null
194
-     * @throws ReflectionException
195
-     */
196
-    public static function module_factory($module_name)
197
-    {
198
-        if ($module_name === 'EED_Module') {
199
-            EE_Error::add_error(
200
-                sprintf(
201
-                    __(
202
-                        'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.',
203
-                        'event_espresso'
204
-                    ), $module_name
205
-                ), __FILE__, __FUNCTION__, __LINE__
206
-            );
207
-            return null;
208
-        }
209
-        // instantiate module class
210
-        $module = new $module_name();
211
-        // ensure that class is actually a module
212
-        if (! $module instanceof EED_Module) {
213
-            EE_Error::add_error(
214
-                sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
215
-                __FILE__, __FUNCTION__, __LINE__
216
-            );
217
-            return null;
218
-        }
219
-        return $module;
220
-    }
189
+	/**
190
+	 * this method instantiates modules and calls the method that was defined when the route was registered
191
+	 *
192
+	 * @param string $module_name
193
+	 * @return EED_Module|object|null
194
+	 * @throws ReflectionException
195
+	 */
196
+	public static function module_factory($module_name)
197
+	{
198
+		if ($module_name === 'EED_Module') {
199
+			EE_Error::add_error(
200
+				sprintf(
201
+					__(
202
+						'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.',
203
+						'event_espresso'
204
+					), $module_name
205
+				), __FILE__, __FUNCTION__, __LINE__
206
+			);
207
+			return null;
208
+		}
209
+		// instantiate module class
210
+		$module = new $module_name();
211
+		// ensure that class is actually a module
212
+		if (! $module instanceof EED_Module) {
213
+			EE_Error::add_error(
214
+				sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
215
+				__FILE__, __FUNCTION__, __LINE__
216
+			);
217
+			return null;
218
+		}
219
+		return $module;
220
+	}
221 221
 
222 222
 
223 223
 
224
-    /**
225
-     * this method instantiates modules and calls the method that was defined when the route was registered
226
-     *
227
-     * @param string $module_name
228
-     * @param string $method
229
-     * @return EED_Module|null
230
-     * @throws EE_Error
231
-     * @throws ReflectionException
232
-     */
233
-    private function _module_router($module_name, $method)
234
-    {
235
-        // instantiate module class
236
-        $module = EE_Module_Request_Router::module_factory($module_name);
237
-        if ($module instanceof EED_Module) {
238
-            // and call whatever action the route was for
239
-            try {
240
-                call_user_func(array($module, $method), $this->WP_Query);
241
-            } catch (EE_Error $e) {
242
-                $e->get_error();
243
-                return null;
244
-            }
245
-        }
246
-        return $module;
247
-    }
224
+	/**
225
+	 * this method instantiates modules and calls the method that was defined when the route was registered
226
+	 *
227
+	 * @param string $module_name
228
+	 * @param string $method
229
+	 * @return EED_Module|null
230
+	 * @throws EE_Error
231
+	 * @throws ReflectionException
232
+	 */
233
+	private function _module_router($module_name, $method)
234
+	{
235
+		// instantiate module class
236
+		$module = EE_Module_Request_Router::module_factory($module_name);
237
+		if ($module instanceof EED_Module) {
238
+			// and call whatever action the route was for
239
+			try {
240
+				call_user_func(array($module, $method), $this->WP_Query);
241
+			} catch (EE_Error $e) {
242
+				$e->get_error();
243
+				return null;
244
+			}
245
+		}
246
+		return $module;
247
+	}
248 248
 
249 249
 
250 250
 
251
-    /**
252
-     * @param $current_route
253
-     * @return string
254
-     */
255
-    public function get_forward($current_route)
256
-    {
257
-        return EE_Config::get_forward($current_route);
258
-    }
251
+	/**
252
+	 * @param $current_route
253
+	 * @return string
254
+	 */
255
+	public function get_forward($current_route)
256
+	{
257
+		return EE_Config::get_forward($current_route);
258
+	}
259 259
 
260 260
 
261 261
 
262
-    /**
263
-     * @param $current_route
264
-     * @return string
265
-     */
266
-    public function get_view($current_route)
267
-    {
268
-        return EE_Config::get_view($current_route);
269
-    }
262
+	/**
263
+	 * @param $current_route
264
+	 * @return string
265
+	 */
266
+	public function get_view($current_route)
267
+	{
268
+		return EE_Config::get_view($current_route);
269
+	}
270 270
 
271 271
 
272 272
 }
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha_invisible/EED_Recaptcha_Invisible.module.php 2 patches
Indentation   +301 added lines, -301 removed lines patch added patch discarded remove patch
@@ -22,305 +22,305 @@
 block discarded – undo
22 22
 class EED_Recaptcha_Invisible extends EED_Module
23 23
 {
24 24
 
25
-    /**
26
-     * @var EE_Registration_Config $config
27
-     */
28
-    private static $config;
29
-
30
-
31
-    /**
32
-     * @return EED_Module|EED_Recaptcha
33
-     */
34
-    public static function instance()
35
-    {
36
-        return parent::get_instance(__CLASS__);
37
-    }
38
-
39
-
40
-    /**
41
-     * @return void
42
-     * @throws InvalidInterfaceException
43
-     * @throws InvalidDataTypeException
44
-     * @throws InvalidArgumentException
45
-     */
46
-    public static function set_hooks()
47
-    {
48
-        EED_Recaptcha_Invisible::setProperties();
49
-        if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) {
50
-            // ticket selection
51
-            add_filter(
52
-                'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
53
-                array('EED_Recaptcha_Invisible', 'ticketSelectorForm'),
54
-                10, 2
55
-            );
56
-            add_action(
57
-                'EED_Ticket_Selector__process_ticket_selections__before',
58
-                array('EED_Recaptcha_Invisible', 'processTicketSelectorForm')
59
-            );
60
-            // checkout
61
-            add_action(
62
-                'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form',
63
-                array('EED_Recaptcha_Invisible', 'spcoRegStepForm')
64
-            );
65
-            add_filter(
66
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
67
-                array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'),
68
-                10, 2
69
-            );
70
-        }
71
-    }
72
-
73
-
74
-    /**
75
-     * @return void
76
-     * @throws InvalidInterfaceException
77
-     * @throws InvalidDataTypeException
78
-     * @throws InvalidArgumentException
79
-     */
80
-    public static function set_hooks_admin()
81
-    {
82
-        // admin settings
83
-        add_action(
84
-            'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
85
-            array('EED_Recaptcha_Invisible', 'adminSettings')
86
-        );
87
-        add_filter(
88
-            'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
89
-            array('EED_Recaptcha_Invisible', 'updateAdminSettings')
90
-        );
91
-    }
92
-
93
-
94
-    /**
95
-     * @return void
96
-     * @throws InvalidInterfaceException
97
-     * @throws InvalidDataTypeException
98
-     * @throws InvalidArgumentException
99
-     */
100
-    public static function setProperties()
101
-    {
102
-        EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration;
103
-    }
104
-
105
-
106
-    /**
107
-     * @return boolean
108
-     */
109
-    public static function useInvisibleRecaptcha()
110
-    {
111
-        return EED_Recaptcha_Invisible::$config->use_captcha
112
-               && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible';
113
-    }
114
-
115
-
116
-    /**
117
-     * @return string
118
-     */
119
-    public static function assetsUrl()
120
-    {
121
-        return plugin_dir_url(__FILE__) . 'assets' . DS;
122
-    }
123
-
124
-
125
-    /**
126
-     * @param \WP $WP
127
-     */
128
-    public function run($WP)
129
-    {
130
-    }
131
-
132
-
133
-    /**
134
-     * @return boolean
135
-     * @throws InvalidInterfaceException
136
-     * @throws InvalidDataTypeException
137
-     * @throws InvalidArgumentException
138
-     */
139
-    public static function recaptchaPassed()
140
-    {
141
-        // logged in means you have already passed a turing test of sorts
142
-        if (EED_Recaptcha_Invisible::useInvisibleRecaptcha() === false || is_user_logged_in()) {
143
-            return true;
144
-        }
145
-        // was test already passed?
146
-        return filter_var(
147
-            EE_Registry::instance()->SSN->get_session_data(
148
-                InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
149
-            ),
150
-            FILTER_VALIDATE_BOOLEAN
151
-        );
152
-    }
153
-
154
-
155
-    /**
156
-     * @param EE_Request $request
157
-     * @return bool
158
-     * @throws InvalidArgumentException
159
-     * @throws InvalidDataTypeException
160
-     * @throws InvalidInterfaceException
161
-     * @throws RuntimeException
162
-     */
163
-    public static function verifyToken(EE_Request $request)
164
-    {
165
-        $invisible_recaptcha = RecaptchaFactory::create();
166
-        if ($invisible_recaptcha->verifyToken($request)) {
167
-            add_action('shutdown', array('EED_Recaptcha_Invisible', 'setSessionData'));
168
-            return true;
169
-        }
170
-        return false;
171
-    }
172
-
173
-
174
-    /**
175
-     * @param EE_Form_Section_Proper $reg_form
176
-     * @return void
177
-     * @throws EE_Error
178
-     * @throws InvalidArgumentException
179
-     * @throws InvalidDataTypeException
180
-     * @throws InvalidInterfaceException
181
-     */
182
-    public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form)
183
-    {
184
-        // do nothing if form isn't for a reg step or test has already been passed
185
-        if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) {
186
-            return;
187
-        }
188
-        $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs');
189
-        if ($default_hidden_inputs instanceof EE_Form_Section_Proper) {
190
-            $invisible_recaptcha = RecaptchaFactory::create();
191
-            $invisible_recaptcha->addToFormSection($default_hidden_inputs);
192
-        }
193
-    }
194
-
195
-
196
-    /**
197
-     * @param EE_Form_Section_Proper $reg_form
198
-     * @return bool
199
-     * @throws InvalidDataTypeException
200
-     * @throws InvalidInterfaceException
201
-     * @throws EE_Error
202
-     * @throws InvalidArgumentException
203
-     */
204
-    public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form)
205
-    {
206
-        return strpos($reg_form->name(), 'reg-step-form') === false || EED_Recaptcha_Invisible::recaptchaPassed();
207
-    }
208
-
209
-
210
-    /**
211
-     * @param array|null             $req_data
212
-     * @param EE_Form_Section_Proper $reg_form
213
-     * @return array
214
-     * @throws EE_Error
215
-     * @throws InvalidArgumentException
216
-     * @throws InvalidDataTypeException
217
-     * @throws InvalidInterfaceException
218
-     * @throws RuntimeException
219
-     */
220
-    public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form)
221
-    {
222
-        // do nothing if form isn't for a reg step or test has already been passed
223
-        if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) {
224
-            return $req_data;
225
-        }
226
-        /** @var EE_Request $request */
227
-        $request = LoaderFactory::getLoader()->getShared('EE_Request');
228
-        if (! EED_Recaptcha_Invisible::verifyToken($request)) {
229
-            if ($request->isAjax()) {
230
-                $json_response = new EE_SPCO_JSON_Response();
231
-                $json_response->echoAndExit();
232
-            }
233
-            EEH_URL::safeRedirectAndExit(
234
-                EE_Registry::instance()->CFG->core->reg_page_url()
235
-            );
236
-        }
237
-        return $req_data;
238
-    }
239
-
240
-
241
-    /**
242
-     * @param string   $html
243
-     * @param EE_Event $event
244
-     * @return string
245
-     * @throws InvalidArgumentException
246
-     * @throws InvalidDataTypeException
247
-     * @throws InvalidInterfaceException
248
-     * @throws EE_Error
249
-     */
250
-    public static function ticketSelectorForm($html = '', EE_Event $event)
251
-    {
252
-        // do nothing if test has  already  been passed
253
-        if (EED_Recaptcha_Invisible::recaptchaPassed()) {
254
-            return $html;
255
-        }
256
-        $html .= RecaptchaFactory::create()->getInputHtml(
257
-            array('recaptcha_id' => $event->ID())
258
-        );
259
-        return $html;
260
-    }
261
-
262
-
263
-    /**
264
-     * @return void
265
-     * @throws InvalidArgumentException
266
-     * @throws InvalidInterfaceException
267
-     * @throws InvalidDataTypeException
268
-     * @throws RuntimeException
269
-     */
270
-    public static function processTicketSelectorForm()
271
-    {
272
-        // do nothing if test has  already  been passed
273
-        if (EED_Recaptcha_Invisible::recaptchaPassed()) {
274
-            return;
275
-        }
276
-        /** @var EE_Request $request */
277
-        $request = LoaderFactory::getLoader()->getShared('EE_Request');
278
-        if (! EED_Recaptcha_Invisible::verifyToken($request)) {
279
-            $event_id   = $request->get('tkt-slctr-event-id');
280
-            $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}")
281
-                ? $request->get("tkt-slctr-return-url-{$event_id}")
282
-                : get_permalink($event_id);
283
-            EEH_URL::safeRedirectAndExit($return_url);
284
-        }
285
-    }
286
-
287
-
288
-    /**
289
-     * @throws InvalidArgumentException
290
-     * @throws InvalidDataTypeException
291
-     * @throws InvalidInterfaceException
292
-     */
293
-    public static function setSessionData()
294
-    {
295
-        EE_Registry::instance()->SSN->set_session_data(
296
-            array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
297
-        );
298
-    }
299
-
300
-
301
-    /**
302
-     * @throws EE_Error
303
-     * @throws InvalidArgumentException
304
-     * @throws InvalidDataTypeException
305
-     * @throws InvalidInterfaceException
306
-     */
307
-    public static function adminSettings()
308
-    {
309
-        RecaptchaFactory::getAdminModule()->adminSettings();
310
-    }
311
-
312
-
313
-    /**
314
-     * @param EE_Registration_Config $EE_Registration_Config
315
-     * @return EE_Registration_Config
316
-     * @throws EE_Error
317
-     * @throws InvalidArgumentException
318
-     * @throws InvalidDataTypeException
319
-     * @throws InvalidInterfaceException
320
-     * @throws ReflectionException
321
-     */
322
-    public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config)
323
-    {
324
-        return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config);
325
-    }
25
+	/**
26
+	 * @var EE_Registration_Config $config
27
+	 */
28
+	private static $config;
29
+
30
+
31
+	/**
32
+	 * @return EED_Module|EED_Recaptcha
33
+	 */
34
+	public static function instance()
35
+	{
36
+		return parent::get_instance(__CLASS__);
37
+	}
38
+
39
+
40
+	/**
41
+	 * @return void
42
+	 * @throws InvalidInterfaceException
43
+	 * @throws InvalidDataTypeException
44
+	 * @throws InvalidArgumentException
45
+	 */
46
+	public static function set_hooks()
47
+	{
48
+		EED_Recaptcha_Invisible::setProperties();
49
+		if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) {
50
+			// ticket selection
51
+			add_filter(
52
+				'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
53
+				array('EED_Recaptcha_Invisible', 'ticketSelectorForm'),
54
+				10, 2
55
+			);
56
+			add_action(
57
+				'EED_Ticket_Selector__process_ticket_selections__before',
58
+				array('EED_Recaptcha_Invisible', 'processTicketSelectorForm')
59
+			);
60
+			// checkout
61
+			add_action(
62
+				'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form',
63
+				array('EED_Recaptcha_Invisible', 'spcoRegStepForm')
64
+			);
65
+			add_filter(
66
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
67
+				array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'),
68
+				10, 2
69
+			);
70
+		}
71
+	}
72
+
73
+
74
+	/**
75
+	 * @return void
76
+	 * @throws InvalidInterfaceException
77
+	 * @throws InvalidDataTypeException
78
+	 * @throws InvalidArgumentException
79
+	 */
80
+	public static function set_hooks_admin()
81
+	{
82
+		// admin settings
83
+		add_action(
84
+			'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
85
+			array('EED_Recaptcha_Invisible', 'adminSettings')
86
+		);
87
+		add_filter(
88
+			'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
89
+			array('EED_Recaptcha_Invisible', 'updateAdminSettings')
90
+		);
91
+	}
92
+
93
+
94
+	/**
95
+	 * @return void
96
+	 * @throws InvalidInterfaceException
97
+	 * @throws InvalidDataTypeException
98
+	 * @throws InvalidArgumentException
99
+	 */
100
+	public static function setProperties()
101
+	{
102
+		EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration;
103
+	}
104
+
105
+
106
+	/**
107
+	 * @return boolean
108
+	 */
109
+	public static function useInvisibleRecaptcha()
110
+	{
111
+		return EED_Recaptcha_Invisible::$config->use_captcha
112
+			   && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible';
113
+	}
114
+
115
+
116
+	/**
117
+	 * @return string
118
+	 */
119
+	public static function assetsUrl()
120
+	{
121
+		return plugin_dir_url(__FILE__) . 'assets' . DS;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @param \WP $WP
127
+	 */
128
+	public function run($WP)
129
+	{
130
+	}
131
+
132
+
133
+	/**
134
+	 * @return boolean
135
+	 * @throws InvalidInterfaceException
136
+	 * @throws InvalidDataTypeException
137
+	 * @throws InvalidArgumentException
138
+	 */
139
+	public static function recaptchaPassed()
140
+	{
141
+		// logged in means you have already passed a turing test of sorts
142
+		if (EED_Recaptcha_Invisible::useInvisibleRecaptcha() === false || is_user_logged_in()) {
143
+			return true;
144
+		}
145
+		// was test already passed?
146
+		return filter_var(
147
+			EE_Registry::instance()->SSN->get_session_data(
148
+				InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
149
+			),
150
+			FILTER_VALIDATE_BOOLEAN
151
+		);
152
+	}
153
+
154
+
155
+	/**
156
+	 * @param EE_Request $request
157
+	 * @return bool
158
+	 * @throws InvalidArgumentException
159
+	 * @throws InvalidDataTypeException
160
+	 * @throws InvalidInterfaceException
161
+	 * @throws RuntimeException
162
+	 */
163
+	public static function verifyToken(EE_Request $request)
164
+	{
165
+		$invisible_recaptcha = RecaptchaFactory::create();
166
+		if ($invisible_recaptcha->verifyToken($request)) {
167
+			add_action('shutdown', array('EED_Recaptcha_Invisible', 'setSessionData'));
168
+			return true;
169
+		}
170
+		return false;
171
+	}
172
+
173
+
174
+	/**
175
+	 * @param EE_Form_Section_Proper $reg_form
176
+	 * @return void
177
+	 * @throws EE_Error
178
+	 * @throws InvalidArgumentException
179
+	 * @throws InvalidDataTypeException
180
+	 * @throws InvalidInterfaceException
181
+	 */
182
+	public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form)
183
+	{
184
+		// do nothing if form isn't for a reg step or test has already been passed
185
+		if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) {
186
+			return;
187
+		}
188
+		$default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs');
189
+		if ($default_hidden_inputs instanceof EE_Form_Section_Proper) {
190
+			$invisible_recaptcha = RecaptchaFactory::create();
191
+			$invisible_recaptcha->addToFormSection($default_hidden_inputs);
192
+		}
193
+	}
194
+
195
+
196
+	/**
197
+	 * @param EE_Form_Section_Proper $reg_form
198
+	 * @return bool
199
+	 * @throws InvalidDataTypeException
200
+	 * @throws InvalidInterfaceException
201
+	 * @throws EE_Error
202
+	 * @throws InvalidArgumentException
203
+	 */
204
+	public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form)
205
+	{
206
+		return strpos($reg_form->name(), 'reg-step-form') === false || EED_Recaptcha_Invisible::recaptchaPassed();
207
+	}
208
+
209
+
210
+	/**
211
+	 * @param array|null             $req_data
212
+	 * @param EE_Form_Section_Proper $reg_form
213
+	 * @return array
214
+	 * @throws EE_Error
215
+	 * @throws InvalidArgumentException
216
+	 * @throws InvalidDataTypeException
217
+	 * @throws InvalidInterfaceException
218
+	 * @throws RuntimeException
219
+	 */
220
+	public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form)
221
+	{
222
+		// do nothing if form isn't for a reg step or test has already been passed
223
+		if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) {
224
+			return $req_data;
225
+		}
226
+		/** @var EE_Request $request */
227
+		$request = LoaderFactory::getLoader()->getShared('EE_Request');
228
+		if (! EED_Recaptcha_Invisible::verifyToken($request)) {
229
+			if ($request->isAjax()) {
230
+				$json_response = new EE_SPCO_JSON_Response();
231
+				$json_response->echoAndExit();
232
+			}
233
+			EEH_URL::safeRedirectAndExit(
234
+				EE_Registry::instance()->CFG->core->reg_page_url()
235
+			);
236
+		}
237
+		return $req_data;
238
+	}
239
+
240
+
241
+	/**
242
+	 * @param string   $html
243
+	 * @param EE_Event $event
244
+	 * @return string
245
+	 * @throws InvalidArgumentException
246
+	 * @throws InvalidDataTypeException
247
+	 * @throws InvalidInterfaceException
248
+	 * @throws EE_Error
249
+	 */
250
+	public static function ticketSelectorForm($html = '', EE_Event $event)
251
+	{
252
+		// do nothing if test has  already  been passed
253
+		if (EED_Recaptcha_Invisible::recaptchaPassed()) {
254
+			return $html;
255
+		}
256
+		$html .= RecaptchaFactory::create()->getInputHtml(
257
+			array('recaptcha_id' => $event->ID())
258
+		);
259
+		return $html;
260
+	}
261
+
262
+
263
+	/**
264
+	 * @return void
265
+	 * @throws InvalidArgumentException
266
+	 * @throws InvalidInterfaceException
267
+	 * @throws InvalidDataTypeException
268
+	 * @throws RuntimeException
269
+	 */
270
+	public static function processTicketSelectorForm()
271
+	{
272
+		// do nothing if test has  already  been passed
273
+		if (EED_Recaptcha_Invisible::recaptchaPassed()) {
274
+			return;
275
+		}
276
+		/** @var EE_Request $request */
277
+		$request = LoaderFactory::getLoader()->getShared('EE_Request');
278
+		if (! EED_Recaptcha_Invisible::verifyToken($request)) {
279
+			$event_id   = $request->get('tkt-slctr-event-id');
280
+			$return_url = $request->is_set("tkt-slctr-return-url-{$event_id}")
281
+				? $request->get("tkt-slctr-return-url-{$event_id}")
282
+				: get_permalink($event_id);
283
+			EEH_URL::safeRedirectAndExit($return_url);
284
+		}
285
+	}
286
+
287
+
288
+	/**
289
+	 * @throws InvalidArgumentException
290
+	 * @throws InvalidDataTypeException
291
+	 * @throws InvalidInterfaceException
292
+	 */
293
+	public static function setSessionData()
294
+	{
295
+		EE_Registry::instance()->SSN->set_session_data(
296
+			array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
297
+		);
298
+	}
299
+
300
+
301
+	/**
302
+	 * @throws EE_Error
303
+	 * @throws InvalidArgumentException
304
+	 * @throws InvalidDataTypeException
305
+	 * @throws InvalidInterfaceException
306
+	 */
307
+	public static function adminSettings()
308
+	{
309
+		RecaptchaFactory::getAdminModule()->adminSettings();
310
+	}
311
+
312
+
313
+	/**
314
+	 * @param EE_Registration_Config $EE_Registration_Config
315
+	 * @return EE_Registration_Config
316
+	 * @throws EE_Error
317
+	 * @throws InvalidArgumentException
318
+	 * @throws InvalidDataTypeException
319
+	 * @throws InvalidInterfaceException
320
+	 * @throws ReflectionException
321
+	 */
322
+	public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config)
323
+	{
324
+		return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config);
325
+	}
326 326
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
      */
119 119
     public static function assetsUrl()
120 120
     {
121
-        return plugin_dir_url(__FILE__) . 'assets' . DS;
121
+        return plugin_dir_url(__FILE__).'assets'.DS;
122 122
     }
123 123
 
124 124
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
     public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form)
183 183
     {
184 184
         // do nothing if form isn't for a reg step or test has already been passed
185
-        if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) {
185
+        if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) {
186 186
             return;
187 187
         }
188 188
         $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs');
@@ -220,12 +220,12 @@  discard block
 block discarded – undo
220 220
     public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form)
221 221
     {
222 222
         // do nothing if form isn't for a reg step or test has already been passed
223
-        if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) {
223
+        if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) {
224 224
             return $req_data;
225 225
         }
226 226
         /** @var EE_Request $request */
227 227
         $request = LoaderFactory::getLoader()->getShared('EE_Request');
228
-        if (! EED_Recaptcha_Invisible::verifyToken($request)) {
228
+        if ( ! EED_Recaptcha_Invisible::verifyToken($request)) {
229 229
             if ($request->isAjax()) {
230 230
                 $json_response = new EE_SPCO_JSON_Response();
231 231
                 $json_response->echoAndExit();
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
         }
276 276
         /** @var EE_Request $request */
277 277
         $request = LoaderFactory::getLoader()->getShared('EE_Request');
278
-        if (! EED_Recaptcha_Invisible::verifyToken($request)) {
278
+        if ( ! EED_Recaptcha_Invisible::verifyToken($request)) {
279 279
             $event_id   = $request->get('tkt-slctr-event-id');
280 280
             $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}")
281 281
                 ? $request->get("tkt-slctr-return-url-{$event_id}")
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha_invisible/InvisibleRecaptcha.php 2 patches
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -29,154 +29,154 @@
 block discarded – undo
29 29
 class InvisibleRecaptcha
30 30
 {
31 31
 
32
-    const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
33
-
34
-    const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
35
-
36
-    /**
37
-     * @var EE_Registration_Config $config
38
-     */
39
-    private $config;
40
-
41
-
42
-    /**
43
-     * InvisibleRecaptcha constructor.
44
-     *
45
-     * @param EE_Registration_Config $registration_config
46
-     */
47
-    public function __construct(EE_Registration_Config $registration_config)
48
-    {
49
-        $this->config = $registration_config;
50
-    }
51
-
52
-
53
-    /**
54
-     * @param array $input_settings
55
-     * @return EE_Invisible_Recaptcha_Input
56
-     * @throws InvalidDataTypeException
57
-     * @throws InvalidInterfaceException
58
-     * @throws InvalidArgumentException
59
-     */
60
-    public function getInput(array $input_settings = array())
61
-    {
62
-        return new EE_Invisible_Recaptcha_Input(
63
-            $input_settings,
64
-            $this->config
65
-        );
66
-    }
67
-
68
-
69
-    /**
70
-     * @param array $input_settings
71
-     * @return string
72
-     * @throws EE_Error
73
-     * @throws InvalidDataTypeException
74
-     * @throws InvalidInterfaceException
75
-     * @throws InvalidArgumentException
76
-     */
77
-    public function getInputHtml(array $input_settings = array())
78
-    {
79
-        return $this->getInput($input_settings)->get_html_for_input();
80
-    }
81
-
82
-
83
-    /**
84
-     * @param EE_Form_Section_Proper $form
85
-     * @param array                  $input_settings
86
-     * @throws EE_Error
87
-     * @throws InvalidArgumentException
88
-     * @throws InvalidDataTypeException
89
-     * @throws InvalidInterfaceException
90
-     */
91
-    public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
92
-    {
93
-        $form->add_subsections(
94
-            array(
95
-                'espresso_recaptcha' => $this->getInput($input_settings),
96
-            ),
97
-            null,
98
-            false
99
-        );
100
-    }
101
-
102
-
103
-    /**
104
-     * @param EE_Request $request
105
-     * @return boolean
106
-     * @throws RuntimeException
107
-     */
108
-    public function verifyToken(EE_Request $request)
109
-    {
110
-        static $previous_recaptcha_response = array();
111
-        $grecaptcha_response = $request->get('g-recaptcha-response');
112
-        // if this token has already been verified, then return previous response
113
-        if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
114
-            return $previous_recaptcha_response[ $grecaptcha_response ];
115
-        }
116
-        // will update to true if everything passes
117
-        $previous_recaptcha_response[ $grecaptcha_response ] = false;
118
-        $response                                            = wp_safe_remote_post(
119
-            InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
120
-            array(
121
-                'body' => array(
122
-                    'secret'   => $this->config->recaptcha_privatekey,
123
-                    'response' => $grecaptcha_response,
124
-                    'remoteip' => $request->ip_address(),
125
-                ),
126
-            )
127
-        );
128
-        if ($response instanceof WP_Error) {
129
-            $this->generateError($response->get_error_messages());
130
-            return false;
131
-        }
132
-        $results = json_decode(wp_remote_retrieve_body($response), true);
133
-        if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
134
-            $errors   = array_map(
135
-                array($this, 'getErrorCode'),
136
-                $results['error-codes']
137
-            );
138
-            $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
139
-            $this->generateError(implode(' ', $errors));
140
-        }
141
-        $previous_recaptcha_response[ $grecaptcha_response ] = true;
142
-        return true;
143
-    }
144
-
145
-
146
-    /**
147
-     * @param string $error_response
148
-     * @return void
149
-     * @throws RuntimeException
150
-     */
151
-    public function generateError($error_response = '')
152
-    {
153
-        throw new RuntimeException(
154
-            sprintf(
155
-                esc_html__(
156
-                    'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
157
-                    'event_espresso'
158
-                ),
159
-                '<br />',
160
-                current_user_can('manage_options') ? $error_response : ''
161
-            )
162
-        );
163
-    }
164
-
165
-
166
-    /**
167
-     * @param string $error_code
168
-     * @return string
169
-     */
170
-    public function getErrorCode(&$error_code)
171
-    {
172
-        $error_codes = array(
173
-            'missing-input-secret'   => 'The secret parameter is missing.',
174
-            'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
175
-            'missing-input-response' => 'The response parameter is missing.',
176
-            'invalid-input-response' => 'The response parameter is invalid or malformed.',
177
-            'bad-request'            => 'The request is invalid or malformed.',
178
-            'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
179
-        );
180
-        return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
181
-    }
32
+	const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
33
+
34
+	const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
35
+
36
+	/**
37
+	 * @var EE_Registration_Config $config
38
+	 */
39
+	private $config;
40
+
41
+
42
+	/**
43
+	 * InvisibleRecaptcha constructor.
44
+	 *
45
+	 * @param EE_Registration_Config $registration_config
46
+	 */
47
+	public function __construct(EE_Registration_Config $registration_config)
48
+	{
49
+		$this->config = $registration_config;
50
+	}
51
+
52
+
53
+	/**
54
+	 * @param array $input_settings
55
+	 * @return EE_Invisible_Recaptcha_Input
56
+	 * @throws InvalidDataTypeException
57
+	 * @throws InvalidInterfaceException
58
+	 * @throws InvalidArgumentException
59
+	 */
60
+	public function getInput(array $input_settings = array())
61
+	{
62
+		return new EE_Invisible_Recaptcha_Input(
63
+			$input_settings,
64
+			$this->config
65
+		);
66
+	}
67
+
68
+
69
+	/**
70
+	 * @param array $input_settings
71
+	 * @return string
72
+	 * @throws EE_Error
73
+	 * @throws InvalidDataTypeException
74
+	 * @throws InvalidInterfaceException
75
+	 * @throws InvalidArgumentException
76
+	 */
77
+	public function getInputHtml(array $input_settings = array())
78
+	{
79
+		return $this->getInput($input_settings)->get_html_for_input();
80
+	}
81
+
82
+
83
+	/**
84
+	 * @param EE_Form_Section_Proper $form
85
+	 * @param array                  $input_settings
86
+	 * @throws EE_Error
87
+	 * @throws InvalidArgumentException
88
+	 * @throws InvalidDataTypeException
89
+	 * @throws InvalidInterfaceException
90
+	 */
91
+	public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
92
+	{
93
+		$form->add_subsections(
94
+			array(
95
+				'espresso_recaptcha' => $this->getInput($input_settings),
96
+			),
97
+			null,
98
+			false
99
+		);
100
+	}
101
+
102
+
103
+	/**
104
+	 * @param EE_Request $request
105
+	 * @return boolean
106
+	 * @throws RuntimeException
107
+	 */
108
+	public function verifyToken(EE_Request $request)
109
+	{
110
+		static $previous_recaptcha_response = array();
111
+		$grecaptcha_response = $request->get('g-recaptcha-response');
112
+		// if this token has already been verified, then return previous response
113
+		if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
114
+			return $previous_recaptcha_response[ $grecaptcha_response ];
115
+		}
116
+		// will update to true if everything passes
117
+		$previous_recaptcha_response[ $grecaptcha_response ] = false;
118
+		$response                                            = wp_safe_remote_post(
119
+			InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
120
+			array(
121
+				'body' => array(
122
+					'secret'   => $this->config->recaptcha_privatekey,
123
+					'response' => $grecaptcha_response,
124
+					'remoteip' => $request->ip_address(),
125
+				),
126
+			)
127
+		);
128
+		if ($response instanceof WP_Error) {
129
+			$this->generateError($response->get_error_messages());
130
+			return false;
131
+		}
132
+		$results = json_decode(wp_remote_retrieve_body($response), true);
133
+		if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
134
+			$errors   = array_map(
135
+				array($this, 'getErrorCode'),
136
+				$results['error-codes']
137
+			);
138
+			$errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
139
+			$this->generateError(implode(' ', $errors));
140
+		}
141
+		$previous_recaptcha_response[ $grecaptcha_response ] = true;
142
+		return true;
143
+	}
144
+
145
+
146
+	/**
147
+	 * @param string $error_response
148
+	 * @return void
149
+	 * @throws RuntimeException
150
+	 */
151
+	public function generateError($error_response = '')
152
+	{
153
+		throw new RuntimeException(
154
+			sprintf(
155
+				esc_html__(
156
+					'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
157
+					'event_espresso'
158
+				),
159
+				'<br />',
160
+				current_user_can('manage_options') ? $error_response : ''
161
+			)
162
+		);
163
+	}
164
+
165
+
166
+	/**
167
+	 * @param string $error_code
168
+	 * @return string
169
+	 */
170
+	public function getErrorCode(&$error_code)
171
+	{
172
+		$error_codes = array(
173
+			'missing-input-secret'   => 'The secret parameter is missing.',
174
+			'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
175
+			'missing-input-response' => 'The response parameter is missing.',
176
+			'invalid-input-response' => 'The response parameter is invalid or malformed.',
177
+			'bad-request'            => 'The request is invalid or malformed.',
178
+			'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
179
+		);
180
+		return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
181
+	}
182 182
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -110,11 +110,11 @@  discard block
 block discarded – undo
110 110
         static $previous_recaptcha_response = array();
111 111
         $grecaptcha_response = $request->get('g-recaptcha-response');
112 112
         // if this token has already been verified, then return previous response
113
-        if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
114
-            return $previous_recaptcha_response[ $grecaptcha_response ];
113
+        if (isset($previous_recaptcha_response[$grecaptcha_response])) {
114
+            return $previous_recaptcha_response[$grecaptcha_response];
115 115
         }
116 116
         // will update to true if everything passes
117
-        $previous_recaptcha_response[ $grecaptcha_response ] = false;
117
+        $previous_recaptcha_response[$grecaptcha_response] = false;
118 118
         $response                                            = wp_safe_remote_post(
119 119
             InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
120 120
             array(
@@ -131,14 +131,14 @@  discard block
 block discarded – undo
131 131
         }
132 132
         $results = json_decode(wp_remote_retrieve_body($response), true);
133 133
         if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
134
-            $errors   = array_map(
134
+            $errors = array_map(
135 135
                 array($this, 'getErrorCode'),
136 136
                 $results['error-codes']
137 137
             );
138
-            $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
138
+            $errors[] = 'challenge timestamp: '.$results['challenge_ts'].'.';
139 139
             $this->generateError(implode(' ', $errors));
140 140
         }
141
-        $previous_recaptcha_response[ $grecaptcha_response ] = true;
141
+        $previous_recaptcha_response[$grecaptcha_response] = true;
142 142
         return true;
143 143
     }
144 144
 
@@ -177,6 +177,6 @@  discard block
 block discarded – undo
177 177
             'bad-request'            => 'The request is invalid or malformed.',
178 178
             'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
179 179
         );
180
-        return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
180
+        return isset($error_codes[$error_code]) ? $error_codes[$error_code] : '';
181 181
     }
182 182
 }
Please login to merge, or discard this patch.