Completed
Branch master (d65695)
by
unknown
04:25
created
caffeinated/core/libraries/shortcodes/EE_Question_List_Shortcodes.lib.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -94,16 +94,16 @@
 block discarded – undo
94 94
             ? $this->_extra_data['template']['question_list']
95 95
             : $template;
96 96
         $ans_result       = '';
97
-        $answers          = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'])
98
-            ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']
97
+        $answers          = ! empty($this->_extra_data['data']->registrations[$reg_obj->ID()]['ans_objs'])
98
+            ? $this->_extra_data['data']->registrations[$reg_obj->ID()]['ans_objs']
99 99
             : [];
100 100
         $questions        = ! empty($this->_extra_data['data']->questions)
101 101
             ? $this->_extra_data['data']->questions
102 102
             : [];
103 103
         foreach ($answers as $answer) {
104 104
             // first see if the question is in our $questions array.  If not then try to get from answer object
105
-            $question = isset($questions[ $answer->ID() ])
106
-                ? $questions[ $answer->ID() ]
105
+            $question = isset($questions[$answer->ID()])
106
+                ? $questions[$answer->ID()]
107 107
                 : null;
108 108
             $question = ! $question instanceof EE_Question
109 109
                 ? $answer->question()
Please login to merge, or discard this patch.
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -15,113 +15,113 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Question_List_Shortcodes extends EE_Shortcodes
17 17
 {
18
-    public function __construct()
19
-    {
20
-        parent::__construct();
21
-    }
18
+	public function __construct()
19
+	{
20
+		parent::__construct();
21
+	}
22 22
 
23 23
 
24
-    protected function _init_props()
25
-    {
26
-        $this->label       = esc_html__('Questions and Answers Shortcodes', 'event_espresso');
27
-        $this->description = esc_html__('All shortcodes related to custom questions and answers', 'event_espresso');
28
-        $this->_shortcodes = [
29
-            '[QUESTION_LIST]' => esc_html__(
30
-                'This is used to indicate where you want the list of questions and answers to show for the registrant.  You place this within the "[attendee_list]" field.',
31
-                'event_espresso'
32
-            ),
33
-        ];
34
-    }
24
+	protected function _init_props()
25
+	{
26
+		$this->label       = esc_html__('Questions and Answers Shortcodes', 'event_espresso');
27
+		$this->description = esc_html__('All shortcodes related to custom questions and answers', 'event_espresso');
28
+		$this->_shortcodes = [
29
+			'[QUESTION_LIST]' => esc_html__(
30
+				'This is used to indicate where you want the list of questions and answers to show for the registrant.  You place this within the "[attendee_list]" field.',
31
+				'event_espresso'
32
+			),
33
+		];
34
+	}
35 35
 
36 36
 
37
-    /**
38
-     * @param string $shortcode
39
-     * @return string
40
-     * @throws EE_Error
41
-     * @throws ReflectionException
42
-     */
43
-    protected function _parser($shortcode)
44
-    {
45
-        switch ($shortcode) {
46
-            case '[QUESTION_LIST]':
47
-                return $this->_get_question_list();
48
-        }
49
-        return '';
50
-    }
37
+	/**
38
+	 * @param string $shortcode
39
+	 * @return string
40
+	 * @throws EE_Error
41
+	 * @throws ReflectionException
42
+	 */
43
+	protected function _parser($shortcode)
44
+	{
45
+		switch ($shortcode) {
46
+			case '[QUESTION_LIST]':
47
+				return $this->_get_question_list();
48
+		}
49
+		return '';
50
+	}
51 51
 
52 52
 
53
-    /**
54
-     * @return string
55
-     * @throws EE_Error
56
-     * @throws ReflectionException
57
-     */
58
-    protected function _get_question_list()
59
-    {
60
-        $this->_validate_list_requirements();
53
+	/**
54
+	 * @return string
55
+	 * @throws EE_Error
56
+	 * @throws ReflectionException
57
+	 */
58
+	protected function _get_question_list()
59
+	{
60
+		$this->_validate_list_requirements();
61 61
 
62
-        // for when [QUESTION_LIST] is used in the [attendee_list] field.
63
-        if ($this->_data['data'] instanceof EE_Registration) {
64
-            return $this->_get_question_answer_list_for_attendee();
65
-        }
62
+		// for when [QUESTION_LIST] is used in the [attendee_list] field.
63
+		if ($this->_data['data'] instanceof EE_Registration) {
64
+			return $this->_get_question_answer_list_for_attendee();
65
+		}
66 66
 
67
-        // for when [QUESTION_LIST] is used in the main content field.
68
-        if (
69
-            $this->_data['data'] instanceof EE_Messages_Addressee
70
-            && $this->_data['data']->reg_obj instanceof EE_Registration
71
-        ) {
72
-            return $this->_get_question_answer_list_for_attendee($this->_data['data']->reg_obj);
73
-        }
74
-        return '';
75
-    }
67
+		// for when [QUESTION_LIST] is used in the main content field.
68
+		if (
69
+			$this->_data['data'] instanceof EE_Messages_Addressee
70
+			&& $this->_data['data']->reg_obj instanceof EE_Registration
71
+		) {
72
+			return $this->_get_question_answer_list_for_attendee($this->_data['data']->reg_obj);
73
+		}
74
+		return '';
75
+	}
76 76
 
77 77
 
78
-    /**
79
-     * Note when we parse the "[question_list]" shortcode for attendees we're actually going to retrieve the list of
80
-     * answers for that attendee since that is what we really need (we can derive the questions from the answers);
81
-     *
82
-     * @param null $reg_obj
83
-     * @return string parsed template.
84
-     * @throws EE_Error
85
-     * @throws ReflectionException
86
-     */
87
-    private function _get_question_answer_list_for_attendee($reg_obj = null)
88
-    {
89
-        $valid_shortcodes = ['question'];
90
-        $reg_obj          = $reg_obj instanceof EE_Registration
91
-            ? $reg_obj
92
-            : $this->_data['data'];
93
-        $template         = is_array($this->_data['template']) && isset($this->_data['template']['question_list'])
94
-            ? $this->_data['template']['question_list']
95
-            : '';
96
-        $template         = empty($template) && isset($this->_extra_data['template']['question_list'])
97
-            ? $this->_extra_data['template']['question_list']
98
-            : $template;
99
-        $ans_result       = '';
100
-        $answers          = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'])
101
-            ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']
102
-            : [];
103
-        $questions        = ! empty($this->_extra_data['data']->questions)
104
-            ? $this->_extra_data['data']->questions
105
-            : [];
106
-        foreach ($answers as $answer) {
107
-            // first see if the question is in our $questions array.  If not then try to get from answer object
108
-            $question = isset($questions[ $answer->ID() ])
109
-                ? $questions[ $answer->ID() ]
110
-                : null;
111
-            $question = ! $question instanceof EE_Question
112
-                ? $answer->question()
113
-                : $question;
114
-            if ($question instanceof EE_Question and $question->admin_only()) {
115
-                continue;
116
-            }
117
-            $ans_result .= $this->_shortcode_helper->parse_question_list_template(
118
-                $template,
119
-                $answer,
120
-                $valid_shortcodes,
121
-                $this->_extra_data
122
-            );
123
-        }
78
+	/**
79
+	 * Note when we parse the "[question_list]" shortcode for attendees we're actually going to retrieve the list of
80
+	 * answers for that attendee since that is what we really need (we can derive the questions from the answers);
81
+	 *
82
+	 * @param null $reg_obj
83
+	 * @return string parsed template.
84
+	 * @throws EE_Error
85
+	 * @throws ReflectionException
86
+	 */
87
+	private function _get_question_answer_list_for_attendee($reg_obj = null)
88
+	{
89
+		$valid_shortcodes = ['question'];
90
+		$reg_obj          = $reg_obj instanceof EE_Registration
91
+			? $reg_obj
92
+			: $this->_data['data'];
93
+		$template         = is_array($this->_data['template']) && isset($this->_data['template']['question_list'])
94
+			? $this->_data['template']['question_list']
95
+			: '';
96
+		$template         = empty($template) && isset($this->_extra_data['template']['question_list'])
97
+			? $this->_extra_data['template']['question_list']
98
+			: $template;
99
+		$ans_result       = '';
100
+		$answers          = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'])
101
+			? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']
102
+			: [];
103
+		$questions        = ! empty($this->_extra_data['data']->questions)
104
+			? $this->_extra_data['data']->questions
105
+			: [];
106
+		foreach ($answers as $answer) {
107
+			// first see if the question is in our $questions array.  If not then try to get from answer object
108
+			$question = isset($questions[ $answer->ID() ])
109
+				? $questions[ $answer->ID() ]
110
+				: null;
111
+			$question = ! $question instanceof EE_Question
112
+				? $answer->question()
113
+				: $question;
114
+			if ($question instanceof EE_Question and $question->admin_only()) {
115
+				continue;
116
+			}
117
+			$ans_result .= $this->_shortcode_helper->parse_question_list_template(
118
+				$template,
119
+				$answer,
120
+				$valid_shortcodes,
121
+				$this->_extra_data
122
+			);
123
+		}
124 124
 
125
-        return $ans_result;
126
-    }
125
+		return $ans_result;
126
+	}
127 127
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/ModelDataTranslator.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         ) {
70 70
             $new_value_maybe_array = [];
71 71
             foreach ($original_value_maybe_array as $array_key => $array_item) {
72
-                $new_value_maybe_array[ $array_key ] = ModelDataTranslator::prepareFieldValueFromJson(
72
+                $new_value_maybe_array[$array_key] = ModelDataTranslator::prepareFieldValueFromJson(
73 73
                     $field_obj,
74 74
                     $array_item,
75 75
                     $requested_version,
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         if (is_array($original_value_maybe_array)) {
104 104
             $new_value = [];
105 105
             foreach ($original_value_maybe_array as $key => $value) {
106
-                $new_value[ $key ] = ModelDataTranslator::prepareFieldValuesForJson(
106
+                $new_value[$key] = ModelDataTranslator::prepareFieldValuesForJson(
107 107
                     $field_obj,
108 108
                     $value,
109 109
                     $request_version
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
                 '0',
245 245
                 STR_PAD_LEFT
246 246
             );
247
-        return $original_timestamp . $offset_sign . $offset_string;
247
+        return $original_timestamp.$offset_sign.$offset_string;
248 248
     }
249 249
 
250 250
 
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
                     // first, check if its a MySQL timestamp in GMT
324 324
                     $datetime_obj = DateTime::createFromFormat('Y-m-d H:i:s', $original_value);
325 325
                 }
326
-                if (! $datetime_obj instanceof DateTime) {
326
+                if ( ! $datetime_obj instanceof DateTime) {
327 327
                     // so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format?
328 328
                     $datetime_obj = $field_obj->prepare_for_set($original_value);
329 329
                 }
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
                         $original_value,
350 350
                         $field_obj->get_name(),
351 351
                         $field_obj->get_model_name(),
352
-                        $field_obj->get_time_format() . ' ' . $field_obj->get_time_format()
352
+                        $field_obj->get_time_format().' '.$field_obj->get_time_format()
353 353
                     )
354 354
                 );
355 355
             }
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
         }
364 364
         // are we about to send an object? just don't. We have no good way to represent it in JSON.
365 365
         // can't just check using is_object() because that missed PHP incomplete objects
366
-        if (! ModelDataTranslator::isRepresentableInJson($new_value)) {
366
+        if ( ! ModelDataTranslator::isRepresentableInJson($new_value)) {
367 367
             $new_value = [
368 368
                 'error_code'    => 'php_object_not_return',
369 369
                 'error_message' => esc_html__(
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
             if ($query_param_meta->getField() instanceof EE_Model_Field_Base) {
415 415
                 $translated_value = $query_param_meta->determineConditionsQueryParameterValue();
416 416
                 if (
417
-                    (isset($query_param_for_models[ $query_param_meta->getQueryParamKey() ])
417
+                    (isset($query_param_for_models[$query_param_meta->getQueryParamKey()])
418 418
                      && $query_param_meta->isGmtField())
419 419
                     || $translated_value === null
420 420
                 ) {
@@ -423,11 +423,11 @@  discard block
 block discarded – undo
423 423
                     // OR we couldn't create a translated value from their input
424 424
                     continue;
425 425
                 }
426
-                $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $translated_value;
426
+                $query_param_for_models[$query_param_meta->getQueryParamKey()] = $translated_value;
427 427
             } else {
428 428
                 $nested_query_params = $query_param_meta->determineNestedConditionQueryParameters();
429 429
                 if ($nested_query_params) {
430
-                    $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $nested_query_params;
430
+                    $query_param_for_models[$query_param_meta->getQueryParamKey()] = $nested_query_params;
431 431
                 }
432 432
             }
433 433
         }
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
      */
458 458
     public static function removeGmtFromFieldName($field_name)
459 459
     {
460
-        if (! ModelDataTranslator::isGmtDateFieldName($field_name)) {
460
+        if ( ! ModelDataTranslator::isGmtDateFieldName($field_name)) {
461 461
             return $field_name;
462 462
         }
463 463
         $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey(
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
     {
501 501
         $new_array = [];
502 502
         foreach ($field_names as $key => $field_name) {
503
-            $new_array[ $key ] = ModelDataTranslator::prepareFieldNameFromJson($field_name);
503
+            $new_array[$key] = ModelDataTranslator::prepareFieldNameFromJson($field_name);
504 504
         }
505 505
         return $new_array;
506 506
     }
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
     {
518 518
         $new_array = [];
519 519
         foreach ($field_names_as_keys as $field_name => $value) {
520
-            $new_array[ ModelDataTranslator::prepareFieldNameFromJson($field_name) ] = $value;
520
+            $new_array[ModelDataTranslator::prepareFieldNameFromJson($field_name)] = $value;
521 521
         }
522 522
         return $new_array;
523 523
     }
@@ -613,10 +613,10 @@  discard block
 block discarded – undo
613 613
                         $requested_version
614 614
                     );
615 615
                 }
616
-                $query_param_for_models[ $query_param_key ] = $translated_value;
616
+                $query_param_for_models[$query_param_key] = $translated_value;
617 617
             } else {
618 618
                 // so it's not for a field, assume it's a logic query param key
619
-                $query_param_for_models[ $query_param_key ] =
619
+                $query_param_for_models[$query_param_key] =
620 620
                     ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
621 621
                         $query_param_value,
622 622
                         $model,
@@ -668,11 +668,11 @@  discard block
 block discarded – undo
668 668
             );
669 669
         }
670 670
         $number_of_parts       = count($query_param_parts);
671
-        $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
671
+        $last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
672 672
         $field_name            = $last_query_param_part;
673 673
         if ($number_of_parts !== 1) {
674 674
             // the last part is the column name, and there are only 2parts. therefore...
675
-            $model = EE_Registry::instance()->load_model($query_param_parts[ $number_of_parts - 2 ]);
675
+            $model = EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]);
676 676
         }
677 677
         try {
678 678
             return $model->field_settings_for($field_name, false);
Please login to merge, or discard this patch.
Indentation   +654 added lines, -654 removed lines patch added patch discarded remove patch
@@ -38,658 +38,658 @@
 block discarded – undo
38 38
  */
39 39
 class ModelDataTranslator
40 40
 {
41
-    /**
42
-     * We used to use -1 for infinity in the rest api, but that's ambiguous for
43
-     * fields that COULD contain -1; so we use null
44
-     */
45
-    const EE_INF_IN_REST = null;
46
-
47
-
48
-    /**
49
-     * Prepares a possible array of input values from JSON for use by the models
50
-     *
51
-     * @param EE_Model_Field_Base $field_obj
52
-     * @param mixed               $original_value_maybe_array
53
-     * @param string              $requested_version
54
-     * @param string              $timezone_string treat values as being in this timezone
55
-     * @return mixed
56
-     * @throws RestException
57
-     * @throws EE_Error
58
-     */
59
-    public static function prepareFieldValuesFromJson(
60
-        $field_obj,
61
-        $original_value_maybe_array,
62
-        $requested_version,
63
-        $timezone_string = 'UTC'
64
-    ) {
65
-        if (
66
-            is_array($original_value_maybe_array)
67
-            && ! $field_obj instanceof EE_Serialized_Text_Field
68
-        ) {
69
-            $new_value_maybe_array = [];
70
-            foreach ($original_value_maybe_array as $array_key => $array_item) {
71
-                $new_value_maybe_array[ $array_key ] = ModelDataTranslator::prepareFieldValueFromJson(
72
-                    $field_obj,
73
-                    $array_item,
74
-                    $requested_version,
75
-                    $timezone_string
76
-                );
77
-            }
78
-        } else {
79
-            $new_value_maybe_array = ModelDataTranslator::prepareFieldValueFromJson(
80
-                $field_obj,
81
-                $original_value_maybe_array,
82
-                $requested_version,
83
-                $timezone_string
84
-            );
85
-        }
86
-        return $new_value_maybe_array;
87
-    }
88
-
89
-
90
-    /**
91
-     * Prepares an array of field values FOR use in JSON/REST API
92
-     *
93
-     * @param EE_Model_Field_Base $field_obj
94
-     * @param mixed               $original_value_maybe_array
95
-     * @param string              $request_version (eg 4.8.36)
96
-     * @return array|int|string
97
-     * @throws EE_Error
98
-     * @throws EE_Error
99
-     */
100
-    public static function prepareFieldValuesForJson($field_obj, $original_value_maybe_array, $request_version)
101
-    {
102
-        if (is_array($original_value_maybe_array)) {
103
-            $new_value = [];
104
-            foreach ($original_value_maybe_array as $key => $value) {
105
-                $new_value[ $key ] = ModelDataTranslator::prepareFieldValuesForJson(
106
-                    $field_obj,
107
-                    $value,
108
-                    $request_version
109
-                );
110
-            }
111
-        } else {
112
-            $new_value = ModelDataTranslator::prepareFieldValueForJson(
113
-                $field_obj,
114
-                $original_value_maybe_array,
115
-                $request_version
116
-            );
117
-        }
118
-        return $new_value;
119
-    }
120
-
121
-
122
-    /**
123
-     * Prepares incoming data from the json or request parameters for the models'
124
-     * "$query_params".
125
-     *
126
-     * @param EE_Model_Field_Base $field_obj
127
-     * @param mixed               $original_value
128
-     * @param string              $requested_version
129
-     * @param string              $timezone_string treat values as being in this timezone
130
-     * @return mixed
131
-     * @throws RestException
132
-     * @throws DomainException
133
-     * @throws EE_Error
134
-     */
135
-    public static function prepareFieldValueFromJson(
136
-        $field_obj,
137
-        $original_value,
138
-        $requested_version,
139
-        $timezone_string = 'UTC'
140
-    ) {
141
-        // check if they accidentally submitted an error value. If so throw an exception
142
-        if (
143
-            is_array($original_value)
144
-            && isset($original_value['error_code'], $original_value['error_message'])
145
-        ) {
146
-            throw new RestException(
147
-                'rest_submitted_error_value',
148
-                sprintf(
149
-                    esc_html__(
150
-                        'You tried to submit a JSON error object as a value for %1$s. That\'s not allowed.',
151
-                        'event_espresso'
152
-                    ),
153
-                    $field_obj->get_name()
154
-                ),
155
-                [
156
-                    'status' => 400,
157
-                ]
158
-            );
159
-        }
160
-        // double-check for serialized PHP. We never accept serialized PHP. No way Jose.
161
-        ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value);
162
-        $timezone_string =
163
-            $timezone_string !== ''
164
-                ? $timezone_string
165
-                : get_option('timezone_string', '');
166
-        // walk through the submitted data and double-check for serialized PHP. We never accept serialized PHP. No
167
-        // way Jose.
168
-        ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value);
169
-        if (
170
-            $field_obj instanceof EE_Infinite_Integer_Field
171
-            && in_array($original_value, [null, ''], true)
172
-        ) {
173
-            $new_value = EE_INF;
174
-        } elseif ($field_obj instanceof EE_Datetime_Field) {
175
-            $new_value = rest_parse_date(
176
-                self::getTimestampWithTimezoneOffset($original_value, $field_obj, $timezone_string)
177
-            );
178
-            if ($new_value === false) {
179
-                throw new RestException(
180
-                    'invalid_format_for_timestamp',
181
-                    sprintf(
182
-                        esc_html__(
183
-                            'Timestamps received on a request as the value for Date and Time fields must be in %1$s/%2$s format.  The timestamp provided (%3$s) is not that format.',
184
-                            'event_espresso'
185
-                        ),
186
-                        'RFC3339',
187
-                        'ISO8601',
188
-                        $original_value
189
-                    ),
190
-                    [
191
-                        'status' => 400,
192
-                    ]
193
-                );
194
-            }
195
-        } elseif ($field_obj instanceof EE_Boolean_Field) {
196
-            // Interpreted the strings "false", "true", "on", "off" appropriately.
197
-            $new_value = filter_var($original_value, FILTER_VALIDATE_BOOLEAN);
198
-        } else {
199
-            $new_value = $original_value;
200
-        }
201
-        return $new_value;
202
-    }
203
-
204
-
205
-    /**
206
-     * This checks if the incoming timestamp has timezone information already on it and if it doesn't then adds timezone
207
-     * information via details obtained from the host site.
208
-     *
209
-     * @param string            $original_timestamp
210
-     * @param EE_Datetime_Field $datetime_field
211
-     * @param                   $timezone_string
212
-     * @return string
213
-     * @throws DomainException
214
-     */
215
-    private static function getTimestampWithTimezoneOffset(
216
-        $original_timestamp,
217
-        EE_Datetime_Field $datetime_field,
218
-        $timezone_string
219
-    ) {
220
-        // already have timezone information?
221
-        if (preg_match('/Z|([+-])(\d{2}:\d{2})/', $original_timestamp)) {
222
-            // yes, we're ignoring the timezone.
223
-            return $original_timestamp;
224
-        }
225
-        // need to append timezone
226
-        list($offset_sign, $offset_secs) = self::parseTimezoneOffset(
227
-            $datetime_field->get_timezone_offset(
228
-                new DateTimeZone($timezone_string),
229
-                $original_timestamp
230
-            )
231
-        );
232
-        $offset_string =
233
-            str_pad(
234
-                floor($offset_secs / HOUR_IN_SECONDS),
235
-                2,
236
-                '0',
237
-                STR_PAD_LEFT
238
-            )
239
-            . ':'
240
-            . str_pad(
241
-                ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS,
242
-                2,
243
-                '0',
244
-                STR_PAD_LEFT
245
-            );
246
-        return $original_timestamp . $offset_sign . $offset_string;
247
-    }
248
-
249
-
250
-    /**
251
-     * Throws an exception if $data is a serialized PHP string (or somehow an actually PHP object, although I don't
252
-     * think that can happen). If $data is an array, recurses into its keys and values
253
-     *
254
-     * @param mixed $data
255
-     * @return void
256
-     * @throws RestException
257
-     */
258
-    public static function throwExceptionIfContainsSerializedData($data)
259
-    {
260
-        if (is_array($data)) {
261
-            foreach ($data as $key => $value) {
262
-                ModelDataTranslator::throwExceptionIfContainsSerializedData($key);
263
-                ModelDataTranslator::throwExceptionIfContainsSerializedData($value);
264
-            }
265
-        } else {
266
-            if (is_serialized($data) || is_object($data)) {
267
-                throw new RestException(
268
-                    'serialized_data_submission_prohibited',
269
-                    esc_html__(
270
-                    // @codingStandardsIgnoreStart
271
-                        'You tried to submit a string of serialized text. Serialized PHP is prohibited over the EE4 REST API.',
272
-                        // @codingStandardsIgnoreEnd
273
-                        'event_espresso'
274
-                    )
275
-                );
276
-            }
277
-        }
278
-    }
279
-
280
-
281
-    /**
282
-     * determines what's going on with them timezone strings
283
-     *
284
-     * @param int $timezone_offset
285
-     * @return array
286
-     */
287
-    private static function parseTimezoneOffset($timezone_offset)
288
-    {
289
-        $first_char = substr((string) $timezone_offset, 0, 1);
290
-        if ($first_char === '+' || $first_char === '-') {
291
-            $offset_sign = $first_char;
292
-            $offset_secs = substr((string) $timezone_offset, 1);
293
-        } else {
294
-            $offset_sign = '+';
295
-            $offset_secs = $timezone_offset;
296
-        }
297
-        return [$offset_sign, $offset_secs];
298
-    }
299
-
300
-
301
-    /**
302
-     * Prepares a field's value for display in the API
303
-     *
304
-     * @param EE_Model_Field_Base $field_obj
305
-     * @param mixed               $original_value
306
-     * @param string              $requested_version
307
-     * @return mixed
308
-     * @throws EE_Error
309
-     * @throws EE_Error
310
-     */
311
-    public static function prepareFieldValueForJson($field_obj, $original_value, $requested_version)
312
-    {
313
-        if ($original_value === EE_INF) {
314
-            $new_value = ModelDataTranslator::EE_INF_IN_REST;
315
-        } elseif ($field_obj instanceof EE_Datetime_Field) {
316
-            if (is_string($original_value)) {
317
-                // did they submit a string of a unix timestamp?
318
-                if (is_numeric($original_value)) {
319
-                    $datetime_obj = new DateTime();
320
-                    $datetime_obj->setTimestamp((int) $original_value);
321
-                } else {
322
-                    // first, check if its a MySQL timestamp in GMT
323
-                    $datetime_obj = DateTime::createFromFormat('Y-m-d H:i:s', $original_value);
324
-                }
325
-                if (! $datetime_obj instanceof DateTime) {
326
-                    // so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format?
327
-                    $datetime_obj = $field_obj->prepare_for_set($original_value);
328
-                }
329
-                $original_value = $datetime_obj;
330
-            }
331
-            if ($original_value instanceof DateTime) {
332
-                $new_value = $original_value->format('Y-m-d H:i:s');
333
-            } elseif (is_int($original_value) || is_float($original_value)) {
334
-                $new_value = date('Y-m-d H:i:s', $original_value);
335
-            } elseif ($original_value === null || $original_value === '') {
336
-                $new_value = null;
337
-            } else {
338
-                // so it's not a datetime object, unix timestamp (as string or int),
339
-                // MySQL timestamp, or even a string in the field object's format. So no idea what it is
340
-                throw new EE_Error(
341
-                    sprintf(
342
-                        esc_html__(
343
-                        // @codingStandardsIgnoreStart
344
-                            'The value "%1$s" for the field "%2$s" on model "%3$s" could not be understood. It should be a PHP DateTime, unix timestamp, MySQL date, or string in the format "%4$s".',
345
-                            // @codingStandardsIgnoreEnd
346
-                            'event_espresso'
347
-                        ),
348
-                        $original_value,
349
-                        $field_obj->get_name(),
350
-                        $field_obj->get_model_name(),
351
-                        $field_obj->get_time_format() . ' ' . $field_obj->get_time_format()
352
-                    )
353
-                );
354
-            }
355
-            if ($new_value !== null) {
356
-                $new_value = mysql2date('Y-m-d\TH:i:s', $new_value, false);
357
-            }
358
-        } else {
359
-            $new_value = $original_value;
360
-        }
361
-        // are we about to send an object? just don't. We have no good way to represent it in JSON.
362
-        // can't just check using is_object() because that missed PHP incomplete objects
363
-        if (! ModelDataTranslator::isRepresentableInJson($new_value)) {
364
-            $new_value = [
365
-                'error_code'    => 'php_object_not_return',
366
-                'error_message' => esc_html__(
367
-                    'The value of this field in the database is a PHP object, which can\'t be represented in JSON.',
368
-                    'event_espresso'
369
-                ),
370
-            ];
371
-        }
372
-        return apply_filters(
373
-            'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
374
-            $new_value,
375
-            $field_obj,
376
-            $original_value,
377
-            $requested_version
378
-        );
379
-    }
380
-
381
-
382
-    /**
383
-     * Prepares condition-query-parameters (like what's in where and having) from
384
-     * the format expected in the API to use in the models
385
-     *
386
-     * @param array    $inputted_query_params_of_this_type
387
-     * @param EEM_Base $model
388
-     * @param string   $requested_version
389
-     * @param boolean  $writing whether this data will be written to the DB, or if we're just building a query.
390
-     *                          If we're writing to the DB, we don't expect any operators, or any logic query
391
-     *                          parameters, and we also won't accept serialized data unless the current user has
392
-     *                          unfiltered_html.
393
-     * @return array
394
-     * @throws DomainException
395
-     * @throws EE_Error
396
-     * @throws RestException
397
-     * @throws InvalidDataTypeException
398
-     * @throws InvalidInterfaceException
399
-     * @throws InvalidArgumentException
400
-     */
401
-    public static function prepareConditionsQueryParamsForModels(
402
-        $inputted_query_params_of_this_type,
403
-        EEM_Base $model,
404
-        $requested_version,
405
-        $writing = false
406
-    ) {
407
-        $query_param_for_models = [];
408
-        $context                = new RestIncomingQueryParamContext($model, $requested_version, $writing);
409
-        foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
410
-            $query_param_meta = new RestIncomingQueryParamMetadata($query_param_key, $query_param_value, $context);
411
-            if ($query_param_meta->getField() instanceof EE_Model_Field_Base) {
412
-                $translated_value = $query_param_meta->determineConditionsQueryParameterValue();
413
-                if (
414
-                    (isset($query_param_for_models[ $query_param_meta->getQueryParamKey() ])
415
-                     && $query_param_meta->isGmtField())
416
-                    || $translated_value === null
417
-                ) {
418
-                    // they have already provided a non-gmt field, ignore the gmt one. That's what WP core
419
-                    // currently does (they might change it though). See https://core.trac.wordpress.org/ticket/39954
420
-                    // OR we couldn't create a translated value from their input
421
-                    continue;
422
-                }
423
-                $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $translated_value;
424
-            } else {
425
-                $nested_query_params = $query_param_meta->determineNestedConditionQueryParameters();
426
-                if ($nested_query_params) {
427
-                    $query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $nested_query_params;
428
-                }
429
-            }
430
-        }
431
-        return $query_param_for_models;
432
-    }
433
-
434
-
435
-    /**
436
-     * Mostly checks if the last 4 characters are "_gmt", indicating its a
437
-     * gmt date field name
438
-     *
439
-     * @param string $field_name
440
-     * @return boolean
441
-     */
442
-    public static function isGmtDateFieldName($field_name)
443
-    {
444
-        $field_name = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($field_name);
445
-        return substr($field_name, -4, 4) === '_gmt';
446
-    }
447
-
448
-
449
-    /**
450
-     * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone)
451
-     *
452
-     * @param string $field_name
453
-     * @return string
454
-     */
455
-    public static function removeGmtFromFieldName($field_name)
456
-    {
457
-        if (! ModelDataTranslator::isGmtDateFieldName($field_name)) {
458
-            return $field_name;
459
-        }
460
-        $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey(
461
-            $field_name
462
-        );
463
-        $query_param_sans_gmt_and_sans_stars = substr(
464
-            $query_param_sans_stars,
465
-            0,
466
-            strrpos(
467
-                $field_name,
468
-                '_gmt'
469
-            )
470
-        );
471
-        return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name);
472
-    }
473
-
474
-
475
-    /**
476
-     * Takes a field name from the REST API and prepares it for the model querying
477
-     *
478
-     * @param string $field_name
479
-     * @return string
480
-     */
481
-    public static function prepareFieldNameFromJson($field_name)
482
-    {
483
-        if (ModelDataTranslator::isGmtDateFieldName($field_name)) {
484
-            return ModelDataTranslator::removeGmtFromFieldName($field_name);
485
-        }
486
-        return $field_name;
487
-    }
488
-
489
-
490
-    /**
491
-     * Takes array of field names from REST API and prepares for models
492
-     *
493
-     * @param array $field_names
494
-     * @return array of field names (possibly include model prefixes)
495
-     */
496
-    public static function prepareFieldNamesFromJson(array $field_names)
497
-    {
498
-        $new_array = [];
499
-        foreach ($field_names as $key => $field_name) {
500
-            $new_array[ $key ] = ModelDataTranslator::prepareFieldNameFromJson($field_name);
501
-        }
502
-        return $new_array;
503
-    }
504
-
505
-
506
-    /**
507
-     * Takes array where array keys are field names (possibly with model path prefixes)
508
-     * from the REST API and prepares them for model querying
509
-     *
510
-     * @param array $field_names_as_keys
511
-     * @return array
512
-     */
513
-    public static function prepareFieldNamesInArrayKeysFromJson(array $field_names_as_keys)
514
-    {
515
-        $new_array = [];
516
-        foreach ($field_names_as_keys as $field_name => $value) {
517
-            $new_array[ ModelDataTranslator::prepareFieldNameFromJson($field_name) ] = $value;
518
-        }
519
-        return $new_array;
520
-    }
521
-
522
-
523
-    /**
524
-     * Prepares an array of model query params for use in the REST API
525
-     *
526
-     * @param array    $model_query_params
527
-     * @param EEM_Base $model
528
-     * @param string   $requested_version  eg "4.8.36". If null is provided, defaults to the latest release of the EE4
529
-     *                                     REST API
530
-     * @return array which can be passed into the EE4 REST API when querying a model resource
531
-     * @throws EE_Error
532
-     * @throws ReflectionException
533
-     */
534
-    public static function prepareQueryParamsForRestApi(
535
-        array $model_query_params,
536
-        EEM_Base $model,
537
-        $requested_version = null
538
-    ) {
539
-        if ($requested_version === null) {
540
-            $requested_version = EED_Core_Rest_Api::latest_rest_api_version();
541
-        }
542
-        $rest_query_params = $model_query_params;
543
-        if (isset($model_query_params[0])) {
544
-            $rest_query_params['where'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
545
-                $model_query_params[0],
546
-                $model,
547
-                $requested_version
548
-            );
549
-            unset($rest_query_params[0]);
550
-        }
551
-        if (isset($model_query_params['having'])) {
552
-            $rest_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
553
-                $model_query_params['having'],
554
-                $model,
555
-                $requested_version
556
-            );
557
-        }
558
-        return apply_filters(
559
-            'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api',
560
-            $rest_query_params,
561
-            $model_query_params,
562
-            $model,
563
-            $requested_version
564
-        );
565
-    }
566
-
567
-
568
-    /**
569
-     * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api
570
-     *
571
-     * @param array    $inputted_query_params_of_this_type  eg like the "where" or "having" conditions query params
572
-     * @param EEM_Base $model
573
-     * @param string   $requested_version                   eg "4.8.36"
574
-     * @return array ready for use in the rest api query params
575
-     * @throws EE_Error
576
-     * @throws RestException if somehow a PHP object were in the query params' values,*@throws
577
-     * @throws ReflectionException
578
-     *                                                      ReflectionException
579
-     *                                                      (which would be really unusual)
580
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
581
-     */
582
-    public static function prepareConditionsQueryParamsForRestApi(
583
-        $inputted_query_params_of_this_type,
584
-        EEM_Base $model,
585
-        $requested_version
586
-    ) {
587
-        $query_param_for_models = [];
588
-        foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
589
-            $field = ModelDataTranslator::deduceFieldFromQueryParam(
590
-                ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($query_param_key),
591
-                $model
592
-            );
593
-            if ($field instanceof EE_Model_Field_Base) {
594
-                // did they specify an operator?
595
-                if (is_array($query_param_value)) {
596
-                    $op               = $query_param_value[0];
597
-                    $translated_value = [$op];
598
-                    if (isset($query_param_value[1])) {
599
-                        $value               = $query_param_value[1];
600
-                        $translated_value[1] = ModelDataTranslator::prepareFieldValuesForJson(
601
-                            $field,
602
-                            $value,
603
-                            $requested_version
604
-                        );
605
-                    }
606
-                } else {
607
-                    $translated_value = ModelDataTranslator::prepareFieldValueForJson(
608
-                        $field,
609
-                        $query_param_value,
610
-                        $requested_version
611
-                    );
612
-                }
613
-                $query_param_for_models[ $query_param_key ] = $translated_value;
614
-            } else {
615
-                // so it's not for a field, assume it's a logic query param key
616
-                $query_param_for_models[ $query_param_key ] =
617
-                    ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
618
-                        $query_param_value,
619
-                        $model,
620
-                        $requested_version
621
-                    );
622
-            }
623
-        }
624
-        return $query_param_for_models;
625
-    }
626
-
627
-
628
-    /**
629
-     * @param $condition_query_param_key
630
-     * @return string
631
-     */
632
-    public static function removeStarsAndAnythingAfterFromConditionQueryParamKey($condition_query_param_key)
633
-    {
634
-        $pos_of_star = strpos($condition_query_param_key, '*');
635
-        if ($pos_of_star === false) {
636
-            return $condition_query_param_key;
637
-        }
638
-        return substr($condition_query_param_key, 0, $pos_of_star);
639
-    }
640
-
641
-
642
-    /**
643
-     * Takes the input parameter and finds the model field that it indicates.
644
-     *
645
-     * @param string   $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID
646
-     * @param EEM_Base $model
647
-     * @return EE_Model_Field_Base
648
-     * @throws EE_Error
649
-     * @throws ReflectionException
650
-     */
651
-    public static function deduceFieldFromQueryParam($query_param_name, EEM_Base $model)
652
-    {
653
-        // ok, now proceed with deducing which part is the model's name, and which is the field's name
654
-        // which will help us find the database table and column
655
-        $query_param_parts = explode('.', $query_param_name);
656
-        if (empty($query_param_parts)) {
657
-            throw new EE_Error(
658
-                sprintf(
659
-                    esc_html__(
660
-                        '_extract_column_name is empty when trying to extract column and table name from %s',
661
-                        'event_espresso'
662
-                    ),
663
-                    $query_param_name
664
-                )
665
-            );
666
-        }
667
-        $number_of_parts       = count($query_param_parts);
668
-        $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
669
-        $field_name            = $last_query_param_part;
670
-        if ($number_of_parts !== 1) {
671
-            // the last part is the column name, and there are only 2parts. therefore...
672
-            $model = EE_Registry::instance()->load_model($query_param_parts[ $number_of_parts - 2 ]);
673
-        }
674
-        try {
675
-            return $model->field_settings_for($field_name, false);
676
-        } catch (EE_Error $e) {
677
-            return null;
678
-        }
679
-    }
680
-
681
-
682
-    /**
683
-     * Returns true if $data can be easily represented in JSON.
684
-     * Basically, objects and resources can't be represented in JSON easily.
685
-     *
686
-     * @param mixed $data
687
-     * @return bool
688
-     */
689
-    protected static function isRepresentableInJson($data)
690
-    {
691
-        return is_scalar($data)
692
-               || is_array($data)
693
-               || is_null($data);
694
-    }
41
+	/**
42
+	 * We used to use -1 for infinity in the rest api, but that's ambiguous for
43
+	 * fields that COULD contain -1; so we use null
44
+	 */
45
+	const EE_INF_IN_REST = null;
46
+
47
+
48
+	/**
49
+	 * Prepares a possible array of input values from JSON for use by the models
50
+	 *
51
+	 * @param EE_Model_Field_Base $field_obj
52
+	 * @param mixed               $original_value_maybe_array
53
+	 * @param string              $requested_version
54
+	 * @param string              $timezone_string treat values as being in this timezone
55
+	 * @return mixed
56
+	 * @throws RestException
57
+	 * @throws EE_Error
58
+	 */
59
+	public static function prepareFieldValuesFromJson(
60
+		$field_obj,
61
+		$original_value_maybe_array,
62
+		$requested_version,
63
+		$timezone_string = 'UTC'
64
+	) {
65
+		if (
66
+			is_array($original_value_maybe_array)
67
+			&& ! $field_obj instanceof EE_Serialized_Text_Field
68
+		) {
69
+			$new_value_maybe_array = [];
70
+			foreach ($original_value_maybe_array as $array_key => $array_item) {
71
+				$new_value_maybe_array[ $array_key ] = ModelDataTranslator::prepareFieldValueFromJson(
72
+					$field_obj,
73
+					$array_item,
74
+					$requested_version,
75
+					$timezone_string
76
+				);
77
+			}
78
+		} else {
79
+			$new_value_maybe_array = ModelDataTranslator::prepareFieldValueFromJson(
80
+				$field_obj,
81
+				$original_value_maybe_array,
82
+				$requested_version,
83
+				$timezone_string
84
+			);
85
+		}
86
+		return $new_value_maybe_array;
87
+	}
88
+
89
+
90
+	/**
91
+	 * Prepares an array of field values FOR use in JSON/REST API
92
+	 *
93
+	 * @param EE_Model_Field_Base $field_obj
94
+	 * @param mixed               $original_value_maybe_array
95
+	 * @param string              $request_version (eg 4.8.36)
96
+	 * @return array|int|string
97
+	 * @throws EE_Error
98
+	 * @throws EE_Error
99
+	 */
100
+	public static function prepareFieldValuesForJson($field_obj, $original_value_maybe_array, $request_version)
101
+	{
102
+		if (is_array($original_value_maybe_array)) {
103
+			$new_value = [];
104
+			foreach ($original_value_maybe_array as $key => $value) {
105
+				$new_value[ $key ] = ModelDataTranslator::prepareFieldValuesForJson(
106
+					$field_obj,
107
+					$value,
108
+					$request_version
109
+				);
110
+			}
111
+		} else {
112
+			$new_value = ModelDataTranslator::prepareFieldValueForJson(
113
+				$field_obj,
114
+				$original_value_maybe_array,
115
+				$request_version
116
+			);
117
+		}
118
+		return $new_value;
119
+	}
120
+
121
+
122
+	/**
123
+	 * Prepares incoming data from the json or request parameters for the models'
124
+	 * "$query_params".
125
+	 *
126
+	 * @param EE_Model_Field_Base $field_obj
127
+	 * @param mixed               $original_value
128
+	 * @param string              $requested_version
129
+	 * @param string              $timezone_string treat values as being in this timezone
130
+	 * @return mixed
131
+	 * @throws RestException
132
+	 * @throws DomainException
133
+	 * @throws EE_Error
134
+	 */
135
+	public static function prepareFieldValueFromJson(
136
+		$field_obj,
137
+		$original_value,
138
+		$requested_version,
139
+		$timezone_string = 'UTC'
140
+	) {
141
+		// check if they accidentally submitted an error value. If so throw an exception
142
+		if (
143
+			is_array($original_value)
144
+			&& isset($original_value['error_code'], $original_value['error_message'])
145
+		) {
146
+			throw new RestException(
147
+				'rest_submitted_error_value',
148
+				sprintf(
149
+					esc_html__(
150
+						'You tried to submit a JSON error object as a value for %1$s. That\'s not allowed.',
151
+						'event_espresso'
152
+					),
153
+					$field_obj->get_name()
154
+				),
155
+				[
156
+					'status' => 400,
157
+				]
158
+			);
159
+		}
160
+		// double-check for serialized PHP. We never accept serialized PHP. No way Jose.
161
+		ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value);
162
+		$timezone_string =
163
+			$timezone_string !== ''
164
+				? $timezone_string
165
+				: get_option('timezone_string', '');
166
+		// walk through the submitted data and double-check for serialized PHP. We never accept serialized PHP. No
167
+		// way Jose.
168
+		ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value);
169
+		if (
170
+			$field_obj instanceof EE_Infinite_Integer_Field
171
+			&& in_array($original_value, [null, ''], true)
172
+		) {
173
+			$new_value = EE_INF;
174
+		} elseif ($field_obj instanceof EE_Datetime_Field) {
175
+			$new_value = rest_parse_date(
176
+				self::getTimestampWithTimezoneOffset($original_value, $field_obj, $timezone_string)
177
+			);
178
+			if ($new_value === false) {
179
+				throw new RestException(
180
+					'invalid_format_for_timestamp',
181
+					sprintf(
182
+						esc_html__(
183
+							'Timestamps received on a request as the value for Date and Time fields must be in %1$s/%2$s format.  The timestamp provided (%3$s) is not that format.',
184
+							'event_espresso'
185
+						),
186
+						'RFC3339',
187
+						'ISO8601',
188
+						$original_value
189
+					),
190
+					[
191
+						'status' => 400,
192
+					]
193
+				);
194
+			}
195
+		} elseif ($field_obj instanceof EE_Boolean_Field) {
196
+			// Interpreted the strings "false", "true", "on", "off" appropriately.
197
+			$new_value = filter_var($original_value, FILTER_VALIDATE_BOOLEAN);
198
+		} else {
199
+			$new_value = $original_value;
200
+		}
201
+		return $new_value;
202
+	}
203
+
204
+
205
+	/**
206
+	 * This checks if the incoming timestamp has timezone information already on it and if it doesn't then adds timezone
207
+	 * information via details obtained from the host site.
208
+	 *
209
+	 * @param string            $original_timestamp
210
+	 * @param EE_Datetime_Field $datetime_field
211
+	 * @param                   $timezone_string
212
+	 * @return string
213
+	 * @throws DomainException
214
+	 */
215
+	private static function getTimestampWithTimezoneOffset(
216
+		$original_timestamp,
217
+		EE_Datetime_Field $datetime_field,
218
+		$timezone_string
219
+	) {
220
+		// already have timezone information?
221
+		if (preg_match('/Z|([+-])(\d{2}:\d{2})/', $original_timestamp)) {
222
+			// yes, we're ignoring the timezone.
223
+			return $original_timestamp;
224
+		}
225
+		// need to append timezone
226
+		list($offset_sign, $offset_secs) = self::parseTimezoneOffset(
227
+			$datetime_field->get_timezone_offset(
228
+				new DateTimeZone($timezone_string),
229
+				$original_timestamp
230
+			)
231
+		);
232
+		$offset_string =
233
+			str_pad(
234
+				floor($offset_secs / HOUR_IN_SECONDS),
235
+				2,
236
+				'0',
237
+				STR_PAD_LEFT
238
+			)
239
+			. ':'
240
+			. str_pad(
241
+				($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS,
242
+				2,
243
+				'0',
244
+				STR_PAD_LEFT
245
+			);
246
+		return $original_timestamp . $offset_sign . $offset_string;
247
+	}
248
+
249
+
250
+	/**
251
+	 * Throws an exception if $data is a serialized PHP string (or somehow an actually PHP object, although I don't
252
+	 * think that can happen). If $data is an array, recurses into its keys and values
253
+	 *
254
+	 * @param mixed $data
255
+	 * @return void
256
+	 * @throws RestException
257
+	 */
258
+	public static function throwExceptionIfContainsSerializedData($data)
259
+	{
260
+		if (is_array($data)) {
261
+			foreach ($data as $key => $value) {
262
+				ModelDataTranslator::throwExceptionIfContainsSerializedData($key);
263
+				ModelDataTranslator::throwExceptionIfContainsSerializedData($value);
264
+			}
265
+		} else {
266
+			if (is_serialized($data) || is_object($data)) {
267
+				throw new RestException(
268
+					'serialized_data_submission_prohibited',
269
+					esc_html__(
270
+					// @codingStandardsIgnoreStart
271
+						'You tried to submit a string of serialized text. Serialized PHP is prohibited over the EE4 REST API.',
272
+						// @codingStandardsIgnoreEnd
273
+						'event_espresso'
274
+					)
275
+				);
276
+			}
277
+		}
278
+	}
279
+
280
+
281
+	/**
282
+	 * determines what's going on with them timezone strings
283
+	 *
284
+	 * @param int $timezone_offset
285
+	 * @return array
286
+	 */
287
+	private static function parseTimezoneOffset($timezone_offset)
288
+	{
289
+		$first_char = substr((string) $timezone_offset, 0, 1);
290
+		if ($first_char === '+' || $first_char === '-') {
291
+			$offset_sign = $first_char;
292
+			$offset_secs = substr((string) $timezone_offset, 1);
293
+		} else {
294
+			$offset_sign = '+';
295
+			$offset_secs = $timezone_offset;
296
+		}
297
+		return [$offset_sign, $offset_secs];
298
+	}
299
+
300
+
301
+	/**
302
+	 * Prepares a field's value for display in the API
303
+	 *
304
+	 * @param EE_Model_Field_Base $field_obj
305
+	 * @param mixed               $original_value
306
+	 * @param string              $requested_version
307
+	 * @return mixed
308
+	 * @throws EE_Error
309
+	 * @throws EE_Error
310
+	 */
311
+	public static function prepareFieldValueForJson($field_obj, $original_value, $requested_version)
312
+	{
313
+		if ($original_value === EE_INF) {
314
+			$new_value = ModelDataTranslator::EE_INF_IN_REST;
315
+		} elseif ($field_obj instanceof EE_Datetime_Field) {
316
+			if (is_string($original_value)) {
317
+				// did they submit a string of a unix timestamp?
318
+				if (is_numeric($original_value)) {
319
+					$datetime_obj = new DateTime();
320
+					$datetime_obj->setTimestamp((int) $original_value);
321
+				} else {
322
+					// first, check if its a MySQL timestamp in GMT
323
+					$datetime_obj = DateTime::createFromFormat('Y-m-d H:i:s', $original_value);
324
+				}
325
+				if (! $datetime_obj instanceof DateTime) {
326
+					// so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format?
327
+					$datetime_obj = $field_obj->prepare_for_set($original_value);
328
+				}
329
+				$original_value = $datetime_obj;
330
+			}
331
+			if ($original_value instanceof DateTime) {
332
+				$new_value = $original_value->format('Y-m-d H:i:s');
333
+			} elseif (is_int($original_value) || is_float($original_value)) {
334
+				$new_value = date('Y-m-d H:i:s', $original_value);
335
+			} elseif ($original_value === null || $original_value === '') {
336
+				$new_value = null;
337
+			} else {
338
+				// so it's not a datetime object, unix timestamp (as string or int),
339
+				// MySQL timestamp, or even a string in the field object's format. So no idea what it is
340
+				throw new EE_Error(
341
+					sprintf(
342
+						esc_html__(
343
+						// @codingStandardsIgnoreStart
344
+							'The value "%1$s" for the field "%2$s" on model "%3$s" could not be understood. It should be a PHP DateTime, unix timestamp, MySQL date, or string in the format "%4$s".',
345
+							// @codingStandardsIgnoreEnd
346
+							'event_espresso'
347
+						),
348
+						$original_value,
349
+						$field_obj->get_name(),
350
+						$field_obj->get_model_name(),
351
+						$field_obj->get_time_format() . ' ' . $field_obj->get_time_format()
352
+					)
353
+				);
354
+			}
355
+			if ($new_value !== null) {
356
+				$new_value = mysql2date('Y-m-d\TH:i:s', $new_value, false);
357
+			}
358
+		} else {
359
+			$new_value = $original_value;
360
+		}
361
+		// are we about to send an object? just don't. We have no good way to represent it in JSON.
362
+		// can't just check using is_object() because that missed PHP incomplete objects
363
+		if (! ModelDataTranslator::isRepresentableInJson($new_value)) {
364
+			$new_value = [
365
+				'error_code'    => 'php_object_not_return',
366
+				'error_message' => esc_html__(
367
+					'The value of this field in the database is a PHP object, which can\'t be represented in JSON.',
368
+					'event_espresso'
369
+				),
370
+			];
371
+		}
372
+		return apply_filters(
373
+			'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
374
+			$new_value,
375
+			$field_obj,
376
+			$original_value,
377
+			$requested_version
378
+		);
379
+	}
380
+
381
+
382
+	/**
383
+	 * Prepares condition-query-parameters (like what's in where and having) from
384
+	 * the format expected in the API to use in the models
385
+	 *
386
+	 * @param array    $inputted_query_params_of_this_type
387
+	 * @param EEM_Base $model
388
+	 * @param string   $requested_version
389
+	 * @param boolean  $writing whether this data will be written to the DB, or if we're just building a query.
390
+	 *                          If we're writing to the DB, we don't expect any operators, or any logic query
391
+	 *                          parameters, and we also won't accept serialized data unless the current user has
392
+	 *                          unfiltered_html.
393
+	 * @return array
394
+	 * @throws DomainException
395
+	 * @throws EE_Error
396
+	 * @throws RestException
397
+	 * @throws InvalidDataTypeException
398
+	 * @throws InvalidInterfaceException
399
+	 * @throws InvalidArgumentException
400
+	 */
401
+	public static function prepareConditionsQueryParamsForModels(
402
+		$inputted_query_params_of_this_type,
403
+		EEM_Base $model,
404
+		$requested_version,
405
+		$writing = false
406
+	) {
407
+		$query_param_for_models = [];
408
+		$context                = new RestIncomingQueryParamContext($model, $requested_version, $writing);
409
+		foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
410
+			$query_param_meta = new RestIncomingQueryParamMetadata($query_param_key, $query_param_value, $context);
411
+			if ($query_param_meta->getField() instanceof EE_Model_Field_Base) {
412
+				$translated_value = $query_param_meta->determineConditionsQueryParameterValue();
413
+				if (
414
+					(isset($query_param_for_models[ $query_param_meta->getQueryParamKey() ])
415
+					 && $query_param_meta->isGmtField())
416
+					|| $translated_value === null
417
+				) {
418
+					// they have already provided a non-gmt field, ignore the gmt one. That's what WP core
419
+					// currently does (they might change it though). See https://core.trac.wordpress.org/ticket/39954
420
+					// OR we couldn't create a translated value from their input
421
+					continue;
422
+				}
423
+				$query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $translated_value;
424
+			} else {
425
+				$nested_query_params = $query_param_meta->determineNestedConditionQueryParameters();
426
+				if ($nested_query_params) {
427
+					$query_param_for_models[ $query_param_meta->getQueryParamKey() ] = $nested_query_params;
428
+				}
429
+			}
430
+		}
431
+		return $query_param_for_models;
432
+	}
433
+
434
+
435
+	/**
436
+	 * Mostly checks if the last 4 characters are "_gmt", indicating its a
437
+	 * gmt date field name
438
+	 *
439
+	 * @param string $field_name
440
+	 * @return boolean
441
+	 */
442
+	public static function isGmtDateFieldName($field_name)
443
+	{
444
+		$field_name = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($field_name);
445
+		return substr($field_name, -4, 4) === '_gmt';
446
+	}
447
+
448
+
449
+	/**
450
+	 * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone)
451
+	 *
452
+	 * @param string $field_name
453
+	 * @return string
454
+	 */
455
+	public static function removeGmtFromFieldName($field_name)
456
+	{
457
+		if (! ModelDataTranslator::isGmtDateFieldName($field_name)) {
458
+			return $field_name;
459
+		}
460
+		$query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey(
461
+			$field_name
462
+		);
463
+		$query_param_sans_gmt_and_sans_stars = substr(
464
+			$query_param_sans_stars,
465
+			0,
466
+			strrpos(
467
+				$field_name,
468
+				'_gmt'
469
+			)
470
+		);
471
+		return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name);
472
+	}
473
+
474
+
475
+	/**
476
+	 * Takes a field name from the REST API and prepares it for the model querying
477
+	 *
478
+	 * @param string $field_name
479
+	 * @return string
480
+	 */
481
+	public static function prepareFieldNameFromJson($field_name)
482
+	{
483
+		if (ModelDataTranslator::isGmtDateFieldName($field_name)) {
484
+			return ModelDataTranslator::removeGmtFromFieldName($field_name);
485
+		}
486
+		return $field_name;
487
+	}
488
+
489
+
490
+	/**
491
+	 * Takes array of field names from REST API and prepares for models
492
+	 *
493
+	 * @param array $field_names
494
+	 * @return array of field names (possibly include model prefixes)
495
+	 */
496
+	public static function prepareFieldNamesFromJson(array $field_names)
497
+	{
498
+		$new_array = [];
499
+		foreach ($field_names as $key => $field_name) {
500
+			$new_array[ $key ] = ModelDataTranslator::prepareFieldNameFromJson($field_name);
501
+		}
502
+		return $new_array;
503
+	}
504
+
505
+
506
+	/**
507
+	 * Takes array where array keys are field names (possibly with model path prefixes)
508
+	 * from the REST API and prepares them for model querying
509
+	 *
510
+	 * @param array $field_names_as_keys
511
+	 * @return array
512
+	 */
513
+	public static function prepareFieldNamesInArrayKeysFromJson(array $field_names_as_keys)
514
+	{
515
+		$new_array = [];
516
+		foreach ($field_names_as_keys as $field_name => $value) {
517
+			$new_array[ ModelDataTranslator::prepareFieldNameFromJson($field_name) ] = $value;
518
+		}
519
+		return $new_array;
520
+	}
521
+
522
+
523
+	/**
524
+	 * Prepares an array of model query params for use in the REST API
525
+	 *
526
+	 * @param array    $model_query_params
527
+	 * @param EEM_Base $model
528
+	 * @param string   $requested_version  eg "4.8.36". If null is provided, defaults to the latest release of the EE4
529
+	 *                                     REST API
530
+	 * @return array which can be passed into the EE4 REST API when querying a model resource
531
+	 * @throws EE_Error
532
+	 * @throws ReflectionException
533
+	 */
534
+	public static function prepareQueryParamsForRestApi(
535
+		array $model_query_params,
536
+		EEM_Base $model,
537
+		$requested_version = null
538
+	) {
539
+		if ($requested_version === null) {
540
+			$requested_version = EED_Core_Rest_Api::latest_rest_api_version();
541
+		}
542
+		$rest_query_params = $model_query_params;
543
+		if (isset($model_query_params[0])) {
544
+			$rest_query_params['where'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
545
+				$model_query_params[0],
546
+				$model,
547
+				$requested_version
548
+			);
549
+			unset($rest_query_params[0]);
550
+		}
551
+		if (isset($model_query_params['having'])) {
552
+			$rest_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
553
+				$model_query_params['having'],
554
+				$model,
555
+				$requested_version
556
+			);
557
+		}
558
+		return apply_filters(
559
+			'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api',
560
+			$rest_query_params,
561
+			$model_query_params,
562
+			$model,
563
+			$requested_version
564
+		);
565
+	}
566
+
567
+
568
+	/**
569
+	 * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api
570
+	 *
571
+	 * @param array    $inputted_query_params_of_this_type  eg like the "where" or "having" conditions query params
572
+	 * @param EEM_Base $model
573
+	 * @param string   $requested_version                   eg "4.8.36"
574
+	 * @return array ready for use in the rest api query params
575
+	 * @throws EE_Error
576
+	 * @throws RestException if somehow a PHP object were in the query params' values,*@throws
577
+	 * @throws ReflectionException
578
+	 *                                                      ReflectionException
579
+	 *                                                      (which would be really unusual)
580
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
581
+	 */
582
+	public static function prepareConditionsQueryParamsForRestApi(
583
+		$inputted_query_params_of_this_type,
584
+		EEM_Base $model,
585
+		$requested_version
586
+	) {
587
+		$query_param_for_models = [];
588
+		foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
589
+			$field = ModelDataTranslator::deduceFieldFromQueryParam(
590
+				ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($query_param_key),
591
+				$model
592
+			);
593
+			if ($field instanceof EE_Model_Field_Base) {
594
+				// did they specify an operator?
595
+				if (is_array($query_param_value)) {
596
+					$op               = $query_param_value[0];
597
+					$translated_value = [$op];
598
+					if (isset($query_param_value[1])) {
599
+						$value               = $query_param_value[1];
600
+						$translated_value[1] = ModelDataTranslator::prepareFieldValuesForJson(
601
+							$field,
602
+							$value,
603
+							$requested_version
604
+						);
605
+					}
606
+				} else {
607
+					$translated_value = ModelDataTranslator::prepareFieldValueForJson(
608
+						$field,
609
+						$query_param_value,
610
+						$requested_version
611
+					);
612
+				}
613
+				$query_param_for_models[ $query_param_key ] = $translated_value;
614
+			} else {
615
+				// so it's not for a field, assume it's a logic query param key
616
+				$query_param_for_models[ $query_param_key ] =
617
+					ModelDataTranslator::prepareConditionsQueryParamsForRestApi(
618
+						$query_param_value,
619
+						$model,
620
+						$requested_version
621
+					);
622
+			}
623
+		}
624
+		return $query_param_for_models;
625
+	}
626
+
627
+
628
+	/**
629
+	 * @param $condition_query_param_key
630
+	 * @return string
631
+	 */
632
+	public static function removeStarsAndAnythingAfterFromConditionQueryParamKey($condition_query_param_key)
633
+	{
634
+		$pos_of_star = strpos($condition_query_param_key, '*');
635
+		if ($pos_of_star === false) {
636
+			return $condition_query_param_key;
637
+		}
638
+		return substr($condition_query_param_key, 0, $pos_of_star);
639
+	}
640
+
641
+
642
+	/**
643
+	 * Takes the input parameter and finds the model field that it indicates.
644
+	 *
645
+	 * @param string   $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID
646
+	 * @param EEM_Base $model
647
+	 * @return EE_Model_Field_Base
648
+	 * @throws EE_Error
649
+	 * @throws ReflectionException
650
+	 */
651
+	public static function deduceFieldFromQueryParam($query_param_name, EEM_Base $model)
652
+	{
653
+		// ok, now proceed with deducing which part is the model's name, and which is the field's name
654
+		// which will help us find the database table and column
655
+		$query_param_parts = explode('.', $query_param_name);
656
+		if (empty($query_param_parts)) {
657
+			throw new EE_Error(
658
+				sprintf(
659
+					esc_html__(
660
+						'_extract_column_name is empty when trying to extract column and table name from %s',
661
+						'event_espresso'
662
+					),
663
+					$query_param_name
664
+				)
665
+			);
666
+		}
667
+		$number_of_parts       = count($query_param_parts);
668
+		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
669
+		$field_name            = $last_query_param_part;
670
+		if ($number_of_parts !== 1) {
671
+			// the last part is the column name, and there are only 2parts. therefore...
672
+			$model = EE_Registry::instance()->load_model($query_param_parts[ $number_of_parts - 2 ]);
673
+		}
674
+		try {
675
+			return $model->field_settings_for($field_name, false);
676
+		} catch (EE_Error $e) {
677
+			return null;
678
+		}
679
+	}
680
+
681
+
682
+	/**
683
+	 * Returns true if $data can be easily represented in JSON.
684
+	 * Basically, objects and resources can't be represented in JSON easily.
685
+	 *
686
+	 * @param mixed $data
687
+	 * @return bool
688
+	 */
689
+	protected static function isRepresentableInJson($data)
690
+	{
691
+		return is_scalar($data)
692
+			   || is_array($data)
693
+			   || is_null($data);
694
+	}
695 695
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Attendee_Shortcodes.lib.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             ? null
115 115
             : $this->_data;
116 116
 
117
-        if (! $registration instanceof EE_Registration) {
117
+        if ( ! $registration instanceof EE_Registration) {
118 118
             // let's attempt to get the txn_id for the error message.
119 119
             $txn_id  = isset($this->_extra->txn) && $this->_extra->txn instanceof EE_Transaction
120 120
                 ? $this->_extra->txn->ID()
@@ -131,12 +131,12 @@  discard block
 block discarded – undo
131 131
         }
132 132
 
133 133
         // attendee obj for this registration
134
-        $attendee = isset($this->_extra->registrations[ $registration->ID() ]['att_obj'])
135
-            ? $this->_extra->registrations[ $registration->ID() ]['att_obj']
134
+        $attendee = isset($this->_extra->registrations[$registration->ID()]['att_obj'])
135
+            ? $this->_extra->registrations[$registration->ID()]['att_obj']
136 136
             : null;
137 137
 
138
-        if (! $attendee instanceof EE_Attendee) {
139
-            $msg     = esc_html__(
138
+        if ( ! $attendee instanceof EE_Attendee) {
139
+            $msg = esc_html__(
140 140
                 'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.',
141 141
                 'event_espresso'
142 142
             );
Please login to merge, or discard this patch.
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -15,192 +15,192 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Attendee_Shortcodes extends EE_Shortcodes
17 17
 {
18
-    /**
19
-     * hold all extra data.
20
-     *
21
-     * @var array
22
-     */
23
-    protected $_extra;
24
-
25
-
26
-    /**
27
-     * EE_Attendee_Shortcodes constructor.
28
-     */
29
-    public function __construct()
30
-    {
31
-        parent::__construct();
32
-    }
33
-
34
-
35
-    protected function _init_props()
36
-    {
37
-        $this->label       = esc_html__('Attendee Shortcodes', 'event_espresso');
38
-        $this->description = esc_html__('All shortcodes specific to attendee related data', 'event_espresso');
39
-        $this->_shortcodes = [
40
-            '[FNAME]'                          => esc_html__('First Name of an attendee.', 'event_espresso'),
41
-            '[LNAME]'                          => esc_html__('Last Name of an attendee.', 'event_espresso'),
42
-            '[ATTENDEE_EMAIL]'                 => esc_html__('Email address for the attendee.', 'event_espresso'),
43
-            '[EDIT_ATTENDEE_LINK]'             => esc_html__(
44
-                'Edit Registration Link (typically you\'d only use this for messages going to event administrators)',
45
-                'event_espresso'
46
-            ),
47
-            '[REGISTRATION_ID]'                => esc_html__(
48
-                'Unique Registration ID for the registration',
49
-                'event_espresso'
50
-            ),
51
-            '[REGISTRATION_CODE]'              => esc_html__(
52
-                'Unique Registration Code for the registration',
53
-                'event_espresso'
54
-            ),
55
-            '[REGISTRATION_STATUS_ID]'         => esc_html__(
56
-                'Parses to the registration status for the attendee',
57
-                'event_espresso'
58
-            ),
59
-            '[REGISTRATION_STATUS_LABEL]'      => esc_html__(
60
-                'Parses to the status label for the registrant',
61
-                'event_espresso'
62
-            ),
63
-            '[REGISTRATION_TOTAL_AMOUNT_PAID]' => esc_html__(
64
-                'Parses to the total amount paid for this registration.',
65
-                'event_espresso'
66
-            ),
67
-            '[FRONTEND_EDIT_REG_LINK]'         => esc_html__(
68
-                'Generates a link for the given registration to edit this registration details on the frontend.',
69
-                'event_espresso'
70
-            ),
71
-            '[PHONE_NUMBER]'                   => esc_html__(
72
-                'The Phone Number for the Registration.',
73
-                'event_espresso'
74
-            ),
75
-            '[ADDRESS]'                        => esc_html__('The Address for the Registration', 'event_espresso'),
76
-            '[ADDRESS2]'                       => esc_html__(
77
-                'Whatever was in the address 2 field for the registration.',
78
-                'event_espresso'
79
-            ),
80
-            '[CITY]'                           => esc_html__('The city for the registration.', 'event_espresso'),
81
-            '[ZIP_PC]'                         => esc_html__(
82
-                'The ZIP (or Postal) Code for the Registration.',
83
-                'event_espresso'
84
-            ),
85
-            '[ADDRESS_STATE]'                  => esc_html__(
86
-                'The state/province for the registration.',
87
-                'event_espresso'
88
-            ),
89
-            '[COUNTRY]'                        => esc_html__('The country for the registration.', 'event_espresso'),
90
-        ];
91
-    }
92
-
93
-
94
-    /**
95
-     * handles shortcode parsing
96
-     *
97
-     * @access protected
98
-     * @param string $shortcode the shortcode to be parsed.
99
-     * @return string
100
-     * @throws EE_Error
101
-     * @throws ReflectionException
102
-     */
103
-    protected function _parser($shortcode)
104
-    {
105
-
106
-
107
-        $this->_extra = ! empty($this->_extra_data) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
108
-            ? $this->_extra_data['data']
109
-            : null;
110
-
111
-        // incoming object should only be a registration object.
112
-        $registration = ! $this->_data instanceof EE_Registration
113
-            ? null
114
-            : $this->_data;
115
-
116
-        if (! $registration instanceof EE_Registration) {
117
-            // let's attempt to get the txn_id for the error message.
118
-            $txn_id  = isset($this->_extra->txn) && $this->_extra->txn instanceof EE_Transaction
119
-                ? $this->_extra->txn->ID()
120
-                : esc_html__('Unknown', 'event_espresso');
121
-            $msg     = esc_html__(
122
-                'There is no EE_Registration object in the data sent to the EE_Attendee Shortcode Parser for the messages system.',
123
-                'event_espresso'
124
-            );
125
-            $dev_msg = sprintf(
126
-                esc_html__('The transaction ID for this request is: %s', 'event_espresso'),
127
-                $txn_id
128
-            );
129
-            throw new EE_Error("{$msg}||{$msg} {$dev_msg}");
130
-        }
131
-
132
-        // attendee obj for this registration
133
-        $attendee = isset($this->_extra->registrations[ $registration->ID() ]['att_obj'])
134
-            ? $this->_extra->registrations[ $registration->ID() ]['att_obj']
135
-            : null;
136
-
137
-        if (! $attendee instanceof EE_Attendee) {
138
-            $msg     = esc_html__(
139
-                'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.',
140
-                'event_espresso'
141
-            );
142
-            $dev_msg = sprintf(
143
-                esc_html__('The registration ID for this request is: %s', 'event_espresso'),
144
-                $registration->ID()
145
-            );
146
-            throw new EE_Error("{$msg}||{$msg} {$dev_msg}");
147
-        }
148
-
149
-        switch ($shortcode) {
150
-            case '[FNAME]':
151
-                return $attendee->fname();
152
-
153
-            case '[LNAME]':
154
-                return $attendee->lname();
155
-
156
-            case '[ATTENDEE_EMAIL]':
157
-                return $attendee->email();
158
-
159
-            case '[EDIT_ATTENDEE_LINK]':
160
-                return $registration->get_admin_edit_url();
161
-
162
-            case '[REGISTRATION_CODE]':
163
-                return $registration->reg_code();
164
-
165
-            case '[REGISTRATION_ID]':
166
-                return $registration->ID();
167
-
168
-            case '[FRONTEND_EDIT_REG_LINK]':
169
-                return $registration->edit_attendee_information_url();
170
-
171
-            case '[PHONE_NUMBER]':
172
-                return $attendee->phone();
173
-
174
-            case '[ADDRESS]':
175
-                return $attendee->address();
176
-
177
-            case '[ADDRESS2]':
178
-                return $attendee->address2();
179
-
180
-            case '[CITY]':
181
-                return $attendee->city();
182
-
183
-            case '[ZIP_PC]':
184
-                return $attendee->zip();
185
-
186
-            case '[ADDRESS_STATE]':
187
-                $state_obj = $attendee->state_obj();
188
-                return $state_obj instanceof EE_State ? $state_obj->name() : '';
189
-
190
-            case '[COUNTRY]':
191
-                $country_obj = $attendee->country_obj();
192
-                return $country_obj instanceof EE_Country ? $country_obj->name() : '';
193
-
194
-            case '[REGISTRATION_STATUS_ID]':
195
-                return $registration->status_ID();
196
-
197
-            case '[REGISTRATION_STATUS_LABEL]':
198
-                return $registration->pretty_status();
199
-
200
-            case '[REGISTRATION_TOTAL_AMOUNT_PAID]':
201
-                return $registration->pretty_paid();
202
-        }
203
-
204
-        return '';
205
-    }
18
+	/**
19
+	 * hold all extra data.
20
+	 *
21
+	 * @var array
22
+	 */
23
+	protected $_extra;
24
+
25
+
26
+	/**
27
+	 * EE_Attendee_Shortcodes constructor.
28
+	 */
29
+	public function __construct()
30
+	{
31
+		parent::__construct();
32
+	}
33
+
34
+
35
+	protected function _init_props()
36
+	{
37
+		$this->label       = esc_html__('Attendee Shortcodes', 'event_espresso');
38
+		$this->description = esc_html__('All shortcodes specific to attendee related data', 'event_espresso');
39
+		$this->_shortcodes = [
40
+			'[FNAME]'                          => esc_html__('First Name of an attendee.', 'event_espresso'),
41
+			'[LNAME]'                          => esc_html__('Last Name of an attendee.', 'event_espresso'),
42
+			'[ATTENDEE_EMAIL]'                 => esc_html__('Email address for the attendee.', 'event_espresso'),
43
+			'[EDIT_ATTENDEE_LINK]'             => esc_html__(
44
+				'Edit Registration Link (typically you\'d only use this for messages going to event administrators)',
45
+				'event_espresso'
46
+			),
47
+			'[REGISTRATION_ID]'                => esc_html__(
48
+				'Unique Registration ID for the registration',
49
+				'event_espresso'
50
+			),
51
+			'[REGISTRATION_CODE]'              => esc_html__(
52
+				'Unique Registration Code for the registration',
53
+				'event_espresso'
54
+			),
55
+			'[REGISTRATION_STATUS_ID]'         => esc_html__(
56
+				'Parses to the registration status for the attendee',
57
+				'event_espresso'
58
+			),
59
+			'[REGISTRATION_STATUS_LABEL]'      => esc_html__(
60
+				'Parses to the status label for the registrant',
61
+				'event_espresso'
62
+			),
63
+			'[REGISTRATION_TOTAL_AMOUNT_PAID]' => esc_html__(
64
+				'Parses to the total amount paid for this registration.',
65
+				'event_espresso'
66
+			),
67
+			'[FRONTEND_EDIT_REG_LINK]'         => esc_html__(
68
+				'Generates a link for the given registration to edit this registration details on the frontend.',
69
+				'event_espresso'
70
+			),
71
+			'[PHONE_NUMBER]'                   => esc_html__(
72
+				'The Phone Number for the Registration.',
73
+				'event_espresso'
74
+			),
75
+			'[ADDRESS]'                        => esc_html__('The Address for the Registration', 'event_espresso'),
76
+			'[ADDRESS2]'                       => esc_html__(
77
+				'Whatever was in the address 2 field for the registration.',
78
+				'event_espresso'
79
+			),
80
+			'[CITY]'                           => esc_html__('The city for the registration.', 'event_espresso'),
81
+			'[ZIP_PC]'                         => esc_html__(
82
+				'The ZIP (or Postal) Code for the Registration.',
83
+				'event_espresso'
84
+			),
85
+			'[ADDRESS_STATE]'                  => esc_html__(
86
+				'The state/province for the registration.',
87
+				'event_espresso'
88
+			),
89
+			'[COUNTRY]'                        => esc_html__('The country for the registration.', 'event_espresso'),
90
+		];
91
+	}
92
+
93
+
94
+	/**
95
+	 * handles shortcode parsing
96
+	 *
97
+	 * @access protected
98
+	 * @param string $shortcode the shortcode to be parsed.
99
+	 * @return string
100
+	 * @throws EE_Error
101
+	 * @throws ReflectionException
102
+	 */
103
+	protected function _parser($shortcode)
104
+	{
105
+
106
+
107
+		$this->_extra = ! empty($this->_extra_data) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
108
+			? $this->_extra_data['data']
109
+			: null;
110
+
111
+		// incoming object should only be a registration object.
112
+		$registration = ! $this->_data instanceof EE_Registration
113
+			? null
114
+			: $this->_data;
115
+
116
+		if (! $registration instanceof EE_Registration) {
117
+			// let's attempt to get the txn_id for the error message.
118
+			$txn_id  = isset($this->_extra->txn) && $this->_extra->txn instanceof EE_Transaction
119
+				? $this->_extra->txn->ID()
120
+				: esc_html__('Unknown', 'event_espresso');
121
+			$msg     = esc_html__(
122
+				'There is no EE_Registration object in the data sent to the EE_Attendee Shortcode Parser for the messages system.',
123
+				'event_espresso'
124
+			);
125
+			$dev_msg = sprintf(
126
+				esc_html__('The transaction ID for this request is: %s', 'event_espresso'),
127
+				$txn_id
128
+			);
129
+			throw new EE_Error("{$msg}||{$msg} {$dev_msg}");
130
+		}
131
+
132
+		// attendee obj for this registration
133
+		$attendee = isset($this->_extra->registrations[ $registration->ID() ]['att_obj'])
134
+			? $this->_extra->registrations[ $registration->ID() ]['att_obj']
135
+			: null;
136
+
137
+		if (! $attendee instanceof EE_Attendee) {
138
+			$msg     = esc_html__(
139
+				'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.',
140
+				'event_espresso'
141
+			);
142
+			$dev_msg = sprintf(
143
+				esc_html__('The registration ID for this request is: %s', 'event_espresso'),
144
+				$registration->ID()
145
+			);
146
+			throw new EE_Error("{$msg}||{$msg} {$dev_msg}");
147
+		}
148
+
149
+		switch ($shortcode) {
150
+			case '[FNAME]':
151
+				return $attendee->fname();
152
+
153
+			case '[LNAME]':
154
+				return $attendee->lname();
155
+
156
+			case '[ATTENDEE_EMAIL]':
157
+				return $attendee->email();
158
+
159
+			case '[EDIT_ATTENDEE_LINK]':
160
+				return $registration->get_admin_edit_url();
161
+
162
+			case '[REGISTRATION_CODE]':
163
+				return $registration->reg_code();
164
+
165
+			case '[REGISTRATION_ID]':
166
+				return $registration->ID();
167
+
168
+			case '[FRONTEND_EDIT_REG_LINK]':
169
+				return $registration->edit_attendee_information_url();
170
+
171
+			case '[PHONE_NUMBER]':
172
+				return $attendee->phone();
173
+
174
+			case '[ADDRESS]':
175
+				return $attendee->address();
176
+
177
+			case '[ADDRESS2]':
178
+				return $attendee->address2();
179
+
180
+			case '[CITY]':
181
+				return $attendee->city();
182
+
183
+			case '[ZIP_PC]':
184
+				return $attendee->zip();
185
+
186
+			case '[ADDRESS_STATE]':
187
+				$state_obj = $attendee->state_obj();
188
+				return $state_obj instanceof EE_State ? $state_obj->name() : '';
189
+
190
+			case '[COUNTRY]':
191
+				$country_obj = $attendee->country_obj();
192
+				return $country_obj instanceof EE_Country ? $country_obj->name() : '';
193
+
194
+			case '[REGISTRATION_STATUS_ID]':
195
+				return $registration->status_ID();
196
+
197
+			case '[REGISTRATION_STATUS_LABEL]':
198
+				return $registration->pretty_status();
199
+
200
+			case '[REGISTRATION_TOTAL_AMOUNT_PAID]':
201
+				return $registration->pretty_paid();
202
+		}
203
+
204
+		return '';
205
+	}
206 206
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Attendee_List_Shortcodes.lib.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
         $att_result    = '';
160 160
         $registrations =
161 161
             isset($this->_extra_data['data']->tickets)
162
-                ? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs']
162
+                ? $this->_extra_data['data']->tickets[$ticket->ID()]['reg_objs']
163 163
                 : [];
164 164
 
165 165
         // each attendee in this case should be an attendee object.
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
     private function _get_registrations_from_event(EE_Event $event)
186 186
     {
187 187
         return isset($this->_extra_data['data']->events)
188
-            ? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs']
188
+            ? $this->_extra_data['data']->events[$event->ID()]['reg_objs']
189 189
             : [];
190 190
     }
191 191
 }
Please login to merge, or discard this patch.
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -18,167 +18,167 @@
 block discarded – undo
18 18
  */
19 19
 class EE_Attendee_List_Shortcodes extends EE_Shortcodes
20 20
 {
21
-    protected function _init_props()
22
-    {
23
-        $this->label       = esc_html__('Attendee List Shortcodes', 'event_espresso');
24
-        $this->description = esc_html__('All shortcodes specific to attendee lists', 'event_espresso');
25
-        $this->_shortcodes = [
26
-            '[ATTENDEE_LIST]' => esc_html__('Will output a list of attendees', 'event_espresso'),
27
-        ];
28
-    }
29
-
30
-
31
-    /**
32
-     * @param string $shortcode
33
-     * @return string
34
-     * @throws EE_Error
35
-     * @throws ReflectionException
36
-     */
37
-    protected function _parser($shortcode)
38
-    {
39
-        switch ($shortcode) {
40
-            case '[ATTENDEE_LIST]':
41
-                return $this->_get_attendee_list();
42
-        }
43
-        return '';
44
-    }
45
-
46
-
47
-    /**
48
-     * figure out what the incoming data is and then return the appropriate parsed value.
49
-     *
50
-     * @return string
51
-     * @throws EE_Error
52
-     * @throws ReflectionException
53
-     */
54
-    private function _get_attendee_list()
55
-    {
56
-        $this->_validate_list_requirements();
57
-
58
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
59
-            return $this->_get_attendee_list_for_main();
60
-        }
61
-        if ($this->_data['data'] instanceof EE_Event) {
62
-            return $this->_get_attendee_list_for_event();
63
-        }
64
-        if ($this->_data['data'] instanceof EE_Ticket) {
65
-            return $this->_get_registration_list_for_ticket();
66
-        }
67
-        // prevent recursive loop
68
-        return '';
69
-    }
70
-
71
-
72
-    /**
73
-     * This returns the parsed attendee list for main template;
74
-     */
75
-    private function _get_attendee_list_for_main()
76
-    {
77
-        $valid_shortcodes = ['attendee', 'event_list', 'ticket_list', 'question_list', 'recipient_details'];
78
-        $template         = $this->_data['template'];
79
-        $data             = $this->_data['data'];
80
-        $attendees        = '';
81
-
82
-
83
-        // now we need to loop through the attendee list and send data to the EE_Parser helper.
84
-        foreach ($data->reg_objs as $registration) {
85
-            $attendees .= $this->_shortcode_helper->parse_attendee_list_template(
86
-                $template,
87
-                $registration,
88
-                $valid_shortcodes,
89
-                $this->_extra_data
90
-            );
91
-        }
92
-
93
-        return $attendees;
94
-    }
95
-
96
-
97
-    /**
98
-     * return parsed list of attendees for an event
99
-     *
100
-     * @return string
101
-     * @throws EE_Error
102
-     * @throws ReflectionException
103
-     */
104
-    private function _get_attendee_list_for_event()
105
-    {
106
-        $valid_shortcodes = ['attendee', 'ticket_list', 'question_list', 'recipient_details'];
107
-        $template         = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list'])
108
-            ? $this->_data['template']['attendee_list']
109
-            : $this->_extra_data['template']['attendee_list'];
110
-        $event            = $this->_data['data'];
111
-
112
-        // let's remove any existing [EVENT_LIST] shortcode from the attendee list template so that we don't get recursion.
113
-        $template = str_replace('[EVENT_LIST]', '', $template);
114
-
115
-        // here we're setting up the attendees for the attendee_list template for THIS event.
116
-        $att_result    = '';
117
-        $registrations = $this->_get_registrations_from_event($event);
118
-
119
-        // each attendee in this case should be an attendee object.
120
-        foreach ($registrations as $registration) {
121
-            $att_result .= $this->_shortcode_helper->parse_attendee_list_template(
122
-                $template,
123
-                $registration,
124
-                $valid_shortcodes,
125
-                $this->_extra_data
126
-            );
127
-        }
128
-
129
-        return $att_result;
130
-    }
131
-
132
-
133
-    /**
134
-     * return parsed list of attendees for a ticket
135
-     *
136
-     * @return string
137
-     */
138
-    private function _get_registration_list_for_ticket()
139
-    {
140
-        $valid_shortcodes = ['attendee', 'event_list', 'question_list', 'recipient_details'];
141
-        $template         = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list'])
142
-            ? $this->_data['template']['attendee_list']
143
-            : $this->_extra_data['template']['attendee_list'];
144
-        $ticket           = $this->_data['data'];
145
-
146
-        // let's remove any existing [TICKET_LIST] (or related) shortcode from the attendee list template so that we don't get recursion.
147
-        $template = str_replace('[TICKET_LIST]', '', $template);
148
-        $template = str_replace('[RECIPIENT_TICKET_LIST]', '', $template);
149
-        $template = str_replace('[PRIMARY_REGISTRANT_TICKET_LIST]', '', $template);
150
-
151
-        // here we're setting up the attendees for the attendee_list template for THIS ticket.
152
-        $att_result    = '';
153
-        $registrations =
154
-            isset($this->_extra_data['data']->tickets)
155
-                ? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs']
156
-                : [];
157
-
158
-        // each attendee in this case should be an attendee object.
159
-        foreach ($registrations as $registration) {
160
-            $att_result .= $this->_shortcode_helper->parse_attendee_list_template(
161
-                $template,
162
-                $registration,
163
-                $valid_shortcodes,
164
-                $this->_extra_data
165
-            );
166
-        }
167
-
168
-        return $att_result;
169
-    }
170
-
171
-
172
-    /**
173
-     * @param EE_Event $event
174
-     * @return array|mixed
175
-     * @throws EE_Error
176
-     * @throws ReflectionException
177
-     */
178
-    private function _get_registrations_from_event(EE_Event $event)
179
-    {
180
-        return isset($this->_extra_data['data']->events)
181
-            ? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs']
182
-            : [];
183
-    }
21
+	protected function _init_props()
22
+	{
23
+		$this->label       = esc_html__('Attendee List Shortcodes', 'event_espresso');
24
+		$this->description = esc_html__('All shortcodes specific to attendee lists', 'event_espresso');
25
+		$this->_shortcodes = [
26
+			'[ATTENDEE_LIST]' => esc_html__('Will output a list of attendees', 'event_espresso'),
27
+		];
28
+	}
29
+
30
+
31
+	/**
32
+	 * @param string $shortcode
33
+	 * @return string
34
+	 * @throws EE_Error
35
+	 * @throws ReflectionException
36
+	 */
37
+	protected function _parser($shortcode)
38
+	{
39
+		switch ($shortcode) {
40
+			case '[ATTENDEE_LIST]':
41
+				return $this->_get_attendee_list();
42
+		}
43
+		return '';
44
+	}
45
+
46
+
47
+	/**
48
+	 * figure out what the incoming data is and then return the appropriate parsed value.
49
+	 *
50
+	 * @return string
51
+	 * @throws EE_Error
52
+	 * @throws ReflectionException
53
+	 */
54
+	private function _get_attendee_list()
55
+	{
56
+		$this->_validate_list_requirements();
57
+
58
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
59
+			return $this->_get_attendee_list_for_main();
60
+		}
61
+		if ($this->_data['data'] instanceof EE_Event) {
62
+			return $this->_get_attendee_list_for_event();
63
+		}
64
+		if ($this->_data['data'] instanceof EE_Ticket) {
65
+			return $this->_get_registration_list_for_ticket();
66
+		}
67
+		// prevent recursive loop
68
+		return '';
69
+	}
70
+
71
+
72
+	/**
73
+	 * This returns the parsed attendee list for main template;
74
+	 */
75
+	private function _get_attendee_list_for_main()
76
+	{
77
+		$valid_shortcodes = ['attendee', 'event_list', 'ticket_list', 'question_list', 'recipient_details'];
78
+		$template         = $this->_data['template'];
79
+		$data             = $this->_data['data'];
80
+		$attendees        = '';
81
+
82
+
83
+		// now we need to loop through the attendee list and send data to the EE_Parser helper.
84
+		foreach ($data->reg_objs as $registration) {
85
+			$attendees .= $this->_shortcode_helper->parse_attendee_list_template(
86
+				$template,
87
+				$registration,
88
+				$valid_shortcodes,
89
+				$this->_extra_data
90
+			);
91
+		}
92
+
93
+		return $attendees;
94
+	}
95
+
96
+
97
+	/**
98
+	 * return parsed list of attendees for an event
99
+	 *
100
+	 * @return string
101
+	 * @throws EE_Error
102
+	 * @throws ReflectionException
103
+	 */
104
+	private function _get_attendee_list_for_event()
105
+	{
106
+		$valid_shortcodes = ['attendee', 'ticket_list', 'question_list', 'recipient_details'];
107
+		$template         = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list'])
108
+			? $this->_data['template']['attendee_list']
109
+			: $this->_extra_data['template']['attendee_list'];
110
+		$event            = $this->_data['data'];
111
+
112
+		// let's remove any existing [EVENT_LIST] shortcode from the attendee list template so that we don't get recursion.
113
+		$template = str_replace('[EVENT_LIST]', '', $template);
114
+
115
+		// here we're setting up the attendees for the attendee_list template for THIS event.
116
+		$att_result    = '';
117
+		$registrations = $this->_get_registrations_from_event($event);
118
+
119
+		// each attendee in this case should be an attendee object.
120
+		foreach ($registrations as $registration) {
121
+			$att_result .= $this->_shortcode_helper->parse_attendee_list_template(
122
+				$template,
123
+				$registration,
124
+				$valid_shortcodes,
125
+				$this->_extra_data
126
+			);
127
+		}
128
+
129
+		return $att_result;
130
+	}
131
+
132
+
133
+	/**
134
+	 * return parsed list of attendees for a ticket
135
+	 *
136
+	 * @return string
137
+	 */
138
+	private function _get_registration_list_for_ticket()
139
+	{
140
+		$valid_shortcodes = ['attendee', 'event_list', 'question_list', 'recipient_details'];
141
+		$template         = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list'])
142
+			? $this->_data['template']['attendee_list']
143
+			: $this->_extra_data['template']['attendee_list'];
144
+		$ticket           = $this->_data['data'];
145
+
146
+		// let's remove any existing [TICKET_LIST] (or related) shortcode from the attendee list template so that we don't get recursion.
147
+		$template = str_replace('[TICKET_LIST]', '', $template);
148
+		$template = str_replace('[RECIPIENT_TICKET_LIST]', '', $template);
149
+		$template = str_replace('[PRIMARY_REGISTRANT_TICKET_LIST]', '', $template);
150
+
151
+		// here we're setting up the attendees for the attendee_list template for THIS ticket.
152
+		$att_result    = '';
153
+		$registrations =
154
+			isset($this->_extra_data['data']->tickets)
155
+				? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs']
156
+				: [];
157
+
158
+		// each attendee in this case should be an attendee object.
159
+		foreach ($registrations as $registration) {
160
+			$att_result .= $this->_shortcode_helper->parse_attendee_list_template(
161
+				$template,
162
+				$registration,
163
+				$valid_shortcodes,
164
+				$this->_extra_data
165
+			);
166
+		}
167
+
168
+		return $att_result;
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param EE_Event $event
174
+	 * @return array|mixed
175
+	 * @throws EE_Error
176
+	 * @throws ReflectionException
177
+	 */
178
+	private function _get_registrations_from_event(EE_Event $event)
179
+	{
180
+		return isset($this->_extra_data['data']->events)
181
+			? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs']
182
+			: [];
183
+	}
184 184
 }
Please login to merge, or discard this patch.
core/domain/services/admin/privacy/policy/privacy_policy.template.php 2 patches
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -7,10 +7,10 @@  discard block
 block discarded – undo
7 7
 ?>
8 8
 <h2><?php esc_html_e('Event Registration Data', 'event_espresso'); ?></h2>
9 9
 <p><?php
10
-    esc_html_e(
11
-        'We collect information about you during event registration. This information may include but is not limited to:',
12
-        'event_espresso'
13
-    ); ?></p>
10
+	esc_html_e(
11
+		'We collect information about you during event registration. This information may include but is not limited to:',
12
+		'event_espresso'
13
+	); ?></p>
14 14
 <ul>
15 15
     <li><?php esc_html_e('Your names', 'event_espresso'); ?></li>
16 16
     <li><?php esc_html_e('Billing address', 'event_espresso'); ?></li>
@@ -18,16 +18,16 @@  discard block
 block discarded – undo
18 18
     <li><?php esc_html_e('Email address', 'event_espresso'); ?></li>
19 19
     <li><?php esc_html_e('Phone number', 'event_espresso'); ?></li>
20 20
     <li><?php
21
-        esc_html_e(
22
-            'Location and traffic data (including partial IP address and browser type)',
23
-            'event_espresso'
24
-        ); ?>
21
+		esc_html_e(
22
+			'Location and traffic data (including partial IP address and browser type)',
23
+			'event_espresso'
24
+		); ?>
25 25
     </li>
26 26
     <li><?php
27
-        esc_html_e(
28
-            'Any other details that might be requested from you for the purpose of processing your registration or ticket purchase',
29
-            'event_espresso'
30
-        ); ?>
27
+		esc_html_e(
28
+			'Any other details that might be requested from you for the purpose of processing your registration or ticket purchase',
29
+			'event_espresso'
30
+		); ?>
31 31
     </li>
32 32
 </ul>
33 33
 
@@ -36,101 +36,101 @@  discard block
 block discarded – undo
36 36
     <li><?php esc_html_e('Send you important account/purchase/service information.', 'event_espresso'); ?></li>
37 37
     <li><?php esc_html_e('Respond to your queries, refund requests, or complaints.', 'event_espresso'); ?></li>
38 38
     <li><?php
39
-        esc_html_e(
40
-            'Process payments and prevent fraudulent transactions. We do this on the basis of our legitimate business interests.',
41
-            'event_espresso'
42
-        ); ?></li>
39
+		esc_html_e(
40
+			'Process payments and prevent fraudulent transactions. We do this on the basis of our legitimate business interests.',
41
+			'event_espresso'
42
+		); ?></li>
43 43
     <li><?php
44
-        esc_html_e(
45
-            'Set up and administer your account, provide technical and customer support, and to verify your identity.',
46
-            'event_espresso'
47
-        ); ?></li>
44
+		esc_html_e(
45
+			'Set up and administer your account, provide technical and customer support, and to verify your identity.',
46
+			'event_espresso'
47
+		); ?></li>
48 48
 </ul>
49 49
 
50 50
 <?php if (! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?>
51 51
     <h2><?php esc_html_e('Billing Information', 'event_espresso'); ?> </h2>
52 52
     <?php
53
-    // if onsite or offsite payment methods are active
54
-    if (! empty($active_onsite_payment_methods)) { ?>
53
+	// if onsite or offsite payment methods are active
54
+	if (! empty($active_onsite_payment_methods)) { ?>
55 55
         <p><?php
56
-            esc_html_e(
57
-                'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.',
58
-                'event_espresso'
59
-            ); ?></p>
56
+			esc_html_e(
57
+				'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.',
58
+				'event_espresso'
59
+			); ?></p>
60 60
         <p><?php
61
-            printf(
62
-                esc_html_x(
63
-                    'Please see the privacy policy of %1$s.',
64
-                    'Please see the privacy policy of PayPal Pro',
65
-                    'event_espresso'
66
-                ),
67
-                implode(
68
-                    ', ',
69
-                    array_merge(
70
-                        $active_onsite_payment_methods,
71
-                        $active_offsite_payment_methods
72
-                    )
73
-                )
74
-            ); ?></p>
61
+			printf(
62
+				esc_html_x(
63
+					'Please see the privacy policy of %1$s.',
64
+					'Please see the privacy policy of PayPal Pro',
65
+					'event_espresso'
66
+				),
67
+				implode(
68
+					', ',
69
+					array_merge(
70
+						$active_onsite_payment_methods,
71
+						$active_offsite_payment_methods
72
+					)
73
+				)
74
+			); ?></p>
75 75
         <p><?php
76
-            esc_html_e(
77
-                'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).',
78
-                'event_espresso'
79
-            ); ?></p>
76
+			esc_html_e(
77
+				'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).',
78
+				'event_espresso'
79
+			); ?></p>
80 80
     <?php } elseif (! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?>
81 81
         <p><?php
82
-            printf(
83
-                esc_html_x(
84
-                    'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of %1$s.',
85
-                    'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of PayPal Pro.',
86
-                    'event_espresso'
87
-                ),
88
-                implode(', ', $active_offsite_payment_methods)
89
-            ); ?></p>
82
+			printf(
83
+				esc_html_x(
84
+					'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of %1$s.',
85
+					'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of PayPal Pro.',
86
+					'event_espresso'
87
+				),
88
+				implode(', ', $active_offsite_payment_methods)
89
+			); ?></p>
90 90
     <?php } ?>
91 91
     <h2><?php esc_html_e('Payment Logging', 'event_espresso'); ?></h2>
92 92
     <p><?php
93
-        esc_html_e(
94
-            'Site administrators may keep a log of communications with the payment processors in order to verify payments are being processed correctly. These logs are automatically deleted after a week.',
95
-            'event_espresso'
96
-        ); ?></p>
93
+		esc_html_e(
94
+			'Site administrators may keep a log of communications with the payment processors in order to verify payments are being processed correctly. These logs are automatically deleted after a week.',
95
+			'event_espresso'
96
+		); ?></p>
97 97
 <?php } ?>
98 98
 
99 99
 <h2><?php esc_html_e('Event Registration Cookies', 'event_espresso'); ?></h2>
100 100
 <p><?php
101
-    printf(
102
-        esc_html_x(
103
-            'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts %1$s.',
104
-            'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts 2 hours.',
105
-            'event_espresso'
106
-        ),
107
-        $session_lifespan
108
-    ); ?></p>
101
+	printf(
102
+		esc_html_x(
103
+			'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts %1$s.',
104
+			'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts 2 hours.',
105
+			'event_espresso'
106
+		),
107
+		$session_lifespan
108
+	); ?></p>
109 109
 
110 110
 <h2><?php esc_html_e('Email History Data', 'event_espresso'); ?></h2>
111 111
 <p><?php
112
-    esc_html_e(
113
-        'We keep a record of the emails sent to you. This is to ensure communication is successfully sent and its information is accurate.',
114
-        'event_espresso'
115
-    ); ?></p>
112
+	esc_html_e(
113
+		'We keep a record of the emails sent to you. This is to ensure communication is successfully sent and its information is accurate.',
114
+		'event_espresso'
115
+	); ?></p>
116 116
 
117 117
 <h2><?php esc_html_e('Event Check-In Record', 'event_espresso'); ?></h2>
118 118
 <p><?php
119
-    esc_html_e(
120
-        'When you attend an event, an event manager may record the time you check in or out of the event.',
121
-        'event_espresso'
122
-    ); ?></p>
119
+	esc_html_e(
120
+		'When you attend an event, an event manager may record the time you check in or out of the event.',
121
+		'event_espresso'
122
+	); ?></p>
123 123
 
124 124
 <h2><?php esc_html_e('Event Registration Data Retention', 'event_espresso'); ?></h2>
125 125
 <p><?php
126
-    esc_html_e(
127
-        'Personal data is stored at least until the date of the event, and may be kept indefinitely in case of future registrations.',
128
-        'event_espresso'
129
-    ); ?></p>
126
+	esc_html_e(
127
+		'Personal data is stored at least until the date of the event, and may be kept indefinitely in case of future registrations.',
128
+		'event_espresso'
129
+	); ?></p>
130 130
 
131 131
 <h2><?php esc_html_e('Event Registration Data Erasure and Export', 'event_espresso'); ?></h2>
132 132
 <p><?php
133
-    esc_html_e(
134
-        'You have the right to request your personal data be sent to you electronically, and the right to request your registration data be erased after the event. To do so, please contact the event manager or site administrator.',
135
-        'event_espresso'
136
-    ); ?></p>
133
+	esc_html_e(
134
+		'You have the right to request your personal data be sent to you electronically, and the right to request your registration data be erased after the event. To do so, please contact the event manager or site administrator.',
135
+		'event_espresso'
136
+	); ?></p>
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -47,11 +47,11 @@  discard block
 block discarded – undo
47 47
         ); ?></li>
48 48
 </ul>
49 49
 
50
-<?php if (! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?>
50
+<?php if ( ! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?>
51 51
     <h2><?php esc_html_e('Billing Information', 'event_espresso'); ?> </h2>
52 52
     <?php
53 53
     // if onsite or offsite payment methods are active
54
-    if (! empty($active_onsite_payment_methods)) { ?>
54
+    if ( ! empty($active_onsite_payment_methods)) { ?>
55 55
         <p><?php
56 56
             esc_html_e(
57 57
                 'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.',
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
                 'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).',
78 78
                 'event_espresso'
79 79
             ); ?></p>
80
-    <?php } elseif (! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?>
80
+    <?php } elseif ( ! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?>
81 81
         <p><?php
82 82
             printf(
83 83
                 esc_html_x(
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/loop-espresso_events.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -11,48 +11,48 @@
 block discarded – undo
11 11
  * @version     4+
12 12
  */
13 13
 if (have_posts()) :
14
-    if (apply_filters('FHEE__archive_espresso_events_template__show_header', true)) : ?>
14
+	if (apply_filters('FHEE__archive_espresso_events_template__show_header', true)) : ?>
15 15
         <header class="page-header">
16 16
             <h1 class="page-title">
17 17
                 <?php
18
-                if (is_day()) :
19
-                    printf(esc_html__('Today\'s Events: %s', 'event_espresso'), get_the_date());
20
-                elseif (is_month()) :
21
-                    printf(
22
-                        esc_html__('Events This Month: %s', 'event_espresso'),
23
-                        get_the_date(_x('F Y', 'monthly archives date format', 'event_espresso'))
24
-                    );
25
-                elseif (is_year()) :
26
-                    printf(
27
-                        esc_html__('Events This Year: %s', 'event_espresso'),
28
-                        get_the_date(_x('Y', 'yearly archives date format', 'event_espresso'))
29
-                    );
30
-                else :
31
-                    echo apply_filters(
32
-                        'FHEE__archive_espresso_events_template__upcoming_events_h1',
33
-                        esc_html__('Upcoming Events', 'event_espresso')
34
-                    );
35
-                endif;
36
-                ?>
18
+				if (is_day()) :
19
+					printf(esc_html__('Today\'s Events: %s', 'event_espresso'), get_the_date());
20
+				elseif (is_month()) :
21
+					printf(
22
+						esc_html__('Events This Month: %s', 'event_espresso'),
23
+						get_the_date(_x('F Y', 'monthly archives date format', 'event_espresso'))
24
+					);
25
+				elseif (is_year()) :
26
+					printf(
27
+						esc_html__('Events This Year: %s', 'event_espresso'),
28
+						get_the_date(_x('Y', 'yearly archives date format', 'event_espresso'))
29
+					);
30
+				else :
31
+					echo apply_filters(
32
+						'FHEE__archive_espresso_events_template__upcoming_events_h1',
33
+						esc_html__('Upcoming Events', 'event_espresso')
34
+					);
35
+				endif;
36
+				?>
37 37
             </h1>
38 38
 
39 39
         </header><!-- .page-header -->
40 40
 
41 41
         <?php
42
-    endif;
43
-    // allow other stuff
44
-    do_action('AHEE__archive_espresso_events_template__before_loop');
45
-    // Start the Loop.
46
-    while (have_posts()) : the_post();
47
-        // Include the post TYPE-specific template for the content.
48
-        espresso_get_template_part('content', 'espresso_events-shortcode');
49
-    endwhile;
50
-    // Previous/next page navigation.
51
-    espresso_pagination();
52
-    // allow moar other stuff
53
-    do_action('AHEE__archive_espresso_events_template__after_loop');
42
+	endif;
43
+	// allow other stuff
44
+	do_action('AHEE__archive_espresso_events_template__before_loop');
45
+	// Start the Loop.
46
+	while (have_posts()) : the_post();
47
+		// Include the post TYPE-specific template for the content.
48
+		espresso_get_template_part('content', 'espresso_events-shortcode');
49
+	endwhile;
50
+	// Previous/next page navigation.
51
+	espresso_pagination();
52
+	// allow moar other stuff
53
+	do_action('AHEE__archive_espresso_events_template__after_loop');
54 54
 else :
55
-    // If no content, include the "No posts found" template.
56
-    espresso_get_template_part('content', 'none');
55
+	// If no content, include the "No posts found" template.
56
+	espresso_get_template_part('content', 'none');
57 57
 endif;
58 58
 
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,11 +27,13 @@  discard block
 block discarded – undo
27 27
                         esc_html__('Events This Year: %s', 'event_espresso'),
28 28
                         get_the_date(_x('Y', 'yearly archives date format', 'event_espresso'))
29 29
                     );
30
-                else :
30
+                else {
31
+                	:
31 32
                     echo apply_filters(
32 33
                         'FHEE__archive_espresso_events_template__upcoming_events_h1',
33 34
                         esc_html__('Upcoming Events', 'event_espresso')
34 35
                     );
36
+                }
35 37
                 endif;
36 38
                 ?>
37 39
             </h1>
@@ -51,8 +53,10 @@  discard block
 block discarded – undo
51 53
     espresso_pagination();
52 54
     // allow moar other stuff
53 55
     do_action('AHEE__archive_espresso_events_template__after_loop');
54
-else :
56
+else {
57
+	:
55 58
     // If no content, include the "No posts found" template.
56 59
     espresso_get_template_part('content', 'none');
60
+}
57 61
 endif;
58 62
 
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/functions.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,9 +9,9 @@  discard block
 block discarded – undo
9 9
  * @ link			http://www.eventespresso.com
10 10
  * @ version		4+
11 11
  */
12
-define( 'EE_THEME_FUNCTIONS_LOADED', TRUE );
12
+define('EE_THEME_FUNCTIONS_LOADED', TRUE);
13 13
 
14
-if ( ! function_exists( 'espresso_pagination' ) ) {
14
+if ( ! function_exists('espresso_pagination')) {
15 15
 	/**
16 16
 	 *    espresso_pagination
17 17
 	 *
@@ -23,21 +23,21 @@  discard block
 block discarded – undo
23 23
 		$big = 999999999; // need an unlikely integer
24 24
 		$pagination = paginate_links(
25 25
 			array(
26
-				'base'         => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
26
+				'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
27 27
 				'format'       => '?paged=%#%',
28
-				'current'      => max( 1, get_query_var( 'paged' ) ),
28
+				'current'      => max(1, get_query_var('paged')),
29 29
 				'total'        => $wp_query->max_num_pages,
30 30
 				'show_all'     => true,
31 31
 				'end_size'     => 10,
32 32
 				'mid_size'     => 6,
33 33
 				'prev_next'    => true,
34
-				'prev_text'    => esc_html__( '&lsaquo; PREV', 'event_espresso' ),
35
-				'next_text'    => esc_html__( 'NEXT &rsaquo;', 'event_espresso' ),
34
+				'prev_text'    => esc_html__('&lsaquo; PREV', 'event_espresso'),
35
+				'next_text'    => esc_html__('NEXT &rsaquo;', 'event_espresso'),
36 36
 				'type'         => 'plain',
37 37
 				'add_args'     => false,
38 38
 				'add_fragment' => ''
39 39
 			)
40 40
 		);
41
-		echo ! empty( $pagination ) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
41
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : '';
42 42
 	}
43 43
 }
44 44
\ No newline at end of file
Please login to merge, or discard this patch.
core/libraries/messages/data_class/EE_Messages_REG_incoming_data.class.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -31,14 +31,14 @@  discard block
 block discarded – undo
31 31
     {
32 32
         $filtered_reg_status = null;
33 33
 
34
-        if (! is_array($data) && $data instanceof EE_Registration) {
34
+        if ( ! is_array($data) && $data instanceof EE_Registration) {
35 35
             $this->reg_obj = $data;
36 36
         } else {
37 37
             $this->reg_obj = is_array($data) && isset($data[0]) && $data[0] instanceof EE_Registration ? $data[0] : null;
38 38
             $filtered_reg_status = is_array($data) && ! empty($data[1]) ? $data[1] : null;
39 39
         }
40 40
 
41
-        if (! $this->reg_obj instanceof EE_Registration) {
41
+        if ( ! $this->reg_obj instanceof EE_Registration) {
42 42
             throw new EE_Error(
43 43
                 sprintf(
44 44
                     esc_html__('%1$s requires the incoming data argument to be an instance of %2$s or an array where the first value is an instance of %2$s', 'event_espresso'),
@@ -66,16 +66,16 @@  discard block
 block discarded – undo
66 66
     public static function convert_data_for_persistent_storage($data)
67 67
     {
68 68
         $prepped_data = array();
69
-        if (! is_array($data) && $data instanceof EE_Registration) {
69
+        if ( ! is_array($data) && $data instanceof EE_Registration) {
70 70
             $prepped_data['Registration'] = $data->ID();
71 71
             return $prepped_data;
72
-        } elseif (! is_array($data)) {
72
+        } elseif ( ! is_array($data)) {
73 73
             return array();
74 74
         } else {
75 75
             if ($data[0] instanceof EE_Registration) {
76 76
                 $prepped_data['Registration'] = $data[0];
77 77
             }
78
-            if (! empty($data[1])) {
78
+            if ( ! empty($data[1])) {
79 79
                 $prepped_data['filter'] = $data[1];
80 80
             }
81 81
         }
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
         $this->txn = $this->reg_obj->transaction();
122 122
         // possible session stuff?
123 123
         $session = $this->txn->session_data();
124
-        $session_data =  $session instanceof EE_Session ? $session->get_session_data() : array();
124
+        $session_data = $session instanceof EE_Session ? $session->get_session_data() : array();
125 125
 
126 126
         // other data from the session (if possible)
127 127
         $this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : '';
Please login to merge, or discard this patch.
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -15,137 +15,137 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Messages_REG_incoming_data extends EE_Messages_incoming_data
17 17
 {
18
-    /**
19
-     * For the constructor of this special preview class.
20
-     *
21
-     * The data is expected to be an array that came from the request data
22
-     * and should have at least one property from the list looked for.
23
-     *
24
-     * @param EE_Registration|array $data
25
-     * @throws \EE_Error
26
-     */
27
-    public function __construct($data)
28
-    {
29
-        $filtered_reg_status = null;
30
-
31
-        if (! is_array($data) && $data instanceof EE_Registration) {
32
-            $this->reg_obj = $data;
33
-        } else {
34
-            $this->reg_obj = is_array($data) && isset($data[0]) && $data[0] instanceof EE_Registration ? $data[0] : null;
35
-            $filtered_reg_status = is_array($data) && ! empty($data[1]) ? $data[1] : null;
36
-        }
37
-
38
-        if (! $this->reg_obj instanceof EE_Registration) {
39
-            throw new EE_Error(
40
-                sprintf(
41
-                    esc_html__('%1$s requires the incoming data argument to be an instance of %2$s or an array where the first value is an instance of %2$s', 'event_espresso'),
42
-                    'EE_Messages_REG_incoming_data',
43
-                    'EE_Registration'
44
-                )
45
-            );
46
-        }
47
-
48
-        $data = array(
49
-            'reg_obj' => $this->reg_obj,
50
-            'filtered_reg_status' => $filtered_reg_status
51
-            );
52
-
53
-        parent::__construct($data);
54
-    }
55
-
56
-    /**
57
-     * Returns database safe representation of the data later used to when instantiating this object.
58
-     *
59
-     * @param mixed $data The incoming data to be prepped.
60
-     *
61
-     * @return array   The prepped data for db
62
-     */
63
-    public static function convert_data_for_persistent_storage($data)
64
-    {
65
-        $prepped_data = array();
66
-        if (! is_array($data) && $data instanceof EE_Registration) {
67
-            $prepped_data['Registration'] = $data->ID();
68
-            return $prepped_data;
69
-        } elseif (! is_array($data)) {
70
-            return array();
71
-        } else {
72
-            if ($data[0] instanceof EE_Registration) {
73
-                $prepped_data['Registration'] = $data[0];
74
-            }
75
-            if (! empty($data[1])) {
76
-                $prepped_data['filter'] = $data[1];
77
-            }
78
-        }
79
-
80
-        return $prepped_data;
81
-    }
82
-
83
-    /**
84
-     * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
85
-     * can be sent into this method and converted back into the format used for instantiating with this data handler.
86
-     *
87
-     * @param $data
88
-     *
89
-     * @return mixed
90
-     */
91
-    public static function convert_data_from_persistent_storage($data)
92
-    {
93
-        $registration = null;
94
-        // $data['Registration'] could be either an ID (back compat) or a registration object (prepped using old system).
95
-        if (isset($data['Registration'])) {
96
-            $registration = $data['Registration'] instanceof EE_Registration
97
-                ? $data['Registration']
98
-                : EEM_Registration::instance()->get_one_by_ID($data['Registration']);
99
-        }
100
-        $prepped_data = array(
101
-            0 => $registration,
102
-            1 => isset($data['filter']) ? $data['filter'] : null
103
-        );
104
-        return $prepped_data;
105
-    }
106
-
107
-
108
-    /**
109
-     * This will just setup the _events property in the expected format.
110
-     * @return void
111
-     */
112
-    protected function _setup_data()
113
-    {
114
-
115
-        // now let's loop and set up the _events property.  At the same time we'll set up attendee properties.
116
-        $this->filtered_reg_status = $this->_data['filtered_reg_status'];
117
-        // get txn
118
-        $this->txn = $this->reg_obj->transaction();
119
-        // possible session stuff?
120
-        $session = $this->txn->session_data();
121
-        $session_data =  $session instanceof EE_Session ? $session->get_session_data() : array();
122
-
123
-        // other data from the session (if possible)
124
-        $this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : '';
125
-        $this->ip_address = isset($session_data['ip_address']) ? $session_data['ip_address'] : '';
126
-        $this->user_agent = isset($session_data['user_agent']) ? $session_data['user_agent'] : '';
127
-        $this->init_access = $this->last_access = '';
128
-
129
-        $this->payment = $this->txn->get_first_related('Payment');
130
-        // if there is no payments associated with the transaction
131
-        // then we just create a default payment object for potential parsing.
132
-        $this->payment = empty($this->payment)
133
-            ? EE_Payment::new_instance(
134
-                array(
135
-                    'STS_ID'               => EEM_Payment::status_id_pending,
136
-                    'PAY_timestamp'        => time(),
137
-                    'PMD_ID'               => $this->txn->payment_method_ID(),
138
-                    'PAY_gateway_response' => $this->txn->gateway_response_on_transaction(),
139
-                )
140
-            )
141
-            : $this->payment;
142
-
143
-
144
-        // get reg_objs for txn
145
-        $this->reg_objs = $this->txn->registrations();
146
-
147
-        // now we can set things up like we do for other handlers
148
-
149
-        $this->_assemble_data();
150
-    }
18
+	/**
19
+	 * For the constructor of this special preview class.
20
+	 *
21
+	 * The data is expected to be an array that came from the request data
22
+	 * and should have at least one property from the list looked for.
23
+	 *
24
+	 * @param EE_Registration|array $data
25
+	 * @throws \EE_Error
26
+	 */
27
+	public function __construct($data)
28
+	{
29
+		$filtered_reg_status = null;
30
+
31
+		if (! is_array($data) && $data instanceof EE_Registration) {
32
+			$this->reg_obj = $data;
33
+		} else {
34
+			$this->reg_obj = is_array($data) && isset($data[0]) && $data[0] instanceof EE_Registration ? $data[0] : null;
35
+			$filtered_reg_status = is_array($data) && ! empty($data[1]) ? $data[1] : null;
36
+		}
37
+
38
+		if (! $this->reg_obj instanceof EE_Registration) {
39
+			throw new EE_Error(
40
+				sprintf(
41
+					esc_html__('%1$s requires the incoming data argument to be an instance of %2$s or an array where the first value is an instance of %2$s', 'event_espresso'),
42
+					'EE_Messages_REG_incoming_data',
43
+					'EE_Registration'
44
+				)
45
+			);
46
+		}
47
+
48
+		$data = array(
49
+			'reg_obj' => $this->reg_obj,
50
+			'filtered_reg_status' => $filtered_reg_status
51
+			);
52
+
53
+		parent::__construct($data);
54
+	}
55
+
56
+	/**
57
+	 * Returns database safe representation of the data later used to when instantiating this object.
58
+	 *
59
+	 * @param mixed $data The incoming data to be prepped.
60
+	 *
61
+	 * @return array   The prepped data for db
62
+	 */
63
+	public static function convert_data_for_persistent_storage($data)
64
+	{
65
+		$prepped_data = array();
66
+		if (! is_array($data) && $data instanceof EE_Registration) {
67
+			$prepped_data['Registration'] = $data->ID();
68
+			return $prepped_data;
69
+		} elseif (! is_array($data)) {
70
+			return array();
71
+		} else {
72
+			if ($data[0] instanceof EE_Registration) {
73
+				$prepped_data['Registration'] = $data[0];
74
+			}
75
+			if (! empty($data[1])) {
76
+				$prepped_data['filter'] = $data[1];
77
+			}
78
+		}
79
+
80
+		return $prepped_data;
81
+	}
82
+
83
+	/**
84
+	 * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
85
+	 * can be sent into this method and converted back into the format used for instantiating with this data handler.
86
+	 *
87
+	 * @param $data
88
+	 *
89
+	 * @return mixed
90
+	 */
91
+	public static function convert_data_from_persistent_storage($data)
92
+	{
93
+		$registration = null;
94
+		// $data['Registration'] could be either an ID (back compat) or a registration object (prepped using old system).
95
+		if (isset($data['Registration'])) {
96
+			$registration = $data['Registration'] instanceof EE_Registration
97
+				? $data['Registration']
98
+				: EEM_Registration::instance()->get_one_by_ID($data['Registration']);
99
+		}
100
+		$prepped_data = array(
101
+			0 => $registration,
102
+			1 => isset($data['filter']) ? $data['filter'] : null
103
+		);
104
+		return $prepped_data;
105
+	}
106
+
107
+
108
+	/**
109
+	 * This will just setup the _events property in the expected format.
110
+	 * @return void
111
+	 */
112
+	protected function _setup_data()
113
+	{
114
+
115
+		// now let's loop and set up the _events property.  At the same time we'll set up attendee properties.
116
+		$this->filtered_reg_status = $this->_data['filtered_reg_status'];
117
+		// get txn
118
+		$this->txn = $this->reg_obj->transaction();
119
+		// possible session stuff?
120
+		$session = $this->txn->session_data();
121
+		$session_data =  $session instanceof EE_Session ? $session->get_session_data() : array();
122
+
123
+		// other data from the session (if possible)
124
+		$this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : '';
125
+		$this->ip_address = isset($session_data['ip_address']) ? $session_data['ip_address'] : '';
126
+		$this->user_agent = isset($session_data['user_agent']) ? $session_data['user_agent'] : '';
127
+		$this->init_access = $this->last_access = '';
128
+
129
+		$this->payment = $this->txn->get_first_related('Payment');
130
+		// if there is no payments associated with the transaction
131
+		// then we just create a default payment object for potential parsing.
132
+		$this->payment = empty($this->payment)
133
+			? EE_Payment::new_instance(
134
+				array(
135
+					'STS_ID'               => EEM_Payment::status_id_pending,
136
+					'PAY_timestamp'        => time(),
137
+					'PMD_ID'               => $this->txn->payment_method_ID(),
138
+					'PAY_gateway_response' => $this->txn->gateway_response_on_transaction(),
139
+				)
140
+			)
141
+			: $this->payment;
142
+
143
+
144
+		// get reg_objs for txn
145
+		$this->reg_objs = $this->txn->registrations();
146
+
147
+		// now we can set things up like we do for other handlers
148
+
149
+		$this->_assemble_data();
150
+	}
151 151
 }
Please login to merge, or discard this patch.
libraries/messages/data_class/EE_Messages_Gateways_incoming_data.class.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     {
33 33
 
34 34
         // test for valid params
35
-        if (! ( $data[0] instanceof EE_Transaction )) {
35
+        if ( ! ($data[0] instanceof EE_Transaction)) {
36 36
             throw new EE_Error(esc_html__('Incoming data for the Gateways data handler must have an EE_Transaction object as the value for the first array index.', 'event_espresso'));
37 37
         }
38 38
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
             $pmt_obj = $this->_get_empty_payment_obj($data[0]);
41 41
         }
42 42
 
43
-        if (! empty($data[2])) {
43
+        if ( ! empty($data[2])) {
44 44
             $filtered_reg_status = $data[2];
45 45
         }
46 46
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             $prepped_data['Payment'] = $data[1]->ID();
76 76
         }
77 77
 
78
-        if (! empty($data[2])) {
78
+        if ( ! empty($data[2])) {
79 79
             $prepped_data['filter'] = $data[2];
80 80
         }
81 81
 
Please login to merge, or discard this patch.
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -13,141 +13,141 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Messages_Gateways_incoming_data extends EE_Messages_incoming_data
15 15
 {
16
-    /**
17
-     * This holds the incoming payment object
18
-     * @var EE_Payment
19
-     */
20
-    public $payment;
21
-
22
-
23
-
24
-    /**
25
-     * incoming data is expected to be a EE_Transaction object and (possibly) EE_Payment object in an array.
26
-     *
27
-     * @param array $data
28
-     * @throws EE_Error
29
-     */
30
-    public function __construct($data)
31
-    {
32
-
33
-        // test for valid params
34
-        if (! ( $data[0] instanceof EE_Transaction )) {
35
-            throw new EE_Error(esc_html__('Incoming data for the Gateways data handler must have an EE_Transaction object as the value for the first array index.', 'event_espresso'));
36
-        }
37
-
38
-        if (empty($data[1]) || ! $data[1] instanceof  EE_Payment) {
39
-            $pmt_obj = $this->_get_empty_payment_obj($data[0]);
40
-        }
41
-
42
-        if (! empty($data[2])) {
43
-            $filtered_reg_status = $data[2];
44
-        }
16
+	/**
17
+	 * This holds the incoming payment object
18
+	 * @var EE_Payment
19
+	 */
20
+	public $payment;
21
+
22
+
23
+
24
+	/**
25
+	 * incoming data is expected to be a EE_Transaction object and (possibly) EE_Payment object in an array.
26
+	 *
27
+	 * @param array $data
28
+	 * @throws EE_Error
29
+	 */
30
+	public function __construct($data)
31
+	{
32
+
33
+		// test for valid params
34
+		if (! ( $data[0] instanceof EE_Transaction )) {
35
+			throw new EE_Error(esc_html__('Incoming data for the Gateways data handler must have an EE_Transaction object as the value for the first array index.', 'event_espresso'));
36
+		}
37
+
38
+		if (empty($data[1]) || ! $data[1] instanceof  EE_Payment) {
39
+			$pmt_obj = $this->_get_empty_payment_obj($data[0]);
40
+		}
41
+
42
+		if (! empty($data[2])) {
43
+			$filtered_reg_status = $data[2];
44
+		}
45 45
 
46
-        $data = array(
47
-            'txn_obj' => $data[0],
48
-            'pmt_obj' => isset($pmt_obj) ? $pmt_obj : $data[1],
49
-            'filtered_reg_status' => isset($filtered_reg_status) ? $filtered_reg_status : null
50
-            );
51
-        parent::__construct($data);
52
-    }
53
-
54
-
55
-
56
-
57
-
58
-    /**
59
-     * Returns database safe representation of the data later used to when instantiating this object.
60
-     *
61
-     * @param array $data The incoming data to be prepped.
62
-     *
63
-     * @return array   The prepped data for db
64
-     */
65
-    public static function convert_data_for_persistent_storage($data)
66
-    {
67
-        $prepped_data = array();
68
-
69
-        if ($data[0] instanceof EE_Transaction) {
70
-            $prepped_data['Transaction'] = $data[0]->ID();
71
-        }
72
-
73
-        if (isset($data[1]) && $data[1] instanceof EE_Payment) {
74
-            $prepped_data['Payment'] = $data[1]->ID();
75
-        }
76
-
77
-        if (! empty($data[2])) {
78
-            $prepped_data['filter'] = $data[2];
79
-        }
80
-
81
-        return $prepped_data;
82
-    }
83
-
84
-
85
-
86
-
87
-
88
-
89
-    /**
90
-     * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
91
-     * can be sent into this method and converted back into the format used for instantiating with this data handler.
92
-     *
93
-     * @param array  $data
94
-     *
95
-     * @return array
96
-     */
97
-    public static function convert_data_from_persistent_storage($data)
98
-    {
99
-        $prepped_data = array(
100
-            0 => isset($data['Transaction']) ? EEM_Transaction::instance()->get_one_by_ID($data['Transaction']) : null,
101
-            1 => isset($data['Payment']) ? EEM_Payment::instance()->get_one_by_ID($data['Payment']) : null,
102
-            2 => isset($data['filter']) ? $data['filter'] : null
103
-        );
104
-        return $prepped_data;
105
-    }
106
-
107
-
108
-    /**
109
-     * This sets up an empty EE_Payment object for the purpose of shortcode parsing.  Note that this doesn't actually get saved to the db.
110
-     * @param \EE_Transaction $txn
111
-     * @return \EE_Payment
112
-     */
113
-    private function _get_empty_payment_obj(EE_Transaction $txn)
114
-    {
115
-        $PMT = EE_Payment::new_instance(array(
116
-            'STS_ID' => EEM_Payment::status_id_pending,
117
-            'PAY_timestamp' => time(),
118
-            'PMD_ID' => $txn->payment_method_ID(),
119
-            'PAY_gateway_response' => $txn->gateway_response_on_transaction(),
120
-            ));
121
-        return $PMT;
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * _setup_data
128
-     *
129
-     * @throws EE_Error
130
-     */
131
-    protected function _setup_data()
132
-    {
133
-
134
-        $this->reg_info = array();
135
-
136
-        $this->txn = $this->_data['txn_obj'];
137
-        $this->payment = $this->_data['pmt_obj'];
138
-        $this->filtered_reg_status = $this->_data['filtered_reg_status'];
139
-        $this->incoming_data = $this->_data;
140
-
141
-        $session_data = $this->txn->session_data();
142
-
143
-
144
-        // other data from the session (if possible)
145
-        $this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : '';
146
-        $this->ip_address = isset($session_data['ip_address']) ? $session_data['ip_address'] : '';
147
-        $this->user_agent = isset($session_data['user_agent']) ? $session_data['user_agent'] : '';
148
-        $this->init_access = $this->last_access = '';
149
-        // get all non-trashed registrations
150
-        $this->reg_objs = $this->txn->registrations(array(array('REG_deleted' => false)));
151
-        $this->_assemble_data();
152
-    }
46
+		$data = array(
47
+			'txn_obj' => $data[0],
48
+			'pmt_obj' => isset($pmt_obj) ? $pmt_obj : $data[1],
49
+			'filtered_reg_status' => isset($filtered_reg_status) ? $filtered_reg_status : null
50
+			);
51
+		parent::__construct($data);
52
+	}
53
+
54
+
55
+
56
+
57
+
58
+	/**
59
+	 * Returns database safe representation of the data later used to when instantiating this object.
60
+	 *
61
+	 * @param array $data The incoming data to be prepped.
62
+	 *
63
+	 * @return array   The prepped data for db
64
+	 */
65
+	public static function convert_data_for_persistent_storage($data)
66
+	{
67
+		$prepped_data = array();
68
+
69
+		if ($data[0] instanceof EE_Transaction) {
70
+			$prepped_data['Transaction'] = $data[0]->ID();
71
+		}
72
+
73
+		if (isset($data[1]) && $data[1] instanceof EE_Payment) {
74
+			$prepped_data['Payment'] = $data[1]->ID();
75
+		}
76
+
77
+		if (! empty($data[2])) {
78
+			$prepped_data['filter'] = $data[2];
79
+		}
80
+
81
+		return $prepped_data;
82
+	}
83
+
84
+
85
+
86
+
87
+
88
+
89
+	/**
90
+	 * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
91
+	 * can be sent into this method and converted back into the format used for instantiating with this data handler.
92
+	 *
93
+	 * @param array  $data
94
+	 *
95
+	 * @return array
96
+	 */
97
+	public static function convert_data_from_persistent_storage($data)
98
+	{
99
+		$prepped_data = array(
100
+			0 => isset($data['Transaction']) ? EEM_Transaction::instance()->get_one_by_ID($data['Transaction']) : null,
101
+			1 => isset($data['Payment']) ? EEM_Payment::instance()->get_one_by_ID($data['Payment']) : null,
102
+			2 => isset($data['filter']) ? $data['filter'] : null
103
+		);
104
+		return $prepped_data;
105
+	}
106
+
107
+
108
+	/**
109
+	 * This sets up an empty EE_Payment object for the purpose of shortcode parsing.  Note that this doesn't actually get saved to the db.
110
+	 * @param \EE_Transaction $txn
111
+	 * @return \EE_Payment
112
+	 */
113
+	private function _get_empty_payment_obj(EE_Transaction $txn)
114
+	{
115
+		$PMT = EE_Payment::new_instance(array(
116
+			'STS_ID' => EEM_Payment::status_id_pending,
117
+			'PAY_timestamp' => time(),
118
+			'PMD_ID' => $txn->payment_method_ID(),
119
+			'PAY_gateway_response' => $txn->gateway_response_on_transaction(),
120
+			));
121
+		return $PMT;
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * _setup_data
128
+	 *
129
+	 * @throws EE_Error
130
+	 */
131
+	protected function _setup_data()
132
+	{
133
+
134
+		$this->reg_info = array();
135
+
136
+		$this->txn = $this->_data['txn_obj'];
137
+		$this->payment = $this->_data['pmt_obj'];
138
+		$this->filtered_reg_status = $this->_data['filtered_reg_status'];
139
+		$this->incoming_data = $this->_data;
140
+
141
+		$session_data = $this->txn->session_data();
142
+
143
+
144
+		// other data from the session (if possible)
145
+		$this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : '';
146
+		$this->ip_address = isset($session_data['ip_address']) ? $session_data['ip_address'] : '';
147
+		$this->user_agent = isset($session_data['user_agent']) ? $session_data['user_agent'] : '';
148
+		$this->init_access = $this->last_access = '';
149
+		// get all non-trashed registrations
150
+		$this->reg_objs = $this->txn->registrations(array(array('REG_deleted' => false)));
151
+		$this->_assemble_data();
152
+	}
153 153
 }
Please login to merge, or discard this patch.