Completed
Branch BUG/3575-event-deletion-previe... (bbeda1)
by
unknown
06:40 queued 04:49
created
core/services/loaders/LoaderInterface.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -8,57 +8,57 @@
 block discarded – undo
8 8
 interface LoaderInterface
9 9
 {
10 10
 
11
-    /**
12
-     * Can be for instantiating a new instance of a class,
13
-     * or for getting a shared instance of a class (default)
14
-     *
15
-     * @param FullyQualifiedName|string $fqcn
16
-     * @param array                     $arguments
17
-     * @param bool                      $shared
18
-     * @return mixed
19
-     */
20
-    public function load($fqcn, array $arguments = array(), $shared = true);
11
+	/**
12
+	 * Can be for instantiating a new instance of a class,
13
+	 * or for getting a shared instance of a class (default)
14
+	 *
15
+	 * @param FullyQualifiedName|string $fqcn
16
+	 * @param array                     $arguments
17
+	 * @param bool                      $shared
18
+	 * @return mixed
19
+	 */
20
+	public function load($fqcn, array $arguments = array(), $shared = true);
21 21
 
22 22
 
23
-    /**
24
-     * Used for instantiating a new instance of a class
25
-     *
26
-     * @param FullyQualifiedName|string $fqcn
27
-     * @param array                     $arguments
28
-     * @return mixed
29
-     */
30
-    public function getNew($fqcn, array $arguments = array());
23
+	/**
24
+	 * Used for instantiating a new instance of a class
25
+	 *
26
+	 * @param FullyQualifiedName|string $fqcn
27
+	 * @param array                     $arguments
28
+	 * @return mixed
29
+	 */
30
+	public function getNew($fqcn, array $arguments = array());
31 31
 
32 32
 
33
-    /**
34
-     * Used for getting a shared instance of a class
35
-     *
36
-     * @param FullyQualifiedName|string $fqcn
37
-     * @param array                     $arguments
38
-     * @return mixed
39
-     */
40
-    public function getShared($fqcn, array $arguments = array());
33
+	/**
34
+	 * Used for getting a shared instance of a class
35
+	 *
36
+	 * @param FullyQualifiedName|string $fqcn
37
+	 * @param array                     $arguments
38
+	 * @return mixed
39
+	 */
40
+	public function getShared($fqcn, array $arguments = array());
41 41
 
42 42
 
43
-    /**
44
-     * @param FullyQualifiedName|string $fqcn
45
-     * @param mixed                     $object
46
-     * @return bool
47
-     * @throws InvalidArgumentException
48
-     */
49
-    public function share($fqcn, $object);
43
+	/**
44
+	 * @param FullyQualifiedName|string $fqcn
45
+	 * @param mixed                     $object
46
+	 * @return bool
47
+	 * @throws InvalidArgumentException
48
+	 */
49
+	public function share($fqcn, $object);
50 50
 
51 51
 
52
-    /**
53
-     * @param FullyQualifiedName|string $fqcn
54
-     * @return bool
55
-     * @throws InvalidArgumentException
56
-     */
57
-    public function remove($fqcn);
52
+	/**
53
+	 * @param FullyQualifiedName|string $fqcn
54
+	 * @return bool
55
+	 * @throws InvalidArgumentException
56
+	 */
57
+	public function remove($fqcn);
58 58
 
59 59
 
60
-    /**
61
-     * calls reset() on loader if method exists
62
-     */
63
-    public function reset();
60
+	/**
61
+	 * calls reset() on loader if method exists
62
+	 */
63
+	public function reset();
64 64
 }
Please login to merge, or discard this patch.
core/services/request/files/FilesDataHandler.php 2 patches
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -40,279 +40,279 @@
 block discarded – undo
40 40
  */
41 41
 class FilesDataHandler
42 42
 {
43
-    /**
44
-     * @var Request
45
-     */
46
-    protected $request;
43
+	/**
44
+	 * @var Request
45
+	 */
46
+	protected $request;
47 47
 
48
-    /**
49
-     * @var CollectionInterface | FileSubmissionInterface[]
50
-     */
51
-    protected $file_objects;
48
+	/**
49
+	 * @var CollectionInterface | FileSubmissionInterface[]
50
+	 */
51
+	protected $file_objects;
52 52
 
53
-    /**
54
-     * @var bool
55
-     */
56
-    protected $initialized = false;
53
+	/**
54
+	 * @var bool
55
+	 */
56
+	protected $initialized = false;
57 57
 
58 58
 
59
-    /**
60
-     * FilesDataHandler constructor.
61
-     *
62
-     * @param Request $request
63
-     */
64
-    public function __construct(Request $request)
65
-    {
66
-        $this->request = $request;
67
-    }
59
+	/**
60
+	 * FilesDataHandler constructor.
61
+	 *
62
+	 * @param Request $request
63
+	 */
64
+	public function __construct(Request $request)
65
+	{
66
+		$this->request = $request;
67
+	}
68 68
 
69 69
 
70
-    /**
71
-     * @return CollectionInterface | FileSubmissionInterface[]
72
-     * @throws UnexpectedValueException
73
-     * @throws InvalidArgumentException
74
-     * @since 4.9.80.p
75
-     */
76
-    protected function getFileObjects()
77
-    {
78
-        $this->initialize();
79
-        return $this->file_objects;
80
-    }
70
+	/**
71
+	 * @return CollectionInterface | FileSubmissionInterface[]
72
+	 * @throws UnexpectedValueException
73
+	 * @throws InvalidArgumentException
74
+	 * @since 4.9.80.p
75
+	 */
76
+	protected function getFileObjects()
77
+	{
78
+		$this->initialize();
79
+		return $this->file_objects;
80
+	}
81 81
 
82 82
 
83
-    /**
84
-     * Sets up the file objects from the request's $_FILES data.
85
-     *
86
-     * @throws UnexpectedValueException
87
-     * @throws InvalidArgumentException
88
-     * @throws InvalidInterfaceException
89
-     * @since 4.9.80.p
90
-     */
91
-    protected function initialize()
92
-    {
93
-        if ($this->initialized) {
94
-            return;
95
-        }
96
-        $this->file_objects = new Collection(
97
-        // collection interface
98
-            'EventEspresso\core\services\request\files\FileSubmissionInterface',
99
-            // collection name
100
-            'submitted_files'
101
-        );
102
-        $files_raw_data     = $this->request->filesParams();
103
-        if (empty($files_raw_data)) {
104
-            return;
105
-        }
106
-        if ($this->isStrangeFilesArray($files_raw_data)) {
107
-            $data = $this->fixFilesDataArray($files_raw_data);
108
-        } else {
109
-            $data = $files_raw_data;
110
-        }
111
-        $this->createFileObjects($data);
112
-        $this->initialized = true;
113
-    }
83
+	/**
84
+	 * Sets up the file objects from the request's $_FILES data.
85
+	 *
86
+	 * @throws UnexpectedValueException
87
+	 * @throws InvalidArgumentException
88
+	 * @throws InvalidInterfaceException
89
+	 * @since 4.9.80.p
90
+	 */
91
+	protected function initialize()
92
+	{
93
+		if ($this->initialized) {
94
+			return;
95
+		}
96
+		$this->file_objects = new Collection(
97
+		// collection interface
98
+			'EventEspresso\core\services\request\files\FileSubmissionInterface',
99
+			// collection name
100
+			'submitted_files'
101
+		);
102
+		$files_raw_data     = $this->request->filesParams();
103
+		if (empty($files_raw_data)) {
104
+			return;
105
+		}
106
+		if ($this->isStrangeFilesArray($files_raw_data)) {
107
+			$data = $this->fixFilesDataArray($files_raw_data);
108
+		} else {
109
+			$data = $files_raw_data;
110
+		}
111
+		$this->createFileObjects($data);
112
+		$this->initialized = true;
113
+	}
114 114
 
115 115
 
116
-    /**
117
-     * Detects if $_FILES is a weird multi-dimensional array that needs fixing or not.
118
-     *
119
-     * @param $files_data
120
-     * @return bool
121
-     * @throws UnexpectedValueException
122
-     * @since 4.9.80.p
123
-     */
124
-    protected function isStrangeFilesArray($files_data)
125
-    {
126
-        if (! is_array($files_data)) {
127
-            throw new UnexpectedValueException(
128
-                sprintf(
129
-                    esc_html__(
130
-                        'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.',
131
-                        'event_espresso'
132
-                    ),
133
-                    (string) $files_data
134
-                )
135
-            );
136
-        }
137
-        $first_value = reset($files_data);
138
-        if (! is_array($first_value)) {
139
-            throw new UnexpectedValueException(
140
-                sprintf(
141
-                    esc_html__(
142
-                        'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.',
143
-                        'event_espresso'
144
-                    ),
145
-                    (string) $first_value
146
-                )
147
-            );
148
-        }
149
-        $first_sub_array_item = reset($first_value);
150
-        if (is_array($first_sub_array_item)) {
151
-            // not just a 2d array
152
-            return true;
153
-        }
154
-        // yep, just 2d array
155
-        return false;
156
-    }
116
+	/**
117
+	 * Detects if $_FILES is a weird multi-dimensional array that needs fixing or not.
118
+	 *
119
+	 * @param $files_data
120
+	 * @return bool
121
+	 * @throws UnexpectedValueException
122
+	 * @since 4.9.80.p
123
+	 */
124
+	protected function isStrangeFilesArray($files_data)
125
+	{
126
+		if (! is_array($files_data)) {
127
+			throw new UnexpectedValueException(
128
+				sprintf(
129
+					esc_html__(
130
+						'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.',
131
+						'event_espresso'
132
+					),
133
+					(string) $files_data
134
+				)
135
+			);
136
+		}
137
+		$first_value = reset($files_data);
138
+		if (! is_array($first_value)) {
139
+			throw new UnexpectedValueException(
140
+				sprintf(
141
+					esc_html__(
142
+						'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.',
143
+						'event_espresso'
144
+					),
145
+					(string) $first_value
146
+				)
147
+			);
148
+		}
149
+		$first_sub_array_item = reset($first_value);
150
+		if (is_array($first_sub_array_item)) {
151
+			// not just a 2d array
152
+			return true;
153
+		}
154
+		// yep, just 2d array
155
+		return false;
156
+	}
157 157
 
158 158
 
159
-    /**
160
-     * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file"
161
-     * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with
162
-     * "name", "size", "tmp_name", etc. So that file's data is located at "my[name][hierarchical][form]",
163
-     * "my[size][hierarchical][form]", "my[tmp_name][hierarchical][form]", etc. It's really weird.
164
-     *
165
-     * @param $files_data
166
-     * @return array
167
-     * @since 4.9.80.p
168
-     */
169
-    protected function fixFilesDataArray($files_data)
170
-    {
171
-        $sane_files_array = [];
172
-        foreach ($files_data as $top_level_name => $top_level_children) {
173
-            $sub_array                           = [];
174
-            $sane_files_array[ $top_level_name ] = [];
175
-            foreach ($top_level_children as $file_data_part => $second_level_children) {
176
-                foreach ($second_level_children as $next_level_name => $sub_values) {
177
-                    $sub_array[ $next_level_name ] = $this->organizeFilesData($sub_values, $file_data_part);
178
-                }
179
-                $sane_files_array[ $top_level_name ] = array_replace_recursive(
180
-                    $sub_array,
181
-                    $sane_files_array[ $top_level_name ]
182
-                );
183
-            }
184
-        }
185
-        return $sane_files_array;
186
-    }
159
+	/**
160
+	 * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file"
161
+	 * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with
162
+	 * "name", "size", "tmp_name", etc. So that file's data is located at "my[name][hierarchical][form]",
163
+	 * "my[size][hierarchical][form]", "my[tmp_name][hierarchical][form]", etc. It's really weird.
164
+	 *
165
+	 * @param $files_data
166
+	 * @return array
167
+	 * @since 4.9.80.p
168
+	 */
169
+	protected function fixFilesDataArray($files_data)
170
+	{
171
+		$sane_files_array = [];
172
+		foreach ($files_data as $top_level_name => $top_level_children) {
173
+			$sub_array                           = [];
174
+			$sane_files_array[ $top_level_name ] = [];
175
+			foreach ($top_level_children as $file_data_part => $second_level_children) {
176
+				foreach ($second_level_children as $next_level_name => $sub_values) {
177
+					$sub_array[ $next_level_name ] = $this->organizeFilesData($sub_values, $file_data_part);
178
+				}
179
+				$sane_files_array[ $top_level_name ] = array_replace_recursive(
180
+					$sub_array,
181
+					$sane_files_array[ $top_level_name ]
182
+				);
183
+			}
184
+		}
185
+		return $sane_files_array;
186
+	}
187 187
 
188 188
 
189
-    /**
190
-     * Recursively explores the array until it finds a leaf node, and tacks `$type` as a final index in front of it.
191
-     *
192
-     * @param $data array|string
193
-     * @param $type 'name', 'tmp_name', 'size', or 'error'
194
-     * @return array
195
-     * @since 4.9.80.p
196
-     */
197
-    protected function organizeFilesData($data, $type)
198
-    {
199
-        if (! is_array($data)) {
200
-            return [
201
-                $type => $data,
202
-            ];
203
-        }
204
-        $organized_data = [];
205
-        foreach ($data as $input_name_part => $sub_inputs_or_value) {
206
-            if (is_array($sub_inputs_or_value)) {
207
-                $organized_data[ $input_name_part ] = $this->organizeFilesData($sub_inputs_or_value, $type);
208
-            } else {
209
-                $organized_data[ $input_name_part ][ $type ] = $sub_inputs_or_value;
210
-            }
211
-        }
212
-        return $organized_data;
213
-    }
189
+	/**
190
+	 * Recursively explores the array until it finds a leaf node, and tacks `$type` as a final index in front of it.
191
+	 *
192
+	 * @param $data array|string
193
+	 * @param $type 'name', 'tmp_name', 'size', or 'error'
194
+	 * @return array
195
+	 * @since 4.9.80.p
196
+	 */
197
+	protected function organizeFilesData($data, $type)
198
+	{
199
+		if (! is_array($data)) {
200
+			return [
201
+				$type => $data,
202
+			];
203
+		}
204
+		$organized_data = [];
205
+		foreach ($data as $input_name_part => $sub_inputs_or_value) {
206
+			if (is_array($sub_inputs_or_value)) {
207
+				$organized_data[ $input_name_part ] = $this->organizeFilesData($sub_inputs_or_value, $type);
208
+			} else {
209
+				$organized_data[ $input_name_part ][ $type ] = $sub_inputs_or_value;
210
+			}
211
+		}
212
+		return $organized_data;
213
+	}
214 214
 
215 215
 
216
-    /**
217
-     * Takes the organized $_FILES array (where all file info is located at the same spot as you'd expect an input
218
-     * to be in post data, with all the file's data located side-by-side in an array) and creates a
219
-     * multi-dimensional array of FileSubmissionInterface objects. Stores it in `$this->file_objects`.
220
-     *
221
-     * @param array $organized_files   $_FILES but organized like $_POST
222
-     * @param array $name_parts_so_far for multidimensional HTML form names,
223
-     * @throws UnexpectedValueException
224
-     * @throws InvalidArgumentException
225
-     * @since 4.9.80.p
226
-     */
227
-    protected function createFileObjects($organized_files, $name_parts_so_far = [])
228
-    {
229
-        if (! is_array($organized_files)) {
230
-            throw new UnexpectedValueException(
231
-                sprintf(
232
-                    esc_html__(
233
-                        'Unexpected PHP $organized_files data format. "%1$s" was expected to be an array.',
234
-                        'event_espresso'
235
-                    ),
236
-                    (string) $organized_files
237
-                )
238
-            );
239
-        }
240
-        foreach ($organized_files as $key => $value) {
241
-            $this_input_name_parts = $name_parts_so_far;
242
-            array_push(
243
-                $this_input_name_parts,
244
-                $key
245
-            );
246
-            if (isset($value['name'], $value['tmp_name'], $value['size'])) {
247
-                $html_name = $this->inputNameFromParts($this_input_name_parts);
248
-                $this->file_objects->add(
249
-                    new FileSubmission(
250
-                        $value['name'],
251
-                        $value['tmp_name'],
252
-                        $value['size'],
253
-                        $value['error']
254
-                    ),
255
-                    $html_name
256
-                );
257
-            } else {
258
-                $this->createFileObjects($value, $this_input_name_parts);
259
-            }
260
-        }
261
-    }
216
+	/**
217
+	 * Takes the organized $_FILES array (where all file info is located at the same spot as you'd expect an input
218
+	 * to be in post data, with all the file's data located side-by-side in an array) and creates a
219
+	 * multi-dimensional array of FileSubmissionInterface objects. Stores it in `$this->file_objects`.
220
+	 *
221
+	 * @param array $organized_files   $_FILES but organized like $_POST
222
+	 * @param array $name_parts_so_far for multidimensional HTML form names,
223
+	 * @throws UnexpectedValueException
224
+	 * @throws InvalidArgumentException
225
+	 * @since 4.9.80.p
226
+	 */
227
+	protected function createFileObjects($organized_files, $name_parts_so_far = [])
228
+	{
229
+		if (! is_array($organized_files)) {
230
+			throw new UnexpectedValueException(
231
+				sprintf(
232
+					esc_html__(
233
+						'Unexpected PHP $organized_files data format. "%1$s" was expected to be an array.',
234
+						'event_espresso'
235
+					),
236
+					(string) $organized_files
237
+				)
238
+			);
239
+		}
240
+		foreach ($organized_files as $key => $value) {
241
+			$this_input_name_parts = $name_parts_so_far;
242
+			array_push(
243
+				$this_input_name_parts,
244
+				$key
245
+			);
246
+			if (isset($value['name'], $value['tmp_name'], $value['size'])) {
247
+				$html_name = $this->inputNameFromParts($this_input_name_parts);
248
+				$this->file_objects->add(
249
+					new FileSubmission(
250
+						$value['name'],
251
+						$value['tmp_name'],
252
+						$value['size'],
253
+						$value['error']
254
+					),
255
+					$html_name
256
+				);
257
+			} else {
258
+				$this->createFileObjects($value, $this_input_name_parts);
259
+			}
260
+		}
261
+	}
262 262
 
263 263
 
264
-    /**
265
-     * Takes the input name parts, like `['my', 'great', 'file', 'input1']`
266
-     * and returns the HTML name for it, "my[great][file][input1]"
267
-     *
268
-     * @throws UnexpectedValueException
269
-     * @since 4.9.80.p
270
-     */
271
-    protected function inputNameFromParts($parts)
272
-    {
273
-        if (! is_array($parts)) {
274
-            throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso'));
275
-        }
276
-        $generated_string = '';
277
-        foreach ($parts as $part) {
278
-            $part = (string) $part;
279
-            // wrap all but the first part in []
280
-            $generated_string .= $generated_string === '' ? $part : '[' . $part . ']';
281
-        }
282
-        return $generated_string;
283
-    }
264
+	/**
265
+	 * Takes the input name parts, like `['my', 'great', 'file', 'input1']`
266
+	 * and returns the HTML name for it, "my[great][file][input1]"
267
+	 *
268
+	 * @throws UnexpectedValueException
269
+	 * @since 4.9.80.p
270
+	 */
271
+	protected function inputNameFromParts($parts)
272
+	{
273
+		if (! is_array($parts)) {
274
+			throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso'));
275
+		}
276
+		$generated_string = '';
277
+		foreach ($parts as $part) {
278
+			$part = (string) $part;
279
+			// wrap all but the first part in []
280
+			$generated_string .= $generated_string === '' ? $part : '[' . $part . ']';
281
+		}
282
+		return $generated_string;
283
+	}
284 284
 
285 285
 
286
-    /**
287
-     * Gets the input by the indicated $name_parts.
288
-     * Eg if you're looking for an input named "my[great][file][input1]", $name_parts
289
-     * should be `['my', 'great', 'file', 'input1']`.
290
-     * Alternatively, you could use `FileDataHandler::getFileObject('my[great][file][input1]');`
291
-     *
292
-     * @param $name_parts
293
-     * @return FileSubmissionInterface
294
-     * @throws UnexpectedValueException
295
-     * @since 4.9.80.p
296
-     */
297
-    public function getFileObjectFromNameParts($name_parts)
298
-    {
299
-        return $this->getFileObjects()->get($this->inputNameFromParts($name_parts));
300
-    }
286
+	/**
287
+	 * Gets the input by the indicated $name_parts.
288
+	 * Eg if you're looking for an input named "my[great][file][input1]", $name_parts
289
+	 * should be `['my', 'great', 'file', 'input1']`.
290
+	 * Alternatively, you could use `FileDataHandler::getFileObject('my[great][file][input1]');`
291
+	 *
292
+	 * @param $name_parts
293
+	 * @return FileSubmissionInterface
294
+	 * @throws UnexpectedValueException
295
+	 * @since 4.9.80.p
296
+	 */
297
+	public function getFileObjectFromNameParts($name_parts)
298
+	{
299
+		return $this->getFileObjects()->get($this->inputNameFromParts($name_parts));
300
+	}
301 301
 
302 302
 
303
-    /**
304
-     * Gets the FileSubmissionInterface corresponding to the HTML name provided.
305
-     *
306
-     * @param $html_name
307
-     * @return mixed
308
-     * @throws InvalidArgumentException
309
-     * @throws UnexpectedValueException
310
-     * @since 4.9.80.p
311
-     */
312
-    public function getFileObject($html_name)
313
-    {
314
-        return $this->getFileObjects()->get($html_name);
315
-    }
303
+	/**
304
+	 * Gets the FileSubmissionInterface corresponding to the HTML name provided.
305
+	 *
306
+	 * @param $html_name
307
+	 * @return mixed
308
+	 * @throws InvalidArgumentException
309
+	 * @throws UnexpectedValueException
310
+	 * @since 4.9.80.p
311
+	 */
312
+	public function getFileObject($html_name)
313
+	{
314
+		return $this->getFileObjects()->get($html_name);
315
+	}
316 316
 }
317 317
 // End of file FilesDataHandler.php
318 318
 // Location: EventEspresso\core\services\request\files/FilesDataHandler.php
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
             // collection name
100 100
             'submitted_files'
101 101
         );
102
-        $files_raw_data     = $this->request->filesParams();
102
+        $files_raw_data = $this->request->filesParams();
103 103
         if (empty($files_raw_data)) {
104 104
             return;
105 105
         }
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
      */
124 124
     protected function isStrangeFilesArray($files_data)
125 125
     {
126
-        if (! is_array($files_data)) {
126
+        if ( ! is_array($files_data)) {
127 127
             throw new UnexpectedValueException(
128 128
                 sprintf(
129 129
                     esc_html__(
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
             );
136 136
         }
137 137
         $first_value = reset($files_data);
138
-        if (! is_array($first_value)) {
138
+        if ( ! is_array($first_value)) {
139 139
             throw new UnexpectedValueException(
140 140
                 sprintf(
141 141
                     esc_html__(
@@ -171,14 +171,14 @@  discard block
 block discarded – undo
171 171
         $sane_files_array = [];
172 172
         foreach ($files_data as $top_level_name => $top_level_children) {
173 173
             $sub_array                           = [];
174
-            $sane_files_array[ $top_level_name ] = [];
174
+            $sane_files_array[$top_level_name] = [];
175 175
             foreach ($top_level_children as $file_data_part => $second_level_children) {
176 176
                 foreach ($second_level_children as $next_level_name => $sub_values) {
177
-                    $sub_array[ $next_level_name ] = $this->organizeFilesData($sub_values, $file_data_part);
177
+                    $sub_array[$next_level_name] = $this->organizeFilesData($sub_values, $file_data_part);
178 178
                 }
179
-                $sane_files_array[ $top_level_name ] = array_replace_recursive(
179
+                $sane_files_array[$top_level_name] = array_replace_recursive(
180 180
                     $sub_array,
181
-                    $sane_files_array[ $top_level_name ]
181
+                    $sane_files_array[$top_level_name]
182 182
                 );
183 183
             }
184 184
         }
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
      */
197 197
     protected function organizeFilesData($data, $type)
198 198
     {
199
-        if (! is_array($data)) {
199
+        if ( ! is_array($data)) {
200 200
             return [
201 201
                 $type => $data,
202 202
             ];
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
         $organized_data = [];
205 205
         foreach ($data as $input_name_part => $sub_inputs_or_value) {
206 206
             if (is_array($sub_inputs_or_value)) {
207
-                $organized_data[ $input_name_part ] = $this->organizeFilesData($sub_inputs_or_value, $type);
207
+                $organized_data[$input_name_part] = $this->organizeFilesData($sub_inputs_or_value, $type);
208 208
             } else {
209
-                $organized_data[ $input_name_part ][ $type ] = $sub_inputs_or_value;
209
+                $organized_data[$input_name_part][$type] = $sub_inputs_or_value;
210 210
             }
211 211
         }
212 212
         return $organized_data;
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
      */
227 227
     protected function createFileObjects($organized_files, $name_parts_so_far = [])
228 228
     {
229
-        if (! is_array($organized_files)) {
229
+        if ( ! is_array($organized_files)) {
230 230
             throw new UnexpectedValueException(
231 231
                 sprintf(
232 232
                     esc_html__(
@@ -270,14 +270,14 @@  discard block
 block discarded – undo
270 270
      */
271 271
     protected function inputNameFromParts($parts)
272 272
     {
273
-        if (! is_array($parts)) {
273
+        if ( ! is_array($parts)) {
274 274
             throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso'));
275 275
         }
276 276
         $generated_string = '';
277 277
         foreach ($parts as $part) {
278 278
             $part = (string) $part;
279 279
             // wrap all but the first part in []
280
-            $generated_string .= $generated_string === '' ? $part : '[' . $part . ']';
280
+            $generated_string .= $generated_string === '' ? $part : '['.$part.']';
281 281
         }
282 282
         return $generated_string;
283 283
     }
Please login to merge, or discard this patch.
core/services/request/sanitizers/ServerSanitizer.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -11,59 +11,59 @@
 block discarded – undo
11 11
  */
12 12
 class ServerSanitizer
13 13
 {
14
-    /**
15
-     * @param string $value
16
-     * @return mixed|string
17
-     */
18
-    public function clean($key, $value)
19
-    {
20
-        switch ($key) {
21
-            case 'AUTH_TYPE':
22
-                $valid_types = [
23
-                    'Basic',
24
-                    'Bearer',
25
-                    'Digest',
26
-                    'HOBA',
27
-                    'Mutual',
28
-                    'Negotiate',
29
-                    'OAuth',
30
-                    'SCRAM-SHA-1',
31
-                    'SCRAM-SHA-256',
32
-                    'vapid',
33
-                ];
34
-                return in_array($value, $valid_types, true) ? $value : 'Basic';
35
-            case 'argc':
36
-            case 'HTTP_DNT':
37
-            case 'HTTP_UPGRADE_INSECURE_REQUESTS':
38
-            case 'SERVER_PORT':
39
-            case 'REMOTE_PORT':
40
-            case 'REQUEST_TIME':
41
-                return (int) filter_var($value, FILTER_SANITIZE_NUMBER_INT);
42
-            case 'REQUEST_TIME_FLOAT':
43
-                return (float) filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
44
-            case 'REQUEST_METHOD':
45
-                $valid_types = [
46
-                    'CONNECT',
47
-                    'DELETE',
48
-                    'GET',
49
-                    'HEAD',
50
-                    'OPTIONS',
51
-                    'PATCH',
52
-                    'POST',
53
-                    'PUT',
54
-                    'TRACE',
55
-                ];
56
-                return in_array($value, $valid_types, true) ? $value : 'GET';
57
-            case 'HTTP_HOST':
58
-            case 'QUERY_STRING':
59
-            case 'REQUEST_URI':
60
-            case 'SCRIPT_NAME':
61
-            case 'SERVER_NAME':
62
-                return filter_var($value, FILTER_SANITIZE_URL);
63
-            case 'SERVER_ADMIN':
64
-                return filter_var($value, FILTER_SANITIZE_EMAIL);
65
-            default:
66
-                return filter_var($value, FILTER_SANITIZE_STRING);
67
-        }
68
-    }
14
+	/**
15
+	 * @param string $value
16
+	 * @return mixed|string
17
+	 */
18
+	public function clean($key, $value)
19
+	{
20
+		switch ($key) {
21
+			case 'AUTH_TYPE':
22
+				$valid_types = [
23
+					'Basic',
24
+					'Bearer',
25
+					'Digest',
26
+					'HOBA',
27
+					'Mutual',
28
+					'Negotiate',
29
+					'OAuth',
30
+					'SCRAM-SHA-1',
31
+					'SCRAM-SHA-256',
32
+					'vapid',
33
+				];
34
+				return in_array($value, $valid_types, true) ? $value : 'Basic';
35
+			case 'argc':
36
+			case 'HTTP_DNT':
37
+			case 'HTTP_UPGRADE_INSECURE_REQUESTS':
38
+			case 'SERVER_PORT':
39
+			case 'REMOTE_PORT':
40
+			case 'REQUEST_TIME':
41
+				return (int) filter_var($value, FILTER_SANITIZE_NUMBER_INT);
42
+			case 'REQUEST_TIME_FLOAT':
43
+				return (float) filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
44
+			case 'REQUEST_METHOD':
45
+				$valid_types = [
46
+					'CONNECT',
47
+					'DELETE',
48
+					'GET',
49
+					'HEAD',
50
+					'OPTIONS',
51
+					'PATCH',
52
+					'POST',
53
+					'PUT',
54
+					'TRACE',
55
+				];
56
+				return in_array($value, $valid_types, true) ? $value : 'GET';
57
+			case 'HTTP_HOST':
58
+			case 'QUERY_STRING':
59
+			case 'REQUEST_URI':
60
+			case 'SCRIPT_NAME':
61
+			case 'SERVER_NAME':
62
+				return filter_var($value, FILTER_SANITIZE_URL);
63
+			case 'SERVER_ADMIN':
64
+				return filter_var($value, FILTER_SANITIZE_EMAIL);
65
+			default:
66
+				return filter_var($value, FILTER_SANITIZE_STRING);
67
+		}
68
+	}
69 69
 }
Please login to merge, or discard this patch.
core/services/request/RequestParams.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     {
97 97
         // don't allow "ee" to be overwritten unless explicitly instructed to do so
98 98
         if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
99
-            $this->request[ $key ] = $value;
99
+            $this->request[$key] = $value;
100 100
         }
101 101
     }
102 102
 
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
             preg_quote($pattern, '/')
200 200
         );
201 201
         foreach ($request_params as $key => $request_param) {
202
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
202
+            if (preg_match('/^'.$pattern.'$/is', $key)) {
203 203
                 // return value for request param
204 204
                 if ($return === 'value') {
205 205
                     return $request_param;
@@ -261,30 +261,30 @@  discard block
 block discarded – undo
261 261
                 $key      = $real_key ?: $key;
262 262
             }
263 263
             // check if top level key exists
264
-            if (isset($request_params[ $key ])) {
264
+            if (isset($request_params[$key])) {
265 265
                 // build a new key to pass along like: 'second[third]'
266 266
                 // or just 'second' depending on depth of keys
267 267
                 $key_string = array_shift($keys);
268
-                if (! empty($keys)) {
269
-                    $key_string .= '[' . implode('][', $keys) . ']';
268
+                if ( ! empty($keys)) {
269
+                    $key_string .= '['.implode('][', $keys).']';
270 270
                 }
271 271
                 return $this->parameterDrillDown(
272 272
                     $key_string,
273 273
                     $default,
274 274
                     $callback,
275 275
                     $return,
276
-                    $request_params[ $key ]
276
+                    $request_params[$key]
277 277
                 );
278 278
             }
279 279
         }
280 280
         if ($callback === 'is_set') {
281
-            return isset($request_params[ $key ]);
281
+            return isset($request_params[$key]);
282 282
         }
283 283
         if ($callback === 'match') {
284 284
             return $this->match($key, $request_params, $default, $return);
285 285
         }
286
-        return isset($request_params[ $key ])
287
-            ? $request_params[ $key ]
286
+        return isset($request_params[$key])
287
+            ? $request_params[$key]
288 288
             : $default;
289 289
     }
290 290
 
@@ -298,12 +298,12 @@  discard block
 block discarded – undo
298 298
     public function unSetRequestParam($key, $unset_from_global_too = false)
299 299
     {
300 300
         // because unset may not actually remove var
301
-        $this->get[ $key ]     = null;
302
-        $this->post[ $key ]    = null;
303
-        $this->request[ $key ] = null;
304
-        unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]);
301
+        $this->get[$key]     = null;
302
+        $this->post[$key]    = null;
303
+        $this->request[$key] = null;
304
+        unset($this->get[$key], $this->post[$key], $this->request[$key]);
305 305
         if ($unset_from_global_too) {
306
-            unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]);
306
+            unset($_GET[$key], $_POST[$key], $_REQUEST[$key]);
307 307
         }
308 308
     }
309 309
 
Please login to merge, or discard this patch.
Indentation   +310 added lines, -310 removed lines patch added patch discarded remove patch
@@ -14,314 +14,314 @@
 block discarded – undo
14 14
 class RequestParams
15 15
 {
16 16
 
17
-    /**
18
-     * $_GET parameters
19
-     *
20
-     * @var array
21
-     */
22
-    protected $get;
23
-
24
-    /**
25
-     * $_POST parameters
26
-     *
27
-     * @var array
28
-     */
29
-    protected $post;
30
-
31
-    /**
32
-     * $_REQUEST parameters
33
-     *
34
-     * @var array
35
-     */
36
-    protected $request;
37
-
38
-    /**
39
-     * @var RequestSanitizer
40
-     */
41
-    protected $sanitizer;
42
-
43
-
44
-    /**
45
-     * RequestParams constructor.
46
-     *
47
-     * @param RequestSanitizer $sanitizer
48
-     * @param array            $get
49
-     * @param array            $post
50
-     */
51
-    public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = [])
52
-    {
53
-        $this->sanitizer = $sanitizer;
54
-        $this->get       = ! empty($get) ? $get : (array) filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
55
-        $this->post      = ! empty($post) ? $post : (array) filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
56
-        $this->request   = array_merge($this->get, $this->post);
57
-    }
58
-
59
-
60
-    /**
61
-     * @return array
62
-     */
63
-    public function getParams()
64
-    {
65
-        return $this->get;
66
-    }
67
-
68
-
69
-    /**
70
-     * @return array
71
-     */
72
-    public function postParams()
73
-    {
74
-        return $this->post;
75
-    }
76
-
77
-
78
-    /**
79
-     * returns contents of $_REQUEST
80
-     *
81
-     * @return array
82
-     */
83
-    public function requestParams()
84
-    {
85
-        return $this->request;
86
-    }
87
-
88
-
89
-    /**
90
-     * @param string     $key
91
-     * @param mixed|null $value
92
-     * @param bool       $override_ee
93
-     * @return    void
94
-     */
95
-    public function setRequestParam($key, $value, $override_ee = false)
96
-    {
97
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
98
-        if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
99
-            $this->request[ $key ] = $value;
100
-        }
101
-    }
102
-
103
-
104
-    /**
105
-     * returns   the value for a request param if the given key exists
106
-     *
107
-     * @param string     $key
108
-     * @param mixed|null $default
109
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
110
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
111
-     * @param string     $delimiter for CSV type strings that should be returned as an array
112
-     * @return array|bool|float|int|string
113
-     */
114
-    public function getRequestParam($key, $default = null, $type = 'string', $is_array = false, $delimiter = '')
115
-    {
116
-        return $this->sanitizer->clean(
117
-            $this->parameterDrillDown($key, $default, 'get'),
118
-            $type,
119
-            $is_array,
120
-            $delimiter
121
-        );
122
-    }
123
-
124
-
125
-    /**
126
-     * check if param exists
127
-     *
128
-     * @param string $key
129
-     * @return bool
130
-     */
131
-    public function requestParamIsSet($key)
132
-    {
133
-        return (bool) $this->parameterDrillDown($key);
134
-    }
135
-
136
-
137
-    /**
138
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
139
-     * and return the value for the first match found
140
-     * wildcards can be either of the following:
141
-     *      ? to represent a single character of any type
142
-     *      * to represent one or more characters of any type
143
-     *
144
-     * @param string     $pattern
145
-     * @param mixed|null $default
146
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
147
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
148
-     * @param string     $delimiter for CSV type strings that should be returned as an array
149
-     * @return array|bool|float|int|string
150
-     */
151
-    public function getMatch($pattern, $default = null, $type = 'string', $is_array = false, $delimiter = '')
152
-    {
153
-        return $this->sanitizer->clean(
154
-            $this->parameterDrillDown($pattern, $default, 'match'),
155
-            $type,
156
-            $is_array,
157
-            $delimiter
158
-        );
159
-    }
160
-
161
-
162
-    /**
163
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
164
-     * wildcards can be either of the following:
165
-     *      ? to represent a single character of any type
166
-     *      * to represent one or more characters of any type
167
-     * returns true if a match is found or false if not
168
-     *
169
-     * @param string $pattern
170
-     * @return bool
171
-     */
172
-    public function matches($pattern)
173
-    {
174
-        return (bool) $this->parameterDrillDown($pattern, false, 'match', 'bool');
175
-    }
176
-
177
-
178
-    /**
179
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
180
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
181
-     *                                      and used to search through the current request's parameter keys
182
-     * @param array  $request_params        The array of request parameters to search through
183
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
184
-     *                                      Default is null
185
-     * @param string $return                [optional] Controls what kind of value is returned.
186
-     *                                      Options are:
187
-     *                                      'bool' will return true or false if match is found or not
188
-     *                                      'key' will return the first key found that matches the supplied pattern
189
-     *                                      'value' will return the value for the first request parameter
190
-     *                                      whose key matches the supplied pattern
191
-     *                                      Default is 'value'
192
-     * @return boolean|string
193
-     */
194
-    private function match($pattern, array $request_params, $default = null, $return = 'value')
195
-    {
196
-        $return = in_array($return, ['bool', 'key', 'value'], true)
197
-            ? $return
198
-            : 'is_set';
199
-        // replace wildcard chars with regex chars
200
-        $pattern = str_replace(
201
-            ['\*', '\?'],
202
-            ['.*', '.'],
203
-            preg_quote($pattern, '/')
204
-        );
205
-        foreach ($request_params as $key => $request_param) {
206
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
207
-                // return value for request param
208
-                if ($return === 'value') {
209
-                    return $request_param;
210
-                }
211
-                // or actual key or true just to indicate it was found
212
-                return $return === 'key' ? $key : true;
213
-            }
214
-        }
215
-        // match not found so return default value or false
216
-        return $return === 'value' ? $default : false;
217
-    }
218
-
219
-
220
-    /**
221
-     * the supplied key can be a simple string to represent a "top-level" request parameter
222
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
223
-     * by using square brackets to surround keys for deeper array elements.
224
-     * For example :
225
-     * if the supplied $key was: "first[second][third]"
226
-     * then this will attempt to drill down into the request parameter array to find a value.
227
-     * Given the following request parameters:
228
-     *  array(
229
-     *      'first' => array(
230
-     *          'second' => array(
231
-     *              'third' => 'has a value'
232
-     *          )
233
-     *      )
234
-     *  )
235
-     * would return true if default parameters were set
236
-     *
237
-     * @param string $callback
238
-     * @param        $key
239
-     * @param null   $default
240
-     * @param string $return
241
-     * @param mixed  $request_params
242
-     * @return bool|mixed|null
243
-     */
244
-    private function parameterDrillDown(
245
-        $key,
246
-        $default = null,
247
-        $callback = 'is_set',
248
-        $return = 'value',
249
-        $request_params = []
250
-    ) {
251
-        $callback       = in_array($callback, ['is_set', 'get', 'match'], true)
252
-            ? $callback
253
-            : 'is_set';
254
-        $request_params = ! empty($request_params)
255
-            ? $request_params
256
-            : $this->request;
257
-        // does incoming key represent an array like 'first[second][third]'  ?
258
-        if (strpos($key, '[') !== false) {
259
-            // turn it into an actual array
260
-            $key  = str_replace(']', '', $key);
261
-            $keys = explode('[', $key);
262
-            $key  = array_shift($keys);
263
-            if ($callback === 'match') {
264
-                $real_key = $this->match($key, $request_params, $default, 'key');
265
-                $key      = $real_key ?: $key;
266
-            }
267
-            // check if top level key exists
268
-            if (isset($request_params[ $key ])) {
269
-                // build a new key to pass along like: 'second[third]'
270
-                // or just 'second' depending on depth of keys
271
-                $key_string = array_shift($keys);
272
-                if (! empty($keys)) {
273
-                    $key_string .= '[' . implode('][', $keys) . ']';
274
-                }
275
-                return $this->parameterDrillDown(
276
-                    $key_string,
277
-                    $default,
278
-                    $callback,
279
-                    $return,
280
-                    $request_params[ $key ]
281
-                );
282
-            }
283
-        }
284
-        if ($callback === 'is_set') {
285
-            return isset($request_params[ $key ]);
286
-        }
287
-        if ($callback === 'match') {
288
-            return $this->match($key, $request_params, $default, $return);
289
-        }
290
-        return isset($request_params[ $key ])
291
-            ? $request_params[ $key ]
292
-            : $default;
293
-    }
294
-
295
-
296
-    /**
297
-     * remove param
298
-     *
299
-     * @param      $key
300
-     * @param bool $unset_from_global_too
301
-     */
302
-    public function unSetRequestParam($key, $unset_from_global_too = false)
303
-    {
304
-        // because unset may not actually remove var
305
-        $this->get[ $key ]     = null;
306
-        $this->post[ $key ]    = null;
307
-        $this->request[ $key ] = null;
308
-        unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]);
309
-        if ($unset_from_global_too) {
310
-            unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]);
311
-        }
312
-    }
313
-
314
-
315
-    /**
316
-     * remove params
317
-     *
318
-     * @param array $keys
319
-     * @param bool  $unset_from_global_too
320
-     */
321
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false)
322
-    {
323
-        foreach ($keys as $key) {
324
-            $this->unSetRequestParam($key, $unset_from_global_too);
325
-        }
326
-    }
17
+	/**
18
+	 * $_GET parameters
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected $get;
23
+
24
+	/**
25
+	 * $_POST parameters
26
+	 *
27
+	 * @var array
28
+	 */
29
+	protected $post;
30
+
31
+	/**
32
+	 * $_REQUEST parameters
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected $request;
37
+
38
+	/**
39
+	 * @var RequestSanitizer
40
+	 */
41
+	protected $sanitizer;
42
+
43
+
44
+	/**
45
+	 * RequestParams constructor.
46
+	 *
47
+	 * @param RequestSanitizer $sanitizer
48
+	 * @param array            $get
49
+	 * @param array            $post
50
+	 */
51
+	public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = [])
52
+	{
53
+		$this->sanitizer = $sanitizer;
54
+		$this->get       = ! empty($get) ? $get : (array) filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
55
+		$this->post      = ! empty($post) ? $post : (array) filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
56
+		$this->request   = array_merge($this->get, $this->post);
57
+	}
58
+
59
+
60
+	/**
61
+	 * @return array
62
+	 */
63
+	public function getParams()
64
+	{
65
+		return $this->get;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @return array
71
+	 */
72
+	public function postParams()
73
+	{
74
+		return $this->post;
75
+	}
76
+
77
+
78
+	/**
79
+	 * returns contents of $_REQUEST
80
+	 *
81
+	 * @return array
82
+	 */
83
+	public function requestParams()
84
+	{
85
+		return $this->request;
86
+	}
87
+
88
+
89
+	/**
90
+	 * @param string     $key
91
+	 * @param mixed|null $value
92
+	 * @param bool       $override_ee
93
+	 * @return    void
94
+	 */
95
+	public function setRequestParam($key, $value, $override_ee = false)
96
+	{
97
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
98
+		if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
99
+			$this->request[ $key ] = $value;
100
+		}
101
+	}
102
+
103
+
104
+	/**
105
+	 * returns   the value for a request param if the given key exists
106
+	 *
107
+	 * @param string     $key
108
+	 * @param mixed|null $default
109
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
110
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
111
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
112
+	 * @return array|bool|float|int|string
113
+	 */
114
+	public function getRequestParam($key, $default = null, $type = 'string', $is_array = false, $delimiter = '')
115
+	{
116
+		return $this->sanitizer->clean(
117
+			$this->parameterDrillDown($key, $default, 'get'),
118
+			$type,
119
+			$is_array,
120
+			$delimiter
121
+		);
122
+	}
123
+
124
+
125
+	/**
126
+	 * check if param exists
127
+	 *
128
+	 * @param string $key
129
+	 * @return bool
130
+	 */
131
+	public function requestParamIsSet($key)
132
+	{
133
+		return (bool) $this->parameterDrillDown($key);
134
+	}
135
+
136
+
137
+	/**
138
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
139
+	 * and return the value for the first match found
140
+	 * wildcards can be either of the following:
141
+	 *      ? to represent a single character of any type
142
+	 *      * to represent one or more characters of any type
143
+	 *
144
+	 * @param string     $pattern
145
+	 * @param mixed|null $default
146
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
147
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
148
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
149
+	 * @return array|bool|float|int|string
150
+	 */
151
+	public function getMatch($pattern, $default = null, $type = 'string', $is_array = false, $delimiter = '')
152
+	{
153
+		return $this->sanitizer->clean(
154
+			$this->parameterDrillDown($pattern, $default, 'match'),
155
+			$type,
156
+			$is_array,
157
+			$delimiter
158
+		);
159
+	}
160
+
161
+
162
+	/**
163
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
164
+	 * wildcards can be either of the following:
165
+	 *      ? to represent a single character of any type
166
+	 *      * to represent one or more characters of any type
167
+	 * returns true if a match is found or false if not
168
+	 *
169
+	 * @param string $pattern
170
+	 * @return bool
171
+	 */
172
+	public function matches($pattern)
173
+	{
174
+		return (bool) $this->parameterDrillDown($pattern, false, 'match', 'bool');
175
+	}
176
+
177
+
178
+	/**
179
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
180
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
181
+	 *                                      and used to search through the current request's parameter keys
182
+	 * @param array  $request_params        The array of request parameters to search through
183
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
184
+	 *                                      Default is null
185
+	 * @param string $return                [optional] Controls what kind of value is returned.
186
+	 *                                      Options are:
187
+	 *                                      'bool' will return true or false if match is found or not
188
+	 *                                      'key' will return the first key found that matches the supplied pattern
189
+	 *                                      'value' will return the value for the first request parameter
190
+	 *                                      whose key matches the supplied pattern
191
+	 *                                      Default is 'value'
192
+	 * @return boolean|string
193
+	 */
194
+	private function match($pattern, array $request_params, $default = null, $return = 'value')
195
+	{
196
+		$return = in_array($return, ['bool', 'key', 'value'], true)
197
+			? $return
198
+			: 'is_set';
199
+		// replace wildcard chars with regex chars
200
+		$pattern = str_replace(
201
+			['\*', '\?'],
202
+			['.*', '.'],
203
+			preg_quote($pattern, '/')
204
+		);
205
+		foreach ($request_params as $key => $request_param) {
206
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
207
+				// return value for request param
208
+				if ($return === 'value') {
209
+					return $request_param;
210
+				}
211
+				// or actual key or true just to indicate it was found
212
+				return $return === 'key' ? $key : true;
213
+			}
214
+		}
215
+		// match not found so return default value or false
216
+		return $return === 'value' ? $default : false;
217
+	}
218
+
219
+
220
+	/**
221
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
222
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
223
+	 * by using square brackets to surround keys for deeper array elements.
224
+	 * For example :
225
+	 * if the supplied $key was: "first[second][third]"
226
+	 * then this will attempt to drill down into the request parameter array to find a value.
227
+	 * Given the following request parameters:
228
+	 *  array(
229
+	 *      'first' => array(
230
+	 *          'second' => array(
231
+	 *              'third' => 'has a value'
232
+	 *          )
233
+	 *      )
234
+	 *  )
235
+	 * would return true if default parameters were set
236
+	 *
237
+	 * @param string $callback
238
+	 * @param        $key
239
+	 * @param null   $default
240
+	 * @param string $return
241
+	 * @param mixed  $request_params
242
+	 * @return bool|mixed|null
243
+	 */
244
+	private function parameterDrillDown(
245
+		$key,
246
+		$default = null,
247
+		$callback = 'is_set',
248
+		$return = 'value',
249
+		$request_params = []
250
+	) {
251
+		$callback       = in_array($callback, ['is_set', 'get', 'match'], true)
252
+			? $callback
253
+			: 'is_set';
254
+		$request_params = ! empty($request_params)
255
+			? $request_params
256
+			: $this->request;
257
+		// does incoming key represent an array like 'first[second][third]'  ?
258
+		if (strpos($key, '[') !== false) {
259
+			// turn it into an actual array
260
+			$key  = str_replace(']', '', $key);
261
+			$keys = explode('[', $key);
262
+			$key  = array_shift($keys);
263
+			if ($callback === 'match') {
264
+				$real_key = $this->match($key, $request_params, $default, 'key');
265
+				$key      = $real_key ?: $key;
266
+			}
267
+			// check if top level key exists
268
+			if (isset($request_params[ $key ])) {
269
+				// build a new key to pass along like: 'second[third]'
270
+				// or just 'second' depending on depth of keys
271
+				$key_string = array_shift($keys);
272
+				if (! empty($keys)) {
273
+					$key_string .= '[' . implode('][', $keys) . ']';
274
+				}
275
+				return $this->parameterDrillDown(
276
+					$key_string,
277
+					$default,
278
+					$callback,
279
+					$return,
280
+					$request_params[ $key ]
281
+				);
282
+			}
283
+		}
284
+		if ($callback === 'is_set') {
285
+			return isset($request_params[ $key ]);
286
+		}
287
+		if ($callback === 'match') {
288
+			return $this->match($key, $request_params, $default, $return);
289
+		}
290
+		return isset($request_params[ $key ])
291
+			? $request_params[ $key ]
292
+			: $default;
293
+	}
294
+
295
+
296
+	/**
297
+	 * remove param
298
+	 *
299
+	 * @param      $key
300
+	 * @param bool $unset_from_global_too
301
+	 */
302
+	public function unSetRequestParam($key, $unset_from_global_too = false)
303
+	{
304
+		// because unset may not actually remove var
305
+		$this->get[ $key ]     = null;
306
+		$this->post[ $key ]    = null;
307
+		$this->request[ $key ] = null;
308
+		unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]);
309
+		if ($unset_from_global_too) {
310
+			unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]);
311
+		}
312
+	}
313
+
314
+
315
+	/**
316
+	 * remove params
317
+	 *
318
+	 * @param array $keys
319
+	 * @param bool  $unset_from_global_too
320
+	 */
321
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false)
322
+	{
323
+		foreach ($keys as $key) {
324
+			$this->unSetRequestParam($key, $unset_from_global_too);
325
+		}
326
+	}
327 327
 }
Please login to merge, or discard this patch.
core/services/request/LegacyRequestInterface.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -12,125 +12,125 @@
 block discarded – undo
12 12
 interface LegacyRequestInterface
13 13
 {
14 14
 
15
-    /**
16
-     * @return array
17
-     */
18
-    public function get_params();
15
+	/**
16
+	 * @return array
17
+	 */
18
+	public function get_params();
19 19
 
20 20
 
21
-    /**
22
-     * @return array
23
-     */
24
-    public function post_params();
21
+	/**
22
+	 * @return array
23
+	 */
24
+	public function post_params();
25 25
 
26 26
 
27
-    /**
28
-     * @return array
29
-     */
30
-    public function cookie_params();
27
+	/**
28
+	 * @return array
29
+	 */
30
+	public function cookie_params();
31 31
 
32 32
 
33
-    /**
34
-     * @return array
35
-     */
36
-    public function server_params();
33
+	/**
34
+	 * @return array
35
+	 */
36
+	public function server_params();
37 37
 
38 38
 
39
-    /**
40
-     * returns sanitized contents of $_REQUEST
41
-     *
42
-     * @return array
43
-     */
44
-    public function params();
39
+	/**
40
+	 * returns sanitized contents of $_REQUEST
41
+	 *
42
+	 * @return array
43
+	 */
44
+	public function params();
45 45
 
46 46
 
47
-    /**
48
-     * @param      $key
49
-     * @param      $value
50
-     * @param bool $override_ee
51
-     * @return    void
52
-     */
53
-    public function set($key, $value, $override_ee = false);
47
+	/**
48
+	 * @param      $key
49
+	 * @param      $value
50
+	 * @param bool $override_ee
51
+	 * @return    void
52
+	 */
53
+	public function set($key, $value, $override_ee = false);
54 54
 
55 55
 
56
-    /**
57
-     * returns   the value for a request param if the given key exists
58
-     *
59
-     * @param       $key
60
-     * @param null  $default
61
-     * @return mixed
62
-     */
63
-    public function get($key, $default = null);
56
+	/**
57
+	 * returns   the value for a request param if the given key exists
58
+	 *
59
+	 * @param       $key
60
+	 * @param null  $default
61
+	 * @return mixed
62
+	 */
63
+	public function get($key, $default = null);
64 64
 
65 65
 
66
-    /**
67
-     * check if param exists
68
-     *
69
-     * @param       $key
70
-     * @return bool
71
-     */
72
-    public function is_set($key);
66
+	/**
67
+	 * check if param exists
68
+	 *
69
+	 * @param       $key
70
+	 * @return bool
71
+	 */
72
+	public function is_set($key);
73 73
 
74 74
 
75
-    /**
76
-     * remove param
77
-     *
78
-     * @param      $key
79
-     * @param bool $unset_from_global_too
80
-     */
81
-    public function un_set($key, $unset_from_global_too = false);
75
+	/**
76
+	 * remove param
77
+	 *
78
+	 * @param      $key
79
+	 * @param bool $unset_from_global_too
80
+	 */
81
+	public function un_set($key, $unset_from_global_too = false);
82 82
 
83 83
 
84
-    /**
85
-     * @return string
86
-     */
87
-    public function ip_address();
84
+	/**
85
+	 * @return string
86
+	 */
87
+	public function ip_address();
88 88
 
89 89
 
90
-    /**
91
-     * @return bool
92
-     */
93
-    public function isAdmin();
90
+	/**
91
+	 * @return bool
92
+	 */
93
+	public function isAdmin();
94 94
 
95 95
 
96
-    /**
97
-     * @return mixed
98
-     */
99
-    public function isAjax();
96
+	/**
97
+	 * @return mixed
98
+	 */
99
+	public function isAjax();
100 100
 
101 101
 
102
-    /**
103
-     * @return mixed
104
-     */
105
-    public function isFrontAjax();
102
+	/**
103
+	 * @return mixed
104
+	 */
105
+	public function isFrontAjax();
106 106
 
107 107
 
108
-    /**
109
-     * @return mixed|string
110
-     */
111
-    public function requestUri();
108
+	/**
109
+	 * @return mixed|string
110
+	 */
111
+	public function requestUri();
112 112
 
113 113
 
114
-    /**
115
-     * @return string
116
-     */
117
-    public function userAgent();
114
+	/**
115
+	 * @return string
116
+	 */
117
+	public function userAgent();
118 118
 
119 119
 
120
-    /**
121
-     * @param string $user_agent
122
-     */
123
-    public function setUserAgent($user_agent = '');
120
+	/**
121
+	 * @param string $user_agent
122
+	 */
123
+	public function setUserAgent($user_agent = '');
124 124
 
125 125
 
126
-    /**
127
-     * @return bool
128
-     */
129
-    public function isBot();
126
+	/**
127
+	 * @return bool
128
+	 */
129
+	public function isBot();
130 130
 
131 131
 
132
-    /**
133
-     * @param bool $is_bot
134
-     */
135
-    public function setIsBot($is_bot);
132
+	/**
133
+	 * @param bool $is_bot
134
+	 */
135
+	public function setIsBot($is_bot);
136 136
 }
Please login to merge, or discard this patch.
core/services/privacy/policy/PrivacyPolicyManager.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -26,71 +26,71 @@
 block discarded – undo
26 26
 class PrivacyPolicyManager
27 27
 {
28 28
 
29
-    public function __construct()
30
-    {
31
-        add_action('current_screen', array($this, 'addPrivacyPolicy'), 9);
32
-    }
29
+	public function __construct()
30
+	{
31
+		add_action('current_screen', array($this, 'addPrivacyPolicy'), 9);
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * For all the registered `PrivacyPolicyInterface`s, add their privacy policy content
37
-     *
38
-     * @param WP_Screen $screen
39
-     * @throws InvalidClassException
40
-     * @throws InvalidDataTypeException
41
-     * @throws InvalidEntityException
42
-     * @throws InvalidFilePathException
43
-     * @throws InvalidIdentifierException
44
-     * @throws InvalidInterfaceException
45
-     */
46
-    public function addPrivacyPolicy(WP_Screen $screen)
47
-    {
48
-        /** @var RequestInterface $request */
49
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
35
+	/**
36
+	 * For all the registered `PrivacyPolicyInterface`s, add their privacy policy content
37
+	 *
38
+	 * @param WP_Screen $screen
39
+	 * @throws InvalidClassException
40
+	 * @throws InvalidDataTypeException
41
+	 * @throws InvalidEntityException
42
+	 * @throws InvalidFilePathException
43
+	 * @throws InvalidIdentifierException
44
+	 * @throws InvalidInterfaceException
45
+	 */
46
+	public function addPrivacyPolicy(WP_Screen $screen)
47
+	{
48
+		/** @var RequestInterface $request */
49
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
50 50
 
51
-        if ($screen->id === 'tools' && $request->requestParamIsSet('wp-privacy-policy-guide')) {
52
-            // load all the privacy policy stuff
53
-            // add post policy text
54
-            foreach ($this->loadPrivacyPolicyCollection() as $privacy_policy) {
55
-                wp_add_privacy_policy_content($privacy_policy->getName(), $privacy_policy->getContent());
56
-            }
57
-        }
58
-    }
51
+		if ($screen->id === 'tools' && $request->requestParamIsSet('wp-privacy-policy-guide')) {
52
+			// load all the privacy policy stuff
53
+			// add post policy text
54
+			foreach ($this->loadPrivacyPolicyCollection() as $privacy_policy) {
55
+				wp_add_privacy_policy_content($privacy_policy->getName(), $privacy_policy->getContent());
56
+			}
57
+		}
58
+	}
59 59
 
60 60
 
61
-    /**
62
-     * @return CollectionInterface|PrivacyPolicyInterface[]
63
-     * @throws InvalidIdentifierException
64
-     * @throws InvalidInterfaceException
65
-     * @throws InvalidFilePathException
66
-     * @throws InvalidEntityException
67
-     * @throws InvalidDataTypeException
68
-     * @throws InvalidClassException
69
-     */
70
-    protected function loadPrivacyPolicyCollection()
71
-    {
72
-        $loader = new CollectionLoader(
73
-            new CollectionDetails(
74
-                // collection name
75
-                'privacy_policies',
76
-                // collection interface
77
-                'EventEspresso\core\services\privacy\policy\PrivacyPolicyInterface',
78
-                // FQCNs for classes to add (all classes within that namespace will be loaded)
79
-                apply_filters(
80
-                    'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies',
81
-                    array('EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy')
82
-                ),
83
-                // filepaths to classes to add
84
-                array(),
85
-                // file mask to use if parsing folder for files to add
86
-                '',
87
-                // what to use as identifier for collection entities
88
-                // using CLASS NAME prevents duplicates (works like a singleton)
89
-                CollectionDetails::ID_CLASS_NAME
90
-            )
91
-        );
92
-        return $loader->getCollection();
93
-    }
61
+	/**
62
+	 * @return CollectionInterface|PrivacyPolicyInterface[]
63
+	 * @throws InvalidIdentifierException
64
+	 * @throws InvalidInterfaceException
65
+	 * @throws InvalidFilePathException
66
+	 * @throws InvalidEntityException
67
+	 * @throws InvalidDataTypeException
68
+	 * @throws InvalidClassException
69
+	 */
70
+	protected function loadPrivacyPolicyCollection()
71
+	{
72
+		$loader = new CollectionLoader(
73
+			new CollectionDetails(
74
+				// collection name
75
+				'privacy_policies',
76
+				// collection interface
77
+				'EventEspresso\core\services\privacy\policy\PrivacyPolicyInterface',
78
+				// FQCNs for classes to add (all classes within that namespace will be loaded)
79
+				apply_filters(
80
+					'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies',
81
+					array('EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy')
82
+				),
83
+				// filepaths to classes to add
84
+				array(),
85
+				// file mask to use if parsing folder for files to add
86
+				'',
87
+				// what to use as identifier for collection entities
88
+				// using CLASS NAME prevents duplicates (works like a singleton)
89
+				CollectionDetails::ID_CLASS_NAME
90
+			)
91
+		);
92
+		return $loader->getCollection();
93
+	}
94 94
 }
95 95
 // End of file PrivacyPolicyManager.php
96 96
 // Location: EventEspresso\core\domain\services\admin/PrivacyPolicyManager.php
Please login to merge, or discard this patch.
libraries/messages/data_class/EE_Messages_Preview_incoming_data.class.php 2 patches
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -106,72 +106,72 @@  discard block
 block discarded – undo
106 106
         // we'll actually use the generated line_item identifiers for our loop
107 107
         $dtts = $tkts = [];
108 108
         foreach ($events as $id => $event) {
109
-            if (! $event instanceof EE_Event) {
109
+            if ( ! $event instanceof EE_Event) {
110 110
                 continue;
111 111
             }
112
-            $this->_events[ $id ]['ID']       = $id;
113
-            $this->_events[ $id ]['name']     = $event->get('EVT_name');
112
+            $this->_events[$id]['ID']       = $id;
113
+            $this->_events[$id]['name']     = $event->get('EVT_name');
114 114
             $datetime                         = $event->get_first_related('Datetime');
115 115
             $tickets                          = $datetime instanceof EE_Datetime ? $datetime->get_many_related(
116 116
                 'Ticket',
117 117
                 ['default_where_conditions' => 'none']
118 118
             ) : [];
119
-            $this->_events[ $id ]['event']    = $event;
120
-            $this->_events[ $id ]['reg_objs'] = [];
121
-            $this->_events[ $id ]['tkt_objs'] = $tickets;
122
-            $this->_events[ $id ]['dtt_objs'] = [];
119
+            $this->_events[$id]['event']    = $event;
120
+            $this->_events[$id]['reg_objs'] = [];
121
+            $this->_events[$id]['tkt_objs'] = $tickets;
122
+            $this->_events[$id]['dtt_objs'] = [];
123 123
 
124 124
             $dttcache = [];
125 125
             $tkts     = [];
126 126
             foreach ($tickets as $ticket) {
127
-                if (! $ticket instanceof EE_Ticket) {
127
+                if ( ! $ticket instanceof EE_Ticket) {
128 128
                     continue;
129 129
                 }
130 130
                 $reldatetime                       = $ticket->datetimes();
131
-                $tkts[ $ticket->ID() ]             = [];
132
-                $tkts[ $ticket->ID() ]['ticket']   = $ticket;
133
-                $tkts[ $ticket->ID() ]['dtt_objs'] = $reldatetime;
134
-                $tkts[ $ticket->ID() ]['att_objs'] = $attendees;
135
-                $tkts[ $ticket->ID() ]['count']    = count($attendees);
136
-                $tkts[ $ticket->ID() ]['EE_Event'] = $event;
131
+                $tkts[$ticket->ID()]             = [];
132
+                $tkts[$ticket->ID()]['ticket']   = $ticket;
133
+                $tkts[$ticket->ID()]['dtt_objs'] = $reldatetime;
134
+                $tkts[$ticket->ID()]['att_objs'] = $attendees;
135
+                $tkts[$ticket->ID()]['count']    = count($attendees);
136
+                $tkts[$ticket->ID()]['EE_Event'] = $event;
137 137
                 foreach ($reldatetime as $datetime) {
138
-                    if ($datetime instanceof EE_Datetime && ! isset($dtts[ $datetime->ID() ])) {
139
-                        $this->_events[ $id ]['dtt_objs'][ $datetime->ID() ] = $datetime;
140
-                        $dtts[ $datetime->ID() ]['datetime']                 = $datetime;
141
-                        $dtts[ $datetime->ID() ]['tkt_objs'][]               = $ticket;
142
-                        $dtts[ $datetime->ID() ]['evt_objs'][]               = $event;
143
-                        $dttcache[ $datetime->ID() ]                         = $datetime;
138
+                    if ($datetime instanceof EE_Datetime && ! isset($dtts[$datetime->ID()])) {
139
+                        $this->_events[$id]['dtt_objs'][$datetime->ID()] = $datetime;
140
+                        $dtts[$datetime->ID()]['datetime']                 = $datetime;
141
+                        $dtts[$datetime->ID()]['tkt_objs'][]               = $ticket;
142
+                        $dtts[$datetime->ID()]['evt_objs'][]               = $event;
143
+                        $dttcache[$datetime->ID()]                         = $datetime;
144 144
                     }
145 145
                 }
146 146
             }
147 147
 
148
-            $this->_events[ $id ]['total_attendees'] = count($attendees);
149
-            $this->_events[ $id ]['att_objs']        = $attendees;
148
+            $this->_events[$id]['total_attendees'] = count($attendees);
149
+            $this->_events[$id]['att_objs']        = $attendees;
150 150
 
151 151
             // let's also setup the dummy attendees property!
152 152
             foreach ($attendees as $att_key => $attendee) {
153
-                if (! $attendee instanceof EE_Attendee) {
153
+                if ( ! $attendee instanceof EE_Attendee) {
154 154
                     continue;
155 155
                 }
156
-                $this->_attendees[ $att_key ]['line_ref'][] =
157
-                    $id;  // so later it can be determined what events this attendee registered for!
158
-                $this->_attendees[ $att_key ]['evt_objs'][] = $event;
159
-                $this->_attendees[ $att_key ]['att_obj']    = $attendee;
156
+                $this->_attendees[$att_key]['line_ref'][] =
157
+                    $id; // so later it can be determined what events this attendee registered for!
158
+                $this->_attendees[$att_key]['evt_objs'][] = $event;
159
+                $this->_attendees[$att_key]['att_obj']    = $attendee;
160 160
                 // $this->_attendees[$att_key]['registration_id'] = 0;
161
-                $this->_attendees[ $att_key ]['attendee_email'] = $attendee->email();
162
-                $this->_attendees[ $att_key ]['tkt_objs']       = $tickets;
161
+                $this->_attendees[$att_key]['attendee_email'] = $attendee->email();
162
+                $this->_attendees[$att_key]['tkt_objs']       = $tickets;
163 163
                 if ($att_key == 999999991) {
164
-                    $this->_attendees[ $att_key ]['ans_objs'][999]  = $answers_n_questions['answers'][999];
165
-                    $this->_attendees[ $att_key ]['ans_objs'][1002] = $answers_n_questions['answers'][1002];
166
-                    $this->_attendees[ $att_key ]['ans_objs'][1005] = $answers_n_questions['answers'][1005];
164
+                    $this->_attendees[$att_key]['ans_objs'][999]  = $answers_n_questions['answers'][999];
165
+                    $this->_attendees[$att_key]['ans_objs'][1002] = $answers_n_questions['answers'][1002];
166
+                    $this->_attendees[$att_key]['ans_objs'][1005] = $answers_n_questions['answers'][1005];
167 167
                 } elseif ($att_key == 999999992) {
168
-                    $this->_attendees[ $att_key ]['ans_objs'][1000] = $answers_n_questions['answers'][1000];
169
-                    $this->_attendees[ $att_key ]['ans_objs'][1003] = $answers_n_questions['answers'][1003];
170
-                    $this->_attendees[ $att_key ]['ans_objs'][1006] = $answers_n_questions['answers'][1006];
168
+                    $this->_attendees[$att_key]['ans_objs'][1000] = $answers_n_questions['answers'][1000];
169
+                    $this->_attendees[$att_key]['ans_objs'][1003] = $answers_n_questions['answers'][1003];
170
+                    $this->_attendees[$att_key]['ans_objs'][1006] = $answers_n_questions['answers'][1006];
171 171
                 } elseif ($att_key == 999999993) {
172
-                    $this->_attendees[ $att_key ]['ans_objs'][1001] = $answers_n_questions['answers'][1001];
173
-                    $this->_attendees[ $att_key ]['ans_objs'][1004] = $answers_n_questions['answers'][1004];
174
-                    $this->_attendees[ $att_key ]['ans_objs'][1007] = $answers_n_questions['answers'][1007];
172
+                    $this->_attendees[$att_key]['ans_objs'][1001] = $answers_n_questions['answers'][1001];
173
+                    $this->_attendees[$att_key]['ans_objs'][1004] = $answers_n_questions['answers'][1004];
174
+                    $this->_attendees[$att_key]['ans_objs'][1007] = $answers_n_questions['answers'][1007];
175 175
                 }
176 176
             }
177 177
         }
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
             /** @var $email string */
273 273
             /** @var $phone string */
274 274
             /** @var $attid string */
275
-            $attendees[ $attid ] = EE_Attendee::new_instance(
275
+            $attendees[$attid] = EE_Attendee::new_instance(
276 276
                 [
277 277
                     'ATT_fname'    => $fname,
278 278
                     'ATT_lname'    => $lname,
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
         // first the questions
380 380
         foreach ($quests_array as $qst) {
381 381
             $qstobj                    = array_combine($qst_columns, $qst);
382
-            $qsts[ $qstobj['QST_ID'] ] = EE_Question::new_instance($qstobj);
382
+            $qsts[$qstobj['QST_ID']] = EE_Question::new_instance($qstobj);
383 383
         }
384 384
 
385 385
         // now the answers (and we'll setup our arrays)
@@ -387,8 +387,8 @@  discard block
 block discarded – undo
387 387
         foreach ($ans_array as $ans) {
388 388
             $ansobj                               = array_combine($ans_columns, $ans);
389 389
             $ansobj                               = EE_Answer::new_instance($ansobj);
390
-            $q_n_as['answers'][ $ansobj->ID() ]   = $ansobj;
391
-            $q_n_as['questions'][ $ansobj->ID() ] = $qsts[ $ansobj->get('QST_ID') ];
390
+            $q_n_as['answers'][$ansobj->ID()]   = $ansobj;
391
+            $q_n_as['questions'][$ansobj->ID()] = $qsts[$ansobj->get('QST_ID')];
392 392
         }
393 393
 
394 394
         return $q_n_as;
@@ -471,11 +471,11 @@  discard block
 block discarded – undo
471 471
             $regtxn = $this->txn->ID();
472 472
             $regcnt = 1;
473 473
             foreach ($attendee['line_ref'] as $evtid) {
474
-                foreach ($this->_events[ $evtid ]['tkt_objs'] as $ticket) {
475
-                    if (! $ticket instanceof EE_Ticket) {
474
+                foreach ($this->_events[$evtid]['tkt_objs'] as $ticket) {
475
+                    if ( ! $ticket instanceof EE_Ticket) {
476 476
                         continue;
477 477
                     }
478
-                    $reg_array                                            = [
478
+                    $reg_array = [
479 479
                         'EVT_ID'           => $evtid,
480 480
                         'ATT_ID'           => $regatt,
481 481
                         'TXN_ID'           => $regtxn,
@@ -484,18 +484,18 @@  discard block
 block discarded – undo
484 484
                         'REG_date'         => time(),
485 485
                         'REG_final_price'  => $ticket->get('TKT_price'),
486 486
                         'REG_session'      => 'dummy_session_id',
487
-                        'REG_code'         => $regid . '-dummy-generated-code',
488
-                        'REG_url_link'     => $regcnt . '-daafpapasdlfakasdfpqasdfasdf',
487
+                        'REG_code'         => $regid.'-dummy-generated-code',
488
+                        'REG_url_link'     => $regcnt.'-daafpapasdlfakasdfpqasdfasdf',
489 489
                         'REG_count'        => $regcnt,
490
-                        'REG_group_size'   => $this->_events[ $evtid ]['total_attendees'],
490
+                        'REG_group_size'   => $this->_events[$evtid]['total_attendees'],
491 491
                         'REG_att_is_going' => true,
492 492
                         'REG_ID'           => $regid,
493 493
                     ];
494 494
                     $REG_OBJ                                              = EE_Registration::new_instance($reg_array);
495
-                    $this->_attendees[ $key ]['reg_objs'][ $regid ]       = $REG_OBJ;
496
-                    $this->_events[ $evtid ]['reg_objs'][]                = $REG_OBJ;
495
+                    $this->_attendees[$key]['reg_objs'][$regid]       = $REG_OBJ;
496
+                    $this->_events[$evtid]['reg_objs'][]                = $REG_OBJ;
497 497
                     $this->reg_objs[]                                     = $REG_OBJ;
498
-                    $this->tickets[ $ticket->ID() ]['reg_objs'][ $regid ] = $REG_OBJ;
498
+                    $this->tickets[$ticket->ID()]['reg_objs'][$regid] = $REG_OBJ;
499 499
 
500 500
                     $regcnt++;
501 501
                     $regid++;
@@ -537,19 +537,19 @@  discard block
 block discarded – undo
537 537
         $event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children();
538 538
         $line_items       = [];
539 539
         foreach ($event_line_items as $line_item) {
540
-            if (! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
540
+            if ( ! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
541 541
                 continue;
542 542
             }
543 543
             $ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item);
544 544
             foreach ($ticket_line_items as $ticket_line_item) {
545
-                if (! $ticket_line_item instanceof EE_Line_Item) {
545
+                if ( ! $ticket_line_item instanceof EE_Line_Item) {
546 546
                     continue;
547 547
                 }
548
-                $this->tickets[ $ticket_line_item->OBJ_ID() ]['line_item']      = $ticket_line_item;
549
-                $this->tickets[ $ticket_line_item->OBJ_ID() ]['sub_line_items'] = $ticket_line_item->children();
550
-                $line_items[ $ticket_line_item->ID() ]['children']              = $ticket_line_item->children();
551
-                $line_items[ $ticket_line_item->ID() ]['EE_Ticket']             =
552
-                    $this->tickets[ $ticket_line_item->OBJ_ID() ]['ticket'];
548
+                $this->tickets[$ticket_line_item->OBJ_ID()]['line_item']      = $ticket_line_item;
549
+                $this->tickets[$ticket_line_item->OBJ_ID()]['sub_line_items'] = $ticket_line_item->children();
550
+                $line_items[$ticket_line_item->ID()]['children']              = $ticket_line_item->children();
551
+                $line_items[$ticket_line_item->ID()]['EE_Ticket']             =
552
+                    $this->tickets[$ticket_line_item->OBJ_ID()]['ticket'];
553 553
             }
554 554
         }
555 555
 
@@ -564,15 +564,15 @@  discard block
 block discarded – undo
564 564
 
565 565
         // add additional details for each registration
566 566
         foreach ($this->reg_objs as $reg) {
567
-            if (! $reg instanceof EE_Registration) {
567
+            if ( ! $reg instanceof EE_Registration) {
568 568
                 continue;
569 569
             }
570
-            $this->_registrations[ $reg->ID() ]['tkt_obj']  = $this->tickets[ $reg->get('TKT_ID') ]['ticket'];
571
-            $this->_registrations[ $reg->ID() ]['evt_obj']  = $this->_events[ $reg->get('EVT_ID') ]['event'];
572
-            $this->_registrations[ $reg->ID() ]['reg_obj']  = $reg;
573
-            $this->_registrations[ $reg->ID() ]['ans_objs'] = $this->_attendees[ $reg->get('ATT_ID') ]['ans_objs'];
574
-            $this->_registrations[ $reg->ID() ]['att_obj']  = $this->_attendees[ $reg->get('ATT_ID') ]['att_obj'];
575
-            $this->_registrations[ $reg->ID() ]['dtt_objs'] = $this->tickets[ $reg->get('TKT_ID') ]['dtt_objs'];
570
+            $this->_registrations[$reg->ID()]['tkt_obj']  = $this->tickets[$reg->get('TKT_ID')]['ticket'];
571
+            $this->_registrations[$reg->ID()]['evt_obj']  = $this->_events[$reg->get('EVT_ID')]['event'];
572
+            $this->_registrations[$reg->ID()]['reg_obj']  = $reg;
573
+            $this->_registrations[$reg->ID()]['ans_objs'] = $this->_attendees[$reg->get('ATT_ID')]['ans_objs'];
574
+            $this->_registrations[$reg->ID()]['att_obj']  = $this->_attendees[$reg->get('ATT_ID')]['att_obj'];
575
+            $this->_registrations[$reg->ID()]['dtt_objs'] = $this->tickets[$reg->get('TKT_ID')]['dtt_objs'];
576 576
         }
577 577
 
578 578
 
Please login to merge, or discard this patch.
Indentation   +599 added lines, -599 removed lines patch added patch discarded remove patch
@@ -21,603 +21,603 @@
 block discarded – undo
21 21
 class EE_Messages_Preview_incoming_data extends EE_Messages_incoming_data
22 22
 {
23 23
 
24
-    // some specific properties we need for this class
25
-    private $_events        = [];
26
-
27
-    private $_attendees     = [];
28
-
29
-    private $_registrations = [];
30
-
31
-
32
-    /**
33
-     * For the constructor of this special preview class.  We're either looking for an event id or empty data.  If we
34
-     * have an event id (or ids) then we'll use that as the source for the "dummy" data.  If the data is empty then
35
-     * we'll get the first three published events from the users database and use that as a source.
36
-     *
37
-     * @param array $data
38
-     * @throws EE_Error
39
-     * @throws EE_Error
40
-     * @throws ReflectionException
41
-     */
42
-    public function __construct($data = [])
43
-    {
44
-        $this->_data = isset($data['event_ids']) ? $data['event_ids'] : [];
45
-        $this->_setup_attendees_events();
46
-        parent::__construct($data);
47
-    }
48
-
49
-
50
-    /**
51
-     * Returns database safe representation of the data later used to when instantiating this object.
52
-     *
53
-     * @param array $data The incoming data to be prepped.
54
-     *
55
-     * @return array   The prepped data for db
56
-     */
57
-    public static function convert_data_for_persistent_storage($data)
58
-    {
59
-        return $data;
60
-    }
61
-
62
-
63
-    /**
64
-     * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
65
-     * can be sent into this method and converted back into the format used for instantiating with this data handler.
66
-     *
67
-     * @param array $data
68
-     *
69
-     * @return array
70
-     */
71
-    public static function convert_data_from_persistent_storage($data)
72
-    {
73
-        return $data;
74
-    }
75
-
76
-
77
-    /**
78
-     * This will just setup the _events property in the expected format.
79
-     *
80
-     * @throws EE_Error
81
-     * @throws ReflectionException
82
-     */
83
-    private function _setup_attendees_events()
84
-    {
85
-
86
-        // setup some attendee objects
87
-        $attendees = $this->_get_some_attendees();
88
-
89
-        // if empty $data we'll do a query to get some events from the server.
90
-        // otherwise we'll retrieve the event data for the given ids.
91
-        $events = $this->_get_some_events($this->_data);
92
-
93
-        $answers_n_questions = $this->_get_some_q_and_as();
94
-
95
-        if (count($events) < 1) {
96
-            throw new EE_Error(
97
-                esc_html__(
98
-                    'We can\'t generate a preview for you because there are no active events in your database',
99
-                    'event_espresso'
100
-                )
101
-            );
102
-        }
103
-
104
-
105
-        // now let's loop and set up the _events property.  At the same time we'll set up attendee properties.
106
-        // we'll actually use the generated line_item identifiers for our loop
107
-        $dtts = $tkts = [];
108
-        foreach ($events as $id => $event) {
109
-            if (! $event instanceof EE_Event) {
110
-                continue;
111
-            }
112
-            $this->_events[ $id ]['ID']       = $id;
113
-            $this->_events[ $id ]['name']     = $event->get('EVT_name');
114
-            $datetime                         = $event->get_first_related('Datetime');
115
-            $tickets                          = $datetime instanceof EE_Datetime ? $datetime->get_many_related(
116
-                'Ticket',
117
-                ['default_where_conditions' => 'none']
118
-            ) : [];
119
-            $this->_events[ $id ]['event']    = $event;
120
-            $this->_events[ $id ]['reg_objs'] = [];
121
-            $this->_events[ $id ]['tkt_objs'] = $tickets;
122
-            $this->_events[ $id ]['dtt_objs'] = [];
123
-
124
-            $dttcache = [];
125
-            $tkts     = [];
126
-            foreach ($tickets as $ticket) {
127
-                if (! $ticket instanceof EE_Ticket) {
128
-                    continue;
129
-                }
130
-                $reldatetime                       = $ticket->datetimes();
131
-                $tkts[ $ticket->ID() ]             = [];
132
-                $tkts[ $ticket->ID() ]['ticket']   = $ticket;
133
-                $tkts[ $ticket->ID() ]['dtt_objs'] = $reldatetime;
134
-                $tkts[ $ticket->ID() ]['att_objs'] = $attendees;
135
-                $tkts[ $ticket->ID() ]['count']    = count($attendees);
136
-                $tkts[ $ticket->ID() ]['EE_Event'] = $event;
137
-                foreach ($reldatetime as $datetime) {
138
-                    if ($datetime instanceof EE_Datetime && ! isset($dtts[ $datetime->ID() ])) {
139
-                        $this->_events[ $id ]['dtt_objs'][ $datetime->ID() ] = $datetime;
140
-                        $dtts[ $datetime->ID() ]['datetime']                 = $datetime;
141
-                        $dtts[ $datetime->ID() ]['tkt_objs'][]               = $ticket;
142
-                        $dtts[ $datetime->ID() ]['evt_objs'][]               = $event;
143
-                        $dttcache[ $datetime->ID() ]                         = $datetime;
144
-                    }
145
-                }
146
-            }
147
-
148
-            $this->_events[ $id ]['total_attendees'] = count($attendees);
149
-            $this->_events[ $id ]['att_objs']        = $attendees;
150
-
151
-            // let's also setup the dummy attendees property!
152
-            foreach ($attendees as $att_key => $attendee) {
153
-                if (! $attendee instanceof EE_Attendee) {
154
-                    continue;
155
-                }
156
-                $this->_attendees[ $att_key ]['line_ref'][] =
157
-                    $id;  // so later it can be determined what events this attendee registered for!
158
-                $this->_attendees[ $att_key ]['evt_objs'][] = $event;
159
-                $this->_attendees[ $att_key ]['att_obj']    = $attendee;
160
-                // $this->_attendees[$att_key]['registration_id'] = 0;
161
-                $this->_attendees[ $att_key ]['attendee_email'] = $attendee->email();
162
-                $this->_attendees[ $att_key ]['tkt_objs']       = $tickets;
163
-                if ($att_key == 999999991) {
164
-                    $this->_attendees[ $att_key ]['ans_objs'][999]  = $answers_n_questions['answers'][999];
165
-                    $this->_attendees[ $att_key ]['ans_objs'][1002] = $answers_n_questions['answers'][1002];
166
-                    $this->_attendees[ $att_key ]['ans_objs'][1005] = $answers_n_questions['answers'][1005];
167
-                } elseif ($att_key == 999999992) {
168
-                    $this->_attendees[ $att_key ]['ans_objs'][1000] = $answers_n_questions['answers'][1000];
169
-                    $this->_attendees[ $att_key ]['ans_objs'][1003] = $answers_n_questions['answers'][1003];
170
-                    $this->_attendees[ $att_key ]['ans_objs'][1006] = $answers_n_questions['answers'][1006];
171
-                } elseif ($att_key == 999999993) {
172
-                    $this->_attendees[ $att_key ]['ans_objs'][1001] = $answers_n_questions['answers'][1001];
173
-                    $this->_attendees[ $att_key ]['ans_objs'][1004] = $answers_n_questions['answers'][1004];
174
-                    $this->_attendees[ $att_key ]['ans_objs'][1007] = $answers_n_questions['answers'][1007];
175
-                }
176
-            }
177
-        }
178
-
179
-        $this->tickets            = $tkts;
180
-        $this->datetimes          = $dtts;
181
-        $this->answers            = $answers_n_questions['answers'];
182
-        $this->questions          = $answers_n_questions['questions'];
183
-        $this->total_ticket_count = count($tkts) * count($this->_attendees);
184
-    }
185
-
186
-
187
-    /**
188
-     * This just returns an array of dummy attendee objects that we'll use to attach to events for our preview data
189
-     *
190
-     * @access private
191
-     * @return array an array of attendee objects
192
-     * @throws EE_Error
193
-     * @throws EE_Error
194
-     */
195
-    private function _get_some_attendees()
196
-    {
197
-        // let's just setup a dummy array of various attendee details
198
-        $dummy_attendees = [
199
-            0 => [
200
-                'Luke',
201
-                'Skywalker',
202
-                '[email protected]',
203
-                '804 Bantha Dr.',
204
-                'Complex 8',
205
-                'Mos Eisley',
206
-                32,
207
-                'US',
208
-                'f0r3e',
209
-                '222-333-4763',
210
-                false,
211
-                '999999991',
212
-            ],
213
-            1 => [
214
-                'Princess',
215
-                'Leia',
216
-                '[email protected]',
217
-                '1456 Valley Way Boulevard',
218
-                'Suite 9',
219
-                'Alderaan',
220
-                15,
221
-                'US',
222
-                'c1h2c',
223
-                '78-123-111-1111',
224
-                false,
225
-                '999999992',
226
-            ],
227
-            2 => [
228
-                'Yoda',
229
-                'I Am',
230
-                '[email protected]',
231
-                '4th Tree',
232
-                '5th Knot',
233
-                'Marsh',
234
-                22,
235
-                'US',
236
-                'l18n',
237
-                '999-999-9999',
238
-                false,
239
-                '999999993',
240
-            ],
241
-        ];
242
-
243
-        // let's generate the attendee objects
244
-        $attendees = [];
245
-        $var_array = [
246
-            'fname',
247
-            'lname',
248
-            'email',
249
-            'address',
250
-            'address2',
251
-            'city',
252
-            'staid',
253
-            'cntry',
254
-            'zip',
255
-            'phone',
256
-            'deleted',
257
-            'attid',
258
-        ];
259
-
260
-        // EE_Registry::instance()->load_class( 'Attendee', array(), FALSE, false, TRUE );
261
-        foreach ($dummy_attendees as $dummy) {
262
-            $att = array_combine($var_array, $dummy);
263
-            extract($att);
264
-            /** @var $fname string */
265
-            /** @var $lname string */
266
-            /** @var $address string */
267
-            /** @var $address2 string */
268
-            /** @var $city string */
269
-            /** @var $staid string */
270
-            /** @var $cntry string */
271
-            /** @var $zip string */
272
-            /** @var $email string */
273
-            /** @var $phone string */
274
-            /** @var $attid string */
275
-            $attendees[ $attid ] = EE_Attendee::new_instance(
276
-                [
277
-                    'ATT_fname'    => $fname,
278
-                    'ATT_lname'    => $lname,
279
-                    'ATT_address'  => $address,
280
-                    'ATT_address2' => $address2,
281
-                    'ATT_city'     => $city,
282
-                    'STA_ID'       => $staid,
283
-                    'CNT_ISO'      => $cntry,
284
-                    'ATT_zip'      => $zip,
285
-                    'ATT_email'    => $email,
286
-                    'ATT_phone'    => $phone,
287
-                    'ATT_ID'       => $attid,
288
-                ]
289
-            );
290
-        }
291
-
292
-        return $attendees;
293
-    }
294
-
295
-
296
-    /**
297
-     * Return an array of dummy question objects indexed by answer id and dummy answer objects indexed by answer id.
298
-     * This will be used in our dummy data setup
299
-     *
300
-     * @return array
301
-     * @throws EE_Error
302
-     * @throws ReflectionException
303
-     */
304
-    private function _get_some_q_and_as()
305
-    {
306
-        $quests_array = [
307
-            0 => [
308
-                555,
309
-                esc_html__('What is your favorite planet?', 'event_espresso'),
310
-                0,
311
-            ],
312
-            1 => [
313
-                556,
314
-                esc_html__('What is your favorite food?', 'event_espresso'),
315
-                0,
316
-            ],
317
-            2 => [
318
-                557,
319
-                esc_html__('How many lightyears have you travelled', 'event_espresso'),
320
-                0,
321
-            ],
322
-        ];
323
-
324
-        $ans_array = [
325
-            0 => [
326
-                999,
327
-                555,
328
-                'Tattoine',
329
-            ],
330
-            1 => [
331
-                1000,
332
-                555,
333
-                'Alderaan',
334
-            ],
335
-            2 => [
336
-                1001,
337
-                555,
338
-                'Dantooine',
339
-            ],
340
-            3 => [
341
-                1002,
342
-                556,
343
-                'Fish Fingers',
344
-            ],
345
-            4 => [
346
-                1003,
347
-                556,
348
-                'Sushi',
349
-            ],
350
-            5 => [
351
-                1004,
352
-                556,
353
-                'Water',
354
-            ],
355
-            6 => [
356
-                1005,
357
-                557,
358
-                'A lot',
359
-            ],
360
-            7 => [
361
-                1006,
362
-                557,
363
-                "That's none of your business.",
364
-            ],
365
-            8 => [
366
-                1007,
367
-                557,
368
-                "People less travel me then.",
369
-            ],
370
-        ];
371
-
372
-        $qst_columns = ['QST_ID', 'QST_display_text', 'QST_system'];
373
-        $ans_columns = ['ANS_ID', 'QST_ID', 'ANS_value'];
374
-
375
-        // EE_Registry::instance()->load_class( 'Question', array(), FALSE, TRUE, TRUE );
376
-        // EE_Registry::instance()->load_class( 'Answer', array(), FALSE, TRUE, TRUE );
377
-
378
-        $qsts = [];
379
-        // first the questions
380
-        foreach ($quests_array as $qst) {
381
-            $qstobj                    = array_combine($qst_columns, $qst);
382
-            $qsts[ $qstobj['QST_ID'] ] = EE_Question::new_instance($qstobj);
383
-        }
384
-
385
-        // now the answers (and we'll setup our arrays)
386
-        $q_n_as = [];
387
-        foreach ($ans_array as $ans) {
388
-            $ansobj                               = array_combine($ans_columns, $ans);
389
-            $ansobj                               = EE_Answer::new_instance($ansobj);
390
-            $q_n_as['answers'][ $ansobj->ID() ]   = $ansobj;
391
-            $q_n_as['questions'][ $ansobj->ID() ] = $qsts[ $ansobj->get('QST_ID') ];
392
-        }
393
-
394
-        return $q_n_as;
395
-    }
396
-
397
-
398
-    /**
399
-     * Return an array of event objects from the database
400
-     *
401
-     * If event ids are not included then we'll just retrieve the first published event from the database.
402
-     *
403
-     * @param array $event_ids if set, this will be an array of event ids to obtain events for.
404
-     *
405
-     * @return array    An array of event objects from the db.
406
-     * @throws EE_Error
407
-     */
408
-    private function _get_some_events(array $event_ids = [])
409
-    {
410
-        /** @var RequestInterface $request */
411
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
412
-        // if we have an evt_id then we want to make sure we use that for the preview
413
-        // (because a specific event template is being viewed);
414
-        $event_ids = $request->getRequestParam('evt_id', $event_ids, 'int', true);
415
-        $limit     = ! empty($event_ids)
416
-            ? null
417
-            : apply_filters('FHEE__EE_Messages_Preview_incoming_data___get_some_events__limit', '0,1');
418
-
419
-        $where = ! empty($event_ids)
420
-            ? [
421
-                'EVT_ID'                 => ['IN', $event_ids],
422
-                'Datetime.Ticket.TKT_ID' => ['>', 1],
423
-            ]
424
-            : ['Datetime.Ticket.TKT_ID' => ['>', 1]];
425
-
426
-        return EEM_Event::instance()->get_all([$where, 'limit' => $limit]);
427
-    }
428
-
429
-
430
-    /**
431
-     * @throws EE_Error
432
-     * @throws ReflectionException
433
-     */
434
-    protected function _setup_data()
435
-    {
436
-        // need to figure out the running total for test purposes so... we're going to create a temp cart and add the tickets to it!
437
-        if (EE_Registry::instance()->SSN instanceof EE_Session) {
438
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
439
-            $session = EE_Registry::instance()->SSN;
440
-        } else {
441
-            $session = EE_Registry::instance()->load_core('Session');
442
-        }
443
-        $cart = EE_Cart::instance(null, $session);
444
-
445
-        // add tickets to cart
446
-        foreach ($this->tickets as $ticket) {
447
-            $cart->add_ticket_to_cart($ticket['ticket']);
448
-        }
449
-
450
-        // setup txn property
451
-        $this->txn = EE_Transaction::new_instance(
452
-            [
453
-                'TXN_timestamp'    => time(), // unix timestamp
454
-                'TXN_total'        => 0, // txn_total
455
-                'TXN_paid'         => 0, // txn_paid
456
-                'STS_ID'           => EEM_Transaction::incomplete_status_code, // sts_id
457
-                'TXN_session_data' => null, // dump of txn session object (we're just going to leave blank here)
458
-                'TXN_hash_salt'    => null, // hash salt blank as well
459
-                'TXN_ID'           => 999999,
460
-            ]
461
-        );
462
-
463
-
464
-        // setup reg_objects
465
-        // note we're setting up a reg object for each attendee in each event but ALSO adding to the reg_object array.
466
-        $this->reg_objs = [];
467
-        $regid          = 9999990;
468
-        foreach ($this->_attendees as $key => $attendee) {
469
-            // note we need to setup reg_objects for each event this attendee belongs to
470
-            $regatt = $attendee['att_obj'] instanceof EE_Attendee ? $attendee['att_obj']->ID() : null;
471
-            $regtxn = $this->txn->ID();
472
-            $regcnt = 1;
473
-            foreach ($attendee['line_ref'] as $evtid) {
474
-                foreach ($this->_events[ $evtid ]['tkt_objs'] as $ticket) {
475
-                    if (! $ticket instanceof EE_Ticket) {
476
-                        continue;
477
-                    }
478
-                    $reg_array                                            = [
479
-                        'EVT_ID'           => $evtid,
480
-                        'ATT_ID'           => $regatt,
481
-                        'TXN_ID'           => $regtxn,
482
-                        'TKT_ID'           => $ticket->ID(),
483
-                        'STS_ID'           => EEM_Registration::status_id_pending_payment,
484
-                        'REG_date'         => time(),
485
-                        'REG_final_price'  => $ticket->get('TKT_price'),
486
-                        'REG_session'      => 'dummy_session_id',
487
-                        'REG_code'         => $regid . '-dummy-generated-code',
488
-                        'REG_url_link'     => $regcnt . '-daafpapasdlfakasdfpqasdfasdf',
489
-                        'REG_count'        => $regcnt,
490
-                        'REG_group_size'   => $this->_events[ $evtid ]['total_attendees'],
491
-                        'REG_att_is_going' => true,
492
-                        'REG_ID'           => $regid,
493
-                    ];
494
-                    $REG_OBJ                                              = EE_Registration::new_instance($reg_array);
495
-                    $this->_attendees[ $key ]['reg_objs'][ $regid ]       = $REG_OBJ;
496
-                    $this->_events[ $evtid ]['reg_objs'][]                = $REG_OBJ;
497
-                    $this->reg_objs[]                                     = $REG_OBJ;
498
-                    $this->tickets[ $ticket->ID() ]['reg_objs'][ $regid ] = $REG_OBJ;
499
-
500
-                    $regcnt++;
501
-                    $regid++;
502
-                }
503
-            }
504
-        }
505
-
506
-
507
-        // setup line items!
508
-        $line_item_total = EEH_Line_Item::create_total_line_item($this->txn);
509
-
510
-        // add tickets
511
-        foreach ($this->tickets as $item) {
512
-            $qty    = $item['count'];
513
-            $ticket = $item['ticket'];
514
-            EEH_Line_Item::add_ticket_purchase($line_item_total, $ticket, $qty);
515
-        }
516
-
517
-        $shipping_line_item = EE_Line_Item::new_instance(
518
-            [
519
-                'LIN_name'       => esc_html__(
520
-                    'Shipping Surcharge',
521
-                    'event_espresso'
522
-                ),
523
-                'LIN_desc'       => esc_html__(
524
-                    'Sent via Millenium Falcon',
525
-                    'event_espresso'
526
-                ),
527
-                'LIN_unit_price' => 20,
528
-                'LIN_quantity'   => 1,
529
-                'LIN_is_taxable' => true,
530
-                'LIN_total'      => 20,
531
-                'LIN_type'       => EEM_Line_Item::type_line_item,
532
-            ]
533
-        );
534
-        EEH_Line_Item::add_item($line_item_total, $shipping_line_item);
535
-        $this->additional_line_items = [$shipping_line_item];
536
-
537
-        // now let's add taxes
538
-        EEH_Line_Item::apply_taxes($line_item_total);
539
-
540
-        // now we should be able to get the items we need from this object
541
-        $event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children();
542
-        $line_items       = [];
543
-        foreach ($event_line_items as $line_item) {
544
-            if (! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
545
-                continue;
546
-            }
547
-            $ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item);
548
-            foreach ($ticket_line_items as $ticket_line_item) {
549
-                if (! $ticket_line_item instanceof EE_Line_Item) {
550
-                    continue;
551
-                }
552
-                $this->tickets[ $ticket_line_item->OBJ_ID() ]['line_item']      = $ticket_line_item;
553
-                $this->tickets[ $ticket_line_item->OBJ_ID() ]['sub_line_items'] = $ticket_line_item->children();
554
-                $line_items[ $ticket_line_item->ID() ]['children']              = $ticket_line_item->children();
555
-                $line_items[ $ticket_line_item->ID() ]['EE_Ticket']             =
556
-                    $this->tickets[ $ticket_line_item->OBJ_ID() ]['ticket'];
557
-            }
558
-        }
559
-
560
-        $this->line_items_with_children = $line_items;
561
-        $this->tax_line_items           = $line_item_total->tax_descendants();
562
-
563
-        // add proper total to transaction object.
564
-        $grand_total                 = $line_item_total->recalculate_total_including_taxes();
565
-        $this->grand_total_line_item = $line_item_total;
566
-        $this->txn->set_total($grand_total);
567
-
568
-
569
-        // add additional details for each registration
570
-        foreach ($this->reg_objs as $reg) {
571
-            if (! $reg instanceof EE_Registration) {
572
-                continue;
573
-            }
574
-            $this->_registrations[ $reg->ID() ]['tkt_obj']  = $this->tickets[ $reg->get('TKT_ID') ]['ticket'];
575
-            $this->_registrations[ $reg->ID() ]['evt_obj']  = $this->_events[ $reg->get('EVT_ID') ]['event'];
576
-            $this->_registrations[ $reg->ID() ]['reg_obj']  = $reg;
577
-            $this->_registrations[ $reg->ID() ]['ans_objs'] = $this->_attendees[ $reg->get('ATT_ID') ]['ans_objs'];
578
-            $this->_registrations[ $reg->ID() ]['att_obj']  = $this->_attendees[ $reg->get('ATT_ID') ]['att_obj'];
579
-            $this->_registrations[ $reg->ID() ]['dtt_objs'] = $this->tickets[ $reg->get('TKT_ID') ]['dtt_objs'];
580
-        }
581
-
582
-
583
-        // events and attendees
584
-        $this->events        = $this->_events;
585
-        $this->attendees     = $this->_attendees;
586
-        $this->registrations = $this->_registrations;
587
-
588
-        $attendees_to_shift = $this->_attendees;
589
-
590
-        // setup primary attendee property
591
-        $this->primary_attendee_data = [
592
-            'fname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
593
-                ? $this->_attendees[999999991]['att_obj']->fname()
594
-                : '',
595
-
596
-            'lname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
597
-                ? $this->_attendees[999999991]['att_obj']->lname()
598
-                : '',
599
-
600
-            'email' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
601
-                ? $this->_attendees[999999991]['att_obj']->email()
602
-                : '',
603
-
604
-            'att_obj' => $this->_attendees[999999991]['att_obj'],
605
-
606
-            'reg_obj' => array_shift($attendees_to_shift[999999991]['reg_objs']),
607
-        ];
608
-
609
-        // reg_info property
610
-        // note this isn't referenced by any shortcode parsers so we'll ignore for now.
611
-        $this->reg_info = [];
612
-
613
-        // let's set a reg_obj for messengers expecting one.
614
-        $this->reg_obj = array_shift($this->_attendees[999999991]['reg_objs']);
615
-
616
-        // the below are just dummy items.
617
-        $this->user_id     = 1;
618
-        $this->ip_address  = '192.0.2.1';
619
-        $this->user_agent  = '';
620
-        $this->init_access = time();
621
-        $this->last_access = time();
622
-    }
24
+	// some specific properties we need for this class
25
+	private $_events        = [];
26
+
27
+	private $_attendees     = [];
28
+
29
+	private $_registrations = [];
30
+
31
+
32
+	/**
33
+	 * For the constructor of this special preview class.  We're either looking for an event id or empty data.  If we
34
+	 * have an event id (or ids) then we'll use that as the source for the "dummy" data.  If the data is empty then
35
+	 * we'll get the first three published events from the users database and use that as a source.
36
+	 *
37
+	 * @param array $data
38
+	 * @throws EE_Error
39
+	 * @throws EE_Error
40
+	 * @throws ReflectionException
41
+	 */
42
+	public function __construct($data = [])
43
+	{
44
+		$this->_data = isset($data['event_ids']) ? $data['event_ids'] : [];
45
+		$this->_setup_attendees_events();
46
+		parent::__construct($data);
47
+	}
48
+
49
+
50
+	/**
51
+	 * Returns database safe representation of the data later used to when instantiating this object.
52
+	 *
53
+	 * @param array $data The incoming data to be prepped.
54
+	 *
55
+	 * @return array   The prepped data for db
56
+	 */
57
+	public static function convert_data_for_persistent_storage($data)
58
+	{
59
+		return $data;
60
+	}
61
+
62
+
63
+	/**
64
+	 * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
65
+	 * can be sent into this method and converted back into the format used for instantiating with this data handler.
66
+	 *
67
+	 * @param array $data
68
+	 *
69
+	 * @return array
70
+	 */
71
+	public static function convert_data_from_persistent_storage($data)
72
+	{
73
+		return $data;
74
+	}
75
+
76
+
77
+	/**
78
+	 * This will just setup the _events property in the expected format.
79
+	 *
80
+	 * @throws EE_Error
81
+	 * @throws ReflectionException
82
+	 */
83
+	private function _setup_attendees_events()
84
+	{
85
+
86
+		// setup some attendee objects
87
+		$attendees = $this->_get_some_attendees();
88
+
89
+		// if empty $data we'll do a query to get some events from the server.
90
+		// otherwise we'll retrieve the event data for the given ids.
91
+		$events = $this->_get_some_events($this->_data);
92
+
93
+		$answers_n_questions = $this->_get_some_q_and_as();
94
+
95
+		if (count($events) < 1) {
96
+			throw new EE_Error(
97
+				esc_html__(
98
+					'We can\'t generate a preview for you because there are no active events in your database',
99
+					'event_espresso'
100
+				)
101
+			);
102
+		}
103
+
104
+
105
+		// now let's loop and set up the _events property.  At the same time we'll set up attendee properties.
106
+		// we'll actually use the generated line_item identifiers for our loop
107
+		$dtts = $tkts = [];
108
+		foreach ($events as $id => $event) {
109
+			if (! $event instanceof EE_Event) {
110
+				continue;
111
+			}
112
+			$this->_events[ $id ]['ID']       = $id;
113
+			$this->_events[ $id ]['name']     = $event->get('EVT_name');
114
+			$datetime                         = $event->get_first_related('Datetime');
115
+			$tickets                          = $datetime instanceof EE_Datetime ? $datetime->get_many_related(
116
+				'Ticket',
117
+				['default_where_conditions' => 'none']
118
+			) : [];
119
+			$this->_events[ $id ]['event']    = $event;
120
+			$this->_events[ $id ]['reg_objs'] = [];
121
+			$this->_events[ $id ]['tkt_objs'] = $tickets;
122
+			$this->_events[ $id ]['dtt_objs'] = [];
123
+
124
+			$dttcache = [];
125
+			$tkts     = [];
126
+			foreach ($tickets as $ticket) {
127
+				if (! $ticket instanceof EE_Ticket) {
128
+					continue;
129
+				}
130
+				$reldatetime                       = $ticket->datetimes();
131
+				$tkts[ $ticket->ID() ]             = [];
132
+				$tkts[ $ticket->ID() ]['ticket']   = $ticket;
133
+				$tkts[ $ticket->ID() ]['dtt_objs'] = $reldatetime;
134
+				$tkts[ $ticket->ID() ]['att_objs'] = $attendees;
135
+				$tkts[ $ticket->ID() ]['count']    = count($attendees);
136
+				$tkts[ $ticket->ID() ]['EE_Event'] = $event;
137
+				foreach ($reldatetime as $datetime) {
138
+					if ($datetime instanceof EE_Datetime && ! isset($dtts[ $datetime->ID() ])) {
139
+						$this->_events[ $id ]['dtt_objs'][ $datetime->ID() ] = $datetime;
140
+						$dtts[ $datetime->ID() ]['datetime']                 = $datetime;
141
+						$dtts[ $datetime->ID() ]['tkt_objs'][]               = $ticket;
142
+						$dtts[ $datetime->ID() ]['evt_objs'][]               = $event;
143
+						$dttcache[ $datetime->ID() ]                         = $datetime;
144
+					}
145
+				}
146
+			}
147
+
148
+			$this->_events[ $id ]['total_attendees'] = count($attendees);
149
+			$this->_events[ $id ]['att_objs']        = $attendees;
150
+
151
+			// let's also setup the dummy attendees property!
152
+			foreach ($attendees as $att_key => $attendee) {
153
+				if (! $attendee instanceof EE_Attendee) {
154
+					continue;
155
+				}
156
+				$this->_attendees[ $att_key ]['line_ref'][] =
157
+					$id;  // so later it can be determined what events this attendee registered for!
158
+				$this->_attendees[ $att_key ]['evt_objs'][] = $event;
159
+				$this->_attendees[ $att_key ]['att_obj']    = $attendee;
160
+				// $this->_attendees[$att_key]['registration_id'] = 0;
161
+				$this->_attendees[ $att_key ]['attendee_email'] = $attendee->email();
162
+				$this->_attendees[ $att_key ]['tkt_objs']       = $tickets;
163
+				if ($att_key == 999999991) {
164
+					$this->_attendees[ $att_key ]['ans_objs'][999]  = $answers_n_questions['answers'][999];
165
+					$this->_attendees[ $att_key ]['ans_objs'][1002] = $answers_n_questions['answers'][1002];
166
+					$this->_attendees[ $att_key ]['ans_objs'][1005] = $answers_n_questions['answers'][1005];
167
+				} elseif ($att_key == 999999992) {
168
+					$this->_attendees[ $att_key ]['ans_objs'][1000] = $answers_n_questions['answers'][1000];
169
+					$this->_attendees[ $att_key ]['ans_objs'][1003] = $answers_n_questions['answers'][1003];
170
+					$this->_attendees[ $att_key ]['ans_objs'][1006] = $answers_n_questions['answers'][1006];
171
+				} elseif ($att_key == 999999993) {
172
+					$this->_attendees[ $att_key ]['ans_objs'][1001] = $answers_n_questions['answers'][1001];
173
+					$this->_attendees[ $att_key ]['ans_objs'][1004] = $answers_n_questions['answers'][1004];
174
+					$this->_attendees[ $att_key ]['ans_objs'][1007] = $answers_n_questions['answers'][1007];
175
+				}
176
+			}
177
+		}
178
+
179
+		$this->tickets            = $tkts;
180
+		$this->datetimes          = $dtts;
181
+		$this->answers            = $answers_n_questions['answers'];
182
+		$this->questions          = $answers_n_questions['questions'];
183
+		$this->total_ticket_count = count($tkts) * count($this->_attendees);
184
+	}
185
+
186
+
187
+	/**
188
+	 * This just returns an array of dummy attendee objects that we'll use to attach to events for our preview data
189
+	 *
190
+	 * @access private
191
+	 * @return array an array of attendee objects
192
+	 * @throws EE_Error
193
+	 * @throws EE_Error
194
+	 */
195
+	private function _get_some_attendees()
196
+	{
197
+		// let's just setup a dummy array of various attendee details
198
+		$dummy_attendees = [
199
+			0 => [
200
+				'Luke',
201
+				'Skywalker',
202
+				'[email protected]',
203
+				'804 Bantha Dr.',
204
+				'Complex 8',
205
+				'Mos Eisley',
206
+				32,
207
+				'US',
208
+				'f0r3e',
209
+				'222-333-4763',
210
+				false,
211
+				'999999991',
212
+			],
213
+			1 => [
214
+				'Princess',
215
+				'Leia',
216
+				'[email protected]',
217
+				'1456 Valley Way Boulevard',
218
+				'Suite 9',
219
+				'Alderaan',
220
+				15,
221
+				'US',
222
+				'c1h2c',
223
+				'78-123-111-1111',
224
+				false,
225
+				'999999992',
226
+			],
227
+			2 => [
228
+				'Yoda',
229
+				'I Am',
230
+				'[email protected]',
231
+				'4th Tree',
232
+				'5th Knot',
233
+				'Marsh',
234
+				22,
235
+				'US',
236
+				'l18n',
237
+				'999-999-9999',
238
+				false,
239
+				'999999993',
240
+			],
241
+		];
242
+
243
+		// let's generate the attendee objects
244
+		$attendees = [];
245
+		$var_array = [
246
+			'fname',
247
+			'lname',
248
+			'email',
249
+			'address',
250
+			'address2',
251
+			'city',
252
+			'staid',
253
+			'cntry',
254
+			'zip',
255
+			'phone',
256
+			'deleted',
257
+			'attid',
258
+		];
259
+
260
+		// EE_Registry::instance()->load_class( 'Attendee', array(), FALSE, false, TRUE );
261
+		foreach ($dummy_attendees as $dummy) {
262
+			$att = array_combine($var_array, $dummy);
263
+			extract($att);
264
+			/** @var $fname string */
265
+			/** @var $lname string */
266
+			/** @var $address string */
267
+			/** @var $address2 string */
268
+			/** @var $city string */
269
+			/** @var $staid string */
270
+			/** @var $cntry string */
271
+			/** @var $zip string */
272
+			/** @var $email string */
273
+			/** @var $phone string */
274
+			/** @var $attid string */
275
+			$attendees[ $attid ] = EE_Attendee::new_instance(
276
+				[
277
+					'ATT_fname'    => $fname,
278
+					'ATT_lname'    => $lname,
279
+					'ATT_address'  => $address,
280
+					'ATT_address2' => $address2,
281
+					'ATT_city'     => $city,
282
+					'STA_ID'       => $staid,
283
+					'CNT_ISO'      => $cntry,
284
+					'ATT_zip'      => $zip,
285
+					'ATT_email'    => $email,
286
+					'ATT_phone'    => $phone,
287
+					'ATT_ID'       => $attid,
288
+				]
289
+			);
290
+		}
291
+
292
+		return $attendees;
293
+	}
294
+
295
+
296
+	/**
297
+	 * Return an array of dummy question objects indexed by answer id and dummy answer objects indexed by answer id.
298
+	 * This will be used in our dummy data setup
299
+	 *
300
+	 * @return array
301
+	 * @throws EE_Error
302
+	 * @throws ReflectionException
303
+	 */
304
+	private function _get_some_q_and_as()
305
+	{
306
+		$quests_array = [
307
+			0 => [
308
+				555,
309
+				esc_html__('What is your favorite planet?', 'event_espresso'),
310
+				0,
311
+			],
312
+			1 => [
313
+				556,
314
+				esc_html__('What is your favorite food?', 'event_espresso'),
315
+				0,
316
+			],
317
+			2 => [
318
+				557,
319
+				esc_html__('How many lightyears have you travelled', 'event_espresso'),
320
+				0,
321
+			],
322
+		];
323
+
324
+		$ans_array = [
325
+			0 => [
326
+				999,
327
+				555,
328
+				'Tattoine',
329
+			],
330
+			1 => [
331
+				1000,
332
+				555,
333
+				'Alderaan',
334
+			],
335
+			2 => [
336
+				1001,
337
+				555,
338
+				'Dantooine',
339
+			],
340
+			3 => [
341
+				1002,
342
+				556,
343
+				'Fish Fingers',
344
+			],
345
+			4 => [
346
+				1003,
347
+				556,
348
+				'Sushi',
349
+			],
350
+			5 => [
351
+				1004,
352
+				556,
353
+				'Water',
354
+			],
355
+			6 => [
356
+				1005,
357
+				557,
358
+				'A lot',
359
+			],
360
+			7 => [
361
+				1006,
362
+				557,
363
+				"That's none of your business.",
364
+			],
365
+			8 => [
366
+				1007,
367
+				557,
368
+				"People less travel me then.",
369
+			],
370
+		];
371
+
372
+		$qst_columns = ['QST_ID', 'QST_display_text', 'QST_system'];
373
+		$ans_columns = ['ANS_ID', 'QST_ID', 'ANS_value'];
374
+
375
+		// EE_Registry::instance()->load_class( 'Question', array(), FALSE, TRUE, TRUE );
376
+		// EE_Registry::instance()->load_class( 'Answer', array(), FALSE, TRUE, TRUE );
377
+
378
+		$qsts = [];
379
+		// first the questions
380
+		foreach ($quests_array as $qst) {
381
+			$qstobj                    = array_combine($qst_columns, $qst);
382
+			$qsts[ $qstobj['QST_ID'] ] = EE_Question::new_instance($qstobj);
383
+		}
384
+
385
+		// now the answers (and we'll setup our arrays)
386
+		$q_n_as = [];
387
+		foreach ($ans_array as $ans) {
388
+			$ansobj                               = array_combine($ans_columns, $ans);
389
+			$ansobj                               = EE_Answer::new_instance($ansobj);
390
+			$q_n_as['answers'][ $ansobj->ID() ]   = $ansobj;
391
+			$q_n_as['questions'][ $ansobj->ID() ] = $qsts[ $ansobj->get('QST_ID') ];
392
+		}
393
+
394
+		return $q_n_as;
395
+	}
396
+
397
+
398
+	/**
399
+	 * Return an array of event objects from the database
400
+	 *
401
+	 * If event ids are not included then we'll just retrieve the first published event from the database.
402
+	 *
403
+	 * @param array $event_ids if set, this will be an array of event ids to obtain events for.
404
+	 *
405
+	 * @return array    An array of event objects from the db.
406
+	 * @throws EE_Error
407
+	 */
408
+	private function _get_some_events(array $event_ids = [])
409
+	{
410
+		/** @var RequestInterface $request */
411
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
412
+		// if we have an evt_id then we want to make sure we use that for the preview
413
+		// (because a specific event template is being viewed);
414
+		$event_ids = $request->getRequestParam('evt_id', $event_ids, 'int', true);
415
+		$limit     = ! empty($event_ids)
416
+			? null
417
+			: apply_filters('FHEE__EE_Messages_Preview_incoming_data___get_some_events__limit', '0,1');
418
+
419
+		$where = ! empty($event_ids)
420
+			? [
421
+				'EVT_ID'                 => ['IN', $event_ids],
422
+				'Datetime.Ticket.TKT_ID' => ['>', 1],
423
+			]
424
+			: ['Datetime.Ticket.TKT_ID' => ['>', 1]];
425
+
426
+		return EEM_Event::instance()->get_all([$where, 'limit' => $limit]);
427
+	}
428
+
429
+
430
+	/**
431
+	 * @throws EE_Error
432
+	 * @throws ReflectionException
433
+	 */
434
+	protected function _setup_data()
435
+	{
436
+		// need to figure out the running total for test purposes so... we're going to create a temp cart and add the tickets to it!
437
+		if (EE_Registry::instance()->SSN instanceof EE_Session) {
438
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
439
+			$session = EE_Registry::instance()->SSN;
440
+		} else {
441
+			$session = EE_Registry::instance()->load_core('Session');
442
+		}
443
+		$cart = EE_Cart::instance(null, $session);
444
+
445
+		// add tickets to cart
446
+		foreach ($this->tickets as $ticket) {
447
+			$cart->add_ticket_to_cart($ticket['ticket']);
448
+		}
449
+
450
+		// setup txn property
451
+		$this->txn = EE_Transaction::new_instance(
452
+			[
453
+				'TXN_timestamp'    => time(), // unix timestamp
454
+				'TXN_total'        => 0, // txn_total
455
+				'TXN_paid'         => 0, // txn_paid
456
+				'STS_ID'           => EEM_Transaction::incomplete_status_code, // sts_id
457
+				'TXN_session_data' => null, // dump of txn session object (we're just going to leave blank here)
458
+				'TXN_hash_salt'    => null, // hash salt blank as well
459
+				'TXN_ID'           => 999999,
460
+			]
461
+		);
462
+
463
+
464
+		// setup reg_objects
465
+		// note we're setting up a reg object for each attendee in each event but ALSO adding to the reg_object array.
466
+		$this->reg_objs = [];
467
+		$regid          = 9999990;
468
+		foreach ($this->_attendees as $key => $attendee) {
469
+			// note we need to setup reg_objects for each event this attendee belongs to
470
+			$regatt = $attendee['att_obj'] instanceof EE_Attendee ? $attendee['att_obj']->ID() : null;
471
+			$regtxn = $this->txn->ID();
472
+			$regcnt = 1;
473
+			foreach ($attendee['line_ref'] as $evtid) {
474
+				foreach ($this->_events[ $evtid ]['tkt_objs'] as $ticket) {
475
+					if (! $ticket instanceof EE_Ticket) {
476
+						continue;
477
+					}
478
+					$reg_array                                            = [
479
+						'EVT_ID'           => $evtid,
480
+						'ATT_ID'           => $regatt,
481
+						'TXN_ID'           => $regtxn,
482
+						'TKT_ID'           => $ticket->ID(),
483
+						'STS_ID'           => EEM_Registration::status_id_pending_payment,
484
+						'REG_date'         => time(),
485
+						'REG_final_price'  => $ticket->get('TKT_price'),
486
+						'REG_session'      => 'dummy_session_id',
487
+						'REG_code'         => $regid . '-dummy-generated-code',
488
+						'REG_url_link'     => $regcnt . '-daafpapasdlfakasdfpqasdfasdf',
489
+						'REG_count'        => $regcnt,
490
+						'REG_group_size'   => $this->_events[ $evtid ]['total_attendees'],
491
+						'REG_att_is_going' => true,
492
+						'REG_ID'           => $regid,
493
+					];
494
+					$REG_OBJ                                              = EE_Registration::new_instance($reg_array);
495
+					$this->_attendees[ $key ]['reg_objs'][ $regid ]       = $REG_OBJ;
496
+					$this->_events[ $evtid ]['reg_objs'][]                = $REG_OBJ;
497
+					$this->reg_objs[]                                     = $REG_OBJ;
498
+					$this->tickets[ $ticket->ID() ]['reg_objs'][ $regid ] = $REG_OBJ;
499
+
500
+					$regcnt++;
501
+					$regid++;
502
+				}
503
+			}
504
+		}
505
+
506
+
507
+		// setup line items!
508
+		$line_item_total = EEH_Line_Item::create_total_line_item($this->txn);
509
+
510
+		// add tickets
511
+		foreach ($this->tickets as $item) {
512
+			$qty    = $item['count'];
513
+			$ticket = $item['ticket'];
514
+			EEH_Line_Item::add_ticket_purchase($line_item_total, $ticket, $qty);
515
+		}
516
+
517
+		$shipping_line_item = EE_Line_Item::new_instance(
518
+			[
519
+				'LIN_name'       => esc_html__(
520
+					'Shipping Surcharge',
521
+					'event_espresso'
522
+				),
523
+				'LIN_desc'       => esc_html__(
524
+					'Sent via Millenium Falcon',
525
+					'event_espresso'
526
+				),
527
+				'LIN_unit_price' => 20,
528
+				'LIN_quantity'   => 1,
529
+				'LIN_is_taxable' => true,
530
+				'LIN_total'      => 20,
531
+				'LIN_type'       => EEM_Line_Item::type_line_item,
532
+			]
533
+		);
534
+		EEH_Line_Item::add_item($line_item_total, $shipping_line_item);
535
+		$this->additional_line_items = [$shipping_line_item];
536
+
537
+		// now let's add taxes
538
+		EEH_Line_Item::apply_taxes($line_item_total);
539
+
540
+		// now we should be able to get the items we need from this object
541
+		$event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children();
542
+		$line_items       = [];
543
+		foreach ($event_line_items as $line_item) {
544
+			if (! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
545
+				continue;
546
+			}
547
+			$ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item);
548
+			foreach ($ticket_line_items as $ticket_line_item) {
549
+				if (! $ticket_line_item instanceof EE_Line_Item) {
550
+					continue;
551
+				}
552
+				$this->tickets[ $ticket_line_item->OBJ_ID() ]['line_item']      = $ticket_line_item;
553
+				$this->tickets[ $ticket_line_item->OBJ_ID() ]['sub_line_items'] = $ticket_line_item->children();
554
+				$line_items[ $ticket_line_item->ID() ]['children']              = $ticket_line_item->children();
555
+				$line_items[ $ticket_line_item->ID() ]['EE_Ticket']             =
556
+					$this->tickets[ $ticket_line_item->OBJ_ID() ]['ticket'];
557
+			}
558
+		}
559
+
560
+		$this->line_items_with_children = $line_items;
561
+		$this->tax_line_items           = $line_item_total->tax_descendants();
562
+
563
+		// add proper total to transaction object.
564
+		$grand_total                 = $line_item_total->recalculate_total_including_taxes();
565
+		$this->grand_total_line_item = $line_item_total;
566
+		$this->txn->set_total($grand_total);
567
+
568
+
569
+		// add additional details for each registration
570
+		foreach ($this->reg_objs as $reg) {
571
+			if (! $reg instanceof EE_Registration) {
572
+				continue;
573
+			}
574
+			$this->_registrations[ $reg->ID() ]['tkt_obj']  = $this->tickets[ $reg->get('TKT_ID') ]['ticket'];
575
+			$this->_registrations[ $reg->ID() ]['evt_obj']  = $this->_events[ $reg->get('EVT_ID') ]['event'];
576
+			$this->_registrations[ $reg->ID() ]['reg_obj']  = $reg;
577
+			$this->_registrations[ $reg->ID() ]['ans_objs'] = $this->_attendees[ $reg->get('ATT_ID') ]['ans_objs'];
578
+			$this->_registrations[ $reg->ID() ]['att_obj']  = $this->_attendees[ $reg->get('ATT_ID') ]['att_obj'];
579
+			$this->_registrations[ $reg->ID() ]['dtt_objs'] = $this->tickets[ $reg->get('TKT_ID') ]['dtt_objs'];
580
+		}
581
+
582
+
583
+		// events and attendees
584
+		$this->events        = $this->_events;
585
+		$this->attendees     = $this->_attendees;
586
+		$this->registrations = $this->_registrations;
587
+
588
+		$attendees_to_shift = $this->_attendees;
589
+
590
+		// setup primary attendee property
591
+		$this->primary_attendee_data = [
592
+			'fname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
593
+				? $this->_attendees[999999991]['att_obj']->fname()
594
+				: '',
595
+
596
+			'lname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
597
+				? $this->_attendees[999999991]['att_obj']->lname()
598
+				: '',
599
+
600
+			'email' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
601
+				? $this->_attendees[999999991]['att_obj']->email()
602
+				: '',
603
+
604
+			'att_obj' => $this->_attendees[999999991]['att_obj'],
605
+
606
+			'reg_obj' => array_shift($attendees_to_shift[999999991]['reg_objs']),
607
+		];
608
+
609
+		// reg_info property
610
+		// note this isn't referenced by any shortcode parsers so we'll ignore for now.
611
+		$this->reg_info = [];
612
+
613
+		// let's set a reg_obj for messengers expecting one.
614
+		$this->reg_obj = array_shift($this->_attendees[999999991]['reg_objs']);
615
+
616
+		// the below are just dummy items.
617
+		$this->user_id     = 1;
618
+		$this->ip_address  = '192.0.2.1';
619
+		$this->user_agent  = '';
620
+		$this->init_access = time();
621
+		$this->last_access = time();
622
+	}
623 623
 }
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_Offsite_Gateway.lib.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -15,117 +15,117 @@
 block discarded – undo
15 15
 abstract class EE_Offsite_Gateway extends EE_Gateway
16 16
 {
17 17
 
18
-    /**
19
-     * whether or not the gateway uses an IPN
20
-     * that is sent in a separate request than the returning registrant.
21
-     * if false, then we need to process the payment results manually
22
-     * as soon as the registrant returns from the off-site gateway
23
-     *
24
-     * @type bool
25
-     */
26
-    protected $_uses_separate_IPN_request = false;
18
+	/**
19
+	 * whether or not the gateway uses an IPN
20
+	 * that is sent in a separate request than the returning registrant.
21
+	 * if false, then we need to process the payment results manually
22
+	 * as soon as the registrant returns from the off-site gateway
23
+	 *
24
+	 * @type bool
25
+	 */
26
+	protected $_uses_separate_IPN_request = false;
27 27
 
28 28
 
29
-    /**
30
-     * @return EE_Offsite_Gateway
31
-     */
32
-    public function __construct()
33
-    {
34
-        $this->_supports_receiving_refunds = true;
35
-        parent::__construct();
36
-    }
29
+	/**
30
+	 * @return EE_Offsite_Gateway
31
+	 */
32
+	public function __construct()
33
+	{
34
+		$this->_supports_receiving_refunds = true;
35
+		parent::__construct();
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * Adds information into the payment object's redirect_url and redirect_args so
41
-     * client code can use that payment to know where (and with what information)
42
-     * to redirect the user to in order to make the payment on the offsite gateway's website.
43
-     * Saving the payment from within this method is unnecessary,
44
-     * as it is the responsibility of client code to save it.
45
-     *
46
-     * @param EE_Payment $payment    to process
47
-     * @param array      $billing_info
48
-     * @param string     $return_url URL to send the user to after a successful payment on the payment provider's
49
-     *                               website
50
-     * @param string     $notify_url URL to send the instant payment notification
51
-     * @param string     $cancel_url URL to send the user to after a cancelled payment attempt on teh payment
52
-     *                               provider's website
53
-     * @return EE_Payment
54
-     */
55
-    abstract public function set_redirection_info(
56
-        $payment,
57
-        $billing_info = array(),
58
-        $return_url = null,
59
-        $notify_url = null,
60
-        $cancel_url = null
61
-    );
39
+	/**
40
+	 * Adds information into the payment object's redirect_url and redirect_args so
41
+	 * client code can use that payment to know where (and with what information)
42
+	 * to redirect the user to in order to make the payment on the offsite gateway's website.
43
+	 * Saving the payment from within this method is unnecessary,
44
+	 * as it is the responsibility of client code to save it.
45
+	 *
46
+	 * @param EE_Payment $payment    to process
47
+	 * @param array      $billing_info
48
+	 * @param string     $return_url URL to send the user to after a successful payment on the payment provider's
49
+	 *                               website
50
+	 * @param string     $notify_url URL to send the instant payment notification
51
+	 * @param string     $cancel_url URL to send the user to after a cancelled payment attempt on teh payment
52
+	 *                               provider's website
53
+	 * @return EE_Payment
54
+	 */
55
+	abstract public function set_redirection_info(
56
+		$payment,
57
+		$billing_info = array(),
58
+		$return_url = null,
59
+		$notify_url = null,
60
+		$cancel_url = null
61
+	);
62 62
 
63 63
 
64
-    /**
65
-     * Often used for IPNs. But applies the info in $update_info to the payment.
66
-     * What is $update_info? Often the contents of request, but not necessarily. Whatever
67
-     * the payment method passes in. Saving the payment from within this method is unnecessary,
68
-     * as it is the responsibility of client code to save it.
69
-     *
70
-     * @param array           $update_info of whatever
71
-     * @param EEI_Transaction $transaction
72
-     * @return EEI_Payment updated
73
-     */
74
-    abstract public function handle_payment_update($update_info, $transaction);
64
+	/**
65
+	 * Often used for IPNs. But applies the info in $update_info to the payment.
66
+	 * What is $update_info? Often the contents of request, but not necessarily. Whatever
67
+	 * the payment method passes in. Saving the payment from within this method is unnecessary,
68
+	 * as it is the responsibility of client code to save it.
69
+	 *
70
+	 * @param array           $update_info of whatever
71
+	 * @param EEI_Transaction $transaction
72
+	 * @return EEI_Payment updated
73
+	 */
74
+	abstract public function handle_payment_update($update_info, $transaction);
75 75
 
76 76
 
77
-    /**
78
-     * uses_separate_IPN_request
79
-     *
80
-     * return true or false for whether or not the gateway uses an IPN
81
-     * that is sent in a separate request than the returning registrant.
82
-     * if false, then we need to process the payment results manually
83
-     * as soon as the registrant returns from the off-site gateway
84
-     *
85
-     * @deprecated since version 4.8.39.rc.001 please use handle_IPN_in_this_request() instead
86
-     *
87
-     * @return bool
88
-     */
89
-    public function uses_separate_IPN_request()
90
-    {
91
-        return $this->_uses_separate_IPN_request;
92
-    }
77
+	/**
78
+	 * uses_separate_IPN_request
79
+	 *
80
+	 * return true or false for whether or not the gateway uses an IPN
81
+	 * that is sent in a separate request than the returning registrant.
82
+	 * if false, then we need to process the payment results manually
83
+	 * as soon as the registrant returns from the off-site gateway
84
+	 *
85
+	 * @deprecated since version 4.8.39.rc.001 please use handle_IPN_in_this_request() instead
86
+	 *
87
+	 * @return bool
88
+	 */
89
+	public function uses_separate_IPN_request()
90
+	{
91
+		return $this->_uses_separate_IPN_request;
92
+	}
93 93
 
94 94
 
95
-    /**
96
-     * set_uses_separate_IPN_request
97
-     *
98
-     * @access protected
99
-     * @param boolean $uses_separate_IPN_request
100
-     */
101
-    protected function set_uses_separate_IPN_request($uses_separate_IPN_request)
102
-    {
103
-        $this->_uses_separate_IPN_request = filter_var($uses_separate_IPN_request, FILTER_VALIDATE_BOOLEAN);
104
-    }
95
+	/**
96
+	 * set_uses_separate_IPN_request
97
+	 *
98
+	 * @access protected
99
+	 * @param boolean $uses_separate_IPN_request
100
+	 */
101
+	protected function set_uses_separate_IPN_request($uses_separate_IPN_request)
102
+	{
103
+		$this->_uses_separate_IPN_request = filter_var($uses_separate_IPN_request, FILTER_VALIDATE_BOOLEAN);
104
+	}
105 105
 
106
-    /**
107
-     * Allows gateway to dynamically decide whether or not to handle a payment update
108
-     * by overriding this method. By default, if this is a "true" IPN (meaning
109
-     * it's a separate request from when the user returns from the offsite gateway)
110
-     * and this gateway class is setup to handle IPNs in separate "true" IPNs, then
111
-     * this will return true, otherwise it will return false.
112
-     * If however, this is a request when the user is returning
113
-     * from an offsite gateway, and this gateway class is setup to process the payment
114
-     * data when the user returns, then this will return true.
115
-     *
116
-     * @param array   $request_data
117
-     * @param boolean $separate_IPN_request
118
-     * @return boolean
119
-     */
120
-    public function handle_IPN_in_this_request($request_data, $separate_IPN_request)
121
-    {
122
-        if ($separate_IPN_request) {
123
-            // payment data being sent in a request separate from the user
124
-            // it is this other request that will update the TXN and payment info
125
-            return $this->_uses_separate_IPN_request;
126
-        } else {
127
-            // it's a request where the user returned from an offsite gateway WITH the payment data
128
-            return ! $this->_uses_separate_IPN_request;
129
-        }
130
-    }
106
+	/**
107
+	 * Allows gateway to dynamically decide whether or not to handle a payment update
108
+	 * by overriding this method. By default, if this is a "true" IPN (meaning
109
+	 * it's a separate request from when the user returns from the offsite gateway)
110
+	 * and this gateway class is setup to handle IPNs in separate "true" IPNs, then
111
+	 * this will return true, otherwise it will return false.
112
+	 * If however, this is a request when the user is returning
113
+	 * from an offsite gateway, and this gateway class is setup to process the payment
114
+	 * data when the user returns, then this will return true.
115
+	 *
116
+	 * @param array   $request_data
117
+	 * @param boolean $separate_IPN_request
118
+	 * @return boolean
119
+	 */
120
+	public function handle_IPN_in_this_request($request_data, $separate_IPN_request)
121
+	{
122
+		if ($separate_IPN_request) {
123
+			// payment data being sent in a request separate from the user
124
+			// it is this other request that will update the TXN and payment info
125
+			return $this->_uses_separate_IPN_request;
126
+		} else {
127
+			// it's a request where the user returned from an offsite gateway WITH the payment data
128
+			return ! $this->_uses_separate_IPN_request;
129
+		}
130
+	}
131 131
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Fixed_Hidden_Input.input.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -10,15 +10,15 @@
 block discarded – undo
10 10
 {
11 11
 
12 12
 
13
-    /**
14
-     * Fixed Inputs are inputs that do NOT accept user input
15
-     * therefore they will ALWAYS return the default value that was set upon their creation
16
-     * and NO normalization or sanitization will occur because the request value is being ignored
17
-     *
18
-     * @param array $req_data
19
-     * @return boolean whether or not there was an error
20
-     */
21
-    protected function _normalize($req_data)
22
-    {
23
-    }
13
+	/**
14
+	 * Fixed Inputs are inputs that do NOT accept user input
15
+	 * therefore they will ALWAYS return the default value that was set upon their creation
16
+	 * and NO normalization or sanitization will occur because the request value is being ignored
17
+	 *
18
+	 * @param array $req_data
19
+	 * @return boolean whether or not there was an error
20
+	 */
21
+	protected function _normalize($req_data)
22
+	{
23
+	}
24 24
 }
Please login to merge, or discard this patch.