Completed
Branch BUG-10626-dst-unit-test (cc62a6)
by
unknown
37:15 queued 23:58
created
modules/bot_trap/EED_Bot_Trap.module.php 2 patches
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -17,323 +17,323 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * @return EED_Bot_Trap|EED_Module
22
-     */
23
-    public static function instance()
24
-    {
25
-        return parent::get_instance(__CLASS__);
26
-    }
20
+	/**
21
+	 * @return EED_Bot_Trap|EED_Module
22
+	 */
23
+	public static function instance()
24
+	{
25
+		return parent::get_instance(__CLASS__);
26
+	}
27 27
 
28 28
 
29
-    /**
30
-     * set_hooks - for hooking into EE Core, other modules, etc
31
-     *
32
-     * @return void
33
-     */
34
-    public static function set_hooks()
35
-    {
36
-        if (
37
-            apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) &&
38
-            \EE_Registry::instance()->CFG->registration->use_bot_trap
39
-        ) {
40
-            \EED_Bot_Trap::set_trap();
41
-            // redirect bots to bogus success page
42
-            \EE_Config::register_route('ticket_selection_received', 'EED_Bot_Trap', 'display_bot_trap_success');
43
-        }
44
-    }
29
+	/**
30
+	 * set_hooks - for hooking into EE Core, other modules, etc
31
+	 *
32
+	 * @return void
33
+	 */
34
+	public static function set_hooks()
35
+	{
36
+		if (
37
+			apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) &&
38
+			\EE_Registry::instance()->CFG->registration->use_bot_trap
39
+		) {
40
+			\EED_Bot_Trap::set_trap();
41
+			// redirect bots to bogus success page
42
+			\EE_Config::register_route('ticket_selection_received', 'EED_Bot_Trap', 'display_bot_trap_success');
43
+		}
44
+	}
45 45
 
46 46
 
47
-    /**
48
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
49
-     *
50
-     * @return void
51
-     */
52
-    public static function set_trap()
53
-    {
54
-        define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . DS);
55
-        add_action(
56
-            'AHEE__ticket_selector_chart__template__after_ticket_selector',
57
-            array('EED_Bot_Trap', 'generate_bot_trap'),
58
-            10, 2
59
-        );
60
-        add_action(
61
-            'EED_Ticket_Selector__process_ticket_selections__before',
62
-            array('EED_Bot_Trap', 'process_bot_trap'),
63
-            1, 2
64
-        );
65
-    }
47
+	/**
48
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
49
+	 *
50
+	 * @return void
51
+	 */
52
+	public static function set_trap()
53
+	{
54
+		define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . DS);
55
+		add_action(
56
+			'AHEE__ticket_selector_chart__template__after_ticket_selector',
57
+			array('EED_Bot_Trap', 'generate_bot_trap'),
58
+			10, 2
59
+		);
60
+		add_action(
61
+			'EED_Ticket_Selector__process_ticket_selections__before',
62
+			array('EED_Bot_Trap', 'process_bot_trap'),
63
+			1, 2
64
+		);
65
+	}
66 66
 
67 67
 
68
-    /**
69
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
70
-     *
71
-     * @return void
72
-     */
73
-    public static function set_hooks_admin()
74
-    {
75
-        if (
76
-            defined('DOING_AJAX')
77
-            && DOING_AJAX
78
-            && apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true)
79
-            && \EE_Registry::instance()->CFG->registration->use_bot_trap
80
-        ) {
81
-            \EED_Bot_Trap::set_trap();
82
-        }
83
-        add_action(
84
-            'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
85
-            array('EED_Bot_Trap', 'bot_trap_settings_form'),
86
-            5
87
-        );
88
-        add_filter(
89
-            'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
90
-            array('EED_Bot_Trap', 'update_bot_trap_settings_form'),
91
-            10, 1
92
-        );
93
-    }
68
+	/**
69
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
70
+	 *
71
+	 * @return void
72
+	 */
73
+	public static function set_hooks_admin()
74
+	{
75
+		if (
76
+			defined('DOING_AJAX')
77
+			&& DOING_AJAX
78
+			&& apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true)
79
+			&& \EE_Registry::instance()->CFG->registration->use_bot_trap
80
+		) {
81
+			\EED_Bot_Trap::set_trap();
82
+		}
83
+		add_action(
84
+			'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
85
+			array('EED_Bot_Trap', 'bot_trap_settings_form'),
86
+			5
87
+		);
88
+		add_filter(
89
+			'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
90
+			array('EED_Bot_Trap', 'update_bot_trap_settings_form'),
91
+			10, 1
92
+		);
93
+	}
94 94
 
95 95
 
96
-    /**
97
-     * run - initial module setup
98
-     *
99
-     * @param WP $WP
100
-     * @return void
101
-     */
102
-    public function run($WP)
103
-    {
104
-    }
96
+	/**
97
+	 * run - initial module setup
98
+	 *
99
+	 * @param WP $WP
100
+	 * @return void
101
+	 */
102
+	public function run($WP)
103
+	{
104
+	}
105 105
 
106 106
 
107
-    /**
108
-     * generate_bot_trap
109
-     *
110
-     * @return void
111
-     * @throws RuntimeException
112
-     */
113
-    public static function generate_bot_trap()
114
-    {
115
-        $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso');
116
-        $time = microtime(true);
117
-        $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">';
118
-        $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>';
119
-        $html .= '<input type="email" id="tkt-slctr-request-processor-email-';
120
-        $html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>';
121
-        $html .= '<input type="hidden" name="tkt-slctr-request-processor-token" value="';
122
-        if (EE_Registry::instance()->CFG->registration->use_encryption) {
123
-            EE_Registry::instance()->load_core('EE_Encryption');
124
-            $html .= EE_Encryption::instance()->encrypt($time);
125
-        } else {
126
-            $html .= $time;
127
-        }
128
-        $html .= '"/>';
129
-        $html .= '</div><!-- .tkt-slctr-request-processor-dv -->';
130
-        echo $html;
131
-    }
107
+	/**
108
+	 * generate_bot_trap
109
+	 *
110
+	 * @return void
111
+	 * @throws RuntimeException
112
+	 */
113
+	public static function generate_bot_trap()
114
+	{
115
+		$do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso');
116
+		$time = microtime(true);
117
+		$html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">';
118
+		$html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>';
119
+		$html .= '<input type="email" id="tkt-slctr-request-processor-email-';
120
+		$html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>';
121
+		$html .= '<input type="hidden" name="tkt-slctr-request-processor-token" value="';
122
+		if (EE_Registry::instance()->CFG->registration->use_encryption) {
123
+			EE_Registry::instance()->load_core('EE_Encryption');
124
+			$html .= EE_Encryption::instance()->encrypt($time);
125
+		} else {
126
+			$html .= $time;
127
+		}
128
+		$html .= '"/>';
129
+		$html .= '</div><!-- .tkt-slctr-request-processor-dv -->';
130
+		echo $html;
131
+	}
132 132
 
133 133
 
134
-    /**
135
-     * process_bot_trap
136
-     *
137
-     * @param array|string $triggered_trap_callback Callback that will be executed for handling the
138
-     *                                              response if the bot trap is triggered.
139
-     *                                              It should receive one argument: a boolean indicating
140
-     *                                              whether the trap was triggered by suspicious timing or not.
141
-     * @throws RuntimeException
142
-     */
143
-    public static function process_bot_trap($triggered_trap_callback = array())
144
-    {
145
-        // what's your email address Mr. Bot ?
146
-        $empty_trap = isset($_REQUEST['tkt-slctr-request-processor-email'])
147
-            && $_REQUEST['tkt-slctr-request-processor-email'] === '';
148
-        // get encrypted timestamp for when the form was originally displayed
149
-        $bot_trap_timestamp = isset($_REQUEST['tkt-slctr-request-processor-token'])
150
-            ? sanitize_text_field($_REQUEST['tkt-slctr-request-processor-token'])
151
-            : '';
152
-        // decrypt and convert to absolute  integer
153
-        if (EE_Registry::instance()->CFG->registration->use_encryption) {
154
-            EE_Registry::instance()->load_core('EE_Encryption');
155
-            $bot_trap_timestamp = absint(EE_Encryption::instance()->decrypt($bot_trap_timestamp));
156
-        } else {
157
-            $bot_trap_timestamp = absint($bot_trap_timestamp);
158
-        }
159
-        // ticket form submitted too impossibly fast ( after now ) or more than an hour later ???
160
-        $suspicious_timing = $bot_trap_timestamp > time() || $bot_trap_timestamp < (time() - HOUR_IN_SECONDS);
161
-        // are we human ?
162
-        if ($empty_trap && !$suspicious_timing) {
163
-            do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered');
164
-            return;
165
-        }
166
-        // check the given callback is valid first before executing
167
-        if (!is_callable($triggered_trap_callback)) {
168
-            // invalid callback so lets just sub in our default.
169
-            $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response');
170
-        }
171
-        call_user_func($triggered_trap_callback, $suspicious_timing);
172
-    }
134
+	/**
135
+	 * process_bot_trap
136
+	 *
137
+	 * @param array|string $triggered_trap_callback Callback that will be executed for handling the
138
+	 *                                              response if the bot trap is triggered.
139
+	 *                                              It should receive one argument: a boolean indicating
140
+	 *                                              whether the trap was triggered by suspicious timing or not.
141
+	 * @throws RuntimeException
142
+	 */
143
+	public static function process_bot_trap($triggered_trap_callback = array())
144
+	{
145
+		// what's your email address Mr. Bot ?
146
+		$empty_trap = isset($_REQUEST['tkt-slctr-request-processor-email'])
147
+			&& $_REQUEST['tkt-slctr-request-processor-email'] === '';
148
+		// get encrypted timestamp for when the form was originally displayed
149
+		$bot_trap_timestamp = isset($_REQUEST['tkt-slctr-request-processor-token'])
150
+			? sanitize_text_field($_REQUEST['tkt-slctr-request-processor-token'])
151
+			: '';
152
+		// decrypt and convert to absolute  integer
153
+		if (EE_Registry::instance()->CFG->registration->use_encryption) {
154
+			EE_Registry::instance()->load_core('EE_Encryption');
155
+			$bot_trap_timestamp = absint(EE_Encryption::instance()->decrypt($bot_trap_timestamp));
156
+		} else {
157
+			$bot_trap_timestamp = absint($bot_trap_timestamp);
158
+		}
159
+		// ticket form submitted too impossibly fast ( after now ) or more than an hour later ???
160
+		$suspicious_timing = $bot_trap_timestamp > time() || $bot_trap_timestamp < (time() - HOUR_IN_SECONDS);
161
+		// are we human ?
162
+		if ($empty_trap && !$suspicious_timing) {
163
+			do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered');
164
+			return;
165
+		}
166
+		// check the given callback is valid first before executing
167
+		if (!is_callable($triggered_trap_callback)) {
168
+			// invalid callback so lets just sub in our default.
169
+			$triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response');
170
+		}
171
+		call_user_func($triggered_trap_callback, $suspicious_timing);
172
+	}
173 173
 
174 174
 
175
-    /**
176
-     * This is the default callback executed by EED_Bot_Trap::process_bot_trap that handles the response.
177
-     *
178
-     * @param bool $suspicious_timing If true, then the bot trap was triggered due to the suspicious timing test.
179
-     */
180
-    public static function triggered_trap_response($suspicious_timing)
181
-    {
182
-        // UH OH...
183
-        $redirect_url = add_query_arg(
184
-            array('ee' => 'ticket_selection_received'),
185
-            EE_Registry::instance()->CFG->core->reg_page_url()
186
-        );
187
-        if ($suspicious_timing) {
188
-            $redirect_url = add_query_arg(
189
-                array(
190
-                    'ee-notice' => urlencode(
191
-                        esc_html__(
192
-                            'We\'re sorry, but your ticket selections could not be processed due to a server timing error. Please hit the back button on your browser and try again.',
193
-                            'event_espresso'
194
-                        )
195
-                    )
196
-                ),
197
-                $redirect_url
198
-            );
199
-        }
200
-        $redirect_url = apply_filters('FHEE__EED_Bot_Trap__process_bot_trap__redirect_url', $redirect_url);
201
-        // if AJAX, return the redirect URL
202
-        if (defined('DOING_AJAX') && DOING_AJAX) {
203
-            echo wp_json_encode(
204
-                array_merge(
205
-                    EE_Error::get_notices(false),
206
-                    array(
207
-                        'redirect_url' => $redirect_url
208
-                    )
209
-                )
210
-            );
211
-            exit();
212
-        }
213
-        wp_safe_redirect($redirect_url);
214
-        exit();
215
-    }
175
+	/**
176
+	 * This is the default callback executed by EED_Bot_Trap::process_bot_trap that handles the response.
177
+	 *
178
+	 * @param bool $suspicious_timing If true, then the bot trap was triggered due to the suspicious timing test.
179
+	 */
180
+	public static function triggered_trap_response($suspicious_timing)
181
+	{
182
+		// UH OH...
183
+		$redirect_url = add_query_arg(
184
+			array('ee' => 'ticket_selection_received'),
185
+			EE_Registry::instance()->CFG->core->reg_page_url()
186
+		);
187
+		if ($suspicious_timing) {
188
+			$redirect_url = add_query_arg(
189
+				array(
190
+					'ee-notice' => urlencode(
191
+						esc_html__(
192
+							'We\'re sorry, but your ticket selections could not be processed due to a server timing error. Please hit the back button on your browser and try again.',
193
+							'event_espresso'
194
+						)
195
+					)
196
+				),
197
+				$redirect_url
198
+			);
199
+		}
200
+		$redirect_url = apply_filters('FHEE__EED_Bot_Trap__process_bot_trap__redirect_url', $redirect_url);
201
+		// if AJAX, return the redirect URL
202
+		if (defined('DOING_AJAX') && DOING_AJAX) {
203
+			echo wp_json_encode(
204
+				array_merge(
205
+					EE_Error::get_notices(false),
206
+					array(
207
+						'redirect_url' => $redirect_url
208
+					)
209
+				)
210
+			);
211
+			exit();
212
+		}
213
+		wp_safe_redirect($redirect_url);
214
+		exit();
215
+	}
216 216
 
217 217
 
218
-    /**
219
-     * display_bot_trap_success
220
-     * shows a "success" screen to bots so that they (ie: the ppl managing them)
221
-     * think the form was submitted successfully
222
-     *
223
-     * @return void
224
-     */
225
-    public static function display_bot_trap_success()
226
-    {
227
-        add_filter('FHEE__EED_Single_Page_Checkout__run', '__return_false');
228
-        $bot_notice = esc_html__(
229
-            'Thank you so much. Your ticket selections have been received for consideration.',
230
-            'event_espresso'
231
-        );
232
-        $bot_notice = isset($_REQUEST['ee-notice']) && $_REQUEST['ee-notice'] !== ''
233
-            ? sanitize_text_field(stripslashes($_REQUEST['ee-notice']))
234
-            : $bot_notice;
235
-        EE_Registry::instance()->REQ->add_output(EEH_HTML::div($bot_notice, '', 'ee-attention'));
236
-    }
218
+	/**
219
+	 * display_bot_trap_success
220
+	 * shows a "success" screen to bots so that they (ie: the ppl managing them)
221
+	 * think the form was submitted successfully
222
+	 *
223
+	 * @return void
224
+	 */
225
+	public static function display_bot_trap_success()
226
+	{
227
+		add_filter('FHEE__EED_Single_Page_Checkout__run', '__return_false');
228
+		$bot_notice = esc_html__(
229
+			'Thank you so much. Your ticket selections have been received for consideration.',
230
+			'event_espresso'
231
+		);
232
+		$bot_notice = isset($_REQUEST['ee-notice']) && $_REQUEST['ee-notice'] !== ''
233
+			? sanitize_text_field(stripslashes($_REQUEST['ee-notice']))
234
+			: $bot_notice;
235
+		EE_Registry::instance()->REQ->add_output(EEH_HTML::div($bot_notice, '', 'ee-attention'));
236
+	}
237 237
 
238 238
 
239 239
 
240
-    /***********************************    ADMIN    **********************************/
240
+	/***********************************    ADMIN    **********************************/
241 241
 
242 242
 
243
-    /**
244
-     * bot_trap_settings_form
245
-     *
246
-     * @return void
247
-     * @throws EE_Error
248
-     */
249
-    public static function bot_trap_settings_form()
250
-    {
251
-        EED_Bot_Trap::_bot_trap_settings_form()->enqueue_js();
252
-        echo EED_Bot_Trap::_bot_trap_settings_form()->get_html();
253
-    }
243
+	/**
244
+	 * bot_trap_settings_form
245
+	 *
246
+	 * @return void
247
+	 * @throws EE_Error
248
+	 */
249
+	public static function bot_trap_settings_form()
250
+	{
251
+		EED_Bot_Trap::_bot_trap_settings_form()->enqueue_js();
252
+		echo EED_Bot_Trap::_bot_trap_settings_form()->get_html();
253
+	}
254 254
 
255 255
 
256
-    /**
257
-     * _bot_trap_settings_form
258
-     *
259
-     * @return EE_Form_Section_Proper
260
-     * @throws EE_Error
261
-     */
262
-    protected static function _bot_trap_settings_form()
263
-    {
264
-        return new EE_Form_Section_Proper(
265
-            array(
266
-                'name' => 'bot_trap_settings',
267
-                'html_id' => 'bot_trap_settings',
268
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
269
-                'subsections' => array(
270
-                    'bot_trap_hdr' => new EE_Form_Section_HTML(EEH_HTML::h2(esc_html__('Bot Trap Settings', 'event_espresso'))),
271
-                    'use_bot_trap' => new EE_Yes_No_Input(
272
-                        array(
273
-                            'html_label_text' => esc_html__('Enable Bot Trap', 'event_espresso'),
274
-                            'html_help_text' => esc_html__('The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.', 'event_espresso'),
275
-                            'default' => EE_Registry::instance()->CFG->registration->use_bot_trap !== null
276
-                                ? EE_Registry::instance()->CFG->registration->use_bot_trap
277
-                                : true,
278
-                            'required' => false
279
-                        )
280
-                    ),
281
-                    'use_encryption' => new EE_Yes_No_Input(
282
-                        array(
283
-                            'html_label_text' => esc_html__('Encrypt Bot Trap Data', 'event_espresso'),
284
-                            'html_help_text' => esc_html__(
285
-                                'One way to detect spam bots is by looking at how long it takes them to submit a form. They are often inhumanly fast, or will submit forms hours, days, or even weeks after the form was first scraped off the web. The Event Espresso Bot Trap will send a timestamp with the Ticket Selector form when it is submitted. By default, this timestamp is encrypted so that the spam bots can not change it, but encryption may cause issues on some servers due to configuration "conflicts". If you continuously get caught in the bot trap, then try setting this option to "No". This may increase the number of spam submissions you receive, but increases server compatibility.',
286
-                                'event_espresso'
287
-                            ),
288
-                            'default' => EE_Registry::instance()->CFG->registration->use_encryption !== null
289
-                                ? EE_Registry::instance()->CFG->registration->use_encryption
290
-                                : true,
291
-                            'required' => false
292
-                        )
293
-                    ),
294
-                )
295
-            )
296
-        );
297
-    }
256
+	/**
257
+	 * _bot_trap_settings_form
258
+	 *
259
+	 * @return EE_Form_Section_Proper
260
+	 * @throws EE_Error
261
+	 */
262
+	protected static function _bot_trap_settings_form()
263
+	{
264
+		return new EE_Form_Section_Proper(
265
+			array(
266
+				'name' => 'bot_trap_settings',
267
+				'html_id' => 'bot_trap_settings',
268
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
269
+				'subsections' => array(
270
+					'bot_trap_hdr' => new EE_Form_Section_HTML(EEH_HTML::h2(esc_html__('Bot Trap Settings', 'event_espresso'))),
271
+					'use_bot_trap' => new EE_Yes_No_Input(
272
+						array(
273
+							'html_label_text' => esc_html__('Enable Bot Trap', 'event_espresso'),
274
+							'html_help_text' => esc_html__('The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.', 'event_espresso'),
275
+							'default' => EE_Registry::instance()->CFG->registration->use_bot_trap !== null
276
+								? EE_Registry::instance()->CFG->registration->use_bot_trap
277
+								: true,
278
+							'required' => false
279
+						)
280
+					),
281
+					'use_encryption' => new EE_Yes_No_Input(
282
+						array(
283
+							'html_label_text' => esc_html__('Encrypt Bot Trap Data', 'event_espresso'),
284
+							'html_help_text' => esc_html__(
285
+								'One way to detect spam bots is by looking at how long it takes them to submit a form. They are often inhumanly fast, or will submit forms hours, days, or even weeks after the form was first scraped off the web. The Event Espresso Bot Trap will send a timestamp with the Ticket Selector form when it is submitted. By default, this timestamp is encrypted so that the spam bots can not change it, but encryption may cause issues on some servers due to configuration "conflicts". If you continuously get caught in the bot trap, then try setting this option to "No". This may increase the number of spam submissions you receive, but increases server compatibility.',
286
+								'event_espresso'
287
+							),
288
+							'default' => EE_Registry::instance()->CFG->registration->use_encryption !== null
289
+								? EE_Registry::instance()->CFG->registration->use_encryption
290
+								: true,
291
+							'required' => false
292
+						)
293
+					),
294
+				)
295
+			)
296
+		);
297
+	}
298 298
 
299 299
 
300
-    /**
301
-     * update_bot_trap_settings_form
302
-     *
303
-     * @param EE_Registration_Config $EE_Registration_Config
304
-     * @return EE_Registration_Config
305
-     * @throws ReflectionException
306
-     * @throws EE_Error
307
-     */
308
-    public static function update_bot_trap_settings_form(EE_Registration_Config $EE_Registration_Config)
309
-    {
310
-        try {
311
-            $bot_trap_settings_form = EED_Bot_Trap::_bot_trap_settings_form();
312
-            // if not displaying a form, then check for form submission
313
-            if ($bot_trap_settings_form->was_submitted()) {
314
-                // capture form data
315
-                $bot_trap_settings_form->receive_form_submission();
316
-                // validate form data
317
-                if ($bot_trap_settings_form->is_valid()) {
318
-                    // grab validated data from form
319
-                    $valid_data = $bot_trap_settings_form->valid_data();
320
-                    if (isset($valid_data['use_bot_trap'], $valid_data['use_encryption'])) {
321
-                        $EE_Registration_Config->use_bot_trap = $valid_data['use_bot_trap'];
322
-                        $EE_Registration_Config->use_encryption = $valid_data['use_encryption'];
323
-                    } else {
324
-                        EE_Error::add_error(esc_html__('Invalid or missing Bot Trap settings. Please refresh the form and try again.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
325
-                    }
326
-                } else {
327
-                    if ($bot_trap_settings_form->submission_error_message() !== '') {
328
-                        EE_Error::add_error($bot_trap_settings_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__);
329
-                    }
330
-                }
331
-            }
332
-        } catch (EE_Error $e) {
333
-            $e->get_error();
334
-        }
335
-        return $EE_Registration_Config;
336
-    }
300
+	/**
301
+	 * update_bot_trap_settings_form
302
+	 *
303
+	 * @param EE_Registration_Config $EE_Registration_Config
304
+	 * @return EE_Registration_Config
305
+	 * @throws ReflectionException
306
+	 * @throws EE_Error
307
+	 */
308
+	public static function update_bot_trap_settings_form(EE_Registration_Config $EE_Registration_Config)
309
+	{
310
+		try {
311
+			$bot_trap_settings_form = EED_Bot_Trap::_bot_trap_settings_form();
312
+			// if not displaying a form, then check for form submission
313
+			if ($bot_trap_settings_form->was_submitted()) {
314
+				// capture form data
315
+				$bot_trap_settings_form->receive_form_submission();
316
+				// validate form data
317
+				if ($bot_trap_settings_form->is_valid()) {
318
+					// grab validated data from form
319
+					$valid_data = $bot_trap_settings_form->valid_data();
320
+					if (isset($valid_data['use_bot_trap'], $valid_data['use_encryption'])) {
321
+						$EE_Registration_Config->use_bot_trap = $valid_data['use_bot_trap'];
322
+						$EE_Registration_Config->use_encryption = $valid_data['use_encryption'];
323
+					} else {
324
+						EE_Error::add_error(esc_html__('Invalid or missing Bot Trap settings. Please refresh the form and try again.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
325
+					}
326
+				} else {
327
+					if ($bot_trap_settings_form->submission_error_message() !== '') {
328
+						EE_Error::add_error($bot_trap_settings_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__);
329
+					}
330
+				}
331
+			}
332
+		} catch (EE_Error $e) {
333
+			$e->get_error();
334
+		}
335
+		return $EE_Registration_Config;
336
+	}
337 337
 
338 338
 
339 339
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public static function set_trap()
53 53
     {
54
-        define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . DS);
54
+        define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__).DS);
55 55
         add_action(
56 56
             'AHEE__ticket_selector_chart__template__after_ticket_selector',
57 57
             array('EED_Bot_Trap', 'generate_bot_trap'),
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
         $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso');
116 116
         $time = microtime(true);
117 117
         $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">';
118
-        $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>';
118
+        $html .= '<label for="tkt-slctr-request-processor-email-'.$time.'">'.$do_not_enter.'</label>';
119 119
         $html .= '<input type="email" id="tkt-slctr-request-processor-email-';
120
-        $html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>';
120
+        $html .= $time.'" name="tkt-slctr-request-processor-email" value=""/>';
121 121
         $html .= '<input type="hidden" name="tkt-slctr-request-processor-token" value="';
122 122
         if (EE_Registry::instance()->CFG->registration->use_encryption) {
123 123
             EE_Registry::instance()->load_core('EE_Encryption');
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
         // ticket form submitted too impossibly fast ( after now ) or more than an hour later ???
160 160
         $suspicious_timing = $bot_trap_timestamp > time() || $bot_trap_timestamp < (time() - HOUR_IN_SECONDS);
161 161
         // are we human ?
162
-        if ($empty_trap && !$suspicious_timing) {
162
+        if ($empty_trap && ! $suspicious_timing) {
163 163
             do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered');
164 164
             return;
165 165
         }
166 166
         // check the given callback is valid first before executing
167
-        if (!is_callable($triggered_trap_callback)) {
167
+        if ( ! is_callable($triggered_trap_callback)) {
168 168
             // invalid callback so lets just sub in our default.
169 169
             $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response');
170 170
         }
Please login to merge, or discard this patch.
caffeinated/brewing_regular.php 1 patch
Indentation   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\database\TableAnalysis;
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
  * the purpose of this file is to simply contain any action/filter hook callbacks etc for specific aspects of EE
@@ -29,277 +29,277 @@  discard block
 block discarded – undo
29 29
 class EE_Brewing_Regular extends EE_BASE implements InterminableInterface
30 30
 {
31 31
 
32
-    /**
33
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
34
-     */
35
-    protected $_table_analysis;
36
-
37
-
38
-
39
-    /**
40
-     * EE_Brewing_Regular constructor.
41
-     */
42
-    public function __construct(TableAnalysis $table_analysis)
43
-    {
44
-        $this->_table_analysis = $table_analysis;
45
-        if (defined('EE_CAFF_PATH')) {
46
-            // activation
47
-            add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
48
-            // load caff init
49
-            add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
50
-            // remove the "powered by" credit link from receipts and invoices
51
-            add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
52
-            // add caffeinated modules
53
-            add_filter(
54
-                'FHEE__EE_Config__register_modules__modules_to_register',
55
-                array($this, 'caffeinated_modules_to_register')
56
-            );
57
-            // load caff scripts
58
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
59
-            add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
60
-            add_filter(
61
-                'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
62
-                array($this, 'caf_payment_methods')
63
-            );
64
-            // caffeinated constructed
65
-            do_action('AHEE__EE_Brewing_Regular__construct__complete');
66
-            //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
67
-            add_filter('FHEE__ee_show_affiliate_links', '__return_false');
68
-        }
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
75
-     *
76
-     * @param array $paths original helper paths array
77
-     * @return array             new array of paths
78
-     */
79
-    public function caf_helper_paths($paths)
80
-    {
81
-        $paths[] = EE_CAF_CORE . 'helpers' . DS;
82
-        return $paths;
83
-    }
84
-
85
-
86
-
87
-    /**
88
-     * Upon brand-new activation, if this is a new activation of CAF, we want to add
89
-     * some global prices that will show off EE4's capabilities. However, if they're upgrading
90
-     * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
91
-     * This action should only be called when EE 4.x.0.P is initially activated.
92
-     * Right now the only CAF content are these global prices. If there's more in the future, then
93
-     * we should probably create a caf file to contain it all instead just a function like this.
94
-     * Right now, we ASSUME the only price types in the system are default ones
95
-     *
96
-     * @global wpdb $wpdb
97
-     */
98
-    public function initialize_caf_db_content()
99
-    {
100
-        global $wpdb;
101
-        //use same method of getting creator id as the version introducing the change
102
-        $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
103
-        $price_type_table = $wpdb->prefix . "esp_price_type";
104
-        $price_table = $wpdb->prefix . "esp_price";
105
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
106
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
107
-            $tax_price_type_count = $wpdb->get_var($SQL);
108
-            if ($tax_price_type_count <= 1) {
109
-                $wpdb->insert(
110
-                    $price_type_table,
111
-                    array(
112
-                        'PRT_name'       => __("Regional Tax", "event_espresso"),
113
-                        'PBT_ID'         => 4,
114
-                        'PRT_is_percent' => true,
115
-                        'PRT_order'      => 60,
116
-                        'PRT_deleted'    => false,
117
-                        'PRT_wp_user'    => $default_creator_id,
118
-                    ),
119
-                    array(
120
-                        '%s',//PRT_name
121
-                        '%d',//PBT_id
122
-                        '%d',//PRT_is_percent
123
-                        '%d',//PRT_order
124
-                        '%d',//PRT_deleted
125
-                        '%d', //PRT_wp_user
126
-                    )
127
-                );
128
-                //federal tax
129
-                $result = $wpdb->insert(
130
-                    $price_type_table,
131
-                    array(
132
-                        'PRT_name'       => __("Federal Tax", "event_espresso"),
133
-                        'PBT_ID'         => 4,
134
-                        'PRT_is_percent' => true,
135
-                        'PRT_order'      => 70,
136
-                        'PRT_deleted'    => false,
137
-                        'PRT_wp_user'    => $default_creator_id,
138
-                    ),
139
-                    array(
140
-                        '%s',//PRT_name
141
-                        '%d',//PBT_id
142
-                        '%d',//PRT_is_percent
143
-                        '%d',//PRT_order
144
-                        '%d',//PRT_deleted
145
-                        '%d' //PRT_wp_user
146
-                    )
147
-                );
148
-                if ($result) {
149
-                    $wpdb->insert(
150
-                        $price_table,
151
-                        array(
152
-                            'PRT_ID'         => $wpdb->insert_id,
153
-                            'PRC_amount'     => 15.00,
154
-                            'PRC_name'       => __("Sales Tax", "event_espresso"),
155
-                            'PRC_desc'       => '',
156
-                            'PRC_is_default' => true,
157
-                            'PRC_overrides'  => null,
158
-                            'PRC_deleted'    => false,
159
-                            'PRC_order'      => 50,
160
-                            'PRC_parent'     => null,
161
-                            'PRC_wp_user'    => $default_creator_id,
162
-                        ),
163
-                        array(
164
-                            '%d',//PRT_id
165
-                            '%f',//PRC_amount
166
-                            '%s',//PRC_name
167
-                            '%s',//PRC_desc
168
-                            '%d',//PRC_is_default
169
-                            '%d',//PRC_overrides
170
-                            '%d',//PRC_deleted
171
-                            '%d',//PRC_order
172
-                            '%d',//PRC_parent
173
-                            '%d' //PRC_wp_user
174
-                        )
175
-                    );
176
-                }
177
-            }
178
-        }
179
-    }
180
-
181
-
182
-
183
-    /**
184
-     *    caffeinated_modules_to_register
185
-     *
186
-     * @access public
187
-     * @param array $modules_to_register
188
-     * @return array
189
-     */
190
-    public function caffeinated_modules_to_register($modules_to_register = array())
191
-    {
192
-        if (is_readable(EE_CAFF_PATH . 'modules')) {
193
-            $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
194
-            if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
195
-                $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
196
-            }
197
-        }
198
-        return $modules_to_register;
199
-    }
200
-
201
-
202
-
203
-    public function caffeinated_init()
204
-    {
205
-        // EE_Register_CPTs hooks
206
-        add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10);
207
-        add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10);
208
-        add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10);
209
-        EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false);
210
-        // caffeinated_init__complete hook
211
-        do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
212
-    }
213
-
214
-
215
-
216
-    public function enqueue_caffeinated_scripts()
217
-    {
218
-        // sound of crickets...
219
-    }
220
-
221
-
222
-
223
-    /**
224
-     * callbacks below here
225
-     *
226
-     * @param array $taxonomy_array
227
-     * @return array
228
-     */
229
-    public function filter_taxonomies(array $taxonomy_array)
230
-    {
231
-        $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
232
-        return $taxonomy_array;
233
-    }
234
-
235
-
236
-
237
-    /**
238
-     * @param array $cpt_array
239
-     * @return mixed
240
-     */
241
-    public function filter_cpts(array $cpt_array)
242
-    {
243
-        $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
244
-        return $cpt_array;
245
-    }
246
-
247
-
248
-
249
-    /**
250
-     * @param array $menuitems
251
-     * @return array
252
-     */
253
-    public function nav_metabox_items(array $menuitems)
254
-    {
255
-        $menuitems[] = array(
256
-            'title'       => __('Venue List', 'event_espresso'),
257
-            'url'         => get_post_type_archive_link('espresso_venues'),
258
-            'description' => __('Archive page for all venues.', 'event_espresso'),
259
-        );
260
-        return $menuitems;
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods
267
-     *
268
-     * @param array $payment_method_paths
269
-     * @return array values are folder paths to payment method folders
270
-     */
271
-    public function caf_payment_methods($payment_method_paths)
272
-    {
273
-        $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
274
-        $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths);
275
-        return $payment_method_paths;
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * Gets the injected table analyzer, or throws an exception
282
-     *
283
-     * @return TableAnalysis
284
-     * @throws \EE_Error
285
-     */
286
-    protected function _get_table_analysis()
287
-    {
288
-        if ($this->_table_analysis instanceof TableAnalysis) {
289
-            return $this->_table_analysis;
290
-        } else {
291
-            throw new \EE_Error(
292
-                sprintf(
293
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
294
-                    get_class($this)
295
-                )
296
-            );
297
-        }
298
-    }
32
+	/**
33
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
34
+	 */
35
+	protected $_table_analysis;
36
+
37
+
38
+
39
+	/**
40
+	 * EE_Brewing_Regular constructor.
41
+	 */
42
+	public function __construct(TableAnalysis $table_analysis)
43
+	{
44
+		$this->_table_analysis = $table_analysis;
45
+		if (defined('EE_CAFF_PATH')) {
46
+			// activation
47
+			add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
48
+			// load caff init
49
+			add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
50
+			// remove the "powered by" credit link from receipts and invoices
51
+			add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
52
+			// add caffeinated modules
53
+			add_filter(
54
+				'FHEE__EE_Config__register_modules__modules_to_register',
55
+				array($this, 'caffeinated_modules_to_register')
56
+			);
57
+			// load caff scripts
58
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
59
+			add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
60
+			add_filter(
61
+				'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
62
+				array($this, 'caf_payment_methods')
63
+			);
64
+			// caffeinated constructed
65
+			do_action('AHEE__EE_Brewing_Regular__construct__complete');
66
+			//seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
67
+			add_filter('FHEE__ee_show_affiliate_links', '__return_false');
68
+		}
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
75
+	 *
76
+	 * @param array $paths original helper paths array
77
+	 * @return array             new array of paths
78
+	 */
79
+	public function caf_helper_paths($paths)
80
+	{
81
+		$paths[] = EE_CAF_CORE . 'helpers' . DS;
82
+		return $paths;
83
+	}
84
+
85
+
86
+
87
+	/**
88
+	 * Upon brand-new activation, if this is a new activation of CAF, we want to add
89
+	 * some global prices that will show off EE4's capabilities. However, if they're upgrading
90
+	 * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
91
+	 * This action should only be called when EE 4.x.0.P is initially activated.
92
+	 * Right now the only CAF content are these global prices. If there's more in the future, then
93
+	 * we should probably create a caf file to contain it all instead just a function like this.
94
+	 * Right now, we ASSUME the only price types in the system are default ones
95
+	 *
96
+	 * @global wpdb $wpdb
97
+	 */
98
+	public function initialize_caf_db_content()
99
+	{
100
+		global $wpdb;
101
+		//use same method of getting creator id as the version introducing the change
102
+		$default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
103
+		$price_type_table = $wpdb->prefix . "esp_price_type";
104
+		$price_table = $wpdb->prefix . "esp_price";
105
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
106
+			$SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
107
+			$tax_price_type_count = $wpdb->get_var($SQL);
108
+			if ($tax_price_type_count <= 1) {
109
+				$wpdb->insert(
110
+					$price_type_table,
111
+					array(
112
+						'PRT_name'       => __("Regional Tax", "event_espresso"),
113
+						'PBT_ID'         => 4,
114
+						'PRT_is_percent' => true,
115
+						'PRT_order'      => 60,
116
+						'PRT_deleted'    => false,
117
+						'PRT_wp_user'    => $default_creator_id,
118
+					),
119
+					array(
120
+						'%s',//PRT_name
121
+						'%d',//PBT_id
122
+						'%d',//PRT_is_percent
123
+						'%d',//PRT_order
124
+						'%d',//PRT_deleted
125
+						'%d', //PRT_wp_user
126
+					)
127
+				);
128
+				//federal tax
129
+				$result = $wpdb->insert(
130
+					$price_type_table,
131
+					array(
132
+						'PRT_name'       => __("Federal Tax", "event_espresso"),
133
+						'PBT_ID'         => 4,
134
+						'PRT_is_percent' => true,
135
+						'PRT_order'      => 70,
136
+						'PRT_deleted'    => false,
137
+						'PRT_wp_user'    => $default_creator_id,
138
+					),
139
+					array(
140
+						'%s',//PRT_name
141
+						'%d',//PBT_id
142
+						'%d',//PRT_is_percent
143
+						'%d',//PRT_order
144
+						'%d',//PRT_deleted
145
+						'%d' //PRT_wp_user
146
+					)
147
+				);
148
+				if ($result) {
149
+					$wpdb->insert(
150
+						$price_table,
151
+						array(
152
+							'PRT_ID'         => $wpdb->insert_id,
153
+							'PRC_amount'     => 15.00,
154
+							'PRC_name'       => __("Sales Tax", "event_espresso"),
155
+							'PRC_desc'       => '',
156
+							'PRC_is_default' => true,
157
+							'PRC_overrides'  => null,
158
+							'PRC_deleted'    => false,
159
+							'PRC_order'      => 50,
160
+							'PRC_parent'     => null,
161
+							'PRC_wp_user'    => $default_creator_id,
162
+						),
163
+						array(
164
+							'%d',//PRT_id
165
+							'%f',//PRC_amount
166
+							'%s',//PRC_name
167
+							'%s',//PRC_desc
168
+							'%d',//PRC_is_default
169
+							'%d',//PRC_overrides
170
+							'%d',//PRC_deleted
171
+							'%d',//PRC_order
172
+							'%d',//PRC_parent
173
+							'%d' //PRC_wp_user
174
+						)
175
+					);
176
+				}
177
+			}
178
+		}
179
+	}
180
+
181
+
182
+
183
+	/**
184
+	 *    caffeinated_modules_to_register
185
+	 *
186
+	 * @access public
187
+	 * @param array $modules_to_register
188
+	 * @return array
189
+	 */
190
+	public function caffeinated_modules_to_register($modules_to_register = array())
191
+	{
192
+		if (is_readable(EE_CAFF_PATH . 'modules')) {
193
+			$caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
194
+			if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
195
+				$modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
196
+			}
197
+		}
198
+		return $modules_to_register;
199
+	}
200
+
201
+
202
+
203
+	public function caffeinated_init()
204
+	{
205
+		// EE_Register_CPTs hooks
206
+		add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10);
207
+		add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10);
208
+		add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10);
209
+		EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false);
210
+		// caffeinated_init__complete hook
211
+		do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
212
+	}
213
+
214
+
215
+
216
+	public function enqueue_caffeinated_scripts()
217
+	{
218
+		// sound of crickets...
219
+	}
220
+
221
+
222
+
223
+	/**
224
+	 * callbacks below here
225
+	 *
226
+	 * @param array $taxonomy_array
227
+	 * @return array
228
+	 */
229
+	public function filter_taxonomies(array $taxonomy_array)
230
+	{
231
+		$taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
232
+		return $taxonomy_array;
233
+	}
234
+
235
+
236
+
237
+	/**
238
+	 * @param array $cpt_array
239
+	 * @return mixed
240
+	 */
241
+	public function filter_cpts(array $cpt_array)
242
+	{
243
+		$cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
244
+		return $cpt_array;
245
+	}
246
+
247
+
248
+
249
+	/**
250
+	 * @param array $menuitems
251
+	 * @return array
252
+	 */
253
+	public function nav_metabox_items(array $menuitems)
254
+	{
255
+		$menuitems[] = array(
256
+			'title'       => __('Venue List', 'event_espresso'),
257
+			'url'         => get_post_type_archive_link('espresso_venues'),
258
+			'description' => __('Archive page for all venues.', 'event_espresso'),
259
+		);
260
+		return $menuitems;
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods
267
+	 *
268
+	 * @param array $payment_method_paths
269
+	 * @return array values are folder paths to payment method folders
270
+	 */
271
+	public function caf_payment_methods($payment_method_paths)
272
+	{
273
+		$caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
274
+		$payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths);
275
+		return $payment_method_paths;
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * Gets the injected table analyzer, or throws an exception
282
+	 *
283
+	 * @return TableAnalysis
284
+	 * @throws \EE_Error
285
+	 */
286
+	protected function _get_table_analysis()
287
+	{
288
+		if ($this->_table_analysis instanceof TableAnalysis) {
289
+			return $this->_table_analysis;
290
+		} else {
291
+			throw new \EE_Error(
292
+				sprintf(
293
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
294
+					get_class($this)
295
+				)
296
+			);
297
+		}
298
+	}
299 299
 }
300 300
 
301 301
 
302 302
 
303 303
 $brewing = new EE_Brewing_Regular(
304
-    EE_Registry::instance()->create('TableAnalysis', array(), true)
304
+	EE_Registry::instance()->create('TableAnalysis', array(), true)
305 305
 );
306 306
\ No newline at end of file
Please login to merge, or discard this patch.
core/EE_Cart.core.php 1 patch
Indentation   +413 added lines, -413 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\interfaces\ResettableInterface;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 do_action('AHEE_log', __FILE__, __FUNCTION__, '');
8 8
 
@@ -23,418 +23,418 @@  discard block
 block discarded – undo
23 23
 class EE_Cart implements ResettableInterface
24 24
 {
25 25
 
26
-    /**
27
-     * instance of the EE_Cart object
28
-     *
29
-     * @access    private
30
-     * @var EE_Cart $_instance
31
-     */
32
-    private static $_instance;
33
-
34
-    /**
35
-     * instance of the EE_Session object
36
-     *
37
-     * @access    protected
38
-     * @var EE_Session $_session
39
-     */
40
-    protected $_session;
41
-
42
-    /**
43
-     * The total Line item which comprises all the children line-item subtotals,
44
-     * which in turn each have their line items.
45
-     * Typically, the line item structure will look like:
46
-     * grand total
47
-     * -tickets-sub-total
48
-     * --ticket1
49
-     * --ticket2
50
-     * --...
51
-     * -taxes-sub-total
52
-     * --tax1
53
-     * --tax2
54
-     *
55
-     * @var EE_Line_Item
56
-     */
57
-    private $_grand_total;
58
-
59
-
60
-
61
-    /**
62
-     * @singleton method used to instantiate class object
63
-     * @access    public
64
-     * @param EE_Line_Item $grand_total
65
-     * @param EE_Session   $session
66
-     * @return \EE_Cart
67
-     * @throws \EE_Error
68
-     */
69
-    public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
70
-    {
71
-        if ( ! empty($grand_total)) {
72
-            self::$_instance = new self($grand_total, $session);
73
-        }
74
-        // or maybe retrieve an existing one ?
75
-        if ( ! self::$_instance instanceof EE_Cart) {
76
-            // try getting the cart out of the session
77
-            $saved_cart = $session instanceof EE_Session ? $session->cart() : null;
78
-            self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
79
-            unset($saved_cart);
80
-        }
81
-        // verify that cart is ok and grand total line item exists
82
-        if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
83
-            self::$_instance = new self($grand_total, $session);
84
-        }
85
-        self::$_instance->get_grand_total();
86
-        // once everything is all said and done, save the cart to the EE_Session
87
-        add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
88
-        return self::$_instance;
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * private constructor to prevent direct creation
95
-     *
96
-     * @Constructor
97
-     * @access private
98
-     * @param EE_Line_Item $grand_total
99
-     * @param EE_Session   $session
100
-     */
101
-    private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
102
-    {
103
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
104
-        $this->set_session($session);
105
-        if ($grand_total instanceof EE_Line_Item) {
106
-            $this->set_grand_total_line_item($grand_total);
107
-        }
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * Resets the cart completely (whereas empty_cart
114
-     *
115
-     * @param EE_Line_Item $grand_total
116
-     * @param EE_Session   $session
117
-     * @return EE_Cart
118
-     * @throws \EE_Error
119
-     */
120
-    public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
121
-    {
122
-        remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
123
-        if ($session instanceof EE_Session) {
124
-            $session->reset_cart();
125
-        }
126
-        self::$_instance = null;
127
-        return self::instance($grand_total, $session);
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return \EE_Session
134
-     */
135
-    public function session()
136
-    {
137
-        if ( ! $this->_session instanceof EE_Session) {
138
-            $this->set_session();
139
-        }
140
-        return $this->_session;
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * @param EE_Session $session
147
-     */
148
-    public function set_session(EE_Session $session = null)
149
-    {
150
-        $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Sets the cart to match the line item. Especially handy for loading an old cart where you
157
-     *  know the grand total line item on it
158
-     *
159
-     * @param EE_Line_Item $line_item
160
-     */
161
-    public function set_grand_total_line_item(EE_Line_Item $line_item)
162
-    {
163
-        $this->_grand_total = $line_item;
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * get_cart_from_reg_url_link
170
-     *
171
-     * @access public
172
-     * @param EE_Transaction $transaction
173
-     * @param EE_Session     $session
174
-     * @return \EE_Cart
175
-     * @throws \EE_Error
176
-     */
177
-    public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
178
-    {
179
-        $grand_total = $transaction->total_line_item();
180
-        $grand_total->get_items();
181
-        $grand_total->tax_descendants();
182
-        return EE_Cart::instance($grand_total, $session);
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
189
-     *
190
-     * @return EE_Line_Item
191
-     * @throws \EE_Error
192
-     */
193
-    private function _create_grand_total()
194
-    {
195
-        $this->_grand_total = EEH_Line_Item::create_total_line_item();
196
-        return $this->_grand_total;
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * Gets all the line items of object type Ticket
203
-     *
204
-     * @access public
205
-     * @return \EE_Line_Item[]
206
-     */
207
-    public function get_tickets()
208
-    {
209
-        if ($this->_grand_total === null ) {
210
-            return array();
211
-        }
212
-        return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * returns the total quantity of tickets in the cart
219
-     *
220
-     * @access public
221
-     * @return int
222
-     * @throws \EE_Error
223
-     */
224
-    public function all_ticket_quantity_count()
225
-    {
226
-        $tickets = $this->get_tickets();
227
-        if (empty($tickets)) {
228
-            return 0;
229
-        }
230
-        $count = 0;
231
-        foreach ($tickets as $ticket) {
232
-            $count += $ticket->get('LIN_quantity');
233
-        }
234
-        return $count;
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * Gets all the tax line items
241
-     *
242
-     * @return \EE_Line_Item[]
243
-     * @throws \EE_Error
244
-     */
245
-    public function get_taxes()
246
-    {
247
-        return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * Gets the total line item (which is a parent of all other line items) on this cart
254
-     *
255
-     * @return EE_Line_Item
256
-     * @throws \EE_Error
257
-     */
258
-    public function get_grand_total()
259
-    {
260
-        return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * @process items for adding to cart
267
-     * @access  public
268
-     * @param EE_Ticket $ticket
269
-     * @param int       $qty
270
-     * @return TRUE on success, FALSE on fail
271
-     * @throws \EE_Error
272
-     */
273
-    public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
274
-    {
275
-        EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
276
-        return $this->save_cart() ? true : false;
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * get_cart_total_before_tax
283
-     *
284
-     * @access public
285
-     * @return float
286
-     * @throws \EE_Error
287
-     */
288
-    public function get_cart_total_before_tax()
289
-    {
290
-        return $this->get_grand_total()->recalculate_pre_tax_total();
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * gets the total amount of tax paid for items in this cart
297
-     *
298
-     * @access public
299
-     * @return float
300
-     * @throws \EE_Error
301
-     */
302
-    public function get_applied_taxes()
303
-    {
304
-        return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
305
-    }
306
-
307
-
308
-
309
-    /**
310
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
311
-     *
312
-     * @access public
313
-     * @return float
314
-     * @throws \EE_Error
315
-     */
316
-    public function get_cart_grand_total()
317
-    {
318
-        EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
319
-        return $this->get_grand_total()->total();
320
-    }
321
-
322
-
323
-
324
-    /**
325
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
326
-     *
327
-     * @access public
328
-     * @return float
329
-     * @throws \EE_Error
330
-     */
331
-    public function recalculate_all_cart_totals()
332
-    {
333
-        $pre_tax_total = $this->get_cart_total_before_tax();
334
-        $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
335
-        $this->_grand_total->set_total($pre_tax_total + $taxes_total);
336
-        $this->_grand_total->save_this_and_descendants_to_txn();
337
-        return $this->get_grand_total()->total();
338
-    }
339
-
340
-
341
-
342
-    /**
343
-     * deletes an item from the cart
344
-     *
345
-     * @access public
346
-     * @param array|bool|string $line_item_codes
347
-     * @return int on success, FALSE on fail
348
-     * @throws \EE_Error
349
-     */
350
-    public function delete_items($line_item_codes = false)
351
-    {
352
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
353
-        return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * @remove ALL items from cart and zero ALL totals
360
-     * @access public
361
-     * @return bool
362
-     * @throws \EE_Error
363
-     */
364
-    public function empty_cart()
365
-    {
366
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
367
-        $this->_grand_total = $this->_create_grand_total();
368
-        return $this->save_cart(true);
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * @remove ALL items from cart and delete total as well
375
-     * @access public
376
-     * @return bool
377
-     * @throws \EE_Error
378
-     */
379
-    public function delete_cart()
380
-    {
381
-        $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
382
-        if ($deleted) {
383
-            $deleted += $this->_grand_total->delete();
384
-            $this->_grand_total = null;
385
-        }
386
-        return $deleted;
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * @save   cart to session
393
-     * @access public
394
-     * @param bool $apply_taxes
395
-     * @return TRUE on success, FALSE on fail
396
-     * @throws \EE_Error
397
-     */
398
-    public function save_cart($apply_taxes = true)
399
-    {
400
-        if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
401
-            EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
402
-            //make sure we don't cache the transaction because it can get stale
403
-            if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
404
-                && $this->_grand_total->get_one_from_cache('Transaction')->ID()
405
-            ) {
406
-                $this->_grand_total->clear_cache('Transaction', null, true);
407
-            }
408
-        }
409
-        if ($this->session() instanceof EE_Session) {
410
-            return $this->session()->set_cart($this);
411
-        } else {
412
-            return false;
413
-        }
414
-    }
415
-
416
-
417
-
418
-    public function __wakeup()
419
-    {
420
-        if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
421
-            // $this->_grand_total is actually just an ID, so use it to get the object from the db
422
-            $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
423
-        }
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * @return array
430
-     */
431
-    public function __sleep()
432
-    {
433
-        if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
434
-            $this->_grand_total = $this->_grand_total->ID();
435
-        }
436
-        return array('_grand_total');
437
-    }
26
+	/**
27
+	 * instance of the EE_Cart object
28
+	 *
29
+	 * @access    private
30
+	 * @var EE_Cart $_instance
31
+	 */
32
+	private static $_instance;
33
+
34
+	/**
35
+	 * instance of the EE_Session object
36
+	 *
37
+	 * @access    protected
38
+	 * @var EE_Session $_session
39
+	 */
40
+	protected $_session;
41
+
42
+	/**
43
+	 * The total Line item which comprises all the children line-item subtotals,
44
+	 * which in turn each have their line items.
45
+	 * Typically, the line item structure will look like:
46
+	 * grand total
47
+	 * -tickets-sub-total
48
+	 * --ticket1
49
+	 * --ticket2
50
+	 * --...
51
+	 * -taxes-sub-total
52
+	 * --tax1
53
+	 * --tax2
54
+	 *
55
+	 * @var EE_Line_Item
56
+	 */
57
+	private $_grand_total;
58
+
59
+
60
+
61
+	/**
62
+	 * @singleton method used to instantiate class object
63
+	 * @access    public
64
+	 * @param EE_Line_Item $grand_total
65
+	 * @param EE_Session   $session
66
+	 * @return \EE_Cart
67
+	 * @throws \EE_Error
68
+	 */
69
+	public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
70
+	{
71
+		if ( ! empty($grand_total)) {
72
+			self::$_instance = new self($grand_total, $session);
73
+		}
74
+		// or maybe retrieve an existing one ?
75
+		if ( ! self::$_instance instanceof EE_Cart) {
76
+			// try getting the cart out of the session
77
+			$saved_cart = $session instanceof EE_Session ? $session->cart() : null;
78
+			self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
79
+			unset($saved_cart);
80
+		}
81
+		// verify that cart is ok and grand total line item exists
82
+		if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
83
+			self::$_instance = new self($grand_total, $session);
84
+		}
85
+		self::$_instance->get_grand_total();
86
+		// once everything is all said and done, save the cart to the EE_Session
87
+		add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
88
+		return self::$_instance;
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * private constructor to prevent direct creation
95
+	 *
96
+	 * @Constructor
97
+	 * @access private
98
+	 * @param EE_Line_Item $grand_total
99
+	 * @param EE_Session   $session
100
+	 */
101
+	private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
102
+	{
103
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
104
+		$this->set_session($session);
105
+		if ($grand_total instanceof EE_Line_Item) {
106
+			$this->set_grand_total_line_item($grand_total);
107
+		}
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * Resets the cart completely (whereas empty_cart
114
+	 *
115
+	 * @param EE_Line_Item $grand_total
116
+	 * @param EE_Session   $session
117
+	 * @return EE_Cart
118
+	 * @throws \EE_Error
119
+	 */
120
+	public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
121
+	{
122
+		remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
123
+		if ($session instanceof EE_Session) {
124
+			$session->reset_cart();
125
+		}
126
+		self::$_instance = null;
127
+		return self::instance($grand_total, $session);
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return \EE_Session
134
+	 */
135
+	public function session()
136
+	{
137
+		if ( ! $this->_session instanceof EE_Session) {
138
+			$this->set_session();
139
+		}
140
+		return $this->_session;
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * @param EE_Session $session
147
+	 */
148
+	public function set_session(EE_Session $session = null)
149
+	{
150
+		$this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Sets the cart to match the line item. Especially handy for loading an old cart where you
157
+	 *  know the grand total line item on it
158
+	 *
159
+	 * @param EE_Line_Item $line_item
160
+	 */
161
+	public function set_grand_total_line_item(EE_Line_Item $line_item)
162
+	{
163
+		$this->_grand_total = $line_item;
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * get_cart_from_reg_url_link
170
+	 *
171
+	 * @access public
172
+	 * @param EE_Transaction $transaction
173
+	 * @param EE_Session     $session
174
+	 * @return \EE_Cart
175
+	 * @throws \EE_Error
176
+	 */
177
+	public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
178
+	{
179
+		$grand_total = $transaction->total_line_item();
180
+		$grand_total->get_items();
181
+		$grand_total->tax_descendants();
182
+		return EE_Cart::instance($grand_total, $session);
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
189
+	 *
190
+	 * @return EE_Line_Item
191
+	 * @throws \EE_Error
192
+	 */
193
+	private function _create_grand_total()
194
+	{
195
+		$this->_grand_total = EEH_Line_Item::create_total_line_item();
196
+		return $this->_grand_total;
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * Gets all the line items of object type Ticket
203
+	 *
204
+	 * @access public
205
+	 * @return \EE_Line_Item[]
206
+	 */
207
+	public function get_tickets()
208
+	{
209
+		if ($this->_grand_total === null ) {
210
+			return array();
211
+		}
212
+		return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * returns the total quantity of tickets in the cart
219
+	 *
220
+	 * @access public
221
+	 * @return int
222
+	 * @throws \EE_Error
223
+	 */
224
+	public function all_ticket_quantity_count()
225
+	{
226
+		$tickets = $this->get_tickets();
227
+		if (empty($tickets)) {
228
+			return 0;
229
+		}
230
+		$count = 0;
231
+		foreach ($tickets as $ticket) {
232
+			$count += $ticket->get('LIN_quantity');
233
+		}
234
+		return $count;
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * Gets all the tax line items
241
+	 *
242
+	 * @return \EE_Line_Item[]
243
+	 * @throws \EE_Error
244
+	 */
245
+	public function get_taxes()
246
+	{
247
+		return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * Gets the total line item (which is a parent of all other line items) on this cart
254
+	 *
255
+	 * @return EE_Line_Item
256
+	 * @throws \EE_Error
257
+	 */
258
+	public function get_grand_total()
259
+	{
260
+		return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * @process items for adding to cart
267
+	 * @access  public
268
+	 * @param EE_Ticket $ticket
269
+	 * @param int       $qty
270
+	 * @return TRUE on success, FALSE on fail
271
+	 * @throws \EE_Error
272
+	 */
273
+	public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
274
+	{
275
+		EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
276
+		return $this->save_cart() ? true : false;
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * get_cart_total_before_tax
283
+	 *
284
+	 * @access public
285
+	 * @return float
286
+	 * @throws \EE_Error
287
+	 */
288
+	public function get_cart_total_before_tax()
289
+	{
290
+		return $this->get_grand_total()->recalculate_pre_tax_total();
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * gets the total amount of tax paid for items in this cart
297
+	 *
298
+	 * @access public
299
+	 * @return float
300
+	 * @throws \EE_Error
301
+	 */
302
+	public function get_applied_taxes()
303
+	{
304
+		return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
305
+	}
306
+
307
+
308
+
309
+	/**
310
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
311
+	 *
312
+	 * @access public
313
+	 * @return float
314
+	 * @throws \EE_Error
315
+	 */
316
+	public function get_cart_grand_total()
317
+	{
318
+		EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
319
+		return $this->get_grand_total()->total();
320
+	}
321
+
322
+
323
+
324
+	/**
325
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
326
+	 *
327
+	 * @access public
328
+	 * @return float
329
+	 * @throws \EE_Error
330
+	 */
331
+	public function recalculate_all_cart_totals()
332
+	{
333
+		$pre_tax_total = $this->get_cart_total_before_tax();
334
+		$taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
335
+		$this->_grand_total->set_total($pre_tax_total + $taxes_total);
336
+		$this->_grand_total->save_this_and_descendants_to_txn();
337
+		return $this->get_grand_total()->total();
338
+	}
339
+
340
+
341
+
342
+	/**
343
+	 * deletes an item from the cart
344
+	 *
345
+	 * @access public
346
+	 * @param array|bool|string $line_item_codes
347
+	 * @return int on success, FALSE on fail
348
+	 * @throws \EE_Error
349
+	 */
350
+	public function delete_items($line_item_codes = false)
351
+	{
352
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
353
+		return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * @remove ALL items from cart and zero ALL totals
360
+	 * @access public
361
+	 * @return bool
362
+	 * @throws \EE_Error
363
+	 */
364
+	public function empty_cart()
365
+	{
366
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
367
+		$this->_grand_total = $this->_create_grand_total();
368
+		return $this->save_cart(true);
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * @remove ALL items from cart and delete total as well
375
+	 * @access public
376
+	 * @return bool
377
+	 * @throws \EE_Error
378
+	 */
379
+	public function delete_cart()
380
+	{
381
+		$deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
382
+		if ($deleted) {
383
+			$deleted += $this->_grand_total->delete();
384
+			$this->_grand_total = null;
385
+		}
386
+		return $deleted;
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * @save   cart to session
393
+	 * @access public
394
+	 * @param bool $apply_taxes
395
+	 * @return TRUE on success, FALSE on fail
396
+	 * @throws \EE_Error
397
+	 */
398
+	public function save_cart($apply_taxes = true)
399
+	{
400
+		if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
401
+			EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
402
+			//make sure we don't cache the transaction because it can get stale
403
+			if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
404
+				&& $this->_grand_total->get_one_from_cache('Transaction')->ID()
405
+			) {
406
+				$this->_grand_total->clear_cache('Transaction', null, true);
407
+			}
408
+		}
409
+		if ($this->session() instanceof EE_Session) {
410
+			return $this->session()->set_cart($this);
411
+		} else {
412
+			return false;
413
+		}
414
+	}
415
+
416
+
417
+
418
+	public function __wakeup()
419
+	{
420
+		if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
421
+			// $this->_grand_total is actually just an ID, so use it to get the object from the db
422
+			$this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
423
+		}
424
+	}
425
+
426
+
427
+
428
+	/**
429
+	 * @return array
430
+	 */
431
+	public function __sleep()
432
+	{
433
+		if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
434
+			$this->_grand_total = $this->_grand_total->ID();
435
+		}
436
+		return array('_grand_total');
437
+	}
438 438
 
439 439
 
440 440
 }
Please login to merge, or discard this patch.
core/EE_Payment_Processor.core.php 1 patch
Indentation   +745 added lines, -745 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\interfaces\ResettableInterface;
2 2
 
3 3
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 EE_Registry::instance()->load_class('Processor_Base');
7 7
 
@@ -18,748 +18,748 @@  discard block
 block discarded – undo
18 18
 class EE_Payment_Processor extends EE_Processor_Base implements ResettableInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Payment_Processor $_instance
23
-     * @access    private
24
-     */
25
-    private static $_instance;
26
-
27
-
28
-
29
-    /**
30
-     * @singleton method used to instantiate class object
31
-     * @access    public
32
-     * @return EE_Payment_Processor instance
33
-     */
34
-    public static function instance()
35
-    {
36
-        // check if class object is instantiated
37
-        if ( ! self::$_instance instanceof EE_Payment_Processor) {
38
-            self::$_instance = new self();
39
-        }
40
-        return self::$_instance;
41
-    }
42
-
43
-
44
-
45
-    /**
46
-     * @return EE_Payment_Processor
47
-     */
48
-    public static function reset()
49
-    {
50
-        self::$_instance = null;
51
-        return self::instance();
52
-    }
53
-
54
-
55
-
56
-    /**
57
-     *private constructor to prevent direct creation
58
-     *
59
-     * @Constructor
60
-     * @access private
61
-     */
62
-    private function __construct()
63
-    {
64
-        do_action('AHEE__EE_Payment_Processor__construct');
65
-        add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * Using the selected gateway, processes the payment for that transaction, and updates the transaction
72
-     * appropriately. Saves the payment that is generated
73
-     *
74
-     * @param EE_Payment_Method    $payment_method
75
-     * @param EE_Transaction       $transaction
76
-     * @param float                $amount       if only part of the transaction is to be paid for, how much.
77
-     *                                           Leave null if payment is for the full amount owing
78
-     * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
79
-     *                                           Receive_form_submission() should have
80
-     *                                           already been called on the billing form
81
-     *                                           (ie, its inputs should have their normalized values set).
82
-     * @param string               $return_url   string used mostly by offsite gateways to specify
83
-     *                                           where to go AFTER the offsite gateway
84
-     * @param string               $method       like 'CART', indicates who the client who called this was
85
-     * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
86
-     * @param boolean              $update_txn   whether or not to call
87
-     *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
88
-     * @param string               $cancel_url   URL to return to if off-site payments are cancelled
89
-     * @return \EE_Payment
90
-     * @throws \EE_Error
91
-     */
92
-    public function process_payment(
93
-        EE_Payment_Method $payment_method,
94
-        EE_Transaction $transaction,
95
-        $amount = null,
96
-        $billing_form = null,
97
-        $return_url = null,
98
-        $method = 'CART',
99
-        $by_admin = false,
100
-        $update_txn = true,
101
-        $cancel_url = ''
102
-    ) {
103
-        if ((float)$amount < 0) {
104
-            throw new EE_Error(
105
-                sprintf(
106
-                    __(
107
-                        'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
108
-                        'event_espresso'
109
-                    ),
110
-                    $amount,
111
-                    $transaction->ID()
112
-                )
113
-            );
114
-        }
115
-        // verify payment method
116
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
117
-        // verify transaction
118
-        EEM_Transaction::instance()->ensure_is_obj($transaction);
119
-        $transaction->set_payment_method_ID($payment_method->ID());
120
-        // verify payment method type
121
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
122
-            $payment = $payment_method->type_obj()->process_payment(
123
-                $transaction,
124
-                min($amount, $transaction->remaining()),//make sure we don't overcharge
125
-                $billing_form,
126
-                $return_url,
127
-                add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
128
-                $method,
129
-                $by_admin
130
-            );
131
-            // check if payment method uses an off-site gateway
132
-            if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
133
-                // don't process payments for off-site gateways yet because no payment has occurred yet
134
-                $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
135
-            }
136
-            return $payment;
137
-        } else {
138
-            EE_Error::add_error(
139
-                sprintf(
140
-                    __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
141
-                    '<br/>',
142
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
143
-                ), __FILE__, __FUNCTION__, __LINE__
144
-            );
145
-            return null;
146
-        }
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * @param EE_Transaction|int $transaction
153
-     * @param EE_Payment_Method  $payment_method
154
-     * @throws EE_Error
155
-     * @return string
156
-     */
157
-    public function get_ipn_url_for_payment_method($transaction, $payment_method)
158
-    {
159
-        /** @type \EE_Transaction $transaction */
160
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
161
-        $primary_reg = $transaction->primary_registration();
162
-        if ( ! $primary_reg instanceof EE_Registration) {
163
-            throw new EE_Error(
164
-                sprintf(
165
-                    __(
166
-                        "Cannot get IPN URL for transaction with ID %d because it has no primary registration",
167
-                        "event_espresso"
168
-                    ),
169
-                    $transaction->ID()
170
-                )
171
-            );
172
-        }
173
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
174
-        $url = add_query_arg(
175
-            array(
176
-                'e_reg_url_link'    => $primary_reg->reg_url_link(),
177
-                'ee_payment_method' => $payment_method->slug(),
178
-            ),
179
-            EE_Registry::instance()->CFG->core->txn_page_url()
180
-        );
181
-        return $url;
182
-    }
183
-
184
-
185
-
186
-    /**
187
-     * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
188
-     * we can easily find what registration the IPN is for and what payment method.
189
-     * However, if not, we'll give all payment methods a chance to claim it and process it.
190
-     * If a payment is found for the IPN info, it is saved.
191
-     *
192
-     * @param array              $_req_data            eg $_REQUEST
193
-     * @param EE_Transaction|int $transaction          optional (or a transactions id)
194
-     * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
195
-     * @param boolean            $update_txn           whether or not to call
196
-     *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
197
-     * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
198
-     *                                                 or is processed manually ( false like Mijireh )
199
-     * @throws EE_Error
200
-     * @throws Exception
201
-     * @return EE_Payment
202
-     */
203
-    public function process_ipn(
204
-        $_req_data,
205
-        $transaction = null,
206
-        $payment_method = null,
207
-        $update_txn = true,
208
-        $separate_IPN_request = true
209
-    ) {
210
-        EE_Registry::instance()->load_model('Change_Log');
211
-        $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data);
212
-        EE_Processor_Base::set_IPN($separate_IPN_request);
213
-        $obj_for_log = null;
214
-        if ($transaction instanceof EE_Transaction) {
215
-            $obj_for_log = $transaction;
216
-            if ($payment_method instanceof EE_Payment_Method) {
217
-                $obj_for_log = EEM_Payment::instance()->get_one(
218
-                    array(
219
-                        array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
220
-                        'order_by' => array('PAY_timestamp' => 'desc'),
221
-                    )
222
-                );
223
-            }
224
-        } else if ($payment_method instanceof EE_Payment) {
225
-            $obj_for_log = $payment_method;
226
-        }
227
-        $log = EEM_Change_Log::instance()->log(
228
-            EEM_Change_Log::type_gateway,
229
-            array('IPN data received' => $_req_data),
230
-            $obj_for_log
231
-        );
232
-        try {
233
-            /**
234
-             * @var EE_Payment $payment
235
-             */
236
-            $payment = null;
237
-            if ($transaction && $payment_method) {
238
-                /** @type EE_Transaction $transaction */
239
-                $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
240
-                /** @type EE_Payment_Method $payment_method */
241
-                $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
242
-                if ($payment_method->type_obj() instanceof EE_PMT_Base) {
243
-                    try {
244
-                        $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
245
-                        $log->set_object($payment);
246
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
247
-                        EEM_Change_Log::instance()->log(
248
-                            EEM_Change_Log::type_gateway,
249
-                            array(
250
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
251
-                                'current_url' => EEH_URL::current_url(),
252
-                                'payment'     => $e->getPaymentProperties(),
253
-                                'IPN_data'    => $e->getIpnData(),
254
-                            ),
255
-                            $obj_for_log
256
-                        );
257
-                        return $e->getPayment();
258
-                    }
259
-                } else {
260
-                    // not a payment
261
-                    EE_Error::add_error(
262
-                        sprintf(
263
-                            __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'),
264
-                            '<br/>',
265
-                            EE_Registry::instance()->CFG->organization->get_pretty('email')
266
-                        ),
267
-                        __FILE__, __FUNCTION__, __LINE__
268
-                    );
269
-                }
270
-            } else {
271
-                //that's actually pretty ok. The IPN just wasn't able
272
-                //to identify which transaction or payment method this was for
273
-                // give all active payment methods a chance to claim it
274
-                $active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
275
-                foreach ($active_payment_methods as $active_payment_method) {
276
-                    try {
277
-                        $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
278
-                        $payment_method = $active_payment_method;
279
-                        EEM_Change_Log::instance()->log(
280
-                            EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment
281
-                        );
282
-                        break;
283
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
284
-                        EEM_Change_Log::instance()->log(
285
-                            EEM_Change_Log::type_gateway,
286
-                            array(
287
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
288
-                                'current_url' => EEH_URL::current_url(),
289
-                                'payment'     => $e->getPaymentProperties(),
290
-                                'IPN_data'    => $e->getIpnData(),
291
-                            ),
292
-                            $obj_for_log
293
-                        );
294
-                        return $e->getPayment();
295
-                    } catch (EE_Error $e) {
296
-                        //that's fine- it apparently couldn't handle the IPN
297
-                    }
298
-                }
299
-            }
300
-            // 			EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
301
-            if ($payment instanceof EE_Payment) {
302
-                $payment->save();
303
-                //  update the TXN
304
-                $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request);
305
-            } else {
306
-                //we couldn't find the payment for this IPN... let's try and log at least SOMETHING
307
-                if ($payment_method) {
308
-                    EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method);
309
-                } elseif ($transaction) {
310
-                    EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction);
311
-                }
312
-            }
313
-            return $payment;
314
-        } catch (EE_Error $e) {
315
-            do_action(
316
-                'AHEE__log', __FILE__, __FUNCTION__, sprintf(
317
-                    __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'),
318
-                    print_r($transaction, true),
319
-                    print_r($_req_data, true),
320
-                    $e->getMessage()
321
-                )
322
-            );
323
-            throw $e;
324
-        }
325
-    }
326
-
327
-
328
-
329
-    /**
330
-     * Removes any non-printable illegal characters from the input,
331
-     * which might cause a raucous when trying to insert into the database
332
-     *
333
-     * @param  array $request_data
334
-     * @return array
335
-     */
336
-    protected function _remove_unusable_characters_from_array(array $request_data)
337
-    {
338
-        $return_data = array();
339
-        foreach ($request_data as $key => $value) {
340
-            $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value);
341
-        }
342
-        return $return_data;
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     * Removes any non-printable illegal characters from the input,
349
-     * which might cause a raucous when trying to insert into the database
350
-     *
351
-     * @param string $request_data
352
-     * @return string
353
-     */
354
-    protected function _remove_unusable_characters($request_data)
355
-    {
356
-        return preg_replace('/[^[:print:]]/', '', $request_data);
357
-    }
358
-
359
-
360
-
361
-    /**
362
-     * Should be called just before displaying the payment attempt results to the user,
363
-     * when the payment attempt has finished. Some payment methods may have special
364
-     * logic to perform here. For example, if process_payment() happens on a special request
365
-     * and then the user is redirected to a page that displays the payment's status, this
366
-     * should be called while loading the page that displays the payment's status. If the user is
367
-     * sent to an offsite payment provider, this should be called upon returning from that offsite payment
368
-     * provider.
369
-     *
370
-     * @param EE_Transaction|int $transaction
371
-     * @param bool               $update_txn whether or not to call
372
-     *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
373
-     * @throws \EE_Error
374
-     * @return EE_Payment
375
-     * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
376
-     *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
377
-     */
378
-    public function finalize_payment_for($transaction, $update_txn = true)
379
-    {
380
-        /** @var $transaction EE_Transaction */
381
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
382
-        $last_payment_method = $transaction->payment_method();
383
-        if ($last_payment_method instanceof EE_Payment_Method) {
384
-            $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
385
-            $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
386
-            return $payment;
387
-        } else {
388
-            return null;
389
-        }
390
-    }
391
-
392
-
393
-
394
-    /**
395
-     * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
396
-     *
397
-     * @param EE_Payment_Method $payment_method
398
-     * @param EE_Payment        $payment_to_refund
399
-     * @param array             $refund_info
400
-     * @return EE_Payment
401
-     * @throws \EE_Error
402
-     */
403
-    public function process_refund(
404
-        EE_Payment_Method $payment_method,
405
-        EE_Payment $payment_to_refund,
406
-        $refund_info = array()
407
-    ) {
408
-        if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
409
-            $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
410
-            $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
411
-        }
412
-        return $payment_to_refund;
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     * This should be called each time there may have been an update to a
419
-     * payment on a transaction (ie, we asked for a payment to process a
420
-     * payment for a transaction, or we told a payment method about an IPN, or
421
-     * we told a payment method to
422
-     * "finalize_payment_for" (a transaction), or we told a payment method to
423
-     * process a refund. This should handle firing the correct hooks to
424
-     * indicate
425
-     * what exactly happened and updating the transaction appropriately). This
426
-     * could be integrated directly into EE_Transaction upon save, but we want
427
-     * this logic to be separate from 'normal' plain-jane saving and updating
428
-     * of transactions and payments, and to be tied to payment processing.
429
-     * Note: this method DOES NOT save the payment passed into it. It is the responsibility
430
-     * of previous code to decide whether or not to save (because the payment passed into
431
-     * this method might be a temporary, never-to-be-saved payment from an offline gateway,
432
-     * in which case we only want that payment object for some temporary usage during this request,
433
-     * but we don't want it to be saved).
434
-     *
435
-     * @param EE_Transaction|int $transaction
436
-     * @param EE_Payment         $payment
437
-     * @param boolean            $update_txn
438
-     *                        whether or not to call
439
-     *                        EE_Transaction_Processor::
440
-     *                        update_transaction_and_registrations_after_checkout_or_payment()
441
-     *                        (you can save 1 DB query if you know you're going
442
-     *                        to save it later instead)
443
-     * @param bool               $IPN
444
-     *                        if processing IPNs or other similar payment
445
-     *                        related activities that occur in alternate
446
-     *                        requests than the main one that is processing the
447
-     *                        TXN, then set this to true to check whether the
448
-     *                        TXN is locked before updating
449
-     * @throws \EE_Error
450
-     */
451
-    public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
452
-    {
453
-        $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
454
-        /** @type EE_Transaction $transaction */
455
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
456
-        // can we freely update the TXN at this moment?
457
-        if ($IPN && $transaction->is_locked()) {
458
-            // don't update the transaction at this exact moment
459
-            // because the TXN is active in another request
460
-            EE_Cron_Tasks::schedule_update_transaction_with_payment(
461
-                time(),
462
-                $transaction->ID(),
463
-                $payment->ID()
464
-            );
465
-        } else {
466
-            // verify payment and that it has been saved
467
-            if ($payment instanceof EE_Payment && $payment->ID()) {
468
-                if (
469
-                    $payment->payment_method() instanceof EE_Payment_Method
470
-                    && $payment->payment_method()->type_obj() instanceof EE_PMT_Base
471
-                ) {
472
-                    $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
473
-                    // update TXN registrations with payment info
474
-                    $this->process_registration_payments($transaction, $payment);
475
-                }
476
-                $do_action = $payment->just_approved()
477
-                    ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
478
-                    : $do_action;
479
-            } else {
480
-                // send out notifications
481
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
482
-                $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
483
-            }
484
-            if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
485
-                /** @type EE_Transaction_Payments $transaction_payments */
486
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
487
-                // set new value for total paid
488
-                $transaction_payments->calculate_total_payments_and_update_status($transaction);
489
-                // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
490
-                if ($update_txn) {
491
-                    $this->_post_payment_processing($transaction, $payment, $IPN);
492
-                }
493
-            }
494
-            // granular hook for others to use.
495
-            do_action($do_action, $transaction, $payment);
496
-            do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
497
-            //global hook for others to use.
498
-            do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
499
-        }
500
-    }
501
-
502
-
503
-
504
-    /**
505
-     * update registrations REG_paid field after successful payment and link registrations with payment
506
-     *
507
-     * @param EE_Transaction    $transaction
508
-     * @param EE_Payment        $payment
509
-     * @param EE_Registration[] $registrations
510
-     * @throws \EE_Error
511
-     */
512
-    public function process_registration_payments(
513
-        EE_Transaction $transaction,
514
-        EE_Payment $payment,
515
-        $registrations = array()
516
-    ) {
517
-        // only process if payment was successful
518
-        if ($payment->status() !== EEM_Payment::status_id_approved) {
519
-            return;
520
-        }
521
-        //EEM_Registration::instance()->show_next_x_db_queries();
522
-        if (empty($registrations)) {
523
-            // find registrations with monies owing that can receive a payment
524
-            $registrations = $transaction->registrations(
525
-                array(
526
-                    array(
527
-                        // only these reg statuses can receive payments
528
-                        'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
529
-                        'REG_final_price'  => array('!=', 0),
530
-                        'REG_final_price*' => array('!=', 'REG_paid', true),
531
-                    ),
532
-                )
533
-            );
534
-        }
535
-        // still nothing ??!??
536
-        if (empty($registrations)) {
537
-            return;
538
-        }
539
-        // todo: break out the following logic into a separate strategy class
540
-        // todo: named something like "Sequential_Reg_Payment_Strategy"
541
-        // todo: which would apply payments using the capitalist "first come first paid" approach
542
-        // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
543
-        // todo: which would be the socialist "everybody gets a piece of pie" approach,
544
-        // todo: which would be better for deposits, where you want a bit of the payment applied to each registration
545
-        $refund = $payment->is_a_refund();
546
-        // how much is available to apply to registrations?
547
-        $available_payment_amount = abs($payment->amount());
548
-        foreach ($registrations as $registration) {
549
-            if ($registration instanceof EE_Registration) {
550
-                // nothing left?
551
-                if ($available_payment_amount <= 0) {
552
-                    break;
553
-                }
554
-                if ($refund) {
555
-                    $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount);
556
-                } else {
557
-                    $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount);
558
-                }
559
-            }
560
-        }
561
-        if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) {
562
-            EE_Error::add_attention(
563
-                sprintf(
564
-                    __('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
565
-                        'event_espresso'),
566
-                    EEH_Template::format_currency($available_payment_amount),
567
-                    implode(', ', array_keys($registrations)),
568
-                    '<br/>',
569
-                    EEH_Template::format_currency($payment->amount())
570
-                ),
571
-                __FILE__, __FUNCTION__, __LINE__
572
-            );
573
-        }
574
-    }
575
-
576
-
577
-
578
-    /**
579
-     * update registration REG_paid field after successful payment and link registration with payment
580
-     *
581
-     * @param EE_Registration $registration
582
-     * @param EE_Payment      $payment
583
-     * @param float           $available_payment_amount
584
-     * @return float
585
-     * @throws \EE_Error
586
-     */
587
-    public function process_registration_payment(
588
-        EE_Registration $registration,
589
-        EE_Payment $payment,
590
-        $available_payment_amount = 0.00
591
-    ) {
592
-        $owing = $registration->final_price() - $registration->paid();
593
-        if ($owing > 0) {
594
-            // don't allow payment amount to exceed the available payment amount, OR the amount owing
595
-            $payment_amount = min($available_payment_amount, $owing);
596
-            // update $available_payment_amount
597
-            $available_payment_amount -= $payment_amount;
598
-            //calculate and set new REG_paid
599
-            $registration->set_paid($registration->paid() + $payment_amount);
600
-            // now save it
601
-            $this->_apply_registration_payment($registration, $payment, $payment_amount);
602
-        }
603
-        return $available_payment_amount;
604
-    }
605
-
606
-
607
-
608
-    /**
609
-     * update registration REG_paid field after successful payment and link registration with payment
610
-     *
611
-     * @param EE_Registration $registration
612
-     * @param EE_Payment      $payment
613
-     * @param float           $payment_amount
614
-     * @return void
615
-     * @throws \EE_Error
616
-     */
617
-    protected function _apply_registration_payment(
618
-        EE_Registration $registration,
619
-        EE_Payment $payment,
620
-        $payment_amount = 0.00
621
-    ) {
622
-        // find any existing reg payment records for this registration and payment
623
-        $existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
624
-            array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
625
-        );
626
-        // if existing registration payment exists
627
-        if ($existing_reg_payment instanceof EE_Registration_Payment) {
628
-            // then update that record
629
-            $existing_reg_payment->set_amount($payment_amount);
630
-            $existing_reg_payment->save();
631
-        } else {
632
-            // or add new relation between registration and payment and set amount
633
-            $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount));
634
-            // make it stick
635
-            $registration->save();
636
-        }
637
-    }
638
-
639
-
640
-
641
-    /**
642
-     * update registration REG_paid field after refund and link registration with payment
643
-     *
644
-     * @param EE_Registration $registration
645
-     * @param EE_Payment      $payment
646
-     * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
647
-     * @return float
648
-     * @throws \EE_Error
649
-     */
650
-    public function process_registration_refund(
651
-        EE_Registration $registration,
652
-        EE_Payment $payment,
653
-        $available_refund_amount = 0.00
654
-    ) {
655
-        //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
656
-        if ($registration->paid() > 0) {
657
-            // ensure $available_refund_amount is NOT negative
658
-            $available_refund_amount = (float)abs($available_refund_amount);
659
-            // don't allow refund amount to exceed the available payment amount, OR the amount paid
660
-            $refund_amount = min($available_refund_amount, (float)$registration->paid());
661
-            // update $available_payment_amount
662
-            $available_refund_amount -= $refund_amount;
663
-            //calculate and set new REG_paid
664
-            $registration->set_paid($registration->paid() - $refund_amount);
665
-            // convert payment amount back to a negative value for storage in the db
666
-            $refund_amount = (float)abs($refund_amount) * -1;
667
-            // now save it
668
-            $this->_apply_registration_payment($registration, $payment, $refund_amount);
669
-        }
670
-        return $available_refund_amount;
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     * Process payments and transaction after payment process completed.
677
-     * ultimately this will send the TXN and payment details off so that notifications can be sent out.
678
-     * if this request happens to be processing an IPN,
679
-     * then we will also set the Payment Options Reg Step to completed,
680
-     * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
681
-     *
682
-     * @param EE_Transaction $transaction
683
-     * @param EE_Payment     $payment
684
-     * @param bool           $IPN
685
-     * @throws \EE_Error
686
-     */
687
-    protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
688
-    {
689
-        /** @type EE_Transaction_Processor $transaction_processor */
690
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
691
-        // is the Payment Options Reg Step completed ?
692
-        $payment_options_step_completed = $transaction->reg_step_completed('payment_options');
693
-        // if the Payment Options Reg Step is completed...
694
-        $revisit = $payment_options_step_completed === true ? true : false;
695
-        // then this is kinda sorta a revisit with regards to payments at least
696
-        $transaction_processor->set_revisit($revisit);
697
-        // if this is an IPN, let's consider the Payment Options Reg Step completed if not already
698
-        if (
699
-            $IPN
700
-            && $payment_options_step_completed !== true
701
-            && ($payment->is_approved() || $payment->is_pending())
702
-        ) {
703
-            $payment_options_step_completed = $transaction->set_reg_step_completed(
704
-                'payment_options'
705
-            );
706
-        }
707
-        // maybe update status, but don't save transaction just yet
708
-        $transaction->update_status_based_on_total_paid(false);
709
-        // check if 'finalize_registration' step has been completed...
710
-        $finalized = $transaction->reg_step_completed('finalize_registration');
711
-        //  if this is an IPN and the final step has not been initiated
712
-        if ($IPN && $payment_options_step_completed && $finalized === false) {
713
-            // and if it hasn't already been set as being started...
714
-            $finalized = $transaction->set_reg_step_initiated('finalize_registration');
715
-        }
716
-        $transaction->save();
717
-        // because the above will return false if the final step was not fully completed, we need to check again...
718
-        if ($IPN && $finalized !== false) {
719
-            // and if we are all good to go, then send out notifications
720
-            add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
721
-            //ok, now process the transaction according to the payment
722
-            $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment);
723
-        }
724
-        // DEBUG LOG
725
-        $payment_method = $payment->payment_method();
726
-        if ($payment_method instanceof EE_Payment_Method) {
727
-            $payment_method_type_obj = $payment_method->type_obj();
728
-            if ($payment_method_type_obj instanceof EE_PMT_Base) {
729
-                $gateway = $payment_method_type_obj->get_gateway();
730
-                if ($gateway instanceof EE_Gateway) {
731
-                    $gateway->log(
732
-                        array(
733
-                            'message'               => __('Post Payment Transaction Details', 'event_espresso'),
734
-                            'transaction'           => $transaction->model_field_array(),
735
-                            'finalized'             => $finalized,
736
-                            'IPN'                   => $IPN,
737
-                            'deliver_notifications' => has_filter(
738
-                                'FHEE__EED_Messages___maybe_registration__deliver_notifications'
739
-                            ),
740
-                        ),
741
-                        $payment
742
-                    );
743
-                }
744
-            }
745
-        }
746
-    }
747
-
748
-
749
-
750
-    /**
751
-     * Force posts to PayPal to use TLS v1.2. See:
752
-     * https://core.trac.wordpress.org/ticket/36320
753
-     * https://core.trac.wordpress.org/ticket/34924#comment:15
754
-     * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
755
-     * This will affect paypal standard, pro, express, and payflow.
756
-     */
757
-    public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
758
-    {
759
-        if (strstr($url, 'https://') && strstr($url, '.paypal.com')) {
760
-            //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
761
-            //instead of the constant because it might not be defined
762
-            curl_setopt($handle, CURLOPT_SSLVERSION, 1);
763
-        }
764
-    }
21
+	/**
22
+	 * @var EE_Payment_Processor $_instance
23
+	 * @access    private
24
+	 */
25
+	private static $_instance;
26
+
27
+
28
+
29
+	/**
30
+	 * @singleton method used to instantiate class object
31
+	 * @access    public
32
+	 * @return EE_Payment_Processor instance
33
+	 */
34
+	public static function instance()
35
+	{
36
+		// check if class object is instantiated
37
+		if ( ! self::$_instance instanceof EE_Payment_Processor) {
38
+			self::$_instance = new self();
39
+		}
40
+		return self::$_instance;
41
+	}
42
+
43
+
44
+
45
+	/**
46
+	 * @return EE_Payment_Processor
47
+	 */
48
+	public static function reset()
49
+	{
50
+		self::$_instance = null;
51
+		return self::instance();
52
+	}
53
+
54
+
55
+
56
+	/**
57
+	 *private constructor to prevent direct creation
58
+	 *
59
+	 * @Constructor
60
+	 * @access private
61
+	 */
62
+	private function __construct()
63
+	{
64
+		do_action('AHEE__EE_Payment_Processor__construct');
65
+		add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * Using the selected gateway, processes the payment for that transaction, and updates the transaction
72
+	 * appropriately. Saves the payment that is generated
73
+	 *
74
+	 * @param EE_Payment_Method    $payment_method
75
+	 * @param EE_Transaction       $transaction
76
+	 * @param float                $amount       if only part of the transaction is to be paid for, how much.
77
+	 *                                           Leave null if payment is for the full amount owing
78
+	 * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
79
+	 *                                           Receive_form_submission() should have
80
+	 *                                           already been called on the billing form
81
+	 *                                           (ie, its inputs should have their normalized values set).
82
+	 * @param string               $return_url   string used mostly by offsite gateways to specify
83
+	 *                                           where to go AFTER the offsite gateway
84
+	 * @param string               $method       like 'CART', indicates who the client who called this was
85
+	 * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
86
+	 * @param boolean              $update_txn   whether or not to call
87
+	 *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
88
+	 * @param string               $cancel_url   URL to return to if off-site payments are cancelled
89
+	 * @return \EE_Payment
90
+	 * @throws \EE_Error
91
+	 */
92
+	public function process_payment(
93
+		EE_Payment_Method $payment_method,
94
+		EE_Transaction $transaction,
95
+		$amount = null,
96
+		$billing_form = null,
97
+		$return_url = null,
98
+		$method = 'CART',
99
+		$by_admin = false,
100
+		$update_txn = true,
101
+		$cancel_url = ''
102
+	) {
103
+		if ((float)$amount < 0) {
104
+			throw new EE_Error(
105
+				sprintf(
106
+					__(
107
+						'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
108
+						'event_espresso'
109
+					),
110
+					$amount,
111
+					$transaction->ID()
112
+				)
113
+			);
114
+		}
115
+		// verify payment method
116
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
117
+		// verify transaction
118
+		EEM_Transaction::instance()->ensure_is_obj($transaction);
119
+		$transaction->set_payment_method_ID($payment_method->ID());
120
+		// verify payment method type
121
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
122
+			$payment = $payment_method->type_obj()->process_payment(
123
+				$transaction,
124
+				min($amount, $transaction->remaining()),//make sure we don't overcharge
125
+				$billing_form,
126
+				$return_url,
127
+				add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
128
+				$method,
129
+				$by_admin
130
+			);
131
+			// check if payment method uses an off-site gateway
132
+			if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
133
+				// don't process payments for off-site gateways yet because no payment has occurred yet
134
+				$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
135
+			}
136
+			return $payment;
137
+		} else {
138
+			EE_Error::add_error(
139
+				sprintf(
140
+					__('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
141
+					'<br/>',
142
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
143
+				), __FILE__, __FUNCTION__, __LINE__
144
+			);
145
+			return null;
146
+		}
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * @param EE_Transaction|int $transaction
153
+	 * @param EE_Payment_Method  $payment_method
154
+	 * @throws EE_Error
155
+	 * @return string
156
+	 */
157
+	public function get_ipn_url_for_payment_method($transaction, $payment_method)
158
+	{
159
+		/** @type \EE_Transaction $transaction */
160
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
161
+		$primary_reg = $transaction->primary_registration();
162
+		if ( ! $primary_reg instanceof EE_Registration) {
163
+			throw new EE_Error(
164
+				sprintf(
165
+					__(
166
+						"Cannot get IPN URL for transaction with ID %d because it has no primary registration",
167
+						"event_espresso"
168
+					),
169
+					$transaction->ID()
170
+				)
171
+			);
172
+		}
173
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
174
+		$url = add_query_arg(
175
+			array(
176
+				'e_reg_url_link'    => $primary_reg->reg_url_link(),
177
+				'ee_payment_method' => $payment_method->slug(),
178
+			),
179
+			EE_Registry::instance()->CFG->core->txn_page_url()
180
+		);
181
+		return $url;
182
+	}
183
+
184
+
185
+
186
+	/**
187
+	 * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
188
+	 * we can easily find what registration the IPN is for and what payment method.
189
+	 * However, if not, we'll give all payment methods a chance to claim it and process it.
190
+	 * If a payment is found for the IPN info, it is saved.
191
+	 *
192
+	 * @param array              $_req_data            eg $_REQUEST
193
+	 * @param EE_Transaction|int $transaction          optional (or a transactions id)
194
+	 * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
195
+	 * @param boolean            $update_txn           whether or not to call
196
+	 *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
197
+	 * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
198
+	 *                                                 or is processed manually ( false like Mijireh )
199
+	 * @throws EE_Error
200
+	 * @throws Exception
201
+	 * @return EE_Payment
202
+	 */
203
+	public function process_ipn(
204
+		$_req_data,
205
+		$transaction = null,
206
+		$payment_method = null,
207
+		$update_txn = true,
208
+		$separate_IPN_request = true
209
+	) {
210
+		EE_Registry::instance()->load_model('Change_Log');
211
+		$_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data);
212
+		EE_Processor_Base::set_IPN($separate_IPN_request);
213
+		$obj_for_log = null;
214
+		if ($transaction instanceof EE_Transaction) {
215
+			$obj_for_log = $transaction;
216
+			if ($payment_method instanceof EE_Payment_Method) {
217
+				$obj_for_log = EEM_Payment::instance()->get_one(
218
+					array(
219
+						array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
220
+						'order_by' => array('PAY_timestamp' => 'desc'),
221
+					)
222
+				);
223
+			}
224
+		} else if ($payment_method instanceof EE_Payment) {
225
+			$obj_for_log = $payment_method;
226
+		}
227
+		$log = EEM_Change_Log::instance()->log(
228
+			EEM_Change_Log::type_gateway,
229
+			array('IPN data received' => $_req_data),
230
+			$obj_for_log
231
+		);
232
+		try {
233
+			/**
234
+			 * @var EE_Payment $payment
235
+			 */
236
+			$payment = null;
237
+			if ($transaction && $payment_method) {
238
+				/** @type EE_Transaction $transaction */
239
+				$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
240
+				/** @type EE_Payment_Method $payment_method */
241
+				$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
242
+				if ($payment_method->type_obj() instanceof EE_PMT_Base) {
243
+					try {
244
+						$payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
245
+						$log->set_object($payment);
246
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
247
+						EEM_Change_Log::instance()->log(
248
+							EEM_Change_Log::type_gateway,
249
+							array(
250
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
251
+								'current_url' => EEH_URL::current_url(),
252
+								'payment'     => $e->getPaymentProperties(),
253
+								'IPN_data'    => $e->getIpnData(),
254
+							),
255
+							$obj_for_log
256
+						);
257
+						return $e->getPayment();
258
+					}
259
+				} else {
260
+					// not a payment
261
+					EE_Error::add_error(
262
+						sprintf(
263
+							__('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'),
264
+							'<br/>',
265
+							EE_Registry::instance()->CFG->organization->get_pretty('email')
266
+						),
267
+						__FILE__, __FUNCTION__, __LINE__
268
+					);
269
+				}
270
+			} else {
271
+				//that's actually pretty ok. The IPN just wasn't able
272
+				//to identify which transaction or payment method this was for
273
+				// give all active payment methods a chance to claim it
274
+				$active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
275
+				foreach ($active_payment_methods as $active_payment_method) {
276
+					try {
277
+						$payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
278
+						$payment_method = $active_payment_method;
279
+						EEM_Change_Log::instance()->log(
280
+							EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment
281
+						);
282
+						break;
283
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
284
+						EEM_Change_Log::instance()->log(
285
+							EEM_Change_Log::type_gateway,
286
+							array(
287
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
288
+								'current_url' => EEH_URL::current_url(),
289
+								'payment'     => $e->getPaymentProperties(),
290
+								'IPN_data'    => $e->getIpnData(),
291
+							),
292
+							$obj_for_log
293
+						);
294
+						return $e->getPayment();
295
+					} catch (EE_Error $e) {
296
+						//that's fine- it apparently couldn't handle the IPN
297
+					}
298
+				}
299
+			}
300
+			// 			EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
301
+			if ($payment instanceof EE_Payment) {
302
+				$payment->save();
303
+				//  update the TXN
304
+				$this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request);
305
+			} else {
306
+				//we couldn't find the payment for this IPN... let's try and log at least SOMETHING
307
+				if ($payment_method) {
308
+					EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method);
309
+				} elseif ($transaction) {
310
+					EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction);
311
+				}
312
+			}
313
+			return $payment;
314
+		} catch (EE_Error $e) {
315
+			do_action(
316
+				'AHEE__log', __FILE__, __FUNCTION__, sprintf(
317
+					__('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'),
318
+					print_r($transaction, true),
319
+					print_r($_req_data, true),
320
+					$e->getMessage()
321
+				)
322
+			);
323
+			throw $e;
324
+		}
325
+	}
326
+
327
+
328
+
329
+	/**
330
+	 * Removes any non-printable illegal characters from the input,
331
+	 * which might cause a raucous when trying to insert into the database
332
+	 *
333
+	 * @param  array $request_data
334
+	 * @return array
335
+	 */
336
+	protected function _remove_unusable_characters_from_array(array $request_data)
337
+	{
338
+		$return_data = array();
339
+		foreach ($request_data as $key => $value) {
340
+			$return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value);
341
+		}
342
+		return $return_data;
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 * Removes any non-printable illegal characters from the input,
349
+	 * which might cause a raucous when trying to insert into the database
350
+	 *
351
+	 * @param string $request_data
352
+	 * @return string
353
+	 */
354
+	protected function _remove_unusable_characters($request_data)
355
+	{
356
+		return preg_replace('/[^[:print:]]/', '', $request_data);
357
+	}
358
+
359
+
360
+
361
+	/**
362
+	 * Should be called just before displaying the payment attempt results to the user,
363
+	 * when the payment attempt has finished. Some payment methods may have special
364
+	 * logic to perform here. For example, if process_payment() happens on a special request
365
+	 * and then the user is redirected to a page that displays the payment's status, this
366
+	 * should be called while loading the page that displays the payment's status. If the user is
367
+	 * sent to an offsite payment provider, this should be called upon returning from that offsite payment
368
+	 * provider.
369
+	 *
370
+	 * @param EE_Transaction|int $transaction
371
+	 * @param bool               $update_txn whether or not to call
372
+	 *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
373
+	 * @throws \EE_Error
374
+	 * @return EE_Payment
375
+	 * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
376
+	 *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
377
+	 */
378
+	public function finalize_payment_for($transaction, $update_txn = true)
379
+	{
380
+		/** @var $transaction EE_Transaction */
381
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
382
+		$last_payment_method = $transaction->payment_method();
383
+		if ($last_payment_method instanceof EE_Payment_Method) {
384
+			$payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
385
+			$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
386
+			return $payment;
387
+		} else {
388
+			return null;
389
+		}
390
+	}
391
+
392
+
393
+
394
+	/**
395
+	 * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
396
+	 *
397
+	 * @param EE_Payment_Method $payment_method
398
+	 * @param EE_Payment        $payment_to_refund
399
+	 * @param array             $refund_info
400
+	 * @return EE_Payment
401
+	 * @throws \EE_Error
402
+	 */
403
+	public function process_refund(
404
+		EE_Payment_Method $payment_method,
405
+		EE_Payment $payment_to_refund,
406
+		$refund_info = array()
407
+	) {
408
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
409
+			$payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
410
+			$this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
411
+		}
412
+		return $payment_to_refund;
413
+	}
414
+
415
+
416
+
417
+	/**
418
+	 * This should be called each time there may have been an update to a
419
+	 * payment on a transaction (ie, we asked for a payment to process a
420
+	 * payment for a transaction, or we told a payment method about an IPN, or
421
+	 * we told a payment method to
422
+	 * "finalize_payment_for" (a transaction), or we told a payment method to
423
+	 * process a refund. This should handle firing the correct hooks to
424
+	 * indicate
425
+	 * what exactly happened and updating the transaction appropriately). This
426
+	 * could be integrated directly into EE_Transaction upon save, but we want
427
+	 * this logic to be separate from 'normal' plain-jane saving and updating
428
+	 * of transactions and payments, and to be tied to payment processing.
429
+	 * Note: this method DOES NOT save the payment passed into it. It is the responsibility
430
+	 * of previous code to decide whether or not to save (because the payment passed into
431
+	 * this method might be a temporary, never-to-be-saved payment from an offline gateway,
432
+	 * in which case we only want that payment object for some temporary usage during this request,
433
+	 * but we don't want it to be saved).
434
+	 *
435
+	 * @param EE_Transaction|int $transaction
436
+	 * @param EE_Payment         $payment
437
+	 * @param boolean            $update_txn
438
+	 *                        whether or not to call
439
+	 *                        EE_Transaction_Processor::
440
+	 *                        update_transaction_and_registrations_after_checkout_or_payment()
441
+	 *                        (you can save 1 DB query if you know you're going
442
+	 *                        to save it later instead)
443
+	 * @param bool               $IPN
444
+	 *                        if processing IPNs or other similar payment
445
+	 *                        related activities that occur in alternate
446
+	 *                        requests than the main one that is processing the
447
+	 *                        TXN, then set this to true to check whether the
448
+	 *                        TXN is locked before updating
449
+	 * @throws \EE_Error
450
+	 */
451
+	public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
452
+	{
453
+		$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
454
+		/** @type EE_Transaction $transaction */
455
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
456
+		// can we freely update the TXN at this moment?
457
+		if ($IPN && $transaction->is_locked()) {
458
+			// don't update the transaction at this exact moment
459
+			// because the TXN is active in another request
460
+			EE_Cron_Tasks::schedule_update_transaction_with_payment(
461
+				time(),
462
+				$transaction->ID(),
463
+				$payment->ID()
464
+			);
465
+		} else {
466
+			// verify payment and that it has been saved
467
+			if ($payment instanceof EE_Payment && $payment->ID()) {
468
+				if (
469
+					$payment->payment_method() instanceof EE_Payment_Method
470
+					&& $payment->payment_method()->type_obj() instanceof EE_PMT_Base
471
+				) {
472
+					$payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
473
+					// update TXN registrations with payment info
474
+					$this->process_registration_payments($transaction, $payment);
475
+				}
476
+				$do_action = $payment->just_approved()
477
+					? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
478
+					: $do_action;
479
+			} else {
480
+				// send out notifications
481
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
482
+				$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
483
+			}
484
+			if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
485
+				/** @type EE_Transaction_Payments $transaction_payments */
486
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
487
+				// set new value for total paid
488
+				$transaction_payments->calculate_total_payments_and_update_status($transaction);
489
+				// call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
490
+				if ($update_txn) {
491
+					$this->_post_payment_processing($transaction, $payment, $IPN);
492
+				}
493
+			}
494
+			// granular hook for others to use.
495
+			do_action($do_action, $transaction, $payment);
496
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
497
+			//global hook for others to use.
498
+			do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
499
+		}
500
+	}
501
+
502
+
503
+
504
+	/**
505
+	 * update registrations REG_paid field after successful payment and link registrations with payment
506
+	 *
507
+	 * @param EE_Transaction    $transaction
508
+	 * @param EE_Payment        $payment
509
+	 * @param EE_Registration[] $registrations
510
+	 * @throws \EE_Error
511
+	 */
512
+	public function process_registration_payments(
513
+		EE_Transaction $transaction,
514
+		EE_Payment $payment,
515
+		$registrations = array()
516
+	) {
517
+		// only process if payment was successful
518
+		if ($payment->status() !== EEM_Payment::status_id_approved) {
519
+			return;
520
+		}
521
+		//EEM_Registration::instance()->show_next_x_db_queries();
522
+		if (empty($registrations)) {
523
+			// find registrations with monies owing that can receive a payment
524
+			$registrations = $transaction->registrations(
525
+				array(
526
+					array(
527
+						// only these reg statuses can receive payments
528
+						'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
529
+						'REG_final_price'  => array('!=', 0),
530
+						'REG_final_price*' => array('!=', 'REG_paid', true),
531
+					),
532
+				)
533
+			);
534
+		}
535
+		// still nothing ??!??
536
+		if (empty($registrations)) {
537
+			return;
538
+		}
539
+		// todo: break out the following logic into a separate strategy class
540
+		// todo: named something like "Sequential_Reg_Payment_Strategy"
541
+		// todo: which would apply payments using the capitalist "first come first paid" approach
542
+		// todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
543
+		// todo: which would be the socialist "everybody gets a piece of pie" approach,
544
+		// todo: which would be better for deposits, where you want a bit of the payment applied to each registration
545
+		$refund = $payment->is_a_refund();
546
+		// how much is available to apply to registrations?
547
+		$available_payment_amount = abs($payment->amount());
548
+		foreach ($registrations as $registration) {
549
+			if ($registration instanceof EE_Registration) {
550
+				// nothing left?
551
+				if ($available_payment_amount <= 0) {
552
+					break;
553
+				}
554
+				if ($refund) {
555
+					$available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount);
556
+				} else {
557
+					$available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount);
558
+				}
559
+			}
560
+		}
561
+		if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) {
562
+			EE_Error::add_attention(
563
+				sprintf(
564
+					__('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
565
+						'event_espresso'),
566
+					EEH_Template::format_currency($available_payment_amount),
567
+					implode(', ', array_keys($registrations)),
568
+					'<br/>',
569
+					EEH_Template::format_currency($payment->amount())
570
+				),
571
+				__FILE__, __FUNCTION__, __LINE__
572
+			);
573
+		}
574
+	}
575
+
576
+
577
+
578
+	/**
579
+	 * update registration REG_paid field after successful payment and link registration with payment
580
+	 *
581
+	 * @param EE_Registration $registration
582
+	 * @param EE_Payment      $payment
583
+	 * @param float           $available_payment_amount
584
+	 * @return float
585
+	 * @throws \EE_Error
586
+	 */
587
+	public function process_registration_payment(
588
+		EE_Registration $registration,
589
+		EE_Payment $payment,
590
+		$available_payment_amount = 0.00
591
+	) {
592
+		$owing = $registration->final_price() - $registration->paid();
593
+		if ($owing > 0) {
594
+			// don't allow payment amount to exceed the available payment amount, OR the amount owing
595
+			$payment_amount = min($available_payment_amount, $owing);
596
+			// update $available_payment_amount
597
+			$available_payment_amount -= $payment_amount;
598
+			//calculate and set new REG_paid
599
+			$registration->set_paid($registration->paid() + $payment_amount);
600
+			// now save it
601
+			$this->_apply_registration_payment($registration, $payment, $payment_amount);
602
+		}
603
+		return $available_payment_amount;
604
+	}
605
+
606
+
607
+
608
+	/**
609
+	 * update registration REG_paid field after successful payment and link registration with payment
610
+	 *
611
+	 * @param EE_Registration $registration
612
+	 * @param EE_Payment      $payment
613
+	 * @param float           $payment_amount
614
+	 * @return void
615
+	 * @throws \EE_Error
616
+	 */
617
+	protected function _apply_registration_payment(
618
+		EE_Registration $registration,
619
+		EE_Payment $payment,
620
+		$payment_amount = 0.00
621
+	) {
622
+		// find any existing reg payment records for this registration and payment
623
+		$existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
624
+			array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
625
+		);
626
+		// if existing registration payment exists
627
+		if ($existing_reg_payment instanceof EE_Registration_Payment) {
628
+			// then update that record
629
+			$existing_reg_payment->set_amount($payment_amount);
630
+			$existing_reg_payment->save();
631
+		} else {
632
+			// or add new relation between registration and payment and set amount
633
+			$registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount));
634
+			// make it stick
635
+			$registration->save();
636
+		}
637
+	}
638
+
639
+
640
+
641
+	/**
642
+	 * update registration REG_paid field after refund and link registration with payment
643
+	 *
644
+	 * @param EE_Registration $registration
645
+	 * @param EE_Payment      $payment
646
+	 * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
647
+	 * @return float
648
+	 * @throws \EE_Error
649
+	 */
650
+	public function process_registration_refund(
651
+		EE_Registration $registration,
652
+		EE_Payment $payment,
653
+		$available_refund_amount = 0.00
654
+	) {
655
+		//EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
656
+		if ($registration->paid() > 0) {
657
+			// ensure $available_refund_amount is NOT negative
658
+			$available_refund_amount = (float)abs($available_refund_amount);
659
+			// don't allow refund amount to exceed the available payment amount, OR the amount paid
660
+			$refund_amount = min($available_refund_amount, (float)$registration->paid());
661
+			// update $available_payment_amount
662
+			$available_refund_amount -= $refund_amount;
663
+			//calculate and set new REG_paid
664
+			$registration->set_paid($registration->paid() - $refund_amount);
665
+			// convert payment amount back to a negative value for storage in the db
666
+			$refund_amount = (float)abs($refund_amount) * -1;
667
+			// now save it
668
+			$this->_apply_registration_payment($registration, $payment, $refund_amount);
669
+		}
670
+		return $available_refund_amount;
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 * Process payments and transaction after payment process completed.
677
+	 * ultimately this will send the TXN and payment details off so that notifications can be sent out.
678
+	 * if this request happens to be processing an IPN,
679
+	 * then we will also set the Payment Options Reg Step to completed,
680
+	 * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
681
+	 *
682
+	 * @param EE_Transaction $transaction
683
+	 * @param EE_Payment     $payment
684
+	 * @param bool           $IPN
685
+	 * @throws \EE_Error
686
+	 */
687
+	protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
688
+	{
689
+		/** @type EE_Transaction_Processor $transaction_processor */
690
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
691
+		// is the Payment Options Reg Step completed ?
692
+		$payment_options_step_completed = $transaction->reg_step_completed('payment_options');
693
+		// if the Payment Options Reg Step is completed...
694
+		$revisit = $payment_options_step_completed === true ? true : false;
695
+		// then this is kinda sorta a revisit with regards to payments at least
696
+		$transaction_processor->set_revisit($revisit);
697
+		// if this is an IPN, let's consider the Payment Options Reg Step completed if not already
698
+		if (
699
+			$IPN
700
+			&& $payment_options_step_completed !== true
701
+			&& ($payment->is_approved() || $payment->is_pending())
702
+		) {
703
+			$payment_options_step_completed = $transaction->set_reg_step_completed(
704
+				'payment_options'
705
+			);
706
+		}
707
+		// maybe update status, but don't save transaction just yet
708
+		$transaction->update_status_based_on_total_paid(false);
709
+		// check if 'finalize_registration' step has been completed...
710
+		$finalized = $transaction->reg_step_completed('finalize_registration');
711
+		//  if this is an IPN and the final step has not been initiated
712
+		if ($IPN && $payment_options_step_completed && $finalized === false) {
713
+			// and if it hasn't already been set as being started...
714
+			$finalized = $transaction->set_reg_step_initiated('finalize_registration');
715
+		}
716
+		$transaction->save();
717
+		// because the above will return false if the final step was not fully completed, we need to check again...
718
+		if ($IPN && $finalized !== false) {
719
+			// and if we are all good to go, then send out notifications
720
+			add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
721
+			//ok, now process the transaction according to the payment
722
+			$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment);
723
+		}
724
+		// DEBUG LOG
725
+		$payment_method = $payment->payment_method();
726
+		if ($payment_method instanceof EE_Payment_Method) {
727
+			$payment_method_type_obj = $payment_method->type_obj();
728
+			if ($payment_method_type_obj instanceof EE_PMT_Base) {
729
+				$gateway = $payment_method_type_obj->get_gateway();
730
+				if ($gateway instanceof EE_Gateway) {
731
+					$gateway->log(
732
+						array(
733
+							'message'               => __('Post Payment Transaction Details', 'event_espresso'),
734
+							'transaction'           => $transaction->model_field_array(),
735
+							'finalized'             => $finalized,
736
+							'IPN'                   => $IPN,
737
+							'deliver_notifications' => has_filter(
738
+								'FHEE__EED_Messages___maybe_registration__deliver_notifications'
739
+							),
740
+						),
741
+						$payment
742
+					);
743
+				}
744
+			}
745
+		}
746
+	}
747
+
748
+
749
+
750
+	/**
751
+	 * Force posts to PayPal to use TLS v1.2. See:
752
+	 * https://core.trac.wordpress.org/ticket/36320
753
+	 * https://core.trac.wordpress.org/ticket/34924#comment:15
754
+	 * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
755
+	 * This will affect paypal standard, pro, express, and payflow.
756
+	 */
757
+	public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
758
+	{
759
+		if (strstr($url, 'https://') && strstr($url, '.paypal.com')) {
760
+			//Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
761
+			//instead of the constant because it might not be defined
762
+			curl_setopt($handle, CURLOPT_SSLVERSION, 1);
763
+		}
764
+	}
765 765
 }
Please login to merge, or discard this patch.
core/EE_Bootstrap.core.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -42,13 +42,13 @@  discard block
 block discarded – undo
42 42
 
43 43
 	public function __construct() {
44 44
 		// construct request stack and run middleware apps as soon as all WP plugins are loaded
45
-		add_action( 'plugins_loaded', array( $this, 'run_request_stack' ), 0 );
45
+		add_action('plugins_loaded', array($this, 'run_request_stack'), 0);
46 46
 		// set framework for the rest of EE to hook into when loading
47
-		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'load_espresso_addons' ), 1 );
48
-		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'detect_activations_or_upgrades' ), 3 );
49
-		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'load_core_configuration' ), 5 );
50
-		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'register_shortcodes_modules_and_widgets' ), 7 );
51
-		add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'brew_espresso' ), 9 );
47
+		add_action('plugins_loaded', array('EE_Bootstrap', 'load_espresso_addons'), 1);
48
+		add_action('plugins_loaded', array('EE_Bootstrap', 'detect_activations_or_upgrades'), 3);
49
+		add_action('plugins_loaded', array('EE_Bootstrap', 'load_core_configuration'), 5);
50
+		add_action('plugins_loaded', array('EE_Bootstrap', 'register_shortcodes_modules_and_widgets'), 7);
51
+		add_action('plugins_loaded', array('EE_Bootstrap', 'brew_espresso'), 9);
52 52
 	}
53 53
 
54 54
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 			new EE_Load_Espresso_Core()
66 66
 		);
67 67
 		$this->_request_stack->handle_request(
68
-			new EE_Request( $_GET, $_POST, $_COOKIE ),
68
+			new EE_Request($_GET, $_POST, $_COOKIE),
69 69
 			new EE_Response()
70 70
 		);
71 71
 		$this->_request_stack->handle_response();
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 */
79 79
 	protected function load_autoloader() {
80 80
 		// load interfaces
81
-		espresso_load_required( 'EEH_Autoloader', EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' );
81
+		espresso_load_required('EEH_Autoloader', EE_CORE.'helpers'.DS.'EEH_Autoloader.helper.php');
82 82
 		EEH_Autoloader::instance();
83 83
 	}
84 84
 
@@ -89,15 +89,15 @@  discard block
 block discarded – undo
89 89
 	 */
90 90
 	protected function set_autoloaders_for_required_files() {
91 91
 		// load interfaces
92
-		espresso_load_required( 'EEI_Interfaces', EE_CORE . 'interfaces' . DS . 'EEI_Interfaces.php' );
93
-		espresso_load_required( 'InterminableInterface', EE_CORE . 'interfaces' . DS . 'InterminableInterface.php' );
94
-		espresso_load_required( 'ResettableInterface', EE_CORE . 'interfaces' . DS . 'ResettableInterface.php' );
92
+		espresso_load_required('EEI_Interfaces', EE_CORE.'interfaces'.DS.'EEI_Interfaces.php');
93
+		espresso_load_required('InterminableInterface', EE_CORE.'interfaces'.DS.'InterminableInterface.php');
94
+		espresso_load_required('ResettableInterface', EE_CORE.'interfaces'.DS.'ResettableInterface.php');
95 95
 		// load helpers
96
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_HELPERS );
96
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
97 97
 		// load request stack
98
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_CORE . 'request_stack' . DS );
98
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'request_stack'.DS);
99 99
 		// load middleware
100
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_CORE . 'middleware' . DS );
100
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'middleware'.DS);
101 101
 	}
102 102
 
103 103
 
@@ -118,9 +118,9 @@  discard block
 block discarded – undo
118 118
 			)
119 119
 		);
120 120
 		// load middleware onto stack : FILO (First In Last Out)
121
-		foreach ( (array)$stack_apps as $stack_app ) {
121
+		foreach ((array) $stack_apps as $stack_app) {
122 122
 			//$request_stack_builder->push( $stack_app );
123
-			$request_stack_builder->unshift( $stack_app );
123
+			$request_stack_builder->unshift($stack_app);
124 124
 		}
125 125
 		return apply_filters(
126 126
 			'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder',
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 * no other logic should be performed at this point
138 138
 	 */
139 139
 	public static function load_espresso_addons() {
140
-		do_action( 'AHEE__EE_Bootstrap__load_espresso_addons' );
140
+		do_action('AHEE__EE_Bootstrap__load_espresso_addons');
141 141
 	}
142 142
 
143 143
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * we can determine if anything needs activating or upgrading
150 150
 	 */
151 151
 	public static function detect_activations_or_upgrades() {
152
-		do_action( 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' );
152
+		do_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades');
153 153
 	}
154 154
 
155 155
 
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	 * we can load and set all of the system configurations
162 162
 	 */
163 163
 	public static function load_core_configuration() {
164
-		do_action( 'AHEE__EE_Bootstrap__load_core_configuration' );
164
+		do_action('AHEE__EE_Bootstrap__load_core_configuration');
165 165
 	}
166 166
 
167 167
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 	 * so that they are ready to be used throughout the system
174 174
 	 */
175 175
 	public static function register_shortcodes_modules_and_widgets() {
176
-		do_action( 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' );
176
+		do_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets');
177 177
 	}
178 178
 
179 179
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 * so let the fun begin...
186 186
 	 */
187 187
 	public static function brew_espresso() {
188
-		do_action( 'AHEE__EE_Bootstrap__brew_espresso' );
188
+		do_action('AHEE__EE_Bootstrap__brew_espresso');
189 189
 	}
190 190
 
191 191
 
Please login to merge, or discard this patch.
caffeinated/modules/events_archive_caff/EED_Events_Archive_Caff.module.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -86,52 +86,52 @@  discard block
 block discarded – undo
86 86
 		$gen_set_admin = EE_Registry::instance()->LIB->EE_Admin_Page_Loader->get_admin_page_object( 'general_settings' );
87 87
 		if ( $gen_set_admin instanceof General_Settings_Admin_Page ) {
88 88
 			remove_action(
89
-			    'AHEE__template_settings__template__before_settings_form',
90
-                array( $gen_set_admin, 'template_settings_caff_features' ),
91
-                100
92
-            );
89
+				'AHEE__template_settings__template__before_settings_form',
90
+				array( $gen_set_admin, 'template_settings_caff_features' ),
91
+				100
92
+			);
93 93
 		}
94 94
 		// first just grab the template settings
95 95
 		$config = EE_Registry::instance()->CFG->template_settings;
96 96
 		// then if the Event Archive config is valid, use that, else create a new one
97 97
 		$config = isset( $config->EED_Events_Archive ) && $config->EED_Events_Archive instanceof EE_Events_Archive_Config
98
-            ? $config->EED_Events_Archive
99
-            : new EE_Events_Archive_Config();
98
+			? $config->EED_Events_Archive
99
+			: new EE_Events_Archive_Config();
100 100
 		$config = apply_filters( 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', $config );
101 101
 		$config->display_status_banner = isset( $config->display_status_banner )
102
-            ? $config->display_status_banner
103
-            : 0;
102
+			? $config->display_status_banner
103
+			: 0;
104 104
 		$config->display_description = isset( $config->display_description )
105
-            ? $config->display_description
106
-            : 1;
105
+			? $config->display_description
106
+			: 1;
107 107
 		$config->display_ticket_selector = isset( $config->display_ticket_selector )
108
-            ? $config->display_ticket_selector
109
-            : 0;
108
+			? $config->display_ticket_selector
109
+			: 0;
110 110
 		$config->display_datetimes = isset( $config->display_datetimes )
111
-            ? $config->display_datetimes
112
-            : 1;
111
+			? $config->display_datetimes
112
+			: 1;
113 113
 		$config->display_venue = isset( $config->display_venue )
114
-            ? $config->display_venue
115
-            : 0;
114
+			? $config->display_venue
115
+			: 0;
116 116
 		$config->display_expired_events = isset( $config->display_expired_events )
117
-            ? $config->display_expired_events
118
-            : 0;
117
+			? $config->display_expired_events
118
+			: 0;
119 119
 		// display order options
120 120
 		$config->use_sortable_display_order = isset( $config->use_sortable_display_order  )
121
-            ? $config->use_sortable_display_order
122
-            : false;
121
+			? $config->use_sortable_display_order
122
+			: false;
123 123
 		$config->display_order_tickets = isset( $config->display_order_tickets  )
124
-            ? $config->display_order_tickets
125
-            : 120;
124
+			? $config->display_order_tickets
125
+			: 120;
126 126
 		$config->display_order_datetimes = isset( $config->display_order_datetimes  )
127
-            ? $config->display_order_datetimes
128
-            : 110;
127
+			? $config->display_order_datetimes
128
+			: 110;
129 129
 		$config->display_order_event = isset( $config->display_order_event  )
130
-            ? $config->display_order_event
131
-            : 100;
130
+			? $config->display_order_event
131
+			: 100;
132 132
 		$config->display_order_venue = isset( $config->display_order_venue  )
133
-            ? $config->display_order_venue
134
-            : 130;
133
+			? $config->display_order_venue
134
+			: 130;
135 135
 		// get template parts
136 136
 		$template_parts = EED_Events_Archive::instance()->initialize_template_parts( $config );
137 137
 		// convert to array so that we can add more properties
@@ -165,17 +165,17 @@  discard block
 block discarded – undo
165 165
 			$config->display_expired_events = isset( $REQ['EED_Events_Archive_display_expired_events'] ) ? absint( $REQ['EED_Events_Archive_display_expired_events'] ) : 0;
166 166
 			$config->use_sortable_display_order = isset( $REQ['EED_Events_Archive_use_sortable_display_order'] ) ? absint( $REQ['EED_Events_Archive_use_sortable_display_order'] ) : 0;
167 167
 			$config->display_order_event = isset( $CFG->EED_Events_Archive->display_order_event ) && $config->use_sortable_display_order
168
-                ? $CFG->EED_Events_Archive->display_order_event
169
-                : EED_Events_Archive::EVENT_DETAILS_PRIORITY;
168
+				? $CFG->EED_Events_Archive->display_order_event
169
+				: EED_Events_Archive::EVENT_DETAILS_PRIORITY;
170 170
 			$config->display_order_datetimes = isset( $CFG->EED_Events_Archive->display_order_datetimes ) && $config->use_sortable_display_order
171
-                ? $CFG->EED_Events_Archive->display_order_datetimes
172
-                : EED_Events_Archive::EVENT_DATETIMES_PRIORITY;
171
+				? $CFG->EED_Events_Archive->display_order_datetimes
172
+				: EED_Events_Archive::EVENT_DATETIMES_PRIORITY;
173 173
 			$config->display_order_tickets = isset( $CFG->EED_Events_Archive->display_order_tickets ) && $config->use_sortable_display_order
174
-                ? $CFG->EED_Events_Archive->display_order_tickets
175
-                : EED_Events_Archive::EVENT_TICKETS_PRIORITY;
174
+				? $CFG->EED_Events_Archive->display_order_tickets
175
+				: EED_Events_Archive::EVENT_TICKETS_PRIORITY;
176 176
 			$config->display_order_venue = isset( $CFG->EED_Events_Archive->display_order_venue ) && $config->use_sortable_display_order
177
-                ? $CFG->EED_Events_Archive->display_order_venue
178
-                : EED_Events_Archive::EVENT_VENUES_PRIORITY;
177
+				? $CFG->EED_Events_Archive->display_order_venue
178
+				: EED_Events_Archive::EVENT_VENUES_PRIORITY;
179 179
 		}
180 180
 		$CFG->EED_Events_Archive = $config;
181 181
 		do_action( 'AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ );
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	 * @return EED_Events_Archive_Caff
29 29
 	 */
30 30
 	public static function instance() {
31
-		return parent::get_instance( __CLASS__ );
31
+		return parent::get_instance(__CLASS__);
32 32
 	}
33 33
 
34 34
 
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
 	 *  @return 	void
50 50
 	 */
51 51
 	public static function set_hooks_admin() {
52
-		define( 'EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS );
53
-		define( 'EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
54
-		add_action( 'AHEE__template_settings__template__before_settings_form', array( 'EED_Events_Archive_Caff', 'template_settings_form' ), 10 );
55
-		add_filter( 'FHEE__General_Settings_Admin_Page__update_template_settings__data', array( 'EED_Events_Archive_Caff', 'update_template_settings' ), 10, 2 );
52
+		define('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS);
53
+		define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
54
+		add_action('AHEE__template_settings__template__before_settings_form', array('EED_Events_Archive_Caff', 'template_settings_form'), 10);
55
+		add_filter('FHEE__General_Settings_Admin_Page__update_template_settings__data', array('EED_Events_Archive_Caff', 'update_template_settings'), 10, 2);
56 56
 		// AJAX
57
-		add_action( 'wp_ajax_espresso_update_event_archive_order', array( 'EED_Events_Archive_Caff', 'update_event_archive_order' ) );
58
-		add_action( 'wp_ajax_nopriv_espresso_update_event_archive_order', array( 'EED_Events_Archive_Caff', 'update_event_archive_order' ) );
57
+		add_action('wp_ajax_espresso_update_event_archive_order', array('EED_Events_Archive_Caff', 'update_event_archive_order'));
58
+		add_action('wp_ajax_nopriv_espresso_update_event_archive_order', array('EED_Events_Archive_Caff', 'update_event_archive_order'));
59 59
 	}
60 60
 
61 61
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 * @param    WP $WP
69 69
 	 * @return    void
70 70
 	 */
71
-	public function run( $WP ) {
71
+	public function run($WP) {
72 72
 	}
73 73
 
74 74
 
@@ -83,61 +83,61 @@  discard block
 block discarded – undo
83 83
 	 */
84 84
 	public static function template_settings_form() {
85 85
 		// grab general settings admin page and remove the existing hook callback
86
-		$gen_set_admin = EE_Registry::instance()->LIB->EE_Admin_Page_Loader->get_admin_page_object( 'general_settings' );
87
-		if ( $gen_set_admin instanceof General_Settings_Admin_Page ) {
86
+		$gen_set_admin = EE_Registry::instance()->LIB->EE_Admin_Page_Loader->get_admin_page_object('general_settings');
87
+		if ($gen_set_admin instanceof General_Settings_Admin_Page) {
88 88
 			remove_action(
89 89
 			    'AHEE__template_settings__template__before_settings_form',
90
-                array( $gen_set_admin, 'template_settings_caff_features' ),
90
+                array($gen_set_admin, 'template_settings_caff_features'),
91 91
                 100
92 92
             );
93 93
 		}
94 94
 		// first just grab the template settings
95 95
 		$config = EE_Registry::instance()->CFG->template_settings;
96 96
 		// then if the Event Archive config is valid, use that, else create a new one
97
-		$config = isset( $config->EED_Events_Archive ) && $config->EED_Events_Archive instanceof EE_Events_Archive_Config
97
+		$config = isset($config->EED_Events_Archive) && $config->EED_Events_Archive instanceof EE_Events_Archive_Config
98 98
             ? $config->EED_Events_Archive
99 99
             : new EE_Events_Archive_Config();
100
-		$config = apply_filters( 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', $config );
101
-		$config->display_status_banner = isset( $config->display_status_banner )
100
+		$config = apply_filters('FHEE__EED_Events_Archive__template_settings_form__event_list_config', $config);
101
+		$config->display_status_banner = isset($config->display_status_banner)
102 102
             ? $config->display_status_banner
103 103
             : 0;
104
-		$config->display_description = isset( $config->display_description )
104
+		$config->display_description = isset($config->display_description)
105 105
             ? $config->display_description
106 106
             : 1;
107
-		$config->display_ticket_selector = isset( $config->display_ticket_selector )
107
+		$config->display_ticket_selector = isset($config->display_ticket_selector)
108 108
             ? $config->display_ticket_selector
109 109
             : 0;
110
-		$config->display_datetimes = isset( $config->display_datetimes )
110
+		$config->display_datetimes = isset($config->display_datetimes)
111 111
             ? $config->display_datetimes
112 112
             : 1;
113
-		$config->display_venue = isset( $config->display_venue )
113
+		$config->display_venue = isset($config->display_venue)
114 114
             ? $config->display_venue
115 115
             : 0;
116
-		$config->display_expired_events = isset( $config->display_expired_events )
116
+		$config->display_expired_events = isset($config->display_expired_events)
117 117
             ? $config->display_expired_events
118 118
             : 0;
119 119
 		// display order options
120
-		$config->use_sortable_display_order = isset( $config->use_sortable_display_order  )
120
+		$config->use_sortable_display_order = isset($config->use_sortable_display_order)
121 121
             ? $config->use_sortable_display_order
122 122
             : false;
123
-		$config->display_order_tickets = isset( $config->display_order_tickets  )
123
+		$config->display_order_tickets = isset($config->display_order_tickets)
124 124
             ? $config->display_order_tickets
125 125
             : 120;
126
-		$config->display_order_datetimes = isset( $config->display_order_datetimes  )
126
+		$config->display_order_datetimes = isset($config->display_order_datetimes)
127 127
             ? $config->display_order_datetimes
128 128
             : 110;
129
-		$config->display_order_event = isset( $config->display_order_event  )
129
+		$config->display_order_event = isset($config->display_order_event)
130 130
             ? $config->display_order_event
131 131
             : 100;
132
-		$config->display_order_venue = isset( $config->display_order_venue  )
132
+		$config->display_order_venue = isset($config->display_order_venue)
133 133
             ? $config->display_order_venue
134 134
             : 130;
135 135
 		// get template parts
136
-		$template_parts = EED_Events_Archive::instance()->initialize_template_parts( $config );
136
+		$template_parts = EED_Events_Archive::instance()->initialize_template_parts($config);
137 137
 		// convert to array so that we can add more properties
138
-		$config = get_object_vars( $config );
139
-		$config[ 'event_archive_display_order' ] = $template_parts->generate_sortable_list_of_template_parts( 'event-archive-sortable-js', '', 'archive-sortable-li archive-sortable-js' );
140
-		EEH_Template::display_template( EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $config );
138
+		$config = get_object_vars($config);
139
+		$config['event_archive_display_order'] = $template_parts->generate_sortable_list_of_template_parts('event-archive-sortable-js', '', 'archive-sortable-li archive-sortable-js');
140
+		EEH_Template::display_template(EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH.'admin-event-list-settings.template.php', $config);
141 141
 	}
142 142
 
143 143
 
@@ -153,32 +153,32 @@  discard block
 block discarded – undo
153 153
 	 *  @param 	array $REQ
154 154
 	 *  @return    EE_Events_Archive_Config
155 155
 	 */
156
-	public static function update_template_settings( $CFG, $REQ ) {
156
+	public static function update_template_settings($CFG, $REQ) {
157 157
 		$config = new EE_Events_Archive_Config();
158 158
 		// unless we are resetting the config...
159
-		if ( ! isset( $REQ['EED_Events_Archive_reset_event_list_settings'] ) || absint( $REQ['EED_Events_Archive_reset_event_list_settings'] ) !== 1 ) {
160
-			$config->display_status_banner = isset( $REQ['EED_Events_Archive_display_status_banner'] ) ? absint( $REQ['EED_Events_Archive_display_status_banner'] ) : 0;
161
-			$config->display_description = isset( $REQ['EED_Events_Archive_display_description'] ) ? absint( $REQ['EED_Events_Archive_display_description'] ) : 1;
162
-			$config->display_ticket_selector = isset( $REQ['EED_Events_Archive_display_ticket_selector'] ) ? absint( $REQ['EED_Events_Archive_display_ticket_selector'] ) : 0;
163
-			$config->display_datetimes = isset( $REQ['EED_Events_Archive_display_datetimes'] ) ? absint( $REQ['EED_Events_Archive_display_datetimes'] ) : 1;
164
-			$config->display_venue = isset( $REQ['EED_Events_Archive_display_venue'] ) ? absint( $REQ['EED_Events_Archive_display_venue'] ) : 0;
165
-			$config->display_expired_events = isset( $REQ['EED_Events_Archive_display_expired_events'] ) ? absint( $REQ['EED_Events_Archive_display_expired_events'] ) : 0;
166
-			$config->use_sortable_display_order = isset( $REQ['EED_Events_Archive_use_sortable_display_order'] ) ? absint( $REQ['EED_Events_Archive_use_sortable_display_order'] ) : 0;
167
-			$config->display_order_event = isset( $CFG->EED_Events_Archive->display_order_event ) && $config->use_sortable_display_order
159
+		if ( ! isset($REQ['EED_Events_Archive_reset_event_list_settings']) || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1) {
160
+			$config->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0;
161
+			$config->display_description = isset($REQ['EED_Events_Archive_display_description']) ? absint($REQ['EED_Events_Archive_display_description']) : 1;
162
+			$config->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0;
163
+			$config->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint($REQ['EED_Events_Archive_display_datetimes']) : 1;
164
+			$config->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint($REQ['EED_Events_Archive_display_venue']) : 0;
165
+			$config->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0;
166
+			$config->use_sortable_display_order = isset($REQ['EED_Events_Archive_use_sortable_display_order']) ? absint($REQ['EED_Events_Archive_use_sortable_display_order']) : 0;
167
+			$config->display_order_event = isset($CFG->EED_Events_Archive->display_order_event) && $config->use_sortable_display_order
168 168
                 ? $CFG->EED_Events_Archive->display_order_event
169 169
                 : EED_Events_Archive::EVENT_DETAILS_PRIORITY;
170
-			$config->display_order_datetimes = isset( $CFG->EED_Events_Archive->display_order_datetimes ) && $config->use_sortable_display_order
170
+			$config->display_order_datetimes = isset($CFG->EED_Events_Archive->display_order_datetimes) && $config->use_sortable_display_order
171 171
                 ? $CFG->EED_Events_Archive->display_order_datetimes
172 172
                 : EED_Events_Archive::EVENT_DATETIMES_PRIORITY;
173
-			$config->display_order_tickets = isset( $CFG->EED_Events_Archive->display_order_tickets ) && $config->use_sortable_display_order
173
+			$config->display_order_tickets = isset($CFG->EED_Events_Archive->display_order_tickets) && $config->use_sortable_display_order
174 174
                 ? $CFG->EED_Events_Archive->display_order_tickets
175 175
                 : EED_Events_Archive::EVENT_TICKETS_PRIORITY;
176
-			$config->display_order_venue = isset( $CFG->EED_Events_Archive->display_order_venue ) && $config->use_sortable_display_order
176
+			$config->display_order_venue = isset($CFG->EED_Events_Archive->display_order_venue) && $config->use_sortable_display_order
177 177
                 ? $CFG->EED_Events_Archive->display_order_venue
178 178
                 : EED_Events_Archive::EVENT_VENUES_PRIORITY;
179 179
 		}
180 180
 		$CFG->EED_Events_Archive = $config;
181
-		do_action( 'AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ );
181
+		do_action('AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ);
182 182
 		return $CFG;
183 183
 	}
184 184
 
@@ -192,12 +192,12 @@  discard block
 block discarded – undo
192 192
 	 */
193 193
 	public static function update_event_archive_order() {
194 194
 		$config_saved = false;
195
-		$template_parts = sanitize_text_field( $_POST[ 'elements' ] );
196
-		if ( ! empty( $template_parts ) ) {
197
-			$template_parts = explode( ',', trim( $template_parts, ',' ) );
198
-			foreach ( $template_parts as $key => $template_part ) {
195
+		$template_parts = sanitize_text_field($_POST['elements']);
196
+		if ( ! empty($template_parts)) {
197
+			$template_parts = explode(',', trim($template_parts, ','));
198
+			foreach ($template_parts as $key => $template_part) {
199 199
 				$template_part = "display_order_$template_part";
200
-				$priority = ( $key * 10 ) + EED_Events_Archive::EVENT_DETAILS_PRIORITY;
200
+				$priority = ($key * 10) + EED_Events_Archive::EVENT_DETAILS_PRIORITY;
201 201
 				if (
202 202
 					property_exists(
203 203
 						EE_Registry::instance()->CFG->template_settings->EED_Events_Archive,
@@ -206,16 +206,16 @@  discard block
 block discarded – undo
206 206
 				) {
207 207
 					EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->{$template_part} = $priority;
208 208
 				}
209
-				do_action( "AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority );
209
+				do_action("AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority);
210 210
 			}
211
-			$config_saved = EE_Registry::instance()->CFG->update_espresso_config( false, false );
211
+			$config_saved = EE_Registry::instance()->CFG->update_espresso_config(false, false);
212 212
 		}
213
-		if ( $config_saved ) {
214
-			EE_Error::add_success( __( 'Display Order has been successfully updated.', 'event_espresso' ) );
213
+		if ($config_saved) {
214
+			EE_Error::add_success(__('Display Order has been successfully updated.', 'event_espresso'));
215 215
 		} else {
216
-			EE_Error::add_error( __( 'Display Order was not updated.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
216
+			EE_Error::add_error(__('Display Order was not updated.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
217 217
 		}
218
-		echo wp_json_encode( EE_Error::get_notices( false ) );
218
+		echo wp_json_encode(EE_Error::get_notices(false));
219 219
 		exit();
220 220
 	}
221 221
 
Please login to merge, or discard this patch.
core/libraries/template_parts/EE_Template_Part_Manager.class.php 2 patches
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 //namespace EventEspresso\core\libraries\templates;
3 3
 if (!defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -19,198 +19,198 @@  discard block
 block discarded – undo
19 19
 class EE_Template_Part_Manager
20 20
 {
21 21
 
22
-    /**
23
-     * @param EE_Template_Part_PriorityQueue $template_parts
24
-     */
25
-    protected $template_parts;
26
-
27
-    /**
28
-     * @param array $priorities
29
-     */
30
-    protected $priorities = array();
31
-
32
-    /**
33
-     * @param int $event_desc_priority
34
-     */
35
-    protected $event_desc_priority;
36
-
37
-    /**
38
-     * @param string $before_event_content
39
-     */
40
-    protected $before_event_content;
41
-
42
-    /**
43
-     * @param string $event_content
44
-     */
45
-    protected $event_content;
46
-
47
-    /**
48
-     * @param string $after_event_content
49
-     */
50
-    protected $after_event_content;
51
-
52
-
53
-    /**
54
-     *    class constructor
55
-     */
56
-    public function __construct()
57
-    {
58
-        $this->template_parts = new EE_Template_Part_PriorityQueue();
59
-    }
60
-
61
-
62
-    /**
63
-     *    add_template_part
64
-     *
65
-     *    used for setting the details about a particular template part
66
-     *
67
-     * @param string $name - just a simple string identifier - do NOT use 'event'
68
-     * @param string $label - template part label displayed in admin
69
-     * @param string $template - name or path of template to be used by EEH_Template::locate_template()
70
-     * @param int $priority - order in which template parts should be applied
71
-     */
72
-    public function add_template_part($name, $label, $template, $priority)
73
-    {
74
-        // SplPriorityQueue doesn't play nice with multiple items having the same priority
75
-        // so if the incoming priority is already occupied, then let's increment it by one,
76
-        // and then pass everything back into this method and try again with the new priority
77
-        if (isset($this->priorities[$priority])) {
78
-            $priority++;
79
-            $this->add_template_part($name, $label, $template, $priority);
80
-            return;
81
-        }
82
-        // kk now we can mark this priority as being occupied
83
-        $this->priorities[$priority] = true;
84
-        // create the template part and add to the queue
85
-        $this->template_parts->insert(
86
-            new EE_Template_Part($name, $label, $template, $priority),
87
-            $priority
88
-        );
89
-        if ($name === 'event') {
90
-            $this->event_desc_priority = $priority;
91
-        }
92
-    }
93
-
94
-
95
-    /**
96
-     *    apply_template_part_filters
97
-     *
98
-     *    adds template parts to the supplied content
99
-     *    according to the details set when the template parts were added
100
-     *
101
-     * @access public
102
-     * @param string $content
103
-     * @return string
104
-     */
105
-    public function apply_template_part_filters($content = '')
106
-    {
107
-        $this->template_parts->rewind();
108
-        // loop through template parts and position content
109
-        while ($this->template_parts->valid()) {
110
-            $this->_position_template_part(
111
-                $content,
112
-                $this->template_parts->current()->template(),
113
-                $this->template_parts->current()->priority()
114
-            );
115
-            $this->template_parts->next();
116
-        }
117
-        // now simply add our three strings of content together
118
-        return $this->before_event_content . $this->event_content . $this->after_event_content;
119
-    }
120
-
121
-
122
-    /**
123
-     *    position_template_part
124
-     *
125
-     * based on the priority of the incoming template part
126
-     * relative to the known event description template part priority,
127
-     * this method will assign template parts to one of the following:
128
-     *        $this->before_event_content
129
-     *        $this->event_content
130
-     *        $this->after_event_content
131
-     *
132
-     * @access protected
133
-     * @param string $content
134
-     * @param string $template
135
-     * @param int $priority
136
-     * @return void
137
-     */
138
-    protected function _position_template_part($content, $template, $priority)
139
-    {
140
-        // Event Description content is the actual incoming content itself
141
-        if ($priority === $this->event_desc_priority) {
142
-            $this->event_content = $content;
143
-        } else if ($priority < $this->event_desc_priority) {
144
-            // everything BEFORE the Event Description
145
-            $this->before_event_content .= EEH_Template::locate_template($template);
146
-        } else if ($priority > $this->event_desc_priority) {
147
-            // everything AFTER the Event Description
148
-            $this->after_event_content .= EEH_Template::locate_template($template);
149
-        }
150
-    }
151
-
152
-
153
-    /**
154
-     *    generate_sortable_list_of_template_parts
155
-     *
156
-     *    creates an HTML list (<ul>) with list items (<li>) for each template part,
157
-     *    in a format that can be used as a sortable list in the admin
158
-     *
159
-     * @access public
160
-     * @param string $list_css_id
161
-     * @param string $list_css_class
162
-     * @param string $list_item_css_class
163
-     * @param string $list_item_css_id_prefix
164
-     * @return string
165
-     */
166
-    public function generate_sortable_list_of_template_parts(
167
-        $list_css_id = '',
168
-        $list_css_class = '',
169
-        $list_item_css_class = '',
170
-        $list_item_css_id_prefix = ''
171
-    )
172
-    {
173
-        $event_archive_display_order = EEH_HTML::ul($list_css_id, $list_css_class);
174
-        $this->template_parts->rewind();
175
-        // loop through template parts and add template content
176
-        while ($this->template_parts->valid()) {
177
-            $event_archive_display_order .= EEH_HTML::li(
178
-                EEH_HTML::span('', '', 'dashicons dashicons-arrow-up-alt2') .
179
-                EEH_HTML::span('', '', 'dashicons dashicons-arrow-down-alt2') .
180
-                $this->template_parts->current()->label(),
181
-                $list_item_css_id_prefix . $this->template_parts->current()->name(),
182
-                $list_item_css_class
183
-            );
184
-            $this->template_parts->next();
185
-        }
186
-        $event_archive_display_order .= EEH_HTML::ulx();
187
-        return $event_archive_display_order;
188
-    }
189
-
190
-
191
-    /**
192
-     *    display_template_parts
193
-     *
194
-     * just for debugging purposes
195
-     *
196
-     * @access    public
197
-     * @return void
198
-     */
199
-    public function display_template_parts()
200
-    {
201
-        if (WP_DEBUG) {
202
-            $this->template_parts->rewind();
203
-            while ($this->template_parts->valid()) {
204
-                EEH_Debug_Tools::printr(
205
-                    $this->template_parts->current(),
206
-                    'template_part',
207
-                    __FILE__,
208
-                    __LINE__
209
-                );
210
-                $this->template_parts->next();
211
-            }
212
-        }
213
-    }
22
+	/**
23
+	 * @param EE_Template_Part_PriorityQueue $template_parts
24
+	 */
25
+	protected $template_parts;
26
+
27
+	/**
28
+	 * @param array $priorities
29
+	 */
30
+	protected $priorities = array();
31
+
32
+	/**
33
+	 * @param int $event_desc_priority
34
+	 */
35
+	protected $event_desc_priority;
36
+
37
+	/**
38
+	 * @param string $before_event_content
39
+	 */
40
+	protected $before_event_content;
41
+
42
+	/**
43
+	 * @param string $event_content
44
+	 */
45
+	protected $event_content;
46
+
47
+	/**
48
+	 * @param string $after_event_content
49
+	 */
50
+	protected $after_event_content;
51
+
52
+
53
+	/**
54
+	 *    class constructor
55
+	 */
56
+	public function __construct()
57
+	{
58
+		$this->template_parts = new EE_Template_Part_PriorityQueue();
59
+	}
60
+
61
+
62
+	/**
63
+	 *    add_template_part
64
+	 *
65
+	 *    used for setting the details about a particular template part
66
+	 *
67
+	 * @param string $name - just a simple string identifier - do NOT use 'event'
68
+	 * @param string $label - template part label displayed in admin
69
+	 * @param string $template - name or path of template to be used by EEH_Template::locate_template()
70
+	 * @param int $priority - order in which template parts should be applied
71
+	 */
72
+	public function add_template_part($name, $label, $template, $priority)
73
+	{
74
+		// SplPriorityQueue doesn't play nice with multiple items having the same priority
75
+		// so if the incoming priority is already occupied, then let's increment it by one,
76
+		// and then pass everything back into this method and try again with the new priority
77
+		if (isset($this->priorities[$priority])) {
78
+			$priority++;
79
+			$this->add_template_part($name, $label, $template, $priority);
80
+			return;
81
+		}
82
+		// kk now we can mark this priority as being occupied
83
+		$this->priorities[$priority] = true;
84
+		// create the template part and add to the queue
85
+		$this->template_parts->insert(
86
+			new EE_Template_Part($name, $label, $template, $priority),
87
+			$priority
88
+		);
89
+		if ($name === 'event') {
90
+			$this->event_desc_priority = $priority;
91
+		}
92
+	}
93
+
94
+
95
+	/**
96
+	 *    apply_template_part_filters
97
+	 *
98
+	 *    adds template parts to the supplied content
99
+	 *    according to the details set when the template parts were added
100
+	 *
101
+	 * @access public
102
+	 * @param string $content
103
+	 * @return string
104
+	 */
105
+	public function apply_template_part_filters($content = '')
106
+	{
107
+		$this->template_parts->rewind();
108
+		// loop through template parts and position content
109
+		while ($this->template_parts->valid()) {
110
+			$this->_position_template_part(
111
+				$content,
112
+				$this->template_parts->current()->template(),
113
+				$this->template_parts->current()->priority()
114
+			);
115
+			$this->template_parts->next();
116
+		}
117
+		// now simply add our three strings of content together
118
+		return $this->before_event_content . $this->event_content . $this->after_event_content;
119
+	}
120
+
121
+
122
+	/**
123
+	 *    position_template_part
124
+	 *
125
+	 * based on the priority of the incoming template part
126
+	 * relative to the known event description template part priority,
127
+	 * this method will assign template parts to one of the following:
128
+	 *        $this->before_event_content
129
+	 *        $this->event_content
130
+	 *        $this->after_event_content
131
+	 *
132
+	 * @access protected
133
+	 * @param string $content
134
+	 * @param string $template
135
+	 * @param int $priority
136
+	 * @return void
137
+	 */
138
+	protected function _position_template_part($content, $template, $priority)
139
+	{
140
+		// Event Description content is the actual incoming content itself
141
+		if ($priority === $this->event_desc_priority) {
142
+			$this->event_content = $content;
143
+		} else if ($priority < $this->event_desc_priority) {
144
+			// everything BEFORE the Event Description
145
+			$this->before_event_content .= EEH_Template::locate_template($template);
146
+		} else if ($priority > $this->event_desc_priority) {
147
+			// everything AFTER the Event Description
148
+			$this->after_event_content .= EEH_Template::locate_template($template);
149
+		}
150
+	}
151
+
152
+
153
+	/**
154
+	 *    generate_sortable_list_of_template_parts
155
+	 *
156
+	 *    creates an HTML list (<ul>) with list items (<li>) for each template part,
157
+	 *    in a format that can be used as a sortable list in the admin
158
+	 *
159
+	 * @access public
160
+	 * @param string $list_css_id
161
+	 * @param string $list_css_class
162
+	 * @param string $list_item_css_class
163
+	 * @param string $list_item_css_id_prefix
164
+	 * @return string
165
+	 */
166
+	public function generate_sortable_list_of_template_parts(
167
+		$list_css_id = '',
168
+		$list_css_class = '',
169
+		$list_item_css_class = '',
170
+		$list_item_css_id_prefix = ''
171
+	)
172
+	{
173
+		$event_archive_display_order = EEH_HTML::ul($list_css_id, $list_css_class);
174
+		$this->template_parts->rewind();
175
+		// loop through template parts and add template content
176
+		while ($this->template_parts->valid()) {
177
+			$event_archive_display_order .= EEH_HTML::li(
178
+				EEH_HTML::span('', '', 'dashicons dashicons-arrow-up-alt2') .
179
+				EEH_HTML::span('', '', 'dashicons dashicons-arrow-down-alt2') .
180
+				$this->template_parts->current()->label(),
181
+				$list_item_css_id_prefix . $this->template_parts->current()->name(),
182
+				$list_item_css_class
183
+			);
184
+			$this->template_parts->next();
185
+		}
186
+		$event_archive_display_order .= EEH_HTML::ulx();
187
+		return $event_archive_display_order;
188
+	}
189
+
190
+
191
+	/**
192
+	 *    display_template_parts
193
+	 *
194
+	 * just for debugging purposes
195
+	 *
196
+	 * @access    public
197
+	 * @return void
198
+	 */
199
+	public function display_template_parts()
200
+	{
201
+		if (WP_DEBUG) {
202
+			$this->template_parts->rewind();
203
+			while ($this->template_parts->valid()) {
204
+				EEH_Debug_Tools::printr(
205
+					$this->template_parts->current(),
206
+					'template_part',
207
+					__FILE__,
208
+					__LINE__
209
+				);
210
+				$this->template_parts->next();
211
+			}
212
+		}
213
+	}
214 214
 }
215 215
 // End of file EE_Template_Part_Manager.class.php
216 216
 // Location: /EE_Template_Part_Manager.class.php
217 217
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 //namespace EventEspresso\core\libraries\templates;
3
-if (!defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
             $this->template_parts->next();
116 116
         }
117 117
         // now simply add our three strings of content together
118
-        return $this->before_event_content . $this->event_content . $this->after_event_content;
118
+        return $this->before_event_content.$this->event_content.$this->after_event_content;
119 119
     }
120 120
 
121 121
 
@@ -175,10 +175,10 @@  discard block
 block discarded – undo
175 175
         // loop through template parts and add template content
176 176
         while ($this->template_parts->valid()) {
177 177
             $event_archive_display_order .= EEH_HTML::li(
178
-                EEH_HTML::span('', '', 'dashicons dashicons-arrow-up-alt2') .
179
-                EEH_HTML::span('', '', 'dashicons dashicons-arrow-down-alt2') .
178
+                EEH_HTML::span('', '', 'dashicons dashicons-arrow-up-alt2').
179
+                EEH_HTML::span('', '', 'dashicons dashicons-arrow-down-alt2').
180 180
                 $this->template_parts->current()->label(),
181
-                $list_item_css_id_prefix . $this->template_parts->current()->name(),
181
+                $list_item_css_id_prefix.$this->template_parts->current()->name(),
182 182
                 $list_item_css_class
183 183
             );
184 184
             $this->template_parts->next();
Please login to merge, or discard this patch.
core/EE_Configurable.core.php 2 patches
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -12,145 +12,145 @@
 block discarded – undo
12 12
 abstract class EE_Configurable extends EE_Base
13 13
 {
14 14
 
15
-    /**
16
-     * @var $_config
17
-     * @type EE_Config_Base
18
-     */
19
-    protected $_config;
20
-
21
-    /**
22
-     * @var $_config_section
23
-     * @type string
24
-     */
25
-    protected $_config_section = '';
26
-
27
-    /**
28
-     * @var $_config_class
29
-     * @type string
30
-     */
31
-    protected $_config_class = '';
32
-
33
-    /**
34
-     * @var $_config_name
35
-     * @type string
36
-     */
37
-    protected $_config_name = '';
38
-
39
-
40
-    /**
41
-     * @param string $config_section
42
-     */
43
-    public function set_config_section($config_section = '')
44
-    {
45
-        $this->_config_section = !empty($config_section) ? $config_section : 'modules';
46
-    }
47
-
48
-
49
-    /**
50
-     * @return mixed
51
-     */
52
-    public function config_section()
53
-    {
54
-        return $this->_config_section;
55
-    }
56
-
57
-
58
-    /**
59
-     * @param string $config_class
60
-     */
61
-    public function set_config_class($config_class = '')
62
-    {
63
-        $this->_config_class = $config_class;
64
-    }
65
-
66
-
67
-    /**
68
-     * @return mixed
69
-     */
70
-    public function config_class()
71
-    {
72
-        return $this->_config_class;
73
-    }
74
-
75
-
76
-    /**
77
-     * @param mixed $config_name
78
-     */
79
-    public function set_config_name($config_name)
80
-    {
81
-        $this->_config_name = !empty($config_name) ? $config_name : get_called_class();
82
-    }
83
-
84
-
85
-    /**
86
-     * @return mixed
87
-     */
88
-    public function config_name()
89
-    {
90
-        return $this->_config_name;
91
-    }
92
-
93
-
94
-    /**
95
-     *    set_config
96
-     *    this method integrates directly with EE_Config to set up the config object for this class
97
-     *
98
-     * @access    protected
99
-     * @param    EE_Config_Base $config_obj
100
-     * @return    mixed    EE_Config_Base | NULL
101
-     */
102
-    protected function _set_config(EE_Config_Base $config_obj = null)
103
-    {
104
-        return EE_Config::instance()->set_config(
105
-            $this->config_section(),
106
-            $this->config_name(),
107
-            $this->config_class(),
108
-            $config_obj
109
-        );
110
-    }
111
-
112
-
113
-    /**
114
-     *    _update_config
115
-     *    this method integrates directly with EE_Config to update an existing config object for this class
116
-     *
117
-     * @access    protected
118
-     * @param    EE_Config_Base $config_obj
119
-     * @throws \EE_Error
120
-     * @return    mixed    EE_Config_Base | NULL
121
-     */
122
-    public function _update_config(EE_Config_Base $config_obj = null)
123
-    {
124
-        $config_class = $this->config_class();
125
-        if (!$config_obj instanceof $config_class) {
126
-            throw new EE_Error(
127
-                sprintf(
128
-                    __('The "%1$s" class is not an instance of %2$s.', 'event_espresso'),
129
-                    print_r($config_obj, true),
130
-                    $config_class
131
-                )
132
-            );
133
-        }
134
-        return EE_Config::instance()->update_config($this->config_section(), $this->config_name(), $config_obj);
135
-    }
136
-
137
-
138
-    /**
139
-     * gets the class's config object
140
-     *
141
-     * @return EE_Config_Base
142
-     */
143
-    public function config()
144
-    {
145
-        if (empty($this->_config)) {
146
-            $this->_config = EE_Config::instance()->get_config(
147
-                $this->config_section(),
148
-                $this->config_name(),
149
-                $this->config_class()
150
-            );
151
-        }
152
-        return $this->_config;
153
-    }
15
+	/**
16
+	 * @var $_config
17
+	 * @type EE_Config_Base
18
+	 */
19
+	protected $_config;
20
+
21
+	/**
22
+	 * @var $_config_section
23
+	 * @type string
24
+	 */
25
+	protected $_config_section = '';
26
+
27
+	/**
28
+	 * @var $_config_class
29
+	 * @type string
30
+	 */
31
+	protected $_config_class = '';
32
+
33
+	/**
34
+	 * @var $_config_name
35
+	 * @type string
36
+	 */
37
+	protected $_config_name = '';
38
+
39
+
40
+	/**
41
+	 * @param string $config_section
42
+	 */
43
+	public function set_config_section($config_section = '')
44
+	{
45
+		$this->_config_section = !empty($config_section) ? $config_section : 'modules';
46
+	}
47
+
48
+
49
+	/**
50
+	 * @return mixed
51
+	 */
52
+	public function config_section()
53
+	{
54
+		return $this->_config_section;
55
+	}
56
+
57
+
58
+	/**
59
+	 * @param string $config_class
60
+	 */
61
+	public function set_config_class($config_class = '')
62
+	{
63
+		$this->_config_class = $config_class;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return mixed
69
+	 */
70
+	public function config_class()
71
+	{
72
+		return $this->_config_class;
73
+	}
74
+
75
+
76
+	/**
77
+	 * @param mixed $config_name
78
+	 */
79
+	public function set_config_name($config_name)
80
+	{
81
+		$this->_config_name = !empty($config_name) ? $config_name : get_called_class();
82
+	}
83
+
84
+
85
+	/**
86
+	 * @return mixed
87
+	 */
88
+	public function config_name()
89
+	{
90
+		return $this->_config_name;
91
+	}
92
+
93
+
94
+	/**
95
+	 *    set_config
96
+	 *    this method integrates directly with EE_Config to set up the config object for this class
97
+	 *
98
+	 * @access    protected
99
+	 * @param    EE_Config_Base $config_obj
100
+	 * @return    mixed    EE_Config_Base | NULL
101
+	 */
102
+	protected function _set_config(EE_Config_Base $config_obj = null)
103
+	{
104
+		return EE_Config::instance()->set_config(
105
+			$this->config_section(),
106
+			$this->config_name(),
107
+			$this->config_class(),
108
+			$config_obj
109
+		);
110
+	}
111
+
112
+
113
+	/**
114
+	 *    _update_config
115
+	 *    this method integrates directly with EE_Config to update an existing config object for this class
116
+	 *
117
+	 * @access    protected
118
+	 * @param    EE_Config_Base $config_obj
119
+	 * @throws \EE_Error
120
+	 * @return    mixed    EE_Config_Base | NULL
121
+	 */
122
+	public function _update_config(EE_Config_Base $config_obj = null)
123
+	{
124
+		$config_class = $this->config_class();
125
+		if (!$config_obj instanceof $config_class) {
126
+			throw new EE_Error(
127
+				sprintf(
128
+					__('The "%1$s" class is not an instance of %2$s.', 'event_espresso'),
129
+					print_r($config_obj, true),
130
+					$config_class
131
+				)
132
+			);
133
+		}
134
+		return EE_Config::instance()->update_config($this->config_section(), $this->config_name(), $config_obj);
135
+	}
136
+
137
+
138
+	/**
139
+	 * gets the class's config object
140
+	 *
141
+	 * @return EE_Config_Base
142
+	 */
143
+	public function config()
144
+	{
145
+		if (empty($this->_config)) {
146
+			$this->_config = EE_Config::instance()->get_config(
147
+				$this->config_section(),
148
+				$this->config_name(),
149
+				$this->config_class()
150
+			);
151
+		}
152
+		return $this->_config;
153
+	}
154 154
 
155 155
 
156 156
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function set_config_section($config_section = '')
44 44
     {
45
-        $this->_config_section = !empty($config_section) ? $config_section : 'modules';
45
+        $this->_config_section = ! empty($config_section) ? $config_section : 'modules';
46 46
     }
47 47
 
48 48
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
      */
79 79
     public function set_config_name($config_name)
80 80
     {
81
-        $this->_config_name = !empty($config_name) ? $config_name : get_called_class();
81
+        $this->_config_name = ! empty($config_name) ? $config_name : get_called_class();
82 82
     }
83 83
 
84 84
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
     public function _update_config(EE_Config_Base $config_obj = null)
123 123
     {
124 124
         $config_class = $this->config_class();
125
-        if (!$config_obj instanceof $config_class) {
125
+        if ( ! $config_obj instanceof $config_class) {
126 126
             throw new EE_Error(
127 127
                 sprintf(
128 128
                     __('The "%1$s" class is not an instance of %2$s.', 'event_espresso'),
Please login to merge, or discard this patch.
modules/event_single/EED_Event_Single.module.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
      */
71 71
     public static function set_definitions()
72 72
     {
73
-        define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
74
-        define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS);
73
+        define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
74
+        define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__).'templates'.DS);
75 75
     }
76 76
 
77 77
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
         }
164 164
         // not a custom template?
165 165
         if (
166
-            !post_password_required($post)
166
+            ! post_password_required($post)
167 167
             && (
168 168
                 apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
169 169
                 || EE_Registry::instance()
@@ -212,8 +212,8 @@  discard block
 block discarded – undo
212 212
     public static function the_title($title = '', $id = 0)
213 213
     {
214 214
         global $post;
215
-        return in_the_loop() && $post->ID === (int)$id
216
-            ? espresso_event_status_banner($post->ID) . $title
215
+        return in_the_loop() && $post->ID === (int) $id
216
+            ? espresso_event_status_banner($post->ID).$title
217 217
             : $title;
218 218
     }
219 219
 
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
         if (
261 261
             $current_post_ID !== $post->ID
262 262
             && $post->post_type === 'espresso_events'
263
-            && !EED_Event_Single::$using_get_the_excerpt
264
-            && !post_password_required()
263
+            && ! EED_Event_Single::$using_get_the_excerpt
264
+            && ! post_password_required()
265 265
         ) {
266 266
             // Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
267 267
             // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
      */
370 370
     public static function event_datetimes($content)
371 371
     {
372
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
372
+        return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content;
373 373
     }
374 374
 
375 375
 
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
      */
382 382
     public static function event_tickets($content)
383 383
     {
384
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
384
+        return EEH_Template::locate_template('content-espresso_events-tickets.php').$content;
385 385
     }
386 386
 
387 387
 
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
      */
406 406
     public static function event_venues($content)
407 407
     {
408
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
408
+        return $content.EEH_Template::locate_template('content-espresso_events-venues.php');
409 409
     }
410 410
 
411 411
 
@@ -435,16 +435,16 @@  discard block
 block discarded – undo
435 435
             && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', TRUE)
436 436
         ) {
437 437
             // first check uploads folder
438
-            if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
438
+            if (is_readable(get_stylesheet_directory().$this->theme.DS.'style.css')) {
439 439
                 wp_register_style(
440 440
                     $this->theme,
441
-                    get_stylesheet_directory_uri() . $this->theme . DS . 'style.css',
441
+                    get_stylesheet_directory_uri().$this->theme.DS.'style.css',
442 442
                     array('dashicons', 'espresso_default')
443 443
                 );
444 444
             } else {
445 445
                 wp_register_style(
446 446
                     $this->theme,
447
-                    EE_TEMPLATES_URL . $this->theme . DS . 'style.css',
447
+                    EE_TEMPLATES_URL.$this->theme.DS.'style.css',
448 448
                     array('dashicons', 'espresso_default')
449 449
                 );
450 450
             }
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
         $config = EED_Event_Single::instance()->config();
468 468
         $display_venue = $config->display_venue === null ? true : $config->display_venue;
469 469
         $venue_name = EEH_Venue_View::venue_name();
470
-        return $display_venue && !empty($venue_name);
470
+        return $display_venue && ! empty($venue_name);
471 471
     }
472 472
 
473 473
 
Please login to merge, or discard this patch.
Indentation   +462 added lines, -462 removed lines patch added patch discarded remove patch
@@ -13,467 +13,467 @@  discard block
 block discarded – undo
13 13
 class EED_Event_Single extends EED_Module
14 14
 {
15 15
 
16
-    const EVENT_DETAILS_PRIORITY = 100;
17
-    const EVENT_DATETIMES_PRIORITY = 110;
18
-    const EVENT_TICKETS_PRIORITY = 120;
19
-    const EVENT_VENUES_PRIORITY = 130;
20
-
21
-    /**
22
-     * @type bool $using_get_the_excerpt
23
-     */
24
-    protected static $using_get_the_excerpt = false;
25
-
26
-
27
-    /**
28
-     * @type EE_Template_Part_Manager $template_parts
29
-     */
30
-    protected $template_parts;
31
-
32
-
33
-    /**
34
-     * @return EED_Module|EED_Event_Single
35
-     */
36
-    public static function instance()
37
-    {
38
-        return parent::get_instance(__CLASS__);
39
-    }
40
-
41
-
42
-    /**
43
-     * set_hooks - for hooking into EE Core, other modules, etc
44
-     *
45
-     * @return    void
46
-     */
47
-    public static function set_hooks()
48
-    {
49
-        add_filter('FHEE_run_EE_wp', '__return_true');
50
-        add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
51
-        $custom_post_types = EE_Register_CPTs::get_CPTs();
52
-        EE_Config::register_route(
53
-            $custom_post_types['espresso_events']['singular_slug'],
54
-            'Event_Single',
55
-            'run'
56
-        );
57
-    }
58
-
59
-    /**
60
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
61
-     *
62
-     * @return    void
63
-     */
64
-    public static function set_hooks_admin()
65
-    {
66
-        add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
67
-    }
68
-
69
-
70
-    /**
71
-     * set_definitions
72
-     *
73
-     * @static
74
-     * @return void
75
-     */
76
-    public static function set_definitions()
77
-    {
78
-        define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
79
-        define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS);
80
-    }
81
-
82
-
83
-    /**
84
-     * set_config
85
-     *
86
-     * @void
87
-     */
88
-    protected function set_config()
89
-    {
90
-        $this->set_config_section('template_settings');
91
-        $this->set_config_class('EE_Event_Single_Config');
92
-        $this->set_config_name('EED_Event_Single');
93
-    }
94
-
95
-
96
-    /**
97
-     * initialize_template_parts
98
-     *
99
-     * @param EE_Config_Base|EE_Event_Single_Config $config
100
-     * @return EE_Template_Part_Manager
101
-     */
102
-    public function initialize_template_parts(EE_Event_Single_Config $config = null)
103
-    {
104
-        /** @type EE_Event_Single_Config $config */
105
-        $config = $config instanceof EE_Event_Single_Config ? $config : $this->config();
106
-        EEH_Autoloader::instance()->register_template_part_autoloaders();
107
-        $template_parts = new EE_Template_Part_Manager();
108
-        $template_parts->add_template_part(
109
-            'tickets',
110
-            __('Ticket Selector', 'event_espresso'),
111
-            'content-espresso_events-tickets.php',
112
-            $config->display_order_tickets
113
-        );
114
-        $template_parts->add_template_part(
115
-            'datetimes',
116
-            __('Dates and Times', 'event_espresso'),
117
-            'content-espresso_events-datetimes.php',
118
-            $config->display_order_datetimes
119
-        );
120
-        $template_parts->add_template_part(
121
-            'event',
122
-            __('Event Description', 'event_espresso'),
123
-            'content-espresso_events-details.php',
124
-            $config->display_order_event
125
-        );
126
-        $template_parts->add_template_part(
127
-            'venue',
128
-            __('Venue Information', 'event_espresso'),
129
-            'content-espresso_events-venues.php',
130
-            $config->display_order_venue
131
-        );
132
-        do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts);
133
-        return $template_parts;
134
-    }
135
-
136
-
137
-    /**
138
-     * run - initial module setup
139
-     *
140
-     * @param WP $WP
141
-     * @return    void
142
-     */
143
-    public function run($WP)
144
-    {
145
-        // ensure valid EE_Events_Single_Config() object exists
146
-        $this->set_config();
147
-        // check what template is loaded
148
-        add_filter('template_include', array($this, 'template_include'), 999, 1);
149
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
150
-        // load css
151
-        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
152
-    }
153
-
154
-
155
-    /**
156
-     * template_include
157
-     *
158
-     * @param    string $template
159
-     * @return    string
160
-     */
161
-    public function template_include($template)
162
-    {
163
-        global $post;
164
-        /** @type EE_Event_Single_Config $config */
165
-        $config = $this->config();
166
-        if ($config->display_status_banner_single) {
167
-            add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
168
-        }
169
-        // not a custom template?
170
-        if (
171
-            !post_password_required($post)
172
-            && (
173
-                apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
174
-                || EE_Registry::instance()
175
-                    ->load_core('Front_Controller')
176
-                    ->get_selected_template() !== 'single-espresso_events.php'
177
-            )
178
-
179
-        ) {
180
-            EEH_Template::load_espresso_theme_functions();
181
-            // then add extra event data via hooks
182
-            add_action('loop_start', array('EED_Event_Single', 'loop_start'));
183
-            add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1);
184
-            add_filter(
185
-                'the_content',
186
-                array('EED_Event_Single', 'event_details'),
187
-                EED_Event_Single::EVENT_DETAILS_PRIORITY
188
-            );
189
-            add_action('loop_end', array('EED_Event_Single', 'loop_end'));
190
-            // don't display entry meta because the existing theme will take car of that
191
-            add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
192
-        }
193
-        return $template;
194
-    }
195
-
196
-
197
-    /**
198
-     * loop_start
199
-     *
200
-     * @param    array $wp_query_array an array containing the WP_Query object
201
-     * @return    void
202
-     */
203
-    public static function loop_start($wp_query_array)
204
-    {
205
-        global $post;
206
-        do_action('AHEE_event_details_before_post', $post, $wp_query_array);
207
-    }
208
-
209
-
210
-    /**
211
-     * the_title
212
-     *
213
-     * @param    string $title
214
-     * @param    int $id
215
-     * @return    string
216
-     */
217
-    public static function the_title($title = '', $id = 0)
218
-    {
219
-        global $post;
220
-        return in_the_loop() && $post->ID === (int)$id
221
-            ? espresso_event_status_banner($post->ID) . $title
222
-            : $title;
223
-    }
224
-
225
-
226
-    /**
227
-     * get_the_excerpt
228
-     * kinda hacky, but if a theme is using get_the_excerpt(),
229
-     * then we need to remove our filters on the_content()
230
-     *
231
-     * @param        string $excerpt
232
-     * @return        string
233
-     */
234
-    public static function get_the_excerpt($excerpt = '')
235
-    {
236
-        EED_Event_Single::$using_get_the_excerpt = true;
237
-        add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1);
238
-        return $excerpt;
239
-    }
240
-
241
-
242
-    /**
243
-     * end_get_the_excerpt
244
-     *
245
-     * @param  string $text
246
-     * @return string
247
-     */
248
-    public static function end_get_the_excerpt($text = '')
249
-    {
250
-        EED_Event_Single::$using_get_the_excerpt = false;
251
-        return $text;
252
-    }
253
-
254
-
255
-    /**
256
-     * event_details
257
-     *
258
-     * @param    string $content
259
-     * @return    string
260
-     */
261
-    public static function event_details($content)
262
-    {
263
-        global $post;
264
-        static $current_post_ID = 0;
265
-        if (
266
-            $current_post_ID !== $post->ID
267
-            && $post->post_type === 'espresso_events'
268
-            && !EED_Event_Single::$using_get_the_excerpt
269
-            && !post_password_required()
270
-        ) {
271
-            // Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
272
-            // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
273
-            // BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
274
-            // We want to allow those plugins to still do their thing and have access to our content, but depending on
275
-            // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
276
-            // so the following allows this filter to be applied multiple times, but only once for real
277
-            $current_post_ID = did_action('loop_start') ? $post->ID : 0;
278
-            if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) {
279
-                // we need to first remove this callback from being applied to the_content()
280
-                // (otherwise it will recurse and blow up the interweb)
281
-                remove_filter(
282
-                    'the_content',
283
-                    array('EED_Event_Single', 'event_details'),
284
-                    EED_Event_Single::EVENT_DETAILS_PRIORITY
285
-                );
286
-                EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts();
287
-                $content = EEH_Template::locate_template('content-espresso_events-details.php');
288
-                $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content);
289
-                add_filter(
290
-                    'the_content',
291
-                    array('EED_Event_Single', 'event_details'),
292
-                    EED_Event_Single::EVENT_DETAILS_PRIORITY
293
-                );
294
-            } else {
295
-                $content = EED_Event_Single::use_filterable_display_order();
296
-            }
297
-        }
298
-        return $content;
299
-    }
300
-
301
-
302
-    /**
303
-     * use_filterable_display_order
304
-     *
305
-     * @return string
306
-     */
307
-    protected static function use_filterable_display_order()
308
-    {
309
-        // since the 'content-espresso_events-details.php' template might be used directly from within a theme,
310
-        // it uses the_content() for displaying the $post->post_content
311
-        // so in order to load a template that uses the_content()
312
-        // from within a callback being used to filter the_content(),
313
-        // we need to first remove this callback from being applied to the_content()
314
-        // (otherwise it will recurse and blow up the interweb)
315
-        remove_filter(
316
-            'the_content',
317
-            array('EED_Event_Single', 'event_details'),
318
-            EED_Event_Single::EVENT_DETAILS_PRIORITY
319
-        );
320
-        //now add additional content
321
-        add_filter(
322
-            'the_content',
323
-            array('EED_Event_Single', 'event_datetimes'),
324
-            EED_Event_Single::EVENT_DATETIMES_PRIORITY,
325
-            1
326
-        );
327
-        add_filter(
328
-            'the_content',
329
-            array('EED_Event_Single', 'event_tickets'),
330
-            EED_Event_Single::EVENT_TICKETS_PRIORITY,
331
-            1
332
-        );
333
-        add_filter(
334
-            'the_content',
335
-            array('EED_Event_Single', 'event_venues'),
336
-            EED_Event_Single::EVENT_VENUES_PRIORITY,
337
-            1
338
-        );
339
-        do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters');
340
-        // now load our template
341
-        $content = EEH_Template::locate_template('content-espresso_events-details.php');
342
-        //now add our filter back in, plus some others
343
-        add_filter(
344
-            'the_content',
345
-            array('EED_Event_Single', 'event_details'),
346
-            EED_Event_Single::EVENT_DETAILS_PRIORITY
347
-        );
348
-        remove_filter(
349
-            'the_content',
350
-            array('EED_Event_Single', 'event_datetimes'),
351
-            EED_Event_Single::EVENT_DATETIMES_PRIORITY
352
-        );
353
-        remove_filter(
354
-            'the_content',
355
-            array('EED_Event_Single', 'event_tickets'),
356
-            EED_Event_Single::EVENT_TICKETS_PRIORITY
357
-        );
358
-        remove_filter(
359
-            'the_content',
360
-            array('EED_Event_Single', 'event_venues'),
361
-            EED_Event_Single::EVENT_VENUES_PRIORITY
362
-        );
363
-        do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters');
364
-        // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
365
-        return $content;
366
-    }
367
-
368
-
369
-    /**
370
-     * event_datetimes - adds datetimes ABOVE content
371
-     *
372
-     * @param        string $content
373
-     * @return        string
374
-     */
375
-    public static function event_datetimes($content)
376
-    {
377
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
378
-    }
379
-
380
-
381
-    /**
382
-     * event_tickets - adds tickets ABOVE content (which includes datetimes)
383
-     *
384
-     * @param        string $content
385
-     * @return        string
386
-     */
387
-    public static function event_tickets($content)
388
-    {
389
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
390
-    }
391
-
392
-
393
-    /**
394
-     * event_venues
395
-     *
396
-     * @param    string $content
397
-     * @return    string
398
-     */
399
-    public static function event_venue($content)
400
-    {
401
-        return EED_Event_Single::event_venues($content);
402
-    }
403
-
404
-
405
-    /**
406
-     * event_venues - adds venues BELOW content
407
-     *
408
-     * @param        string $content
409
-     * @return        string
410
-     */
411
-    public static function event_venues($content)
412
-    {
413
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
414
-    }
415
-
416
-
417
-    /**
418
-     * loop_end
419
-     *
420
-     * @param        array $wp_query_array an array containing the WP_Query object
421
-     * @return        void
422
-     */
423
-    public static function loop_end($wp_query_array)
424
-    {
425
-        global $post;
426
-        do_action('AHEE_event_details_after_post', $post, $wp_query_array);
427
-    }
428
-
429
-
430
-    /**
431
-     * wp_enqueue_scripts
432
-     *
433
-     * @return    void
434
-     */
435
-    public function wp_enqueue_scripts()
436
-    {
437
-        // get some style
438
-        if (
439
-            apply_filters('FHEE_enable_default_espresso_css', TRUE)
440
-            && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', TRUE)
441
-        ) {
442
-            // first check uploads folder
443
-            if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
444
-                wp_register_style(
445
-                    $this->theme,
446
-                    get_stylesheet_directory_uri() . $this->theme . DS . 'style.css',
447
-                    array('dashicons', 'espresso_default')
448
-                );
449
-            } else {
450
-                wp_register_style(
451
-                    $this->theme,
452
-                    EE_TEMPLATES_URL . $this->theme . DS . 'style.css',
453
-                    array('dashicons', 'espresso_default')
454
-                );
455
-            }
456
-            wp_enqueue_script($this->theme);
457
-            if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
458
-                add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
459
-            }
460
-        }
461
-    }
462
-
463
-
464
-    /**
465
-     * display_venue
466
-     *
467
-     * @return    bool
468
-     */
469
-    public static function display_venue()
470
-    {
471
-        /** @type EE_Event_Single_Config $config */
472
-        $config = EED_Event_Single::instance()->config();
473
-        $display_venue = $config->display_venue === null ? true : $config->display_venue;
474
-        $venue_name = EEH_Venue_View::venue_name();
475
-        return $display_venue && !empty($venue_name);
476
-    }
16
+	const EVENT_DETAILS_PRIORITY = 100;
17
+	const EVENT_DATETIMES_PRIORITY = 110;
18
+	const EVENT_TICKETS_PRIORITY = 120;
19
+	const EVENT_VENUES_PRIORITY = 130;
20
+
21
+	/**
22
+	 * @type bool $using_get_the_excerpt
23
+	 */
24
+	protected static $using_get_the_excerpt = false;
25
+
26
+
27
+	/**
28
+	 * @type EE_Template_Part_Manager $template_parts
29
+	 */
30
+	protected $template_parts;
31
+
32
+
33
+	/**
34
+	 * @return EED_Module|EED_Event_Single
35
+	 */
36
+	public static function instance()
37
+	{
38
+		return parent::get_instance(__CLASS__);
39
+	}
40
+
41
+
42
+	/**
43
+	 * set_hooks - for hooking into EE Core, other modules, etc
44
+	 *
45
+	 * @return    void
46
+	 */
47
+	public static function set_hooks()
48
+	{
49
+		add_filter('FHEE_run_EE_wp', '__return_true');
50
+		add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
51
+		$custom_post_types = EE_Register_CPTs::get_CPTs();
52
+		EE_Config::register_route(
53
+			$custom_post_types['espresso_events']['singular_slug'],
54
+			'Event_Single',
55
+			'run'
56
+		);
57
+	}
58
+
59
+	/**
60
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
61
+	 *
62
+	 * @return    void
63
+	 */
64
+	public static function set_hooks_admin()
65
+	{
66
+		add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
67
+	}
68
+
69
+
70
+	/**
71
+	 * set_definitions
72
+	 *
73
+	 * @static
74
+	 * @return void
75
+	 */
76
+	public static function set_definitions()
77
+	{
78
+		define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
79
+		define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS);
80
+	}
81
+
82
+
83
+	/**
84
+	 * set_config
85
+	 *
86
+	 * @void
87
+	 */
88
+	protected function set_config()
89
+	{
90
+		$this->set_config_section('template_settings');
91
+		$this->set_config_class('EE_Event_Single_Config');
92
+		$this->set_config_name('EED_Event_Single');
93
+	}
94
+
95
+
96
+	/**
97
+	 * initialize_template_parts
98
+	 *
99
+	 * @param EE_Config_Base|EE_Event_Single_Config $config
100
+	 * @return EE_Template_Part_Manager
101
+	 */
102
+	public function initialize_template_parts(EE_Event_Single_Config $config = null)
103
+	{
104
+		/** @type EE_Event_Single_Config $config */
105
+		$config = $config instanceof EE_Event_Single_Config ? $config : $this->config();
106
+		EEH_Autoloader::instance()->register_template_part_autoloaders();
107
+		$template_parts = new EE_Template_Part_Manager();
108
+		$template_parts->add_template_part(
109
+			'tickets',
110
+			__('Ticket Selector', 'event_espresso'),
111
+			'content-espresso_events-tickets.php',
112
+			$config->display_order_tickets
113
+		);
114
+		$template_parts->add_template_part(
115
+			'datetimes',
116
+			__('Dates and Times', 'event_espresso'),
117
+			'content-espresso_events-datetimes.php',
118
+			$config->display_order_datetimes
119
+		);
120
+		$template_parts->add_template_part(
121
+			'event',
122
+			__('Event Description', 'event_espresso'),
123
+			'content-espresso_events-details.php',
124
+			$config->display_order_event
125
+		);
126
+		$template_parts->add_template_part(
127
+			'venue',
128
+			__('Venue Information', 'event_espresso'),
129
+			'content-espresso_events-venues.php',
130
+			$config->display_order_venue
131
+		);
132
+		do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts);
133
+		return $template_parts;
134
+	}
135
+
136
+
137
+	/**
138
+	 * run - initial module setup
139
+	 *
140
+	 * @param WP $WP
141
+	 * @return    void
142
+	 */
143
+	public function run($WP)
144
+	{
145
+		// ensure valid EE_Events_Single_Config() object exists
146
+		$this->set_config();
147
+		// check what template is loaded
148
+		add_filter('template_include', array($this, 'template_include'), 999, 1);
149
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
150
+		// load css
151
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
152
+	}
153
+
154
+
155
+	/**
156
+	 * template_include
157
+	 *
158
+	 * @param    string $template
159
+	 * @return    string
160
+	 */
161
+	public function template_include($template)
162
+	{
163
+		global $post;
164
+		/** @type EE_Event_Single_Config $config */
165
+		$config = $this->config();
166
+		if ($config->display_status_banner_single) {
167
+			add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
168
+		}
169
+		// not a custom template?
170
+		if (
171
+			!post_password_required($post)
172
+			&& (
173
+				apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
174
+				|| EE_Registry::instance()
175
+					->load_core('Front_Controller')
176
+					->get_selected_template() !== 'single-espresso_events.php'
177
+			)
178
+
179
+		) {
180
+			EEH_Template::load_espresso_theme_functions();
181
+			// then add extra event data via hooks
182
+			add_action('loop_start', array('EED_Event_Single', 'loop_start'));
183
+			add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1);
184
+			add_filter(
185
+				'the_content',
186
+				array('EED_Event_Single', 'event_details'),
187
+				EED_Event_Single::EVENT_DETAILS_PRIORITY
188
+			);
189
+			add_action('loop_end', array('EED_Event_Single', 'loop_end'));
190
+			// don't display entry meta because the existing theme will take car of that
191
+			add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
192
+		}
193
+		return $template;
194
+	}
195
+
196
+
197
+	/**
198
+	 * loop_start
199
+	 *
200
+	 * @param    array $wp_query_array an array containing the WP_Query object
201
+	 * @return    void
202
+	 */
203
+	public static function loop_start($wp_query_array)
204
+	{
205
+		global $post;
206
+		do_action('AHEE_event_details_before_post', $post, $wp_query_array);
207
+	}
208
+
209
+
210
+	/**
211
+	 * the_title
212
+	 *
213
+	 * @param    string $title
214
+	 * @param    int $id
215
+	 * @return    string
216
+	 */
217
+	public static function the_title($title = '', $id = 0)
218
+	{
219
+		global $post;
220
+		return in_the_loop() && $post->ID === (int)$id
221
+			? espresso_event_status_banner($post->ID) . $title
222
+			: $title;
223
+	}
224
+
225
+
226
+	/**
227
+	 * get_the_excerpt
228
+	 * kinda hacky, but if a theme is using get_the_excerpt(),
229
+	 * then we need to remove our filters on the_content()
230
+	 *
231
+	 * @param        string $excerpt
232
+	 * @return        string
233
+	 */
234
+	public static function get_the_excerpt($excerpt = '')
235
+	{
236
+		EED_Event_Single::$using_get_the_excerpt = true;
237
+		add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1);
238
+		return $excerpt;
239
+	}
240
+
241
+
242
+	/**
243
+	 * end_get_the_excerpt
244
+	 *
245
+	 * @param  string $text
246
+	 * @return string
247
+	 */
248
+	public static function end_get_the_excerpt($text = '')
249
+	{
250
+		EED_Event_Single::$using_get_the_excerpt = false;
251
+		return $text;
252
+	}
253
+
254
+
255
+	/**
256
+	 * event_details
257
+	 *
258
+	 * @param    string $content
259
+	 * @return    string
260
+	 */
261
+	public static function event_details($content)
262
+	{
263
+		global $post;
264
+		static $current_post_ID = 0;
265
+		if (
266
+			$current_post_ID !== $post->ID
267
+			&& $post->post_type === 'espresso_events'
268
+			&& !EED_Event_Single::$using_get_the_excerpt
269
+			&& !post_password_required()
270
+		) {
271
+			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
272
+			// Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
273
+			// BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
274
+			// We want to allow those plugins to still do their thing and have access to our content, but depending on
275
+			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
276
+			// so the following allows this filter to be applied multiple times, but only once for real
277
+			$current_post_ID = did_action('loop_start') ? $post->ID : 0;
278
+			if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) {
279
+				// we need to first remove this callback from being applied to the_content()
280
+				// (otherwise it will recurse and blow up the interweb)
281
+				remove_filter(
282
+					'the_content',
283
+					array('EED_Event_Single', 'event_details'),
284
+					EED_Event_Single::EVENT_DETAILS_PRIORITY
285
+				);
286
+				EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts();
287
+				$content = EEH_Template::locate_template('content-espresso_events-details.php');
288
+				$content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content);
289
+				add_filter(
290
+					'the_content',
291
+					array('EED_Event_Single', 'event_details'),
292
+					EED_Event_Single::EVENT_DETAILS_PRIORITY
293
+				);
294
+			} else {
295
+				$content = EED_Event_Single::use_filterable_display_order();
296
+			}
297
+		}
298
+		return $content;
299
+	}
300
+
301
+
302
+	/**
303
+	 * use_filterable_display_order
304
+	 *
305
+	 * @return string
306
+	 */
307
+	protected static function use_filterable_display_order()
308
+	{
309
+		// since the 'content-espresso_events-details.php' template might be used directly from within a theme,
310
+		// it uses the_content() for displaying the $post->post_content
311
+		// so in order to load a template that uses the_content()
312
+		// from within a callback being used to filter the_content(),
313
+		// we need to first remove this callback from being applied to the_content()
314
+		// (otherwise it will recurse and blow up the interweb)
315
+		remove_filter(
316
+			'the_content',
317
+			array('EED_Event_Single', 'event_details'),
318
+			EED_Event_Single::EVENT_DETAILS_PRIORITY
319
+		);
320
+		//now add additional content
321
+		add_filter(
322
+			'the_content',
323
+			array('EED_Event_Single', 'event_datetimes'),
324
+			EED_Event_Single::EVENT_DATETIMES_PRIORITY,
325
+			1
326
+		);
327
+		add_filter(
328
+			'the_content',
329
+			array('EED_Event_Single', 'event_tickets'),
330
+			EED_Event_Single::EVENT_TICKETS_PRIORITY,
331
+			1
332
+		);
333
+		add_filter(
334
+			'the_content',
335
+			array('EED_Event_Single', 'event_venues'),
336
+			EED_Event_Single::EVENT_VENUES_PRIORITY,
337
+			1
338
+		);
339
+		do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters');
340
+		// now load our template
341
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
342
+		//now add our filter back in, plus some others
343
+		add_filter(
344
+			'the_content',
345
+			array('EED_Event_Single', 'event_details'),
346
+			EED_Event_Single::EVENT_DETAILS_PRIORITY
347
+		);
348
+		remove_filter(
349
+			'the_content',
350
+			array('EED_Event_Single', 'event_datetimes'),
351
+			EED_Event_Single::EVENT_DATETIMES_PRIORITY
352
+		);
353
+		remove_filter(
354
+			'the_content',
355
+			array('EED_Event_Single', 'event_tickets'),
356
+			EED_Event_Single::EVENT_TICKETS_PRIORITY
357
+		);
358
+		remove_filter(
359
+			'the_content',
360
+			array('EED_Event_Single', 'event_venues'),
361
+			EED_Event_Single::EVENT_VENUES_PRIORITY
362
+		);
363
+		do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters');
364
+		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
365
+		return $content;
366
+	}
367
+
368
+
369
+	/**
370
+	 * event_datetimes - adds datetimes ABOVE content
371
+	 *
372
+	 * @param        string $content
373
+	 * @return        string
374
+	 */
375
+	public static function event_datetimes($content)
376
+	{
377
+		return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
378
+	}
379
+
380
+
381
+	/**
382
+	 * event_tickets - adds tickets ABOVE content (which includes datetimes)
383
+	 *
384
+	 * @param        string $content
385
+	 * @return        string
386
+	 */
387
+	public static function event_tickets($content)
388
+	{
389
+		return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
390
+	}
391
+
392
+
393
+	/**
394
+	 * event_venues
395
+	 *
396
+	 * @param    string $content
397
+	 * @return    string
398
+	 */
399
+	public static function event_venue($content)
400
+	{
401
+		return EED_Event_Single::event_venues($content);
402
+	}
403
+
404
+
405
+	/**
406
+	 * event_venues - adds venues BELOW content
407
+	 *
408
+	 * @param        string $content
409
+	 * @return        string
410
+	 */
411
+	public static function event_venues($content)
412
+	{
413
+		return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
414
+	}
415
+
416
+
417
+	/**
418
+	 * loop_end
419
+	 *
420
+	 * @param        array $wp_query_array an array containing the WP_Query object
421
+	 * @return        void
422
+	 */
423
+	public static function loop_end($wp_query_array)
424
+	{
425
+		global $post;
426
+		do_action('AHEE_event_details_after_post', $post, $wp_query_array);
427
+	}
428
+
429
+
430
+	/**
431
+	 * wp_enqueue_scripts
432
+	 *
433
+	 * @return    void
434
+	 */
435
+	public function wp_enqueue_scripts()
436
+	{
437
+		// get some style
438
+		if (
439
+			apply_filters('FHEE_enable_default_espresso_css', TRUE)
440
+			&& apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', TRUE)
441
+		) {
442
+			// first check uploads folder
443
+			if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
444
+				wp_register_style(
445
+					$this->theme,
446
+					get_stylesheet_directory_uri() . $this->theme . DS . 'style.css',
447
+					array('dashicons', 'espresso_default')
448
+				);
449
+			} else {
450
+				wp_register_style(
451
+					$this->theme,
452
+					EE_TEMPLATES_URL . $this->theme . DS . 'style.css',
453
+					array('dashicons', 'espresso_default')
454
+				);
455
+			}
456
+			wp_enqueue_script($this->theme);
457
+			if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
458
+				add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
459
+			}
460
+		}
461
+	}
462
+
463
+
464
+	/**
465
+	 * display_venue
466
+	 *
467
+	 * @return    bool
468
+	 */
469
+	public static function display_venue()
470
+	{
471
+		/** @type EE_Event_Single_Config $config */
472
+		$config = EED_Event_Single::instance()->config();
473
+		$display_venue = $config->display_venue === null ? true : $config->display_venue;
474
+		$venue_name = EEH_Venue_View::venue_name();
475
+		return $display_venue && !empty($venue_name);
476
+	}
477 477
 
478 478
 
479 479
 }
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
  */
488 488
 function espresso_display_venue_in_event_details()
489 489
 {
490
-    return EED_Event_Single::display_venue();
490
+	return EED_Event_Single::display_venue();
491 491
 }
492 492
 
493 493
 
Please login to merge, or discard this patch.