Completed
Branch FET/extra-logging-when-trashin... (b6e112)
by
unknown
36:04 queued 27:41
created
core/helpers/EEH_Money.helper.php 2 patches
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -12,221 +12,221 @@
 block discarded – undo
12 12
 class EEH_Money extends EEH_Base
13 13
 {
14 14
 
15
-    /**
16
-     * This removes all localized money formatting from the incoming value
17
-     * Note: uses this site's currency settings for deciding what is considered a
18
-     * "thousands separator" (usually the character "," )
19
-     * and what is a "decimal mark" (usually the character ".")
20
-     *
21
-     * @param int|float|string $money_value
22
-     * @param string           $CNT_ISO
23
-     * @return float
24
-     * @throws EE_Error
25
-     */
26
-    public static function strip_localized_money_formatting($money_value, $CNT_ISO = '')
27
-    {
28
-        $currency_config = EEH_Money::get_currency_config($CNT_ISO);
29
-        $money_value     = str_replace(
30
-            array(
31
-                $currency_config->thsnds,
32
-                $currency_config->dec_mrk,
33
-            ),
34
-            array(
35
-                '', // remove thousands separator
36
-                '.', // convert decimal mark to what PHP expects
37
-            ),
38
-            $money_value
39
-        );
40
-        $money_value     = filter_var(
41
-            $money_value,
42
-            FILTER_SANITIZE_NUMBER_FLOAT,
43
-            FILTER_FLAG_ALLOW_FRACTION
44
-        );
45
-        return $money_value;
46
-    }
15
+	/**
16
+	 * This removes all localized money formatting from the incoming value
17
+	 * Note: uses this site's currency settings for deciding what is considered a
18
+	 * "thousands separator" (usually the character "," )
19
+	 * and what is a "decimal mark" (usually the character ".")
20
+	 *
21
+	 * @param int|float|string $money_value
22
+	 * @param string           $CNT_ISO
23
+	 * @return float
24
+	 * @throws EE_Error
25
+	 */
26
+	public static function strip_localized_money_formatting($money_value, $CNT_ISO = '')
27
+	{
28
+		$currency_config = EEH_Money::get_currency_config($CNT_ISO);
29
+		$money_value     = str_replace(
30
+			array(
31
+				$currency_config->thsnds,
32
+				$currency_config->dec_mrk,
33
+			),
34
+			array(
35
+				'', // remove thousands separator
36
+				'.', // convert decimal mark to what PHP expects
37
+			),
38
+			$money_value
39
+		);
40
+		$money_value     = filter_var(
41
+			$money_value,
42
+			FILTER_SANITIZE_NUMBER_FLOAT,
43
+			FILTER_FLAG_ALLOW_FRACTION
44
+		);
45
+		return $money_value;
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * This converts an incoming localized money value into a standard float item (to three decimal places)
51
-     * Only use this if you know the $money_value follows your currency configuration's
52
-     * settings. Note: this uses this site's currency settings for deciding what is considered a
53
-     * "thousands separator" (usually the character "," )
54
-     * and what is a "decimal mark" (usually the character ".")
55
-     *
56
-     * @param int|string $money_value
57
-     * @return float
58
-     * @throws EE_Error
59
-     */
60
-    public static function convert_to_float_from_localized_money($money_value)
61
-    {
62
-        // float it! and round to three decimal places
63
-        return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3);
64
-    }
49
+	/**
50
+	 * This converts an incoming localized money value into a standard float item (to three decimal places)
51
+	 * Only use this if you know the $money_value follows your currency configuration's
52
+	 * settings. Note: this uses this site's currency settings for deciding what is considered a
53
+	 * "thousands separator" (usually the character "," )
54
+	 * and what is a "decimal mark" (usually the character ".")
55
+	 *
56
+	 * @param int|string $money_value
57
+	 * @return float
58
+	 * @throws EE_Error
59
+	 */
60
+	public static function convert_to_float_from_localized_money($money_value)
61
+	{
62
+		// float it! and round to three decimal places
63
+		return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3);
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * For comparing floats. Default operator is '=', but see the $operator below for all options.
69
-     * This should be used to compare floats instead of normal '==' because floats
70
-     * are inherently imprecise, and so you can sometimes have two floats that appear to be identical
71
-     * but actually differ by 0.00000001.
72
-     *
73
-     * @see http://biostall.com/php-function-to-compare-floating-point-numbers
74
-     * @param float  $float1
75
-     * @param float  $float2
76
-     * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne
77
-     * @return bool whether the equation is true or false
78
-     * @throws EE_Error
79
-     */
80
-    public static function compare_floats($float1, $float2, $operator = '=')
81
-    {
82
-        // Check numbers to 5 digits of precision
83
-        $epsilon = 0.00001;
84
-        $float1 = (float) $float1;
85
-        $float2 = (float) $float2;
86
-        switch ($operator) {
87
-            // equal
88
-            case "=":
89
-            case "==":
90
-            case "===":
91
-            case "eq":
92
-                if (abs($float1 - $float2) < $epsilon) {
93
-                    return true;
94
-                }
95
-                break;
96
-            // less than
97
-            case "<":
98
-            case "lt":
99
-                if (abs($float1 - $float2) < $epsilon) {
100
-                    return false;
101
-                } else {
102
-                    if ($float1 < $float2) {
103
-                        return true;
104
-                    }
105
-                }
106
-                break;
107
-            // less than or equal
108
-            case "<=":
109
-            case "lte":
110
-                if (self::compare_floats($float1, $float2, '<') || self::compare_floats($float1, $float2, '=')) {
111
-                    return true;
112
-                }
113
-                break;
114
-            // greater than
115
-            case ">":
116
-            case "gt":
117
-                if (abs($float1 - $float2) < $epsilon) {
118
-                    return false;
119
-                } else {
120
-                    if ($float1 > $float2) {
121
-                        return true;
122
-                    }
123
-                }
124
-                break;
125
-            // greater than or equal
126
-            case ">=":
127
-            case "gte":
128
-                if (self::compare_floats($float1, $float2, '>') || self::compare_floats($float1, $float2, '=')) {
129
-                    return true;
130
-                }
131
-                break;
132
-            case "<>":
133
-            case "!=":
134
-            case "ne":
135
-                if (abs($float1 - $float2) > $epsilon) {
136
-                    return true;
137
-                }
138
-                break;
139
-            default:
140
-                throw new EE_Error(
141
-                    sprintf(
142
-                        __(
143
-                            "Unknown operator %s in EEH_Money::compare_floats()",
144
-                            'event_espresso'
145
-                        ),
146
-                        $operator
147
-                    )
148
-                );
149
-        }
150
-        return false;
151
-    }
67
+	/**
68
+	 * For comparing floats. Default operator is '=', but see the $operator below for all options.
69
+	 * This should be used to compare floats instead of normal '==' because floats
70
+	 * are inherently imprecise, and so you can sometimes have two floats that appear to be identical
71
+	 * but actually differ by 0.00000001.
72
+	 *
73
+	 * @see http://biostall.com/php-function-to-compare-floating-point-numbers
74
+	 * @param float  $float1
75
+	 * @param float  $float2
76
+	 * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne
77
+	 * @return bool whether the equation is true or false
78
+	 * @throws EE_Error
79
+	 */
80
+	public static function compare_floats($float1, $float2, $operator = '=')
81
+	{
82
+		// Check numbers to 5 digits of precision
83
+		$epsilon = 0.00001;
84
+		$float1 = (float) $float1;
85
+		$float2 = (float) $float2;
86
+		switch ($operator) {
87
+			// equal
88
+			case "=":
89
+			case "==":
90
+			case "===":
91
+			case "eq":
92
+				if (abs($float1 - $float2) < $epsilon) {
93
+					return true;
94
+				}
95
+				break;
96
+			// less than
97
+			case "<":
98
+			case "lt":
99
+				if (abs($float1 - $float2) < $epsilon) {
100
+					return false;
101
+				} else {
102
+					if ($float1 < $float2) {
103
+						return true;
104
+					}
105
+				}
106
+				break;
107
+			// less than or equal
108
+			case "<=":
109
+			case "lte":
110
+				if (self::compare_floats($float1, $float2, '<') || self::compare_floats($float1, $float2, '=')) {
111
+					return true;
112
+				}
113
+				break;
114
+			// greater than
115
+			case ">":
116
+			case "gt":
117
+				if (abs($float1 - $float2) < $epsilon) {
118
+					return false;
119
+				} else {
120
+					if ($float1 > $float2) {
121
+						return true;
122
+					}
123
+				}
124
+				break;
125
+			// greater than or equal
126
+			case ">=":
127
+			case "gte":
128
+				if (self::compare_floats($float1, $float2, '>') || self::compare_floats($float1, $float2, '=')) {
129
+					return true;
130
+				}
131
+				break;
132
+			case "<>":
133
+			case "!=":
134
+			case "ne":
135
+				if (abs($float1 - $float2) > $epsilon) {
136
+					return true;
137
+				}
138
+				break;
139
+			default:
140
+				throw new EE_Error(
141
+					sprintf(
142
+						__(
143
+							"Unknown operator %s in EEH_Money::compare_floats()",
144
+							'event_espresso'
145
+						),
146
+						$operator
147
+					)
148
+				);
149
+		}
150
+		return false;
151
+	}
152 152
 
153 153
 
154
-    /**
155
-     * This returns a localized format string suitable for jQplot.
156
-     *
157
-     * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
158
-     *                         Otherwise will use currency settings for current active country on site.
159
-     * @return string
160
-     * @throws EE_Error
161
-     */
162
-    public static function get_format_for_jqplot($CNT_ISO = '')
163
-    {
164
-        // default format
165
-        $format          = 'f';
166
-        $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
167
-        // first get the decimal place and number of places
168
-        $format = "%'." . $currency_config->dec_plc . $format;
169
-        // currency symbol on right side.
170
-        $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
171
-        return $format;
172
-    }
154
+	/**
155
+	 * This returns a localized format string suitable for jQplot.
156
+	 *
157
+	 * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
158
+	 *                         Otherwise will use currency settings for current active country on site.
159
+	 * @return string
160
+	 * @throws EE_Error
161
+	 */
162
+	public static function get_format_for_jqplot($CNT_ISO = '')
163
+	{
164
+		// default format
165
+		$format          = 'f';
166
+		$currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
167
+		// first get the decimal place and number of places
168
+		$format = "%'." . $currency_config->dec_plc . $format;
169
+		// currency symbol on right side.
170
+		$format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
171
+		return $format;
172
+	}
173 173
 
174 174
 
175
-    /**
176
-     * This returns a localized format string suitable for usage with the Google Charts API format param.
177
-     *
178
-     * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
179
-     *                         Otherwise will use currency settings for current active country on site.
180
-     *                         Note: GoogleCharts uses ICU pattern set
181
-     *                         (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details)
182
-     * @return string
183
-     * @throws EE_Error
184
-     */
185
-    public static function get_format_for_google_charts($CNT_ISO = '')
186
-    {
187
-        $currency_config            = EEH_Money::get_currency_config($CNT_ISO);
188
-        $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
189
-        // first get the decimal place and number of places
190
-        $format = '#,##0.' . $decimal_places_placeholder;
191
-        // currency symbol on right side.
192
-        $format          = $currency_config->sign_b4
193
-            ? $currency_config->sign . $format
194
-            : $format
195
-              . $currency_config->sign;
196
-        $formatterObject = array(
197
-            'decimalSymbol'  => $currency_config->dec_mrk,
198
-            'groupingSymbol' => $currency_config->thsnds,
199
-            'fractionDigits' => $currency_config->dec_plc,
200
-        );
201
-        if ($currency_config->sign_b4) {
202
-            $formatterObject['prefix'] = $currency_config->sign;
203
-        } else {
204
-            $formatterObject['suffix'] = $currency_config->sign;
205
-        }
206
-        return array(
207
-            'format'          => $format,
208
-            'formatterObject' => $formatterObject,
209
-        );
210
-    }
175
+	/**
176
+	 * This returns a localized format string suitable for usage with the Google Charts API format param.
177
+	 *
178
+	 * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
179
+	 *                         Otherwise will use currency settings for current active country on site.
180
+	 *                         Note: GoogleCharts uses ICU pattern set
181
+	 *                         (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details)
182
+	 * @return string
183
+	 * @throws EE_Error
184
+	 */
185
+	public static function get_format_for_google_charts($CNT_ISO = '')
186
+	{
187
+		$currency_config            = EEH_Money::get_currency_config($CNT_ISO);
188
+		$decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
189
+		// first get the decimal place and number of places
190
+		$format = '#,##0.' . $decimal_places_placeholder;
191
+		// currency symbol on right side.
192
+		$format          = $currency_config->sign_b4
193
+			? $currency_config->sign . $format
194
+			: $format
195
+			  . $currency_config->sign;
196
+		$formatterObject = array(
197
+			'decimalSymbol'  => $currency_config->dec_mrk,
198
+			'groupingSymbol' => $currency_config->thsnds,
199
+			'fractionDigits' => $currency_config->dec_plc,
200
+		);
201
+		if ($currency_config->sign_b4) {
202
+			$formatterObject['prefix'] = $currency_config->sign;
203
+		} else {
204
+			$formatterObject['suffix'] = $currency_config->sign;
205
+		}
206
+		return array(
207
+			'format'          => $format,
208
+			'formatterObject' => $formatterObject,
209
+		);
210
+	}
211 211
 
212 212
 
213
-    /**
214
-     * @param string $CNT_ISO
215
-     * @return EE_Currency_Config|null
216
-     * @throws EE_Error
217
-     */
218
-    public static function get_currency_config($CNT_ISO = '')
219
-    {
220
-        // if CNT_ISO passed lets try to get currency settings for it.
221
-        $currency_config = $CNT_ISO !== ''
222
-            ? new EE_Currency_Config($CNT_ISO)
223
-            : null;
224
-        // default currency settings for site if not set
225
-        if (! $currency_config instanceof EE_Currency_Config) {
226
-            $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
227
-                ? EE_Registry::instance()->CFG->currency
228
-                : new EE_Currency_Config();
229
-        }
230
-        return $currency_config;
231
-    }
213
+	/**
214
+	 * @param string $CNT_ISO
215
+	 * @return EE_Currency_Config|null
216
+	 * @throws EE_Error
217
+	 */
218
+	public static function get_currency_config($CNT_ISO = '')
219
+	{
220
+		// if CNT_ISO passed lets try to get currency settings for it.
221
+		$currency_config = $CNT_ISO !== ''
222
+			? new EE_Currency_Config($CNT_ISO)
223
+			: null;
224
+		// default currency settings for site if not set
225
+		if (! $currency_config instanceof EE_Currency_Config) {
226
+			$currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
227
+				? EE_Registry::instance()->CFG->currency
228
+				: new EE_Currency_Config();
229
+		}
230
+		return $currency_config;
231
+	}
232 232
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
             ),
38 38
             $money_value
39 39
         );
40
-        $money_value     = filter_var(
40
+        $money_value = filter_var(
41 41
             $money_value,
42 42
             FILTER_SANITIZE_NUMBER_FLOAT,
43 43
             FILTER_FLAG_ALLOW_FRACTION
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
         $format          = 'f';
166 166
         $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
167 167
         // first get the decimal place and number of places
168
-        $format = "%'." . $currency_config->dec_plc . $format;
168
+        $format = "%'.".$currency_config->dec_plc.$format;
169 169
         // currency symbol on right side.
170
-        $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
170
+        $format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign;
171 171
         return $format;
172 172
     }
173 173
 
@@ -187,10 +187,10 @@  discard block
 block discarded – undo
187 187
         $currency_config            = EEH_Money::get_currency_config($CNT_ISO);
188 188
         $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
189 189
         // first get the decimal place and number of places
190
-        $format = '#,##0.' . $decimal_places_placeholder;
190
+        $format = '#,##0.'.$decimal_places_placeholder;
191 191
         // currency symbol on right side.
192
-        $format          = $currency_config->sign_b4
193
-            ? $currency_config->sign . $format
192
+        $format = $currency_config->sign_b4
193
+            ? $currency_config->sign.$format
194 194
             : $format
195 195
               . $currency_config->sign;
196 196
         $formatterObject = array(
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
             ? new EE_Currency_Config($CNT_ISO)
223 223
             : null;
224 224
         // default currency settings for site if not set
225
-        if (! $currency_config instanceof EE_Currency_Config) {
225
+        if ( ! $currency_config instanceof EE_Currency_Config) {
226 226
             $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
227 227
                 ? EE_Registry::instance()->CFG->currency
228 228
                 : new EE_Currency_Config();
Please login to merge, or discard this patch.
core/CPTs/EE_CPT_Default_Strategy.core.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -13,70 +13,70 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * $CPT - the current page, if it utilizes CPTs
18
-     *
19
-     * @var    object
20
-     * @access    protected
21
-     */
22
-    protected $CPT = null;
16
+	/**
17
+	 * $CPT - the current page, if it utilizes CPTs
18
+	 *
19
+	 * @var    object
20
+	 * @access    protected
21
+	 */
22
+	protected $CPT = null;
23 23
 
24 24
 
25
-    /**
26
-     *    class constructor
27
-     *
28
-     * @access    private
29
-     * @param    array $arguments
30
-     * @return    \EE_CPT_Default_Strategy
31
-     */
32
-    public function __construct($arguments = array())
33
-    {
34
-        $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null;
35
-    }
25
+	/**
26
+	 *    class constructor
27
+	 *
28
+	 * @access    private
29
+	 * @param    array $arguments
30
+	 * @return    \EE_CPT_Default_Strategy
31
+	 */
32
+	public function __construct($arguments = array())
33
+	{
34
+		$this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null;
35
+	}
36 36
 
37 37
 
38
-    /**
39
-     *    pre_get_posts
40
-     *
41
-     * @access    public
42
-     * @param    \WP_Query $WP_Query
43
-     * @return    \WP_Query
44
-     */
45
-    public function pre_get_posts(WP_Query $WP_Query)
46
-    {
47
-        if (! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) {
48
-            return $WP_Query;
49
-        }
50
-        return $WP_Query;
51
-    }
38
+	/**
39
+	 *    pre_get_posts
40
+	 *
41
+	 * @access    public
42
+	 * @param    \WP_Query $WP_Query
43
+	 * @return    \WP_Query
44
+	 */
45
+	public function pre_get_posts(WP_Query $WP_Query)
46
+	{
47
+		if (! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) {
48
+			return $WP_Query;
49
+		}
50
+		return $WP_Query;
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     *    wp
56
-     *
57
-     * @access    public
58
-     * @param    \WP_Post[] $posts
59
-     * @param    \WP_Query  $WP_Query
60
-     * @return    \WP_Post[]
61
-     */
62
-    public function the_posts($posts, WP_Query $WP_Query)
63
-    {
64
-        return $posts;
65
-    }
54
+	/**
55
+	 *    wp
56
+	 *
57
+	 * @access    public
58
+	 * @param    \WP_Post[] $posts
59
+	 * @param    \WP_Query  $WP_Query
60
+	 * @return    \WP_Post[]
61
+	 */
62
+	public function the_posts($posts, WP_Query $WP_Query)
63
+	{
64
+		return $posts;
65
+	}
66 66
 
67 67
 
68
-    /**
69
-     *    get_EE_post_type_metadata
70
-     *
71
-     * @access    public
72
-     * @param mixed     $meta_value
73
-     * @param    int    $post_id
74
-     * @param    string $meta_key
75
-     * @param    string $single
76
-     * @return    mixed
77
-     */
78
-    public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single)
79
-    {
80
-        return $meta_value;
81
-    }
68
+	/**
69
+	 *    get_EE_post_type_metadata
70
+	 *
71
+	 * @access    public
72
+	 * @param mixed     $meta_value
73
+	 * @param    int    $post_id
74
+	 * @param    string $meta_key
75
+	 * @param    string $single
76
+	 * @return    mixed
77
+	 */
78
+	public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single)
79
+	{
80
+		return $meta_value;
81
+	}
82 82
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
      */
45 45
     public function pre_get_posts(WP_Query $WP_Query)
46 46
     {
47
-        if (! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) {
47
+        if ( ! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) {
48 48
             return $WP_Query;
49 49
         }
50 50
         return $WP_Query;
Please login to merge, or discard this patch.
core/CPTs/EE_CPT_Attendee_Strategy.core.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -24,39 +24,39 @@
 block discarded – undo
24 24
 class EE_CPT_Attendee_Strategy
25 25
 {
26 26
 
27
-    /**
28
-     * $CPT - the current page, if it utilizes CPTs
29
-     *
30
-     * @var    array
31
-     * @access    protected
32
-     */
33
-    protected $CPT = null;
27
+	/**
28
+	 * $CPT - the current page, if it utilizes CPTs
29
+	 *
30
+	 * @var    array
31
+	 * @access    protected
32
+	 */
33
+	protected $CPT = null;
34 34
 
35 35
 
36
-    /**
37
-     *    class constructor
38
-     *
39
-     * @access    public
40
-     * @param    array $arguments
41
-     * @return \EE_CPT_Attendee_Strategy
42
-     */
43
-    public function __construct($arguments = array())
44
-    {
45
-        $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null;
46
-        $WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null;
47
-    }
36
+	/**
37
+	 *    class constructor
38
+	 *
39
+	 * @access    public
40
+	 * @param    array $arguments
41
+	 * @return \EE_CPT_Attendee_Strategy
42
+	 */
43
+	public function __construct($arguments = array())
44
+	{
45
+		$this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null;
46
+		$WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null;
47
+	}
48 48
 
49 49
 
50
-    /**
51
-     *    the_posts
52
-     *
53
-     * @access    public
54
-     * @param          $posts
55
-     * @param WP_Query $wp_query
56
-     * @return    void
57
-     */
58
-    public function the_posts($posts, WP_Query $wp_query)
59
-    {
60
-        return $posts;
61
-    }
50
+	/**
51
+	 *    the_posts
52
+	 *
53
+	 * @access    public
54
+	 * @param          $posts
55
+	 * @param WP_Query $wp_query
56
+	 * @return    void
57
+	 */
58
+	public function the_posts($posts, WP_Query $wp_query)
59
+	{
60
+		return $posts;
61
+	}
62 62
 }
Please login to merge, or discard this patch.
core/CPTs/EE_CPT_Venue_Strategy.core.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -12,54 +12,54 @@
 block discarded – undo
12 12
 class EE_CPT_Venue_Strategy
13 13
 {
14 14
 
15
-    /**
16
-     * $CPT - the current page, if it utilizes CPTs
17
-     *
18
-     * @var    array
19
-     * @access    protected
20
-     */
21
-    protected $CPT = null;
15
+	/**
16
+	 * $CPT - the current page, if it utilizes CPTs
17
+	 *
18
+	 * @var    array
19
+	 * @access    protected
20
+	 */
21
+	protected $CPT = null;
22 22
 
23 23
 
24
-    /**
25
-     *    class constructor
26
-     *
27
-     * @access    public
28
-     * @param    array $arguments
29
-     * @return \EE_CPT_Venue_Strategy
30
-     */
31
-    public function __construct($arguments = array())
32
-    {
33
-        $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null;
34
-        $WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null;
35
-        if ($WP_Query instanceof WP_Query && ! $WP_Query->is_tag) {
36
-            $WP_Query->is_espresso_venue_single = is_singular()
37
-                                                  && isset($WP_Query->query->post_type)
38
-                                                  && $WP_Query->query->post_type == 'espresso_venues';
39
-            $WP_Query->is_espresso_venue_archive = is_post_type_archive('espresso_venues') ? true : false;
40
-            $WP_Query->is_espresso_venue_taxonomy = is_tax('espresso_venue_categories') ? true : false;
41
-        }
42
-        add_filter('the_posts', array($this, 'the_posts'), 1, 2);
43
-    }
24
+	/**
25
+	 *    class constructor
26
+	 *
27
+	 * @access    public
28
+	 * @param    array $arguments
29
+	 * @return \EE_CPT_Venue_Strategy
30
+	 */
31
+	public function __construct($arguments = array())
32
+	{
33
+		$this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null;
34
+		$WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null;
35
+		if ($WP_Query instanceof WP_Query && ! $WP_Query->is_tag) {
36
+			$WP_Query->is_espresso_venue_single = is_singular()
37
+												  && isset($WP_Query->query->post_type)
38
+												  && $WP_Query->query->post_type == 'espresso_venues';
39
+			$WP_Query->is_espresso_venue_archive = is_post_type_archive('espresso_venues') ? true : false;
40
+			$WP_Query->is_espresso_venue_taxonomy = is_tax('espresso_venue_categories') ? true : false;
41
+		}
42
+		add_filter('the_posts', array($this, 'the_posts'), 1, 2);
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     *    the_posts
48
-     *
49
-     * @access    public
50
-     * @param          $posts
51
-     * @param WP_Query $wp_query
52
-     * @return    void
53
-     */
54
-    public function the_posts($posts, WP_Query $wp_query)
55
-    {
56
-        // automagically load the EEH_Venue_View helper so that it's functions are available
57
-        if (isset(EE_Registry::instance()->CFG->map_settings->use_google_maps)
58
-            && EE_Registry::instance()->CFG->map_settings->use_google_maps
59
-        ) {
60
-            EEH_Maps::espresso_google_map_js();
61
-        }
62
-        remove_filter('the_posts', array($this, 'the_posts'), 1, 2);
63
-        return $posts;
64
-    }
46
+	/**
47
+	 *    the_posts
48
+	 *
49
+	 * @access    public
50
+	 * @param          $posts
51
+	 * @param WP_Query $wp_query
52
+	 * @return    void
53
+	 */
54
+	public function the_posts($posts, WP_Query $wp_query)
55
+	{
56
+		// automagically load the EEH_Venue_View helper so that it's functions are available
57
+		if (isset(EE_Registry::instance()->CFG->map_settings->use_google_maps)
58
+			&& EE_Registry::instance()->CFG->map_settings->use_google_maps
59
+		) {
60
+			EEH_Maps::espresso_google_map_js();
61
+		}
62
+		remove_filter('the_posts', array($this, 'the_posts'), 1, 2);
63
+		return $posts;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
core/EE_Payment_Processor.core.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     public static function instance()
34 34
     {
35 35
         // check if class object is instantiated
36
-        if (! self::$_instance instanceof EE_Payment_Processor) {
36
+        if ( ! self::$_instance instanceof EE_Payment_Processor) {
37 37
             self::$_instance = new self();
38 38
         }
39 39
         return self::$_instance;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
         /** @type \EE_Transaction $transaction */
171 171
         $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
172 172
         $primary_reg = $transaction->primary_registration();
173
-        if (! $primary_reg instanceof EE_Registration) {
173
+        if ( ! $primary_reg instanceof EE_Registration) {
174 174
             throw new EE_Error(
175 175
                 sprintf(
176 176
                     __(
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
                         EEM_Change_Log::instance()->log(
266 266
                             EEM_Change_Log::type_gateway,
267 267
                             array(
268
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
268
+                                'message'     => 'IPN Exception: '.$e->getMessage(),
269 269
                                 'current_url' => EEH_URL::current_url(),
270 270
                                 'payment'     => $e->getPaymentProperties(),
271 271
                                 'IPN_data'    => $e->getIpnData(),
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
                         EEM_Change_Log::instance()->log(
310 310
                             EEM_Change_Log::type_gateway,
311 311
                             array(
312
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
312
+                                'message'     => 'IPN Exception: '.$e->getMessage(),
313 313
                                 'current_url' => EEH_URL::current_url(),
314 314
                                 'payment'     => $e->getPaymentProperties(),
315 315
                                 'IPN_data'    => $e->getIpnData(),
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
     {
381 381
         $return_data = array();
382 382
         foreach ($request_data as $key => $value) {
383
-            $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters(
383
+            $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters(
384 384
                 $value
385 385
             );
386 386
         }
Please login to merge, or discard this patch.
Indentation   +838 added lines, -838 removed lines patch added patch discarded remove patch
@@ -18,842 +18,842 @@
 block discarded – undo
18 18
 class EE_Payment_Processor extends EE_Processor_Base implements ResettableInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Payment_Processor $_instance
23
-     * @access    private
24
-     */
25
-    private static $_instance;
26
-
27
-
28
-    /**
29
-     * @singleton method used to instantiate class object
30
-     * @access    public
31
-     * @return EE_Payment_Processor instance
32
-     */
33
-    public static function instance()
34
-    {
35
-        // check if class object is instantiated
36
-        if (! self::$_instance instanceof EE_Payment_Processor) {
37
-            self::$_instance = new self();
38
-        }
39
-        return self::$_instance;
40
-    }
41
-
42
-
43
-    /**
44
-     * @return EE_Payment_Processor
45
-     */
46
-    public static function reset()
47
-    {
48
-        self::$_instance = null;
49
-        return self::instance();
50
-    }
51
-
52
-
53
-    /**
54
-     *private constructor to prevent direct creation
55
-     *
56
-     * @Constructor
57
-     * @access private
58
-     */
59
-    private function __construct()
60
-    {
61
-        do_action('AHEE__EE_Payment_Processor__construct');
62
-        add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
63
-    }
64
-
65
-
66
-    /**
67
-     * Using the selected gateway, processes the payment for that transaction, and updates the transaction
68
-     * appropriately. Saves the payment that is generated
69
-     *
70
-     * @param EE_Payment_Method    $payment_method
71
-     * @param EE_Transaction       $transaction
72
-     * @param float                $amount       if only part of the transaction is to be paid for, how much.
73
-     *                                           Leave null if payment is for the full amount owing
74
-     * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
75
-     *                                           Receive_form_submission() should have
76
-     *                                           already been called on the billing form
77
-     *                                           (ie, its inputs should have their normalized values set).
78
-     * @param string               $return_url   string used mostly by offsite gateways to specify
79
-     *                                           where to go AFTER the offsite gateway
80
-     * @param string               $method       like 'CART', indicates who the client who called this was
81
-     * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
82
-     * @param boolean              $update_txn   whether or not to call
83
-     *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
84
-     * @param string               $cancel_url   URL to return to if off-site payments are cancelled
85
-     * @return EE_Payment
86
-     * @throws EE_Error
87
-     * @throws InvalidArgumentException
88
-     * @throws ReflectionException
89
-     * @throws RuntimeException
90
-     * @throws InvalidDataTypeException
91
-     * @throws InvalidInterfaceException
92
-     */
93
-    public function process_payment(
94
-        EE_Payment_Method $payment_method,
95
-        EE_Transaction $transaction,
96
-        $amount = null,
97
-        $billing_form = null,
98
-        $return_url = null,
99
-        $method = 'CART',
100
-        $by_admin = false,
101
-        $update_txn = true,
102
-        $cancel_url = ''
103
-    ) {
104
-        if ((float) $amount < 0) {
105
-            throw new EE_Error(
106
-                sprintf(
107
-                    __(
108
-                        'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
109
-                        'event_espresso'
110
-                    ),
111
-                    $amount,
112
-                    $transaction->ID()
113
-                )
114
-            );
115
-        }
116
-        // verify payment method
117
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
118
-            $payment_method,
119
-            true
120
-        );
121
-        // verify transaction
122
-        EEM_Transaction::instance()->ensure_is_obj($transaction);
123
-        $transaction->set_payment_method_ID($payment_method->ID());
124
-        // verify payment method type
125
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
126
-            $payment = $payment_method->type_obj()->process_payment(
127
-                $transaction,
128
-                min($amount, $transaction->remaining()), // make sure we don't overcharge
129
-                $billing_form,
130
-                $return_url,
131
-                add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
132
-                $method,
133
-                $by_admin
134
-            );
135
-            // check if payment method uses an off-site gateway
136
-            if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
137
-                // don't process payments for off-site gateways yet because no payment has occurred yet
138
-                $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
139
-            }
140
-            return $payment;
141
-        }
142
-        EE_Error::add_error(
143
-            sprintf(
144
-                __(
145
-                    'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
146
-                    'event_espresso'
147
-                ),
148
-                '<br/>',
149
-                EE_Registry::instance()->CFG->organization->get_pretty('email')
150
-            ),
151
-            __FILE__,
152
-            __FUNCTION__,
153
-            __LINE__
154
-        );
155
-        return null;
156
-    }
157
-
158
-
159
-    /**
160
-     * @param EE_Transaction|int $transaction
161
-     * @param EE_Payment_Method  $payment_method
162
-     * @return string
163
-     * @throws EE_Error
164
-     * @throws InvalidArgumentException
165
-     * @throws InvalidDataTypeException
166
-     * @throws InvalidInterfaceException
167
-     */
168
-    public function get_ipn_url_for_payment_method($transaction, $payment_method)
169
-    {
170
-        /** @type \EE_Transaction $transaction */
171
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
172
-        $primary_reg = $transaction->primary_registration();
173
-        if (! $primary_reg instanceof EE_Registration) {
174
-            throw new EE_Error(
175
-                sprintf(
176
-                    __(
177
-                        'Cannot get IPN URL for transaction with ID %d because it has no primary registration',
178
-                        'event_espresso'
179
-                    ),
180
-                    $transaction->ID()
181
-                )
182
-            );
183
-        }
184
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
185
-            $payment_method,
186
-            true
187
-        );
188
-        $url = add_query_arg(
189
-            array(
190
-                'e_reg_url_link'    => $primary_reg->reg_url_link(),
191
-                'ee_payment_method' => $payment_method->slug(),
192
-            ),
193
-            EE_Registry::instance()->CFG->core->txn_page_url()
194
-        );
195
-        return $url;
196
-    }
197
-
198
-
199
-    /**
200
-     * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
201
-     * we can easily find what registration the IPN is for and what payment method.
202
-     * However, if not, we'll give all payment methods a chance to claim it and process it.
203
-     * If a payment is found for the IPN info, it is saved.
204
-     *
205
-     * @param array              $_req_data            eg $_REQUEST
206
-     * @param EE_Transaction|int $transaction          optional (or a transactions id)
207
-     * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
208
-     * @param boolean            $update_txn           whether or not to call
209
-     *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
210
-     * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
211
-     *                                                 or is processed manually ( false like Mijireh )
212
-     * @throws EE_Error
213
-     * @throws Exception
214
-     * @return EE_Payment
215
-     * @throws \RuntimeException
216
-     * @throws \ReflectionException
217
-     * @throws \InvalidArgumentException
218
-     * @throws InvalidInterfaceException
219
-     * @throws InvalidDataTypeException
220
-     */
221
-    public function process_ipn(
222
-        $_req_data,
223
-        $transaction = null,
224
-        $payment_method = null,
225
-        $update_txn = true,
226
-        $separate_IPN_request = true
227
-    ) {
228
-        EE_Registry::instance()->load_model('Change_Log');
229
-        $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data);
230
-        EE_Processor_Base::set_IPN($separate_IPN_request);
231
-        $obj_for_log = null;
232
-        if ($transaction instanceof EE_Transaction) {
233
-            $obj_for_log = $transaction;
234
-            if ($payment_method instanceof EE_Payment_Method) {
235
-                $obj_for_log = EEM_Payment::instance()->get_one(
236
-                    array(
237
-                        array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
238
-                        'order_by' => array('PAY_timestamp' => 'desc'),
239
-                    )
240
-                );
241
-            }
242
-        } elseif ($payment_method instanceof EE_Payment) {
243
-            $obj_for_log = $payment_method;
244
-        }
245
-        $log = EEM_Change_Log::instance()->log(
246
-            EEM_Change_Log::type_gateway,
247
-            array('IPN data received' => $_req_data),
248
-            $obj_for_log
249
-        );
250
-        try {
251
-            /**
252
-             * @var EE_Payment $payment
253
-             */
254
-            $payment = null;
255
-            if ($transaction && $payment_method) {
256
-                /** @type EE_Transaction $transaction */
257
-                $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
258
-                /** @type EE_Payment_Method $payment_method */
259
-                $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
260
-                if ($payment_method->type_obj() instanceof EE_PMT_Base) {
261
-                    try {
262
-                        $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
263
-                        $log->set_object($payment);
264
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
265
-                        EEM_Change_Log::instance()->log(
266
-                            EEM_Change_Log::type_gateway,
267
-                            array(
268
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
269
-                                'current_url' => EEH_URL::current_url(),
270
-                                'payment'     => $e->getPaymentProperties(),
271
-                                'IPN_data'    => $e->getIpnData(),
272
-                            ),
273
-                            $obj_for_log
274
-                        );
275
-                        return $e->getPayment();
276
-                    }
277
-                } else {
278
-                    // not a payment
279
-                    EE_Error::add_error(
280
-                        sprintf(
281
-                            __(
282
-                                'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.',
283
-                                'event_espresso'
284
-                            ),
285
-                            '<br/>',
286
-                            EE_Registry::instance()->CFG->organization->get_pretty('email')
287
-                        ),
288
-                        __FILE__,
289
-                        __FUNCTION__,
290
-                        __LINE__
291
-                    );
292
-                }
293
-            } else {
294
-                // that's actually pretty ok. The IPN just wasn't able
295
-                // to identify which transaction or payment method this was for
296
-                // give all active payment methods a chance to claim it
297
-                $active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
298
-                foreach ($active_payment_methods as $active_payment_method) {
299
-                    try {
300
-                        $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
301
-                        $payment_method = $active_payment_method;
302
-                        EEM_Change_Log::instance()->log(
303
-                            EEM_Change_Log::type_gateway,
304
-                            array('IPN data' => $_req_data),
305
-                            $payment
306
-                        );
307
-                        break;
308
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
309
-                        EEM_Change_Log::instance()->log(
310
-                            EEM_Change_Log::type_gateway,
311
-                            array(
312
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
313
-                                'current_url' => EEH_URL::current_url(),
314
-                                'payment'     => $e->getPaymentProperties(),
315
-                                'IPN_data'    => $e->getIpnData(),
316
-                            ),
317
-                            $obj_for_log
318
-                        );
319
-                        return $e->getPayment();
320
-                    } catch (EE_Error $e) {
321
-                        // that's fine- it apparently couldn't handle the IPN
322
-                    }
323
-                }
324
-            }
325
-            // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
326
-            if ($payment instanceof EE_Payment) {
327
-                $payment->save();
328
-                //  update the TXN
329
-                $this->update_txn_based_on_payment(
330
-                    $transaction,
331
-                    $payment,
332
-                    $update_txn,
333
-                    $separate_IPN_request
334
-                );
335
-            } else {
336
-                // we couldn't find the payment for this IPN... let's try and log at least SOMETHING
337
-                if ($payment_method) {
338
-                    EEM_Change_Log::instance()->log(
339
-                        EEM_Change_Log::type_gateway,
340
-                        array('IPN data' => $_req_data),
341
-                        $payment_method
342
-                    );
343
-                } elseif ($transaction) {
344
-                    EEM_Change_Log::instance()->log(
345
-                        EEM_Change_Log::type_gateway,
346
-                        array('IPN data' => $_req_data),
347
-                        $transaction
348
-                    );
349
-                }
350
-            }
351
-            return $payment;
352
-        } catch (EE_Error $e) {
353
-            do_action(
354
-                'AHEE__log',
355
-                __FILE__,
356
-                __FUNCTION__,
357
-                sprintf(
358
-                    __(
359
-                        'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"',
360
-                        'event_espresso'
361
-                    ),
362
-                    print_r($transaction, true),
363
-                    print_r($_req_data, true),
364
-                    $e->getMessage()
365
-                )
366
-            );
367
-            throw $e;
368
-        }
369
-    }
370
-
371
-
372
-    /**
373
-     * Removes any non-printable illegal characters from the input,
374
-     * which might cause a raucous when trying to insert into the database
375
-     *
376
-     * @param  array $request_data
377
-     * @return array
378
-     */
379
-    protected function _remove_unusable_characters_from_array(array $request_data)
380
-    {
381
-        $return_data = array();
382
-        foreach ($request_data as $key => $value) {
383
-            $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters(
384
-                $value
385
-            );
386
-        }
387
-        return $return_data;
388
-    }
389
-
390
-
391
-    /**
392
-     * Removes any non-printable illegal characters from the input,
393
-     * which might cause a raucous when trying to insert into the database
394
-     *
395
-     * @param string $request_data
396
-     * @return string
397
-     */
398
-    protected function _remove_unusable_characters($request_data)
399
-    {
400
-        return preg_replace('/[^[:print:]]/', '', $request_data);
401
-    }
402
-
403
-
404
-    /**
405
-     * Should be called just before displaying the payment attempt results to the user,
406
-     * when the payment attempt has finished. Some payment methods may have special
407
-     * logic to perform here. For example, if process_payment() happens on a special request
408
-     * and then the user is redirected to a page that displays the payment's status, this
409
-     * should be called while loading the page that displays the payment's status. If the user is
410
-     * sent to an offsite payment provider, this should be called upon returning from that offsite payment
411
-     * provider.
412
-     *
413
-     * @param EE_Transaction|int $transaction
414
-     * @param bool               $update_txn whether or not to call
415
-     *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
416
-     * @return EE_Payment
417
-     * @throws EE_Error
418
-     * @throws InvalidArgumentException
419
-     * @throws ReflectionException
420
-     * @throws RuntimeException
421
-     * @throws InvalidDataTypeException
422
-     * @throws InvalidInterfaceException
423
-     * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
424
-     *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
425
-     */
426
-    public function finalize_payment_for($transaction, $update_txn = true)
427
-    {
428
-        /** @var $transaction EE_Transaction */
429
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
430
-        $last_payment_method = $transaction->payment_method();
431
-        if ($last_payment_method instanceof EE_Payment_Method) {
432
-            $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
433
-            $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
434
-            return $payment;
435
-        }
436
-        return null;
437
-    }
438
-
439
-
440
-    /**
441
-     * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
442
-     *
443
-     * @param EE_Payment_Method $payment_method
444
-     * @param EE_Payment        $payment_to_refund
445
-     * @param array             $refund_info
446
-     * @return EE_Payment
447
-     * @throws EE_Error
448
-     * @throws InvalidArgumentException
449
-     * @throws ReflectionException
450
-     * @throws RuntimeException
451
-     * @throws InvalidDataTypeException
452
-     * @throws InvalidInterfaceException
453
-     */
454
-    public function process_refund(
455
-        EE_Payment_Method $payment_method,
456
-        EE_Payment $payment_to_refund,
457
-        array $refund_info = array()
458
-    ) {
459
-        if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
460
-            $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
461
-            $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
462
-        }
463
-        return $payment_to_refund;
464
-    }
465
-
466
-
467
-    /**
468
-     * This should be called each time there may have been an update to a
469
-     * payment on a transaction (ie, we asked for a payment to process a
470
-     * payment for a transaction, or we told a payment method about an IPN, or
471
-     * we told a payment method to
472
-     * "finalize_payment_for" (a transaction), or we told a payment method to
473
-     * process a refund. This should handle firing the correct hooks to
474
-     * indicate
475
-     * what exactly happened and updating the transaction appropriately). This
476
-     * could be integrated directly into EE_Transaction upon save, but we want
477
-     * this logic to be separate from 'normal' plain-jane saving and updating
478
-     * of transactions and payments, and to be tied to payment processing.
479
-     * Note: this method DOES NOT save the payment passed into it. It is the responsibility
480
-     * of previous code to decide whether or not to save (because the payment passed into
481
-     * this method might be a temporary, never-to-be-saved payment from an offline gateway,
482
-     * in which case we only want that payment object for some temporary usage during this request,
483
-     * but we don't want it to be saved).
484
-     *
485
-     * @param EE_Transaction|int $transaction
486
-     * @param EE_Payment         $payment
487
-     * @param boolean            $update_txn
488
-     *                        whether or not to call
489
-     *                        EE_Transaction_Processor::
490
-     *                        update_transaction_and_registrations_after_checkout_or_payment()
491
-     *                        (you can save 1 DB query if you know you're going
492
-     *                        to save it later instead)
493
-     * @param bool               $IPN
494
-     *                        if processing IPNs or other similar payment
495
-     *                        related activities that occur in alternate
496
-     *                        requests than the main one that is processing the
497
-     *                        TXN, then set this to true to check whether the
498
-     *                        TXN is locked before updating
499
-     * @throws EE_Error
500
-     * @throws InvalidArgumentException
501
-     * @throws ReflectionException
502
-     * @throws RuntimeException
503
-     * @throws InvalidDataTypeException
504
-     * @throws InvalidInterfaceException
505
-     */
506
-    public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
507
-    {
508
-        $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
509
-        /** @type EE_Transaction $transaction */
510
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
511
-        // can we freely update the TXN at this moment?
512
-        if ($IPN && $transaction->is_locked()) {
513
-            // don't update the transaction at this exact moment
514
-            // because the TXN is active in another request
515
-            EE_Cron_Tasks::schedule_update_transaction_with_payment(
516
-                time(),
517
-                $transaction->ID(),
518
-                $payment->ID()
519
-            );
520
-        } else {
521
-            // verify payment and that it has been saved
522
-            if ($payment instanceof EE_Payment && $payment->ID()) {
523
-                if ($payment->payment_method() instanceof EE_Payment_Method
524
-                    && $payment->payment_method()->type_obj() instanceof EE_PMT_Base
525
-                ) {
526
-                    $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
527
-                    // update TXN registrations with payment info
528
-                    $this->process_registration_payments($transaction, $payment);
529
-                }
530
-                $do_action = $payment->just_approved()
531
-                    ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
532
-                    : $do_action;
533
-            } else {
534
-                // send out notifications
535
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
536
-                $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
537
-            }
538
-            if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
539
-                /** @type EE_Transaction_Payments $transaction_payments */
540
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
541
-                // set new value for total paid
542
-                $transaction_payments->calculate_total_payments_and_update_status($transaction);
543
-                // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
544
-                if ($update_txn) {
545
-                    $this->_post_payment_processing($transaction, $payment, $IPN);
546
-                }
547
-            }
548
-            // granular hook for others to use.
549
-            do_action($do_action, $transaction, $payment);
550
-            do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
551
-            // global hook for others to use.
552
-            do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
553
-        }
554
-    }
555
-
556
-
557
-    /**
558
-     * update registrations REG_paid field after successful payment and link registrations with payment
559
-     *
560
-     * @param EE_Transaction    $transaction
561
-     * @param EE_Payment        $payment
562
-     * @param EE_Registration[] $registrations
563
-     * @throws EE_Error
564
-     * @throws InvalidArgumentException
565
-     * @throws RuntimeException
566
-     * @throws InvalidDataTypeException
567
-     * @throws InvalidInterfaceException
568
-     */
569
-    public function process_registration_payments(
570
-        EE_Transaction $transaction,
571
-        EE_Payment $payment,
572
-        array $registrations = array()
573
-    ) {
574
-        // only process if payment was successful
575
-        if ($payment->status() !== EEM_Payment::status_id_approved) {
576
-            return;
577
-        }
578
-        // EEM_Registration::instance()->show_next_x_db_queries();
579
-        if (empty($registrations)) {
580
-            // find registrations with monies owing that can receive a payment
581
-            $registrations = $transaction->registrations(
582
-                array(
583
-                    array(
584
-                        // only these reg statuses can receive payments
585
-                        'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
586
-                        'REG_final_price'  => array('!=', 0),
587
-                        'REG_final_price*' => array('!=', 'REG_paid', true),
588
-                    ),
589
-                )
590
-            );
591
-        }
592
-        // still nothing ??!??
593
-        if (empty($registrations)) {
594
-            return;
595
-        }
596
-        // todo: break out the following logic into a separate strategy class
597
-        // todo: named something like "Sequential_Reg_Payment_Strategy"
598
-        // todo: which would apply payments using the capitalist "first come first paid" approach
599
-        // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
600
-        // todo: which would be the socialist "everybody gets a piece of pie" approach,
601
-        // todo: which would be better for deposits, where you want a bit of the payment applied to each registration
602
-        $refund = $payment->is_a_refund();
603
-        // how much is available to apply to registrations?
604
-        $available_payment_amount = abs($payment->amount());
605
-        foreach ($registrations as $registration) {
606
-            if ($registration instanceof EE_Registration) {
607
-                // nothing left?
608
-                if ($available_payment_amount <= 0) {
609
-                    break;
610
-                }
611
-                if ($refund) {
612
-                    $available_payment_amount = $this->process_registration_refund(
613
-                        $registration,
614
-                        $payment,
615
-                        $available_payment_amount
616
-                    );
617
-                } else {
618
-                    $available_payment_amount = $this->process_registration_payment(
619
-                        $registration,
620
-                        $payment,
621
-                        $available_payment_amount
622
-                    );
623
-                }
624
-            }
625
-        }
626
-        if ($available_payment_amount > 0
627
-            && apply_filters(
628
-                'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications',
629
-                false
630
-            )) {
631
-            EE_Error::add_attention(
632
-                sprintf(
633
-                    __(
634
-                        'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
635
-                        'event_espresso'
636
-                    ),
637
-                    EEH_Template::format_currency($available_payment_amount),
638
-                    implode(', ', array_keys($registrations)),
639
-                    '<br/>',
640
-                    EEH_Template::format_currency($payment->amount())
641
-                ),
642
-                __FILE__,
643
-                __FUNCTION__,
644
-                __LINE__
645
-            );
646
-        }
647
-    }
648
-
649
-
650
-    /**
651
-     * update registration REG_paid field after successful payment and link registration with payment
652
-     *
653
-     * @param EE_Registration $registration
654
-     * @param EE_Payment      $payment
655
-     * @param float           $available_payment_amount
656
-     * @return float
657
-     * @throws EE_Error
658
-     * @throws InvalidArgumentException
659
-     * @throws RuntimeException
660
-     * @throws InvalidDataTypeException
661
-     * @throws InvalidInterfaceException
662
-     */
663
-    public function process_registration_payment(
664
-        EE_Registration $registration,
665
-        EE_Payment $payment,
666
-        $available_payment_amount = 0.00
667
-    ) {
668
-        $owing = $registration->final_price() - $registration->paid();
669
-        if ($owing > 0) {
670
-            // don't allow payment amount to exceed the available payment amount, OR the amount owing
671
-            $payment_amount = min($available_payment_amount, $owing);
672
-            // update $available_payment_amount
673
-            $available_payment_amount -= $payment_amount;
674
-            // calculate and set new REG_paid
675
-            $registration->set_paid($registration->paid() + $payment_amount);
676
-            // now save it
677
-            $this->_apply_registration_payment($registration, $payment, $payment_amount);
678
-        }
679
-        return $available_payment_amount;
680
-    }
681
-
682
-
683
-    /**
684
-     * update registration REG_paid field after successful payment and link registration with payment
685
-     *
686
-     * @param EE_Registration $registration
687
-     * @param EE_Payment      $payment
688
-     * @param float           $payment_amount
689
-     * @return void
690
-     * @throws EE_Error
691
-     * @throws InvalidArgumentException
692
-     * @throws InvalidDataTypeException
693
-     * @throws InvalidInterfaceException
694
-     */
695
-    protected function _apply_registration_payment(
696
-        EE_Registration $registration,
697
-        EE_Payment $payment,
698
-        $payment_amount = 0.00
699
-    ) {
700
-        // find any existing reg payment records for this registration and payment
701
-        $existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
702
-            array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
703
-        );
704
-        // if existing registration payment exists
705
-        if ($existing_reg_payment instanceof EE_Registration_Payment) {
706
-            // then update that record
707
-            $existing_reg_payment->set_amount($payment_amount);
708
-            $existing_reg_payment->save();
709
-        } else {
710
-            // or add new relation between registration and payment and set amount
711
-            $registration->_add_relation_to(
712
-                $payment,
713
-                'Payment',
714
-                array('RPY_amount' => $payment_amount)
715
-            );
716
-            // make it stick
717
-            $registration->save();
718
-        }
719
-    }
720
-
721
-
722
-    /**
723
-     * update registration REG_paid field after refund and link registration with payment
724
-     *
725
-     * @param EE_Registration $registration
726
-     * @param EE_Payment      $payment
727
-     * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
728
-     * @return float
729
-     * @throws EE_Error
730
-     * @throws InvalidArgumentException
731
-     * @throws RuntimeException
732
-     * @throws InvalidDataTypeException
733
-     * @throws InvalidInterfaceException
734
-     */
735
-    public function process_registration_refund(
736
-        EE_Registration $registration,
737
-        EE_Payment $payment,
738
-        $available_refund_amount = 0.00
739
-    ) {
740
-        // EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
741
-        if ($registration->paid() > 0) {
742
-            // ensure $available_refund_amount is NOT negative
743
-            $available_refund_amount = (float) abs($available_refund_amount);
744
-            // don't allow refund amount to exceed the available payment amount, OR the amount paid
745
-            $refund_amount = min($available_refund_amount, (float) $registration->paid());
746
-            // update $available_payment_amount
747
-            $available_refund_amount -= $refund_amount;
748
-            // calculate and set new REG_paid
749
-            $registration->set_paid($registration->paid() - $refund_amount);
750
-            // convert payment amount back to a negative value for storage in the db
751
-            $refund_amount = (float) abs($refund_amount) * -1;
752
-            // now save it
753
-            $this->_apply_registration_payment($registration, $payment, $refund_amount);
754
-        }
755
-        return $available_refund_amount;
756
-    }
757
-
758
-
759
-    /**
760
-     * Process payments and transaction after payment process completed.
761
-     * ultimately this will send the TXN and payment details off so that notifications can be sent out.
762
-     * if this request happens to be processing an IPN,
763
-     * then we will also set the Payment Options Reg Step to completed,
764
-     * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
765
-     *
766
-     * @param EE_Transaction $transaction
767
-     * @param EE_Payment     $payment
768
-     * @param bool           $IPN
769
-     * @throws EE_Error
770
-     * @throws InvalidArgumentException
771
-     * @throws ReflectionException
772
-     * @throws RuntimeException
773
-     * @throws InvalidDataTypeException
774
-     * @throws InvalidInterfaceException
775
-     */
776
-    protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
777
-    {
778
-        /** @type EE_Transaction_Processor $transaction_processor */
779
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
780
-        // is the Payment Options Reg Step completed ?
781
-        $payment_options_step_completed = $transaction->reg_step_completed('payment_options');
782
-        // if the Payment Options Reg Step is completed...
783
-        $revisit = $payment_options_step_completed === true;
784
-        // then this is kinda sorta a revisit with regards to payments at least
785
-        $transaction_processor->set_revisit($revisit);
786
-        // if this is an IPN, let's consider the Payment Options Reg Step completed if not already
787
-        if ($IPN
788
-            && $payment_options_step_completed !== true
789
-            && ($payment->is_approved() || $payment->is_pending())
790
-        ) {
791
-            $payment_options_step_completed = $transaction->set_reg_step_completed(
792
-                'payment_options'
793
-            );
794
-        }
795
-        // maybe update status, but don't save transaction just yet
796
-        $transaction->update_status_based_on_total_paid(false);
797
-        // check if 'finalize_registration' step has been completed...
798
-        $finalized = $transaction->reg_step_completed('finalize_registration');
799
-        //  if this is an IPN and the final step has not been initiated
800
-        if ($IPN && $payment_options_step_completed && $finalized === false) {
801
-            // and if it hasn't already been set as being started...
802
-            $finalized = $transaction->set_reg_step_initiated('finalize_registration');
803
-        }
804
-        $transaction->save();
805
-        // because the above will return false if the final step was not fully completed, we need to check again...
806
-        if ($IPN && $finalized !== false) {
807
-            // and if we are all good to go, then send out notifications
808
-            add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
809
-            // ok, now process the transaction according to the payment
810
-            $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
811
-                $transaction,
812
-                $payment
813
-            );
814
-        }
815
-        // DEBUG LOG
816
-        $payment_method = $payment->payment_method();
817
-        if ($payment_method instanceof EE_Payment_Method) {
818
-            $payment_method_type_obj = $payment_method->type_obj();
819
-            if ($payment_method_type_obj instanceof EE_PMT_Base) {
820
-                $gateway = $payment_method_type_obj->get_gateway();
821
-                if ($gateway instanceof EE_Gateway) {
822
-                    $gateway->log(
823
-                        array(
824
-                            'message'               => (string) __('Post Payment Transaction Details', 'event_espresso'),
825
-                            'transaction'           => $transaction->model_field_array(),
826
-                            'finalized'             => $finalized,
827
-                            'IPN'                   => $IPN,
828
-                            'deliver_notifications' => has_filter(
829
-                                'FHEE__EED_Messages___maybe_registration__deliver_notifications'
830
-                            ),
831
-                        ),
832
-                        $payment
833
-                    );
834
-                }
835
-            }
836
-        }
837
-    }
838
-
839
-
840
-    /**
841
-     * Force posts to PayPal to use TLS v1.2. See:
842
-     * https://core.trac.wordpress.org/ticket/36320
843
-     * https://core.trac.wordpress.org/ticket/34924#comment:15
844
-     * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
845
-     * This will affect PayPal standard, pro, express, and Payflow.
846
-     *
847
-     * @param $handle
848
-     * @param $r
849
-     * @param $url
850
-     */
851
-    public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
852
-    {
853
-        if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) {
854
-            // Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
855
-            // instead of the constant because it might not be defined
856
-            curl_setopt($handle, CURLOPT_SSLVERSION, 6);
857
-        }
858
-    }
21
+	/**
22
+	 * @var EE_Payment_Processor $_instance
23
+	 * @access    private
24
+	 */
25
+	private static $_instance;
26
+
27
+
28
+	/**
29
+	 * @singleton method used to instantiate class object
30
+	 * @access    public
31
+	 * @return EE_Payment_Processor instance
32
+	 */
33
+	public static function instance()
34
+	{
35
+		// check if class object is instantiated
36
+		if (! self::$_instance instanceof EE_Payment_Processor) {
37
+			self::$_instance = new self();
38
+		}
39
+		return self::$_instance;
40
+	}
41
+
42
+
43
+	/**
44
+	 * @return EE_Payment_Processor
45
+	 */
46
+	public static function reset()
47
+	{
48
+		self::$_instance = null;
49
+		return self::instance();
50
+	}
51
+
52
+
53
+	/**
54
+	 *private constructor to prevent direct creation
55
+	 *
56
+	 * @Constructor
57
+	 * @access private
58
+	 */
59
+	private function __construct()
60
+	{
61
+		do_action('AHEE__EE_Payment_Processor__construct');
62
+		add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
63
+	}
64
+
65
+
66
+	/**
67
+	 * Using the selected gateway, processes the payment for that transaction, and updates the transaction
68
+	 * appropriately. Saves the payment that is generated
69
+	 *
70
+	 * @param EE_Payment_Method    $payment_method
71
+	 * @param EE_Transaction       $transaction
72
+	 * @param float                $amount       if only part of the transaction is to be paid for, how much.
73
+	 *                                           Leave null if payment is for the full amount owing
74
+	 * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
75
+	 *                                           Receive_form_submission() should have
76
+	 *                                           already been called on the billing form
77
+	 *                                           (ie, its inputs should have their normalized values set).
78
+	 * @param string               $return_url   string used mostly by offsite gateways to specify
79
+	 *                                           where to go AFTER the offsite gateway
80
+	 * @param string               $method       like 'CART', indicates who the client who called this was
81
+	 * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
82
+	 * @param boolean              $update_txn   whether or not to call
83
+	 *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
84
+	 * @param string               $cancel_url   URL to return to if off-site payments are cancelled
85
+	 * @return EE_Payment
86
+	 * @throws EE_Error
87
+	 * @throws InvalidArgumentException
88
+	 * @throws ReflectionException
89
+	 * @throws RuntimeException
90
+	 * @throws InvalidDataTypeException
91
+	 * @throws InvalidInterfaceException
92
+	 */
93
+	public function process_payment(
94
+		EE_Payment_Method $payment_method,
95
+		EE_Transaction $transaction,
96
+		$amount = null,
97
+		$billing_form = null,
98
+		$return_url = null,
99
+		$method = 'CART',
100
+		$by_admin = false,
101
+		$update_txn = true,
102
+		$cancel_url = ''
103
+	) {
104
+		if ((float) $amount < 0) {
105
+			throw new EE_Error(
106
+				sprintf(
107
+					__(
108
+						'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
109
+						'event_espresso'
110
+					),
111
+					$amount,
112
+					$transaction->ID()
113
+				)
114
+			);
115
+		}
116
+		// verify payment method
117
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
118
+			$payment_method,
119
+			true
120
+		);
121
+		// verify transaction
122
+		EEM_Transaction::instance()->ensure_is_obj($transaction);
123
+		$transaction->set_payment_method_ID($payment_method->ID());
124
+		// verify payment method type
125
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
126
+			$payment = $payment_method->type_obj()->process_payment(
127
+				$transaction,
128
+				min($amount, $transaction->remaining()), // make sure we don't overcharge
129
+				$billing_form,
130
+				$return_url,
131
+				add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
132
+				$method,
133
+				$by_admin
134
+			);
135
+			// check if payment method uses an off-site gateway
136
+			if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
137
+				// don't process payments for off-site gateways yet because no payment has occurred yet
138
+				$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
139
+			}
140
+			return $payment;
141
+		}
142
+		EE_Error::add_error(
143
+			sprintf(
144
+				__(
145
+					'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
146
+					'event_espresso'
147
+				),
148
+				'<br/>',
149
+				EE_Registry::instance()->CFG->organization->get_pretty('email')
150
+			),
151
+			__FILE__,
152
+			__FUNCTION__,
153
+			__LINE__
154
+		);
155
+		return null;
156
+	}
157
+
158
+
159
+	/**
160
+	 * @param EE_Transaction|int $transaction
161
+	 * @param EE_Payment_Method  $payment_method
162
+	 * @return string
163
+	 * @throws EE_Error
164
+	 * @throws InvalidArgumentException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws InvalidInterfaceException
167
+	 */
168
+	public function get_ipn_url_for_payment_method($transaction, $payment_method)
169
+	{
170
+		/** @type \EE_Transaction $transaction */
171
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
172
+		$primary_reg = $transaction->primary_registration();
173
+		if (! $primary_reg instanceof EE_Registration) {
174
+			throw new EE_Error(
175
+				sprintf(
176
+					__(
177
+						'Cannot get IPN URL for transaction with ID %d because it has no primary registration',
178
+						'event_espresso'
179
+					),
180
+					$transaction->ID()
181
+				)
182
+			);
183
+		}
184
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
185
+			$payment_method,
186
+			true
187
+		);
188
+		$url = add_query_arg(
189
+			array(
190
+				'e_reg_url_link'    => $primary_reg->reg_url_link(),
191
+				'ee_payment_method' => $payment_method->slug(),
192
+			),
193
+			EE_Registry::instance()->CFG->core->txn_page_url()
194
+		);
195
+		return $url;
196
+	}
197
+
198
+
199
+	/**
200
+	 * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
201
+	 * we can easily find what registration the IPN is for and what payment method.
202
+	 * However, if not, we'll give all payment methods a chance to claim it and process it.
203
+	 * If a payment is found for the IPN info, it is saved.
204
+	 *
205
+	 * @param array              $_req_data            eg $_REQUEST
206
+	 * @param EE_Transaction|int $transaction          optional (or a transactions id)
207
+	 * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
208
+	 * @param boolean            $update_txn           whether or not to call
209
+	 *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
210
+	 * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
211
+	 *                                                 or is processed manually ( false like Mijireh )
212
+	 * @throws EE_Error
213
+	 * @throws Exception
214
+	 * @return EE_Payment
215
+	 * @throws \RuntimeException
216
+	 * @throws \ReflectionException
217
+	 * @throws \InvalidArgumentException
218
+	 * @throws InvalidInterfaceException
219
+	 * @throws InvalidDataTypeException
220
+	 */
221
+	public function process_ipn(
222
+		$_req_data,
223
+		$transaction = null,
224
+		$payment_method = null,
225
+		$update_txn = true,
226
+		$separate_IPN_request = true
227
+	) {
228
+		EE_Registry::instance()->load_model('Change_Log');
229
+		$_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data);
230
+		EE_Processor_Base::set_IPN($separate_IPN_request);
231
+		$obj_for_log = null;
232
+		if ($transaction instanceof EE_Transaction) {
233
+			$obj_for_log = $transaction;
234
+			if ($payment_method instanceof EE_Payment_Method) {
235
+				$obj_for_log = EEM_Payment::instance()->get_one(
236
+					array(
237
+						array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
238
+						'order_by' => array('PAY_timestamp' => 'desc'),
239
+					)
240
+				);
241
+			}
242
+		} elseif ($payment_method instanceof EE_Payment) {
243
+			$obj_for_log = $payment_method;
244
+		}
245
+		$log = EEM_Change_Log::instance()->log(
246
+			EEM_Change_Log::type_gateway,
247
+			array('IPN data received' => $_req_data),
248
+			$obj_for_log
249
+		);
250
+		try {
251
+			/**
252
+			 * @var EE_Payment $payment
253
+			 */
254
+			$payment = null;
255
+			if ($transaction && $payment_method) {
256
+				/** @type EE_Transaction $transaction */
257
+				$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
258
+				/** @type EE_Payment_Method $payment_method */
259
+				$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
260
+				if ($payment_method->type_obj() instanceof EE_PMT_Base) {
261
+					try {
262
+						$payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
263
+						$log->set_object($payment);
264
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
265
+						EEM_Change_Log::instance()->log(
266
+							EEM_Change_Log::type_gateway,
267
+							array(
268
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
269
+								'current_url' => EEH_URL::current_url(),
270
+								'payment'     => $e->getPaymentProperties(),
271
+								'IPN_data'    => $e->getIpnData(),
272
+							),
273
+							$obj_for_log
274
+						);
275
+						return $e->getPayment();
276
+					}
277
+				} else {
278
+					// not a payment
279
+					EE_Error::add_error(
280
+						sprintf(
281
+							__(
282
+								'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.',
283
+								'event_espresso'
284
+							),
285
+							'<br/>',
286
+							EE_Registry::instance()->CFG->organization->get_pretty('email')
287
+						),
288
+						__FILE__,
289
+						__FUNCTION__,
290
+						__LINE__
291
+					);
292
+				}
293
+			} else {
294
+				// that's actually pretty ok. The IPN just wasn't able
295
+				// to identify which transaction or payment method this was for
296
+				// give all active payment methods a chance to claim it
297
+				$active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
298
+				foreach ($active_payment_methods as $active_payment_method) {
299
+					try {
300
+						$payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
301
+						$payment_method = $active_payment_method;
302
+						EEM_Change_Log::instance()->log(
303
+							EEM_Change_Log::type_gateway,
304
+							array('IPN data' => $_req_data),
305
+							$payment
306
+						);
307
+						break;
308
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
309
+						EEM_Change_Log::instance()->log(
310
+							EEM_Change_Log::type_gateway,
311
+							array(
312
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
313
+								'current_url' => EEH_URL::current_url(),
314
+								'payment'     => $e->getPaymentProperties(),
315
+								'IPN_data'    => $e->getIpnData(),
316
+							),
317
+							$obj_for_log
318
+						);
319
+						return $e->getPayment();
320
+					} catch (EE_Error $e) {
321
+						// that's fine- it apparently couldn't handle the IPN
322
+					}
323
+				}
324
+			}
325
+			// EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
326
+			if ($payment instanceof EE_Payment) {
327
+				$payment->save();
328
+				//  update the TXN
329
+				$this->update_txn_based_on_payment(
330
+					$transaction,
331
+					$payment,
332
+					$update_txn,
333
+					$separate_IPN_request
334
+				);
335
+			} else {
336
+				// we couldn't find the payment for this IPN... let's try and log at least SOMETHING
337
+				if ($payment_method) {
338
+					EEM_Change_Log::instance()->log(
339
+						EEM_Change_Log::type_gateway,
340
+						array('IPN data' => $_req_data),
341
+						$payment_method
342
+					);
343
+				} elseif ($transaction) {
344
+					EEM_Change_Log::instance()->log(
345
+						EEM_Change_Log::type_gateway,
346
+						array('IPN data' => $_req_data),
347
+						$transaction
348
+					);
349
+				}
350
+			}
351
+			return $payment;
352
+		} catch (EE_Error $e) {
353
+			do_action(
354
+				'AHEE__log',
355
+				__FILE__,
356
+				__FUNCTION__,
357
+				sprintf(
358
+					__(
359
+						'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"',
360
+						'event_espresso'
361
+					),
362
+					print_r($transaction, true),
363
+					print_r($_req_data, true),
364
+					$e->getMessage()
365
+				)
366
+			);
367
+			throw $e;
368
+		}
369
+	}
370
+
371
+
372
+	/**
373
+	 * Removes any non-printable illegal characters from the input,
374
+	 * which might cause a raucous when trying to insert into the database
375
+	 *
376
+	 * @param  array $request_data
377
+	 * @return array
378
+	 */
379
+	protected function _remove_unusable_characters_from_array(array $request_data)
380
+	{
381
+		$return_data = array();
382
+		foreach ($request_data as $key => $value) {
383
+			$return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters(
384
+				$value
385
+			);
386
+		}
387
+		return $return_data;
388
+	}
389
+
390
+
391
+	/**
392
+	 * Removes any non-printable illegal characters from the input,
393
+	 * which might cause a raucous when trying to insert into the database
394
+	 *
395
+	 * @param string $request_data
396
+	 * @return string
397
+	 */
398
+	protected function _remove_unusable_characters($request_data)
399
+	{
400
+		return preg_replace('/[^[:print:]]/', '', $request_data);
401
+	}
402
+
403
+
404
+	/**
405
+	 * Should be called just before displaying the payment attempt results to the user,
406
+	 * when the payment attempt has finished. Some payment methods may have special
407
+	 * logic to perform here. For example, if process_payment() happens on a special request
408
+	 * and then the user is redirected to a page that displays the payment's status, this
409
+	 * should be called while loading the page that displays the payment's status. If the user is
410
+	 * sent to an offsite payment provider, this should be called upon returning from that offsite payment
411
+	 * provider.
412
+	 *
413
+	 * @param EE_Transaction|int $transaction
414
+	 * @param bool               $update_txn whether or not to call
415
+	 *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
416
+	 * @return EE_Payment
417
+	 * @throws EE_Error
418
+	 * @throws InvalidArgumentException
419
+	 * @throws ReflectionException
420
+	 * @throws RuntimeException
421
+	 * @throws InvalidDataTypeException
422
+	 * @throws InvalidInterfaceException
423
+	 * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
424
+	 *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
425
+	 */
426
+	public function finalize_payment_for($transaction, $update_txn = true)
427
+	{
428
+		/** @var $transaction EE_Transaction */
429
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
430
+		$last_payment_method = $transaction->payment_method();
431
+		if ($last_payment_method instanceof EE_Payment_Method) {
432
+			$payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
433
+			$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
434
+			return $payment;
435
+		}
436
+		return null;
437
+	}
438
+
439
+
440
+	/**
441
+	 * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
442
+	 *
443
+	 * @param EE_Payment_Method $payment_method
444
+	 * @param EE_Payment        $payment_to_refund
445
+	 * @param array             $refund_info
446
+	 * @return EE_Payment
447
+	 * @throws EE_Error
448
+	 * @throws InvalidArgumentException
449
+	 * @throws ReflectionException
450
+	 * @throws RuntimeException
451
+	 * @throws InvalidDataTypeException
452
+	 * @throws InvalidInterfaceException
453
+	 */
454
+	public function process_refund(
455
+		EE_Payment_Method $payment_method,
456
+		EE_Payment $payment_to_refund,
457
+		array $refund_info = array()
458
+	) {
459
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
460
+			$payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
461
+			$this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
462
+		}
463
+		return $payment_to_refund;
464
+	}
465
+
466
+
467
+	/**
468
+	 * This should be called each time there may have been an update to a
469
+	 * payment on a transaction (ie, we asked for a payment to process a
470
+	 * payment for a transaction, or we told a payment method about an IPN, or
471
+	 * we told a payment method to
472
+	 * "finalize_payment_for" (a transaction), or we told a payment method to
473
+	 * process a refund. This should handle firing the correct hooks to
474
+	 * indicate
475
+	 * what exactly happened and updating the transaction appropriately). This
476
+	 * could be integrated directly into EE_Transaction upon save, but we want
477
+	 * this logic to be separate from 'normal' plain-jane saving and updating
478
+	 * of transactions and payments, and to be tied to payment processing.
479
+	 * Note: this method DOES NOT save the payment passed into it. It is the responsibility
480
+	 * of previous code to decide whether or not to save (because the payment passed into
481
+	 * this method might be a temporary, never-to-be-saved payment from an offline gateway,
482
+	 * in which case we only want that payment object for some temporary usage during this request,
483
+	 * but we don't want it to be saved).
484
+	 *
485
+	 * @param EE_Transaction|int $transaction
486
+	 * @param EE_Payment         $payment
487
+	 * @param boolean            $update_txn
488
+	 *                        whether or not to call
489
+	 *                        EE_Transaction_Processor::
490
+	 *                        update_transaction_and_registrations_after_checkout_or_payment()
491
+	 *                        (you can save 1 DB query if you know you're going
492
+	 *                        to save it later instead)
493
+	 * @param bool               $IPN
494
+	 *                        if processing IPNs or other similar payment
495
+	 *                        related activities that occur in alternate
496
+	 *                        requests than the main one that is processing the
497
+	 *                        TXN, then set this to true to check whether the
498
+	 *                        TXN is locked before updating
499
+	 * @throws EE_Error
500
+	 * @throws InvalidArgumentException
501
+	 * @throws ReflectionException
502
+	 * @throws RuntimeException
503
+	 * @throws InvalidDataTypeException
504
+	 * @throws InvalidInterfaceException
505
+	 */
506
+	public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
507
+	{
508
+		$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
509
+		/** @type EE_Transaction $transaction */
510
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
511
+		// can we freely update the TXN at this moment?
512
+		if ($IPN && $transaction->is_locked()) {
513
+			// don't update the transaction at this exact moment
514
+			// because the TXN is active in another request
515
+			EE_Cron_Tasks::schedule_update_transaction_with_payment(
516
+				time(),
517
+				$transaction->ID(),
518
+				$payment->ID()
519
+			);
520
+		} else {
521
+			// verify payment and that it has been saved
522
+			if ($payment instanceof EE_Payment && $payment->ID()) {
523
+				if ($payment->payment_method() instanceof EE_Payment_Method
524
+					&& $payment->payment_method()->type_obj() instanceof EE_PMT_Base
525
+				) {
526
+					$payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
527
+					// update TXN registrations with payment info
528
+					$this->process_registration_payments($transaction, $payment);
529
+				}
530
+				$do_action = $payment->just_approved()
531
+					? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
532
+					: $do_action;
533
+			} else {
534
+				// send out notifications
535
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
536
+				$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
537
+			}
538
+			if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
539
+				/** @type EE_Transaction_Payments $transaction_payments */
540
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
541
+				// set new value for total paid
542
+				$transaction_payments->calculate_total_payments_and_update_status($transaction);
543
+				// call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
544
+				if ($update_txn) {
545
+					$this->_post_payment_processing($transaction, $payment, $IPN);
546
+				}
547
+			}
548
+			// granular hook for others to use.
549
+			do_action($do_action, $transaction, $payment);
550
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
551
+			// global hook for others to use.
552
+			do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
553
+		}
554
+	}
555
+
556
+
557
+	/**
558
+	 * update registrations REG_paid field after successful payment and link registrations with payment
559
+	 *
560
+	 * @param EE_Transaction    $transaction
561
+	 * @param EE_Payment        $payment
562
+	 * @param EE_Registration[] $registrations
563
+	 * @throws EE_Error
564
+	 * @throws InvalidArgumentException
565
+	 * @throws RuntimeException
566
+	 * @throws InvalidDataTypeException
567
+	 * @throws InvalidInterfaceException
568
+	 */
569
+	public function process_registration_payments(
570
+		EE_Transaction $transaction,
571
+		EE_Payment $payment,
572
+		array $registrations = array()
573
+	) {
574
+		// only process if payment was successful
575
+		if ($payment->status() !== EEM_Payment::status_id_approved) {
576
+			return;
577
+		}
578
+		// EEM_Registration::instance()->show_next_x_db_queries();
579
+		if (empty($registrations)) {
580
+			// find registrations with monies owing that can receive a payment
581
+			$registrations = $transaction->registrations(
582
+				array(
583
+					array(
584
+						// only these reg statuses can receive payments
585
+						'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
586
+						'REG_final_price'  => array('!=', 0),
587
+						'REG_final_price*' => array('!=', 'REG_paid', true),
588
+					),
589
+				)
590
+			);
591
+		}
592
+		// still nothing ??!??
593
+		if (empty($registrations)) {
594
+			return;
595
+		}
596
+		// todo: break out the following logic into a separate strategy class
597
+		// todo: named something like "Sequential_Reg_Payment_Strategy"
598
+		// todo: which would apply payments using the capitalist "first come first paid" approach
599
+		// todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
600
+		// todo: which would be the socialist "everybody gets a piece of pie" approach,
601
+		// todo: which would be better for deposits, where you want a bit of the payment applied to each registration
602
+		$refund = $payment->is_a_refund();
603
+		// how much is available to apply to registrations?
604
+		$available_payment_amount = abs($payment->amount());
605
+		foreach ($registrations as $registration) {
606
+			if ($registration instanceof EE_Registration) {
607
+				// nothing left?
608
+				if ($available_payment_amount <= 0) {
609
+					break;
610
+				}
611
+				if ($refund) {
612
+					$available_payment_amount = $this->process_registration_refund(
613
+						$registration,
614
+						$payment,
615
+						$available_payment_amount
616
+					);
617
+				} else {
618
+					$available_payment_amount = $this->process_registration_payment(
619
+						$registration,
620
+						$payment,
621
+						$available_payment_amount
622
+					);
623
+				}
624
+			}
625
+		}
626
+		if ($available_payment_amount > 0
627
+			&& apply_filters(
628
+				'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications',
629
+				false
630
+			)) {
631
+			EE_Error::add_attention(
632
+				sprintf(
633
+					__(
634
+						'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
635
+						'event_espresso'
636
+					),
637
+					EEH_Template::format_currency($available_payment_amount),
638
+					implode(', ', array_keys($registrations)),
639
+					'<br/>',
640
+					EEH_Template::format_currency($payment->amount())
641
+				),
642
+				__FILE__,
643
+				__FUNCTION__,
644
+				__LINE__
645
+			);
646
+		}
647
+	}
648
+
649
+
650
+	/**
651
+	 * update registration REG_paid field after successful payment and link registration with payment
652
+	 *
653
+	 * @param EE_Registration $registration
654
+	 * @param EE_Payment      $payment
655
+	 * @param float           $available_payment_amount
656
+	 * @return float
657
+	 * @throws EE_Error
658
+	 * @throws InvalidArgumentException
659
+	 * @throws RuntimeException
660
+	 * @throws InvalidDataTypeException
661
+	 * @throws InvalidInterfaceException
662
+	 */
663
+	public function process_registration_payment(
664
+		EE_Registration $registration,
665
+		EE_Payment $payment,
666
+		$available_payment_amount = 0.00
667
+	) {
668
+		$owing = $registration->final_price() - $registration->paid();
669
+		if ($owing > 0) {
670
+			// don't allow payment amount to exceed the available payment amount, OR the amount owing
671
+			$payment_amount = min($available_payment_amount, $owing);
672
+			// update $available_payment_amount
673
+			$available_payment_amount -= $payment_amount;
674
+			// calculate and set new REG_paid
675
+			$registration->set_paid($registration->paid() + $payment_amount);
676
+			// now save it
677
+			$this->_apply_registration_payment($registration, $payment, $payment_amount);
678
+		}
679
+		return $available_payment_amount;
680
+	}
681
+
682
+
683
+	/**
684
+	 * update registration REG_paid field after successful payment and link registration with payment
685
+	 *
686
+	 * @param EE_Registration $registration
687
+	 * @param EE_Payment      $payment
688
+	 * @param float           $payment_amount
689
+	 * @return void
690
+	 * @throws EE_Error
691
+	 * @throws InvalidArgumentException
692
+	 * @throws InvalidDataTypeException
693
+	 * @throws InvalidInterfaceException
694
+	 */
695
+	protected function _apply_registration_payment(
696
+		EE_Registration $registration,
697
+		EE_Payment $payment,
698
+		$payment_amount = 0.00
699
+	) {
700
+		// find any existing reg payment records for this registration and payment
701
+		$existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
702
+			array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
703
+		);
704
+		// if existing registration payment exists
705
+		if ($existing_reg_payment instanceof EE_Registration_Payment) {
706
+			// then update that record
707
+			$existing_reg_payment->set_amount($payment_amount);
708
+			$existing_reg_payment->save();
709
+		} else {
710
+			// or add new relation between registration and payment and set amount
711
+			$registration->_add_relation_to(
712
+				$payment,
713
+				'Payment',
714
+				array('RPY_amount' => $payment_amount)
715
+			);
716
+			// make it stick
717
+			$registration->save();
718
+		}
719
+	}
720
+
721
+
722
+	/**
723
+	 * update registration REG_paid field after refund and link registration with payment
724
+	 *
725
+	 * @param EE_Registration $registration
726
+	 * @param EE_Payment      $payment
727
+	 * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
728
+	 * @return float
729
+	 * @throws EE_Error
730
+	 * @throws InvalidArgumentException
731
+	 * @throws RuntimeException
732
+	 * @throws InvalidDataTypeException
733
+	 * @throws InvalidInterfaceException
734
+	 */
735
+	public function process_registration_refund(
736
+		EE_Registration $registration,
737
+		EE_Payment $payment,
738
+		$available_refund_amount = 0.00
739
+	) {
740
+		// EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
741
+		if ($registration->paid() > 0) {
742
+			// ensure $available_refund_amount is NOT negative
743
+			$available_refund_amount = (float) abs($available_refund_amount);
744
+			// don't allow refund amount to exceed the available payment amount, OR the amount paid
745
+			$refund_amount = min($available_refund_amount, (float) $registration->paid());
746
+			// update $available_payment_amount
747
+			$available_refund_amount -= $refund_amount;
748
+			// calculate and set new REG_paid
749
+			$registration->set_paid($registration->paid() - $refund_amount);
750
+			// convert payment amount back to a negative value for storage in the db
751
+			$refund_amount = (float) abs($refund_amount) * -1;
752
+			// now save it
753
+			$this->_apply_registration_payment($registration, $payment, $refund_amount);
754
+		}
755
+		return $available_refund_amount;
756
+	}
757
+
758
+
759
+	/**
760
+	 * Process payments and transaction after payment process completed.
761
+	 * ultimately this will send the TXN and payment details off so that notifications can be sent out.
762
+	 * if this request happens to be processing an IPN,
763
+	 * then we will also set the Payment Options Reg Step to completed,
764
+	 * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
765
+	 *
766
+	 * @param EE_Transaction $transaction
767
+	 * @param EE_Payment     $payment
768
+	 * @param bool           $IPN
769
+	 * @throws EE_Error
770
+	 * @throws InvalidArgumentException
771
+	 * @throws ReflectionException
772
+	 * @throws RuntimeException
773
+	 * @throws InvalidDataTypeException
774
+	 * @throws InvalidInterfaceException
775
+	 */
776
+	protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
777
+	{
778
+		/** @type EE_Transaction_Processor $transaction_processor */
779
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
780
+		// is the Payment Options Reg Step completed ?
781
+		$payment_options_step_completed = $transaction->reg_step_completed('payment_options');
782
+		// if the Payment Options Reg Step is completed...
783
+		$revisit = $payment_options_step_completed === true;
784
+		// then this is kinda sorta a revisit with regards to payments at least
785
+		$transaction_processor->set_revisit($revisit);
786
+		// if this is an IPN, let's consider the Payment Options Reg Step completed if not already
787
+		if ($IPN
788
+			&& $payment_options_step_completed !== true
789
+			&& ($payment->is_approved() || $payment->is_pending())
790
+		) {
791
+			$payment_options_step_completed = $transaction->set_reg_step_completed(
792
+				'payment_options'
793
+			);
794
+		}
795
+		// maybe update status, but don't save transaction just yet
796
+		$transaction->update_status_based_on_total_paid(false);
797
+		// check if 'finalize_registration' step has been completed...
798
+		$finalized = $transaction->reg_step_completed('finalize_registration');
799
+		//  if this is an IPN and the final step has not been initiated
800
+		if ($IPN && $payment_options_step_completed && $finalized === false) {
801
+			// and if it hasn't already been set as being started...
802
+			$finalized = $transaction->set_reg_step_initiated('finalize_registration');
803
+		}
804
+		$transaction->save();
805
+		// because the above will return false if the final step was not fully completed, we need to check again...
806
+		if ($IPN && $finalized !== false) {
807
+			// and if we are all good to go, then send out notifications
808
+			add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
809
+			// ok, now process the transaction according to the payment
810
+			$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
811
+				$transaction,
812
+				$payment
813
+			);
814
+		}
815
+		// DEBUG LOG
816
+		$payment_method = $payment->payment_method();
817
+		if ($payment_method instanceof EE_Payment_Method) {
818
+			$payment_method_type_obj = $payment_method->type_obj();
819
+			if ($payment_method_type_obj instanceof EE_PMT_Base) {
820
+				$gateway = $payment_method_type_obj->get_gateway();
821
+				if ($gateway instanceof EE_Gateway) {
822
+					$gateway->log(
823
+						array(
824
+							'message'               => (string) __('Post Payment Transaction Details', 'event_espresso'),
825
+							'transaction'           => $transaction->model_field_array(),
826
+							'finalized'             => $finalized,
827
+							'IPN'                   => $IPN,
828
+							'deliver_notifications' => has_filter(
829
+								'FHEE__EED_Messages___maybe_registration__deliver_notifications'
830
+							),
831
+						),
832
+						$payment
833
+					);
834
+				}
835
+			}
836
+		}
837
+	}
838
+
839
+
840
+	/**
841
+	 * Force posts to PayPal to use TLS v1.2. See:
842
+	 * https://core.trac.wordpress.org/ticket/36320
843
+	 * https://core.trac.wordpress.org/ticket/34924#comment:15
844
+	 * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
845
+	 * This will affect PayPal standard, pro, express, and Payflow.
846
+	 *
847
+	 * @param $handle
848
+	 * @param $r
849
+	 * @param $url
850
+	 */
851
+	public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
852
+	{
853
+		if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) {
854
+			// Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
855
+			// instead of the constant because it might not be defined
856
+			curl_setopt($handle, CURLOPT_SSLVERSION, 6);
857
+		}
858
+	}
859 859
 }
Please login to merge, or discard this patch.
modules/event_single/EED_Event_Single.module.php 2 patches
Indentation   +467 added lines, -467 removed lines patch added patch discarded remove patch
@@ -14,472 +14,472 @@  discard block
 block discarded – undo
14 14
 class EED_Event_Single extends EED_Module
15 15
 {
16 16
 
17
-    const EVENT_DETAILS_PRIORITY = 100;
18
-    const EVENT_DATETIMES_PRIORITY = 110;
19
-    const EVENT_TICKETS_PRIORITY = 120;
20
-    const EVENT_VENUES_PRIORITY = 130;
21
-
22
-    /**
23
-     * @type bool $using_get_the_excerpt
24
-     */
25
-    protected static $using_get_the_excerpt = false;
26
-
27
-
28
-    /**
29
-     * @type EE_Template_Part_Manager $template_parts
30
-     */
31
-    protected $template_parts;
32
-
33
-
34
-    /**
35
-     * @return EED_Module|EED_Event_Single
36
-     */
37
-    public static function instance()
38
-    {
39
-        return parent::get_instance(__CLASS__);
40
-    }
41
-
42
-
43
-    /**
44
-     * set_hooks - for hooking into EE Core, other modules, etc
45
-     *
46
-     * @return void
47
-     * @throws InvalidArgumentException
48
-     * @throws InvalidDataTypeException
49
-     * @throws InvalidInterfaceException
50
-     */
51
-    public static function set_hooks()
52
-    {
53
-        add_filter('FHEE_run_EE_wp', '__return_true');
54
-        add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
55
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */
56
-        $custom_post_type_definitions = LoaderFactory::getLoader()->getShared(
57
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
58
-        );
59
-        $custom_post_types = $custom_post_type_definitions->getDefinitions();
60
-        EE_Config::register_route(
61
-            $custom_post_types['espresso_events']['singular_slug'],
62
-            'Event_Single',
63
-            'run'
64
-        );
65
-    }
66
-
67
-    /**
68
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
69
-     *
70
-     * @return    void
71
-     */
72
-    public static function set_hooks_admin()
73
-    {
74
-        add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
75
-    }
76
-
77
-
78
-    /**
79
-     * set_definitions
80
-     *
81
-     * @static
82
-     * @return void
83
-     */
84
-    public static function set_definitions()
85
-    {
86
-        define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
87
-        define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS);
88
-    }
89
-
90
-
91
-    /**
92
-     * set_config
93
-     *
94
-     * @void
95
-     */
96
-    protected function set_config()
97
-    {
98
-        $this->set_config_section('template_settings');
99
-        $this->set_config_class('EE_Event_Single_Config');
100
-        $this->set_config_name('EED_Event_Single');
101
-    }
102
-
103
-
104
-    /**
105
-     * initialize_template_parts
106
-     *
107
-     * @param EE_Config_Base|EE_Event_Single_Config $config
108
-     * @return EE_Template_Part_Manager
109
-     */
110
-    public function initialize_template_parts(EE_Event_Single_Config $config = null)
111
-    {
112
-        /** @type EE_Event_Single_Config $config */
113
-        $config = $config instanceof EE_Event_Single_Config ? $config : $this->config();
114
-        EEH_Autoloader::instance()->register_template_part_autoloaders();
115
-        $template_parts = new EE_Template_Part_Manager();
116
-        $template_parts->add_template_part(
117
-            'tickets',
118
-            __('Ticket Selector', 'event_espresso'),
119
-            'content-espresso_events-tickets.php',
120
-            $config->display_order_tickets
121
-        );
122
-        $template_parts->add_template_part(
123
-            'datetimes',
124
-            __('Dates and Times', 'event_espresso'),
125
-            'content-espresso_events-datetimes.php',
126
-            $config->display_order_datetimes
127
-        );
128
-        $template_parts->add_template_part(
129
-            'event',
130
-            __('Event Description', 'event_espresso'),
131
-            'content-espresso_events-details.php',
132
-            $config->display_order_event
133
-        );
134
-        $template_parts->add_template_part(
135
-            'venue',
136
-            __('Venue Information', 'event_espresso'),
137
-            'content-espresso_events-venues.php',
138
-            $config->display_order_venue
139
-        );
140
-        do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts);
141
-        return $template_parts;
142
-    }
143
-
144
-
145
-    /**
146
-     * run - initial module setup
147
-     *
148
-     * @param WP $WP
149
-     * @return    void
150
-     */
151
-    public function run($WP)
152
-    {
153
-        // ensure valid EE_Events_Single_Config() object exists
154
-        $this->set_config();
155
-        // check what template is loaded
156
-        add_filter('template_include', array($this, 'template_include'), 999, 1);
157
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
158
-        // load css
159
-        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
160
-    }
161
-
162
-
163
-    /**
164
-     * template_include
165
-     *
166
-     * @param    string $template
167
-     * @return    string
168
-     */
169
-    public function template_include($template)
170
-    {
171
-        global $post;
172
-        /** @type EE_Event_Single_Config $config */
173
-        $config = $this->config();
174
-        if ($config->display_status_banner_single) {
175
-            add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
176
-        }
177
-        // not a custom template?
178
-        if (! post_password_required($post)
179
-            && (
180
-                apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
181
-                || EE_Registry::instance()
182
-                              ->load_core('Front_Controller')
183
-                              ->get_selected_template() !== 'single-espresso_events.php'
184
-            )
185
-
186
-        ) {
187
-            EEH_Template::load_espresso_theme_functions();
188
-            // then add extra event data via hooks
189
-            add_action('loop_start', array('EED_Event_Single', 'loop_start'));
190
-            add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1);
191
-            add_filter(
192
-                'the_content',
193
-                array('EED_Event_Single', 'event_details'),
194
-                EED_Event_Single::EVENT_DETAILS_PRIORITY
195
-            );
196
-            add_action('loop_end', array('EED_Event_Single', 'loop_end'));
197
-            // don't display entry meta because the existing theme will take car of that
198
-            add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
199
-        }
200
-        return $template;
201
-    }
202
-
203
-
204
-    /**
205
-     * loop_start
206
-     *
207
-     * @param    array $wp_query_array an array containing the WP_Query object
208
-     * @return    void
209
-     */
210
-    public static function loop_start($wp_query_array)
211
-    {
212
-        global $post;
213
-        do_action('AHEE_event_details_before_post', $post, $wp_query_array);
214
-    }
215
-
216
-
217
-    /**
218
-     * the_title
219
-     *
220
-     * @param    string $title
221
-     * @param    int    $id
222
-     * @return    string
223
-     */
224
-    public static function the_title($title = '', $id = 0)
225
-    {
226
-        global $post;
227
-        return in_the_loop() && $post->ID === (int) $id
228
-            ? espresso_event_status_banner($post->ID) . $title
229
-            : $title;
230
-    }
231
-
232
-
233
-    /**
234
-     * get_the_excerpt
235
-     * kinda hacky, but if a theme is using get_the_excerpt(),
236
-     * then we need to remove our filters on the_content()
237
-     *
238
-     * @param        string $excerpt
239
-     * @return        string
240
-     */
241
-    public static function get_the_excerpt($excerpt = '')
242
-    {
243
-        EED_Event_Single::$using_get_the_excerpt = true;
244
-        add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1);
245
-        return $excerpt;
246
-    }
247
-
248
-
249
-    /**
250
-     * end_get_the_excerpt
251
-     *
252
-     * @param  string $text
253
-     * @return string
254
-     */
255
-    public static function end_get_the_excerpt($text = '')
256
-    {
257
-        EED_Event_Single::$using_get_the_excerpt = false;
258
-        return $text;
259
-    }
260
-
261
-
262
-    /**
263
-     * event_details
264
-     *
265
-     * @param    string $content
266
-     * @return    string
267
-     */
268
-    public static function event_details($content)
269
-    {
270
-        global $post;
271
-        static $current_post_ID = 0;
272
-        if ($current_post_ID !== $post->ID
273
-            && $post->post_type === 'espresso_events'
274
-            && ! EED_Event_Single::$using_get_the_excerpt
275
-            && ! post_password_required()
276
-        ) {
277
-            // Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
278
-            // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
279
-            // BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
280
-            // We want to allow those plugins to still do their thing and have access to our content, but depending on
281
-            // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
282
-            // so the following allows this filter to be applied multiple times, but only once for real
283
-            $current_post_ID = did_action('loop_start') ? $post->ID : 0;
284
-            if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) {
285
-                // we need to first remove this callback from being applied to the_content()
286
-                // (otherwise it will recurse and blow up the interweb)
287
-                remove_filter(
288
-                    'the_content',
289
-                    array('EED_Event_Single', 'event_details'),
290
-                    EED_Event_Single::EVENT_DETAILS_PRIORITY
291
-                );
292
-                EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts(
293
-                );
294
-                $content = EEH_Template::locate_template('content-espresso_events-details.php');
295
-                $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content);
296
-                add_filter(
297
-                    'the_content',
298
-                    array('EED_Event_Single', 'event_details'),
299
-                    EED_Event_Single::EVENT_DETAILS_PRIORITY
300
-                );
301
-            } else {
302
-                $content = EED_Event_Single::use_filterable_display_order();
303
-            }
304
-        }
305
-        return $content;
306
-    }
307
-
308
-
309
-    /**
310
-     * use_filterable_display_order
311
-     *
312
-     * @return string
313
-     */
314
-    protected static function use_filterable_display_order()
315
-    {
316
-        // since the 'content-espresso_events-details.php' template might be used directly from within a theme,
317
-        // it uses the_content() for displaying the $post->post_content
318
-        // so in order to load a template that uses the_content()
319
-        // from within a callback being used to filter the_content(),
320
-        // we need to first remove this callback from being applied to the_content()
321
-        // (otherwise it will recurse and blow up the interweb)
322
-        remove_filter(
323
-            'the_content',
324
-            array('EED_Event_Single', 'event_details'),
325
-            EED_Event_Single::EVENT_DETAILS_PRIORITY
326
-        );
327
-        // now add additional content
328
-        add_filter(
329
-            'the_content',
330
-            array('EED_Event_Single', 'event_datetimes'),
331
-            EED_Event_Single::EVENT_DATETIMES_PRIORITY,
332
-            1
333
-        );
334
-        add_filter(
335
-            'the_content',
336
-            array('EED_Event_Single', 'event_tickets'),
337
-            EED_Event_Single::EVENT_TICKETS_PRIORITY,
338
-            1
339
-        );
340
-        add_filter(
341
-            'the_content',
342
-            array('EED_Event_Single', 'event_venues'),
343
-            EED_Event_Single::EVENT_VENUES_PRIORITY,
344
-            1
345
-        );
346
-        do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters');
347
-        // now load our template
348
-        $content = EEH_Template::locate_template('content-espresso_events-details.php');
349
-        // now add our filter back in, plus some others
350
-        add_filter(
351
-            'the_content',
352
-            array('EED_Event_Single', 'event_details'),
353
-            EED_Event_Single::EVENT_DETAILS_PRIORITY
354
-        );
355
-        remove_filter(
356
-            'the_content',
357
-            array('EED_Event_Single', 'event_datetimes'),
358
-            EED_Event_Single::EVENT_DATETIMES_PRIORITY
359
-        );
360
-        remove_filter(
361
-            'the_content',
362
-            array('EED_Event_Single', 'event_tickets'),
363
-            EED_Event_Single::EVENT_TICKETS_PRIORITY
364
-        );
365
-        remove_filter(
366
-            'the_content',
367
-            array('EED_Event_Single', 'event_venues'),
368
-            EED_Event_Single::EVENT_VENUES_PRIORITY
369
-        );
370
-        do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters');
371
-        // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
372
-        return $content;
373
-    }
374
-
375
-
376
-    /**
377
-     * event_datetimes - adds datetimes ABOVE content
378
-     *
379
-     * @param        string $content
380
-     * @return        string
381
-     */
382
-    public static function event_datetimes($content)
383
-    {
384
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
385
-    }
386
-
387
-
388
-    /**
389
-     * event_tickets - adds tickets ABOVE content (which includes datetimes)
390
-     *
391
-     * @param        string $content
392
-     * @return        string
393
-     */
394
-    public static function event_tickets($content)
395
-    {
396
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
397
-    }
398
-
399
-
400
-    /**
401
-     * event_venues
402
-     *
403
-     * @param    string $content
404
-     * @return    string
405
-     */
406
-    public static function event_venue($content)
407
-    {
408
-        return EED_Event_Single::event_venues($content);
409
-    }
410
-
411
-
412
-    /**
413
-     * event_venues - adds venues BELOW content
414
-     *
415
-     * @param        string $content
416
-     * @return        string
417
-     */
418
-    public static function event_venues($content)
419
-    {
420
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
421
-    }
422
-
423
-
424
-    /**
425
-     * loop_end
426
-     *
427
-     * @param        array $wp_query_array an array containing the WP_Query object
428
-     * @return        void
429
-     */
430
-    public static function loop_end($wp_query_array)
431
-    {
432
-        global $post;
433
-        do_action('AHEE_event_details_after_post', $post, $wp_query_array);
434
-    }
435
-
436
-
437
-    /**
438
-     * wp_enqueue_scripts
439
-     *
440
-     * @return    void
441
-     */
442
-    public function wp_enqueue_scripts()
443
-    {
444
-        // get some style
445
-        if (apply_filters('FHEE_enable_default_espresso_css', true)
446
-            && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true)
447
-        ) {
448
-            // first check uploads folder
449
-            if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
450
-                wp_register_style(
451
-                    $this->theme,
452
-                    get_stylesheet_directory_uri() . $this->theme . DS . 'style.css',
453
-                    array('dashicons', 'espresso_default')
454
-                );
455
-            } else {
456
-                wp_register_style(
457
-                    $this->theme,
458
-                    EE_TEMPLATES_URL . $this->theme . DS . 'style.css',
459
-                    array('dashicons', 'espresso_default')
460
-                );
461
-            }
462
-            wp_enqueue_script($this->theme);
463
-            if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
464
-                add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
465
-            }
466
-        }
467
-    }
468
-
469
-
470
-    /**
471
-     * display_venue
472
-     *
473
-     * @return    bool
474
-     */
475
-    public static function display_venue()
476
-    {
477
-        /** @type EE_Event_Single_Config $config */
478
-        $config = EED_Event_Single::instance()->config();
479
-        $display_venue = $config->display_venue === null ? true : $config->display_venue;
480
-        $venue_name = EEH_Venue_View::venue_name();
481
-        return $display_venue && ! empty($venue_name);
482
-    }
17
+	const EVENT_DETAILS_PRIORITY = 100;
18
+	const EVENT_DATETIMES_PRIORITY = 110;
19
+	const EVENT_TICKETS_PRIORITY = 120;
20
+	const EVENT_VENUES_PRIORITY = 130;
21
+
22
+	/**
23
+	 * @type bool $using_get_the_excerpt
24
+	 */
25
+	protected static $using_get_the_excerpt = false;
26
+
27
+
28
+	/**
29
+	 * @type EE_Template_Part_Manager $template_parts
30
+	 */
31
+	protected $template_parts;
32
+
33
+
34
+	/**
35
+	 * @return EED_Module|EED_Event_Single
36
+	 */
37
+	public static function instance()
38
+	{
39
+		return parent::get_instance(__CLASS__);
40
+	}
41
+
42
+
43
+	/**
44
+	 * set_hooks - for hooking into EE Core, other modules, etc
45
+	 *
46
+	 * @return void
47
+	 * @throws InvalidArgumentException
48
+	 * @throws InvalidDataTypeException
49
+	 * @throws InvalidInterfaceException
50
+	 */
51
+	public static function set_hooks()
52
+	{
53
+		add_filter('FHEE_run_EE_wp', '__return_true');
54
+		add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
55
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */
56
+		$custom_post_type_definitions = LoaderFactory::getLoader()->getShared(
57
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
58
+		);
59
+		$custom_post_types = $custom_post_type_definitions->getDefinitions();
60
+		EE_Config::register_route(
61
+			$custom_post_types['espresso_events']['singular_slug'],
62
+			'Event_Single',
63
+			'run'
64
+		);
65
+	}
66
+
67
+	/**
68
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
69
+	 *
70
+	 * @return    void
71
+	 */
72
+	public static function set_hooks_admin()
73
+	{
74
+		add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
75
+	}
76
+
77
+
78
+	/**
79
+	 * set_definitions
80
+	 *
81
+	 * @static
82
+	 * @return void
83
+	 */
84
+	public static function set_definitions()
85
+	{
86
+		define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
87
+		define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS);
88
+	}
89
+
90
+
91
+	/**
92
+	 * set_config
93
+	 *
94
+	 * @void
95
+	 */
96
+	protected function set_config()
97
+	{
98
+		$this->set_config_section('template_settings');
99
+		$this->set_config_class('EE_Event_Single_Config');
100
+		$this->set_config_name('EED_Event_Single');
101
+	}
102
+
103
+
104
+	/**
105
+	 * initialize_template_parts
106
+	 *
107
+	 * @param EE_Config_Base|EE_Event_Single_Config $config
108
+	 * @return EE_Template_Part_Manager
109
+	 */
110
+	public function initialize_template_parts(EE_Event_Single_Config $config = null)
111
+	{
112
+		/** @type EE_Event_Single_Config $config */
113
+		$config = $config instanceof EE_Event_Single_Config ? $config : $this->config();
114
+		EEH_Autoloader::instance()->register_template_part_autoloaders();
115
+		$template_parts = new EE_Template_Part_Manager();
116
+		$template_parts->add_template_part(
117
+			'tickets',
118
+			__('Ticket Selector', 'event_espresso'),
119
+			'content-espresso_events-tickets.php',
120
+			$config->display_order_tickets
121
+		);
122
+		$template_parts->add_template_part(
123
+			'datetimes',
124
+			__('Dates and Times', 'event_espresso'),
125
+			'content-espresso_events-datetimes.php',
126
+			$config->display_order_datetimes
127
+		);
128
+		$template_parts->add_template_part(
129
+			'event',
130
+			__('Event Description', 'event_espresso'),
131
+			'content-espresso_events-details.php',
132
+			$config->display_order_event
133
+		);
134
+		$template_parts->add_template_part(
135
+			'venue',
136
+			__('Venue Information', 'event_espresso'),
137
+			'content-espresso_events-venues.php',
138
+			$config->display_order_venue
139
+		);
140
+		do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts);
141
+		return $template_parts;
142
+	}
143
+
144
+
145
+	/**
146
+	 * run - initial module setup
147
+	 *
148
+	 * @param WP $WP
149
+	 * @return    void
150
+	 */
151
+	public function run($WP)
152
+	{
153
+		// ensure valid EE_Events_Single_Config() object exists
154
+		$this->set_config();
155
+		// check what template is loaded
156
+		add_filter('template_include', array($this, 'template_include'), 999, 1);
157
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
158
+		// load css
159
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
160
+	}
161
+
162
+
163
+	/**
164
+	 * template_include
165
+	 *
166
+	 * @param    string $template
167
+	 * @return    string
168
+	 */
169
+	public function template_include($template)
170
+	{
171
+		global $post;
172
+		/** @type EE_Event_Single_Config $config */
173
+		$config = $this->config();
174
+		if ($config->display_status_banner_single) {
175
+			add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
176
+		}
177
+		// not a custom template?
178
+		if (! post_password_required($post)
179
+			&& (
180
+				apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
181
+				|| EE_Registry::instance()
182
+							  ->load_core('Front_Controller')
183
+							  ->get_selected_template() !== 'single-espresso_events.php'
184
+			)
185
+
186
+		) {
187
+			EEH_Template::load_espresso_theme_functions();
188
+			// then add extra event data via hooks
189
+			add_action('loop_start', array('EED_Event_Single', 'loop_start'));
190
+			add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1);
191
+			add_filter(
192
+				'the_content',
193
+				array('EED_Event_Single', 'event_details'),
194
+				EED_Event_Single::EVENT_DETAILS_PRIORITY
195
+			);
196
+			add_action('loop_end', array('EED_Event_Single', 'loop_end'));
197
+			// don't display entry meta because the existing theme will take car of that
198
+			add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
199
+		}
200
+		return $template;
201
+	}
202
+
203
+
204
+	/**
205
+	 * loop_start
206
+	 *
207
+	 * @param    array $wp_query_array an array containing the WP_Query object
208
+	 * @return    void
209
+	 */
210
+	public static function loop_start($wp_query_array)
211
+	{
212
+		global $post;
213
+		do_action('AHEE_event_details_before_post', $post, $wp_query_array);
214
+	}
215
+
216
+
217
+	/**
218
+	 * the_title
219
+	 *
220
+	 * @param    string $title
221
+	 * @param    int    $id
222
+	 * @return    string
223
+	 */
224
+	public static function the_title($title = '', $id = 0)
225
+	{
226
+		global $post;
227
+		return in_the_loop() && $post->ID === (int) $id
228
+			? espresso_event_status_banner($post->ID) . $title
229
+			: $title;
230
+	}
231
+
232
+
233
+	/**
234
+	 * get_the_excerpt
235
+	 * kinda hacky, but if a theme is using get_the_excerpt(),
236
+	 * then we need to remove our filters on the_content()
237
+	 *
238
+	 * @param        string $excerpt
239
+	 * @return        string
240
+	 */
241
+	public static function get_the_excerpt($excerpt = '')
242
+	{
243
+		EED_Event_Single::$using_get_the_excerpt = true;
244
+		add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1);
245
+		return $excerpt;
246
+	}
247
+
248
+
249
+	/**
250
+	 * end_get_the_excerpt
251
+	 *
252
+	 * @param  string $text
253
+	 * @return string
254
+	 */
255
+	public static function end_get_the_excerpt($text = '')
256
+	{
257
+		EED_Event_Single::$using_get_the_excerpt = false;
258
+		return $text;
259
+	}
260
+
261
+
262
+	/**
263
+	 * event_details
264
+	 *
265
+	 * @param    string $content
266
+	 * @return    string
267
+	 */
268
+	public static function event_details($content)
269
+	{
270
+		global $post;
271
+		static $current_post_ID = 0;
272
+		if ($current_post_ID !== $post->ID
273
+			&& $post->post_type === 'espresso_events'
274
+			&& ! EED_Event_Single::$using_get_the_excerpt
275
+			&& ! post_password_required()
276
+		) {
277
+			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
278
+			// Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
279
+			// BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
280
+			// We want to allow those plugins to still do their thing and have access to our content, but depending on
281
+			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
282
+			// so the following allows this filter to be applied multiple times, but only once for real
283
+			$current_post_ID = did_action('loop_start') ? $post->ID : 0;
284
+			if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) {
285
+				// we need to first remove this callback from being applied to the_content()
286
+				// (otherwise it will recurse and blow up the interweb)
287
+				remove_filter(
288
+					'the_content',
289
+					array('EED_Event_Single', 'event_details'),
290
+					EED_Event_Single::EVENT_DETAILS_PRIORITY
291
+				);
292
+				EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts(
293
+				);
294
+				$content = EEH_Template::locate_template('content-espresso_events-details.php');
295
+				$content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content);
296
+				add_filter(
297
+					'the_content',
298
+					array('EED_Event_Single', 'event_details'),
299
+					EED_Event_Single::EVENT_DETAILS_PRIORITY
300
+				);
301
+			} else {
302
+				$content = EED_Event_Single::use_filterable_display_order();
303
+			}
304
+		}
305
+		return $content;
306
+	}
307
+
308
+
309
+	/**
310
+	 * use_filterable_display_order
311
+	 *
312
+	 * @return string
313
+	 */
314
+	protected static function use_filterable_display_order()
315
+	{
316
+		// since the 'content-espresso_events-details.php' template might be used directly from within a theme,
317
+		// it uses the_content() for displaying the $post->post_content
318
+		// so in order to load a template that uses the_content()
319
+		// from within a callback being used to filter the_content(),
320
+		// we need to first remove this callback from being applied to the_content()
321
+		// (otherwise it will recurse and blow up the interweb)
322
+		remove_filter(
323
+			'the_content',
324
+			array('EED_Event_Single', 'event_details'),
325
+			EED_Event_Single::EVENT_DETAILS_PRIORITY
326
+		);
327
+		// now add additional content
328
+		add_filter(
329
+			'the_content',
330
+			array('EED_Event_Single', 'event_datetimes'),
331
+			EED_Event_Single::EVENT_DATETIMES_PRIORITY,
332
+			1
333
+		);
334
+		add_filter(
335
+			'the_content',
336
+			array('EED_Event_Single', 'event_tickets'),
337
+			EED_Event_Single::EVENT_TICKETS_PRIORITY,
338
+			1
339
+		);
340
+		add_filter(
341
+			'the_content',
342
+			array('EED_Event_Single', 'event_venues'),
343
+			EED_Event_Single::EVENT_VENUES_PRIORITY,
344
+			1
345
+		);
346
+		do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters');
347
+		// now load our template
348
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
349
+		// now add our filter back in, plus some others
350
+		add_filter(
351
+			'the_content',
352
+			array('EED_Event_Single', 'event_details'),
353
+			EED_Event_Single::EVENT_DETAILS_PRIORITY
354
+		);
355
+		remove_filter(
356
+			'the_content',
357
+			array('EED_Event_Single', 'event_datetimes'),
358
+			EED_Event_Single::EVENT_DATETIMES_PRIORITY
359
+		);
360
+		remove_filter(
361
+			'the_content',
362
+			array('EED_Event_Single', 'event_tickets'),
363
+			EED_Event_Single::EVENT_TICKETS_PRIORITY
364
+		);
365
+		remove_filter(
366
+			'the_content',
367
+			array('EED_Event_Single', 'event_venues'),
368
+			EED_Event_Single::EVENT_VENUES_PRIORITY
369
+		);
370
+		do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters');
371
+		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
372
+		return $content;
373
+	}
374
+
375
+
376
+	/**
377
+	 * event_datetimes - adds datetimes ABOVE content
378
+	 *
379
+	 * @param        string $content
380
+	 * @return        string
381
+	 */
382
+	public static function event_datetimes($content)
383
+	{
384
+		return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
385
+	}
386
+
387
+
388
+	/**
389
+	 * event_tickets - adds tickets ABOVE content (which includes datetimes)
390
+	 *
391
+	 * @param        string $content
392
+	 * @return        string
393
+	 */
394
+	public static function event_tickets($content)
395
+	{
396
+		return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
397
+	}
398
+
399
+
400
+	/**
401
+	 * event_venues
402
+	 *
403
+	 * @param    string $content
404
+	 * @return    string
405
+	 */
406
+	public static function event_venue($content)
407
+	{
408
+		return EED_Event_Single::event_venues($content);
409
+	}
410
+
411
+
412
+	/**
413
+	 * event_venues - adds venues BELOW content
414
+	 *
415
+	 * @param        string $content
416
+	 * @return        string
417
+	 */
418
+	public static function event_venues($content)
419
+	{
420
+		return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
421
+	}
422
+
423
+
424
+	/**
425
+	 * loop_end
426
+	 *
427
+	 * @param        array $wp_query_array an array containing the WP_Query object
428
+	 * @return        void
429
+	 */
430
+	public static function loop_end($wp_query_array)
431
+	{
432
+		global $post;
433
+		do_action('AHEE_event_details_after_post', $post, $wp_query_array);
434
+	}
435
+
436
+
437
+	/**
438
+	 * wp_enqueue_scripts
439
+	 *
440
+	 * @return    void
441
+	 */
442
+	public function wp_enqueue_scripts()
443
+	{
444
+		// get some style
445
+		if (apply_filters('FHEE_enable_default_espresso_css', true)
446
+			&& apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true)
447
+		) {
448
+			// first check uploads folder
449
+			if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
450
+				wp_register_style(
451
+					$this->theme,
452
+					get_stylesheet_directory_uri() . $this->theme . DS . 'style.css',
453
+					array('dashicons', 'espresso_default')
454
+				);
455
+			} else {
456
+				wp_register_style(
457
+					$this->theme,
458
+					EE_TEMPLATES_URL . $this->theme . DS . 'style.css',
459
+					array('dashicons', 'espresso_default')
460
+				);
461
+			}
462
+			wp_enqueue_script($this->theme);
463
+			if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
464
+				add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
465
+			}
466
+		}
467
+	}
468
+
469
+
470
+	/**
471
+	 * display_venue
472
+	 *
473
+	 * @return    bool
474
+	 */
475
+	public static function display_venue()
476
+	{
477
+		/** @type EE_Event_Single_Config $config */
478
+		$config = EED_Event_Single::instance()->config();
479
+		$display_venue = $config->display_venue === null ? true : $config->display_venue;
480
+		$venue_name = EEH_Venue_View::venue_name();
481
+		return $display_venue && ! empty($venue_name);
482
+	}
483 483
 }
484 484
 
485 485
 
@@ -491,5 +491,5 @@  discard block
 block discarded – undo
491 491
  */
492 492
 function espresso_display_venue_in_event_details()
493 493
 {
494
-    return EED_Event_Single::display_venue();
494
+	return EED_Event_Single::display_venue();
495 495
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
      */
84 84
     public static function set_definitions()
85 85
     {
86
-        define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
87
-        define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS);
86
+        define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
87
+        define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__).'templates'.DS);
88 88
     }
89 89
 
90 90
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
             add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
176 176
         }
177 177
         // not a custom template?
178
-        if (! post_password_required($post)
178
+        if ( ! post_password_required($post)
179 179
             && (
180 180
                 apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
181 181
                 || EE_Registry::instance()
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
     {
226 226
         global $post;
227 227
         return in_the_loop() && $post->ID === (int) $id
228
-            ? espresso_event_status_banner($post->ID) . $title
228
+            ? espresso_event_status_banner($post->ID).$title
229 229
             : $title;
230 230
     }
231 231
 
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
      */
382 382
     public static function event_datetimes($content)
383 383
     {
384
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
384
+        return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content;
385 385
     }
386 386
 
387 387
 
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
      */
394 394
     public static function event_tickets($content)
395 395
     {
396
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
396
+        return EEH_Template::locate_template('content-espresso_events-tickets.php').$content;
397 397
     }
398 398
 
399 399
 
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
      */
418 418
     public static function event_venues($content)
419 419
     {
420
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
420
+        return $content.EEH_Template::locate_template('content-espresso_events-venues.php');
421 421
     }
422 422
 
423 423
 
@@ -446,16 +446,16 @@  discard block
 block discarded – undo
446 446
             && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true)
447 447
         ) {
448 448
             // first check uploads folder
449
-            if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
449
+            if (is_readable(get_stylesheet_directory().$this->theme.DS.'style.css')) {
450 450
                 wp_register_style(
451 451
                     $this->theme,
452
-                    get_stylesheet_directory_uri() . $this->theme . DS . 'style.css',
452
+                    get_stylesheet_directory_uri().$this->theme.DS.'style.css',
453 453
                     array('dashicons', 'espresso_default')
454 454
                 );
455 455
             } else {
456 456
                 wp_register_style(
457 457
                     $this->theme,
458
-                    EE_TEMPLATES_URL . $this->theme . DS . 'style.css',
458
+                    EE_TEMPLATES_URL.$this->theme.DS.'style.css',
459 459
                     array('dashicons', 'espresso_default')
460 460
                 );
461 461
             }
Please login to merge, or discard this patch.
modules/invalid_checkout_access/EED_Invalid_Checkout_Access.module.php 2 patches
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -13,82 +13,82 @@
 block discarded – undo
13 13
 class EED_Invalid_Checkout_Access extends EED_Module
14 14
 {
15 15
 
16
-    /**
17
-     * @var InvalidCheckoutAccess $invalid_checkout_access_form
18
-     */
19
-    private static $invalid_checkout_access_form;
16
+	/**
17
+	 * @var InvalidCheckoutAccess $invalid_checkout_access_form
18
+	 */
19
+	private static $invalid_checkout_access_form;
20 20
 
21
-    /**
22
-     * set_hooks - for hooking into EE Core, other modules, etc
23
-     */
24
-    public static function set_hooks()
25
-    {
26
-    }
21
+	/**
22
+	 * set_hooks - for hooking into EE Core, other modules, etc
23
+	 */
24
+	public static function set_hooks()
25
+	{
26
+	}
27 27
 
28 28
 
29
-    /**
30
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
31
-     */
32
-    public static function set_hooks_admin()
33
-    {
34
-        add_action(
35
-            'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
36
-            array('EED_Invalid_Checkout_Access', 'display_invalid_checkout_access_form'),
37
-            15
38
-        );
39
-        add_filter(
40
-            'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
41
-            array('EED_Invalid_Checkout_Access', 'process_invalid_checkout_access_form')
42
-        );
43
-    }
29
+	/**
30
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
31
+	 */
32
+	public static function set_hooks_admin()
33
+	{
34
+		add_action(
35
+			'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
36
+			array('EED_Invalid_Checkout_Access', 'display_invalid_checkout_access_form'),
37
+			15
38
+		);
39
+		add_filter(
40
+			'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
41
+			array('EED_Invalid_Checkout_Access', 'process_invalid_checkout_access_form')
42
+		);
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     * run - initial module setup
48
-     * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
49
-     *
50
-     * @var WP $WP
51
-     */
52
-    public function run($WP)
53
-    {
54
-        // TODO: Implement run() method.
55
-    }
46
+	/**
47
+	 * run - initial module setup
48
+	 * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
49
+	 *
50
+	 * @var WP $WP
51
+	 */
52
+	public function run($WP)
53
+	{
54
+		// TODO: Implement run() method.
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * @return InvalidCheckoutAccess
60
-     */
61
-    public static function getInvalidCheckoutAccess()
62
-    {
63
-        if (! self::$invalid_checkout_access_form instanceof InvalidCheckoutAccess) {
64
-            self::$invalid_checkout_access_form = new InvalidCheckoutAccess();
65
-        }
66
-        return self::$invalid_checkout_access_form;
67
-    }
58
+	/**
59
+	 * @return InvalidCheckoutAccess
60
+	 */
61
+	public static function getInvalidCheckoutAccess()
62
+	{
63
+		if (! self::$invalid_checkout_access_form instanceof InvalidCheckoutAccess) {
64
+			self::$invalid_checkout_access_form = new InvalidCheckoutAccess();
65
+		}
66
+		return self::$invalid_checkout_access_form;
67
+	}
68 68
 
69 69
 
70
-    /**
71
-     * email_validation_settings_form
72
-     *
73
-     * @return    void
74
-     * @throws \EE_Error
75
-     */
76
-    public static function display_invalid_checkout_access_form()
77
-    {
78
-        $invalid_checkout_access_form = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
79
-        echo $invalid_checkout_access_form->getForm()->get_html();
80
-    }
70
+	/**
71
+	 * email_validation_settings_form
72
+	 *
73
+	 * @return    void
74
+	 * @throws \EE_Error
75
+	 */
76
+	public static function display_invalid_checkout_access_form()
77
+	{
78
+		$invalid_checkout_access_form = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
79
+		echo $invalid_checkout_access_form->getForm()->get_html();
80
+	}
81 81
 
82 82
 
83
-    /**
84
-     * email_validation_settings_form
85
-     *
86
-     * @param \EE_Registration_Config $EE_Registration_Config
87
-     * @return \EE_Registration_Config
88
-     */
89
-    public static function process_invalid_checkout_access_form(\EE_Registration_Config $EE_Registration_Config)
90
-    {
91
-        $invalid_checkout_access_form = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
92
-        return $invalid_checkout_access_form->processForm($EE_Registration_Config);
93
-    }
83
+	/**
84
+	 * email_validation_settings_form
85
+	 *
86
+	 * @param \EE_Registration_Config $EE_Registration_Config
87
+	 * @return \EE_Registration_Config
88
+	 */
89
+	public static function process_invalid_checkout_access_form(\EE_Registration_Config $EE_Registration_Config)
90
+	{
91
+		$invalid_checkout_access_form = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
92
+		return $invalid_checkout_access_form->processForm($EE_Registration_Config);
93
+	}
94 94
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@
 block discarded – undo
60 60
      */
61 61
     public static function getInvalidCheckoutAccess()
62 62
     {
63
-        if (! self::$invalid_checkout_access_form instanceof InvalidCheckoutAccess) {
63
+        if ( ! self::$invalid_checkout_access_form instanceof InvalidCheckoutAccess) {
64 64
             self::$invalid_checkout_access_form = new InvalidCheckoutAccess();
65 65
         }
66 66
         return self::$invalid_checkout_access_form;
Please login to merge, or discard this patch.
modules/csv/EED_Csv.module.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -12,69 +12,69 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * @return EED_Csv
17
-     */
18
-    public static function instance()
19
-    {
20
-        return parent::get_instance(__CLASS__);
21
-    }
15
+	/**
16
+	 * @return EED_Csv
17
+	 */
18
+	public static function instance()
19
+	{
20
+		return parent::get_instance(__CLASS__);
21
+	}
22 22
 
23 23
 
24
-    /**
25
-     *    set_hooks - for hooking into EE Core, other modules, etc
26
-     *
27
-     * @access    public
28
-     * @return    void
29
-     */
30
-    public static function set_hooks()
31
-    {
32
-    }
24
+	/**
25
+	 *    set_hooks - for hooking into EE Core, other modules, etc
26
+	 *
27
+	 * @access    public
28
+	 * @return    void
29
+	 */
30
+	public static function set_hooks()
31
+	{
32
+	}
33 33
 
34
-    /**
35
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
36
-     *
37
-     * @access    public
38
-     * @return    void
39
-     */
40
-    public static function set_hooks_admin()
41
-    {
42
-    }
34
+	/**
35
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
36
+	 *
37
+	 * @access    public
38
+	 * @return    void
39
+	 */
40
+	public static function set_hooks_admin()
41
+	{
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     *    run - initial module setup
47
-     *
48
-     * @access    public
49
-     * @return    void
50
-     */
51
-    public function run($WP)
52
-    {
53
-    }
45
+	/**
46
+	 *    run - initial module setup
47
+	 *
48
+	 * @access    public
49
+	 * @return    void
50
+	 */
51
+	public function run($WP)
52
+	{
53
+	}
54 54
 
55 55
 
56
-    /**
57
-     *    export
58
-     *
59
-     * @access    public
60
-     * @return    void
61
-     */
62
-    public function export()
63
-    {
64
-        $Export = EE_Registry::instance()->load_class('Export');
65
-        $Export->export();
66
-    }
56
+	/**
57
+	 *    export
58
+	 *
59
+	 * @access    public
60
+	 * @return    void
61
+	 */
62
+	public function export()
63
+	{
64
+		$Export = EE_Registry::instance()->load_class('Export');
65
+		$Export->export();
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     *    import
71
-     *
72
-     * @access    public
73
-     * @return    void
74
-     */
75
-    public function import()
76
-    {
77
-        $Import = EE_Registry::instance()->load_class('Import');
78
-        $Import->import();
79
-    }
69
+	/**
70
+	 *    import
71
+	 *
72
+	 * @access    public
73
+	 * @return    void
74
+	 */
75
+	public function import()
76
+	{
77
+		$Import = EE_Registry::instance()->load_class('Import');
78
+		$Import->import();
79
+	}
80 80
 }
Please login to merge, or discard this patch.
modules/ical/EED_Ical.module.php 2 patches
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -11,239 +11,239 @@
 block discarded – undo
11 11
 class EED_Ical extends EED_Module
12 12
 {
13 13
 
14
-    const iCal_datetime_format = 'Ymd\THis\Z';
15
-
16
-
17
-    /**
18
-     * @return EED_Ical|EED_Module
19
-     */
20
-    public static function instance()
21
-    {
22
-        return parent::get_instance(__CLASS__);
23
-    }
24
-
25
-
26
-    /**
27
-     *    set_hooks - for hooking into EE Core, other modules, etc
28
-     *
29
-     * @access    public
30
-     * @return    void
31
-     */
32
-    public static function set_hooks()
33
-    {
34
-        // create download buttons
35
-        add_filter(
36
-            'FHEE__espresso_list_of_event_dates__datetime_html',
37
-            array('EED_Ical', 'generate_add_to_iCal_button'),
38
-            10,
39
-            2
40
-        );
41
-        // process ics download request
42
-        EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file');
43
-    }
44
-
45
-
46
-    /**
47
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
48
-     *
49
-     * @access    public
50
-     * @return    void
51
-     */
52
-    public static function set_hooks_admin()
53
-    {
54
-    }
55
-
56
-
57
-    /**
58
-     *    run - initial module setup
59
-     *
60
-     * @access    public
61
-     * @param    WP $WP
62
-     * @return    void
63
-     */
64
-    public function run($WP)
65
-    {
66
-    }
67
-
68
-
69
-    /**
70
-     *    generate_add_to_iCal_button
71
-     *
72
-     * @access    public
73
-     * @param $html
74
-     * @param $datetime
75
-     * @return    string
76
-     * @throws \EE_Error
77
-     */
78
-    public static function generate_add_to_iCal_button($html, $datetime)
79
-    {
80
-        // first verify a proper datetime object has been received
81
-        if ($datetime instanceof EE_Datetime) {
82
-            // set whether a link or submit button is shown
83
-            $iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit');
84
-            // generate a link to the route we registered in set_hooks()
85
-            $URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $datetime->ID()), site_url());
86
-            // what type ?
87
-            switch ($iCal_type) {
88
-                // submit buttons appear as buttons and are very compatible with a theme's style
89
-                case 'submit':
90
-                    $html .= '<form id="download-iCal-frm-' . $datetime->ID();
91
-                    $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
92
-                    $html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
93
-                    $html .= __('Add to iCal Calendar', 'event_espresso') . '"/>';
94
-                    $html .= '</form>';
95
-                    break;
96
-                // buttons are just links that have been styled to appear as buttons,
97
-                // but may not be blend with a theme as well as submit buttons
98
-                case 'button':
99
-                    $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
100
-                    $html .= '" title="' . __('Add to iCal Calendar', 'event_espresso') . '">';
101
-                    $html .= ' <span class="dashicons dashicons-calendar"></span>';
102
-                    $html .= '</a>';
103
-                    break;
104
-                // links are just links that use the calendar dashicon
105
-                case 'icon':
106
-                    $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
107
-                    $html .= __('Add to iCal Calendar', 'event_espresso') . '">';
108
-                    $html .= ' <span class="dashicons dashicons-calendar"></span>';
109
-                    $html .= '</a>';
110
-                    break;
111
-            }
112
-        }
113
-        return $html;
114
-    }
115
-
116
-
117
-    /**
118
-     *    download_ics_file
119
-     *
120
-     * @access    public
121
-     * @return    void
122
-     * @throws \EE_Error
123
-     */
124
-    public static function download_ics_file()
125
-    {
126
-        if (EE_Registry::instance()->REQ->is_set('ics_id')) {
127
-            $DTT_ID = absint(EE_Registry::instance()->REQ->get('ics_id'));
128
-            $datetime = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($DTT_ID);
129
-            if ($datetime instanceof EE_Datetime) {
130
-                // get related event, venues, and event categories
131
-                $event = $datetime->event();
132
-                // get related category Term object and it's name
133
-                $category = $event->first_event_category();
134
-                if ($category instanceof EE_Term) {
135
-                    $category = $category->name();
136
-                }
137
-                $location = '';
138
-                // get first related venue and convert to CSV string
139
-                $venue = $event->venues(array('limit' => 1));
140
-                if (is_array($venue) && ! empty($venue)) {
141
-                    $venue = array_shift($venue);
142
-                    if ($venue instanceof EE_Venue) {
143
-                        $location = espresso_venue_raw_address('inline', $venue->ID(), false);
144
-                    }
145
-                }
146
-
147
-                // Generate filename
148
-                $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics';
149
-
150
-                // Check the datetime status has not been cancelled and set the ics value accordingly
151
-                $status = $datetime->get_active_status();
152
-                $status = $status === EE_Datetime::cancelled ? 'CANCELLED' : 'CONFIRMED';
153
-
154
-                // Create array of ics details, escape strings, convert timestamps to ics format, etc
155
-                $ics_data = array(
156
-                    'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
157
-                    'UID'            => md5($event->name() . $event->ID() . $datetime->ID()),
158
-                    'ORGANIZER'      => EE_Registry::instance()->CFG->organization->email,
159
-                    'DTSTAMP'        => date(EED_Ical::iCal_datetime_format),
160
-                    'LOCATION'       => $location,
161
-                    'SUMMARY'        => $event->name(),
162
-                    'DESCRIPTION'    => wp_strip_all_tags($event->description()),
163
-                    'STATUS'         => $status,
164
-                    'CATEGORIES'     => $category,
165
-                    'URL;VALUE=URI'  => get_permalink($event->ID()),
166
-                    'DTSTART'        => date(EED_Ical::iCal_datetime_format, $datetime->start()),
167
-                    'DTEND'          => date(EED_Ical::iCal_datetime_format, $datetime->end()),
168
-                );
169
-
170
-                // Filter the values used within the ics output.
171
-                // NOTE - all values within ics_data will be escaped automatically.
172
-                $ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime);
173
-
174
-                // Escape all ics data
175
-                foreach ($ics_data as $key => $value) {
176
-                    // Description is escaped differently from all all values
177
-                    if ($key === 'DESCRIPTION') {
178
-                        $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
179
-                    } else {
180
-                        $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value);
181
-                    }
182
-                }
183
-
184
-                // Pull the organizer name from ics_data and remove it from the array.
185
-                $organizer_name = isset($ics_data['ORGANIZER_NAME']) ? $ics_data['ORGANIZER_NAME'] : '';
186
-                unset($ics_data['ORGANIZER_NAME']);
187
-
188
-                // set headers
189
-                header('Content-type: text/calendar; charset=utf-8');
190
-                header('Content-Disposition: attachment; filename="' . $filename . '"');
191
-                header('Cache-Control: private, max-age=0, must-revalidate');
192
-                header('Pragma: public');
193
-                header('Content-Type: application/octet-stream');
194
-                header('Content-Type: application/force-download');
195
-                header('Cache-Control: no-cache, must-revalidate');
196
-                header('Content-Transfer-Encoding: binary');
197
-                header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date
198
-                ini_set('zlib.output_compression', '0');
199
-                // echo the output
200
-                echo "BEGIN:VCALENDAR\r\n";
201
-                echo "VERSION:2.0\r\n";
202
-                echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN\r\n";
203
-                echo "CALSCALE:GREGORIAN\r\n";
204
-                echo "BEGIN:VEVENT\r\n";
205
-
206
-                // Output all remaining values from ics_data.
207
-                foreach ($ics_data as $key => $value) {
208
-                    echo $key . ':' . $value . "\r\n";
209
-                }
210
-
211
-                echo "END:VEVENT\r\n";
212
-                echo "END:VCALENDAR\r\n";
213
-            }
214
-        }
215
-        die();
216
-    }
217
-
218
-
219
-    /**
220
-     *    _escape_ICal_data
221
-     *
222
-     * @access    private
223
-     * @param    string $string
224
-     * @return    string
225
-     */
226
-    private static function _escape_ICal_data($string = '')
227
-    {
228
-        return preg_replace('/([\,;])/', '\\\$1', $string);
229
-    }
230
-
231
-    /**
232
-     *    _escape_ICal_description
233
-     *
234
-     * @access    private
235
-     * @param    string $description
236
-     * @return    string
237
-     */
238
-    private static function _escape_ICal_description($description = '')
239
-    {
240
-
241
-        // Escape special chars within the description
242
-        $description = EED_Ical::_escape_ICal_data($description);
243
-
244
-        // Remove line breaks and output in iCal format
245
-        $description = str_replace(array("\r\n", "\n"), '\n', $description);
246
-
247
-        return $description;
248
-    }
14
+	const iCal_datetime_format = 'Ymd\THis\Z';
15
+
16
+
17
+	/**
18
+	 * @return EED_Ical|EED_Module
19
+	 */
20
+	public static function instance()
21
+	{
22
+		return parent::get_instance(__CLASS__);
23
+	}
24
+
25
+
26
+	/**
27
+	 *    set_hooks - for hooking into EE Core, other modules, etc
28
+	 *
29
+	 * @access    public
30
+	 * @return    void
31
+	 */
32
+	public static function set_hooks()
33
+	{
34
+		// create download buttons
35
+		add_filter(
36
+			'FHEE__espresso_list_of_event_dates__datetime_html',
37
+			array('EED_Ical', 'generate_add_to_iCal_button'),
38
+			10,
39
+			2
40
+		);
41
+		// process ics download request
42
+		EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file');
43
+	}
44
+
45
+
46
+	/**
47
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
48
+	 *
49
+	 * @access    public
50
+	 * @return    void
51
+	 */
52
+	public static function set_hooks_admin()
53
+	{
54
+	}
55
+
56
+
57
+	/**
58
+	 *    run - initial module setup
59
+	 *
60
+	 * @access    public
61
+	 * @param    WP $WP
62
+	 * @return    void
63
+	 */
64
+	public function run($WP)
65
+	{
66
+	}
67
+
68
+
69
+	/**
70
+	 *    generate_add_to_iCal_button
71
+	 *
72
+	 * @access    public
73
+	 * @param $html
74
+	 * @param $datetime
75
+	 * @return    string
76
+	 * @throws \EE_Error
77
+	 */
78
+	public static function generate_add_to_iCal_button($html, $datetime)
79
+	{
80
+		// first verify a proper datetime object has been received
81
+		if ($datetime instanceof EE_Datetime) {
82
+			// set whether a link or submit button is shown
83
+			$iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit');
84
+			// generate a link to the route we registered in set_hooks()
85
+			$URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $datetime->ID()), site_url());
86
+			// what type ?
87
+			switch ($iCal_type) {
88
+				// submit buttons appear as buttons and are very compatible with a theme's style
89
+				case 'submit':
90
+					$html .= '<form id="download-iCal-frm-' . $datetime->ID();
91
+					$html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
92
+					$html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
93
+					$html .= __('Add to iCal Calendar', 'event_espresso') . '"/>';
94
+					$html .= '</form>';
95
+					break;
96
+				// buttons are just links that have been styled to appear as buttons,
97
+				// but may not be blend with a theme as well as submit buttons
98
+				case 'button':
99
+					$html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
100
+					$html .= '" title="' . __('Add to iCal Calendar', 'event_espresso') . '">';
101
+					$html .= ' <span class="dashicons dashicons-calendar"></span>';
102
+					$html .= '</a>';
103
+					break;
104
+				// links are just links that use the calendar dashicon
105
+				case 'icon':
106
+					$html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
107
+					$html .= __('Add to iCal Calendar', 'event_espresso') . '">';
108
+					$html .= ' <span class="dashicons dashicons-calendar"></span>';
109
+					$html .= '</a>';
110
+					break;
111
+			}
112
+		}
113
+		return $html;
114
+	}
115
+
116
+
117
+	/**
118
+	 *    download_ics_file
119
+	 *
120
+	 * @access    public
121
+	 * @return    void
122
+	 * @throws \EE_Error
123
+	 */
124
+	public static function download_ics_file()
125
+	{
126
+		if (EE_Registry::instance()->REQ->is_set('ics_id')) {
127
+			$DTT_ID = absint(EE_Registry::instance()->REQ->get('ics_id'));
128
+			$datetime = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($DTT_ID);
129
+			if ($datetime instanceof EE_Datetime) {
130
+				// get related event, venues, and event categories
131
+				$event = $datetime->event();
132
+				// get related category Term object and it's name
133
+				$category = $event->first_event_category();
134
+				if ($category instanceof EE_Term) {
135
+					$category = $category->name();
136
+				}
137
+				$location = '';
138
+				// get first related venue and convert to CSV string
139
+				$venue = $event->venues(array('limit' => 1));
140
+				if (is_array($venue) && ! empty($venue)) {
141
+					$venue = array_shift($venue);
142
+					if ($venue instanceof EE_Venue) {
143
+						$location = espresso_venue_raw_address('inline', $venue->ID(), false);
144
+					}
145
+				}
146
+
147
+				// Generate filename
148
+				$filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics';
149
+
150
+				// Check the datetime status has not been cancelled and set the ics value accordingly
151
+				$status = $datetime->get_active_status();
152
+				$status = $status === EE_Datetime::cancelled ? 'CANCELLED' : 'CONFIRMED';
153
+
154
+				// Create array of ics details, escape strings, convert timestamps to ics format, etc
155
+				$ics_data = array(
156
+					'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
157
+					'UID'            => md5($event->name() . $event->ID() . $datetime->ID()),
158
+					'ORGANIZER'      => EE_Registry::instance()->CFG->organization->email,
159
+					'DTSTAMP'        => date(EED_Ical::iCal_datetime_format),
160
+					'LOCATION'       => $location,
161
+					'SUMMARY'        => $event->name(),
162
+					'DESCRIPTION'    => wp_strip_all_tags($event->description()),
163
+					'STATUS'         => $status,
164
+					'CATEGORIES'     => $category,
165
+					'URL;VALUE=URI'  => get_permalink($event->ID()),
166
+					'DTSTART'        => date(EED_Ical::iCal_datetime_format, $datetime->start()),
167
+					'DTEND'          => date(EED_Ical::iCal_datetime_format, $datetime->end()),
168
+				);
169
+
170
+				// Filter the values used within the ics output.
171
+				// NOTE - all values within ics_data will be escaped automatically.
172
+				$ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime);
173
+
174
+				// Escape all ics data
175
+				foreach ($ics_data as $key => $value) {
176
+					// Description is escaped differently from all all values
177
+					if ($key === 'DESCRIPTION') {
178
+						$ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
179
+					} else {
180
+						$ics_data[ $key ] = EED_Ical::_escape_ICal_data($value);
181
+					}
182
+				}
183
+
184
+				// Pull the organizer name from ics_data and remove it from the array.
185
+				$organizer_name = isset($ics_data['ORGANIZER_NAME']) ? $ics_data['ORGANIZER_NAME'] : '';
186
+				unset($ics_data['ORGANIZER_NAME']);
187
+
188
+				// set headers
189
+				header('Content-type: text/calendar; charset=utf-8');
190
+				header('Content-Disposition: attachment; filename="' . $filename . '"');
191
+				header('Cache-Control: private, max-age=0, must-revalidate');
192
+				header('Pragma: public');
193
+				header('Content-Type: application/octet-stream');
194
+				header('Content-Type: application/force-download');
195
+				header('Cache-Control: no-cache, must-revalidate');
196
+				header('Content-Transfer-Encoding: binary');
197
+				header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date
198
+				ini_set('zlib.output_compression', '0');
199
+				// echo the output
200
+				echo "BEGIN:VCALENDAR\r\n";
201
+				echo "VERSION:2.0\r\n";
202
+				echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN\r\n";
203
+				echo "CALSCALE:GREGORIAN\r\n";
204
+				echo "BEGIN:VEVENT\r\n";
205
+
206
+				// Output all remaining values from ics_data.
207
+				foreach ($ics_data as $key => $value) {
208
+					echo $key . ':' . $value . "\r\n";
209
+				}
210
+
211
+				echo "END:VEVENT\r\n";
212
+				echo "END:VCALENDAR\r\n";
213
+			}
214
+		}
215
+		die();
216
+	}
217
+
218
+
219
+	/**
220
+	 *    _escape_ICal_data
221
+	 *
222
+	 * @access    private
223
+	 * @param    string $string
224
+	 * @return    string
225
+	 */
226
+	private static function _escape_ICal_data($string = '')
227
+	{
228
+		return preg_replace('/([\,;])/', '\\\$1', $string);
229
+	}
230
+
231
+	/**
232
+	 *    _escape_ICal_description
233
+	 *
234
+	 * @access    private
235
+	 * @param    string $description
236
+	 * @return    string
237
+	 */
238
+	private static function _escape_ICal_description($description = '')
239
+	{
240
+
241
+		// Escape special chars within the description
242
+		$description = EED_Ical::_escape_ICal_data($description);
243
+
244
+		// Remove line breaks and output in iCal format
245
+		$description = str_replace(array("\r\n", "\n"), '\n', $description);
246
+
247
+		return $description;
248
+	}
249 249
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -87,24 +87,24 @@  discard block
 block discarded – undo
87 87
             switch ($iCal_type) {
88 88
                 // submit buttons appear as buttons and are very compatible with a theme's style
89 89
                 case 'submit':
90
-                    $html .= '<form id="download-iCal-frm-' . $datetime->ID();
91
-                    $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
90
+                    $html .= '<form id="download-iCal-frm-'.$datetime->ID();
91
+                    $html .= '" class="download-iCal-frm" action="'.$URL.'" method="post" >';
92 92
                     $html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
93
-                    $html .= __('Add to iCal Calendar', 'event_espresso') . '"/>';
93
+                    $html .= __('Add to iCal Calendar', 'event_espresso').'"/>';
94 94
                     $html .= '</form>';
95 95
                     break;
96 96
                 // buttons are just links that have been styled to appear as buttons,
97 97
                 // but may not be blend with a theme as well as submit buttons
98 98
                 case 'button':
99
-                    $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
100
-                    $html .= '" title="' . __('Add to iCal Calendar', 'event_espresso') . '">';
99
+                    $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="'.$URL;
100
+                    $html .= '" title="'.__('Add to iCal Calendar', 'event_espresso').'">';
101 101
                     $html .= ' <span class="dashicons dashicons-calendar"></span>';
102 102
                     $html .= '</a>';
103 103
                     break;
104 104
                 // links are just links that use the calendar dashicon
105 105
                 case 'icon':
106
-                    $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
107
-                    $html .= __('Add to iCal Calendar', 'event_espresso') . '">';
106
+                    $html .= '<a class="ee-ical-lnk" href="'.$URL.'" title="';
107
+                    $html .= __('Add to iCal Calendar', 'event_espresso').'">';
108 108
                     $html .= ' <span class="dashicons dashicons-calendar"></span>';
109 109
                     $html .= '</a>';
110 110
                     break;
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
                 }
146 146
 
147 147
                 // Generate filename
148
-                $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics';
148
+                $filename = $event->slug().'-'.$datetime->start_date('Y-m-d').'.ics';
149 149
 
150 150
                 // Check the datetime status has not been cancelled and set the ics value accordingly
151 151
                 $status = $datetime->get_active_status();
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
                 // Create array of ics details, escape strings, convert timestamps to ics format, etc
155 155
                 $ics_data = array(
156 156
                     'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
157
-                    'UID'            => md5($event->name() . $event->ID() . $datetime->ID()),
157
+                    'UID'            => md5($event->name().$event->ID().$datetime->ID()),
158 158
                     'ORGANIZER'      => EE_Registry::instance()->CFG->organization->email,
159 159
                     'DTSTAMP'        => date(EED_Ical::iCal_datetime_format),
160 160
                     'LOCATION'       => $location,
@@ -175,9 +175,9 @@  discard block
 block discarded – undo
175 175
                 foreach ($ics_data as $key => $value) {
176 176
                     // Description is escaped differently from all all values
177 177
                     if ($key === 'DESCRIPTION') {
178
-                        $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
178
+                        $ics_data[$key] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
179 179
                     } else {
180
-                        $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value);
180
+                        $ics_data[$key] = EED_Ical::_escape_ICal_data($value);
181 181
                     }
182 182
                 }
183 183
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 
188 188
                 // set headers
189 189
                 header('Content-type: text/calendar; charset=utf-8');
190
-                header('Content-Disposition: attachment; filename="' . $filename . '"');
190
+                header('Content-Disposition: attachment; filename="'.$filename.'"');
191 191
                 header('Cache-Control: private, max-age=0, must-revalidate');
192 192
                 header('Pragma: public');
193 193
                 header('Content-Type: application/octet-stream');
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 
206 206
                 // Output all remaining values from ics_data.
207 207
                 foreach ($ics_data as $key => $value) {
208
-                    echo $key . ':' . $value . "\r\n";
208
+                    echo $key.':'.$value."\r\n";
209 209
                 }
210 210
 
211 211
                 echo "END:VEVENT\r\n";
Please login to merge, or discard this patch.