Completed
Branch BUG/3575-event-deletion-previe... (bbeda1)
by
unknown
06:40 queued 04:49
created
caffeinated/modules/events_archive_caff/EED_Events_Archive_Caff.module.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -79,12 +79,12 @@  discard block
 block discarded – undo
79 79
      */
80 80
     public static function setDefinitions()
81 81
     {
82
-        if (! defined('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH')) {
82
+        if ( ! defined('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH')) {
83 83
             define(
84 84
                 'EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH',
85
-                str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates/'
85
+                str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates/'
86 86
             );
87
-            define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
87
+            define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__).'assets/');
88 88
         }
89 89
     }
90 90
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             'archive-sortable-li archive-sortable-js'
163 163
         );
164 164
         EEH_Template::display_template(
165
-            EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
165
+            EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH.'admin-event-list-settings.template.php',
166 166
             $config
167 167
         );
168 168
     }
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
         $config = EE_Registry::instance()->CFG;
241 241
         $config_saved = false;
242 242
         $template_parts = EED_Events_Archive_Caff::getRequest()->getRequestParam('elements');
243
-        if (! empty($template_parts)) {
243
+        if ( ! empty($template_parts)) {
244 244
             $template_parts = explode(',', trim($template_parts, ','));
245 245
             foreach ($template_parts as $key => $template_part) {
246 246
                 $template_part = "display_order_$template_part";
Please login to merge, or discard this patch.
Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -14,264 +14,264 @@
 block discarded – undo
14 14
 class EED_Events_Archive_Caff extends EED_Events_Archive
15 15
 {
16 16
 
17
-    /**
18
-     * @return EED_Events_Archive_Caff|EED_Module
19
-     */
20
-    public static function instance()
21
-    {
22
-        return parent::get_instance(__CLASS__);
23
-    }
17
+	/**
18
+	 * @return EED_Events_Archive_Caff|EED_Module
19
+	 */
20
+	public static function instance()
21
+	{
22
+		return parent::get_instance(__CLASS__);
23
+	}
24 24
 
25 25
 
26
-    /**
27
-     * set_hooks - for hooking into EE Core, other modules, etc
28
-     *
29
-     * @return    void
30
-     */
31
-    public static function set_hooks()
32
-    {
33
-    }
26
+	/**
27
+	 * set_hooks - for hooking into EE Core, other modules, etc
28
+	 *
29
+	 * @return    void
30
+	 */
31
+	public static function set_hooks()
32
+	{
33
+	}
34 34
 
35
-    /**
36
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
37
-     *
38
-     * @access    public
39
-     * @return    void
40
-     */
41
-    public static function set_hooks_admin()
42
-    {
43
-        self::setDefinitions();
44
-        add_action(
45
-            'AHEE__template_settings__template__before_settings_form',
46
-            array('EED_Events_Archive_Caff', 'template_settings_form'),
47
-            10
48
-        );
49
-        add_filter(
50
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
51
-            array('EED_Events_Archive_Caff', 'update_template_settings'),
52
-            10,
53
-            2
54
-        );
55
-        // AJAX
56
-        add_action(
57
-            'wp_ajax_espresso_update_event_archive_order',
58
-            array('EED_Events_Archive_Caff', 'update_event_archive_order')
59
-        );
60
-        add_action(
61
-            'wp_ajax_nopriv_espresso_update_event_archive_order',
62
-            array('EED_Events_Archive_Caff', 'update_event_archive_order')
63
-        );
64
-    }
35
+	/**
36
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
37
+	 *
38
+	 * @access    public
39
+	 * @return    void
40
+	 */
41
+	public static function set_hooks_admin()
42
+	{
43
+		self::setDefinitions();
44
+		add_action(
45
+			'AHEE__template_settings__template__before_settings_form',
46
+			array('EED_Events_Archive_Caff', 'template_settings_form'),
47
+			10
48
+		);
49
+		add_filter(
50
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
51
+			array('EED_Events_Archive_Caff', 'update_template_settings'),
52
+			10,
53
+			2
54
+		);
55
+		// AJAX
56
+		add_action(
57
+			'wp_ajax_espresso_update_event_archive_order',
58
+			array('EED_Events_Archive_Caff', 'update_event_archive_order')
59
+		);
60
+		add_action(
61
+			'wp_ajax_nopriv_espresso_update_event_archive_order',
62
+			array('EED_Events_Archive_Caff', 'update_event_archive_order')
63
+		);
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * run - initial module setup
69
-     *
70
-     * @param    WP $WP
71
-     * @return    void
72
-     */
73
-    public function run($WP)
74
-    {
75
-    }
67
+	/**
68
+	 * run - initial module setup
69
+	 *
70
+	 * @param    WP $WP
71
+	 * @return    void
72
+	 */
73
+	public function run($WP)
74
+	{
75
+	}
76 76
 
77 77
 
78
-    /**
79
-     * Conditionally set constants if they haven't been defined yet.
80
-     */
81
-    public static function setDefinitions()
82
-    {
83
-        if (! defined('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH')) {
84
-            define(
85
-                'EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH',
86
-                str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates/'
87
-            );
88
-            define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
89
-        }
90
-    }
78
+	/**
79
+	 * Conditionally set constants if they haven't been defined yet.
80
+	 */
81
+	public static function setDefinitions()
82
+	{
83
+		if (! defined('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH')) {
84
+			define(
85
+				'EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH',
86
+				str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates/'
87
+			);
88
+			define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
89
+		}
90
+	}
91 91
 
92 92
 
93
-    /**
94
-     * @return void
95
-     * @throws DomainException
96
-     * @throws InvalidArgumentException
97
-     * @throws InvalidDataTypeException
98
-     * @throws InvalidInterfaceException
99
-     */
100
-    public static function template_settings_form()
101
-    {
102
-        /** @var EE_Admin_Page_Loader $admin_page_loader */
103
-        $admin_page_loader = LoaderFactory::getLoader()->getShared('EE_Admin_Page_Loader');
104
-        // grab general settings admin page and remove the existing hook callback
105
-        $gen_set_admin = $admin_page_loader->get_admin_page_object('general_settings');
106
-        if ($gen_set_admin instanceof General_Settings_Admin_Page) {
107
-            remove_action(
108
-                'AHEE__template_settings__template__before_settings_form',
109
-                array($gen_set_admin, 'template_settings_caff_features'),
110
-                100
111
-            );
112
-        }
113
-        // first just grab the template settings
114
-        $config = EE_Registry::instance()->CFG->template_settings;
115
-        // then if the Event Archive config is valid, use that, else create a new one
116
-        $config = $config instanceof EE_Template_Config
117
-                  && $config->EED_Events_Archive instanceof EE_Events_Archive_Config
118
-            ? $config->EED_Events_Archive
119
-            : new EE_Events_Archive_Config();
120
-        $config = apply_filters(
121
-            'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
122
-            $config
123
-        );
124
-        $config->display_status_banner = isset($config->display_status_banner)
125
-            ? $config->display_status_banner
126
-            : 0;
127
-        $config->display_description = isset($config->display_description)
128
-            ? $config->display_description
129
-            : 1;
130
-        $config->display_ticket_selector = isset($config->display_ticket_selector)
131
-            ? $config->display_ticket_selector
132
-            : 0;
133
-        $config->display_datetimes = isset($config->display_datetimes)
134
-            ? $config->display_datetimes
135
-            : 1;
136
-        $config->display_venue = isset($config->display_venue)
137
-            ? $config->display_venue
138
-            : 0;
139
-        $config->display_expired_events = isset($config->display_expired_events)
140
-            ? $config->display_expired_events
141
-            : 0;
142
-        // display order options
143
-        $config->use_sortable_display_order = isset($config->use_sortable_display_order)
144
-            ? $config->use_sortable_display_order
145
-            : false;
146
-        $config->display_order_tickets = isset($config->display_order_tickets)
147
-            ? $config->display_order_tickets
148
-            : 120;
149
-        $config->display_order_datetimes = isset($config->display_order_datetimes)
150
-            ? $config->display_order_datetimes
151
-            : 110;
152
-        $config->display_order_event = isset($config->display_order_event)
153
-            ? $config->display_order_event
154
-            : 100;
155
-        $config->display_order_venue = isset($config->display_order_venue)
156
-            ? $config->display_order_venue
157
-            : 130;
158
-        // get template parts
159
-        $template_parts = EED_Events_Archive::instance()->initialize_template_parts($config);
160
-        // convert to array so that we can add more properties
161
-        $config = get_object_vars($config);
162
-        $config['event_archive_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
163
-            'event-archive-sortable-js',
164
-            '',
165
-            'archive-sortable-li archive-sortable-js'
166
-        );
167
-        EEH_Template::display_template(
168
-            EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
169
-            $config
170
-        );
171
-    }
93
+	/**
94
+	 * @return void
95
+	 * @throws DomainException
96
+	 * @throws InvalidArgumentException
97
+	 * @throws InvalidDataTypeException
98
+	 * @throws InvalidInterfaceException
99
+	 */
100
+	public static function template_settings_form()
101
+	{
102
+		/** @var EE_Admin_Page_Loader $admin_page_loader */
103
+		$admin_page_loader = LoaderFactory::getLoader()->getShared('EE_Admin_Page_Loader');
104
+		// grab general settings admin page and remove the existing hook callback
105
+		$gen_set_admin = $admin_page_loader->get_admin_page_object('general_settings');
106
+		if ($gen_set_admin instanceof General_Settings_Admin_Page) {
107
+			remove_action(
108
+				'AHEE__template_settings__template__before_settings_form',
109
+				array($gen_set_admin, 'template_settings_caff_features'),
110
+				100
111
+			);
112
+		}
113
+		// first just grab the template settings
114
+		$config = EE_Registry::instance()->CFG->template_settings;
115
+		// then if the Event Archive config is valid, use that, else create a new one
116
+		$config = $config instanceof EE_Template_Config
117
+				  && $config->EED_Events_Archive instanceof EE_Events_Archive_Config
118
+			? $config->EED_Events_Archive
119
+			: new EE_Events_Archive_Config();
120
+		$config = apply_filters(
121
+			'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
122
+			$config
123
+		);
124
+		$config->display_status_banner = isset($config->display_status_banner)
125
+			? $config->display_status_banner
126
+			: 0;
127
+		$config->display_description = isset($config->display_description)
128
+			? $config->display_description
129
+			: 1;
130
+		$config->display_ticket_selector = isset($config->display_ticket_selector)
131
+			? $config->display_ticket_selector
132
+			: 0;
133
+		$config->display_datetimes = isset($config->display_datetimes)
134
+			? $config->display_datetimes
135
+			: 1;
136
+		$config->display_venue = isset($config->display_venue)
137
+			? $config->display_venue
138
+			: 0;
139
+		$config->display_expired_events = isset($config->display_expired_events)
140
+			? $config->display_expired_events
141
+			: 0;
142
+		// display order options
143
+		$config->use_sortable_display_order = isset($config->use_sortable_display_order)
144
+			? $config->use_sortable_display_order
145
+			: false;
146
+		$config->display_order_tickets = isset($config->display_order_tickets)
147
+			? $config->display_order_tickets
148
+			: 120;
149
+		$config->display_order_datetimes = isset($config->display_order_datetimes)
150
+			? $config->display_order_datetimes
151
+			: 110;
152
+		$config->display_order_event = isset($config->display_order_event)
153
+			? $config->display_order_event
154
+			: 100;
155
+		$config->display_order_venue = isset($config->display_order_venue)
156
+			? $config->display_order_venue
157
+			: 130;
158
+		// get template parts
159
+		$template_parts = EED_Events_Archive::instance()->initialize_template_parts($config);
160
+		// convert to array so that we can add more properties
161
+		$config = get_object_vars($config);
162
+		$config['event_archive_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
163
+			'event-archive-sortable-js',
164
+			'',
165
+			'archive-sortable-li archive-sortable-js'
166
+		);
167
+		EEH_Template::display_template(
168
+			EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
169
+			$config
170
+		);
171
+	}
172 172
 
173 173
 
174
-    /**
175
-     * @param EE_Template_Config $CFG
176
-     * @param array              $REQ
177
-     * @return EE_Template_Config
178
-     */
179
-    public static function update_template_settings($CFG, $REQ)
180
-    {
181
-        /** @var EE_Events_Archive_Config $config */
182
-        $config = $CFG->EED_Events_Archive instanceof EE_Events_Archive_Config
183
-            ? $CFG->EED_Events_Archive
184
-            : new EE_Events_Archive_Config();
185
-        // unless we are resetting the config...
186
-        if (
187
-            ! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
188
-            || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
189
-        ) {
190
-            $config->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner'])
191
-                ? absint($REQ['EED_Events_Archive_display_status_banner'])
192
-                : 0;
193
-            $config->display_description = isset($REQ['EED_Events_Archive_display_description'])
194
-                ? absint($REQ['EED_Events_Archive_display_description'])
195
-                : 1;
196
-            $config->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
197
-                ? absint($REQ['EED_Events_Archive_display_ticket_selector'])
198
-                : 0;
199
-            $config->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes'])
200
-                ? absint($REQ['EED_Events_Archive_display_datetimes'])
201
-                : 1;
202
-            $config->display_venue = isset($REQ['EED_Events_Archive_display_venue'])
203
-                ? absint($REQ['EED_Events_Archive_display_venue'])
204
-                : 0;
205
-            $config->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events'])
206
-                ? absint($REQ['EED_Events_Archive_display_expired_events'])
207
-                : 0;
208
-            $config->use_sortable_display_order = isset($REQ['EED_Events_Archive_use_sortable_display_order'])
209
-                ? absint($REQ['EED_Events_Archive_use_sortable_display_order'])
210
-                : 0;
211
-            $config->display_order_event = $config->display_order_event !== null
212
-                                           && $config->use_sortable_display_order
213
-                ? $config->display_order_event
214
-                : EED_Events_Archive::EVENT_DETAILS_PRIORITY;
215
-            $config->display_order_datetimes = $config->display_order_datetimes !== null
216
-                                               && $config->use_sortable_display_order
217
-                ? $config->display_order_datetimes
218
-                : EED_Events_Archive::EVENT_DATETIMES_PRIORITY;
219
-            $config->display_order_tickets = $config->display_order_tickets !== null
220
-                                             && $config->use_sortable_display_order
221
-                ? $config->display_order_tickets
222
-                : EED_Events_Archive::EVENT_TICKETS_PRIORITY;
223
-            $config->display_order_venue = $config->display_order_venue !== null
224
-                                           && $config->use_sortable_display_order
225
-                ? $config->display_order_venue
226
-                : EED_Events_Archive::EVENT_VENUES_PRIORITY;
227
-        }
228
-        $CFG->EED_Events_Archive = $config;
229
-        do_action('AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ);
230
-        return $CFG;
231
-    }
174
+	/**
175
+	 * @param EE_Template_Config $CFG
176
+	 * @param array              $REQ
177
+	 * @return EE_Template_Config
178
+	 */
179
+	public static function update_template_settings($CFG, $REQ)
180
+	{
181
+		/** @var EE_Events_Archive_Config $config */
182
+		$config = $CFG->EED_Events_Archive instanceof EE_Events_Archive_Config
183
+			? $CFG->EED_Events_Archive
184
+			: new EE_Events_Archive_Config();
185
+		// unless we are resetting the config...
186
+		if (
187
+			! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
188
+			|| absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
189
+		) {
190
+			$config->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner'])
191
+				? absint($REQ['EED_Events_Archive_display_status_banner'])
192
+				: 0;
193
+			$config->display_description = isset($REQ['EED_Events_Archive_display_description'])
194
+				? absint($REQ['EED_Events_Archive_display_description'])
195
+				: 1;
196
+			$config->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
197
+				? absint($REQ['EED_Events_Archive_display_ticket_selector'])
198
+				: 0;
199
+			$config->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes'])
200
+				? absint($REQ['EED_Events_Archive_display_datetimes'])
201
+				: 1;
202
+			$config->display_venue = isset($REQ['EED_Events_Archive_display_venue'])
203
+				? absint($REQ['EED_Events_Archive_display_venue'])
204
+				: 0;
205
+			$config->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events'])
206
+				? absint($REQ['EED_Events_Archive_display_expired_events'])
207
+				: 0;
208
+			$config->use_sortable_display_order = isset($REQ['EED_Events_Archive_use_sortable_display_order'])
209
+				? absint($REQ['EED_Events_Archive_use_sortable_display_order'])
210
+				: 0;
211
+			$config->display_order_event = $config->display_order_event !== null
212
+										   && $config->use_sortable_display_order
213
+				? $config->display_order_event
214
+				: EED_Events_Archive::EVENT_DETAILS_PRIORITY;
215
+			$config->display_order_datetimes = $config->display_order_datetimes !== null
216
+											   && $config->use_sortable_display_order
217
+				? $config->display_order_datetimes
218
+				: EED_Events_Archive::EVENT_DATETIMES_PRIORITY;
219
+			$config->display_order_tickets = $config->display_order_tickets !== null
220
+											 && $config->use_sortable_display_order
221
+				? $config->display_order_tickets
222
+				: EED_Events_Archive::EVENT_TICKETS_PRIORITY;
223
+			$config->display_order_venue = $config->display_order_venue !== null
224
+										   && $config->use_sortable_display_order
225
+				? $config->display_order_venue
226
+				: EED_Events_Archive::EVENT_VENUES_PRIORITY;
227
+		}
228
+		$CFG->EED_Events_Archive = $config;
229
+		do_action('AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ);
230
+		return $CFG;
231
+	}
232 232
 
233 233
 
234
-    /**
235
-     * @return void
236
-     * @throws InvalidArgumentException
237
-     * @throws InvalidDataTypeException
238
-     * @throws InvalidInterfaceException
239
-     */
240
-    public static function update_event_archive_order()
241
-    {
242
-        /** @var EE_Config $config */
243
-        $config = EE_Registry::instance()->CFG;
244
-        $config_saved = false;
245
-        $template_parts = EED_Events_Archive_Caff::getRequest()->getRequestParam('elements');
246
-        if (! empty($template_parts)) {
247
-            $template_parts = explode(',', trim($template_parts, ','));
248
-            foreach ($template_parts as $key => $template_part) {
249
-                $template_part = "display_order_$template_part";
250
-                $priority = ($key * 10) + EED_Events_Archive::EVENT_DETAILS_PRIORITY;
251
-                if (
252
-                    $config->template_settings->EED_Events_Archive instanceof EE_Events_Archive_Config
253
-                    && property_exists(
254
-                        $config->template_settings->EED_Events_Archive,
255
-                        $template_part
256
-                    )
257
-                ) {
258
-                    $config->template_settings->EED_Events_Archive->{$template_part} = $priority;
259
-                }
260
-                do_action("AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority);
261
-            }
262
-            $config_saved = $config->update_espresso_config(false, false);
263
-        }
264
-        if ($config_saved) {
265
-            EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
266
-        } else {
267
-            EE_Error::add_error(
268
-                esc_html__('Display Order was not updated.', 'event_espresso'),
269
-                __FILE__,
270
-                __FUNCTION__,
271
-                __LINE__
272
-            );
273
-        }
274
-        echo wp_json_encode(EE_Error::get_notices(false));
275
-        exit();
276
-    }
234
+	/**
235
+	 * @return void
236
+	 * @throws InvalidArgumentException
237
+	 * @throws InvalidDataTypeException
238
+	 * @throws InvalidInterfaceException
239
+	 */
240
+	public static function update_event_archive_order()
241
+	{
242
+		/** @var EE_Config $config */
243
+		$config = EE_Registry::instance()->CFG;
244
+		$config_saved = false;
245
+		$template_parts = EED_Events_Archive_Caff::getRequest()->getRequestParam('elements');
246
+		if (! empty($template_parts)) {
247
+			$template_parts = explode(',', trim($template_parts, ','));
248
+			foreach ($template_parts as $key => $template_part) {
249
+				$template_part = "display_order_$template_part";
250
+				$priority = ($key * 10) + EED_Events_Archive::EVENT_DETAILS_PRIORITY;
251
+				if (
252
+					$config->template_settings->EED_Events_Archive instanceof EE_Events_Archive_Config
253
+					&& property_exists(
254
+						$config->template_settings->EED_Events_Archive,
255
+						$template_part
256
+					)
257
+				) {
258
+					$config->template_settings->EED_Events_Archive->{$template_part} = $priority;
259
+				}
260
+				do_action("AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority);
261
+			}
262
+			$config_saved = $config->update_espresso_config(false, false);
263
+		}
264
+		if ($config_saved) {
265
+			EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
266
+		} else {
267
+			EE_Error::add_error(
268
+				esc_html__('Display Order was not updated.', 'event_espresso'),
269
+				__FILE__,
270
+				__FUNCTION__,
271
+				__LINE__
272
+			);
273
+		}
274
+		echo wp_json_encode(EE_Error::get_notices(false));
275
+		exit();
276
+	}
277 277
 }
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha/EED_Recaptcha.module.php 2 patches
Indentation   +378 added lines, -378 removed lines patch added patch discarded remove patch
@@ -18,382 +18,382 @@
 block discarded – undo
18 18
 class EED_Recaptcha extends EED_Module
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Registration_Config $config
23
-     */
24
-    private static $config;
25
-
26
-    /**
27
-     * @type bool $_not_a_robot
28
-     */
29
-    private static $_not_a_robot;
30
-
31
-    /**
32
-     * @type string $_recaptcha_response
33
-     */
34
-    private static $_recaptcha_response;
35
-
36
-
37
-    /**
38
-     * @return EED_Module|EED_Recaptcha
39
-     */
40
-    public static function instance()
41
-    {
42
-        return parent::get_instance(__CLASS__);
43
-    }
44
-
45
-
46
-    /**
47
-     * set_hooks - for hooking into EE Core, other modules, etc
48
-     *
49
-     * @return void
50
-     * @throws InvalidArgumentException
51
-     * @throws InvalidInterfaceException
52
-     * @throws InvalidDataTypeException
53
-     */
54
-    public static function set_hooks()
55
-    {
56
-        EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
57
-        // use_captcha ?
58
-        if (
59
-            EED_Recaptcha::useRecaptcha()
60
-            && EED_Recaptcha::notPaymentOptionsRevisit()
61
-        ) {
62
-            EED_Recaptcha::set_definitions();
63
-            EED_Recaptcha::enqueue_styles_and_scripts();
64
-            add_action('wp', array('EED_Recaptcha', 'set_late_hooks'), 1, 0);
65
-            add_action(
66
-                'AHEE__before_spco_whats_next_buttons',
67
-                array('EED_Recaptcha', 'display_recaptcha'),
68
-                10,
69
-                0
70
-            );
71
-            add_filter(
72
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
73
-                array('EED_Recaptcha', 'not_a_robot')
74
-            );
75
-            add_filter(
76
-                'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
77
-                array('EED_Recaptcha', 'not_a_robot')
78
-            );
79
-            add_filter(
80
-                'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
81
-                array('EED_Recaptcha', 'recaptcha_response')
82
-            );
83
-            add_filter(
84
-                'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
85
-                array('EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method')
86
-            );
87
-        }
88
-    }
89
-
90
-
91
-    /**
92
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
93
-     *
94
-     * @return void
95
-     * @throws InvalidArgumentException
96
-     * @throws InvalidInterfaceException
97
-     * @throws InvalidDataTypeException
98
-     */
99
-    public static function set_hooks_admin()
100
-    {
101
-        EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
102
-        EED_Recaptcha::set_definitions();
103
-        // use_captcha ?
104
-        if (
105
-            EED_Recaptcha::useRecaptcha()
106
-            && EED_Recaptcha::notPaymentOptionsRevisit()
107
-            && EED_Recaptcha::getRequest()->getRequestParam('step', '') !== ''
108
-        ) {
109
-            EED_Recaptcha::enqueue_styles_and_scripts();
110
-            add_filter(
111
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
112
-                array('EED_Recaptcha', 'not_a_robot')
113
-            );
114
-            add_filter(
115
-                'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
116
-                array('EED_Recaptcha', 'not_a_robot')
117
-            );
118
-            add_filter(
119
-                'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
120
-                array('EED_Recaptcha', 'recaptcha_response')
121
-            );
122
-        }
123
-    }
124
-
125
-
126
-    /**
127
-     * @return void
128
-     */
129
-    public static function set_definitions()
130
-    {
131
-        if (is_user_logged_in()) {
132
-            EED_Recaptcha::$_not_a_robot = true;
133
-        }
134
-        define(
135
-            'RECAPTCHA_BASE_PATH',
136
-            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
137
-        );
138
-        define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__));
139
-    }
140
-
141
-
142
-    /**
143
-     * @return void
144
-     */
145
-    public static function set_late_hooks()
146
-    {
147
-        add_filter(
148
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
149
-            array('EED_Recaptcha', 'not_a_robot')
150
-        );
151
-    }
152
-
153
-
154
-    /**
155
-     * @return boolean
156
-     */
157
-    public static function useRecaptcha()
158
-    {
159
-        return EED_Recaptcha::$config->use_captcha
160
-               && EED_Recaptcha::$config->recaptcha_theme !== 'invisible';
161
-    }
162
-
163
-
164
-    /**
165
-     * @return boolean
166
-     * @throws InvalidArgumentException
167
-     * @throws InvalidInterfaceException
168
-     * @throws InvalidDataTypeException
169
-     */
170
-    public static function notPaymentOptionsRevisit()
171
-    {
172
-        $request = EED_Recaptcha::getRequest();
173
-        return ! (
174
-            $request->getRequestParam('step', '') === 'payment_options'
175
-            && $request->getRequestParam('revisit', false, 'bool') === true
176
-        );
177
-    }
178
-
179
-
180
-    /**
181
-     * @return void
182
-     * @throws InvalidArgumentException
183
-     * @throws InvalidInterfaceException
184
-     * @throws InvalidDataTypeException
185
-     */
186
-    public static function enqueue_styles_and_scripts()
187
-    {
188
-        wp_register_script(
189
-            'espresso_recaptcha',
190
-            RECAPTCHA_BASE_URL . 'scripts/espresso_recaptcha.js',
191
-            array('single_page_checkout'),
192
-            EVENT_ESPRESSO_VERSION,
193
-            true
194
-        );
195
-        wp_register_script(
196
-            'google_recaptcha',
197
-            'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language,
198
-            array('espresso_recaptcha'),
199
-            EVENT_ESPRESSO_VERSION,
200
-            true
201
-        );
202
-        EE_Registry::$i18n_js_strings['no_SPCO_error'] = __(
203
-            'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.',
204
-            'event_espresso'
205
-        );
206
-        EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __(
207
-            'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.',
208
-            'event_espresso'
209
-        );
210
-        EE_Registry::$i18n_js_strings['recaptcha_fail'] = __(
211
-            'Please complete the anti-spam test before proceeding.',
212
-            'event_espresso'
213
-        );
214
-    }
215
-
216
-
217
-    /**
218
-     * @param WP $WP
219
-     */
220
-    public function run($WP)
221
-    {
222
-    }
223
-
224
-
225
-    /**
226
-     * @return boolean
227
-     * @throws InvalidArgumentException
228
-     * @throws InvalidInterfaceException
229
-     * @throws InvalidDataTypeException
230
-     */
231
-    public static function not_a_robot()
232
-    {
233
-        return is_bool(EED_Recaptcha::$_not_a_robot)
234
-            ? EED_Recaptcha::$_not_a_robot
235
-            : EED_Recaptcha::recaptcha_passed();
236
-    }
237
-
238
-
239
-    /**
240
-     * @return void
241
-     * @throws DomainException
242
-     * @throws InvalidArgumentException
243
-     * @throws InvalidInterfaceException
244
-     * @throws InvalidDataTypeException
245
-     */
246
-    public static function display_recaptcha()
247
-    {
248
-        // logged in means you have already passed a turing test of sorts
249
-        if (is_user_logged_in()) {
250
-            return;
251
-        }
252
-        // don't display if not using recaptcha or user is logged in
253
-        if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) {
254
-            // only display if they have NOT passed the test yet
255
-            EEH_Template::display_template(
256
-                RECAPTCHA_BASE_PATH . '/templates/recaptcha.template.php',
257
-                array(
258
-                    'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey,
259
-                    'recaptcha_theme'     => EED_Recaptcha::$config->recaptcha_theme,
260
-                    'recaptcha_type'      => EED_Recaptcha::$config->recaptcha_type,
261
-                )
262
-            );
263
-            wp_enqueue_script('google_recaptcha');
264
-        }
265
-    }
266
-
267
-
268
-    /**
269
-     * @return array
270
-     * @throws InvalidArgumentException
271
-     * @throws InvalidInterfaceException
272
-     * @throws InvalidDataTypeException
273
-     */
274
-    public static function bypass_recaptcha_for_spco_load_payment_method()
275
-    {
276
-        return array(
277
-            'EESID'  => EE_Registry::instance()->SSN->id(),
278
-            'step'   => 'payment_options',
279
-            'action' => 'switch_spco_billing_form',
280
-        );
281
-    }
282
-
283
-
284
-    /**
285
-     * @return boolean
286
-     * @throws InvalidArgumentException
287
-     * @throws InvalidInterfaceException
288
-     * @throws InvalidDataTypeException
289
-     */
290
-    public static function recaptcha_passed()
291
-    {
292
-        // logged in means you have already passed a turing test of sorts
293
-        if (is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha()) {
294
-            return true;
295
-        }
296
-        // was test already passed?
297
-        $recaptcha_passed = EE_Registry::instance()->SSN->get_session_data('recaptcha_passed');
298
-        $recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN);
299
-        // verify recaptcha
300
-        EED_Recaptcha::_get_recaptcha_response();
301
-        if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) {
302
-            $recaptcha_passed = EED_Recaptcha::_process_recaptcha_response();
303
-            EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed));
304
-        }
305
-        EED_Recaptcha::$_not_a_robot = $recaptcha_passed;
306
-        return $recaptcha_passed;
307
-    }
308
-
309
-
310
-    /**
311
-     * @param array $recaptcha_response
312
-     * @return array
313
-     */
314
-    public static function recaptcha_response($recaptcha_response = array())
315
-    {
316
-        if (EED_Recaptcha::_bypass_recaptcha()) {
317
-            $recaptcha_response['bypass_recaptcha'] = true;
318
-            $recaptcha_response['recaptcha_passed'] = true;
319
-        } else {
320
-            $recaptcha_response['recaptcha_passed'] = EED_Recaptcha::$_not_a_robot;
321
-        }
322
-        return $recaptcha_response;
323
-    }
324
-
325
-
326
-    /**
327
-     * @return boolean
328
-     */
329
-    private static function _bypass_recaptcha()
330
-    {
331
-        // an array of key value pairs that must match exactly with the incoming request,
332
-        // in order to bypass recaptcha for the current request ONLY
333
-        $bypass_request_params_array = (array) apply_filters(
334
-            'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
335
-            array()
336
-        );
337
-        // does $bypass_request_params_array have any values ?
338
-        if (empty($bypass_request_params_array)) {
339
-            return false;
340
-        }
341
-        $request = EED_Recaptcha::getRequest();
342
-        // initially set bypass to TRUE
343
-        $bypass_recaptcha = true;
344
-        foreach ($bypass_request_params_array as $key => $value) {
345
-            // if $key is not found or value doesn't match exactly, then toggle bypass to FALSE,
346
-            // otherwise carry over it's value. This way, one missed setting results in no bypass
347
-            $bypass_recaptcha = $request->getRequestParam($key) === $value
348
-                ? $bypass_recaptcha
349
-                : false;
350
-        }
351
-        return $bypass_recaptcha;
352
-    }
353
-
354
-
355
-    /**
356
-     * @return void
357
-     * @throws InvalidArgumentException
358
-     * @throws InvalidInterfaceException
359
-     * @throws InvalidDataTypeException
360
-     */
361
-    private static function _get_recaptcha_response()
362
-    {
363
-        EED_Recaptcha::$_recaptcha_response = EED_Recaptcha::getRequest()->getRequestParam(
364
-            'g-recaptcha-response'
365
-        );
366
-    }
367
-
368
-
369
-    /**
370
-     * @return boolean
371
-     * @throws InvalidArgumentException
372
-     * @throws InvalidInterfaceException
373
-     * @throws InvalidDataTypeException
374
-     */
375
-    private static function _process_recaptcha_response()
376
-    {
377
-        // verify library is loaded
378
-        if (! class_exists('\ReCaptcha\ReCaptcha')) {
379
-            require_once RECAPTCHA_BASE_PATH . '/autoload.php';
380
-        }
381
-        // The response from reCAPTCHA
382
-        EED_Recaptcha::_get_recaptcha_response();
383
-        $recaptcha_response = EED_Recaptcha::$_recaptcha_response;
384
-        // Was there a reCAPTCHA response?
385
-        if ($recaptcha_response) {
386
-            // if allow_url_fopen is Off, then set a different request method
387
-            $request_method = ! ini_get('allow_url_fopen') ? new SocketPost() : null;
388
-            $recaptcha = new ReCaptcha(
389
-                EED_Recaptcha::$config->recaptcha_privatekey,
390
-                $request_method
391
-            );
392
-            $recaptcha_response = $recaptcha->verify(
393
-                EED_Recaptcha::$_recaptcha_response,
394
-                EED_Recaptcha::getRequest()->getServerParam('REMOTE_ADDR')
395
-            );
396
-        }
397
-        return $recaptcha_response instanceof Response && $recaptcha_response->isSuccess();
398
-    }
21
+	/**
22
+	 * @var EE_Registration_Config $config
23
+	 */
24
+	private static $config;
25
+
26
+	/**
27
+	 * @type bool $_not_a_robot
28
+	 */
29
+	private static $_not_a_robot;
30
+
31
+	/**
32
+	 * @type string $_recaptcha_response
33
+	 */
34
+	private static $_recaptcha_response;
35
+
36
+
37
+	/**
38
+	 * @return EED_Module|EED_Recaptcha
39
+	 */
40
+	public static function instance()
41
+	{
42
+		return parent::get_instance(__CLASS__);
43
+	}
44
+
45
+
46
+	/**
47
+	 * set_hooks - for hooking into EE Core, other modules, etc
48
+	 *
49
+	 * @return void
50
+	 * @throws InvalidArgumentException
51
+	 * @throws InvalidInterfaceException
52
+	 * @throws InvalidDataTypeException
53
+	 */
54
+	public static function set_hooks()
55
+	{
56
+		EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
57
+		// use_captcha ?
58
+		if (
59
+			EED_Recaptcha::useRecaptcha()
60
+			&& EED_Recaptcha::notPaymentOptionsRevisit()
61
+		) {
62
+			EED_Recaptcha::set_definitions();
63
+			EED_Recaptcha::enqueue_styles_and_scripts();
64
+			add_action('wp', array('EED_Recaptcha', 'set_late_hooks'), 1, 0);
65
+			add_action(
66
+				'AHEE__before_spco_whats_next_buttons',
67
+				array('EED_Recaptcha', 'display_recaptcha'),
68
+				10,
69
+				0
70
+			);
71
+			add_filter(
72
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
73
+				array('EED_Recaptcha', 'not_a_robot')
74
+			);
75
+			add_filter(
76
+				'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
77
+				array('EED_Recaptcha', 'not_a_robot')
78
+			);
79
+			add_filter(
80
+				'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
81
+				array('EED_Recaptcha', 'recaptcha_response')
82
+			);
83
+			add_filter(
84
+				'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
85
+				array('EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method')
86
+			);
87
+		}
88
+	}
89
+
90
+
91
+	/**
92
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
93
+	 *
94
+	 * @return void
95
+	 * @throws InvalidArgumentException
96
+	 * @throws InvalidInterfaceException
97
+	 * @throws InvalidDataTypeException
98
+	 */
99
+	public static function set_hooks_admin()
100
+	{
101
+		EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
102
+		EED_Recaptcha::set_definitions();
103
+		// use_captcha ?
104
+		if (
105
+			EED_Recaptcha::useRecaptcha()
106
+			&& EED_Recaptcha::notPaymentOptionsRevisit()
107
+			&& EED_Recaptcha::getRequest()->getRequestParam('step', '') !== ''
108
+		) {
109
+			EED_Recaptcha::enqueue_styles_and_scripts();
110
+			add_filter(
111
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
112
+				array('EED_Recaptcha', 'not_a_robot')
113
+			);
114
+			add_filter(
115
+				'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
116
+				array('EED_Recaptcha', 'not_a_robot')
117
+			);
118
+			add_filter(
119
+				'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
120
+				array('EED_Recaptcha', 'recaptcha_response')
121
+			);
122
+		}
123
+	}
124
+
125
+
126
+	/**
127
+	 * @return void
128
+	 */
129
+	public static function set_definitions()
130
+	{
131
+		if (is_user_logged_in()) {
132
+			EED_Recaptcha::$_not_a_robot = true;
133
+		}
134
+		define(
135
+			'RECAPTCHA_BASE_PATH',
136
+			rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
137
+		);
138
+		define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__));
139
+	}
140
+
141
+
142
+	/**
143
+	 * @return void
144
+	 */
145
+	public static function set_late_hooks()
146
+	{
147
+		add_filter(
148
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
149
+			array('EED_Recaptcha', 'not_a_robot')
150
+		);
151
+	}
152
+
153
+
154
+	/**
155
+	 * @return boolean
156
+	 */
157
+	public static function useRecaptcha()
158
+	{
159
+		return EED_Recaptcha::$config->use_captcha
160
+			   && EED_Recaptcha::$config->recaptcha_theme !== 'invisible';
161
+	}
162
+
163
+
164
+	/**
165
+	 * @return boolean
166
+	 * @throws InvalidArgumentException
167
+	 * @throws InvalidInterfaceException
168
+	 * @throws InvalidDataTypeException
169
+	 */
170
+	public static function notPaymentOptionsRevisit()
171
+	{
172
+		$request = EED_Recaptcha::getRequest();
173
+		return ! (
174
+			$request->getRequestParam('step', '') === 'payment_options'
175
+			&& $request->getRequestParam('revisit', false, 'bool') === true
176
+		);
177
+	}
178
+
179
+
180
+	/**
181
+	 * @return void
182
+	 * @throws InvalidArgumentException
183
+	 * @throws InvalidInterfaceException
184
+	 * @throws InvalidDataTypeException
185
+	 */
186
+	public static function enqueue_styles_and_scripts()
187
+	{
188
+		wp_register_script(
189
+			'espresso_recaptcha',
190
+			RECAPTCHA_BASE_URL . 'scripts/espresso_recaptcha.js',
191
+			array('single_page_checkout'),
192
+			EVENT_ESPRESSO_VERSION,
193
+			true
194
+		);
195
+		wp_register_script(
196
+			'google_recaptcha',
197
+			'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language,
198
+			array('espresso_recaptcha'),
199
+			EVENT_ESPRESSO_VERSION,
200
+			true
201
+		);
202
+		EE_Registry::$i18n_js_strings['no_SPCO_error'] = __(
203
+			'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.',
204
+			'event_espresso'
205
+		);
206
+		EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __(
207
+			'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.',
208
+			'event_espresso'
209
+		);
210
+		EE_Registry::$i18n_js_strings['recaptcha_fail'] = __(
211
+			'Please complete the anti-spam test before proceeding.',
212
+			'event_espresso'
213
+		);
214
+	}
215
+
216
+
217
+	/**
218
+	 * @param WP $WP
219
+	 */
220
+	public function run($WP)
221
+	{
222
+	}
223
+
224
+
225
+	/**
226
+	 * @return boolean
227
+	 * @throws InvalidArgumentException
228
+	 * @throws InvalidInterfaceException
229
+	 * @throws InvalidDataTypeException
230
+	 */
231
+	public static function not_a_robot()
232
+	{
233
+		return is_bool(EED_Recaptcha::$_not_a_robot)
234
+			? EED_Recaptcha::$_not_a_robot
235
+			: EED_Recaptcha::recaptcha_passed();
236
+	}
237
+
238
+
239
+	/**
240
+	 * @return void
241
+	 * @throws DomainException
242
+	 * @throws InvalidArgumentException
243
+	 * @throws InvalidInterfaceException
244
+	 * @throws InvalidDataTypeException
245
+	 */
246
+	public static function display_recaptcha()
247
+	{
248
+		// logged in means you have already passed a turing test of sorts
249
+		if (is_user_logged_in()) {
250
+			return;
251
+		}
252
+		// don't display if not using recaptcha or user is logged in
253
+		if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) {
254
+			// only display if they have NOT passed the test yet
255
+			EEH_Template::display_template(
256
+				RECAPTCHA_BASE_PATH . '/templates/recaptcha.template.php',
257
+				array(
258
+					'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey,
259
+					'recaptcha_theme'     => EED_Recaptcha::$config->recaptcha_theme,
260
+					'recaptcha_type'      => EED_Recaptcha::$config->recaptcha_type,
261
+				)
262
+			);
263
+			wp_enqueue_script('google_recaptcha');
264
+		}
265
+	}
266
+
267
+
268
+	/**
269
+	 * @return array
270
+	 * @throws InvalidArgumentException
271
+	 * @throws InvalidInterfaceException
272
+	 * @throws InvalidDataTypeException
273
+	 */
274
+	public static function bypass_recaptcha_for_spco_load_payment_method()
275
+	{
276
+		return array(
277
+			'EESID'  => EE_Registry::instance()->SSN->id(),
278
+			'step'   => 'payment_options',
279
+			'action' => 'switch_spco_billing_form',
280
+		);
281
+	}
282
+
283
+
284
+	/**
285
+	 * @return boolean
286
+	 * @throws InvalidArgumentException
287
+	 * @throws InvalidInterfaceException
288
+	 * @throws InvalidDataTypeException
289
+	 */
290
+	public static function recaptcha_passed()
291
+	{
292
+		// logged in means you have already passed a turing test of sorts
293
+		if (is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha()) {
294
+			return true;
295
+		}
296
+		// was test already passed?
297
+		$recaptcha_passed = EE_Registry::instance()->SSN->get_session_data('recaptcha_passed');
298
+		$recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN);
299
+		// verify recaptcha
300
+		EED_Recaptcha::_get_recaptcha_response();
301
+		if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) {
302
+			$recaptcha_passed = EED_Recaptcha::_process_recaptcha_response();
303
+			EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed));
304
+		}
305
+		EED_Recaptcha::$_not_a_robot = $recaptcha_passed;
306
+		return $recaptcha_passed;
307
+	}
308
+
309
+
310
+	/**
311
+	 * @param array $recaptcha_response
312
+	 * @return array
313
+	 */
314
+	public static function recaptcha_response($recaptcha_response = array())
315
+	{
316
+		if (EED_Recaptcha::_bypass_recaptcha()) {
317
+			$recaptcha_response['bypass_recaptcha'] = true;
318
+			$recaptcha_response['recaptcha_passed'] = true;
319
+		} else {
320
+			$recaptcha_response['recaptcha_passed'] = EED_Recaptcha::$_not_a_robot;
321
+		}
322
+		return $recaptcha_response;
323
+	}
324
+
325
+
326
+	/**
327
+	 * @return boolean
328
+	 */
329
+	private static function _bypass_recaptcha()
330
+	{
331
+		// an array of key value pairs that must match exactly with the incoming request,
332
+		// in order to bypass recaptcha for the current request ONLY
333
+		$bypass_request_params_array = (array) apply_filters(
334
+			'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
335
+			array()
336
+		);
337
+		// does $bypass_request_params_array have any values ?
338
+		if (empty($bypass_request_params_array)) {
339
+			return false;
340
+		}
341
+		$request = EED_Recaptcha::getRequest();
342
+		// initially set bypass to TRUE
343
+		$bypass_recaptcha = true;
344
+		foreach ($bypass_request_params_array as $key => $value) {
345
+			// if $key is not found or value doesn't match exactly, then toggle bypass to FALSE,
346
+			// otherwise carry over it's value. This way, one missed setting results in no bypass
347
+			$bypass_recaptcha = $request->getRequestParam($key) === $value
348
+				? $bypass_recaptcha
349
+				: false;
350
+		}
351
+		return $bypass_recaptcha;
352
+	}
353
+
354
+
355
+	/**
356
+	 * @return void
357
+	 * @throws InvalidArgumentException
358
+	 * @throws InvalidInterfaceException
359
+	 * @throws InvalidDataTypeException
360
+	 */
361
+	private static function _get_recaptcha_response()
362
+	{
363
+		EED_Recaptcha::$_recaptcha_response = EED_Recaptcha::getRequest()->getRequestParam(
364
+			'g-recaptcha-response'
365
+		);
366
+	}
367
+
368
+
369
+	/**
370
+	 * @return boolean
371
+	 * @throws InvalidArgumentException
372
+	 * @throws InvalidInterfaceException
373
+	 * @throws InvalidDataTypeException
374
+	 */
375
+	private static function _process_recaptcha_response()
376
+	{
377
+		// verify library is loaded
378
+		if (! class_exists('\ReCaptcha\ReCaptcha')) {
379
+			require_once RECAPTCHA_BASE_PATH . '/autoload.php';
380
+		}
381
+		// The response from reCAPTCHA
382
+		EED_Recaptcha::_get_recaptcha_response();
383
+		$recaptcha_response = EED_Recaptcha::$_recaptcha_response;
384
+		// Was there a reCAPTCHA response?
385
+		if ($recaptcha_response) {
386
+			// if allow_url_fopen is Off, then set a different request method
387
+			$request_method = ! ini_get('allow_url_fopen') ? new SocketPost() : null;
388
+			$recaptcha = new ReCaptcha(
389
+				EED_Recaptcha::$config->recaptcha_privatekey,
390
+				$request_method
391
+			);
392
+			$recaptcha_response = $recaptcha->verify(
393
+				EED_Recaptcha::$_recaptcha_response,
394
+				EED_Recaptcha::getRequest()->getServerParam('REMOTE_ADDR')
395
+			);
396
+		}
397
+		return $recaptcha_response instanceof Response && $recaptcha_response->isSuccess();
398
+	}
399 399
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
         }
134 134
         define(
135 135
             'RECAPTCHA_BASE_PATH',
136
-            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
136
+            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/').'/'
137 137
         );
138 138
         define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__));
139 139
     }
@@ -187,14 +187,14 @@  discard block
 block discarded – undo
187 187
     {
188 188
         wp_register_script(
189 189
             'espresso_recaptcha',
190
-            RECAPTCHA_BASE_URL . 'scripts/espresso_recaptcha.js',
190
+            RECAPTCHA_BASE_URL.'scripts/espresso_recaptcha.js',
191 191
             array('single_page_checkout'),
192 192
             EVENT_ESPRESSO_VERSION,
193 193
             true
194 194
         );
195 195
         wp_register_script(
196 196
             'google_recaptcha',
197
-            'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language,
197
+            'https://www.google.com/recaptcha/api.js?hl='.EED_Recaptcha::$config->recaptcha_language,
198 198
             array('espresso_recaptcha'),
199 199
             EVENT_ESPRESSO_VERSION,
200 200
             true
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
         if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) {
254 254
             // only display if they have NOT passed the test yet
255 255
             EEH_Template::display_template(
256
-                RECAPTCHA_BASE_PATH . '/templates/recaptcha.template.php',
256
+                RECAPTCHA_BASE_PATH.'/templates/recaptcha.template.php',
257 257
                 array(
258 258
                     'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey,
259 259
                     'recaptcha_theme'     => EED_Recaptcha::$config->recaptcha_theme,
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
         $recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN);
299 299
         // verify recaptcha
300 300
         EED_Recaptcha::_get_recaptcha_response();
301
-        if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) {
301
+        if ( ! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) {
302 302
             $recaptcha_passed = EED_Recaptcha::_process_recaptcha_response();
303 303
             EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed));
304 304
         }
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
     private static function _process_recaptcha_response()
376 376
     {
377 377
         // verify library is loaded
378
-        if (! class_exists('\ReCaptcha\ReCaptcha')) {
379
-            require_once RECAPTCHA_BASE_PATH . '/autoload.php';
378
+        if ( ! class_exists('\ReCaptcha\ReCaptcha')) {
379
+            require_once RECAPTCHA_BASE_PATH.'/autoload.php';
380 380
         }
381 381
         // The response from reCAPTCHA
382 382
         EED_Recaptcha::_get_recaptcha_response();
Please login to merge, or discard this patch.
admin_pages/registrations/EE_Registrations_List_Table.class.php 2 patches
Indentation   +989 added lines, -989 removed lines patch added patch discarded remove patch
@@ -15,1065 +15,1065 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * @var Registrations_Admin_Page
20
-     */
21
-    protected $_admin_page;
18
+	/**
19
+	 * @var Registrations_Admin_Page
20
+	 */
21
+	protected $_admin_page;
22 22
 
23
-    /**
24
-     * @var array
25
-     */
26
-    private $_status;
23
+	/**
24
+	 * @var array
25
+	 */
26
+	private $_status;
27 27
 
28
-    /**
29
-     * An array of transaction details for the related transaction to the registration being processed.
30
-     * This is set via the _set_related_details method.
31
-     *
32
-     * @var array
33
-     */
34
-    protected $_transaction_details = [];
28
+	/**
29
+	 * An array of transaction details for the related transaction to the registration being processed.
30
+	 * This is set via the _set_related_details method.
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected $_transaction_details = [];
35 35
 
36
-    /**
37
-     * An array of event details for the related event to the registration being processed.
38
-     * This is set via the _set_related_details method.
39
-     *
40
-     * @var array
41
-     */
42
-    protected $_event_details = [];
36
+	/**
37
+	 * An array of event details for the related event to the registration being processed.
38
+	 * This is set via the _set_related_details method.
39
+	 *
40
+	 * @var array
41
+	 */
42
+	protected $_event_details = [];
43 43
 
44 44
 
45
-    /**
46
-     * @param Registrations_Admin_Page $admin_page
47
-     */
48
-    public function __construct(Registrations_Admin_Page $admin_page)
49
-    {
50
-        $req_data = $admin_page->get_request_data();
51
-        if (! empty($req_data['event_id'])) {
52
-            $extra_query_args = [];
53
-            foreach ($admin_page->get_views() as $view_details) {
54
-                $extra_query_args[ $view_details['slug'] ] = ['event_id' => $req_data['event_id']];
55
-            }
56
-            $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
57
-        }
58
-        parent::__construct($admin_page);
59
-        $this->_status = $this->_admin_page->get_registration_status_array();
60
-    }
45
+	/**
46
+	 * @param Registrations_Admin_Page $admin_page
47
+	 */
48
+	public function __construct(Registrations_Admin_Page $admin_page)
49
+	{
50
+		$req_data = $admin_page->get_request_data();
51
+		if (! empty($req_data['event_id'])) {
52
+			$extra_query_args = [];
53
+			foreach ($admin_page->get_views() as $view_details) {
54
+				$extra_query_args[ $view_details['slug'] ] = ['event_id' => $req_data['event_id']];
55
+			}
56
+			$this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
57
+		}
58
+		parent::__construct($admin_page);
59
+		$this->_status = $this->_admin_page->get_registration_status_array();
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * @return void
65
-     * @throws EE_Error
66
-     */
67
-    protected function _setup_data()
68
-    {
69
-        $this->_data           = $this->_admin_page->get_registrations($this->_per_page);
70
-        $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true);
71
-    }
63
+	/**
64
+	 * @return void
65
+	 * @throws EE_Error
66
+	 */
67
+	protected function _setup_data()
68
+	{
69
+		$this->_data           = $this->_admin_page->get_registrations($this->_per_page);
70
+		$this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true);
71
+	}
72 72
 
73 73
 
74
-    /**
75
-     * @return void
76
-     */
77
-    protected function _set_properties()
78
-    {
79
-        $return_url          = $this->getReturnUrl();
80
-        $this->_wp_list_args = [
81
-            'singular' => esc_html__('registration', 'event_espresso'),
82
-            'plural'   => esc_html__('registrations', 'event_espresso'),
83
-            'ajax'     => true,
84
-            'screen'   => $this->_admin_page->get_current_screen()->id,
85
-        ];
86
-        $ID_column_name      = esc_html__('ID', 'event_espresso');
87
-        $ID_column_name      .= ' : <span class="show-on-mobile-view-only" style="float:none">';
88
-        $ID_column_name      .= esc_html__('Registrant Name', 'event_espresso');
89
-        $ID_column_name      .= '</span> ';
90
-        $req_data            = $this->_admin_page->get_request_data();
91
-        if (isset($req_data['event_id'])) {
92
-            $this->_columns        = [
93
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
94
-                '_REG_ID'          => $ID_column_name,
95
-                'ATT_fname'        => esc_html__('Name', 'event_espresso'),
96
-                'ATT_email'        => esc_html__('Email', 'event_espresso'),
97
-                '_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
98
-                'PRC_amount'       => esc_html__('TKT Price', 'event_espresso'),
99
-                '_REG_final_price' => esc_html__('Final Price', 'event_espresso'),
100
-                'TXN_total'        => esc_html__('Total Txn', 'event_espresso'),
101
-                'TXN_paid'         => esc_html__('Paid', 'event_espresso'),
102
-                'actions'          => esc_html__('Actions', 'event_espresso'),
103
-            ];
104
-            $this->_bottom_buttons = [
105
-                'report' => [
106
-                    'route'         => 'registrations_report',
107
-                    'extra_request' => [
108
-                        'EVT_ID'     => isset($this->_req_data['event_id'])
109
-                            ? $this->_req_data['event_id']
110
-                            : null,
111
-                        'return_url' => $return_url,
112
-                    ],
113
-                ],
114
-            ];
115
-        } else {
116
-            $this->_columns        = [
117
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
118
-                '_REG_ID'          => $ID_column_name,
119
-                'ATT_fname'        => esc_html__('Name', 'event_espresso'),
120
-                '_REG_date'        => esc_html__('TXN Date', 'event_espresso'),
121
-                'event_name'       => esc_html__('Event', 'event_espresso'),
122
-                'DTT_EVT_start'    => esc_html__('Event Date', 'event_espresso'),
123
-                '_REG_final_price' => esc_html__('Price', 'event_espresso'),
124
-                '_REG_paid'        => esc_html__('Paid', 'event_espresso'),
125
-                'actions'          => esc_html__('Actions', 'event_espresso'),
126
-            ];
127
-            $this->_bottom_buttons = [
128
-                'report_all' => [
129
-                    'route'         => 'registrations_report',
130
-                    'extra_request' => [
131
-                        'return_url' => $return_url,
132
-                    ],
133
-                ],
134
-            ];
135
-        }
136
-        $this->_bottom_buttons['report_filtered'] = [
137
-            'route'         => 'registrations_report',
138
-            'extra_request' => [
139
-                'use_filters' => true,
140
-                'return_url'  => $return_url,
141
-            ],
142
-        ];
143
-        $filters                                  = array_diff_key(
144
-            $this->_req_data,
145
-            array_flip(
146
-                [
147
-                    'page',
148
-                    'action',
149
-                    'default_nonce',
150
-                ]
151
-            )
152
-        );
153
-        if (! empty($filters)) {
154
-            $this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
155
-        }
156
-        $this->_primary_column   = '_REG_ID';
157
-        $this->_sortable_columns = [
158
-            '_REG_date'     => ['_REG_date' => true],   // true means its already sorted
159
-            /**
160
-             * Allows users to change the default sort if they wish.
161
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
162
-             * name.
163
-             */
164
-            'ATT_fname'     => [
165
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
166
-                true,
167
-                $this,
168
-            ]
169
-                ? ['ATT_lname' => false]
170
-                : ['ATT_fname' => false],
171
-            'event_name'    => ['event_name' => false],
172
-            'DTT_EVT_start' => ['DTT_EVT_start' => false],
173
-            '_REG_ID'       => ['_REG_ID' => false],
174
-        ];
175
-        $this->_hidden_columns   = [];
176
-    }
74
+	/**
75
+	 * @return void
76
+	 */
77
+	protected function _set_properties()
78
+	{
79
+		$return_url          = $this->getReturnUrl();
80
+		$this->_wp_list_args = [
81
+			'singular' => esc_html__('registration', 'event_espresso'),
82
+			'plural'   => esc_html__('registrations', 'event_espresso'),
83
+			'ajax'     => true,
84
+			'screen'   => $this->_admin_page->get_current_screen()->id,
85
+		];
86
+		$ID_column_name      = esc_html__('ID', 'event_espresso');
87
+		$ID_column_name      .= ' : <span class="show-on-mobile-view-only" style="float:none">';
88
+		$ID_column_name      .= esc_html__('Registrant Name', 'event_espresso');
89
+		$ID_column_name      .= '</span> ';
90
+		$req_data            = $this->_admin_page->get_request_data();
91
+		if (isset($req_data['event_id'])) {
92
+			$this->_columns        = [
93
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
94
+				'_REG_ID'          => $ID_column_name,
95
+				'ATT_fname'        => esc_html__('Name', 'event_espresso'),
96
+				'ATT_email'        => esc_html__('Email', 'event_espresso'),
97
+				'_REG_date'        => esc_html__('Reg Date', 'event_espresso'),
98
+				'PRC_amount'       => esc_html__('TKT Price', 'event_espresso'),
99
+				'_REG_final_price' => esc_html__('Final Price', 'event_espresso'),
100
+				'TXN_total'        => esc_html__('Total Txn', 'event_espresso'),
101
+				'TXN_paid'         => esc_html__('Paid', 'event_espresso'),
102
+				'actions'          => esc_html__('Actions', 'event_espresso'),
103
+			];
104
+			$this->_bottom_buttons = [
105
+				'report' => [
106
+					'route'         => 'registrations_report',
107
+					'extra_request' => [
108
+						'EVT_ID'     => isset($this->_req_data['event_id'])
109
+							? $this->_req_data['event_id']
110
+							: null,
111
+						'return_url' => $return_url,
112
+					],
113
+				],
114
+			];
115
+		} else {
116
+			$this->_columns        = [
117
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
118
+				'_REG_ID'          => $ID_column_name,
119
+				'ATT_fname'        => esc_html__('Name', 'event_espresso'),
120
+				'_REG_date'        => esc_html__('TXN Date', 'event_espresso'),
121
+				'event_name'       => esc_html__('Event', 'event_espresso'),
122
+				'DTT_EVT_start'    => esc_html__('Event Date', 'event_espresso'),
123
+				'_REG_final_price' => esc_html__('Price', 'event_espresso'),
124
+				'_REG_paid'        => esc_html__('Paid', 'event_espresso'),
125
+				'actions'          => esc_html__('Actions', 'event_espresso'),
126
+			];
127
+			$this->_bottom_buttons = [
128
+				'report_all' => [
129
+					'route'         => 'registrations_report',
130
+					'extra_request' => [
131
+						'return_url' => $return_url,
132
+					],
133
+				],
134
+			];
135
+		}
136
+		$this->_bottom_buttons['report_filtered'] = [
137
+			'route'         => 'registrations_report',
138
+			'extra_request' => [
139
+				'use_filters' => true,
140
+				'return_url'  => $return_url,
141
+			],
142
+		];
143
+		$filters                                  = array_diff_key(
144
+			$this->_req_data,
145
+			array_flip(
146
+				[
147
+					'page',
148
+					'action',
149
+					'default_nonce',
150
+				]
151
+			)
152
+		);
153
+		if (! empty($filters)) {
154
+			$this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
155
+		}
156
+		$this->_primary_column   = '_REG_ID';
157
+		$this->_sortable_columns = [
158
+			'_REG_date'     => ['_REG_date' => true],   // true means its already sorted
159
+			/**
160
+			 * Allows users to change the default sort if they wish.
161
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
162
+			 * name.
163
+			 */
164
+			'ATT_fname'     => [
165
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
166
+				true,
167
+				$this,
168
+			]
169
+				? ['ATT_lname' => false]
170
+				: ['ATT_fname' => false],
171
+			'event_name'    => ['event_name' => false],
172
+			'DTT_EVT_start' => ['DTT_EVT_start' => false],
173
+			'_REG_ID'       => ['_REG_ID' => false],
174
+		];
175
+		$this->_hidden_columns   = [];
176
+	}
177 177
 
178 178
 
179
-    /**
180
-     * This simply sets up the row class for the table rows.
181
-     * Allows for easier overriding of child methods for setting up sorting.
182
-     *
183
-     * @param EE_Registration $item the current item
184
-     * @return string
185
-     */
186
-    protected function _get_row_class($item)
187
-    {
188
-        $class = parent::_get_row_class($item);
189
-        // add status class
190
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
191
-        if ($this->_has_checkbox_column) {
192
-            $class .= ' has-checkbox-column';
193
-        }
194
-        return $class;
195
-    }
179
+	/**
180
+	 * This simply sets up the row class for the table rows.
181
+	 * Allows for easier overriding of child methods for setting up sorting.
182
+	 *
183
+	 * @param EE_Registration $item the current item
184
+	 * @return string
185
+	 */
186
+	protected function _get_row_class($item)
187
+	{
188
+		$class = parent::_get_row_class($item);
189
+		// add status class
190
+		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
191
+		if ($this->_has_checkbox_column) {
192
+			$class .= ' has-checkbox-column';
193
+		}
194
+		return $class;
195
+	}
196 196
 
197 197
 
198
-    /**
199
-     * Set the $_transaction_details property if not set yet.
200
-     *
201
-     * @param EE_Registration $registration
202
-     * @throws EE_Error
203
-     * @throws InvalidArgumentException
204
-     * @throws ReflectionException
205
-     * @throws InvalidDataTypeException
206
-     * @throws InvalidInterfaceException
207
-     */
208
-    protected function _set_related_details(EE_Registration $registration)
209
-    {
210
-        $transaction                = $registration->get_first_related('Transaction');
211
-        $status                     = $transaction instanceof EE_Transaction
212
-            ? $transaction->status_ID()
213
-            : EEM_Transaction::failed_status_code;
214
-        $this->_transaction_details = [
215
-            'transaction' => $transaction,
216
-            'status'      => $status,
217
-            'id'          => $transaction instanceof EE_Transaction
218
-                ? $transaction->ID()
219
-                : 0,
220
-            'title_attr'  => sprintf(
221
-                esc_html__('View Transaction Details (%s)', 'event_espresso'),
222
-                EEH_Template::pretty_status($status, false, 'sentence')
223
-            ),
224
-        ];
225
-        try {
226
-            $event = $registration->event();
227
-        } catch (EntityNotFoundException $e) {
228
-            $event = null;
229
-        }
230
-        $status               = $event instanceof EE_Event
231
-            ? $event->get_active_status()
232
-            : EE_Datetime::inactive;
233
-        $this->_event_details = [
234
-            'event'      => $event,
235
-            'status'     => $status,
236
-            'id'         => $event instanceof EE_Event
237
-                ? $event->ID()
238
-                : 0,
239
-            'title_attr' => sprintf(
240
-                esc_html__('Edit Event (%s)', 'event_espresso'),
241
-                EEH_Template::pretty_status($status, false, 'sentence')
242
-            ),
243
-        ];
244
-    }
198
+	/**
199
+	 * Set the $_transaction_details property if not set yet.
200
+	 *
201
+	 * @param EE_Registration $registration
202
+	 * @throws EE_Error
203
+	 * @throws InvalidArgumentException
204
+	 * @throws ReflectionException
205
+	 * @throws InvalidDataTypeException
206
+	 * @throws InvalidInterfaceException
207
+	 */
208
+	protected function _set_related_details(EE_Registration $registration)
209
+	{
210
+		$transaction                = $registration->get_first_related('Transaction');
211
+		$status                     = $transaction instanceof EE_Transaction
212
+			? $transaction->status_ID()
213
+			: EEM_Transaction::failed_status_code;
214
+		$this->_transaction_details = [
215
+			'transaction' => $transaction,
216
+			'status'      => $status,
217
+			'id'          => $transaction instanceof EE_Transaction
218
+				? $transaction->ID()
219
+				: 0,
220
+			'title_attr'  => sprintf(
221
+				esc_html__('View Transaction Details (%s)', 'event_espresso'),
222
+				EEH_Template::pretty_status($status, false, 'sentence')
223
+			),
224
+		];
225
+		try {
226
+			$event = $registration->event();
227
+		} catch (EntityNotFoundException $e) {
228
+			$event = null;
229
+		}
230
+		$status               = $event instanceof EE_Event
231
+			? $event->get_active_status()
232
+			: EE_Datetime::inactive;
233
+		$this->_event_details = [
234
+			'event'      => $event,
235
+			'status'     => $status,
236
+			'id'         => $event instanceof EE_Event
237
+				? $event->ID()
238
+				: 0,
239
+			'title_attr' => sprintf(
240
+				esc_html__('Edit Event (%s)', 'event_espresso'),
241
+				EEH_Template::pretty_status($status, false, 'sentence')
242
+			),
243
+		];
244
+	}
245 245
 
246 246
 
247
-    /**
248
-     *    _get_table_filters
249
-     *
250
-     * @return array
251
-     */
252
-    protected function _get_table_filters()
253
-    {
254
-        $filters = [];
255
-        // todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
256
-        // methods.
257
-        $cur_date     = isset($this->_req_data['month_range'])
258
-            ? $this->_req_data['month_range']
259
-            : '';
260
-        $cur_category = isset($this->_req_data['EVT_CAT'])
261
-            ? $this->_req_data['EVT_CAT']
262
-            : -1;
263
-        $reg_status   = isset($this->_req_data['_reg_status'])
264
-            ? $this->_req_data['_reg_status']
265
-            : '';
266
-        $filters[]    = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
267
-        $filters[]    = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
268
-        $status       = [];
269
-        $status[]     = ['id' => 0, 'text' => esc_html__('Select Status', 'event_espresso')];
270
-        foreach ($this->_status as $key => $value) {
271
-            $status[] = ['id' => $key, 'text' => $value];
272
-        }
273
-        if ($this->_view !== 'incomplete') {
274
-            $filters[] = EEH_Form_Fields::select_input(
275
-                '_reg_status',
276
-                $status,
277
-                isset($this->_req_data['_reg_status'])
278
-                    ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
279
-                    : ''
280
-            );
281
-        }
282
-        if (isset($this->_req_data['event_id'])) {
283
-            $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
284
-        }
285
-        return $filters;
286
-    }
247
+	/**
248
+	 *    _get_table_filters
249
+	 *
250
+	 * @return array
251
+	 */
252
+	protected function _get_table_filters()
253
+	{
254
+		$filters = [];
255
+		// todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
256
+		// methods.
257
+		$cur_date     = isset($this->_req_data['month_range'])
258
+			? $this->_req_data['month_range']
259
+			: '';
260
+		$cur_category = isset($this->_req_data['EVT_CAT'])
261
+			? $this->_req_data['EVT_CAT']
262
+			: -1;
263
+		$reg_status   = isset($this->_req_data['_reg_status'])
264
+			? $this->_req_data['_reg_status']
265
+			: '';
266
+		$filters[]    = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
267
+		$filters[]    = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
268
+		$status       = [];
269
+		$status[]     = ['id' => 0, 'text' => esc_html__('Select Status', 'event_espresso')];
270
+		foreach ($this->_status as $key => $value) {
271
+			$status[] = ['id' => $key, 'text' => $value];
272
+		}
273
+		if ($this->_view !== 'incomplete') {
274
+			$filters[] = EEH_Form_Fields::select_input(
275
+				'_reg_status',
276
+				$status,
277
+				isset($this->_req_data['_reg_status'])
278
+					? strtoupper(sanitize_key($this->_req_data['_reg_status']))
279
+					: ''
280
+			);
281
+		}
282
+		if (isset($this->_req_data['event_id'])) {
283
+			$filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
284
+		}
285
+		return $filters;
286
+	}
287 287
 
288 288
 
289
-    /**
290
-     * @return void
291
-     * @throws EE_Error
292
-     * @throws InvalidArgumentException
293
-     * @throws InvalidDataTypeException
294
-     * @throws InvalidInterfaceException
295
-     */
296
-    protected function _add_view_counts()
297
-    {
298
-        $this->_views['all']['count']   = $this->_total_registrations();
299
-        $this->_views['month']['count'] = $this->_total_registrations_this_month();
300
-        $this->_views['today']['count'] = $this->_total_registrations_today();
301
-        if (
302
-            EE_Registry::instance()->CAP->current_user_can(
303
-                'ee_delete_registrations',
304
-                'espresso_registrations_trash_registrations'
305
-            )
306
-        ) {
307
-            $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
308
-            $this->_views['trash']['count']      = $this->_total_registrations('trash');
309
-        }
310
-    }
289
+	/**
290
+	 * @return void
291
+	 * @throws EE_Error
292
+	 * @throws InvalidArgumentException
293
+	 * @throws InvalidDataTypeException
294
+	 * @throws InvalidInterfaceException
295
+	 */
296
+	protected function _add_view_counts()
297
+	{
298
+		$this->_views['all']['count']   = $this->_total_registrations();
299
+		$this->_views['month']['count'] = $this->_total_registrations_this_month();
300
+		$this->_views['today']['count'] = $this->_total_registrations_today();
301
+		if (
302
+			EE_Registry::instance()->CAP->current_user_can(
303
+				'ee_delete_registrations',
304
+				'espresso_registrations_trash_registrations'
305
+			)
306
+		) {
307
+			$this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
308
+			$this->_views['trash']['count']      = $this->_total_registrations('trash');
309
+		}
310
+	}
311 311
 
312 312
 
313
-    /**
314
-     * @param string $view
315
-     * @return int
316
-     * @throws EE_Error
317
-     * @throws InvalidArgumentException
318
-     * @throws InvalidDataTypeException
319
-     * @throws InvalidInterfaceException
320
-     */
321
-    protected function _total_registrations($view = '')
322
-    {
323
-        $_where = [];
324
-        $EVT_ID = isset($this->_req_data['event_id'])
325
-            ? absint($this->_req_data['event_id'])
326
-            : false;
327
-        if ($EVT_ID) {
328
-            $_where['EVT_ID'] = $EVT_ID;
329
-        }
330
-        switch ($view) {
331
-            case 'trash':
332
-                return EEM_Registration::instance()->count_deleted([$_where]);
333
-            case 'incomplete':
334
-                $_where['STS_ID'] = EEM_Registration::status_id_incomplete;
335
-                break;
336
-            default:
337
-                $_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
338
-        }
339
-        return EEM_Registration::instance()->count([$_where]);
340
-    }
313
+	/**
314
+	 * @param string $view
315
+	 * @return int
316
+	 * @throws EE_Error
317
+	 * @throws InvalidArgumentException
318
+	 * @throws InvalidDataTypeException
319
+	 * @throws InvalidInterfaceException
320
+	 */
321
+	protected function _total_registrations($view = '')
322
+	{
323
+		$_where = [];
324
+		$EVT_ID = isset($this->_req_data['event_id'])
325
+			? absint($this->_req_data['event_id'])
326
+			: false;
327
+		if ($EVT_ID) {
328
+			$_where['EVT_ID'] = $EVT_ID;
329
+		}
330
+		switch ($view) {
331
+			case 'trash':
332
+				return EEM_Registration::instance()->count_deleted([$_where]);
333
+			case 'incomplete':
334
+				$_where['STS_ID'] = EEM_Registration::status_id_incomplete;
335
+				break;
336
+			default:
337
+				$_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
338
+		}
339
+		return EEM_Registration::instance()->count([$_where]);
340
+	}
341 341
 
342 342
 
343
-    /**
344
-     * @return int
345
-     * @throws EE_Error
346
-     * @throws InvalidArgumentException
347
-     * @throws InvalidDataTypeException
348
-     * @throws InvalidInterfaceException
349
-     */
350
-    protected function _total_registrations_this_month()
351
-    {
352
-        $EVT_ID          = isset($this->_req_data['event_id'])
353
-            ? absint($this->_req_data['event_id'])
354
-            : false;
355
-        $_where          = $EVT_ID
356
-            ? ['EVT_ID' => $EVT_ID]
357
-            : [];
358
-        $this_year_r     = date('Y', current_time('timestamp'));
359
-        $time_start      = ' 00:00:00';
360
-        $time_end        = ' 23:59:59';
361
-        $this_month_r    = date('m', current_time('timestamp'));
362
-        $days_this_month = date('t', current_time('timestamp'));
363
-        // setup date query.
364
-        $beginning_string   = EEM_Registration::instance()->convert_datetime_for_query(
365
-            'REG_date',
366
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
367
-            'Y-m-d H:i:s'
368
-        );
369
-        $end_string         = EEM_Registration::instance()->convert_datetime_for_query(
370
-            'REG_date',
371
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
372
-            'Y-m-d H:i:s'
373
-        );
374
-        $_where['REG_date'] = [
375
-            'BETWEEN',
376
-            [
377
-                $beginning_string,
378
-                $end_string,
379
-            ],
380
-        ];
381
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
382
-        return EEM_Registration::instance()->count([$_where]);
383
-    }
343
+	/**
344
+	 * @return int
345
+	 * @throws EE_Error
346
+	 * @throws InvalidArgumentException
347
+	 * @throws InvalidDataTypeException
348
+	 * @throws InvalidInterfaceException
349
+	 */
350
+	protected function _total_registrations_this_month()
351
+	{
352
+		$EVT_ID          = isset($this->_req_data['event_id'])
353
+			? absint($this->_req_data['event_id'])
354
+			: false;
355
+		$_where          = $EVT_ID
356
+			? ['EVT_ID' => $EVT_ID]
357
+			: [];
358
+		$this_year_r     = date('Y', current_time('timestamp'));
359
+		$time_start      = ' 00:00:00';
360
+		$time_end        = ' 23:59:59';
361
+		$this_month_r    = date('m', current_time('timestamp'));
362
+		$days_this_month = date('t', current_time('timestamp'));
363
+		// setup date query.
364
+		$beginning_string   = EEM_Registration::instance()->convert_datetime_for_query(
365
+			'REG_date',
366
+			$this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
367
+			'Y-m-d H:i:s'
368
+		);
369
+		$end_string         = EEM_Registration::instance()->convert_datetime_for_query(
370
+			'REG_date',
371
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
372
+			'Y-m-d H:i:s'
373
+		);
374
+		$_where['REG_date'] = [
375
+			'BETWEEN',
376
+			[
377
+				$beginning_string,
378
+				$end_string,
379
+			],
380
+		];
381
+		$_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
382
+		return EEM_Registration::instance()->count([$_where]);
383
+	}
384 384
 
385 385
 
386
-    /**
387
-     * @return int
388
-     * @throws EE_Error
389
-     * @throws InvalidArgumentException
390
-     * @throws InvalidDataTypeException
391
-     * @throws InvalidInterfaceException
392
-     */
393
-    protected function _total_registrations_today()
394
-    {
395
-        $EVT_ID             = isset($this->_req_data['event_id'])
396
-            ? absint($this->_req_data['event_id'])
397
-            : false;
398
-        $_where             = $EVT_ID
399
-            ? ['EVT_ID' => $EVT_ID]
400
-            : [];
401
-        $current_date       = date('Y-m-d', current_time('timestamp'));
402
-        $time_start         = ' 00:00:00';
403
-        $time_end           = ' 23:59:59';
404
-        $_where['REG_date'] = [
405
-            'BETWEEN',
406
-            [
407
-                EEM_Registration::instance()->convert_datetime_for_query(
408
-                    'REG_date',
409
-                    $current_date . $time_start,
410
-                    'Y-m-d H:i:s'
411
-                ),
412
-                EEM_Registration::instance()->convert_datetime_for_query(
413
-                    'REG_date',
414
-                    $current_date . $time_end,
415
-                    'Y-m-d H:i:s'
416
-                ),
417
-            ],
418
-        ];
419
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
420
-        return EEM_Registration::instance()->count([$_where]);
421
-    }
386
+	/**
387
+	 * @return int
388
+	 * @throws EE_Error
389
+	 * @throws InvalidArgumentException
390
+	 * @throws InvalidDataTypeException
391
+	 * @throws InvalidInterfaceException
392
+	 */
393
+	protected function _total_registrations_today()
394
+	{
395
+		$EVT_ID             = isset($this->_req_data['event_id'])
396
+			? absint($this->_req_data['event_id'])
397
+			: false;
398
+		$_where             = $EVT_ID
399
+			? ['EVT_ID' => $EVT_ID]
400
+			: [];
401
+		$current_date       = date('Y-m-d', current_time('timestamp'));
402
+		$time_start         = ' 00:00:00';
403
+		$time_end           = ' 23:59:59';
404
+		$_where['REG_date'] = [
405
+			'BETWEEN',
406
+			[
407
+				EEM_Registration::instance()->convert_datetime_for_query(
408
+					'REG_date',
409
+					$current_date . $time_start,
410
+					'Y-m-d H:i:s'
411
+				),
412
+				EEM_Registration::instance()->convert_datetime_for_query(
413
+					'REG_date',
414
+					$current_date . $time_end,
415
+					'Y-m-d H:i:s'
416
+				),
417
+			],
418
+		];
419
+		$_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
420
+		return EEM_Registration::instance()->count([$_where]);
421
+	}
422 422
 
423 423
 
424
-    /**
425
-     * @param EE_Registration $item
426
-     * @return string
427
-     * @throws EE_Error
428
-     * @throws InvalidArgumentException
429
-     * @throws InvalidDataTypeException
430
-     * @throws InvalidInterfaceException
431
-     * @throws ReflectionException
432
-     */
433
-    public function column_cb($item)
434
-    {
435
-        /** checkbox/lock **/
436
-        $transaction   = $item->get_first_related('Transaction');
437
-        $payment_count = $transaction instanceof EE_Transaction
438
-            ? $transaction->count_related('Payment')
439
-            : 0;
440
-        return $payment_count > 0 || ! EE_Registry::instance()->CAP->current_user_can(
441
-            'ee_edit_registration',
442
-            'registration_list_table_checkbox_input',
443
-            $item->ID()
444
-        )
445
-            ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
446
-              . '<span class="ee-lock-icon"></span>'
447
-            : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
448
-    }
424
+	/**
425
+	 * @param EE_Registration $item
426
+	 * @return string
427
+	 * @throws EE_Error
428
+	 * @throws InvalidArgumentException
429
+	 * @throws InvalidDataTypeException
430
+	 * @throws InvalidInterfaceException
431
+	 * @throws ReflectionException
432
+	 */
433
+	public function column_cb($item)
434
+	{
435
+		/** checkbox/lock **/
436
+		$transaction   = $item->get_first_related('Transaction');
437
+		$payment_count = $transaction instanceof EE_Transaction
438
+			? $transaction->count_related('Payment')
439
+			: 0;
440
+		return $payment_count > 0 || ! EE_Registry::instance()->CAP->current_user_can(
441
+			'ee_edit_registration',
442
+			'registration_list_table_checkbox_input',
443
+			$item->ID()
444
+		)
445
+			? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
446
+			  . '<span class="ee-lock-icon"></span>'
447
+			: sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
448
+	}
449 449
 
450 450
 
451
-    /**
452
-     * @param EE_Registration $item
453
-     * @return string
454
-     * @throws EE_Error
455
-     * @throws InvalidArgumentException
456
-     * @throws InvalidDataTypeException
457
-     * @throws InvalidInterfaceException
458
-     * @throws ReflectionException
459
-     */
460
-    public function column__REG_ID(EE_Registration $item)
461
-    {
462
-        $attendee = $item->attendee();
463
-        $content  = $item->ID();
464
-        $content  .= '<div class="show-on-mobile-view-only">';
465
-        $content  .= '<br>';
466
-        $content  .= $attendee instanceof EE_Attendee
467
-            ? $attendee->full_name()
468
-            : '';
469
-        $content  .= '&nbsp;';
470
-        $content  .= sprintf(
471
-            esc_html__('(%1$s / %2$s)', 'event_espresso'),
472
-            $item->count(),
473
-            $item->group_size()
474
-        );
475
-        $content  .= '<br>';
476
-        $content  .= sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
477
-        $content  .= '</div>';
478
-        return $content;
479
-    }
451
+	/**
452
+	 * @param EE_Registration $item
453
+	 * @return string
454
+	 * @throws EE_Error
455
+	 * @throws InvalidArgumentException
456
+	 * @throws InvalidDataTypeException
457
+	 * @throws InvalidInterfaceException
458
+	 * @throws ReflectionException
459
+	 */
460
+	public function column__REG_ID(EE_Registration $item)
461
+	{
462
+		$attendee = $item->attendee();
463
+		$content  = $item->ID();
464
+		$content  .= '<div class="show-on-mobile-view-only">';
465
+		$content  .= '<br>';
466
+		$content  .= $attendee instanceof EE_Attendee
467
+			? $attendee->full_name()
468
+			: '';
469
+		$content  .= '&nbsp;';
470
+		$content  .= sprintf(
471
+			esc_html__('(%1$s / %2$s)', 'event_espresso'),
472
+			$item->count(),
473
+			$item->group_size()
474
+		);
475
+		$content  .= '<br>';
476
+		$content  .= sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
477
+		$content  .= '</div>';
478
+		return $content;
479
+	}
480 480
 
481 481
 
482
-    /**
483
-     * @param EE_Registration $item
484
-     * @return string
485
-     * @throws EE_Error
486
-     * @throws InvalidArgumentException
487
-     * @throws InvalidDataTypeException
488
-     * @throws InvalidInterfaceException
489
-     * @throws ReflectionException
490
-     */
491
-    public function column__REG_date(EE_Registration $item)
492
-    {
493
-        $this->_set_related_details($item);
494
-        // Build row actions
495
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
496
-            [
497
-                'action' => 'view_transaction',
498
-                'TXN_ID' => $this->_transaction_details['id'],
499
-            ],
500
-            TXN_ADMIN_URL
501
-        );
502
-        $view_link    = EE_Registry::instance()->CAP->current_user_can(
503
-            'ee_read_transaction',
504
-            'espresso_transactions_view_transaction'
505
-        )
506
-            ? '<a class="ee-status-color-'
507
-              . $this->_transaction_details['status']
508
-              . '" href="'
509
-              . $view_lnk_url
510
-              . '" title="'
511
-              . esc_attr($this->_transaction_details['title_attr'])
512
-              . '">'
513
-              . $item->get_i18n_datetime('REG_date')
514
-              . '</a>'
515
-            : $item->get_i18n_datetime('REG_date');
516
-        $view_link    .= '<br><span class="ee-status-text-small">'
517
-                         . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
518
-                         . '</span>';
519
-        return $view_link;
520
-    }
482
+	/**
483
+	 * @param EE_Registration $item
484
+	 * @return string
485
+	 * @throws EE_Error
486
+	 * @throws InvalidArgumentException
487
+	 * @throws InvalidDataTypeException
488
+	 * @throws InvalidInterfaceException
489
+	 * @throws ReflectionException
490
+	 */
491
+	public function column__REG_date(EE_Registration $item)
492
+	{
493
+		$this->_set_related_details($item);
494
+		// Build row actions
495
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
496
+			[
497
+				'action' => 'view_transaction',
498
+				'TXN_ID' => $this->_transaction_details['id'],
499
+			],
500
+			TXN_ADMIN_URL
501
+		);
502
+		$view_link    = EE_Registry::instance()->CAP->current_user_can(
503
+			'ee_read_transaction',
504
+			'espresso_transactions_view_transaction'
505
+		)
506
+			? '<a class="ee-status-color-'
507
+			  . $this->_transaction_details['status']
508
+			  . '" href="'
509
+			  . $view_lnk_url
510
+			  . '" title="'
511
+			  . esc_attr($this->_transaction_details['title_attr'])
512
+			  . '">'
513
+			  . $item->get_i18n_datetime('REG_date')
514
+			  . '</a>'
515
+			: $item->get_i18n_datetime('REG_date');
516
+		$view_link    .= '<br><span class="ee-status-text-small">'
517
+						 . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
518
+						 . '</span>';
519
+		return $view_link;
520
+	}
521 521
 
522 522
 
523
-    /**
524
-     * @param EE_Registration $item
525
-     * @return string
526
-     * @throws EE_Error
527
-     * @throws InvalidArgumentException
528
-     * @throws InvalidDataTypeException
529
-     * @throws InvalidInterfaceException
530
-     * @throws ReflectionException
531
-     */
532
-    public function column_event_name(EE_Registration $item)
533
-    {
534
-        $this->_set_related_details($item);
535
-        // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
536
-        $EVT_ID     = $item->event_ID();
537
-        $event_name = $item->event_name();
538
-        $event_name =
539
-            $event_name
540
-                ?: esc_html__("No Associated Event", 'event_espresso');
541
-        $event_name = wp_trim_words($event_name, 30, '...');
542
-        if ($EVT_ID) {
543
-            $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(
544
-                ['action' => 'edit', 'post' => $EVT_ID],
545
-                EVENTS_ADMIN_URL
546
-            );
547
-            $edit_event              =
548
-                EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
549
-                    ? '<a class="ee-status-color-'
550
-                      . $this->_event_details['status']
551
-                      . '" href="'
552
-                      . $edit_event_url
553
-                      . '" title="'
554
-                      . esc_attr($this->_event_details['title_attr'])
555
-                      . '">'
556
-                      . $event_name
557
-                      . '</a>'
558
-                    : $event_name;
559
-            $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(['event_id' => $EVT_ID], REG_ADMIN_URL);
560
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
561
-            $actions['event_filter'] .= sprintf(
562
-                esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
563
-                $event_name
564
-            );
565
-            $actions['event_filter'] .= '">' . esc_html__('View Registrations', 'event_espresso') . '</a>';
566
-        } else {
567
-            $edit_event              = $event_name;
568
-            $actions['event_filter'] = '';
569
-        }
570
-        return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
571
-    }
523
+	/**
524
+	 * @param EE_Registration $item
525
+	 * @return string
526
+	 * @throws EE_Error
527
+	 * @throws InvalidArgumentException
528
+	 * @throws InvalidDataTypeException
529
+	 * @throws InvalidInterfaceException
530
+	 * @throws ReflectionException
531
+	 */
532
+	public function column_event_name(EE_Registration $item)
533
+	{
534
+		$this->_set_related_details($item);
535
+		// page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
536
+		$EVT_ID     = $item->event_ID();
537
+		$event_name = $item->event_name();
538
+		$event_name =
539
+			$event_name
540
+				?: esc_html__("No Associated Event", 'event_espresso');
541
+		$event_name = wp_trim_words($event_name, 30, '...');
542
+		if ($EVT_ID) {
543
+			$edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(
544
+				['action' => 'edit', 'post' => $EVT_ID],
545
+				EVENTS_ADMIN_URL
546
+			);
547
+			$edit_event              =
548
+				EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
549
+					? '<a class="ee-status-color-'
550
+					  . $this->_event_details['status']
551
+					  . '" href="'
552
+					  . $edit_event_url
553
+					  . '" title="'
554
+					  . esc_attr($this->_event_details['title_attr'])
555
+					  . '">'
556
+					  . $event_name
557
+					  . '</a>'
558
+					: $event_name;
559
+			$edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(['event_id' => $EVT_ID], REG_ADMIN_URL);
560
+			$actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
561
+			$actions['event_filter'] .= sprintf(
562
+				esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
563
+				$event_name
564
+			);
565
+			$actions['event_filter'] .= '">' . esc_html__('View Registrations', 'event_espresso') . '</a>';
566
+		} else {
567
+			$edit_event              = $event_name;
568
+			$actions['event_filter'] = '';
569
+		}
570
+		return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
571
+	}
572 572
 
573 573
 
574
-    /**
575
-     * @param EE_Registration $item
576
-     * @return string
577
-     * @throws EE_Error
578
-     * @throws InvalidArgumentException
579
-     * @throws InvalidDataTypeException
580
-     * @throws InvalidInterfaceException
581
-     * @throws ReflectionException
582
-     */
583
-    public function column_DTT_EVT_start(EE_Registration $item)
584
-    {
585
-        $datetime_strings = [];
586
-        $ticket           = $item->ticket();
587
-        if ($ticket instanceof EE_Ticket) {
588
-            $remove_defaults = ['default_where_conditions' => 'none'];
589
-            $datetimes       = $ticket->datetimes($remove_defaults);
590
-            foreach ($datetimes as $datetime) {
591
-                $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
592
-            }
593
-            return $this->generateDisplayForDatetimes($datetime_strings);
594
-        }
595
-        return esc_html__('There is no ticket on this registration', 'event_espresso');
596
-    }
574
+	/**
575
+	 * @param EE_Registration $item
576
+	 * @return string
577
+	 * @throws EE_Error
578
+	 * @throws InvalidArgumentException
579
+	 * @throws InvalidDataTypeException
580
+	 * @throws InvalidInterfaceException
581
+	 * @throws ReflectionException
582
+	 */
583
+	public function column_DTT_EVT_start(EE_Registration $item)
584
+	{
585
+		$datetime_strings = [];
586
+		$ticket           = $item->ticket();
587
+		if ($ticket instanceof EE_Ticket) {
588
+			$remove_defaults = ['default_where_conditions' => 'none'];
589
+			$datetimes       = $ticket->datetimes($remove_defaults);
590
+			foreach ($datetimes as $datetime) {
591
+				$datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
592
+			}
593
+			return $this->generateDisplayForDatetimes($datetime_strings);
594
+		}
595
+		return esc_html__('There is no ticket on this registration', 'event_espresso');
596
+	}
597 597
 
598 598
 
599
-    /**
600
-     * Receives an array of datetime strings to display and converts them to the html container for the column.
601
-     *
602
-     * @param array $datetime_strings
603
-     * @return string
604
-     */
605
-    public function generateDisplayForDateTimes(array $datetime_strings)
606
-    {
607
-        $content       = '<div class="ee-registration-event-datetimes-container">';
608
-        $expand_toggle = count($datetime_strings) > 1
609
-            ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
610
-              . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
611
-            : '';
612
-        // get first item for initial visibility
613
-        $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
614
-        $content .= $expand_toggle;
615
-        if ($datetime_strings) {
616
-            $content .= '<div style="clear:both"></div>';
617
-            $content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
618
-            $content .= implode("<br />", $datetime_strings);
619
-            $content .= '</div>';
620
-        }
621
-        $content .= '</div>';
622
-        return $content;
623
-    }
599
+	/**
600
+	 * Receives an array of datetime strings to display and converts them to the html container for the column.
601
+	 *
602
+	 * @param array $datetime_strings
603
+	 * @return string
604
+	 */
605
+	public function generateDisplayForDateTimes(array $datetime_strings)
606
+	{
607
+		$content       = '<div class="ee-registration-event-datetimes-container">';
608
+		$expand_toggle = count($datetime_strings) > 1
609
+			? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
610
+			  . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
611
+			: '';
612
+		// get first item for initial visibility
613
+		$content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
614
+		$content .= $expand_toggle;
615
+		if ($datetime_strings) {
616
+			$content .= '<div style="clear:both"></div>';
617
+			$content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
618
+			$content .= implode("<br />", $datetime_strings);
619
+			$content .= '</div>';
620
+		}
621
+		$content .= '</div>';
622
+		return $content;
623
+	}
624 624
 
625 625
 
626
-    /**
627
-     * @param EE_Registration $item
628
-     * @return string
629
-     * @throws EE_Error
630
-     * @throws InvalidArgumentException
631
-     * @throws InvalidDataTypeException
632
-     * @throws InvalidInterfaceException
633
-     * @throws ReflectionException
634
-     */
635
-    public function column_ATT_fname(EE_Registration $item)
636
-    {
637
-        $attendee      = $item->attendee();
638
-        $edit_lnk_url  = EE_Admin_Page::add_query_args_and_nonce(
639
-            [
640
-                'action'  => 'view_registration',
641
-                '_REG_ID' => $item->ID(),
642
-            ],
643
-            REG_ADMIN_URL
644
-        );
645
-        $attendee_name = $attendee instanceof EE_Attendee
646
-            ? $attendee->full_name()
647
-            : '';
648
-        $link          = EE_Registry::instance()->CAP->current_user_can(
649
-            'ee_read_registration',
650
-            'espresso_registrations_view_registration',
651
-            $item->ID()
652
-        )
653
-            ? '<a href="'
654
-              . $edit_lnk_url
655
-              . '" title="'
656
-              . esc_attr__('View Registration Details', 'event_espresso')
657
-              . '">'
658
-              . $attendee_name
659
-              . '</a>'
660
-            : $attendee_name;
661
-        $link          .= $item->count() === 1
662
-            ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>'
663
-            : '';
664
-        $t             = $item->get_first_related('Transaction');
665
-        $payment_count = $t instanceof EE_Transaction
666
-            ? $t->count_related('Payment')
667
-            : 0;
668
-        // append group count to name
669
-        $link .= '&nbsp;' . sprintf(esc_html__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
670
-        // append reg_code
671
-        $link .= '<br>' . sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
672
-        // reg status text for accessibility
673
-        $link   .= '<br><span class="ee-status-text-small">'
674
-                   . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
675
-                   . '</span>';
676
-        $action = ['_REG_ID' => $item->ID()];
677
-        if (isset($this->_req_data['event_id'])) {
678
-            $action['event_id'] = $item->event_ID();
679
-        }
680
-        // trash/restore/delete actions
681
-        $actions = [];
682
-        if (
683
-            $this->_view !== 'trash'
684
-            && $payment_count === 0
685
-            && EE_Registry::instance()->CAP->current_user_can(
686
-                'ee_delete_registration',
687
-                'espresso_registrations_trash_registrations',
688
-                $item->ID()
689
-            )
690
-        ) {
691
-            $action['action'] = 'trash_registrations';
692
-            $trash_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
693
-                $action,
694
-                REG_ADMIN_URL
695
-            );
696
-            $actions['trash'] = '<a href="'
697
-                                . $trash_lnk_url
698
-                                . '" title="'
699
-                                . esc_attr__('Trash Registration', 'event_espresso')
700
-                                . '">' . esc_html__('Trash', 'event_espresso') . '</a>';
701
-        } elseif ($this->_view === 'trash') {
702
-            // restore registration link
703
-            if (
704
-                EE_Registry::instance()->CAP->current_user_can(
705
-                    'ee_delete_registration',
706
-                    'espresso_registrations_restore_registrations',
707
-                    $item->ID()
708
-                )
709
-            ) {
710
-                $action['action']   = 'restore_registrations';
711
-                $restore_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
712
-                    $action,
713
-                    REG_ADMIN_URL
714
-                );
715
-                $actions['restore'] = '<a href="'
716
-                                      . $restore_lnk_url
717
-                                      . '" title="'
718
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
719
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
720
-            }
721
-            if (
722
-                EE_Registry::instance()->CAP->current_user_can(
723
-                    'ee_delete_registration',
724
-                    'espresso_registrations_ee_delete_registrations',
725
-                    $item->ID()
726
-                )
727
-            ) {
728
-                $action['action']  = 'delete_registrations';
729
-                $delete_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
730
-                    $action,
731
-                    REG_ADMIN_URL
732
-                );
733
-                $actions['delete'] = '<a href="'
734
-                                     . $delete_lnk_url
735
-                                     . '" title="'
736
-                                     . esc_attr__('Delete Registration Permanently', 'event_espresso')
737
-                                     . '">'
738
-                                     . esc_html__('Delete', 'event_espresso')
739
-                                     . '</a>';
740
-            }
741
-        }
742
-        return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
743
-    }
626
+	/**
627
+	 * @param EE_Registration $item
628
+	 * @return string
629
+	 * @throws EE_Error
630
+	 * @throws InvalidArgumentException
631
+	 * @throws InvalidDataTypeException
632
+	 * @throws InvalidInterfaceException
633
+	 * @throws ReflectionException
634
+	 */
635
+	public function column_ATT_fname(EE_Registration $item)
636
+	{
637
+		$attendee      = $item->attendee();
638
+		$edit_lnk_url  = EE_Admin_Page::add_query_args_and_nonce(
639
+			[
640
+				'action'  => 'view_registration',
641
+				'_REG_ID' => $item->ID(),
642
+			],
643
+			REG_ADMIN_URL
644
+		);
645
+		$attendee_name = $attendee instanceof EE_Attendee
646
+			? $attendee->full_name()
647
+			: '';
648
+		$link          = EE_Registry::instance()->CAP->current_user_can(
649
+			'ee_read_registration',
650
+			'espresso_registrations_view_registration',
651
+			$item->ID()
652
+		)
653
+			? '<a href="'
654
+			  . $edit_lnk_url
655
+			  . '" title="'
656
+			  . esc_attr__('View Registration Details', 'event_espresso')
657
+			  . '">'
658
+			  . $attendee_name
659
+			  . '</a>'
660
+			: $attendee_name;
661
+		$link          .= $item->count() === 1
662
+			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>'
663
+			: '';
664
+		$t             = $item->get_first_related('Transaction');
665
+		$payment_count = $t instanceof EE_Transaction
666
+			? $t->count_related('Payment')
667
+			: 0;
668
+		// append group count to name
669
+		$link .= '&nbsp;' . sprintf(esc_html__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
670
+		// append reg_code
671
+		$link .= '<br>' . sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
672
+		// reg status text for accessibility
673
+		$link   .= '<br><span class="ee-status-text-small">'
674
+				   . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
675
+				   . '</span>';
676
+		$action = ['_REG_ID' => $item->ID()];
677
+		if (isset($this->_req_data['event_id'])) {
678
+			$action['event_id'] = $item->event_ID();
679
+		}
680
+		// trash/restore/delete actions
681
+		$actions = [];
682
+		if (
683
+			$this->_view !== 'trash'
684
+			&& $payment_count === 0
685
+			&& EE_Registry::instance()->CAP->current_user_can(
686
+				'ee_delete_registration',
687
+				'espresso_registrations_trash_registrations',
688
+				$item->ID()
689
+			)
690
+		) {
691
+			$action['action'] = 'trash_registrations';
692
+			$trash_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
693
+				$action,
694
+				REG_ADMIN_URL
695
+			);
696
+			$actions['trash'] = '<a href="'
697
+								. $trash_lnk_url
698
+								. '" title="'
699
+								. esc_attr__('Trash Registration', 'event_espresso')
700
+								. '">' . esc_html__('Trash', 'event_espresso') . '</a>';
701
+		} elseif ($this->_view === 'trash') {
702
+			// restore registration link
703
+			if (
704
+				EE_Registry::instance()->CAP->current_user_can(
705
+					'ee_delete_registration',
706
+					'espresso_registrations_restore_registrations',
707
+					$item->ID()
708
+				)
709
+			) {
710
+				$action['action']   = 'restore_registrations';
711
+				$restore_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
712
+					$action,
713
+					REG_ADMIN_URL
714
+				);
715
+				$actions['restore'] = '<a href="'
716
+									  . $restore_lnk_url
717
+									  . '" title="'
718
+									  . esc_attr__('Restore Registration', 'event_espresso') . '">'
719
+									  . esc_html__('Restore', 'event_espresso') . '</a>';
720
+			}
721
+			if (
722
+				EE_Registry::instance()->CAP->current_user_can(
723
+					'ee_delete_registration',
724
+					'espresso_registrations_ee_delete_registrations',
725
+					$item->ID()
726
+				)
727
+			) {
728
+				$action['action']  = 'delete_registrations';
729
+				$delete_lnk_url    = EE_Admin_Page::add_query_args_and_nonce(
730
+					$action,
731
+					REG_ADMIN_URL
732
+				);
733
+				$actions['delete'] = '<a href="'
734
+									 . $delete_lnk_url
735
+									 . '" title="'
736
+									 . esc_attr__('Delete Registration Permanently', 'event_espresso')
737
+									 . '">'
738
+									 . esc_html__('Delete', 'event_espresso')
739
+									 . '</a>';
740
+			}
741
+		}
742
+		return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
743
+	}
744 744
 
745 745
 
746
-    /**
747
-     * @param EE_Registration $item
748
-     * @return string
749
-     * @throws EE_Error
750
-     * @throws InvalidArgumentException
751
-     * @throws InvalidDataTypeException
752
-     * @throws InvalidInterfaceException
753
-     * @throws ReflectionException
754
-     */
755
-    public function column_ATT_email(EE_Registration $item)
756
-    {
757
-        $attendee = $item->get_first_related('Attendee');
758
-        return ! $attendee instanceof EE_Attendee
759
-            ? esc_html__('No attached contact record.', 'event_espresso')
760
-            : $attendee->email();
761
-    }
746
+	/**
747
+	 * @param EE_Registration $item
748
+	 * @return string
749
+	 * @throws EE_Error
750
+	 * @throws InvalidArgumentException
751
+	 * @throws InvalidDataTypeException
752
+	 * @throws InvalidInterfaceException
753
+	 * @throws ReflectionException
754
+	 */
755
+	public function column_ATT_email(EE_Registration $item)
756
+	{
757
+		$attendee = $item->get_first_related('Attendee');
758
+		return ! $attendee instanceof EE_Attendee
759
+			? esc_html__('No attached contact record.', 'event_espresso')
760
+			: $attendee->email();
761
+	}
762 762
 
763 763
 
764
-    /**
765
-     * @param EE_Registration $item
766
-     * @return string
767
-     */
768
-    public function column__REG_count(EE_Registration $item)
769
-    {
770
-        return sprintf(esc_html__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
771
-    }
764
+	/**
765
+	 * @param EE_Registration $item
766
+	 * @return string
767
+	 */
768
+	public function column__REG_count(EE_Registration $item)
769
+	{
770
+		return sprintf(esc_html__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
771
+	}
772 772
 
773 773
 
774
-    /**
775
-     * @param EE_Registration $item
776
-     * @return string
777
-     * @throws EE_Error
778
-     * @throws ReflectionException
779
-     */
780
-    public function column_PRC_amount(EE_Registration $item)
781
-    {
782
-        $ticket   = $item->ticket();
783
-        $req_data = $this->_admin_page->get_request_data();
784
-        $content  = isset($req_data['event_id']) && $ticket instanceof EE_Ticket
785
-            ? '<span class="TKT_name">' . $ticket->name() . '</span><br />'
786
-            : '';
787
-        if ($item->final_price() > 0) {
788
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
789
-        } else {
790
-            // free event
791
-            $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
792
-                        . esc_html__('free', 'event_espresso')
793
-                        . '</span>';
794
-        }
795
-        return $content;
796
-    }
774
+	/**
775
+	 * @param EE_Registration $item
776
+	 * @return string
777
+	 * @throws EE_Error
778
+	 * @throws ReflectionException
779
+	 */
780
+	public function column_PRC_amount(EE_Registration $item)
781
+	{
782
+		$ticket   = $item->ticket();
783
+		$req_data = $this->_admin_page->get_request_data();
784
+		$content  = isset($req_data['event_id']) && $ticket instanceof EE_Ticket
785
+			? '<span class="TKT_name">' . $ticket->name() . '</span><br />'
786
+			: '';
787
+		if ($item->final_price() > 0) {
788
+			$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
789
+		} else {
790
+			// free event
791
+			$content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
792
+						. esc_html__('free', 'event_espresso')
793
+						. '</span>';
794
+		}
795
+		return $content;
796
+	}
797 797
 
798 798
 
799
-    /**
800
-     * @param EE_Registration $item
801
-     * @return string
802
-     * @throws EE_Error
803
-     * @throws ReflectionException
804
-     */
805
-    public function column__REG_final_price(EE_Registration $item)
806
-    {
807
-        $ticket   = $item->ticket();
808
-        $req_data = $this->_admin_page->get_request_data();
809
-        $content  = isset($req_data['event_id']) || ! $ticket instanceof EE_Ticket
810
-            ? ''
811
-            : '<span class="TKT_name">' . $ticket->name() . '</span><br />';
812
-        $content  .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
813
-        return $content;
814
-    }
799
+	/**
800
+	 * @param EE_Registration $item
801
+	 * @return string
802
+	 * @throws EE_Error
803
+	 * @throws ReflectionException
804
+	 */
805
+	public function column__REG_final_price(EE_Registration $item)
806
+	{
807
+		$ticket   = $item->ticket();
808
+		$req_data = $this->_admin_page->get_request_data();
809
+		$content  = isset($req_data['event_id']) || ! $ticket instanceof EE_Ticket
810
+			? ''
811
+			: '<span class="TKT_name">' . $ticket->name() . '</span><br />';
812
+		$content  .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
813
+		return $content;
814
+	}
815 815
 
816 816
 
817
-    /**
818
-     * @param EE_Registration $item
819
-     * @return string
820
-     * @throws EE_Error
821
-     */
822
-    public function column__REG_paid(EE_Registration $item)
823
-    {
824
-        $payment_method      = $item->payment_method();
825
-        $payment_method_name = $payment_method instanceof EE_Payment_Method
826
-            ? $payment_method->admin_name()
827
-            : esc_html__('Unknown', 'event_espresso');
828
-        $content             = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
829
-        if ($item->paid() > 0) {
830
-            $content .= '<br><span class="ee-status-text-small">'
831
-                        . sprintf(
832
-                            esc_html__('...via %s', 'event_espresso'),
833
-                            $payment_method_name
834
-                        )
835
-                        . '</span>';
836
-        }
837
-        return $content;
838
-    }
817
+	/**
818
+	 * @param EE_Registration $item
819
+	 * @return string
820
+	 * @throws EE_Error
821
+	 */
822
+	public function column__REG_paid(EE_Registration $item)
823
+	{
824
+		$payment_method      = $item->payment_method();
825
+		$payment_method_name = $payment_method instanceof EE_Payment_Method
826
+			? $payment_method->admin_name()
827
+			: esc_html__('Unknown', 'event_espresso');
828
+		$content             = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
829
+		if ($item->paid() > 0) {
830
+			$content .= '<br><span class="ee-status-text-small">'
831
+						. sprintf(
832
+							esc_html__('...via %s', 'event_espresso'),
833
+							$payment_method_name
834
+						)
835
+						. '</span>';
836
+		}
837
+		return $content;
838
+	}
839 839
 
840 840
 
841
-    /**
842
-     * @param EE_Registration $item
843
-     * @return string
844
-     * @throws EE_Error
845
-     * @throws EntityNotFoundException
846
-     * @throws InvalidArgumentException
847
-     * @throws InvalidDataTypeException
848
-     * @throws InvalidInterfaceException
849
-     * @throws ReflectionException
850
-     */
851
-    public function column_TXN_total(EE_Registration $item)
852
-    {
853
-        if ($item->transaction()) {
854
-            $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
855
-                [
856
-                    'action' => 'view_transaction',
857
-                    'TXN_ID' => $item->transaction_ID(),
858
-                ],
859
-                TXN_ADMIN_URL
860
-            );
861
-            return EE_Registry::instance()->CAP->current_user_can(
862
-                'ee_read_transaction',
863
-                'espresso_transactions_view_transaction',
864
-                $item->transaction_ID()
865
-            )
866
-                ? '<span class="reg-pad-rght"><a class="status-'
867
-                  . $item->transaction()->status_ID()
868
-                  . '" href="'
869
-                  . $view_txn_lnk_url
870
-                  . '"  title="'
871
-                  . esc_attr__('View Transaction', 'event_espresso')
872
-                  . '">'
873
-                  . $item->transaction()->pretty_total()
874
-                  . '</a></span>'
875
-                : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
876
-        } else {
877
-            return esc_html__("None", "event_espresso");
878
-        }
879
-    }
841
+	/**
842
+	 * @param EE_Registration $item
843
+	 * @return string
844
+	 * @throws EE_Error
845
+	 * @throws EntityNotFoundException
846
+	 * @throws InvalidArgumentException
847
+	 * @throws InvalidDataTypeException
848
+	 * @throws InvalidInterfaceException
849
+	 * @throws ReflectionException
850
+	 */
851
+	public function column_TXN_total(EE_Registration $item)
852
+	{
853
+		if ($item->transaction()) {
854
+			$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
855
+				[
856
+					'action' => 'view_transaction',
857
+					'TXN_ID' => $item->transaction_ID(),
858
+				],
859
+				TXN_ADMIN_URL
860
+			);
861
+			return EE_Registry::instance()->CAP->current_user_can(
862
+				'ee_read_transaction',
863
+				'espresso_transactions_view_transaction',
864
+				$item->transaction_ID()
865
+			)
866
+				? '<span class="reg-pad-rght"><a class="status-'
867
+				  . $item->transaction()->status_ID()
868
+				  . '" href="'
869
+				  . $view_txn_lnk_url
870
+				  . '"  title="'
871
+				  . esc_attr__('View Transaction', 'event_espresso')
872
+				  . '">'
873
+				  . $item->transaction()->pretty_total()
874
+				  . '</a></span>'
875
+				: '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
876
+		} else {
877
+			return esc_html__("None", "event_espresso");
878
+		}
879
+	}
880 880
 
881 881
 
882
-    /**
883
-     * @param EE_Registration $item
884
-     * @return string
885
-     * @throws EE_Error
886
-     * @throws EntityNotFoundException
887
-     * @throws InvalidArgumentException
888
-     * @throws InvalidDataTypeException
889
-     * @throws InvalidInterfaceException
890
-     * @throws ReflectionException
891
-     */
892
-    public function column_TXN_paid(EE_Registration $item)
893
-    {
894
-        if ($item->count() === 1) {
895
-            $transaction = $item->transaction()
896
-                ? $item->transaction()
897
-                : EE_Transaction::new_instance();
898
-            if ($transaction->paid() >= $transaction->total()) {
899
-                return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
900
-            } else {
901
-                $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
902
-                    [
903
-                        'action' => 'view_transaction',
904
-                        'TXN_ID' => $item->transaction_ID(),
905
-                    ],
906
-                    TXN_ADMIN_URL
907
-                );
908
-                return EE_Registry::instance()->CAP->current_user_can(
909
-                    'ee_read_transaction',
910
-                    'espresso_transactions_view_transaction',
911
-                    $item->transaction_ID()
912
-                )
913
-                    ? '<span class="reg-pad-rght"><a class="status-'
914
-                      . $transaction->status_ID()
915
-                      . '" href="'
916
-                      . $view_txn_lnk_url
917
-                      . '"  title="'
918
-                      . esc_attr__('View Transaction', 'event_espresso')
919
-                      . '">'
920
-                      . $item->transaction()->pretty_paid()
921
-                      . '</a><span>'
922
-                    : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
923
-            }
924
-        }
925
-        return '&nbsp;';
926
-    }
882
+	/**
883
+	 * @param EE_Registration $item
884
+	 * @return string
885
+	 * @throws EE_Error
886
+	 * @throws EntityNotFoundException
887
+	 * @throws InvalidArgumentException
888
+	 * @throws InvalidDataTypeException
889
+	 * @throws InvalidInterfaceException
890
+	 * @throws ReflectionException
891
+	 */
892
+	public function column_TXN_paid(EE_Registration $item)
893
+	{
894
+		if ($item->count() === 1) {
895
+			$transaction = $item->transaction()
896
+				? $item->transaction()
897
+				: EE_Transaction::new_instance();
898
+			if ($transaction->paid() >= $transaction->total()) {
899
+				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
900
+			} else {
901
+				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
902
+					[
903
+						'action' => 'view_transaction',
904
+						'TXN_ID' => $item->transaction_ID(),
905
+					],
906
+					TXN_ADMIN_URL
907
+				);
908
+				return EE_Registry::instance()->CAP->current_user_can(
909
+					'ee_read_transaction',
910
+					'espresso_transactions_view_transaction',
911
+					$item->transaction_ID()
912
+				)
913
+					? '<span class="reg-pad-rght"><a class="status-'
914
+					  . $transaction->status_ID()
915
+					  . '" href="'
916
+					  . $view_txn_lnk_url
917
+					  . '"  title="'
918
+					  . esc_attr__('View Transaction', 'event_espresso')
919
+					  . '">'
920
+					  . $item->transaction()->pretty_paid()
921
+					  . '</a><span>'
922
+					: '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
923
+			}
924
+		}
925
+		return '&nbsp;';
926
+	}
927 927
 
928 928
 
929
-    /**
930
-     * column_actions
931
-     *
932
-     * @param EE_Registration $item
933
-     * @return string
934
-     * @throws EE_Error
935
-     * @throws InvalidArgumentException
936
-     * @throws InvalidDataTypeException
937
-     * @throws InvalidInterfaceException
938
-     * @throws ReflectionException
939
-     */
940
-    public function column_actions(EE_Registration $item)
941
-    {
942
-        $actions  = [];
943
-        $attendee = $item->attendee();
944
-        $this->_set_related_details($item);
945
-        // Build row actions
946
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
947
-            [
948
-                'action'  => 'view_registration',
949
-                '_REG_ID' => $item->ID(),
950
-            ],
951
-            REG_ADMIN_URL
952
-        );
953
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
954
-            [
955
-                'action' => 'edit_attendee',
956
-                'post'   => $item->attendee_ID(),
957
-            ],
958
-            REG_ADMIN_URL
959
-        );
960
-        // page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
961
-        // $resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
962
-        $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
963
-            [
964
-                'action'  => 'resend_registration',
965
-                '_REG_ID' => $item->ID(),
966
-            ],
967
-            REG_ADMIN_URL,
968
-            true
969
-        );
970
-        // Build row actions
971
-        $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can(
972
-            'ee_read_registration',
973
-            'espresso_registrations_view_registration',
974
-            $item->ID()
975
-        )
976
-            ? '<li><a href="'
977
-              . $view_lnk_url
978
-              . '" title="'
979
-              . esc_attr__('View Registration Details', 'event_espresso')
980
-              . '" class="tiny-text">
929
+	/**
930
+	 * column_actions
931
+	 *
932
+	 * @param EE_Registration $item
933
+	 * @return string
934
+	 * @throws EE_Error
935
+	 * @throws InvalidArgumentException
936
+	 * @throws InvalidDataTypeException
937
+	 * @throws InvalidInterfaceException
938
+	 * @throws ReflectionException
939
+	 */
940
+	public function column_actions(EE_Registration $item)
941
+	{
942
+		$actions  = [];
943
+		$attendee = $item->attendee();
944
+		$this->_set_related_details($item);
945
+		// Build row actions
946
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
947
+			[
948
+				'action'  => 'view_registration',
949
+				'_REG_ID' => $item->ID(),
950
+			],
951
+			REG_ADMIN_URL
952
+		);
953
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
954
+			[
955
+				'action' => 'edit_attendee',
956
+				'post'   => $item->attendee_ID(),
957
+			],
958
+			REG_ADMIN_URL
959
+		);
960
+		// page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
961
+		// $resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
962
+		$resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
963
+			[
964
+				'action'  => 'resend_registration',
965
+				'_REG_ID' => $item->ID(),
966
+			],
967
+			REG_ADMIN_URL,
968
+			true
969
+		);
970
+		// Build row actions
971
+		$actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can(
972
+			'ee_read_registration',
973
+			'espresso_registrations_view_registration',
974
+			$item->ID()
975
+		)
976
+			? '<li><a href="'
977
+			  . $view_lnk_url
978
+			  . '" title="'
979
+			  . esc_attr__('View Registration Details', 'event_espresso')
980
+			  . '" class="tiny-text">
981 981
 				<div class="dashicons dashicons-clipboard"></div>
982 982
 			</a>
983 983
 			</li>'
984
-            : '';
985
-        $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can(
986
-            'ee_edit_contacts',
987
-            'espresso_registrations_edit_attendee'
988
-        )
989
-                               && $attendee instanceof EE_Attendee
990
-            ? '
984
+			: '';
985
+		$actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can(
986
+			'ee_edit_contacts',
987
+			'espresso_registrations_edit_attendee'
988
+		)
989
+							   && $attendee instanceof EE_Attendee
990
+			? '
991 991
 			<li>
992 992
 			<a href="' . $edit_lnk_url . '" title="'
993
-              . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
993
+			  . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
994 994
 				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
995 995
 			</a>
996 996
 			</li>'
997
-            : '';
997
+			: '';
998 998
 
999
-        $actions['resend_reg_lnk'] = '';
1000
-        if (
1001
-            $attendee instanceof EE_Attendee
1002
-            && EE_Registry::instance()->CAP->current_user_can(
1003
-                'ee_send_message',
1004
-                'espresso_registrations_resend_registration',
1005
-                $item->ID()
1006
-            )
1007
-        ) {
1008
-            $actions['resend_reg_lnk'] = '<li>';
1009
-            $actions['resend_reg_lnk'] .= '<a href="' . $resend_reg_lnk_url;
1010
-            $actions['resend_reg_lnk'] .= '" title="';
1011
-            $actions['resend_reg_lnk'] .= esc_attr__('Resend Registration Details', 'event_espresso');
1012
-            $actions['resend_reg_lnk'] .= '" class="tiny-text">';
1013
-            $actions['resend_reg_lnk'] .= '<div class="dashicons dashicons-email-alt"></div>';
1014
-            $actions['resend_reg_lnk'] .= '</a>';
1015
-            $actions['resend_reg_lnk'] .= '</li>';
1016
-        }
1017
-        // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
1018
-        $view_txn_lnk_url        = EE_Admin_Page::add_query_args_and_nonce(
1019
-            [
1020
-                'action' => 'view_transaction',
1021
-                'TXN_ID' => $this->_transaction_details['id'],
1022
-            ],
1023
-            TXN_ADMIN_URL
1024
-        );
1025
-        $actions['view_txn_lnk'] = '';
1026
-        if (
1027
-            EE_Registry::instance()->CAP->current_user_can(
1028
-                'ee_read_transaction',
1029
-                'espresso_transactions_view_transaction',
1030
-                $this->_transaction_details['id']
1031
-            )
1032
-        ) {
1033
-            $actions['view_txn_lnk'] = '
999
+		$actions['resend_reg_lnk'] = '';
1000
+		if (
1001
+			$attendee instanceof EE_Attendee
1002
+			&& EE_Registry::instance()->CAP->current_user_can(
1003
+				'ee_send_message',
1004
+				'espresso_registrations_resend_registration',
1005
+				$item->ID()
1006
+			)
1007
+		) {
1008
+			$actions['resend_reg_lnk'] = '<li>';
1009
+			$actions['resend_reg_lnk'] .= '<a href="' . $resend_reg_lnk_url;
1010
+			$actions['resend_reg_lnk'] .= '" title="';
1011
+			$actions['resend_reg_lnk'] .= esc_attr__('Resend Registration Details', 'event_espresso');
1012
+			$actions['resend_reg_lnk'] .= '" class="tiny-text">';
1013
+			$actions['resend_reg_lnk'] .= '<div class="dashicons dashicons-email-alt"></div>';
1014
+			$actions['resend_reg_lnk'] .= '</a>';
1015
+			$actions['resend_reg_lnk'] .= '</li>';
1016
+		}
1017
+		// page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
1018
+		$view_txn_lnk_url        = EE_Admin_Page::add_query_args_and_nonce(
1019
+			[
1020
+				'action' => 'view_transaction',
1021
+				'TXN_ID' => $this->_transaction_details['id'],
1022
+			],
1023
+			TXN_ADMIN_URL
1024
+		);
1025
+		$actions['view_txn_lnk'] = '';
1026
+		if (
1027
+			EE_Registry::instance()->CAP->current_user_can(
1028
+				'ee_read_transaction',
1029
+				'espresso_transactions_view_transaction',
1030
+				$this->_transaction_details['id']
1031
+			)
1032
+		) {
1033
+			$actions['view_txn_lnk'] = '
1034 1034
 			<li>
1035 1035
 			<a class="ee-status-color-'
1036
-                                       . $this->_transaction_details['status']
1037
-                                       . ' tiny-text" href="'
1038
-                                       . $view_txn_lnk_url
1039
-                                       . '"  title="'
1040
-                                       . $this->_transaction_details['title_attr']
1041
-                                       . '">
1036
+									   . $this->_transaction_details['status']
1037
+									   . ' tiny-text" href="'
1038
+									   . $view_txn_lnk_url
1039
+									   . '"  title="'
1040
+									   . $this->_transaction_details['title_attr']
1041
+									   . '">
1042 1042
 				<div class="dashicons dashicons-cart"></div>
1043 1043
 			</a>
1044 1044
 			</li>';
1045
-        }
1046
-        // invoice link
1047
-        $actions['dl_invoice_lnk'] = '';
1048
-        $dl_invoice_lnk_url        = $item->invoice_url();
1049
-        // only show invoice link if message type is active.
1050
-        if (
1051
-            $attendee instanceof EE_Attendee
1052
-            && $item->is_primary_registrant()
1053
-            && EEH_MSG_Template::is_mt_active('invoice')
1054
-        ) {
1055
-            $actions['dl_invoice_lnk'] = '
1045
+		}
1046
+		// invoice link
1047
+		$actions['dl_invoice_lnk'] = '';
1048
+		$dl_invoice_lnk_url        = $item->invoice_url();
1049
+		// only show invoice link if message type is active.
1050
+		if (
1051
+			$attendee instanceof EE_Attendee
1052
+			&& $item->is_primary_registrant()
1053
+			&& EEH_MSG_Template::is_mt_active('invoice')
1054
+		) {
1055
+			$actions['dl_invoice_lnk'] = '
1056 1056
 		<li>
1057 1057
 			<a title="' . esc_attr__('View Transaction Invoice', 'event_espresso')
1058
-                                         . '" target="_blank" href="'
1059
-                                         . $dl_invoice_lnk_url
1060
-                                         . '" class="tiny-text">
1058
+										 . '" target="_blank" href="'
1059
+										 . $dl_invoice_lnk_url
1060
+										 . '" class="tiny-text">
1061 1061
 				<span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
1062 1062
 			</a>
1063 1063
 		</li>';
1064
-        }
1065
-        $actions['filtered_messages_link'] = '';
1066
-        // message list table link (filtered by REG_ID
1067
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
1068
-            $actions['filtered_messages_link'] = '<li>';
1069
-            $actions['filtered_messages_link'] .= EEH_MSG_Template::get_message_action_link(
1070
-                'see_notifications_for',
1071
-                null,
1072
-                ['_REG_ID' => $item->ID()]
1073
-            );
1074
-            $actions['filtered_messages_link'] .= '</li>';
1075
-        }
1076
-        $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1077
-        return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1078
-    }
1064
+		}
1065
+		$actions['filtered_messages_link'] = '';
1066
+		// message list table link (filtered by REG_ID
1067
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
1068
+			$actions['filtered_messages_link'] = '<li>';
1069
+			$actions['filtered_messages_link'] .= EEH_MSG_Template::get_message_action_link(
1070
+				'see_notifications_for',
1071
+				null,
1072
+				['_REG_ID' => $item->ID()]
1073
+			);
1074
+			$actions['filtered_messages_link'] .= '</li>';
1075
+		}
1076
+		$actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1077
+		return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1078
+	}
1079 1079
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
     public function __construct(Registrations_Admin_Page $admin_page)
49 49
     {
50 50
         $req_data = $admin_page->get_request_data();
51
-        if (! empty($req_data['event_id'])) {
51
+        if ( ! empty($req_data['event_id'])) {
52 52
             $extra_query_args = [];
53 53
             foreach ($admin_page->get_views() as $view_details) {
54
-                $extra_query_args[ $view_details['slug'] ] = ['event_id' => $req_data['event_id']];
54
+                $extra_query_args[$view_details['slug']] = ['event_id' => $req_data['event_id']];
55 55
             }
56 56
             $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
57 57
         }
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
             'ajax'     => true,
84 84
             'screen'   => $this->_admin_page->get_current_screen()->id,
85 85
         ];
86
-        $ID_column_name      = esc_html__('ID', 'event_espresso');
86
+        $ID_column_name = esc_html__('ID', 'event_espresso');
87 87
         $ID_column_name      .= ' : <span class="show-on-mobile-view-only" style="float:none">';
88 88
         $ID_column_name      .= esc_html__('Registrant Name', 'event_espresso');
89 89
         $ID_column_name      .= '</span> ';
90
-        $req_data            = $this->_admin_page->get_request_data();
90
+        $req_data = $this->_admin_page->get_request_data();
91 91
         if (isset($req_data['event_id'])) {
92
-            $this->_columns        = [
92
+            $this->_columns = [
93 93
                 'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
94 94
                 '_REG_ID'          => $ID_column_name,
95 95
                 'ATT_fname'        => esc_html__('Name', 'event_espresso'),
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
                 ],
114 114
             ];
115 115
         } else {
116
-            $this->_columns        = [
116
+            $this->_columns = [
117 117
                 'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
118 118
                 '_REG_ID'          => $ID_column_name,
119 119
                 'ATT_fname'        => esc_html__('Name', 'event_espresso'),
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
                 'return_url'  => $return_url,
141 141
             ],
142 142
         ];
143
-        $filters                                  = array_diff_key(
143
+        $filters = array_diff_key(
144 144
             $this->_req_data,
145 145
             array_flip(
146 146
                 [
@@ -150,12 +150,12 @@  discard block
 block discarded – undo
150 150
                 ]
151 151
             )
152 152
         );
153
-        if (! empty($filters)) {
153
+        if ( ! empty($filters)) {
154 154
             $this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
155 155
         }
156 156
         $this->_primary_column   = '_REG_ID';
157 157
         $this->_sortable_columns = [
158
-            '_REG_date'     => ['_REG_date' => true],   // true means its already sorted
158
+            '_REG_date'     => ['_REG_date' => true], // true means its already sorted
159 159
             /**
160 160
              * Allows users to change the default sort if they wish.
161 161
              * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
             'DTT_EVT_start' => ['DTT_EVT_start' => false],
173 173
             '_REG_ID'       => ['_REG_ID' => false],
174 174
         ];
175
-        $this->_hidden_columns   = [];
175
+        $this->_hidden_columns = [];
176 176
     }
177 177
 
178 178
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
     {
188 188
         $class = parent::_get_row_class($item);
189 189
         // add status class
190
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
190
+        $class .= ' ee-status-strip reg-status-'.$item->status_ID();
191 191
         if ($this->_has_checkbox_column) {
192 192
             $class .= ' has-checkbox-column';
193 193
         }
@@ -361,14 +361,14 @@  discard block
 block discarded – undo
361 361
         $this_month_r    = date('m', current_time('timestamp'));
362 362
         $days_this_month = date('t', current_time('timestamp'));
363 363
         // setup date query.
364
-        $beginning_string   = EEM_Registration::instance()->convert_datetime_for_query(
364
+        $beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
365 365
             'REG_date',
366
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
366
+            $this_year_r.'-'.$this_month_r.'-01'.' '.$time_start,
367 367
             'Y-m-d H:i:s'
368 368
         );
369
-        $end_string         = EEM_Registration::instance()->convert_datetime_for_query(
369
+        $end_string = EEM_Registration::instance()->convert_datetime_for_query(
370 370
             'REG_date',
371
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
371
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' '.$time_end,
372 372
             'Y-m-d H:i:s'
373 373
         );
374 374
         $_where['REG_date'] = [
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
                 $end_string,
379 379
             ],
380 380
         ];
381
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
381
+        $_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
382 382
         return EEM_Registration::instance()->count([$_where]);
383 383
     }
384 384
 
@@ -406,17 +406,17 @@  discard block
 block discarded – undo
406 406
             [
407 407
                 EEM_Registration::instance()->convert_datetime_for_query(
408 408
                     'REG_date',
409
-                    $current_date . $time_start,
409
+                    $current_date.$time_start,
410 410
                     'Y-m-d H:i:s'
411 411
                 ),
412 412
                 EEM_Registration::instance()->convert_datetime_for_query(
413 413
                     'REG_date',
414
-                    $current_date . $time_end,
414
+                    $current_date.$time_end,
415 415
                     'Y-m-d H:i:s'
416 416
                 ),
417 417
             ],
418 418
         ];
419
-        $_where['STS_ID']   = ['!=', EEM_Registration::status_id_incomplete];
419
+        $_where['STS_ID'] = ['!=', EEM_Registration::status_id_incomplete];
420 420
         return EEM_Registration::instance()->count([$_where]);
421 421
     }
422 422
 
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
             ],
500 500
             TXN_ADMIN_URL
501 501
         );
502
-        $view_link    = EE_Registry::instance()->CAP->current_user_can(
502
+        $view_link = EE_Registry::instance()->CAP->current_user_can(
503 503
             'ee_read_transaction',
504 504
             'espresso_transactions_view_transaction'
505 505
         )
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
               . $item->get_i18n_datetime('REG_date')
514 514
               . '</a>'
515 515
             : $item->get_i18n_datetime('REG_date');
516
-        $view_link    .= '<br><span class="ee-status-text-small">'
516
+        $view_link .= '<br><span class="ee-status-text-small">'
517 517
                          . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
518 518
                          . '</span>';
519 519
         return $view_link;
@@ -540,11 +540,11 @@  discard block
 block discarded – undo
540 540
                 ?: esc_html__("No Associated Event", 'event_espresso');
541 541
         $event_name = wp_trim_words($event_name, 30, '...');
542 542
         if ($EVT_ID) {
543
-            $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(
543
+            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
544 544
                 ['action' => 'edit', 'post' => $EVT_ID],
545 545
                 EVENTS_ADMIN_URL
546 546
             );
547
-            $edit_event              =
547
+            $edit_event =
548 548
                 EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
549 549
                     ? '<a class="ee-status-color-'
550 550
                       . $this->_event_details['status']
@@ -557,12 +557,12 @@  discard block
 block discarded – undo
557 557
                       . '</a>'
558 558
                     : $event_name;
559 559
             $edit_event_url          = EE_Admin_Page::add_query_args_and_nonce(['event_id' => $EVT_ID], REG_ADMIN_URL);
560
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
560
+            $actions['event_filter'] = '<a href="'.$edit_event_url.'" title="';
561 561
             $actions['event_filter'] .= sprintf(
562 562
                 esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
563 563
                 $event_name
564 564
             );
565
-            $actions['event_filter'] .= '">' . esc_html__('View Registrations', 'event_espresso') . '</a>';
565
+            $actions['event_filter'] .= '">'.esc_html__('View Registrations', 'event_espresso').'</a>';
566 566
         } else {
567 567
             $edit_event              = $event_name;
568 568
             $actions['event_filter'] = '';
@@ -606,11 +606,11 @@  discard block
 block discarded – undo
606 606
     {
607 607
         $content       = '<div class="ee-registration-event-datetimes-container">';
608 608
         $expand_toggle = count($datetime_strings) > 1
609
-            ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
609
+            ? ' <span title="'.esc_attr__('Click to view all dates', 'event_espresso')
610 610
               . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
611 611
             : '';
612 612
         // get first item for initial visibility
613
-        $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
613
+        $content .= '<div class="left">'.array_shift($datetime_strings).'</div>';
614 614
         $content .= $expand_toggle;
615 615
         if ($datetime_strings) {
616 616
             $content .= '<div style="clear:both"></div>';
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
               . $attendee_name
659 659
               . '</a>'
660 660
             : $attendee_name;
661
-        $link          .= $item->count() === 1
661
+        $link .= $item->count() === 1
662 662
             ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>'
663 663
             : '';
664 664
         $t             = $item->get_first_related('Transaction');
@@ -666,11 +666,11 @@  discard block
 block discarded – undo
666 666
             ? $t->count_related('Payment')
667 667
             : 0;
668 668
         // append group count to name
669
-        $link .= '&nbsp;' . sprintf(esc_html__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
669
+        $link .= '&nbsp;'.sprintf(esc_html__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
670 670
         // append reg_code
671
-        $link .= '<br>' . sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
671
+        $link .= '<br>'.sprintf(esc_html__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
672 672
         // reg status text for accessibility
673
-        $link   .= '<br><span class="ee-status-text-small">'
673
+        $link .= '<br><span class="ee-status-text-small">'
674 674
                    . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
675 675
                    . '</span>';
676 676
         $action = ['_REG_ID' => $item->ID()];
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
                                 . $trash_lnk_url
698 698
                                 . '" title="'
699 699
                                 . esc_attr__('Trash Registration', 'event_espresso')
700
-                                . '">' . esc_html__('Trash', 'event_espresso') . '</a>';
700
+                                . '">'.esc_html__('Trash', 'event_espresso').'</a>';
701 701
         } elseif ($this->_view === 'trash') {
702 702
             // restore registration link
703 703
             if (
@@ -715,8 +715,8 @@  discard block
 block discarded – undo
715 715
                 $actions['restore'] = '<a href="'
716 716
                                       . $restore_lnk_url
717 717
                                       . '" title="'
718
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
719
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
718
+                                      . esc_attr__('Restore Registration', 'event_espresso').'">'
719
+                                      . esc_html__('Restore', 'event_espresso').'</a>';
720 720
             }
721 721
             if (
722 722
                 EE_Registry::instance()->CAP->current_user_can(
@@ -782,10 +782,10 @@  discard block
 block discarded – undo
782 782
         $ticket   = $item->ticket();
783 783
         $req_data = $this->_admin_page->get_request_data();
784 784
         $content  = isset($req_data['event_id']) && $ticket instanceof EE_Ticket
785
-            ? '<span class="TKT_name">' . $ticket->name() . '</span><br />'
785
+            ? '<span class="TKT_name">'.$ticket->name().'</span><br />'
786 786
             : '';
787 787
         if ($item->final_price() > 0) {
788
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
788
+            $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
789 789
         } else {
790 790
             // free event
791 791
             $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
@@ -808,8 +808,8 @@  discard block
 block discarded – undo
808 808
         $req_data = $this->_admin_page->get_request_data();
809 809
         $content  = isset($req_data['event_id']) || ! $ticket instanceof EE_Ticket
810 810
             ? ''
811
-            : '<span class="TKT_name">' . $ticket->name() . '</span><br />';
812
-        $content  .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
811
+            : '<span class="TKT_name">'.$ticket->name().'</span><br />';
812
+        $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
813 813
         return $content;
814 814
     }
815 815
 
@@ -825,7 +825,7 @@  discard block
 block discarded – undo
825 825
         $payment_method_name = $payment_method instanceof EE_Payment_Method
826 826
             ? $payment_method->admin_name()
827 827
             : esc_html__('Unknown', 'event_espresso');
828
-        $content             = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
828
+        $content             = '<span class="reg-pad-rght">'.$item->pretty_paid().'</span>';
829 829
         if ($item->paid() > 0) {
830 830
             $content .= '<br><span class="ee-status-text-small">'
831 831
                         . sprintf(
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
                   . '">'
873 873
                   . $item->transaction()->pretty_total()
874 874
                   . '</a></span>'
875
-                : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
875
+                : '<span class="reg-pad-rght">'.$item->transaction()->pretty_total().'</span>';
876 876
         } else {
877 877
             return esc_html__("None", "event_espresso");
878 878
         }
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
                       . '">'
920 920
                       . $item->transaction()->pretty_paid()
921 921
                       . '</a><span>'
922
-                    : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
922
+                    : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>';
923 923
             }
924 924
         }
925 925
         return '&nbsp;';
@@ -989,8 +989,8 @@  discard block
 block discarded – undo
989 989
                                && $attendee instanceof EE_Attendee
990 990
             ? '
991 991
 			<li>
992
-			<a href="' . $edit_lnk_url . '" title="'
993
-              . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
992
+			<a href="' . $edit_lnk_url.'" title="'
993
+              . esc_attr__('Edit Contact Details', 'event_espresso').'" class="tiny-text">
994 994
 				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
995 995
 			</a>
996 996
 			</li>'
@@ -1006,7 +1006,7 @@  discard block
 block discarded – undo
1006 1006
             )
1007 1007
         ) {
1008 1008
             $actions['resend_reg_lnk'] = '<li>';
1009
-            $actions['resend_reg_lnk'] .= '<a href="' . $resend_reg_lnk_url;
1009
+            $actions['resend_reg_lnk'] .= '<a href="'.$resend_reg_lnk_url;
1010 1010
             $actions['resend_reg_lnk'] .= '" title="';
1011 1011
             $actions['resend_reg_lnk'] .= esc_attr__('Resend Registration Details', 'event_espresso');
1012 1012
             $actions['resend_reg_lnk'] .= '" class="tiny-text">';
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
             $actions['resend_reg_lnk'] .= '</li>';
1016 1016
         }
1017 1017
         // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
1018
-        $view_txn_lnk_url        = EE_Admin_Page::add_query_args_and_nonce(
1018
+        $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
1019 1019
             [
1020 1020
                 'action' => 'view_transaction',
1021 1021
                 'TXN_ID' => $this->_transaction_details['id'],
Please login to merge, or discard this patch.
modules/gateways/Invoice/lib/invoice_functions.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -13,36 +13,36 @@  discard block
 block discarded – undo
13 13
  */
14 14
 function espresso_invoice_template_files($class_file)
15 15
 {
16
-    $files = [];
17
-    // read our template dir and build an array of files
18
-    $directory_handle = opendir(dirname($class_file) . '/lib/templates/css/');
19
-    //if we managed to open the directory
20
-    if ($directory_handle) {
21
-        /** @var RequestInterface $request */
22
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
23
-        $skip = [
24
-            '.',
25
-            '..',
26
-            '.DS_Store',
27
-            '.svn',
28
-            'images',
29
-            'index.php',
30
-            'print',
31
-            basename($request->getServerParam('PHP_SELF')),
32
-        ];
33
-        // loop through all of the files
34
-        while (false !== ($fname = readdir($directory_handle))) {
35
-            // if the file is not this file, and does not start with a '.' or '..',
36
-            // then store it for later display
37
-            if (! in_array($fname, $skip, true)) {
38
-                $files[] = $fname;
39
-            }
40
-        }
41
-        // close the directory
42
-        closedir($directory_handle);
43
-    }
16
+	$files = [];
17
+	// read our template dir and build an array of files
18
+	$directory_handle = opendir(dirname($class_file) . '/lib/templates/css/');
19
+	//if we managed to open the directory
20
+	if ($directory_handle) {
21
+		/** @var RequestInterface $request */
22
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
23
+		$skip = [
24
+			'.',
25
+			'..',
26
+			'.DS_Store',
27
+			'.svn',
28
+			'images',
29
+			'index.php',
30
+			'print',
31
+			basename($request->getServerParam('PHP_SELF')),
32
+		];
33
+		// loop through all of the files
34
+		while (false !== ($fname = readdir($directory_handle))) {
35
+			// if the file is not this file, and does not start with a '.' or '..',
36
+			// then store it for later display
37
+			if (! in_array($fname, $skip, true)) {
38
+				$files[] = $fname;
39
+			}
40
+		}
41
+		// close the directory
42
+		closedir($directory_handle);
43
+	}
44 44
 
45
-    return $files;
45
+	return $files;
46 46
 }
47 47
 
48 48
 
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
  */
57 57
 function espresso_invoice_is_selected($input_item, $selected = '')
58 58
 {
59
-    if ($input_item === $selected) {
60
-        return 'selected="selected"';
61
-    }
62
-    return '';
59
+	if ($input_item === $selected) {
60
+		return 'selected="selected"';
61
+	}
62
+	return '';
63 63
 }
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 {
16 16
     $files = [];
17 17
     // read our template dir and build an array of files
18
-    $directory_handle = opendir(dirname($class_file) . '/lib/templates/css/');
18
+    $directory_handle = opendir(dirname($class_file).'/lib/templates/css/');
19 19
     //if we managed to open the directory
20 20
     if ($directory_handle) {
21 21
         /** @var RequestInterface $request */
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
         while (false !== ($fname = readdir($directory_handle))) {
35 35
             // if the file is not this file, and does not start with a '.' or '..',
36 36
             // then store it for later display
37
-            if (! in_array($fname, $skip, true)) {
37
+            if ( ! in_array($fname, $skip, true)) {
38 38
                 $files[] = $fname;
39 39
             }
40 40
         }
Please login to merge, or discard this patch.
modules/gateways/Invoice/lib/Invoice.class.php 2 patches
Indentation   +429 added lines, -429 removed lines patch added patch discarded remove patch
@@ -12,433 +12,433 @@
 block discarded – undo
12 12
 class Invoice
13 13
 {
14 14
 
15
-    /**
16
-     *
17
-     * @var EE_Registration
18
-     */
19
-    private $registration;
20
-
21
-    /**
22
-     *
23
-     * @var EE_Transaction
24
-     */
25
-    private $transaction;
26
-
27
-    /**
28
-     *
29
-     * @var EE_Payment_Method
30
-     */
31
-    private $invoice_payment_method;
32
-
33
-
34
-    /**
35
-     * Invoice constructor.
36
-     *
37
-     * @param int $url_link
38
-     * @throws EE_Error
39
-     * @throws ReflectionException
40
-     * @deprecated 4.9.13
41
-     */
42
-    public function __construct($url_link = 0)
43
-    {
44
-        EE_Error::doing_it_wrong(
45
-            __CLASS__,
46
-            esc_html__(
47
-                'This class has been deprecated and replaced by the new Messages library.',
48
-                'event_espresso'
49
-            ),
50
-            '4.9.12',
51
-            '5.0.0'
52
-        );
53
-        /** @var EEM_Registration $reg_model */
54
-        $reg_model = EE_Registry::instance()->load_model('Registration');
55
-        if ($this->registration = $reg_model->get_registration_for_reg_url_link($url_link)) {
56
-            $this->transaction = $this->registration->transaction();
57
-            EE_Config::instance()->gateway->payment_settings;
58
-            $this->invoice_payment_method = EEM_Payment_Method::instance()->get_one_of_type('Invoice');
59
-        } else {
60
-            EE_Error::add_error(
61
-                esc_html__(
62
-                    'Your request appears to be missing some required data, and no information for your transaction could be retrieved.',
63
-                    'event_espresso'
64
-                ),
65
-                __FILE__,
66
-                __FUNCTION__,
67
-                __LINE__
68
-            );
69
-        }
70
-    }
71
-
72
-
73
-    /**
74
-     * @param false $download
75
-     * @throws EE_Error
76
-     * @throws ReflectionException
77
-     */
78
-    public function send_invoice($download = false)
79
-    {
80
-        $template_args = [];
81
-        $EE            = EE_Registry::instance();
82
-        /** @var RequestInterface $request */
83
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
84
-        $theme   = $request->getRequestParam('theme', 0, 'int');
85
-        // allow the request to override the default theme defined in the invoice settings
86
-        $theme_requested = $theme > 0 && $theme < 8
87
-                ? $theme
88
-                : null;
89
-        $themes          = [
90
-            1 => "simple.css",
91
-            2 => "bauhaus.css",
92
-            3 => "ejs.css",
93
-            4 => "horizon.css",
94
-            5 => "lola.css",
95
-            6 => "tranquility.css",
96
-            7 => "union.css",
97
-        ];
98
-        // Get the CSS file
99
-        if (isset($themes[ $theme_requested ])) {
100
-            $template_args['invoice_css'] = $themes[ $theme_requested ];
101
-        } else {
102
-            $template_args['invoice_css'] = $this->invoice_payment_method->get_extra_meta(
103
-                'legacy_invoice_css',
104
-                true,
105
-                'simple.css'
106
-            );
107
-        }
108
-
109
-        if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) {
110
-            $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/';
111
-        } else {
112
-            $template_args['base_url'] = EE_GATEWAYS . '/Invoice/lib/templates/';
113
-        }
114
-        $primary_attendee = $this->transaction->primary_registration()->attendee();
115
-
116
-        $template_args['organization'] = $EE->CFG->organization->get_pretty('name');
117
-        $template_args['street']       = empty($EE->CFG->organization->address_2)
118
-                ? $EE->CFG->organization->get_pretty('address_1')
119
-                : $EE->CFG->organization->get_pretty('address_1')
120
-                  . '<br>'
121
-                  . $EE->CFG->organization->get_pretty('address_2');
122
-        $template_args['city']         = $EE->CFG->organization->get_pretty('city');
123
-        $template_args['state']        = EE_Registry::instance()->load_model('State')->get_one_by_ID(
124
-            $EE->CFG->organization->STA_ID
125
-        );
126
-        $template_args['country']      = EE_Registry::instance()->load_model('Country')->get_one_by_ID(
127
-            $EE->CFG->organization->CNT_ISO
128
-        );
129
-        $template_args['zip']          = $EE->CFG->organization->get_pretty('zip');
130
-        $template_args['email']        = $EE->CFG->organization->get_pretty('email');
131
-
132
-        $template_args['registration_code'] = $this->registration->reg_code();
133
-        $template_args['registration_date'] = $this->registration->date();
134
-        $template_args['name']              = $primary_attendee->full_name();
135
-        $template_args['attendee_address']  = $primary_attendee->address();
136
-        $template_args['attendee_address2'] = $primary_attendee->address2();
137
-        $template_args['attendee_city']     = $primary_attendee->city();
138
-        $attendee_state                     = $primary_attendee->state_obj();
139
-        if ($attendee_state) {
140
-            $attendee_state_name = $attendee_state->name();
141
-        } else {
142
-            $attendee_state_name = '';
143
-        }
144
-        $template_args['attendee_state'] = $attendee_state_name;
145
-        $template_args['attendee_zip']   = $primary_attendee->zip();
146
-
147
-        $template_args['ship_name']    = $template_args['name'];
148
-        $template_args['ship_address'] = $template_args['attendee_address'];
149
-        $template_args['ship_city']    = $template_args['attendee_city'];
150
-        $template_args['ship_state']   = $template_args['attendee_state'];
151
-        $template_args['ship_zip']     = $template_args['attendee_zip'];
152
-
153
-        $template_args['total_cost']                 = number_format($this->transaction->total(), 2, '.', '');
154
-        $template_args['transaction']                = $this->transaction;
155
-        $template_args['amount_pd']                  = $this->transaction->paid();
156
-        $template_args['amount_owed']                = $this->transaction->total() - $this->transaction->paid();
157
-        $template_args['payments']                   = $this->transaction->approved_payments();
158
-        $template_args['net_total']                  = '';
159
-        $template_args['edit_reg_info_url']          = $this->registration->edit_attendee_information_url();
160
-        $template_args['retry_payment_url']          = $this->registration->payment_overview_url();
161
-        $template_args['show_line_item_description'] = $this->check_if_any_line_items_have_a_description(
162
-            $this->transaction->total_line_item()
163
-        );
164
-        if ($template_args['amount_pd'] != $template_args['total_cost']) {
165
-            // $template_args['net_total'] = $this->espressoInvoiceTotals(
166
-            //      esc_html__('SubTotal', 'event_espresso'),
167
-            //      $this->transaction->total());
168
-            //      $this->session_data['cart']['REG']['sub_total']
169
-            // );
170
-            $tax_items = $this->transaction->tax_items();
171
-            if (! empty($tax_items)) {
172
-                foreach ($tax_items as $tax) {
173
-                    $template_args['net_total'] .= $this->espressoInvoiceTotals($tax->name(), $tax->total());
174
-                }
175
-            }
176
-
177
-            $difference = $template_args['amount_pd'] - $template_args['total_cost'];
178
-            if ($difference < 0) {
179
-                $text = esc_html__('Discount', 'event_espresso');
180
-            } else {
181
-                $text = esc_html__('Extra', 'event_espresso');
182
-            }
183
-            $template_args['discount'] = $this->espressoInvoiceTotals($text, $difference);
184
-        }
185
-
186
-        $template_args['currency_symbol']               = $EE->CFG->currency->sign;
187
-        $template_args['template_payment_instructions'] = wpautop(
188
-            stripslashes_deep(
189
-                html_entity_decode($this->invoice_payment_method->get_extra_meta('pdf_instructions', true), ENT_QUOTES)
190
-            )
191
-        );
192
-        $template_args['shameless_plug']                = apply_filters(
193
-            'FHEE_Invoice__send_invoice__shameless_plug',
194
-            true
195
-        );
196
-        $receipt = $request->getRequestParam('receipt');
197
-        if ($receipt) {
198
-            // receipt-specific stuff
199
-            $events_for_txn              = EEM_Event::instance()->get_all(
200
-                [['Registration.TXN_ID' => $this->transaction->ID()]]
201
-            );
202
-            $ticket_line_items_per_event = [];
203
-            $registrations_per_line_item = [];
204
-            $venues_for_events           = [];
205
-            foreach ($events_for_txn as $event_id => $event) {
206
-                $line_items_for_this_event                = EEM_Line_Item::instance()->get_all(
207
-                    [['Ticket.Datetime.EVT_ID' => $event_id, 'TXN_ID' => $this->transaction->ID()]]
208
-                );
209
-                $ticket_line_items_per_event[ $event_id ] = $line_items_for_this_event;
210
-                foreach ($line_items_for_this_event as $line_item_id => $line_item) {
211
-                    if (! $line_item instanceof EE_Line_Item) {
212
-                        continue;
213
-                    }
214
-                    $ticket                                       = $line_item->ticket();
215
-                    $registrations_for_this_ticket                = EEM_Registration::instance()->get_all(
216
-                        [['TKT_ID' => $ticket->ID(), 'TXN_ID' => $this->transaction->ID()]]
217
-                    );
218
-                    $registrations_per_line_item[ $line_item_id ] = $registrations_for_this_ticket;
219
-                }
220
-                if ($event instanceof EE_Event) {
221
-                    $venues_for_events += $event->venues();
222
-                }
223
-            }
224
-            $tax_total_line_item = EEM_Line_Item::instance()->get_one(
225
-                [['TXN_ID' => $this->transaction->ID(), 'LIN_type' => EEM_Line_Item::type_tax_sub_total]]
226
-            );
227
-            $questions_to_skip   = [
228
-                EEM_Attendee::system_question_fname,
229
-                EEM_Attendee::system_question_lname,
230
-                EEM_Attendee::system_question_email,
231
-            ];
232
-
233
-
234
-            $template_args['events_for_txn']              = $events_for_txn;
235
-            $template_args['ticket_line_items_per_event'] = $ticket_line_items_per_event;
236
-            $template_args['registrations_per_line_item'] = $registrations_per_line_item;
237
-            $template_args['venues_for_events']           = $venues_for_events;
238
-            $template_args['tax_total_line_item']         = $tax_total_line_item;
239
-            $template_args['questions_to_skip']           = $questions_to_skip;
240
-            // d($template_args);
241
-            $template_args['download_link'] = $this->registration->receipt_url('download');
242
-        } else {
243
-            // it's just an invoice we're accessing
244
-            $template_args['download_link'] = $this->registration->invoice_url('download');
245
-        }
246
-
247
-        // Get the HTML as an object
248
-        $templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
249
-        $template_header         = EEH_Template::locate_template(
250
-            $templates_relative_path . 'invoice_header.template.php',
251
-            $template_args
252
-        );
253
-        if ($receipt) {
254
-            $template_body = EEH_Template::locate_template(
255
-                $templates_relative_path . 'receipt_body.template.php',
256
-                $template_args
257
-            );
258
-        } else {
259
-            $template_body = EEH_Template::locate_template(
260
-                $templates_relative_path . 'invoice_body.template.php',
261
-                $template_args
262
-            );
263
-        }
264
-
265
-
266
-        $template_footer = EEH_Template::locate_template(
267
-            $templates_relative_path . 'invoice_footer.template.php',
268
-            $template_args
269
-        );
270
-
271
-        $copies = $request->getRequestParam('copies', 1, 'int');
272
-
273
-        $content = $this->espresso_replace_invoice_shortcodes($template_header);
274
-        for ($x = 1; $x <= $copies; $x++) {
275
-            $content .= $this->espresso_replace_invoice_shortcodes($template_body);
276
-        }
277
-        $content .= $this->espresso_replace_invoice_shortcodes($template_footer);
278
-
279
-        // Check if debugging or mobile is set
280
-        if ($request->getRequestParam('html')) {
281
-            echo $content;
282
-            exit(0);
283
-        }
284
-        $invoice_name = $template_args['organization'] . ' ';
285
-        $invoice_name .= esc_html__('Invoice #', 'event_espresso');
286
-        $invoice_name .= $template_args['registration_code'];
287
-        $invoice_name .= esc_html__(' for ', 'event_espresso') . $template_args['name'];
288
-        $invoice_name = str_replace(' ', '_', $invoice_name);
289
-        // Create the PDF
290
-        if ($request->requestParamIsSet('html')) {
291
-            echo $content;
292
-        } else {
293
-            // only load dompdf if nobody else has yet...
294
-            if (! class_exists('Dompdf\Dompdf')) {
295
-                require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php');
296
-                Dompdf\Autoloader::register();
297
-            }
298
-            $options = new Dompdf\Options();
299
-            $options->set('isRemoteEnabled', true);
300
-            $options->set('isJavascriptEnabled', false);
301
-            if (defined('DOMPDF_FONT_DIR')) {
302
-                $options->setFontDir(DOMPDF_FONT_DIR);
303
-                $options->setFontCache(DOMPDF_FONT_DIR);
304
-            }
305
-            $dompdf = new Dompdf\Dompdf($options);
306
-            $dompdf->loadHtml($content);
307
-            $dompdf->render();
308
-            $dompdf->stream($invoice_name . ".pdf", ['Attachment' => $download]);
309
-        }
310
-        exit(0);
311
-    }
312
-
313
-
314
-    /**
315
-     * Checks if this line item, or any of its children, actually has a description.
316
-     * If none do, then the template can decide to not show any description column
317
-     *
318
-     * @param EE_Line_Item $line_item
319
-     * @return boolean
320
-     * @throws EE_Error
321
-     * @throws ReflectionException
322
-     */
323
-    public function check_if_any_line_items_have_a_description(EE_Line_Item $line_item)
324
-    {
325
-        if ($line_item->desc()) {
326
-            return true;
327
-        } else {
328
-            foreach ($line_item->children() as $child_line_item) {
329
-                if ($this->check_if_any_line_items_have_a_description($child_line_item)) {
330
-                    return true;
331
-                }
332
-            }
333
-            // well, if I and my children don't have descriptions, I guess not
334
-            return false;
335
-        }
336
-    }
337
-
338
-
339
-    /**
340
-     * Perform the shortcode replacement
341
-     *
342
-     * @param $content
343
-     * @return array|string|string[]
344
-     * @throws EE_Error
345
-     * @throws ReflectionException
346
-     */
347
-    public function espresso_replace_invoice_shortcodes($content)
348
-    {
349
-
350
-        $EE = EE_Registry::instance();
351
-        // Create the logo
352
-        $invoice_logo_url = $this->invoice_payment_method->get_extra_meta(
353
-            'pdf_logo_image',
354
-            true,
355
-            $EE->CFG->organization->logo_url
356
-        );
357
-        if (! empty($invoice_logo_url)) {
358
-            $image_size         = getimagesize($invoice_logo_url);
359
-            $invoice_logo_image =
360
-                '<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> ';
361
-        } else {
362
-            $invoice_logo_image = '';
363
-        }
364
-        $SearchValues     = [
365
-            "[organization]",
366
-            "[registration_code]",
367
-            "[transaction_id]",
368
-            "[name]",
369
-            "[base_url]",
370
-            "[download_link]",
371
-            "[invoice_logo_image]",
372
-            "[street]",
373
-            "[city]",
374
-            "[state]",
375
-            "[zip]",
376
-            "[email]",
377
-            "[vat]",
378
-            "[registration_date]",
379
-            "[instructions]",
380
-        ];
381
-        $primary_attendee = $this->transaction->primary_registration()->attendee();
382
-        $org_state        = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID);
383
-        if ($org_state) {
384
-            $org_state_name = $org_state->name();
385
-        } else {
386
-            $org_state_name = '';
387
-        }
388
-        $ReplaceValues = [
389
-            $EE->CFG->organization->get_pretty('name'),
390
-            $this->registration->reg_code(),
391
-            $this->transaction->ID(),
392
-            $primary_attendee->full_name(),
393
-            (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice'))
394
-                ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/'
395
-                : EE_GATEWAYS_URL . 'Invoice/lib/templates/',
396
-            $this->registration->invoice_url(),
397
-            // home_url() . '/?download_invoice=true&amp;id=' . $this->registration->reg_url_link(),
398
-            $invoice_logo_image,
399
-            empty($EE->CFG->organization->address_2)
400
-                ? $EE->CFG->organization->get_pretty('address_1')
401
-                : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty(
402
-                    'address_2'
403
-                ),
404
-            $EE->CFG->organization->get_pretty('city'),
405
-            $org_state_name,
406
-            $EE->CFG->organization->get_pretty('zip'),
407
-            $EE->CFG->organization->get_pretty('email'),
408
-            $EE->CFG->organization->vat,
409
-            $this->registration->get_i18n_datetime('REG_date', get_option('date_format')),
410
-            $this->invoice_payment_method->get_extra_meta('pdf_instructions', true),
411
-        ];
412
-
413
-        return str_replace($SearchValues, $ReplaceValues, $content);
414
-    }
415
-
416
-
417
-    public function espressoLoadData($items)
418
-    {
419
-        $lines = $items;
420
-        $data  = [];
421
-        foreach ($lines as $line) {
422
-            $data[] = explode(';', chop($line));
423
-        }
424
-
425
-        return $data;
426
-    }
427
-
428
-
429
-    public function espressoInvoiceTotals($text, $total_cost)
430
-    {
431
-        $html = '';
432
-        if ($total_cost < 0) {
433
-            $total_cost = (-1) * $total_cost;
434
-        }
435
-        $find    = [' '];
436
-        $replace = ['-'];
437
-        $row_id  = strtolower(str_replace($find, $replace, $text));
438
-        $html    .= '<tr id="' . $row_id . '-tr"><td colspan="4">&nbsp;</td>';
439
-        $html    .= '<td class="item_r">' . $text . '</td>';
440
-        $html    .= '<td class="item_r">' . $total_cost . '</td>';
441
-        $html    .= '</tr>';
442
-        return $html;
443
-    }
15
+	/**
16
+	 *
17
+	 * @var EE_Registration
18
+	 */
19
+	private $registration;
20
+
21
+	/**
22
+	 *
23
+	 * @var EE_Transaction
24
+	 */
25
+	private $transaction;
26
+
27
+	/**
28
+	 *
29
+	 * @var EE_Payment_Method
30
+	 */
31
+	private $invoice_payment_method;
32
+
33
+
34
+	/**
35
+	 * Invoice constructor.
36
+	 *
37
+	 * @param int $url_link
38
+	 * @throws EE_Error
39
+	 * @throws ReflectionException
40
+	 * @deprecated 4.9.13
41
+	 */
42
+	public function __construct($url_link = 0)
43
+	{
44
+		EE_Error::doing_it_wrong(
45
+			__CLASS__,
46
+			esc_html__(
47
+				'This class has been deprecated and replaced by the new Messages library.',
48
+				'event_espresso'
49
+			),
50
+			'4.9.12',
51
+			'5.0.0'
52
+		);
53
+		/** @var EEM_Registration $reg_model */
54
+		$reg_model = EE_Registry::instance()->load_model('Registration');
55
+		if ($this->registration = $reg_model->get_registration_for_reg_url_link($url_link)) {
56
+			$this->transaction = $this->registration->transaction();
57
+			EE_Config::instance()->gateway->payment_settings;
58
+			$this->invoice_payment_method = EEM_Payment_Method::instance()->get_one_of_type('Invoice');
59
+		} else {
60
+			EE_Error::add_error(
61
+				esc_html__(
62
+					'Your request appears to be missing some required data, and no information for your transaction could be retrieved.',
63
+					'event_espresso'
64
+				),
65
+				__FILE__,
66
+				__FUNCTION__,
67
+				__LINE__
68
+			);
69
+		}
70
+	}
71
+
72
+
73
+	/**
74
+	 * @param false $download
75
+	 * @throws EE_Error
76
+	 * @throws ReflectionException
77
+	 */
78
+	public function send_invoice($download = false)
79
+	{
80
+		$template_args = [];
81
+		$EE            = EE_Registry::instance();
82
+		/** @var RequestInterface $request */
83
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
84
+		$theme   = $request->getRequestParam('theme', 0, 'int');
85
+		// allow the request to override the default theme defined in the invoice settings
86
+		$theme_requested = $theme > 0 && $theme < 8
87
+				? $theme
88
+				: null;
89
+		$themes          = [
90
+			1 => "simple.css",
91
+			2 => "bauhaus.css",
92
+			3 => "ejs.css",
93
+			4 => "horizon.css",
94
+			5 => "lola.css",
95
+			6 => "tranquility.css",
96
+			7 => "union.css",
97
+		];
98
+		// Get the CSS file
99
+		if (isset($themes[ $theme_requested ])) {
100
+			$template_args['invoice_css'] = $themes[ $theme_requested ];
101
+		} else {
102
+			$template_args['invoice_css'] = $this->invoice_payment_method->get_extra_meta(
103
+				'legacy_invoice_css',
104
+				true,
105
+				'simple.css'
106
+			);
107
+		}
108
+
109
+		if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) {
110
+			$template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/';
111
+		} else {
112
+			$template_args['base_url'] = EE_GATEWAYS . '/Invoice/lib/templates/';
113
+		}
114
+		$primary_attendee = $this->transaction->primary_registration()->attendee();
115
+
116
+		$template_args['organization'] = $EE->CFG->organization->get_pretty('name');
117
+		$template_args['street']       = empty($EE->CFG->organization->address_2)
118
+				? $EE->CFG->organization->get_pretty('address_1')
119
+				: $EE->CFG->organization->get_pretty('address_1')
120
+				  . '<br>'
121
+				  . $EE->CFG->organization->get_pretty('address_2');
122
+		$template_args['city']         = $EE->CFG->organization->get_pretty('city');
123
+		$template_args['state']        = EE_Registry::instance()->load_model('State')->get_one_by_ID(
124
+			$EE->CFG->organization->STA_ID
125
+		);
126
+		$template_args['country']      = EE_Registry::instance()->load_model('Country')->get_one_by_ID(
127
+			$EE->CFG->organization->CNT_ISO
128
+		);
129
+		$template_args['zip']          = $EE->CFG->organization->get_pretty('zip');
130
+		$template_args['email']        = $EE->CFG->organization->get_pretty('email');
131
+
132
+		$template_args['registration_code'] = $this->registration->reg_code();
133
+		$template_args['registration_date'] = $this->registration->date();
134
+		$template_args['name']              = $primary_attendee->full_name();
135
+		$template_args['attendee_address']  = $primary_attendee->address();
136
+		$template_args['attendee_address2'] = $primary_attendee->address2();
137
+		$template_args['attendee_city']     = $primary_attendee->city();
138
+		$attendee_state                     = $primary_attendee->state_obj();
139
+		if ($attendee_state) {
140
+			$attendee_state_name = $attendee_state->name();
141
+		} else {
142
+			$attendee_state_name = '';
143
+		}
144
+		$template_args['attendee_state'] = $attendee_state_name;
145
+		$template_args['attendee_zip']   = $primary_attendee->zip();
146
+
147
+		$template_args['ship_name']    = $template_args['name'];
148
+		$template_args['ship_address'] = $template_args['attendee_address'];
149
+		$template_args['ship_city']    = $template_args['attendee_city'];
150
+		$template_args['ship_state']   = $template_args['attendee_state'];
151
+		$template_args['ship_zip']     = $template_args['attendee_zip'];
152
+
153
+		$template_args['total_cost']                 = number_format($this->transaction->total(), 2, '.', '');
154
+		$template_args['transaction']                = $this->transaction;
155
+		$template_args['amount_pd']                  = $this->transaction->paid();
156
+		$template_args['amount_owed']                = $this->transaction->total() - $this->transaction->paid();
157
+		$template_args['payments']                   = $this->transaction->approved_payments();
158
+		$template_args['net_total']                  = '';
159
+		$template_args['edit_reg_info_url']          = $this->registration->edit_attendee_information_url();
160
+		$template_args['retry_payment_url']          = $this->registration->payment_overview_url();
161
+		$template_args['show_line_item_description'] = $this->check_if_any_line_items_have_a_description(
162
+			$this->transaction->total_line_item()
163
+		);
164
+		if ($template_args['amount_pd'] != $template_args['total_cost']) {
165
+			// $template_args['net_total'] = $this->espressoInvoiceTotals(
166
+			//      esc_html__('SubTotal', 'event_espresso'),
167
+			//      $this->transaction->total());
168
+			//      $this->session_data['cart']['REG']['sub_total']
169
+			// );
170
+			$tax_items = $this->transaction->tax_items();
171
+			if (! empty($tax_items)) {
172
+				foreach ($tax_items as $tax) {
173
+					$template_args['net_total'] .= $this->espressoInvoiceTotals($tax->name(), $tax->total());
174
+				}
175
+			}
176
+
177
+			$difference = $template_args['amount_pd'] - $template_args['total_cost'];
178
+			if ($difference < 0) {
179
+				$text = esc_html__('Discount', 'event_espresso');
180
+			} else {
181
+				$text = esc_html__('Extra', 'event_espresso');
182
+			}
183
+			$template_args['discount'] = $this->espressoInvoiceTotals($text, $difference);
184
+		}
185
+
186
+		$template_args['currency_symbol']               = $EE->CFG->currency->sign;
187
+		$template_args['template_payment_instructions'] = wpautop(
188
+			stripslashes_deep(
189
+				html_entity_decode($this->invoice_payment_method->get_extra_meta('pdf_instructions', true), ENT_QUOTES)
190
+			)
191
+		);
192
+		$template_args['shameless_plug']                = apply_filters(
193
+			'FHEE_Invoice__send_invoice__shameless_plug',
194
+			true
195
+		);
196
+		$receipt = $request->getRequestParam('receipt');
197
+		if ($receipt) {
198
+			// receipt-specific stuff
199
+			$events_for_txn              = EEM_Event::instance()->get_all(
200
+				[['Registration.TXN_ID' => $this->transaction->ID()]]
201
+			);
202
+			$ticket_line_items_per_event = [];
203
+			$registrations_per_line_item = [];
204
+			$venues_for_events           = [];
205
+			foreach ($events_for_txn as $event_id => $event) {
206
+				$line_items_for_this_event                = EEM_Line_Item::instance()->get_all(
207
+					[['Ticket.Datetime.EVT_ID' => $event_id, 'TXN_ID' => $this->transaction->ID()]]
208
+				);
209
+				$ticket_line_items_per_event[ $event_id ] = $line_items_for_this_event;
210
+				foreach ($line_items_for_this_event as $line_item_id => $line_item) {
211
+					if (! $line_item instanceof EE_Line_Item) {
212
+						continue;
213
+					}
214
+					$ticket                                       = $line_item->ticket();
215
+					$registrations_for_this_ticket                = EEM_Registration::instance()->get_all(
216
+						[['TKT_ID' => $ticket->ID(), 'TXN_ID' => $this->transaction->ID()]]
217
+					);
218
+					$registrations_per_line_item[ $line_item_id ] = $registrations_for_this_ticket;
219
+				}
220
+				if ($event instanceof EE_Event) {
221
+					$venues_for_events += $event->venues();
222
+				}
223
+			}
224
+			$tax_total_line_item = EEM_Line_Item::instance()->get_one(
225
+				[['TXN_ID' => $this->transaction->ID(), 'LIN_type' => EEM_Line_Item::type_tax_sub_total]]
226
+			);
227
+			$questions_to_skip   = [
228
+				EEM_Attendee::system_question_fname,
229
+				EEM_Attendee::system_question_lname,
230
+				EEM_Attendee::system_question_email,
231
+			];
232
+
233
+
234
+			$template_args['events_for_txn']              = $events_for_txn;
235
+			$template_args['ticket_line_items_per_event'] = $ticket_line_items_per_event;
236
+			$template_args['registrations_per_line_item'] = $registrations_per_line_item;
237
+			$template_args['venues_for_events']           = $venues_for_events;
238
+			$template_args['tax_total_line_item']         = $tax_total_line_item;
239
+			$template_args['questions_to_skip']           = $questions_to_skip;
240
+			// d($template_args);
241
+			$template_args['download_link'] = $this->registration->receipt_url('download');
242
+		} else {
243
+			// it's just an invoice we're accessing
244
+			$template_args['download_link'] = $this->registration->invoice_url('download');
245
+		}
246
+
247
+		// Get the HTML as an object
248
+		$templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
249
+		$template_header         = EEH_Template::locate_template(
250
+			$templates_relative_path . 'invoice_header.template.php',
251
+			$template_args
252
+		);
253
+		if ($receipt) {
254
+			$template_body = EEH_Template::locate_template(
255
+				$templates_relative_path . 'receipt_body.template.php',
256
+				$template_args
257
+			);
258
+		} else {
259
+			$template_body = EEH_Template::locate_template(
260
+				$templates_relative_path . 'invoice_body.template.php',
261
+				$template_args
262
+			);
263
+		}
264
+
265
+
266
+		$template_footer = EEH_Template::locate_template(
267
+			$templates_relative_path . 'invoice_footer.template.php',
268
+			$template_args
269
+		);
270
+
271
+		$copies = $request->getRequestParam('copies', 1, 'int');
272
+
273
+		$content = $this->espresso_replace_invoice_shortcodes($template_header);
274
+		for ($x = 1; $x <= $copies; $x++) {
275
+			$content .= $this->espresso_replace_invoice_shortcodes($template_body);
276
+		}
277
+		$content .= $this->espresso_replace_invoice_shortcodes($template_footer);
278
+
279
+		// Check if debugging or mobile is set
280
+		if ($request->getRequestParam('html')) {
281
+			echo $content;
282
+			exit(0);
283
+		}
284
+		$invoice_name = $template_args['organization'] . ' ';
285
+		$invoice_name .= esc_html__('Invoice #', 'event_espresso');
286
+		$invoice_name .= $template_args['registration_code'];
287
+		$invoice_name .= esc_html__(' for ', 'event_espresso') . $template_args['name'];
288
+		$invoice_name = str_replace(' ', '_', $invoice_name);
289
+		// Create the PDF
290
+		if ($request->requestParamIsSet('html')) {
291
+			echo $content;
292
+		} else {
293
+			// only load dompdf if nobody else has yet...
294
+			if (! class_exists('Dompdf\Dompdf')) {
295
+				require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php');
296
+				Dompdf\Autoloader::register();
297
+			}
298
+			$options = new Dompdf\Options();
299
+			$options->set('isRemoteEnabled', true);
300
+			$options->set('isJavascriptEnabled', false);
301
+			if (defined('DOMPDF_FONT_DIR')) {
302
+				$options->setFontDir(DOMPDF_FONT_DIR);
303
+				$options->setFontCache(DOMPDF_FONT_DIR);
304
+			}
305
+			$dompdf = new Dompdf\Dompdf($options);
306
+			$dompdf->loadHtml($content);
307
+			$dompdf->render();
308
+			$dompdf->stream($invoice_name . ".pdf", ['Attachment' => $download]);
309
+		}
310
+		exit(0);
311
+	}
312
+
313
+
314
+	/**
315
+	 * Checks if this line item, or any of its children, actually has a description.
316
+	 * If none do, then the template can decide to not show any description column
317
+	 *
318
+	 * @param EE_Line_Item $line_item
319
+	 * @return boolean
320
+	 * @throws EE_Error
321
+	 * @throws ReflectionException
322
+	 */
323
+	public function check_if_any_line_items_have_a_description(EE_Line_Item $line_item)
324
+	{
325
+		if ($line_item->desc()) {
326
+			return true;
327
+		} else {
328
+			foreach ($line_item->children() as $child_line_item) {
329
+				if ($this->check_if_any_line_items_have_a_description($child_line_item)) {
330
+					return true;
331
+				}
332
+			}
333
+			// well, if I and my children don't have descriptions, I guess not
334
+			return false;
335
+		}
336
+	}
337
+
338
+
339
+	/**
340
+	 * Perform the shortcode replacement
341
+	 *
342
+	 * @param $content
343
+	 * @return array|string|string[]
344
+	 * @throws EE_Error
345
+	 * @throws ReflectionException
346
+	 */
347
+	public function espresso_replace_invoice_shortcodes($content)
348
+	{
349
+
350
+		$EE = EE_Registry::instance();
351
+		// Create the logo
352
+		$invoice_logo_url = $this->invoice_payment_method->get_extra_meta(
353
+			'pdf_logo_image',
354
+			true,
355
+			$EE->CFG->organization->logo_url
356
+		);
357
+		if (! empty($invoice_logo_url)) {
358
+			$image_size         = getimagesize($invoice_logo_url);
359
+			$invoice_logo_image =
360
+				'<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> ';
361
+		} else {
362
+			$invoice_logo_image = '';
363
+		}
364
+		$SearchValues     = [
365
+			"[organization]",
366
+			"[registration_code]",
367
+			"[transaction_id]",
368
+			"[name]",
369
+			"[base_url]",
370
+			"[download_link]",
371
+			"[invoice_logo_image]",
372
+			"[street]",
373
+			"[city]",
374
+			"[state]",
375
+			"[zip]",
376
+			"[email]",
377
+			"[vat]",
378
+			"[registration_date]",
379
+			"[instructions]",
380
+		];
381
+		$primary_attendee = $this->transaction->primary_registration()->attendee();
382
+		$org_state        = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID);
383
+		if ($org_state) {
384
+			$org_state_name = $org_state->name();
385
+		} else {
386
+			$org_state_name = '';
387
+		}
388
+		$ReplaceValues = [
389
+			$EE->CFG->organization->get_pretty('name'),
390
+			$this->registration->reg_code(),
391
+			$this->transaction->ID(),
392
+			$primary_attendee->full_name(),
393
+			(is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice'))
394
+				? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/'
395
+				: EE_GATEWAYS_URL . 'Invoice/lib/templates/',
396
+			$this->registration->invoice_url(),
397
+			// home_url() . '/?download_invoice=true&amp;id=' . $this->registration->reg_url_link(),
398
+			$invoice_logo_image,
399
+			empty($EE->CFG->organization->address_2)
400
+				? $EE->CFG->organization->get_pretty('address_1')
401
+				: $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty(
402
+					'address_2'
403
+				),
404
+			$EE->CFG->organization->get_pretty('city'),
405
+			$org_state_name,
406
+			$EE->CFG->organization->get_pretty('zip'),
407
+			$EE->CFG->organization->get_pretty('email'),
408
+			$EE->CFG->organization->vat,
409
+			$this->registration->get_i18n_datetime('REG_date', get_option('date_format')),
410
+			$this->invoice_payment_method->get_extra_meta('pdf_instructions', true),
411
+		];
412
+
413
+		return str_replace($SearchValues, $ReplaceValues, $content);
414
+	}
415
+
416
+
417
+	public function espressoLoadData($items)
418
+	{
419
+		$lines = $items;
420
+		$data  = [];
421
+		foreach ($lines as $line) {
422
+			$data[] = explode(';', chop($line));
423
+		}
424
+
425
+		return $data;
426
+	}
427
+
428
+
429
+	public function espressoInvoiceTotals($text, $total_cost)
430
+	{
431
+		$html = '';
432
+		if ($total_cost < 0) {
433
+			$total_cost = (-1) * $total_cost;
434
+		}
435
+		$find    = [' '];
436
+		$replace = ['-'];
437
+		$row_id  = strtolower(str_replace($find, $replace, $text));
438
+		$html    .= '<tr id="' . $row_id . '-tr"><td colspan="4">&nbsp;</td>';
439
+		$html    .= '<td class="item_r">' . $text . '</td>';
440
+		$html    .= '<td class="item_r">' . $total_cost . '</td>';
441
+		$html    .= '</tr>';
442
+		return $html;
443
+	}
444 444
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
             7 => "union.css",
97 97
         ];
98 98
         // Get the CSS file
99
-        if (isset($themes[ $theme_requested ])) {
100
-            $template_args['invoice_css'] = $themes[ $theme_requested ];
99
+        if (isset($themes[$theme_requested])) {
100
+            $template_args['invoice_css'] = $themes[$theme_requested];
101 101
         } else {
102 102
             $template_args['invoice_css'] = $this->invoice_payment_method->get_extra_meta(
103 103
                 'legacy_invoice_css',
@@ -106,10 +106,10 @@  discard block
 block discarded – undo
106 106
             );
107 107
         }
108 108
 
109
-        if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) {
110
-            $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/';
109
+        if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR.'/invoice')) {
110
+            $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL.'Invoice/lib/templates/';
111 111
         } else {
112
-            $template_args['base_url'] = EE_GATEWAYS . '/Invoice/lib/templates/';
112
+            $template_args['base_url'] = EE_GATEWAYS.'/Invoice/lib/templates/';
113 113
         }
114 114
         $primary_attendee = $this->transaction->primary_registration()->attendee();
115 115
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
             //      $this->session_data['cart']['REG']['sub_total']
169 169
             // );
170 170
             $tax_items = $this->transaction->tax_items();
171
-            if (! empty($tax_items)) {
171
+            if ( ! empty($tax_items)) {
172 172
                 foreach ($tax_items as $tax) {
173 173
                     $template_args['net_total'] .= $this->espressoInvoiceTotals($tax->name(), $tax->total());
174 174
                 }
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
                 html_entity_decode($this->invoice_payment_method->get_extra_meta('pdf_instructions', true), ENT_QUOTES)
190 190
             )
191 191
         );
192
-        $template_args['shameless_plug']                = apply_filters(
192
+        $template_args['shameless_plug'] = apply_filters(
193 193
             'FHEE_Invoice__send_invoice__shameless_plug',
194 194
             true
195 195
         );
@@ -206,16 +206,16 @@  discard block
 block discarded – undo
206 206
                 $line_items_for_this_event                = EEM_Line_Item::instance()->get_all(
207 207
                     [['Ticket.Datetime.EVT_ID' => $event_id, 'TXN_ID' => $this->transaction->ID()]]
208 208
                 );
209
-                $ticket_line_items_per_event[ $event_id ] = $line_items_for_this_event;
209
+                $ticket_line_items_per_event[$event_id] = $line_items_for_this_event;
210 210
                 foreach ($line_items_for_this_event as $line_item_id => $line_item) {
211
-                    if (! $line_item instanceof EE_Line_Item) {
211
+                    if ( ! $line_item instanceof EE_Line_Item) {
212 212
                         continue;
213 213
                     }
214 214
                     $ticket                                       = $line_item->ticket();
215 215
                     $registrations_for_this_ticket                = EEM_Registration::instance()->get_all(
216 216
                         [['TKT_ID' => $ticket->ID(), 'TXN_ID' => $this->transaction->ID()]]
217 217
                     );
218
-                    $registrations_per_line_item[ $line_item_id ] = $registrations_for_this_ticket;
218
+                    $registrations_per_line_item[$line_item_id] = $registrations_for_this_ticket;
219 219
                 }
220 220
                 if ($event instanceof EE_Event) {
221 221
                     $venues_for_events += $event->venues();
@@ -247,24 +247,24 @@  discard block
 block discarded – undo
247 247
         // Get the HTML as an object
248 248
         $templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
249 249
         $template_header         = EEH_Template::locate_template(
250
-            $templates_relative_path . 'invoice_header.template.php',
250
+            $templates_relative_path.'invoice_header.template.php',
251 251
             $template_args
252 252
         );
253 253
         if ($receipt) {
254 254
             $template_body = EEH_Template::locate_template(
255
-                $templates_relative_path . 'receipt_body.template.php',
255
+                $templates_relative_path.'receipt_body.template.php',
256 256
                 $template_args
257 257
             );
258 258
         } else {
259 259
             $template_body = EEH_Template::locate_template(
260
-                $templates_relative_path . 'invoice_body.template.php',
260
+                $templates_relative_path.'invoice_body.template.php',
261 261
                 $template_args
262 262
             );
263 263
         }
264 264
 
265 265
 
266 266
         $template_footer = EEH_Template::locate_template(
267
-            $templates_relative_path . 'invoice_footer.template.php',
267
+            $templates_relative_path.'invoice_footer.template.php',
268 268
             $template_args
269 269
         );
270 270
 
@@ -281,18 +281,18 @@  discard block
 block discarded – undo
281 281
             echo $content;
282 282
             exit(0);
283 283
         }
284
-        $invoice_name = $template_args['organization'] . ' ';
284
+        $invoice_name = $template_args['organization'].' ';
285 285
         $invoice_name .= esc_html__('Invoice #', 'event_espresso');
286 286
         $invoice_name .= $template_args['registration_code'];
287
-        $invoice_name .= esc_html__(' for ', 'event_espresso') . $template_args['name'];
287
+        $invoice_name .= esc_html__(' for ', 'event_espresso').$template_args['name'];
288 288
         $invoice_name = str_replace(' ', '_', $invoice_name);
289 289
         // Create the PDF
290 290
         if ($request->requestParamIsSet('html')) {
291 291
             echo $content;
292 292
         } else {
293 293
             // only load dompdf if nobody else has yet...
294
-            if (! class_exists('Dompdf\Dompdf')) {
295
-                require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php');
294
+            if ( ! class_exists('Dompdf\Dompdf')) {
295
+                require_once(EE_THIRD_PARTY.'dompdf/src/Autoloader.php');
296 296
                 Dompdf\Autoloader::register();
297 297
             }
298 298
             $options = new Dompdf\Options();
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
             $dompdf = new Dompdf\Dompdf($options);
306 306
             $dompdf->loadHtml($content);
307 307
             $dompdf->render();
308
-            $dompdf->stream($invoice_name . ".pdf", ['Attachment' => $download]);
308
+            $dompdf->stream($invoice_name.".pdf", ['Attachment' => $download]);
309 309
         }
310 310
         exit(0);
311 311
     }
@@ -354,14 +354,14 @@  discard block
 block discarded – undo
354 354
             true,
355 355
             $EE->CFG->organization->logo_url
356 356
         );
357
-        if (! empty($invoice_logo_url)) {
357
+        if ( ! empty($invoice_logo_url)) {
358 358
             $image_size         = getimagesize($invoice_logo_url);
359 359
             $invoice_logo_image =
360
-                '<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> ';
360
+                '<img class="logo screen" src="'.$invoice_logo_url.'" '.$image_size[3].' alt="logo" /> ';
361 361
         } else {
362 362
             $invoice_logo_image = '';
363 363
         }
364
-        $SearchValues     = [
364
+        $SearchValues = [
365 365
             "[organization]",
366 366
             "[registration_code]",
367 367
             "[transaction_id]",
@@ -390,15 +390,15 @@  discard block
 block discarded – undo
390 390
             $this->registration->reg_code(),
391 391
             $this->transaction->ID(),
392 392
             $primary_attendee->full_name(),
393
-            (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice'))
393
+            (is_dir(EVENT_ESPRESSO_GATEWAY_DIR.'/invoice'))
394 394
                 ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/'
395
-                : EE_GATEWAYS_URL . 'Invoice/lib/templates/',
395
+                : EE_GATEWAYS_URL.'Invoice/lib/templates/',
396 396
             $this->registration->invoice_url(),
397 397
             // home_url() . '/?download_invoice=true&amp;id=' . $this->registration->reg_url_link(),
398 398
             $invoice_logo_image,
399 399
             empty($EE->CFG->organization->address_2)
400 400
                 ? $EE->CFG->organization->get_pretty('address_1')
401
-                : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty(
401
+                : $EE->CFG->organization->get_pretty('address_1').'<br>'.$EE->CFG->organization->get_pretty(
402 402
                     'address_2'
403 403
                 ),
404 404
             $EE->CFG->organization->get_pretty('city'),
@@ -435,9 +435,9 @@  discard block
 block discarded – undo
435 435
         $find    = [' '];
436 436
         $replace = ['-'];
437 437
         $row_id  = strtolower(str_replace($find, $replace, $text));
438
-        $html    .= '<tr id="' . $row_id . '-tr"><td colspan="4">&nbsp;</td>';
439
-        $html    .= '<td class="item_r">' . $text . '</td>';
440
-        $html    .= '<td class="item_r">' . $total_cost . '</td>';
438
+        $html    .= '<tr id="'.$row_id.'-tr"><td colspan="4">&nbsp;</td>';
439
+        $html    .= '<td class="item_r">'.$text.'</td>';
440
+        $html    .= '<td class="item_r">'.$total_cost.'</td>';
441 441
         $html    .= '</tr>';
442 442
         return $html;
443 443
     }
Please login to merge, or discard this patch.
core/services/encryption/EncryptionMethodInterface.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -12,46 +12,46 @@
 block discarded – undo
12 12
  */
13 13
 interface EncryptionMethodInterface
14 14
 {
15
-    /**
16
-     * returns true if the encryption method is cryptographically secure
17
-     *
18
-     * @return bool
19
-     */
20
-    public function isCryptographicallySecure();
21
-
22
-
23
-    /**
24
-     * returns true if the method can be used on the current server
25
-     *
26
-     * @return bool
27
-     */
28
-    public function canUse();
29
-
30
-
31
-    /**
32
-     * returns a message explaining why the encryption method in question can or can not be used
33
-     *
34
-     * @return string
35
-     */
36
-    public function canUseNotice();
37
-
38
-
39
-    /**
40
-     * encrypts data
41
-     *
42
-     * @param string $text_to_encrypt           - the text to be encrypted
43
-     * @param string $encryption_key_identifier - name of the encryption key to use
44
-     * @return string
45
-     */
46
-    public function encrypt($text_to_encrypt, $encryption_key_identifier = '');
47
-
48
-
49
-    /**
50
-     * decrypts data
51
-     *
52
-     * @param string $encrypted_text            - the text to be decrypted
53
-     * @param string $encryption_key_identifier - name of the encryption key to use
54
-     * @return string
55
-     */
56
-    public function decrypt($encrypted_text, $encryption_key_identifier = '');
15
+	/**
16
+	 * returns true if the encryption method is cryptographically secure
17
+	 *
18
+	 * @return bool
19
+	 */
20
+	public function isCryptographicallySecure();
21
+
22
+
23
+	/**
24
+	 * returns true if the method can be used on the current server
25
+	 *
26
+	 * @return bool
27
+	 */
28
+	public function canUse();
29
+
30
+
31
+	/**
32
+	 * returns a message explaining why the encryption method in question can or can not be used
33
+	 *
34
+	 * @return string
35
+	 */
36
+	public function canUseNotice();
37
+
38
+
39
+	/**
40
+	 * encrypts data
41
+	 *
42
+	 * @param string $text_to_encrypt           - the text to be encrypted
43
+	 * @param string $encryption_key_identifier - name of the encryption key to use
44
+	 * @return string
45
+	 */
46
+	public function encrypt($text_to_encrypt, $encryption_key_identifier = '');
47
+
48
+
49
+	/**
50
+	 * decrypts data
51
+	 *
52
+	 * @param string $encrypted_text            - the text to be decrypted
53
+	 * @param string $encryption_key_identifier - name of the encryption key to use
54
+	 * @return string
55
+	 */
56
+	public function decrypt($encrypted_text, $encryption_key_identifier = '');
57 57
 }
Please login to merge, or discard this patch.
core/services/encryption/openssl/OpenSSL.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public function canUseNotice()
122 122
     {
123
-        if (! $this->openssl_installed) {
123
+        if ( ! $this->openssl_installed) {
124 124
             return esc_html__(
125 125
                 'The PHP openssl server extension is required to use Openssl encryption. Please contact your hosting provider regarding this issue.',
126 126
                 'event_espresso'
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      */
220 220
     protected function getHashAlgorithm()
221 221
     {
222
-        if (! $this->hash_algorithm) {
222
+        if ( ! $this->hash_algorithm) {
223 223
             // get installed hashing algorithms
224 224
             $hash_algorithms = hash_algos();
225 225
             // filter array for "sha" algorithms
Please login to merge, or discard this patch.
Indentation   +262 added lines, -262 removed lines patch added patch discarded remove patch
@@ -18,266 +18,266 @@
 block discarded – undo
18 18
 abstract class OpenSSL implements EncryptionMethodInterface
19 19
 {
20 20
 
21
-    /**
22
-     * the default OPENSSL digest method to use
23
-     */
24
-    const DEFAULT_DIGEST_METHOD = 'sha512';
25
-
26
-    /**
27
-     * separates the encrypted text from the initialization vector
28
-     */
29
-    const IV_DELIMITER = ':iv:';
30
-
31
-    /**
32
-     * @var Base64Encoder
33
-     */
34
-    protected $base64_encoder;
35
-
36
-    /**
37
-     * @var CipherMethod
38
-     */
39
-    protected $cipher_method;
40
-
41
-    /**
42
-     * @var array $digest_methods
43
-     */
44
-    private $digest_methods = [];
45
-
46
-    /**
47
-     * @var EncryptionKeyManagerInterface
48
-     */
49
-    protected $encryption_key_manager;
50
-
51
-    /**
52
-     * @var boolean
53
-     */
54
-    private $openssl_installed;
55
-
56
-    /**
57
-     * @var string
58
-     */
59
-    private $min_php_version;
60
-
61
-    /**
62
-     * @var string
63
-     */
64
-    private $hash_algorithm;
65
-
66
-
67
-    /**
68
-     * To use custom a cipher method and/or encryption keys:
69
-     *  - extend this class
70
-     *  - configure a new CipherMethod / EncryptionKeyManager in the constructor
71
-     *  - pass those to this constructor, like so:
72
-     *
73
-     *      public function __construct(Base64Encoder $base64_encoder) {
74
-     *          parent::__construct(
75
-     *              $base64_encoder,
76
-     *              new CipherMethod(CIPHER_METHOD, CIPHER_METHOD_OPTION_NAME)
77
-     *              new EncryptionKeyManager(CUSTOM_KEY_ID, CUSTOM_KEYS_OPTION_NAME)
78
-     *          );
79
-     *      }
80
-     *
81
-     * @param Base64Encoder                      $base64_encoder
82
-     * @param CipherMethod                       $cipher_method
83
-     * @param EncryptionKeyManagerInterface|null $encryption_key_manager
84
-     * @param string                             $min_php_version
85
-     */
86
-    protected function __construct(
87
-        Base64Encoder $base64_encoder,
88
-        CipherMethod $cipher_method,
89
-        EncryptionKeyManagerInterface $encryption_key_manager,
90
-        $min_php_version
91
-    ) {
92
-        $this->base64_encoder         = $base64_encoder;
93
-        $this->cipher_method          = $cipher_method;
94
-        $this->encryption_key_manager = $encryption_key_manager;
95
-        $this->min_php_version        = $min_php_version;
96
-        $this->openssl_installed      = extension_loaded('openssl');
97
-    }
98
-
99
-
100
-    /**
101
-     * @return bool
102
-     */
103
-    public function isCryptographicallySecure()
104
-    {
105
-        return true;
106
-    }
107
-
108
-
109
-    /**
110
-     * @return bool
111
-     */
112
-    public function canUse()
113
-    {
114
-        return $this->openssl_installed && version_compare(PHP_VERSION, $this->min_php_version, '>=');
115
-    }
116
-
117
-
118
-    /**
119
-     * @return string
120
-     */
121
-    public function canUseNotice()
122
-    {
123
-        if (! $this->openssl_installed) {
124
-            return esc_html__(
125
-                'The PHP openssl server extension is required to use Openssl encryption. Please contact your hosting provider regarding this issue.',
126
-                'event_espresso'
127
-            );
128
-        }
129
-        if (version_compare(PHP_VERSION, $this->min_php_version, '<')) {
130
-            return sprintf(
131
-                esc_html__(
132
-                    'PHP version %1$s or greater is required to use Openssl encryption. Please contact your hosting provider regarding this issue.',
133
-                    'event_espresso'
134
-                ),
135
-                $this->min_php_version
136
-            );
137
-        }
138
-        return sprintf(
139
-            esc_html__('OpenSSL v1 encryption using %1$S is available for use.', 'event_espresso'),
140
-            OpenSSLv1::CIPHER_METHOD
141
-        );
142
-    }
143
-
144
-
145
-    /**
146
-     * Computes the digest hash value using the specified digest method.
147
-     * If that digest method fails to produce a valid hash value,
148
-     * then we'll grab the next digest method and recursively try again until something works.
149
-     *
150
-     * @param string $encryption_key
151
-     * @param string $digest_method
152
-     * @param bool   $return_raw_data
153
-     * @return string
154
-     * @throws RuntimeException
155
-     */
156
-    protected function getDigestHashValue(
157
-        $encryption_key,
158
-        $digest_method = OpenSSL::DEFAULT_DIGEST_METHOD,
159
-        $return_raw_data = false
160
-    ) {
161
-        $digest_hash_value = openssl_digest($encryption_key, $digest_method, $return_raw_data);
162
-        if ($digest_hash_value === false) {
163
-            return $this->getDigestHashValue($this->getDigestMethod());
164
-        }
165
-        return $digest_hash_value;
166
-    }
167
-
168
-
169
-    /**
170
-     * Returns the NEXT element in the $digest_methods array.
171
-     * If the $digest_methods array is empty, then we populate it
172
-     * with the available values returned from openssl_get_md_methods().
173
-     *
174
-     * @return string
175
-     * @throws RuntimeException
176
-     */
177
-    private function getDigestMethod()
178
-    {
179
-        $digest_method = prev($this->digest_methods);
180
-        if (empty($this->digest_methods)) {
181
-            $this->digest_methods = openssl_get_md_methods();
182
-            $digest_method        = end($this->digest_methods);
183
-        }
184
-        if ($digest_method === false) {
185
-            throw new RuntimeException(
186
-                esc_html__(
187
-                    'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.',
188
-                    'event_espresso'
189
-                )
190
-            );
191
-        }
192
-        return $digest_method;
193
-    }
194
-
195
-
196
-    /**
197
-     * @param string $encryption_key
198
-     * @return int
199
-     */
200
-    protected function calculateHashLength($encryption_key)
201
-    {
202
-        // get existing key length
203
-        $prev_key_length = $this->encryption_key_manager->keyLength();
204
-        // set it to something HUGE
205
-        $this->encryption_key_manager->setKeyLength(512);
206
-        // generate a new weak key, which should just be a really long random string
207
-        $test_text = $this->encryption_key_manager->generateEncryptionKey(false);
208
-        // generate a hash using our test string and our real $encryption_key
209
-        $hash = hash_hmac($this->getHashAlgorithm(), $test_text, $encryption_key, true);
210
-        // reset key length back to original value
211
-        $this->encryption_key_manager->setKeyLength($prev_key_length);
212
-        // return the length of the hash
213
-        return strlen($hash);
214
-    }
215
-
216
-
217
-    /**
218
-     * @return string
219
-     */
220
-    protected function getHashAlgorithm()
221
-    {
222
-        if (! $this->hash_algorithm) {
223
-            // get installed hashing algorithms
224
-            $hash_algorithms = hash_algos();
225
-            // filter array for "sha" algorithms
226
-            $hash_algorithms = preg_grep('/^sha\d{3}$/i', $hash_algorithms);
227
-            // if no sha algorithms are installed, then just use md5
228
-            if (empty($hash_algorithms)) {
229
-                $this->hash_algorithm = 'md5';
230
-                return $this->hash_algorithm;
231
-            }
232
-            // sort ascending using "natural ordering"
233
-            sort($hash_algorithms, SORT_NATURAL);
234
-            // return last item from array, which should be the strongest installed sha hash
235
-            $this->hash_algorithm = array_pop($hash_algorithms);
236
-        }
237
-        return $this->hash_algorithm;
238
-    }
239
-
240
-
241
-    /**
242
-     * @param string $encrypted_text
243
-     * @throws RuntimeException
244
-     */
245
-    protected function validateEncryption($encrypted_text)
246
-    {
247
-        if ($encrypted_text === false) {
248
-            throw new RuntimeException(
249
-                sprintf(
250
-                    esc_html__('The following error occurred during OpenSSL encryption: %1$S', 'event_espresso'),
251
-                    $this->getOpenSslError()
252
-                )
253
-            );
254
-        }
255
-    }
256
-
257
-
258
-    /**
259
-     * @return false|string
260
-     */
261
-    private function getOpenSslError()
262
-    {
263
-        $error = openssl_error_string();
264
-        return $error ?: esc_html__('Unknown Error', 'event_espresso');
265
-    }
266
-
267
-
268
-    /**
269
-     * @param string $encrypted_text
270
-     * @throws RuntimeException
271
-     */
272
-    protected function validateDecryption($encrypted_text)
273
-    {
274
-        if ($encrypted_text === false) {
275
-            throw new RuntimeException(
276
-                sprintf(
277
-                    esc_html__('OpenSSL decryption failed for the following reason: %1$S', 'event_espresso'),
278
-                    $this->getOpenSslError()
279
-                )
280
-            );
281
-        }
282
-    }
21
+	/**
22
+	 * the default OPENSSL digest method to use
23
+	 */
24
+	const DEFAULT_DIGEST_METHOD = 'sha512';
25
+
26
+	/**
27
+	 * separates the encrypted text from the initialization vector
28
+	 */
29
+	const IV_DELIMITER = ':iv:';
30
+
31
+	/**
32
+	 * @var Base64Encoder
33
+	 */
34
+	protected $base64_encoder;
35
+
36
+	/**
37
+	 * @var CipherMethod
38
+	 */
39
+	protected $cipher_method;
40
+
41
+	/**
42
+	 * @var array $digest_methods
43
+	 */
44
+	private $digest_methods = [];
45
+
46
+	/**
47
+	 * @var EncryptionKeyManagerInterface
48
+	 */
49
+	protected $encryption_key_manager;
50
+
51
+	/**
52
+	 * @var boolean
53
+	 */
54
+	private $openssl_installed;
55
+
56
+	/**
57
+	 * @var string
58
+	 */
59
+	private $min_php_version;
60
+
61
+	/**
62
+	 * @var string
63
+	 */
64
+	private $hash_algorithm;
65
+
66
+
67
+	/**
68
+	 * To use custom a cipher method and/or encryption keys:
69
+	 *  - extend this class
70
+	 *  - configure a new CipherMethod / EncryptionKeyManager in the constructor
71
+	 *  - pass those to this constructor, like so:
72
+	 *
73
+	 *      public function __construct(Base64Encoder $base64_encoder) {
74
+	 *          parent::__construct(
75
+	 *              $base64_encoder,
76
+	 *              new CipherMethod(CIPHER_METHOD, CIPHER_METHOD_OPTION_NAME)
77
+	 *              new EncryptionKeyManager(CUSTOM_KEY_ID, CUSTOM_KEYS_OPTION_NAME)
78
+	 *          );
79
+	 *      }
80
+	 *
81
+	 * @param Base64Encoder                      $base64_encoder
82
+	 * @param CipherMethod                       $cipher_method
83
+	 * @param EncryptionKeyManagerInterface|null $encryption_key_manager
84
+	 * @param string                             $min_php_version
85
+	 */
86
+	protected function __construct(
87
+		Base64Encoder $base64_encoder,
88
+		CipherMethod $cipher_method,
89
+		EncryptionKeyManagerInterface $encryption_key_manager,
90
+		$min_php_version
91
+	) {
92
+		$this->base64_encoder         = $base64_encoder;
93
+		$this->cipher_method          = $cipher_method;
94
+		$this->encryption_key_manager = $encryption_key_manager;
95
+		$this->min_php_version        = $min_php_version;
96
+		$this->openssl_installed      = extension_loaded('openssl');
97
+	}
98
+
99
+
100
+	/**
101
+	 * @return bool
102
+	 */
103
+	public function isCryptographicallySecure()
104
+	{
105
+		return true;
106
+	}
107
+
108
+
109
+	/**
110
+	 * @return bool
111
+	 */
112
+	public function canUse()
113
+	{
114
+		return $this->openssl_installed && version_compare(PHP_VERSION, $this->min_php_version, '>=');
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return string
120
+	 */
121
+	public function canUseNotice()
122
+	{
123
+		if (! $this->openssl_installed) {
124
+			return esc_html__(
125
+				'The PHP openssl server extension is required to use Openssl encryption. Please contact your hosting provider regarding this issue.',
126
+				'event_espresso'
127
+			);
128
+		}
129
+		if (version_compare(PHP_VERSION, $this->min_php_version, '<')) {
130
+			return sprintf(
131
+				esc_html__(
132
+					'PHP version %1$s or greater is required to use Openssl encryption. Please contact your hosting provider regarding this issue.',
133
+					'event_espresso'
134
+				),
135
+				$this->min_php_version
136
+			);
137
+		}
138
+		return sprintf(
139
+			esc_html__('OpenSSL v1 encryption using %1$S is available for use.', 'event_espresso'),
140
+			OpenSSLv1::CIPHER_METHOD
141
+		);
142
+	}
143
+
144
+
145
+	/**
146
+	 * Computes the digest hash value using the specified digest method.
147
+	 * If that digest method fails to produce a valid hash value,
148
+	 * then we'll grab the next digest method and recursively try again until something works.
149
+	 *
150
+	 * @param string $encryption_key
151
+	 * @param string $digest_method
152
+	 * @param bool   $return_raw_data
153
+	 * @return string
154
+	 * @throws RuntimeException
155
+	 */
156
+	protected function getDigestHashValue(
157
+		$encryption_key,
158
+		$digest_method = OpenSSL::DEFAULT_DIGEST_METHOD,
159
+		$return_raw_data = false
160
+	) {
161
+		$digest_hash_value = openssl_digest($encryption_key, $digest_method, $return_raw_data);
162
+		if ($digest_hash_value === false) {
163
+			return $this->getDigestHashValue($this->getDigestMethod());
164
+		}
165
+		return $digest_hash_value;
166
+	}
167
+
168
+
169
+	/**
170
+	 * Returns the NEXT element in the $digest_methods array.
171
+	 * If the $digest_methods array is empty, then we populate it
172
+	 * with the available values returned from openssl_get_md_methods().
173
+	 *
174
+	 * @return string
175
+	 * @throws RuntimeException
176
+	 */
177
+	private function getDigestMethod()
178
+	{
179
+		$digest_method = prev($this->digest_methods);
180
+		if (empty($this->digest_methods)) {
181
+			$this->digest_methods = openssl_get_md_methods();
182
+			$digest_method        = end($this->digest_methods);
183
+		}
184
+		if ($digest_method === false) {
185
+			throw new RuntimeException(
186
+				esc_html__(
187
+					'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.',
188
+					'event_espresso'
189
+				)
190
+			);
191
+		}
192
+		return $digest_method;
193
+	}
194
+
195
+
196
+	/**
197
+	 * @param string $encryption_key
198
+	 * @return int
199
+	 */
200
+	protected function calculateHashLength($encryption_key)
201
+	{
202
+		// get existing key length
203
+		$prev_key_length = $this->encryption_key_manager->keyLength();
204
+		// set it to something HUGE
205
+		$this->encryption_key_manager->setKeyLength(512);
206
+		// generate a new weak key, which should just be a really long random string
207
+		$test_text = $this->encryption_key_manager->generateEncryptionKey(false);
208
+		// generate a hash using our test string and our real $encryption_key
209
+		$hash = hash_hmac($this->getHashAlgorithm(), $test_text, $encryption_key, true);
210
+		// reset key length back to original value
211
+		$this->encryption_key_manager->setKeyLength($prev_key_length);
212
+		// return the length of the hash
213
+		return strlen($hash);
214
+	}
215
+
216
+
217
+	/**
218
+	 * @return string
219
+	 */
220
+	protected function getHashAlgorithm()
221
+	{
222
+		if (! $this->hash_algorithm) {
223
+			// get installed hashing algorithms
224
+			$hash_algorithms = hash_algos();
225
+			// filter array for "sha" algorithms
226
+			$hash_algorithms = preg_grep('/^sha\d{3}$/i', $hash_algorithms);
227
+			// if no sha algorithms are installed, then just use md5
228
+			if (empty($hash_algorithms)) {
229
+				$this->hash_algorithm = 'md5';
230
+				return $this->hash_algorithm;
231
+			}
232
+			// sort ascending using "natural ordering"
233
+			sort($hash_algorithms, SORT_NATURAL);
234
+			// return last item from array, which should be the strongest installed sha hash
235
+			$this->hash_algorithm = array_pop($hash_algorithms);
236
+		}
237
+		return $this->hash_algorithm;
238
+	}
239
+
240
+
241
+	/**
242
+	 * @param string $encrypted_text
243
+	 * @throws RuntimeException
244
+	 */
245
+	protected function validateEncryption($encrypted_text)
246
+	{
247
+		if ($encrypted_text === false) {
248
+			throw new RuntimeException(
249
+				sprintf(
250
+					esc_html__('The following error occurred during OpenSSL encryption: %1$S', 'event_espresso'),
251
+					$this->getOpenSslError()
252
+				)
253
+			);
254
+		}
255
+	}
256
+
257
+
258
+	/**
259
+	 * @return false|string
260
+	 */
261
+	private function getOpenSslError()
262
+	{
263
+		$error = openssl_error_string();
264
+		return $error ?: esc_html__('Unknown Error', 'event_espresso');
265
+	}
266
+
267
+
268
+	/**
269
+	 * @param string $encrypted_text
270
+	 * @throws RuntimeException
271
+	 */
272
+	protected function validateDecryption($encrypted_text)
273
+	{
274
+		if ($encrypted_text === false) {
275
+			throw new RuntimeException(
276
+				sprintf(
277
+					esc_html__('OpenSSL decryption failed for the following reason: %1$S', 'event_espresso'),
278
+					$this->getOpenSslError()
279
+				)
280
+			);
281
+		}
282
+	}
283 283
 }
Please login to merge, or discard this patch.
core/services/encryption/openssl/OpenSSLv1.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@
 block discarded – undo
122 122
         // hash the raw encrypted text
123 123
         $hmac = hash_hmac($this->getHashAlgorithm(), $encrypted_text, $key, true);
124 124
         // concatenate everything into one big string and encode it again
125
-        return $this->base64_encoder->encodeString($iv . $hmac . $encrypted_text);
125
+        return $this->base64_encoder->encodeString($iv.$hmac.$encrypted_text);
126 126
     }
127 127
 
128 128
 
Please login to merge, or discard this patch.
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -18,155 +18,155 @@
 block discarded – undo
18 18
 class OpenSSLv1 extends OpenSSL
19 19
 {
20 20
 
21
-    /**
22
-     * name used for a default encryption key in case no others are set
23
-     */
24
-    const DEFAULT_ENCRYPTION_KEY_ID = 'default_openssl_v1_key';
21
+	/**
22
+	 * name used for a default encryption key in case no others are set
23
+	 */
24
+	const DEFAULT_ENCRYPTION_KEY_ID = 'default_openssl_v1_key';
25 25
 
26
-    /**
27
-     * name used for saving encryption keys to the wp_options table
28
-     */
29
-    const ENCRYPTION_KEYS_OPTION_NAME = 'ee_openssl_v1_encryption_keys';
26
+	/**
27
+	 * name used for saving encryption keys to the wp_options table
28
+	 */
29
+	const ENCRYPTION_KEYS_OPTION_NAME = 'ee_openssl_v1_encryption_keys';
30 30
 
31
-    /**
32
-     * the OPENSSL cipher method used
33
-     */
34
-    const CIPHER_METHOD = 'aes-128-cbc';
31
+	/**
32
+	 * the OPENSSL cipher method used
33
+	 */
34
+	const CIPHER_METHOD = 'aes-128-cbc';
35 35
 
36
-    /**
37
-     * WP "options_name" used to store a verified available cipher method
38
-     */
39
-    const CIPHER_METHOD_OPTION_NAME = 'ee_openssl_v1_cipher_method';
36
+	/**
37
+	 * WP "options_name" used to store a verified available cipher method
38
+	 */
39
+	const CIPHER_METHOD_OPTION_NAME = 'ee_openssl_v1_cipher_method';
40 40
 
41 41
 
42
-    /**
43
-     * To use custom a cipher method and/or encryption keys and/or minimum PHP version:
44
-     *  - extend this class
45
-     *  - configure a new CipherMethod / EncryptionKeyManager in the constructor
46
-     *  - pass those to this constructor, like so:
47
-     *
48
-     *      public function __construct(Base64Encoder $base64_encoder) {
49
-     *          parent::__construct(
50
-     *              $base64_encoder,
51
-     *              new CipherMethod(CIPHER_METHOD, CIPHER_METHOD_OPTION_NAME),
52
-     *              new EncryptionKeyManager(CUSTOM_KEY_ID, CUSTOM_KEYS_OPTION_NAME),
53
-     *              '7.1.0'
54
-     *          );
55
-     *      }
56
-     *
57
-     * @param Base64Encoder                      $base64_encoder
58
-     * @param CipherMethod|null                  $cipher_method
59
-     * @param EncryptionKeyManagerInterface|null $encryption_key_manager
60
-     * @param string                             $min_php_version defaults to 5.3.0 (when openssl added)
61
-     */
62
-    public function __construct(
63
-        Base64Encoder $base64_encoder,
64
-        CipherMethod $cipher_method = null,
65
-        EncryptionKeyManagerInterface $encryption_key_manager = null,
66
-        $min_php_version = '5.3.0'
67
-    ) {
68
-        parent::__construct(
69
-            $base64_encoder,
70
-            $cipher_method instanceof CipherMethod
71
-                ? $cipher_method
72
-                : new CipherMethod(
73
-                    OpenSSLv1::CIPHER_METHOD,
74
-                    OpenSSLv1::CIPHER_METHOD_OPTION_NAME
75
-                ),
76
-            $encryption_key_manager instanceof EncryptionKeyManager
77
-                ? $encryption_key_manager
78
-                : new EncryptionKeyManager(
79
-                    $base64_encoder,
80
-                    OpenSSLv1::DEFAULT_ENCRYPTION_KEY_ID,
81
-                    OpenSSLv1::ENCRYPTION_KEYS_OPTION_NAME
82
-                ),
83
-            $min_php_version
84
-        );
85
-    }
42
+	/**
43
+	 * To use custom a cipher method and/or encryption keys and/or minimum PHP version:
44
+	 *  - extend this class
45
+	 *  - configure a new CipherMethod / EncryptionKeyManager in the constructor
46
+	 *  - pass those to this constructor, like so:
47
+	 *
48
+	 *      public function __construct(Base64Encoder $base64_encoder) {
49
+	 *          parent::__construct(
50
+	 *              $base64_encoder,
51
+	 *              new CipherMethod(CIPHER_METHOD, CIPHER_METHOD_OPTION_NAME),
52
+	 *              new EncryptionKeyManager(CUSTOM_KEY_ID, CUSTOM_KEYS_OPTION_NAME),
53
+	 *              '7.1.0'
54
+	 *          );
55
+	 *      }
56
+	 *
57
+	 * @param Base64Encoder                      $base64_encoder
58
+	 * @param CipherMethod|null                  $cipher_method
59
+	 * @param EncryptionKeyManagerInterface|null $encryption_key_manager
60
+	 * @param string                             $min_php_version defaults to 5.3.0 (when openssl added)
61
+	 */
62
+	public function __construct(
63
+		Base64Encoder $base64_encoder,
64
+		CipherMethod $cipher_method = null,
65
+		EncryptionKeyManagerInterface $encryption_key_manager = null,
66
+		$min_php_version = '5.3.0'
67
+	) {
68
+		parent::__construct(
69
+			$base64_encoder,
70
+			$cipher_method instanceof CipherMethod
71
+				? $cipher_method
72
+				: new CipherMethod(
73
+					OpenSSLv1::CIPHER_METHOD,
74
+					OpenSSLv1::CIPHER_METHOD_OPTION_NAME
75
+				),
76
+			$encryption_key_manager instanceof EncryptionKeyManager
77
+				? $encryption_key_manager
78
+				: new EncryptionKeyManager(
79
+					$base64_encoder,
80
+					OpenSSLv1::DEFAULT_ENCRYPTION_KEY_ID,
81
+					OpenSSLv1::ENCRYPTION_KEYS_OPTION_NAME
82
+				),
83
+			$min_php_version
84
+		);
85
+	}
86 86
 
87 87
 
88
-    /**
89
-     * encrypts data
90
-     *
91
-     * @param string $text_to_encrypt           - the text to be encrypted
92
-     * @param string $encryption_key_identifier - cryptographically secure passphrase. will generate if necessary
93
-     * @return string
94
-     */
95
-    public function encrypt($text_to_encrypt, $encryption_key_identifier = '')
96
-    {
97
-        $cipher_method  = $this->cipher_method->getCipherMethod();
98
-        $encryption_key = $this->encryption_key_manager->getEncryptionKey($encryption_key_identifier);
99
-        // get initialization vector size
100
-        $iv_length = openssl_cipher_iv_length($cipher_method);
101
-        // generate initialization vector.
102
-        // The second parameter ("crypto_strong") is passed by reference,
103
-        // and is used to determines if the algorithm used was "cryptographically strong"
104
-        // openssl_random_pseudo_bytes() will toggle it to either true or false
105
-        $iv = openssl_random_pseudo_bytes($iv_length, $is_strong);
106
-        if ($iv === false || $is_strong === false) {
107
-            throw new RuntimeException(
108
-                esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
109
-            );
110
-        }
111
-        $key = $this->getDigestHashValue($encryption_key);
112
-        // encrypt it
113
-        $encrypted_text = openssl_encrypt(
114
-            $this->base64_encoder->encodeString($text_to_encrypt), // encode to remove special characters
115
-            $cipher_method,
116
-            $key,
117
-            0,
118
-            $iv
119
-        );
120
-        $this->validateEncryption($encrypted_text);
121
-        $encrypted_text = trim($encrypted_text);
122
-        // hash the raw encrypted text
123
-        $hmac = hash_hmac($this->getHashAlgorithm(), $encrypted_text, $key, true);
124
-        // concatenate everything into one big string and encode it again
125
-        return $this->base64_encoder->encodeString($iv . $hmac . $encrypted_text);
126
-    }
88
+	/**
89
+	 * encrypts data
90
+	 *
91
+	 * @param string $text_to_encrypt           - the text to be encrypted
92
+	 * @param string $encryption_key_identifier - cryptographically secure passphrase. will generate if necessary
93
+	 * @return string
94
+	 */
95
+	public function encrypt($text_to_encrypt, $encryption_key_identifier = '')
96
+	{
97
+		$cipher_method  = $this->cipher_method->getCipherMethod();
98
+		$encryption_key = $this->encryption_key_manager->getEncryptionKey($encryption_key_identifier);
99
+		// get initialization vector size
100
+		$iv_length = openssl_cipher_iv_length($cipher_method);
101
+		// generate initialization vector.
102
+		// The second parameter ("crypto_strong") is passed by reference,
103
+		// and is used to determines if the algorithm used was "cryptographically strong"
104
+		// openssl_random_pseudo_bytes() will toggle it to either true or false
105
+		$iv = openssl_random_pseudo_bytes($iv_length, $is_strong);
106
+		if ($iv === false || $is_strong === false) {
107
+			throw new RuntimeException(
108
+				esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
109
+			);
110
+		}
111
+		$key = $this->getDigestHashValue($encryption_key);
112
+		// encrypt it
113
+		$encrypted_text = openssl_encrypt(
114
+			$this->base64_encoder->encodeString($text_to_encrypt), // encode to remove special characters
115
+			$cipher_method,
116
+			$key,
117
+			0,
118
+			$iv
119
+		);
120
+		$this->validateEncryption($encrypted_text);
121
+		$encrypted_text = trim($encrypted_text);
122
+		// hash the raw encrypted text
123
+		$hmac = hash_hmac($this->getHashAlgorithm(), $encrypted_text, $key, true);
124
+		// concatenate everything into one big string and encode it again
125
+		return $this->base64_encoder->encodeString($iv . $hmac . $encrypted_text);
126
+	}
127 127
 
128 128
 
129
-    /**
130
-     * decrypts data
131
-     *
132
-     * @param string $encrypted_text            - the text to be decrypted
133
-     * @param string $encryption_key_identifier - cryptographically secure passphrase. will use default if necessary
134
-     * @return string
135
-     */
136
-    public function decrypt($encrypted_text, $encryption_key_identifier = '')
137
-    {
138
-        $cipher_method  = $this->cipher_method->getCipherMethod();
139
-        $encryption_key = $this->encryption_key_manager->getEncryptionKey($encryption_key_identifier);
140
-        $key            = $this->getDigestHashValue($encryption_key);
141
-        // decode our concatenated string
142
-        $encrypted_text = $this->base64_encoder->decodeString($encrypted_text);
143
-        // get the string lengths used for the hash and iv
144
-        $hash_length = $this->calculateHashLength($encryption_key);
145
-        $iv_length   = openssl_cipher_iv_length($cipher_method);
146
-        // use the above lengths to snip the required values from the decoded string
147
-        $iv                 = substr($encrypted_text, 0, $iv_length);
148
-        $hmac               = substr($encrypted_text, $iv_length, $hash_length);
149
-        $encrypted_text_raw = substr($encrypted_text, $iv_length + $hash_length);
150
-        // rehash the original raw encrypted text
151
-        $rehash_mac = hash_hmac($this->getHashAlgorithm(), $encrypted_text_raw, $key, true);
152
-        // timing attack safe comparison to determine if anything has changed
153
-        if (hash_equals($hmac, $rehash_mac)) {
154
-            // looks good, decrypt it, trim it, and return it
155
-            $decrypted_text = openssl_decrypt(
156
-                $encrypted_text_raw,
157
-                $this->cipher_method->getCipherMethod(),
158
-                $key,
159
-                0,
160
-                $iv
161
-            );
162
-            $this->validateDecryption($decrypted_text);
163
-            return trim($this->base64_encoder->decodeString($decrypted_text));
164
-        }
165
-        throw new RuntimeException(
166
-            esc_html__(
167
-                'Decryption failed because a hash comparison of the original text and the decrypted text was not the same, meaning something in the system or the encrypted data has changed.',
168
-                'event_espresso'
169
-            )
170
-        );
171
-    }
129
+	/**
130
+	 * decrypts data
131
+	 *
132
+	 * @param string $encrypted_text            - the text to be decrypted
133
+	 * @param string $encryption_key_identifier - cryptographically secure passphrase. will use default if necessary
134
+	 * @return string
135
+	 */
136
+	public function decrypt($encrypted_text, $encryption_key_identifier = '')
137
+	{
138
+		$cipher_method  = $this->cipher_method->getCipherMethod();
139
+		$encryption_key = $this->encryption_key_manager->getEncryptionKey($encryption_key_identifier);
140
+		$key            = $this->getDigestHashValue($encryption_key);
141
+		// decode our concatenated string
142
+		$encrypted_text = $this->base64_encoder->decodeString($encrypted_text);
143
+		// get the string lengths used for the hash and iv
144
+		$hash_length = $this->calculateHashLength($encryption_key);
145
+		$iv_length   = openssl_cipher_iv_length($cipher_method);
146
+		// use the above lengths to snip the required values from the decoded string
147
+		$iv                 = substr($encrypted_text, 0, $iv_length);
148
+		$hmac               = substr($encrypted_text, $iv_length, $hash_length);
149
+		$encrypted_text_raw = substr($encrypted_text, $iv_length + $hash_length);
150
+		// rehash the original raw encrypted text
151
+		$rehash_mac = hash_hmac($this->getHashAlgorithm(), $encrypted_text_raw, $key, true);
152
+		// timing attack safe comparison to determine if anything has changed
153
+		if (hash_equals($hmac, $rehash_mac)) {
154
+			// looks good, decrypt it, trim it, and return it
155
+			$decrypted_text = openssl_decrypt(
156
+				$encrypted_text_raw,
157
+				$this->cipher_method->getCipherMethod(),
158
+				$key,
159
+				0,
160
+				$iv
161
+			);
162
+			$this->validateDecryption($decrypted_text);
163
+			return trim($this->base64_encoder->decodeString($decrypted_text));
164
+		}
165
+		throw new RuntimeException(
166
+			esc_html__(
167
+				'Decryption failed because a hash comparison of the original text and the decrypted text was not the same, meaning something in the system or the encrypted data has changed.',
168
+				'event_espresso'
169
+			)
170
+		);
171
+	}
172 172
 }
Please login to merge, or discard this patch.
core/services/encryption/openssl/CipherMethod.php 2 patches
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -15,206 +15,206 @@
 block discarded – undo
15 15
 class CipherMethod
16 16
 {
17 17
 
18
-    /**
19
-     * @var string
20
-     */
21
-    protected $cipher_method_option_name;
22
-
23
-    /**
24
-     * list of cipher methods that we consider usable,
25
-     * essentially all of the installed_cipher_methods minus weak_algorithms
26
-     *
27
-     * @var array
28
-     */
29
-    protected $cipher_methods = [];
30
-
31
-    /**
32
-     * @var string
33
-     */
34
-    protected $default_cipher_method;
35
-
36
-    /**
37
-     * list of ALL cipher methods available on the server
38
-     *
39
-     * @var array
40
-     */
41
-    protected $installed_cipher_methods;
42
-
43
-    /**
44
-     * the OpenSSL cipher method to use. default: AES-128-CBC
45
-     *
46
-     * @var string
47
-     */
48
-    protected $validated_cipher_method;
49
-
50
-    /**
51
-     * as early as Aug 2016, Openssl declared the following weak: RC2, RC4, DES, 3DES, MD5 based
52
-     * and ECB mode should be avoided
53
-     *
54
-     * @var array
55
-     */
56
-    protected $weak_algorithms = ['des', 'ecb', 'md5', 'rc2', 'rc4'];
57
-
58
-
59
-    /**
60
-     * @param string $default_cipher_method
61
-     * @param string $cipher_method_option_name
62
-     */
63
-    public function __construct($default_cipher_method, $cipher_method_option_name)
64
-    {
65
-        $this->default_cipher_method     = $default_cipher_method;
66
-        $this->cipher_method_option_name = $cipher_method_option_name;
67
-        $this->installed_cipher_methods  = openssl_get_cipher_methods();
68
-    }
69
-
70
-
71
-    /**
72
-     * Returns a cipher method that has been verified to work.
73
-     * First checks if the cached cipher has been set already and if so, returns that.
74
-     * Then tests the incoming default and returns that if it's good.
75
-     * If not, then it retrieves the previously tested and saved cipher method.
76
-     * But if that doesn't exist, then calls getAvailableCipherMethod()
77
-     * to see what is available on the server, and returns the results.
78
-     *
79
-     * @param string $cipher_method
80
-     * @param bool   $load_alternate [optional] if TRUE, will load the default cipher method (or any strong algorithm)
81
-     *                               if the requested cipher method is not installed or invalid.
82
-     *                               if FALSE, will throw an exception if the requested cipher method is not valid.
83
-     * @return string
84
-     * @throws RuntimeException
85
-     */
86
-    public function getCipherMethod($cipher_method = null, $load_alternate = true)
87
-    {
88
-        if (empty($cipher_method) && $this->validated_cipher_method !== null) {
89
-            return $this->validated_cipher_method;
90
-        }
91
-        // if nothing specific was requested and it's ok to load an alternate, then grab the system default
92
-        if (empty($cipher_method) && $load_alternate) {
93
-            $cipher_method = $this->default_cipher_method;
94
-        }
95
-        // verify that the cipher method can produce an initialization vector.
96
-        // but if the requested is invalid and we don't want to load an alternate, then throw an exception
97
-        $throw_exception = ! $load_alternate;
98
-        if ($this->validateCipherMethod($cipher_method, $throw_exception) === false) {
99
-            // nope? ... ok let's see what we can find
100
-            $cipher_method = $this->getAvailableCipherMethod();
101
-        }
102
-        // if nothing has been previously validated, then save the currently requested cipher which appears to be good
103
-        if ($this->validated_cipher_method === null) {
104
-            $this->validated_cipher_method = $cipher_method;
105
-        }
106
-        return $cipher_method;
107
-    }
108
-
109
-
110
-    /**
111
-     * returns true if the selected cipher method either uses Galois/Counter Mode (GCM)
112
-     * or Counter with CBC-MAC (CCM) authenticated encryption modes
113
-     * (also need to be using PHP 7.1 or greater to actually use authenticated encryption modes)
114
-     *
115
-     * @return bool
116
-     */
117
-    public function usesAuthenticatedEncryptionMode()
118
-    {
119
-        return PHP_VERSION_ID >= 70100
120
-               && (
121
-                   stripos($this->validated_cipher_method, 'gcm') !== false
122
-                   || stripos($this->validated_cipher_method, 'ccm') !== false
123
-               );
124
-    }
125
-
126
-
127
-    /**
128
-     * @param string $cipher_method
129
-     * @return string
130
-     * @throws RuntimeException
131
-     */
132
-    protected function getAvailableCipherMethod($cipher_method = null)
133
-    {
134
-        // if nothing was supplied, the get what we found in the past to work
135
-        $cipher_method_to_test = $cipher_method ?: get_option($this->cipher_method_option_name, '');
136
-        // verify that the incoming cipher method exists and can produce an initialization vector
137
-        if ($this->validateCipherMethod($cipher_method_to_test) === false) {
138
-            // what? there's no list?
139
-            if (empty($this->cipher_methods)) {
140
-                // generate that list and cache it
141
-                $this->cipher_methods = $this->getAvailableStrongCipherMethods();
142
-            }
143
-            // then grab the first item from the list (we'll add it back later if it is good)
144
-            $cipher_method_to_test = array_shift($this->cipher_methods);
145
-            if ($cipher_method_to_test === null) {
146
-                throw new RuntimeException(
147
-                    esc_html__(
148
-                        'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.',
149
-                        'event_espresso'
150
-                    )
151
-                );
152
-            }
153
-            // verify that the next cipher method works
154
-            return $this->getAvailableCipherMethod($cipher_method_to_test);
155
-        }
156
-        // if we've gotten this far, then we found an available cipher method that works
157
-        // so save that for next time, if it's not the same as what's there already
158
-        if ($cipher_method_to_test !== $cipher_method) {
159
-            update_option($this->cipher_method_option_name, $cipher_method_to_test);
160
-        }
161
-        // if we previously removed this cipher method from the list of valid ones, then let's put it back
162
-        if (! in_array($cipher_method_to_test, $this->cipher_methods, true)) {
163
-            array_unshift($this->cipher_methods, $cipher_method_to_test);
164
-        }
165
-        return $cipher_method_to_test;
166
-    }
167
-
168
-
169
-    /**
170
-     * @return array
171
-     */
172
-    protected function getAvailableStrongCipherMethods()
173
-    {
174
-        return array_filter($this->installed_cipher_methods, [$this, 'weakAlgorithmFilter']);
175
-    }
176
-
177
-
178
-    /**
179
-     * @param string $cipher_method
180
-     * @param false  $throw_exception
181
-     * @return bool
182
-     */
183
-    protected function validateCipherMethod($cipher_method, $throw_exception = false)
184
-    {
185
-        // verify that the requested cipher method is actually installed and can produce an initialization vector
186
-        if (
187
-            in_array($cipher_method, $this->installed_cipher_methods, true)
188
-            && openssl_cipher_iv_length($cipher_method) !== false
189
-        ) {
190
-            return true;
191
-        }
192
-        if (! $throw_exception) {
193
-            return false;
194
-        }
195
-        throw new RuntimeException(
196
-            sprintf(
197
-                esc_html__(
198
-                    'The requested OpenSSL cipher method "%1$s" is invalid or not installed on the server. Please contact the server administrator.',
199
-                    'event_espresso'
200
-                ),
201
-                $cipher_method
202
-            )
203
-        );
204
-    }
205
-
206
-
207
-    /**
208
-     * @see https://www.php.net/manual/en/function.openssl-get-cipher-methods.php#example-890
209
-     * @param string $cipher_method
210
-     */
211
-    protected function weakAlgorithmFilter($cipher_method)
212
-    {
213
-        foreach ($this->weak_algorithms as $weak_algorithm) {
214
-            if (stripos($cipher_method, $weak_algorithm) !== false) {
215
-                return false;
216
-            }
217
-        }
218
-        return true;
219
-    }
18
+	/**
19
+	 * @var string
20
+	 */
21
+	protected $cipher_method_option_name;
22
+
23
+	/**
24
+	 * list of cipher methods that we consider usable,
25
+	 * essentially all of the installed_cipher_methods minus weak_algorithms
26
+	 *
27
+	 * @var array
28
+	 */
29
+	protected $cipher_methods = [];
30
+
31
+	/**
32
+	 * @var string
33
+	 */
34
+	protected $default_cipher_method;
35
+
36
+	/**
37
+	 * list of ALL cipher methods available on the server
38
+	 *
39
+	 * @var array
40
+	 */
41
+	protected $installed_cipher_methods;
42
+
43
+	/**
44
+	 * the OpenSSL cipher method to use. default: AES-128-CBC
45
+	 *
46
+	 * @var string
47
+	 */
48
+	protected $validated_cipher_method;
49
+
50
+	/**
51
+	 * as early as Aug 2016, Openssl declared the following weak: RC2, RC4, DES, 3DES, MD5 based
52
+	 * and ECB mode should be avoided
53
+	 *
54
+	 * @var array
55
+	 */
56
+	protected $weak_algorithms = ['des', 'ecb', 'md5', 'rc2', 'rc4'];
57
+
58
+
59
+	/**
60
+	 * @param string $default_cipher_method
61
+	 * @param string $cipher_method_option_name
62
+	 */
63
+	public function __construct($default_cipher_method, $cipher_method_option_name)
64
+	{
65
+		$this->default_cipher_method     = $default_cipher_method;
66
+		$this->cipher_method_option_name = $cipher_method_option_name;
67
+		$this->installed_cipher_methods  = openssl_get_cipher_methods();
68
+	}
69
+
70
+
71
+	/**
72
+	 * Returns a cipher method that has been verified to work.
73
+	 * First checks if the cached cipher has been set already and if so, returns that.
74
+	 * Then tests the incoming default and returns that if it's good.
75
+	 * If not, then it retrieves the previously tested and saved cipher method.
76
+	 * But if that doesn't exist, then calls getAvailableCipherMethod()
77
+	 * to see what is available on the server, and returns the results.
78
+	 *
79
+	 * @param string $cipher_method
80
+	 * @param bool   $load_alternate [optional] if TRUE, will load the default cipher method (or any strong algorithm)
81
+	 *                               if the requested cipher method is not installed or invalid.
82
+	 *                               if FALSE, will throw an exception if the requested cipher method is not valid.
83
+	 * @return string
84
+	 * @throws RuntimeException
85
+	 */
86
+	public function getCipherMethod($cipher_method = null, $load_alternate = true)
87
+	{
88
+		if (empty($cipher_method) && $this->validated_cipher_method !== null) {
89
+			return $this->validated_cipher_method;
90
+		}
91
+		// if nothing specific was requested and it's ok to load an alternate, then grab the system default
92
+		if (empty($cipher_method) && $load_alternate) {
93
+			$cipher_method = $this->default_cipher_method;
94
+		}
95
+		// verify that the cipher method can produce an initialization vector.
96
+		// but if the requested is invalid and we don't want to load an alternate, then throw an exception
97
+		$throw_exception = ! $load_alternate;
98
+		if ($this->validateCipherMethod($cipher_method, $throw_exception) === false) {
99
+			// nope? ... ok let's see what we can find
100
+			$cipher_method = $this->getAvailableCipherMethod();
101
+		}
102
+		// if nothing has been previously validated, then save the currently requested cipher which appears to be good
103
+		if ($this->validated_cipher_method === null) {
104
+			$this->validated_cipher_method = $cipher_method;
105
+		}
106
+		return $cipher_method;
107
+	}
108
+
109
+
110
+	/**
111
+	 * returns true if the selected cipher method either uses Galois/Counter Mode (GCM)
112
+	 * or Counter with CBC-MAC (CCM) authenticated encryption modes
113
+	 * (also need to be using PHP 7.1 or greater to actually use authenticated encryption modes)
114
+	 *
115
+	 * @return bool
116
+	 */
117
+	public function usesAuthenticatedEncryptionMode()
118
+	{
119
+		return PHP_VERSION_ID >= 70100
120
+			   && (
121
+				   stripos($this->validated_cipher_method, 'gcm') !== false
122
+				   || stripos($this->validated_cipher_method, 'ccm') !== false
123
+			   );
124
+	}
125
+
126
+
127
+	/**
128
+	 * @param string $cipher_method
129
+	 * @return string
130
+	 * @throws RuntimeException
131
+	 */
132
+	protected function getAvailableCipherMethod($cipher_method = null)
133
+	{
134
+		// if nothing was supplied, the get what we found in the past to work
135
+		$cipher_method_to_test = $cipher_method ?: get_option($this->cipher_method_option_name, '');
136
+		// verify that the incoming cipher method exists and can produce an initialization vector
137
+		if ($this->validateCipherMethod($cipher_method_to_test) === false) {
138
+			// what? there's no list?
139
+			if (empty($this->cipher_methods)) {
140
+				// generate that list and cache it
141
+				$this->cipher_methods = $this->getAvailableStrongCipherMethods();
142
+			}
143
+			// then grab the first item from the list (we'll add it back later if it is good)
144
+			$cipher_method_to_test = array_shift($this->cipher_methods);
145
+			if ($cipher_method_to_test === null) {
146
+				throw new RuntimeException(
147
+					esc_html__(
148
+						'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.',
149
+						'event_espresso'
150
+					)
151
+				);
152
+			}
153
+			// verify that the next cipher method works
154
+			return $this->getAvailableCipherMethod($cipher_method_to_test);
155
+		}
156
+		// if we've gotten this far, then we found an available cipher method that works
157
+		// so save that for next time, if it's not the same as what's there already
158
+		if ($cipher_method_to_test !== $cipher_method) {
159
+			update_option($this->cipher_method_option_name, $cipher_method_to_test);
160
+		}
161
+		// if we previously removed this cipher method from the list of valid ones, then let's put it back
162
+		if (! in_array($cipher_method_to_test, $this->cipher_methods, true)) {
163
+			array_unshift($this->cipher_methods, $cipher_method_to_test);
164
+		}
165
+		return $cipher_method_to_test;
166
+	}
167
+
168
+
169
+	/**
170
+	 * @return array
171
+	 */
172
+	protected function getAvailableStrongCipherMethods()
173
+	{
174
+		return array_filter($this->installed_cipher_methods, [$this, 'weakAlgorithmFilter']);
175
+	}
176
+
177
+
178
+	/**
179
+	 * @param string $cipher_method
180
+	 * @param false  $throw_exception
181
+	 * @return bool
182
+	 */
183
+	protected function validateCipherMethod($cipher_method, $throw_exception = false)
184
+	{
185
+		// verify that the requested cipher method is actually installed and can produce an initialization vector
186
+		if (
187
+			in_array($cipher_method, $this->installed_cipher_methods, true)
188
+			&& openssl_cipher_iv_length($cipher_method) !== false
189
+		) {
190
+			return true;
191
+		}
192
+		if (! $throw_exception) {
193
+			return false;
194
+		}
195
+		throw new RuntimeException(
196
+			sprintf(
197
+				esc_html__(
198
+					'The requested OpenSSL cipher method "%1$s" is invalid or not installed on the server. Please contact the server administrator.',
199
+					'event_espresso'
200
+				),
201
+				$cipher_method
202
+			)
203
+		);
204
+	}
205
+
206
+
207
+	/**
208
+	 * @see https://www.php.net/manual/en/function.openssl-get-cipher-methods.php#example-890
209
+	 * @param string $cipher_method
210
+	 */
211
+	protected function weakAlgorithmFilter($cipher_method)
212
+	{
213
+		foreach ($this->weak_algorithms as $weak_algorithm) {
214
+			if (stripos($cipher_method, $weak_algorithm) !== false) {
215
+				return false;
216
+			}
217
+		}
218
+		return true;
219
+	}
220 220
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
             update_option($this->cipher_method_option_name, $cipher_method_to_test);
160 160
         }
161 161
         // if we previously removed this cipher method from the list of valid ones, then let's put it back
162
-        if (! in_array($cipher_method_to_test, $this->cipher_methods, true)) {
162
+        if ( ! in_array($cipher_method_to_test, $this->cipher_methods, true)) {
163 163
             array_unshift($this->cipher_methods, $cipher_method_to_test);
164 164
         }
165 165
         return $cipher_method_to_test;
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         ) {
190 190
             return true;
191 191
         }
192
-        if (! $throw_exception) {
192
+        if ( ! $throw_exception) {
193 193
             return false;
194 194
         }
195 195
         throw new RuntimeException(
Please login to merge, or discard this patch.