Completed
Branch models-cleanup/main (0d2dda)
by
unknown
09:34
created
core/helpers/EEH_Inflector.helper.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
     /**
53 53
      * @param string $word
54
-     * @return mixed
54
+     * @return string
55 55
      */
56 56
     public static function singularize_and_upper($word)
57 57
     {
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
     /**
247 247
      * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention
248 248
      * with the new PSR-based naming conventions
249
-     * @param $word
249
+     * @param string $word
250 250
      * @return string
251 251
      */
252 252
     public static function camelize_all_but_first($word)
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 
402 402
 
403 403
     /**
404
-     * @param $string
404
+     * @param string $string
405 405
      * @return string
406 406
      */
407 407
     public static function add_indefinite_article($string)
Please login to merge, or discard this patch.
Indentation   +380 added lines, -380 removed lines patch added patch discarded remove patch
@@ -33,384 +33,384 @@
 block discarded – undo
33 33
  */
34 34
 class EEH_Inflector
35 35
 {
36
-    // ------ CLASS METHODS ------ //
37
-    // ---- Public methods ---- //
38
-    // {{{ pluralize()
39
-
40
-    /**
41
-     * Just calls self::pluralize and strtolower on $word and returns it
42
-     * @param string $word
43
-     * @return string
44
-     */
45
-    public static function pluralize_and_lower($word)
46
-    {
47
-        return strtolower(self::pluralize($word));
48
-    }
49
-
50
-
51
-
52
-    /**
53
-     * @param string $word
54
-     * @return mixed
55
-     */
56
-    public static function singularize_and_upper($word)
57
-    {
58
-        return str_replace(' ', '_', self::humanize(self::singularize($word), 'all'));
59
-    }
60
-
61
-
62
-
63
-    /**
64
-     * Pluralizes English nouns.
65
-     *
66
-     * @access public
67
-     * @static
68
-     * @param    string    $word    English noun to pluralize
69
-     * @return string Plural noun
70
-     */
71
-    public static function pluralize($word)
72
-    {
73
-        $plural = array(
74
-            '/(quiz)$/i'               => '\1zes',
75
-            '/^(ox)$/i'                => '\1en',
76
-            '/([m|l])ouse$/i'          => '\1ice',
77
-            '/(matr|vert|ind)ix|ex$/i' => '\1ices',
78
-            '/(x|ch|ss|sh)$/i'         => '\1es',
79
-            '/([^aeiouy]|qu)ies$/i'    => '\1y',
80
-            '/([^aeiouy]|qu)y$/i'      => '\1ies',
81
-            '/(hive)$/i'               => '\1s',
82
-            '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves',
83
-            '/sis$/i'                  => 'ses',
84
-            '/([ti])um$/i'             => '\1a',
85
-            '/(buffal|tomat)o$/i'      => '\1oes',
86
-            '/(bu)s$/i'                => '\1ses',
87
-            '/(alias|status)/i'        => '\1es',
88
-            '/(octop|vir)us$/i'        => '\1i',
89
-            '/(ax|test)is$/i'          => '\1es',
90
-            '/s$/i'                    => 's',
91
-            '/$/'                      => 's');
92
-
93
-        $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep');
94
-
95
-        $irregular = array(
96
-            'person' => 'people',
97
-            'man'    => 'men',
98
-            'child'  => 'children',
99
-            'sex'    => 'sexes',
100
-            'move'   => 'moves');
101
-
102
-        $lowercased_word = strtolower($word);
103
-
104
-        foreach ($uncountable as $_uncountable) {
105
-            if (
106
-                substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter
107
-                    ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ])
108
-            ) {
109
-                return $word;
110
-            }
111
-        }
112
-
113
-        foreach ($irregular as $_plural => $_singular) {
114
-            if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) {
115
-                return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word);
116
-            }
117
-        }
118
-
119
-        foreach ($plural as $rule => $replacement) {
120
-            if (preg_match($rule, $word)) {
121
-                return preg_replace($rule, $replacement, $word);
122
-            }
123
-        }
124
-        return false;
125
-    }
126
-
127
-    // }}}
128
-    // {{{ singularize()
129
-
130
-    /**
131
-     * Singularizes English nouns.
132
-     *
133
-     * @access public
134
-     * @static
135
-     * @param    string    $word    English noun to singularize
136
-     * @return string Singular noun.
137
-     */
138
-    public static function singularize($word)
139
-    {
140
-        $singular = array(
141
-            '/(quiz)zes$/i'                                                    => '\1',
142
-            '/(matr)ices$/i'                                                   => '\1ix',
143
-            '/(vert|ind)ices$/i'                                               => '\1ex',
144
-            '/^(ox)en/i'                                                       => '\1',
145
-            '/(alias|status)es$/i'                                             => '\1',
146
-            '/([octop|vir])i$/i'                                               => '\1us',
147
-            '/(cris|ax|test)es$/i'                                             => '\1is',
148
-            '/(shoe)s$/i'                                                      => '\1',
149
-            '/(o)es$/i'                                                        => '\1',
150
-            '/(bus)es$/i'                                                      => '\1',
151
-            '/([m|l])ice$/i'                                                   => '\1ouse',
152
-            '/(x|ch|ss|sh)es$/i'                                               => '\1',
153
-            '/(m)ovies$/i'                                                     => '\1ovie',
154
-            '/(s)eries$/i'                                                     => '\1eries',
155
-            '/([^aeiouy]|qu)ies$/i'                                            => '\1y',
156
-            '/([lr])ves$/i'                                                    => '\1f',
157
-            '/(tive)s$/i'                                                      => '\1',
158
-            '/(hive)s$/i'                                                      => '\1',
159
-            '/([^f])ves$/i'                                                    => '\1fe',
160
-            '/(^analy)ses$/i'                                                  => '\1sis',
161
-            '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
162
-            '/([ti])a$/i'                                                      => '\1um',
163
-            '/(n)ews$/i'                                                       => '\1ews',
164
-            '/s$/i'                                                            => '',
165
-        );
166
-
167
-        $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep');
168
-
169
-        $irregular = array(
170
-            'person' => 'people',
171
-            'man'    => 'men',
172
-            'child'  => 'children',
173
-            'sex'    => 'sexes',
174
-            'move'   => 'moves');
175
-
176
-        $lowercased_word = strtolower($word);
177
-        foreach ($uncountable as $_uncountable) {
178
-            if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) {
179
-                return $word;
180
-            }
181
-        }
182
-
183
-        foreach ($irregular as $_plural => $_singular) {
184
-            if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) {
185
-                return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word);
186
-            }
187
-        }
188
-
189
-        foreach ($singular as $rule => $replacement) {
190
-            if (preg_match($rule, $word)) {
191
-                return preg_replace($rule, $replacement, $word);
192
-            }
193
-        }
194
-
195
-        return $word;
196
-    }
197
-
198
-    // }}}
199
-    // {{{ titleize()
200
-
201
-    /**
202
-     * Converts an underscored or CamelCase word into a English
203
-     * sentence.
204
-     *
205
-     * The titleize static function converts text like "WelcomePage",
206
-     * "welcome_page" or  "welcome page" to this "Welcome
207
-     * Page".
208
-     * If second parameter is set to 'first' it will only
209
-     * capitalize the first character of the title.
210
-     *
211
-     * @access public
212
-     * @static
213
-     * @param    string    $word    Word to format as tile
214
-     * @param    string    $uppercase    If set to 'first' it will only uppercase the
215
-     * first character. Otherwise it will uppercase all
216
-     * the words in the title.
217
-     * @return string Text formatted as title
218
-     */
219
-    public static function titleize($word, $uppercase = '')
220
-    {
221
-        $uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords';
222
-        return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word)));
223
-    }
224
-
225
-    // }}}
226
-    // {{{ camelize()
227
-
228
-    /**
229
-     * Returns given word as CamelCased
230
-     *
231
-     * Converts a word like "send_email" to "SendEmail". It
232
-     * will remove non alphanumeric character from the word, so
233
-     * "who's online" will be converted to "WhoSOnline"
234
-     *
235
-     * @access public
236
-     * @static
237
-     * @see variablize
238
-     * @param    string    $word    Word to convert to camel case
239
-     * @return string UpperCamelCasedWord
240
-     */
241
-    public static function camelize($word)
242
-    {
243
-        return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word)));
244
-    }
245
-
246
-
247
-
248
-    /**
249
-     * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention
250
-     * with the new PSR-based naming conventions
251
-     * @param $word
252
-     * @return string
253
-     */
254
-    public static function camelize_all_but_first($word)
255
-    {
256
-        return lcfirst(EEH_Inflector::camelize($word));
257
-    }
258
-    // }}}
259
-    // {{{ underscore()
260
-
261
-    /**
262
-     * Converts a word "into_it_s_underscored_version"
263
-     *
264
-     * Convert any "CamelCased" or "ordinary Word" into an
265
-     * "underscored_word".
266
-     *
267
-     * This can be really useful for creating friendly URLs.
268
-     *
269
-     * @access public
270
-     * @static
271
-     * @param    string    $word    Word to underscore
272
-     * @return string Underscored word
273
-     */
274
-    public static function underscore($word)
275
-    {
276
-        return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word))));
277
-    }
278
-
279
-    // }}}
280
-    // {{{ humanize()
281
-
282
-    /**
283
-     * Returns a human-readable string from $word
284
-     *
285
-     * Returns a human-readable string from $word, by replacing
286
-     * underscores with a space, and by upper-casing the initial
287
-     * character by default.
288
-     *
289
-     * If you need to uppercase all the words you just have to
290
-     * pass 'all' as a second parameter.
291
-     *
292
-     * @access public
293
-     * @static
294
-     * @param    string    $word    String to "humanize"
295
-     * @param    string    $uppercase    If set to 'all' it will uppercase all the words
296
-     * instead of just the first one.
297
-     * @return string Human-readable word
298
-     */
299
-    public static function humanize($word, $uppercase = '')
300
-    {
301
-        // make special exceptions for acronyms
302
-        $word = str_replace('wp_', 'WP_', $word);
303
-        $uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst';
304
-        return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word)));
305
-    }
306
-
307
-    // }}}
308
-    // {{{ variablize()
309
-
310
-    /**
311
-     * Same as camelize but first char is underscored
312
-     *
313
-     * Converts a word like "send_email" to "sendEmail". It
314
-     * will remove non alphanumeric character from the word, so
315
-     * "who's online" will be converted to "whoSOnline"
316
-     *
317
-     * @access public
318
-     * @static
319
-     * @see camelize
320
-     * @param    string    $word    Word to lowerCamelCase
321
-     * @return string Returns a lowerCamelCasedWord
322
-     */
323
-    public static function variablize($word)
324
-    {
325
-        $word = EEH_Inflector::camelize($word);
326
-        return strtolower($word[0]) . substr($word, 1);
327
-    }
328
-
329
-    // }}}
330
-    // {{{ tableize()
331
-
332
-    /**
333
-     * Converts a class name to its table name according to rails
334
-     * naming conventions.
335
-     *
336
-     * Converts "Person" to "people"
337
-     *
338
-     * @access public
339
-     * @static
340
-     * @see classify
341
-     * @param    string    $class_name    Class name for getting related table_name.
342
-     * @return string plural_table_name
343
-     */
344
-    public static function tableize($class_name)
345
-    {
346
-        return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name));
347
-    }
348
-
349
-    // }}}
350
-    // {{{ classify()
351
-
352
-    /**
353
-     * Converts a table name to its class name according to rails
354
-     * naming conventions.
355
-     *
356
-     * Converts "people" to "Person"
357
-     *
358
-     * @access public
359
-     * @static
360
-     * @see tableize
361
-     * @param    string    $table_name    Table name for getting related ClassName.
362
-     * @return string SingularClassName
363
-     */
364
-    public static function classify($table_name)
365
-    {
366
-        return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name));
367
-    }
368
-
369
-    // }}}
370
-    // {{{ ordinalize()
371
-
372
-    /**
373
-     * Converts number to its ordinal English form.
374
-     *
375
-     * This method converts 13 to 13th, 2 to 2nd ...
376
-     *
377
-     * @access public
378
-     * @static
379
-     * @param    integer    $number    Number to get its ordinal value
380
-     * @return string Ordinal representation of given string.
381
-     */
382
-    public static function ordinalize($number)
383
-    {
384
-        if (in_array(($number % 100), range(11, 13))) {
385
-            return $number . 'th';
386
-        } else {
387
-            switch (($number % 10)) {
388
-                case 1:
389
-                    return $number . 'st';
390
-                    break;
391
-                case 2:
392
-                    return $number . 'nd';
393
-                    break;
394
-                case 3:
395
-                    return $number . 'rd';
396
-                default:
397
-                    return $number . 'th';
398
-                    break;
399
-            }
400
-        }
401
-    }
402
-
403
-
404
-
405
-    /**
406
-     * @param $string
407
-     * @return string
408
-     */
409
-    public static function add_indefinite_article($string)
410
-    {
411
-        if (strtolower($string) === 'null') {
412
-            return $string;
413
-        }
414
-        return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string;
415
-    }
36
+	// ------ CLASS METHODS ------ //
37
+	// ---- Public methods ---- //
38
+	// {{{ pluralize()
39
+
40
+	/**
41
+	 * Just calls self::pluralize and strtolower on $word and returns it
42
+	 * @param string $word
43
+	 * @return string
44
+	 */
45
+	public static function pluralize_and_lower($word)
46
+	{
47
+		return strtolower(self::pluralize($word));
48
+	}
49
+
50
+
51
+
52
+	/**
53
+	 * @param string $word
54
+	 * @return mixed
55
+	 */
56
+	public static function singularize_and_upper($word)
57
+	{
58
+		return str_replace(' ', '_', self::humanize(self::singularize($word), 'all'));
59
+	}
60
+
61
+
62
+
63
+	/**
64
+	 * Pluralizes English nouns.
65
+	 *
66
+	 * @access public
67
+	 * @static
68
+	 * @param    string    $word    English noun to pluralize
69
+	 * @return string Plural noun
70
+	 */
71
+	public static function pluralize($word)
72
+	{
73
+		$plural = array(
74
+			'/(quiz)$/i'               => '\1zes',
75
+			'/^(ox)$/i'                => '\1en',
76
+			'/([m|l])ouse$/i'          => '\1ice',
77
+			'/(matr|vert|ind)ix|ex$/i' => '\1ices',
78
+			'/(x|ch|ss|sh)$/i'         => '\1es',
79
+			'/([^aeiouy]|qu)ies$/i'    => '\1y',
80
+			'/([^aeiouy]|qu)y$/i'      => '\1ies',
81
+			'/(hive)$/i'               => '\1s',
82
+			'/(?:([^f])fe|([lr])f)$/i' => '\1\2ves',
83
+			'/sis$/i'                  => 'ses',
84
+			'/([ti])um$/i'             => '\1a',
85
+			'/(buffal|tomat)o$/i'      => '\1oes',
86
+			'/(bu)s$/i'                => '\1ses',
87
+			'/(alias|status)/i'        => '\1es',
88
+			'/(octop|vir)us$/i'        => '\1i',
89
+			'/(ax|test)is$/i'          => '\1es',
90
+			'/s$/i'                    => 's',
91
+			'/$/'                      => 's');
92
+
93
+		$uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep');
94
+
95
+		$irregular = array(
96
+			'person' => 'people',
97
+			'man'    => 'men',
98
+			'child'  => 'children',
99
+			'sex'    => 'sexes',
100
+			'move'   => 'moves');
101
+
102
+		$lowercased_word = strtolower($word);
103
+
104
+		foreach ($uncountable as $_uncountable) {
105
+			if (
106
+				substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter
107
+					! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ])
108
+			) {
109
+				return $word;
110
+			}
111
+		}
112
+
113
+		foreach ($irregular as $_plural => $_singular) {
114
+			if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) {
115
+				return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word);
116
+			}
117
+		}
118
+
119
+		foreach ($plural as $rule => $replacement) {
120
+			if (preg_match($rule, $word)) {
121
+				return preg_replace($rule, $replacement, $word);
122
+			}
123
+		}
124
+		return false;
125
+	}
126
+
127
+	// }}}
128
+	// {{{ singularize()
129
+
130
+	/**
131
+	 * Singularizes English nouns.
132
+	 *
133
+	 * @access public
134
+	 * @static
135
+	 * @param    string    $word    English noun to singularize
136
+	 * @return string Singular noun.
137
+	 */
138
+	public static function singularize($word)
139
+	{
140
+		$singular = array(
141
+			'/(quiz)zes$/i'                                                    => '\1',
142
+			'/(matr)ices$/i'                                                   => '\1ix',
143
+			'/(vert|ind)ices$/i'                                               => '\1ex',
144
+			'/^(ox)en/i'                                                       => '\1',
145
+			'/(alias|status)es$/i'                                             => '\1',
146
+			'/([octop|vir])i$/i'                                               => '\1us',
147
+			'/(cris|ax|test)es$/i'                                             => '\1is',
148
+			'/(shoe)s$/i'                                                      => '\1',
149
+			'/(o)es$/i'                                                        => '\1',
150
+			'/(bus)es$/i'                                                      => '\1',
151
+			'/([m|l])ice$/i'                                                   => '\1ouse',
152
+			'/(x|ch|ss|sh)es$/i'                                               => '\1',
153
+			'/(m)ovies$/i'                                                     => '\1ovie',
154
+			'/(s)eries$/i'                                                     => '\1eries',
155
+			'/([^aeiouy]|qu)ies$/i'                                            => '\1y',
156
+			'/([lr])ves$/i'                                                    => '\1f',
157
+			'/(tive)s$/i'                                                      => '\1',
158
+			'/(hive)s$/i'                                                      => '\1',
159
+			'/([^f])ves$/i'                                                    => '\1fe',
160
+			'/(^analy)ses$/i'                                                  => '\1sis',
161
+			'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
162
+			'/([ti])a$/i'                                                      => '\1um',
163
+			'/(n)ews$/i'                                                       => '\1ews',
164
+			'/s$/i'                                                            => '',
165
+		);
166
+
167
+		$uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep');
168
+
169
+		$irregular = array(
170
+			'person' => 'people',
171
+			'man'    => 'men',
172
+			'child'  => 'children',
173
+			'sex'    => 'sexes',
174
+			'move'   => 'moves');
175
+
176
+		$lowercased_word = strtolower($word);
177
+		foreach ($uncountable as $_uncountable) {
178
+			if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) {
179
+				return $word;
180
+			}
181
+		}
182
+
183
+		foreach ($irregular as $_plural => $_singular) {
184
+			if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) {
185
+				return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word);
186
+			}
187
+		}
188
+
189
+		foreach ($singular as $rule => $replacement) {
190
+			if (preg_match($rule, $word)) {
191
+				return preg_replace($rule, $replacement, $word);
192
+			}
193
+		}
194
+
195
+		return $word;
196
+	}
197
+
198
+	// }}}
199
+	// {{{ titleize()
200
+
201
+	/**
202
+	 * Converts an underscored or CamelCase word into a English
203
+	 * sentence.
204
+	 *
205
+	 * The titleize static function converts text like "WelcomePage",
206
+	 * "welcome_page" or  "welcome page" to this "Welcome
207
+	 * Page".
208
+	 * If second parameter is set to 'first' it will only
209
+	 * capitalize the first character of the title.
210
+	 *
211
+	 * @access public
212
+	 * @static
213
+	 * @param    string    $word    Word to format as tile
214
+	 * @param    string    $uppercase    If set to 'first' it will only uppercase the
215
+	 * first character. Otherwise it will uppercase all
216
+	 * the words in the title.
217
+	 * @return string Text formatted as title
218
+	 */
219
+	public static function titleize($word, $uppercase = '')
220
+	{
221
+		$uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords';
222
+		return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word)));
223
+	}
224
+
225
+	// }}}
226
+	// {{{ camelize()
227
+
228
+	/**
229
+	 * Returns given word as CamelCased
230
+	 *
231
+	 * Converts a word like "send_email" to "SendEmail". It
232
+	 * will remove non alphanumeric character from the word, so
233
+	 * "who's online" will be converted to "WhoSOnline"
234
+	 *
235
+	 * @access public
236
+	 * @static
237
+	 * @see variablize
238
+	 * @param    string    $word    Word to convert to camel case
239
+	 * @return string UpperCamelCasedWord
240
+	 */
241
+	public static function camelize($word)
242
+	{
243
+		return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word)));
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention
250
+	 * with the new PSR-based naming conventions
251
+	 * @param $word
252
+	 * @return string
253
+	 */
254
+	public static function camelize_all_but_first($word)
255
+	{
256
+		return lcfirst(EEH_Inflector::camelize($word));
257
+	}
258
+	// }}}
259
+	// {{{ underscore()
260
+
261
+	/**
262
+	 * Converts a word "into_it_s_underscored_version"
263
+	 *
264
+	 * Convert any "CamelCased" or "ordinary Word" into an
265
+	 * "underscored_word".
266
+	 *
267
+	 * This can be really useful for creating friendly URLs.
268
+	 *
269
+	 * @access public
270
+	 * @static
271
+	 * @param    string    $word    Word to underscore
272
+	 * @return string Underscored word
273
+	 */
274
+	public static function underscore($word)
275
+	{
276
+		return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word))));
277
+	}
278
+
279
+	// }}}
280
+	// {{{ humanize()
281
+
282
+	/**
283
+	 * Returns a human-readable string from $word
284
+	 *
285
+	 * Returns a human-readable string from $word, by replacing
286
+	 * underscores with a space, and by upper-casing the initial
287
+	 * character by default.
288
+	 *
289
+	 * If you need to uppercase all the words you just have to
290
+	 * pass 'all' as a second parameter.
291
+	 *
292
+	 * @access public
293
+	 * @static
294
+	 * @param    string    $word    String to "humanize"
295
+	 * @param    string    $uppercase    If set to 'all' it will uppercase all the words
296
+	 * instead of just the first one.
297
+	 * @return string Human-readable word
298
+	 */
299
+	public static function humanize($word, $uppercase = '')
300
+	{
301
+		// make special exceptions for acronyms
302
+		$word = str_replace('wp_', 'WP_', $word);
303
+		$uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst';
304
+		return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word)));
305
+	}
306
+
307
+	// }}}
308
+	// {{{ variablize()
309
+
310
+	/**
311
+	 * Same as camelize but first char is underscored
312
+	 *
313
+	 * Converts a word like "send_email" to "sendEmail". It
314
+	 * will remove non alphanumeric character from the word, so
315
+	 * "who's online" will be converted to "whoSOnline"
316
+	 *
317
+	 * @access public
318
+	 * @static
319
+	 * @see camelize
320
+	 * @param    string    $word    Word to lowerCamelCase
321
+	 * @return string Returns a lowerCamelCasedWord
322
+	 */
323
+	public static function variablize($word)
324
+	{
325
+		$word = EEH_Inflector::camelize($word);
326
+		return strtolower($word[0]) . substr($word, 1);
327
+	}
328
+
329
+	// }}}
330
+	// {{{ tableize()
331
+
332
+	/**
333
+	 * Converts a class name to its table name according to rails
334
+	 * naming conventions.
335
+	 *
336
+	 * Converts "Person" to "people"
337
+	 *
338
+	 * @access public
339
+	 * @static
340
+	 * @see classify
341
+	 * @param    string    $class_name    Class name for getting related table_name.
342
+	 * @return string plural_table_name
343
+	 */
344
+	public static function tableize($class_name)
345
+	{
346
+		return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name));
347
+	}
348
+
349
+	// }}}
350
+	// {{{ classify()
351
+
352
+	/**
353
+	 * Converts a table name to its class name according to rails
354
+	 * naming conventions.
355
+	 *
356
+	 * Converts "people" to "Person"
357
+	 *
358
+	 * @access public
359
+	 * @static
360
+	 * @see tableize
361
+	 * @param    string    $table_name    Table name for getting related ClassName.
362
+	 * @return string SingularClassName
363
+	 */
364
+	public static function classify($table_name)
365
+	{
366
+		return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name));
367
+	}
368
+
369
+	// }}}
370
+	// {{{ ordinalize()
371
+
372
+	/**
373
+	 * Converts number to its ordinal English form.
374
+	 *
375
+	 * This method converts 13 to 13th, 2 to 2nd ...
376
+	 *
377
+	 * @access public
378
+	 * @static
379
+	 * @param    integer    $number    Number to get its ordinal value
380
+	 * @return string Ordinal representation of given string.
381
+	 */
382
+	public static function ordinalize($number)
383
+	{
384
+		if (in_array(($number % 100), range(11, 13))) {
385
+			return $number . 'th';
386
+		} else {
387
+			switch (($number % 10)) {
388
+				case 1:
389
+					return $number . 'st';
390
+					break;
391
+				case 2:
392
+					return $number . 'nd';
393
+					break;
394
+				case 3:
395
+					return $number . 'rd';
396
+				default:
397
+					return $number . 'th';
398
+					break;
399
+			}
400
+		}
401
+	}
402
+
403
+
404
+
405
+	/**
406
+	 * @param $string
407
+	 * @return string
408
+	 */
409
+	public static function add_indefinite_article($string)
410
+	{
411
+		if (strtolower($string) === 'null') {
412
+			return $string;
413
+		}
414
+		return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string;
415
+	}
416 416
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -104,15 +104,15 @@  discard block
 block discarded – undo
104 104
         foreach ($uncountable as $_uncountable) {
105 105
             if (
106 106
                 substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter
107
-                    ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ])
107
+                    ! ctype_alpha($lowercased_word[strlen($lowercased_word) - strlen($_uncountable)])
108 108
             ) {
109 109
                 return $word;
110 110
             }
111 111
         }
112 112
 
113 113
         foreach ($irregular as $_plural => $_singular) {
114
-            if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) {
115
-                return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word);
114
+            if (preg_match('/('.$_plural.')$/i', $word, $arr)) {
115
+                return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word);
116 116
             }
117 117
         }
118 118
 
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
         }
182 182
 
183 183
         foreach ($irregular as $_plural => $_singular) {
184
-            if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) {
185
-                return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word);
184
+            if (preg_match('/('.$_singular.')$/i', $word, $arr)) {
185
+                return preg_replace('/('.$_singular.')$/i', substr($arr[0], 0, 1).substr($_plural, 1), $word);
186 186
             }
187 187
         }
188 188
 
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
     public static function variablize($word)
324 324
     {
325 325
         $word = EEH_Inflector::camelize($word);
326
-        return strtolower($word[0]) . substr($word, 1);
326
+        return strtolower($word[0]).substr($word, 1);
327 327
     }
328 328
 
329 329
     // }}}
@@ -382,19 +382,19 @@  discard block
 block discarded – undo
382 382
     public static function ordinalize($number)
383 383
     {
384 384
         if (in_array(($number % 100), range(11, 13))) {
385
-            return $number . 'th';
385
+            return $number.'th';
386 386
         } else {
387 387
             switch (($number % 10)) {
388 388
                 case 1:
389
-                    return $number . 'st';
389
+                    return $number.'st';
390 390
                     break;
391 391
                 case 2:
392
-                    return $number . 'nd';
392
+                    return $number.'nd';
393 393
                     break;
394 394
                 case 3:
395
-                    return $number . 'rd';
395
+                    return $number.'rd';
396 396
                 default:
397
-                    return $number . 'th';
397
+                    return $number.'th';
398 398
                     break;
399 399
             }
400 400
         }
@@ -411,6 +411,6 @@  discard block
 block discarded – undo
411 411
         if (strtolower($string) === 'null') {
412 412
             return $string;
413 413
         }
414
-        return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string;
414
+        return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ').$string;
415 415
     }
416 416
 }
Please login to merge, or discard this patch.
core/helpers/EEH_MSG_Template.helper.php 3 patches
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      * Updates all message templates matching the incoming messengers and message types to active status.
132 132
      *
133 133
      * @static
134
-     * @param  array  $messenger_names     Messenger slug
134
+     * @param  string[]  $messenger_names     Messenger slug
135 135
      * @param  array  $message_type_names  Message type slug
136 136
      * @return  int                         count of updated records.
137 137
      */
@@ -451,6 +451,7 @@  discard block
 block discarded – undo
451 451
      * @param EE_Registration | null $registration  The registration object must be included if this
452 452
      *                                              is going to be a registration trigger url.
453 453
      * @param string $sending_messenger             The (optional) sending messenger for the url.
454
+     * @param EE_Registration $registration
454 455
      *
455 456
      * @return string
456 457
      * @throws EE_Error
@@ -1018,8 +1019,8 @@  discard block
 block discarded – undo
1018 1019
     /**
1019 1020
      * @param \EE_messenger    $messenger
1020 1021
      * @param \EE_message_type $message_type
1021
-     * @param                  $GRP_ID
1022
-     * @param                  $global
1022
+     * @param                  integer $GRP_ID
1023
+     * @param                  boolean $global
1023 1024
      * @return array|mixed
1024 1025
      */
1025 1026
     protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
Please login to merge, or discard this patch.
Indentation   +1231 added lines, -1231 removed lines patch added patch discarded remove patch
@@ -14,1235 +14,1235 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    /**
18
-     * Holds a collection of EE_Message_Template_Pack objects.
19
-     * @type EE_Messages_Template_Pack_Collection
20
-     */
21
-    protected static $_template_pack_collection;
22
-
23
-
24
-
25
-
26
-    private static function _set_autoloader()
27
-    {
28
-        EED_Messages::set_autoloaders();
29
-    }
30
-
31
-
32
-    /**
33
-     * generate_new_templates
34
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will automatically create the defaults for the event.  The user would then be redirected to edit the default context for the event.
35
-     *
36
-     * @access protected
37
-     * @param  string $messenger     the messenger we are generating templates for
38
-     * @param array   $message_types array of message types that the templates are generated for.
39
-     * @param int     $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID to use as the base for the new generated template.
40
-     * @param bool    $global        true indicates generating templates on messenger activation. false requires GRP_ID for event specific template generation.
41
-     * @throws \EE_Error
42
-     * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array for templates
43
-     *                that are generated.  If this is an empty array then it means no templates were generated which usually
44
-     *                means there was an error.  Anything in the array with an empty value for `MTP_context` means that it
45
-     *                was not a new generated template but just reactivated (which only happens for global templates that
46
-     *                already exist in the database.
47
-     */
48
-    public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
49
-    {
50
-        // make sure message_type is an array.
51
-        $message_types = (array) $message_types;
52
-        $templates = array();
53
-
54
-        if (empty($messenger)) {
55
-            throw new EE_Error(__('We need a messenger to generate templates!', 'event_espresso'));
56
-        }
57
-
58
-        // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
59
-        if (empty($message_types)) {
60
-            throw new EE_Error(__('We need at least one message type to generate templates!', 'event_espresso'));
61
-        }
62
-
63
-        EEH_MSG_Template::_set_autoloader();
64
-        foreach ($message_types as $message_type) {
65
-            // if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
66
-            if ($global && empty($GRP_ID)) {
67
-                $GRP_ID = EEM_Message_Template_Group::instance()->get_one(
68
-                    array(
69
-                        array(
70
-                            'MTP_messenger'    => $messenger,
71
-                            'MTP_message_type' => $message_type,
72
-                            'MTP_is_global'    => true,
73
-                        ),
74
-                    )
75
-                );
76
-                $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
77
-            }
78
-            // if this is global template generation.
79
-            // First let's determine if we already HAVE global templates for this messenger and message_type combination.
80
-            //  If we do then NO generation!!
81
-            if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
82
-                $templates[] = array(
83
-                    'GRP_ID' => $GRP_ID,
84
-                    'MTP_context' => '',
85
-                );
86
-                // we already have generated templates for this so let's go to the next message type.
87
-                continue;
88
-            }
89
-            $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
90
-
91
-            if (! $new_message_template_group) {
92
-                continue;
93
-            }
94
-            $templates[] = $new_message_template_group;
95
-        }
96
-
97
-        return $templates;
98
-    }
99
-
100
-
101
-    /**
102
-     * The purpose of this method is to determine if there are already generated templates in the database for the given variables.
103
-     * @param  string $messenger     messenger
104
-     * @param  string $message_type message type
105
-     * @param  int $GRP_ID        GRP ID ( if a custom template) (if not provided then we're just doing global template check)
106
-     * @return bool                true = generated, false = hasn't been generated.
107
-     */
108
-    public static function already_generated($messenger, $message_type, $GRP_ID = 0)
109
-    {
110
-        EEH_MSG_Template::_set_autoloader();
111
-        // what method we use depends on whether we have an GRP_ID or not
112
-        $count = empty($GRP_ID)
113
-            ? EEM_Message_Template::instance()->count(
114
-                array(
115
-                    array(
116
-                        'Message_Template_Group.MTP_messenger'    => $messenger,
117
-                        'Message_Template_Group.MTP_message_type' => $message_type,
118
-                        'Message_Template_Group.MTP_is_global'    => true
119
-                    )
120
-                )
121
-            )
122
-            : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
123
-
124
-        return $count > 0;
125
-    }
126
-
127
-
128
-
129
-
130
-    /**
131
-     * Updates all message templates matching the incoming messengers and message types to active status.
132
-     *
133
-     * @static
134
-     * @param  array  $messenger_names     Messenger slug
135
-     * @param  array  $message_type_names  Message type slug
136
-     * @return  int                         count of updated records.
137
-     */
138
-    public static function update_to_active($messenger_names, $message_type_names)
139
-    {
140
-        $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
141
-        $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
142
-        return EEM_Message_Template_Group::instance()->update(
143
-            array( 'MTP_is_active' => 1 ),
144
-            array(
145
-                array(
146
-                    'MTP_messenger'     => array( 'IN', $messenger_names ),
147
-                    'MTP_message_type'  => array( 'IN', $message_type_names )
148
-                )
149
-            )
150
-        );
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Updates all message template groups matching the incoming arguments to inactive status.
157
-     *
158
-     * @static
159
-     * @param array $messenger_names    The messenger slugs.
160
-     *                              If empty then all templates matching the message types are marked inactive.
161
-     *                              Otherwise only templates matching the messengers and message types.
162
-     * @param array $message_type_names     The message type slugs.
163
-     *                              If empty then all templates matching the messengers are marked inactive.
164
-     *                              Otherwise only templates matching the messengers and message types.
165
-     *
166
-     * @return int  count of updated records.
167
-     */
168
-    public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
169
-    {
170
-        return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
171
-            $messenger_names,
172
-            $message_type_names
173
-        );
174
-    }
175
-
176
-
177
-    /**
178
-     * The purpose of this function is to return all installed message objects
179
-     * (messengers and message type regardless of whether they are ACTIVE or not)
180
-     *
181
-     * @deprecated 4.9.0
182
-     * @static
183
-     * @param string $type
184
-     * @return array array consisting of installed messenger objects and installed message type objects.
185
-     */
186
-    public static function get_installed_message_objects($type = 'all')
187
-    {
188
-        self::_set_autoloader();
189
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
190
-        return array(
191
-            'messenger' => $message_resource_manager->installed_messengers(),
192
-            'message_type' => $message_resource_manager->installed_message_types()
193
-        );
194
-    }
195
-
196
-
197
-    /**
198
-     * This will return an array of shortcodes => labels from the
199
-     * messenger and message_type objects associated with this
200
-     * template.
201
-     *
202
-     * @since 4.3.0
203
-     *
204
-     * @param string $message_type
205
-     * @param string $messenger
206
-     * @param array  $fields    What fields we're returning valid shortcodes for.
207
-     *                          If empty then we assume all fields are to be returned. Optional.
208
-     * @param string $context   What context we're going to return shortcodes for. Optional.
209
-     * @param bool $merged      If TRUE then we don't return shortcodes indexed by field,
210
-     *                          but instead an array of the unique shortcodes for all the given ( or all) fields.
211
-     *                          Optional.
212
-     * @throws \EE_Error
213
-     * @return mixed (array|bool) an array of shortcodes in the format
214
-     *                                              array( '[shortcode] => 'label')
215
-     *                                              OR
216
-     *                                              FALSE if no shortcodes found.
217
-     */
218
-    public static function get_shortcodes(
219
-        $message_type,
220
-        $messenger,
221
-        $fields = array(),
222
-        $context = 'admin',
223
-        $merged = false
224
-    ) {
225
-        $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
226
-        $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
227
-        /** @var EE_Message_Resource_Manager $message_resource_manager */
228
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
229
-        // convert slug to object
230
-        $messenger = $message_resource_manager->get_messenger($messenger);
231
-
232
-        // if messenger isn't a EE_messenger resource then bail.
233
-        if (! $messenger instanceof EE_messenger) {
234
-            return array();
235
-        }
236
-
237
-        // validate class for getting our list of shortcodes
238
-        $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
239
-        if (! class_exists($classname)) {
240
-            $msg[] = __('The Validator class was unable to load', 'event_espresso');
241
-            $msg[] = sprintf(
242
-                __('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
243
-                $classname
244
-            );
245
-            throw new EE_Error(implode('||', $msg));
246
-        }
247
-
248
-        /** @type EE_Messages_Validator $_VLD */
249
-        $_VLD = new $classname(array(), $context);
250
-        $valid_shortcodes = $_VLD->get_validators();
251
-
252
-        // let's make sure we're only getting the shortcode part of the validators
253
-        $shortcodes = array();
254
-        foreach ($valid_shortcodes as $field => $validators) {
255
-            $shortcodes[ $field ] = $validators['shortcodes'];
256
-        }
257
-        $valid_shortcodes = $shortcodes;
258
-
259
-        // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
260
-        if (! empty($fields)) {
261
-            $specified_shortcodes = array();
262
-            foreach ($fields as $field) {
263
-                if (isset($valid_shortcodes[ $field ])) {
264
-                    $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
265
-                }
266
-            }
267
-            $valid_shortcodes = $specified_shortcodes;
268
-        }
269
-
270
-        // if not merged then let's replace the fields with the localized fields
271
-        if (! $merged) {
272
-            // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
273
-            $field_settings = $messenger->get_template_fields();
274
-            $localized = array();
275
-            foreach ($valid_shortcodes as $field => $shortcodes) {
276
-                // get localized field label
277
-                if (isset($field_settings[ $field ])) {
278
-                    // possible that this is used as a main field.
279
-                    if (empty($field_settings[ $field ])) {
280
-                        if (isset($field_settings['extra'][ $field ])) {
281
-                            $_field = $field_settings['extra'][ $field ]['main']['label'];
282
-                        } else {
283
-                            $_field = $field;
284
-                        }
285
-                    } else {
286
-                        $_field = $field_settings[ $field ]['label'];
287
-                    }
288
-                } elseif (isset($field_settings['extra'])) {
289
-                    // loop through extra "main fields" and see if any of their children have our field
290
-                    foreach ($field_settings['extra'] as $main_field => $fields) {
291
-                        if (isset($fields[ $field ])) {
292
-                            $_field = $fields[ $field ]['label'];
293
-                        } else {
294
-                            $_field = $field;
295
-                        }
296
-                    }
297
-                } else {
298
-                    $_field = $field;
299
-                }
300
-                if (isset($_field)) {
301
-                    $localized[ (string) $_field ] = $shortcodes;
302
-                }
303
-            }
304
-            $valid_shortcodes = $localized;
305
-        }
306
-
307
-        // if $merged then let's merge all the shortcodes into one list NOT indexed by field.
308
-        if ($merged) {
309
-            $merged_codes = array();
310
-            foreach ($valid_shortcodes as $field => $shortcode) {
311
-                foreach ($shortcode as $code => $label) {
312
-                    if (isset($merged_codes[ $code ])) {
313
-                        continue;
314
-                    } else {
315
-                        $merged_codes[ $code ] = $label;
316
-                    }
317
-                }
318
-            }
319
-            $valid_shortcodes = $merged_codes;
320
-        }
321
-
322
-        return $valid_shortcodes;
323
-    }
324
-
325
-
326
-    /**
327
-     * Get Messenger object.
328
-     *
329
-     * @since 4.3.0
330
-     * @deprecated 4.9.0
331
-     * @param string $messenger messenger slug for the messenger object we want to retrieve.
332
-     * @throws \EE_Error
333
-     * @return EE_messenger
334
-     */
335
-    public static function messenger_obj($messenger)
336
-    {
337
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
338
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
339
-        return $Message_Resource_Manager->get_messenger($messenger);
340
-    }
341
-
342
-
343
-    /**
344
-     * get Message type object
345
-     *
346
-     * @since 4.3.0
347
-     * @deprecated 4.9.0
348
-     * @param string $message_type the slug for the message type object to retrieve
349
-     * @throws \EE_Error
350
-     * @return EE_message_type
351
-     */
352
-    public static function message_type_obj($message_type)
353
-    {
354
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
355
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
356
-        return $Message_Resource_Manager->get_message_type($message_type);
357
-    }
358
-
359
-
360
-
361
-
362
-
363
-    /**
364
-     * Given a message_type slug, will return whether that message type is active in the system or not.
365
-     *
366
-     * @since    4.3.0
367
-     * @param  string   $message_type message type to check for.
368
-     * @return boolean
369
-     */
370
-    public static function is_mt_active($message_type)
371
-    {
372
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
373
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
374
-        $active_mts = $Message_Resource_Manager->list_of_active_message_types();
375
-        return in_array($message_type, $active_mts);
376
-    }
377
-
378
-
379
-
380
-    /**
381
-     * Given a messenger slug, will return whether that messenger is active in the system or not.
382
-     *
383
-     * @since    4.3.0
384
-     *
385
-     * @param  string  $messenger slug for messenger to check.
386
-     * @return boolean
387
-     */
388
-    public static function is_messenger_active($messenger)
389
-    {
390
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
391
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
392
-        $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
393
-        return $active_messenger instanceof EE_messenger ? true : false;
394
-    }
395
-
396
-
397
-
398
-    /**
399
-     * Used to return active messengers array stored in the wp options table.
400
-     * If no value is present in the option then an empty array is returned.
401
-     *
402
-     * @deprecated 4.9
403
-     * @since 4.3.1
404
-     *
405
-     * @return array
406
-     */
407
-    public static function get_active_messengers_in_db()
408
-    {
409
-        EE_Error::doing_it_wrong(
410
-            __METHOD__,
411
-            __('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
412
-            '4.9.0'
413
-        );
414
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
415
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
416
-        return $Message_Resource_Manager->get_active_messengers_option();
417
-    }
418
-
419
-
420
-
421
-
422
-    /**
423
-     * Used to update the active messengers array stored in the wp options table.
424
-     *
425
-     * @since 4.3.1
426
-     * @deprecated 4.9.0
427
-     *
428
-     * @param array $data_to_save Incoming data to save.
429
-     *
430
-     * @return bool FALSE if not updated, TRUE if updated.
431
-     */
432
-    public static function update_active_messengers_in_db($data_to_save)
433
-    {
434
-        EE_Error::doing_it_wrong(
435
-            __METHOD__,
436
-            __('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
437
-            '4.9.0'
438
-        );
439
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
440
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
441
-        return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
442
-    }
443
-
444
-
445
-    /**
446
-     * This does some validation of incoming params, determines what type of url is being prepped and returns the
447
-     * appropriate url trigger
448
-     *
449
-     * @param EE_message_type $message_type
450
-     * @param EE_Message $message
451
-     * @param EE_Registration | null $registration  The registration object must be included if this
452
-     *                                              is going to be a registration trigger url.
453
-     * @param string $sending_messenger             The (optional) sending messenger for the url.
454
-     *
455
-     * @return string
456
-     * @throws EE_Error
457
-     */
458
-    public static function get_url_trigger(
459
-        EE_message_type $message_type,
460
-        EE_Message $message,
461
-        $registration = null,
462
-        $sending_messenger = ''
463
-    ) {
464
-        // first determine if the url can be to the EE_Message object.
465
-        if (! $message_type->always_generate()) {
466
-            return EEH_MSG_Template::generate_browser_trigger($message);
467
-        }
468
-
469
-        // if $registration object is not valid then exit early because there's nothing that can be generated.
470
-        if (! $registration instanceof EE_Registration) {
471
-            throw new EE_Error(
472
-                __('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
473
-            );
474
-        }
475
-
476
-        // validate given context
477
-        $contexts = $message_type->get_contexts();
478
-        if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
479
-            throw new EE_Error(
480
-                sprintf(
481
-                    __('The context %s is not a valid context for %s.', 'event_espresso'),
482
-                    $message->context(),
483
-                    get_class($message_type)
484
-                )
485
-            );
486
-        }
487
-
488
-        // valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
489
-        if (! empty($sending_messenger)) {
490
-            $with_messengers = $message_type->with_messengers();
491
-            if (
492
-                ! isset($with_messengers[ $message->messenger() ])
493
-                 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
494
-            ) {
495
-                throw new EE_Error(
496
-                    sprintf(
497
-                        __(
498
-                            'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
499
-                            'event_espresso'
500
-                        ),
501
-                        $sending_messenger,
502
-                        get_class($message_type)
503
-                    )
504
-                );
505
-            }
506
-        } else {
507
-            $sending_messenger = $message->messenger();
508
-        }
509
-        return EEH_MSG_Template::generate_url_trigger(
510
-            $sending_messenger,
511
-            $message->messenger(),
512
-            $message->context(),
513
-            $message->message_type(),
514
-            $registration,
515
-            $message->GRP_ID()
516
-        );
517
-    }
518
-
519
-
520
-    /**
521
-     * This returns the url for triggering a in browser view of a specific EE_Message object.
522
-     * @param EE_Message $message
523
-     * @return string.
524
-     */
525
-    public static function generate_browser_trigger(EE_Message $message)
526
-    {
527
-        $query_args = array(
528
-            'ee' => 'msg_browser_trigger',
529
-            'token' => $message->MSG_token()
530
-        );
531
-        return apply_filters(
532
-            'FHEE__EEH_MSG_Template__generate_browser_trigger',
533
-            add_query_arg($query_args, site_url()),
534
-            $message
535
-        );
536
-    }
537
-
538
-
539
-
540
-
541
-
542
-
543
-    /**
544
-     * This returns the url for triggering an in browser view of the error saved on the incoming message object.
545
-     * @param EE_Message $message
546
-     * @return string
547
-     */
548
-    public static function generate_error_display_trigger(EE_Message $message)
549
-    {
550
-        return apply_filters(
551
-            'FHEE__EEH_MSG_Template__generate_error_display_trigger',
552
-            add_query_arg(
553
-                array(
554
-                    'ee' => 'msg_browser_error_trigger',
555
-                    'token' => $message->MSG_token()
556
-                ),
557
-                site_url()
558
-            ),
559
-            $message
560
-        );
561
-    }
562
-
563
-
564
-
565
-
566
-
567
-
568
-    /**
569
-     * This generates a url trigger for the msg_url_trigger route using the given arguments
570
-     *
571
-     * @param string          $sending_messenger    The sending messenger slug.
572
-     * @param string          $generating_messenger The generating messenger slug.
573
-     * @param string          $context              The context for the template.
574
-     * @param string          $message_type         The message type slug
575
-     * @param EE_Registration $registration
576
-     * @param integer          $message_template_group id   The EE_Message_Template_Group ID for the template.
577
-     * @param integer          $data_id     The id to the EE_Base_Class for getting the data used by the trigger.
578
-     * @return string          The generated url.
579
-     */
580
-    public static function generate_url_trigger(
581
-        $sending_messenger,
582
-        $generating_messenger,
583
-        $context,
584
-        $message_type,
585
-        EE_Registration $registration,
586
-        $message_template_group,
587
-        $data_id = 0
588
-    ) {
589
-        $query_args = array(
590
-            'ee' => 'msg_url_trigger',
591
-            'snd_msgr' => $sending_messenger,
592
-            'gen_msgr' => $generating_messenger,
593
-            'message_type' => $message_type,
594
-            'context' => $context,
595
-            'token' => $registration->reg_url_link(),
596
-            'GRP_ID' => $message_template_group,
597
-            'id' => $data_id
598
-            );
599
-        $url = add_query_arg($query_args, get_home_url());
600
-
601
-        // made it here so now we can just get the url and filter it.  Filtered globally and by message type.
602
-        $url = apply_filters(
603
-            'FHEE__EEH_MSG_Template__generate_url_trigger',
604
-            $url,
605
-            $sending_messenger,
606
-            $generating_messenger,
607
-            $context,
608
-            $message_type,
609
-            $registration,
610
-            $message_template_group,
611
-            $data_id
612
-        );
613
-        return $url;
614
-    }
615
-
616
-
617
-
618
-
619
-    /**
620
-     * Return the specific css for the action icon given.
621
-     *
622
-     * @since 4.9.0
623
-     *
624
-     * @param string $type  What action to return.
625
-     * @return string
626
-     */
627
-    public static function get_message_action_icon($type)
628
-    {
629
-        $action_icons = self::get_message_action_icons();
630
-        return isset($action_icons[ $type ]) ? $action_icons[ $type ] : '';
631
-    }
632
-
633
-
634
-    /**
635
-     * This is used for retrieving the css classes used for the icons representing message actions.
636
-     *
637
-     * @since 4.9.0
638
-     *
639
-     * @return array
640
-     */
641
-    public static function get_message_action_icons()
642
-    {
643
-        return apply_filters(
644
-            'FHEE__EEH_MSG_Template__message_action_icons',
645
-            array(
646
-                'view' => array(
647
-                    'label' => __('View Message', 'event_espresso'),
648
-                    'css_class' => 'dashicons dashicons-welcome-view-site',
649
-                ),
650
-                'error' => array(
651
-                    'label' => __('View Error Message', 'event_espresso'),
652
-                    'css_class' => 'dashicons dashicons-info',
653
-                ),
654
-                'see_notifications_for' => array(
655
-                    'label' => __('View Related Messages', 'event_espresso'),
656
-                    'css_class' => 'dashicons dashicons-megaphone',
657
-                ),
658
-                'generate_now' => array(
659
-                    'label' => __('Generate the message now.', 'event_espresso'),
660
-                    'css_class' => 'dashicons dashicons-admin-tools',
661
-                ),
662
-                'send_now' => array(
663
-                    'label' => __('Send Immediately', 'event_espresso'),
664
-                    'css_class' => 'dashicons dashicons-controls-forward',
665
-                ),
666
-                'queue_for_resending' => array(
667
-                    'label' => __('Queue for Resending', 'event_espresso'),
668
-                    'css_class' => 'dashicons dashicons-controls-repeat',
669
-                ),
670
-                'view_transaction' => array(
671
-                    'label' => __('View related Transaction', 'event_espresso'),
672
-                    'css_class' => 'dashicons dashicons-cart',
673
-                )
674
-            )
675
-        );
676
-    }
677
-
678
-
679
-    /**
680
-     * This returns the url for a given action related to EE_Message.
681
-     *
682
-     * @since 4.9.0
683
-     *
684
-     * @param string $type  What type of action to return the url for.
685
-     * @param EE_Message $message   Required for generating the correct url for some types.
686
-     * @param array  $query_params   Any additional query params to be included with the generated url.
687
-     *
688
-     * @return string
689
-     */
690
-    public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
691
-    {
692
-        $action_urls = self::get_message_action_urls($message, $query_params);
693
-        return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
694
-    }
695
-
696
-
697
-
698
-    /**
699
-     * This returns all the current urls for EE_Message actions.
700
-     *
701
-     * @since 4.9.0
702
-     *
703
-     * @param  EE_Message   $message    The EE_Message object required to generate correct urls for some types.
704
-     * @param  array    $query_params   Any additional query_params to be included with the generated url.
705
-     *
706
-     * @return array
707
-     */
708
-    public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
709
-    {
710
-        EE_Registry::instance()->load_helper('URL');
711
-        // if $message is not an instance of EE_Message then let's just do a dummy.
712
-        $message = empty($message) ? EE_Message_Factory::create() : $message;
713
-        $action_urls =  apply_filters(
714
-            'FHEE__EEH_MSG_Template__get_message_action_url',
715
-            array(
716
-                'view' => EEH_MSG_Template::generate_browser_trigger($message),
717
-                'error' => EEH_MSG_Template::generate_error_display_trigger($message),
718
-                'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
719
-                    array_merge(
720
-                        array(
721
-                            'page' => 'espresso_messages',
722
-                            'action' => 'default',
723
-                            'filterby' => 1,
724
-                        ),
725
-                        $query_params
726
-                    ),
727
-                    admin_url('admin.php')
728
-                ),
729
-                'generate_now' => EEH_URL::add_query_args_and_nonce(
730
-                    array(
731
-                        'page' => 'espresso_messages',
732
-                        'action' => 'generate_now',
733
-                        'MSG_ID' => $message->ID()
734
-                    ),
735
-                    admin_url('admin.php')
736
-                ),
737
-                'send_now' => EEH_URL::add_query_args_and_nonce(
738
-                    array(
739
-                        'page' => 'espresso_messages',
740
-                        'action' => 'send_now',
741
-                        'MSG_ID' => $message->ID()
742
-                    ),
743
-                    admin_url('admin.php')
744
-                ),
745
-                'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
746
-                    array(
747
-                        'page' => 'espresso_messages',
748
-                        'action' => 'queue_for_resending',
749
-                        'MSG_ID' => $message->ID()
750
-                    ),
751
-                    admin_url('admin.php')
752
-                ),
753
-            )
754
-        );
755
-        if (
756
-            $message->TXN_ID() > 0
757
-            && EE_Registry::instance()->CAP->current_user_can(
758
-                'ee_read_transaction',
759
-                'espresso_transactions_default',
760
-                $message->TXN_ID()
761
-            )
762
-        ) {
763
-            $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
764
-                array(
765
-                    'page' => 'espresso_transactions',
766
-                    'action' => 'view_transaction',
767
-                    'TXN_ID' => $message->TXN_ID()
768
-                ),
769
-                admin_url('admin.php')
770
-            );
771
-        } else {
772
-            $action_urls['view_transaction'] = '';
773
-        }
774
-        return $action_urls;
775
-    }
776
-
777
-
778
-    /**
779
-     * This returns a generated link html including the icon used for the action link for EE_Message actions.
780
-     *
781
-     * @since 4.9.0
782
-     *
783
-     * @param string $type What type of action the link is for (if invalid type is passed in then an
784
-     *                     empty string is returned)
785
-     * @param EE_Message|null $message  The EE_Message object (required for some actions to generate correctly)
786
-     * @param array           $query_params Any extra query params to include in the generated link.
787
-     *
788
-     * @return string
789
-     */
790
-    public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
791
-    {
792
-        $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
793
-        $icon_css = EEH_MSG_Template::get_message_action_icon($type);
794
-        $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
795
-
796
-        if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
797
-            return '';
798
-        }
799
-
800
-        $icon_css['css_class'] .= esc_attr(
801
-            apply_filters(
802
-                'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
803
-                ' js-ee-message-action-link ee-message-action-link-' . $type,
804
-                $type,
805
-                $message,
806
-                $query_params
807
-            )
808
-        );
809
-
810
-        return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
811
-    }
812
-
813
-
814
-
815
-
816
-
817
-    /**
818
-     * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
819
-     *
820
-     * @since 4.9.0
821
-     * @return array
822
-     */
823
-    public static function reg_status_to_message_type_array()
824
-    {
825
-        return (array) apply_filters(
826
-            'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
827
-            array(
828
-                EEM_Registration::status_id_approved => 'registration',
829
-                EEM_Registration::status_id_pending_payment => 'pending_approval',
830
-                EEM_Registration::status_id_not_approved => 'not_approved_registration',
831
-                EEM_Registration::status_id_cancelled => 'cancelled_registration',
832
-                EEM_Registration::status_id_declined => 'declined_registration'
833
-            )
834
-        );
835
-    }
836
-
837
-
838
-
839
-
840
-    /**
841
-     * This returns the corresponding registration message type slug to the given reg status. If there isn't a
842
-     * match, then returns an empty string.
843
-     *
844
-     * @since 4.9.0
845
-     * @param $reg_status
846
-     * @return string
847
-     */
848
-    public static function convert_reg_status_to_message_type($reg_status)
849
-    {
850
-        $reg_status_array = self::reg_status_to_message_type_array();
851
-        return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
852
-    }
853
-
854
-
855
-    /**
856
-     * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
857
-     *
858
-     * @since 4.9.0
859
-     * @return array
860
-     */
861
-    public static function payment_status_to_message_type_array()
862
-    {
863
-        return (array) apply_filters(
864
-            'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
865
-            array(
866
-                EEM_Payment::status_id_approved => 'payment',
867
-                EEM_Payment::status_id_pending => 'payment_pending',
868
-                EEM_Payment::status_id_cancelled => 'payment_cancelled',
869
-                EEM_Payment::status_id_declined => 'payment_declined',
870
-                EEM_Payment::status_id_failed => 'payment_failed'
871
-            )
872
-        );
873
-    }
874
-
875
-
876
-
877
-
878
-    /**
879
-     * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
880
-     * an empty string is returned
881
-     *
882
-     * @since 4.9.0
883
-     * @param $payment_status
884
-     * @return string
885
-     */
886
-    public static function convert_payment_status_to_message_type($payment_status)
887
-    {
888
-        $payment_status_array = self::payment_status_to_message_type_array();
889
-        return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
890
-    }
891
-
892
-
893
-    /**
894
-     * This is used to retrieve the template pack for the given name.
895
-     *
896
-     * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
897
-     *
898
-     * @return EE_Messages_Template_Pack
899
-     */
900
-    public static function get_template_pack($template_pack_name)
901
-    {
902
-        if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
903
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
904
-        }
905
-
906
-        // first see if in collection already
907
-        $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
908
-
909
-        if ($template_pack instanceof EE_Messages_Template_Pack) {
910
-            return $template_pack;
911
-        }
912
-
913
-        // nope...let's get it.
914
-        // not set yet so let's attempt to get it.
915
-        $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
916
-            ' ',
917
-            '_',
918
-            ucwords(
919
-                str_replace('_', ' ', $template_pack_name)
920
-            )
921
-        );
922
-        if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
923
-            return self::get_template_pack('default');
924
-        } else {
925
-            $template_pack = new $pack_class_name();
926
-            self::$_template_pack_collection->add($template_pack);
927
-            return $template_pack;
928
-        }
929
-    }
930
-
931
-
932
-
933
-
934
-    /**
935
-     * Globs template packs installed in core and returns the template pack collection with all installed template packs
936
-     * in it.
937
-     *
938
-     * @since 4.9.0
939
-     *
940
-     * @return EE_Messages_Template_Pack_Collection
941
-     */
942
-    public static function get_template_pack_collection()
943
-    {
944
-        $new_collection = false;
945
-        if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
946
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
947
-            $new_collection = true;
948
-        }
949
-
950
-        // glob the defaults directory for messages
951
-        $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
952
-        foreach ($templates as $template_path) {
953
-            // grab folder name
954
-            $template = basename($template_path);
955
-
956
-            if (! $new_collection) {
957
-                // already have it?
958
-                if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
959
-                    continue;
960
-                }
961
-            }
962
-
963
-            // setup classname.
964
-            $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
965
-                ' ',
966
-                '_',
967
-                ucwords(
968
-                    str_replace(
969
-                        '_',
970
-                        ' ',
971
-                        $template
972
-                    )
973
-                )
974
-            );
975
-            if (! class_exists($template_pack_class_name)) {
976
-                continue;
977
-            }
978
-            self::$_template_pack_collection->add(new $template_pack_class_name());
979
-        }
980
-
981
-        /**
982
-         * Filter for plugins to add in any additional template packs
983
-         * Note the filter name here is for backward compat, this used to be found in EED_Messages.
984
-         */
985
-        $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
986
-        foreach ((array) $additional_template_packs as $template_pack) {
987
-            if (
988
-                self::$_template_pack_collection->get_by_name(
989
-                    $template_pack->dbref
990
-                ) instanceof EE_Messages_Template_Pack
991
-            ) {
992
-                continue;
993
-            }
994
-            self::$_template_pack_collection->add($template_pack);
995
-        }
996
-        return self::$_template_pack_collection;
997
-    }
998
-
999
-
1000
-
1001
-    /**
1002
-     * This is a wrapper for the protected _create_new_templates function
1003
-     *
1004
-     * @param string $messenger_name
1005
-     * @param string $message_type_name message type that the templates are being created for
1006
-     * @param int    $GRP_ID
1007
-     * @param bool   $global
1008
-     * @return array
1009
-     * @throws \EE_Error
1010
-     */
1011
-    public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1012
-    {
1013
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1014
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1015
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1016
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1017
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1018
-            return array();
1019
-        }
1020
-        // whew made it this far!  Okay, let's go ahead and create the templates then
1021
-        return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1022
-    }
1023
-
1024
-
1025
-
1026
-    /**
1027
-     * @param \EE_messenger    $messenger
1028
-     * @param \EE_message_type $message_type
1029
-     * @param                  $GRP_ID
1030
-     * @param                  $global
1031
-     * @return array|mixed
1032
-     */
1033
-    protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1034
-    {
1035
-        // if we're creating a custom template then we don't need to use the defaults class
1036
-        if (! $global) {
1037
-            return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1038
-        }
1039
-        /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1040
-        $Message_Template_Defaults = EE_Registry::factory(
1041
-            'EE_Messages_Template_Defaults',
1042
-            array( $messenger, $message_type, $GRP_ID )
1043
-        );
1044
-        // generate templates
1045
-        $success = $Message_Template_Defaults->create_new_templates();
1046
-
1047
-        // if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1048
-        // its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1049
-        // attempts.
1050
-        if (! $success) {
1051
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
1052
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1053
-            $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1054
-        }
1055
-
1056
-        /**
1057
-         * $success is in an array in the following format
1058
-         * array(
1059
-         *    'GRP_ID' => $new_grp_id,
1060
-         *    'MTP_context' => $first_context_in_new_templates,
1061
-         * )
1062
-         */
1063
-        return $success;
1064
-    }
1065
-
1066
-
1067
-
1068
-    /**
1069
-     * This creates a custom template using the incoming GRP_ID
1070
-     *
1071
-     * @param \EE_messenger    $messenger
1072
-     * @param \EE_message_type $message_type
1073
-     * @param  int             $GRP_ID      GRP_ID for the template_group being used as the base
1074
-     * @return  array $success              This will be an array in the format:
1075
-     *                                      array(
1076
-     *                                          'GRP_ID' => $new_grp_id,
1077
-     *                                          'MTP_context' => $first_context_in_created_template
1078
-     *                                      )
1079
-     * @access private
1080
-     */
1081
-    private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1082
-    {
1083
-        // defaults
1084
-        $success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1085
-        // get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1086
-        $Message_Template_Group = empty($GRP_ID)
1087
-            ? EEM_Message_Template_Group::instance()->get_one(
1088
-                array(
1089
-                    array(
1090
-                        'MTP_messenger'    => $messenger->name,
1091
-                        'MTP_message_type' => $message_type->name,
1092
-                        'MTP_is_global'    => true
1093
-                    )
1094
-                )
1095
-            )
1096
-            : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1097
-        // if we don't have a mtg at this point then we need to bail.
1098
-        if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1099
-            EE_Error::add_error(
1100
-                sprintf(
1101
-                    __(
1102
-                        'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1103
-                        'event_espresso'
1104
-                    ),
1105
-                    $GRP_ID
1106
-                ),
1107
-                __FILE__,
1108
-                __FUNCTION__,
1109
-                __LINE__
1110
-            );
1111
-            return $success;
1112
-        }
1113
-        // let's get all the related message_template objects for this group.
1114
-        $message_templates = $Message_Template_Group->message_templates();
1115
-        // now we have what we need to setup the new template
1116
-        $new_mtg = clone $Message_Template_Group;
1117
-        $new_mtg->set('GRP_ID', 0);
1118
-        $new_mtg->set('MTP_is_global', false);
1119
-        $template_name = defined('DOING_AJAX') && ! empty($_POST['templateName'])
1120
-            ? $_POST['templateName']
1121
-            : __(
1122
-                'New Custom Template',
1123
-                'event_espresso'
1124
-            );
1125
-        $template_description = defined("DOING_AJAX") && ! empty($_POST['templateDescription'])
1126
-            ? $_POST['templateDescription']
1127
-            : sprintf(
1128
-                __(
1129
-                    'This is a custom template that was created for the %s messenger and %s message type.',
1130
-                    'event_espresso'
1131
-                ),
1132
-                $new_mtg->messenger_obj()->label['singular'],
1133
-                $new_mtg->message_type_obj()->label['singular']
1134
-            );
1135
-        $new_mtg->set('MTP_name', $template_name);
1136
-        $new_mtg->set('MTP_description', $template_description);
1137
-        // remove ALL relations on this template group so they don't get saved!
1138
-        $new_mtg->_remove_relations('Message_Template');
1139
-        $new_mtg->save();
1140
-        $success['GRP_ID'] = $new_mtg->ID();
1141
-        $success['template_name'] = $template_name;
1142
-        // add new message templates and add relation to.
1143
-        foreach ($message_templates as $message_template) {
1144
-            if (! $message_template instanceof EE_Message_Template) {
1145
-                continue;
1146
-            }
1147
-            $new_message_template = clone $message_template;
1148
-            $new_message_template->set('MTP_ID', 0);
1149
-            $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1150
-            $new_message_template->save();
1151
-            if (empty($success['MTP_context'])) {
1152
-                $success['MTP_context'] = $new_message_template->get('MTP_context');
1153
-            }
1154
-        }
1155
-        return $success;
1156
-    }
1157
-
1158
-
1159
-
1160
-    /**
1161
-     * message_type_has_active_templates_for_messenger
1162
-     *
1163
-     * @param \EE_messenger    $messenger
1164
-     * @param \EE_message_type $message_type
1165
-     * @param bool             $global
1166
-     * @return bool
1167
-     */
1168
-    public static function message_type_has_active_templates_for_messenger(
1169
-        EE_messenger $messenger,
1170
-        EE_message_type $message_type,
1171
-        $global = false
1172
-    ) {
1173
-        // is given message_type valid for given messenger (if this is not a global save)
1174
-        if ($global) {
1175
-            return true;
1176
-        }
1177
-        $active_templates = EEM_Message_Template_Group::instance()->count(
1178
-            array(
1179
-                array(
1180
-                    'MTP_is_active'    => true,
1181
-                    'MTP_messenger'    => $messenger->name,
1182
-                    'MTP_message_type' => $message_type->name
1183
-                )
1184
-            )
1185
-        );
1186
-        if ($active_templates > 0) {
1187
-            return true;
1188
-        }
1189
-        EE_Error::add_error(
1190
-            sprintf(
1191
-                __(
1192
-                    'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1193
-                    'event_espresso'
1194
-                ),
1195
-                $message_type->name,
1196
-                $messenger->name
1197
-            ),
1198
-            __FILE__,
1199
-            __FUNCTION__,
1200
-            __LINE__
1201
-        );
1202
-        return false;
1203
-    }
1204
-
1205
-
1206
-
1207
-    /**
1208
-     * get_fields
1209
-     * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1210
-     *
1211
-     * @param  string $messenger_name    name of EE_messenger
1212
-     * @param  string $message_type_name name of EE_message_type
1213
-     * @return array
1214
-     */
1215
-    public static function get_fields($messenger_name, $message_type_name)
1216
-    {
1217
-        $template_fields = array();
1218
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1219
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1220
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1221
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1222
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1223
-            return array();
1224
-        }
1225
-
1226
-        $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1227
-
1228
-        // okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1229
-        foreach ($message_type->get_contexts() as $context => $details) {
1230
-            foreach ($messenger->get_template_fields() as $field => $value) {
1231
-                if (in_array($field, $excluded_fields_for_messenger, true)) {
1232
-                    continue;
1233
-                }
1234
-                $template_fields[ $context ][ $field ] = $value;
1235
-            }
1236
-        }
1237
-        if (empty($template_fields)) {
1238
-            EE_Error::add_error(
1239
-                __('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1240
-                __FILE__,
1241
-                __FUNCTION__,
1242
-                __LINE__
1243
-            );
1244
-            return array();
1245
-        }
1246
-        return $template_fields;
1247
-    }
17
+	/**
18
+	 * Holds a collection of EE_Message_Template_Pack objects.
19
+	 * @type EE_Messages_Template_Pack_Collection
20
+	 */
21
+	protected static $_template_pack_collection;
22
+
23
+
24
+
25
+
26
+	private static function _set_autoloader()
27
+	{
28
+		EED_Messages::set_autoloaders();
29
+	}
30
+
31
+
32
+	/**
33
+	 * generate_new_templates
34
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will automatically create the defaults for the event.  The user would then be redirected to edit the default context for the event.
35
+	 *
36
+	 * @access protected
37
+	 * @param  string $messenger     the messenger we are generating templates for
38
+	 * @param array   $message_types array of message types that the templates are generated for.
39
+	 * @param int     $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID to use as the base for the new generated template.
40
+	 * @param bool    $global        true indicates generating templates on messenger activation. false requires GRP_ID for event specific template generation.
41
+	 * @throws \EE_Error
42
+	 * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array for templates
43
+	 *                that are generated.  If this is an empty array then it means no templates were generated which usually
44
+	 *                means there was an error.  Anything in the array with an empty value for `MTP_context` means that it
45
+	 *                was not a new generated template but just reactivated (which only happens for global templates that
46
+	 *                already exist in the database.
47
+	 */
48
+	public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
49
+	{
50
+		// make sure message_type is an array.
51
+		$message_types = (array) $message_types;
52
+		$templates = array();
53
+
54
+		if (empty($messenger)) {
55
+			throw new EE_Error(__('We need a messenger to generate templates!', 'event_espresso'));
56
+		}
57
+
58
+		// if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
59
+		if (empty($message_types)) {
60
+			throw new EE_Error(__('We need at least one message type to generate templates!', 'event_espresso'));
61
+		}
62
+
63
+		EEH_MSG_Template::_set_autoloader();
64
+		foreach ($message_types as $message_type) {
65
+			// if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
66
+			if ($global && empty($GRP_ID)) {
67
+				$GRP_ID = EEM_Message_Template_Group::instance()->get_one(
68
+					array(
69
+						array(
70
+							'MTP_messenger'    => $messenger,
71
+							'MTP_message_type' => $message_type,
72
+							'MTP_is_global'    => true,
73
+						),
74
+					)
75
+				);
76
+				$GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
77
+			}
78
+			// if this is global template generation.
79
+			// First let's determine if we already HAVE global templates for this messenger and message_type combination.
80
+			//  If we do then NO generation!!
81
+			if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
82
+				$templates[] = array(
83
+					'GRP_ID' => $GRP_ID,
84
+					'MTP_context' => '',
85
+				);
86
+				// we already have generated templates for this so let's go to the next message type.
87
+				continue;
88
+			}
89
+			$new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
90
+
91
+			if (! $new_message_template_group) {
92
+				continue;
93
+			}
94
+			$templates[] = $new_message_template_group;
95
+		}
96
+
97
+		return $templates;
98
+	}
99
+
100
+
101
+	/**
102
+	 * The purpose of this method is to determine if there are already generated templates in the database for the given variables.
103
+	 * @param  string $messenger     messenger
104
+	 * @param  string $message_type message type
105
+	 * @param  int $GRP_ID        GRP ID ( if a custom template) (if not provided then we're just doing global template check)
106
+	 * @return bool                true = generated, false = hasn't been generated.
107
+	 */
108
+	public static function already_generated($messenger, $message_type, $GRP_ID = 0)
109
+	{
110
+		EEH_MSG_Template::_set_autoloader();
111
+		// what method we use depends on whether we have an GRP_ID or not
112
+		$count = empty($GRP_ID)
113
+			? EEM_Message_Template::instance()->count(
114
+				array(
115
+					array(
116
+						'Message_Template_Group.MTP_messenger'    => $messenger,
117
+						'Message_Template_Group.MTP_message_type' => $message_type,
118
+						'Message_Template_Group.MTP_is_global'    => true
119
+					)
120
+				)
121
+			)
122
+			: EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
123
+
124
+		return $count > 0;
125
+	}
126
+
127
+
128
+
129
+
130
+	/**
131
+	 * Updates all message templates matching the incoming messengers and message types to active status.
132
+	 *
133
+	 * @static
134
+	 * @param  array  $messenger_names     Messenger slug
135
+	 * @param  array  $message_type_names  Message type slug
136
+	 * @return  int                         count of updated records.
137
+	 */
138
+	public static function update_to_active($messenger_names, $message_type_names)
139
+	{
140
+		$messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
141
+		$message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
142
+		return EEM_Message_Template_Group::instance()->update(
143
+			array( 'MTP_is_active' => 1 ),
144
+			array(
145
+				array(
146
+					'MTP_messenger'     => array( 'IN', $messenger_names ),
147
+					'MTP_message_type'  => array( 'IN', $message_type_names )
148
+				)
149
+			)
150
+		);
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Updates all message template groups matching the incoming arguments to inactive status.
157
+	 *
158
+	 * @static
159
+	 * @param array $messenger_names    The messenger slugs.
160
+	 *                              If empty then all templates matching the message types are marked inactive.
161
+	 *                              Otherwise only templates matching the messengers and message types.
162
+	 * @param array $message_type_names     The message type slugs.
163
+	 *                              If empty then all templates matching the messengers are marked inactive.
164
+	 *                              Otherwise only templates matching the messengers and message types.
165
+	 *
166
+	 * @return int  count of updated records.
167
+	 */
168
+	public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
169
+	{
170
+		return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
171
+			$messenger_names,
172
+			$message_type_names
173
+		);
174
+	}
175
+
176
+
177
+	/**
178
+	 * The purpose of this function is to return all installed message objects
179
+	 * (messengers and message type regardless of whether they are ACTIVE or not)
180
+	 *
181
+	 * @deprecated 4.9.0
182
+	 * @static
183
+	 * @param string $type
184
+	 * @return array array consisting of installed messenger objects and installed message type objects.
185
+	 */
186
+	public static function get_installed_message_objects($type = 'all')
187
+	{
188
+		self::_set_autoloader();
189
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
190
+		return array(
191
+			'messenger' => $message_resource_manager->installed_messengers(),
192
+			'message_type' => $message_resource_manager->installed_message_types()
193
+		);
194
+	}
195
+
196
+
197
+	/**
198
+	 * This will return an array of shortcodes => labels from the
199
+	 * messenger and message_type objects associated with this
200
+	 * template.
201
+	 *
202
+	 * @since 4.3.0
203
+	 *
204
+	 * @param string $message_type
205
+	 * @param string $messenger
206
+	 * @param array  $fields    What fields we're returning valid shortcodes for.
207
+	 *                          If empty then we assume all fields are to be returned. Optional.
208
+	 * @param string $context   What context we're going to return shortcodes for. Optional.
209
+	 * @param bool $merged      If TRUE then we don't return shortcodes indexed by field,
210
+	 *                          but instead an array of the unique shortcodes for all the given ( or all) fields.
211
+	 *                          Optional.
212
+	 * @throws \EE_Error
213
+	 * @return mixed (array|bool) an array of shortcodes in the format
214
+	 *                                              array( '[shortcode] => 'label')
215
+	 *                                              OR
216
+	 *                                              FALSE if no shortcodes found.
217
+	 */
218
+	public static function get_shortcodes(
219
+		$message_type,
220
+		$messenger,
221
+		$fields = array(),
222
+		$context = 'admin',
223
+		$merged = false
224
+	) {
225
+		$messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
226
+		$mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
227
+		/** @var EE_Message_Resource_Manager $message_resource_manager */
228
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
229
+		// convert slug to object
230
+		$messenger = $message_resource_manager->get_messenger($messenger);
231
+
232
+		// if messenger isn't a EE_messenger resource then bail.
233
+		if (! $messenger instanceof EE_messenger) {
234
+			return array();
235
+		}
236
+
237
+		// validate class for getting our list of shortcodes
238
+		$classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
239
+		if (! class_exists($classname)) {
240
+			$msg[] = __('The Validator class was unable to load', 'event_espresso');
241
+			$msg[] = sprintf(
242
+				__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
243
+				$classname
244
+			);
245
+			throw new EE_Error(implode('||', $msg));
246
+		}
247
+
248
+		/** @type EE_Messages_Validator $_VLD */
249
+		$_VLD = new $classname(array(), $context);
250
+		$valid_shortcodes = $_VLD->get_validators();
251
+
252
+		// let's make sure we're only getting the shortcode part of the validators
253
+		$shortcodes = array();
254
+		foreach ($valid_shortcodes as $field => $validators) {
255
+			$shortcodes[ $field ] = $validators['shortcodes'];
256
+		}
257
+		$valid_shortcodes = $shortcodes;
258
+
259
+		// if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
260
+		if (! empty($fields)) {
261
+			$specified_shortcodes = array();
262
+			foreach ($fields as $field) {
263
+				if (isset($valid_shortcodes[ $field ])) {
264
+					$specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
265
+				}
266
+			}
267
+			$valid_shortcodes = $specified_shortcodes;
268
+		}
269
+
270
+		// if not merged then let's replace the fields with the localized fields
271
+		if (! $merged) {
272
+			// let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
273
+			$field_settings = $messenger->get_template_fields();
274
+			$localized = array();
275
+			foreach ($valid_shortcodes as $field => $shortcodes) {
276
+				// get localized field label
277
+				if (isset($field_settings[ $field ])) {
278
+					// possible that this is used as a main field.
279
+					if (empty($field_settings[ $field ])) {
280
+						if (isset($field_settings['extra'][ $field ])) {
281
+							$_field = $field_settings['extra'][ $field ]['main']['label'];
282
+						} else {
283
+							$_field = $field;
284
+						}
285
+					} else {
286
+						$_field = $field_settings[ $field ]['label'];
287
+					}
288
+				} elseif (isset($field_settings['extra'])) {
289
+					// loop through extra "main fields" and see if any of their children have our field
290
+					foreach ($field_settings['extra'] as $main_field => $fields) {
291
+						if (isset($fields[ $field ])) {
292
+							$_field = $fields[ $field ]['label'];
293
+						} else {
294
+							$_field = $field;
295
+						}
296
+					}
297
+				} else {
298
+					$_field = $field;
299
+				}
300
+				if (isset($_field)) {
301
+					$localized[ (string) $_field ] = $shortcodes;
302
+				}
303
+			}
304
+			$valid_shortcodes = $localized;
305
+		}
306
+
307
+		// if $merged then let's merge all the shortcodes into one list NOT indexed by field.
308
+		if ($merged) {
309
+			$merged_codes = array();
310
+			foreach ($valid_shortcodes as $field => $shortcode) {
311
+				foreach ($shortcode as $code => $label) {
312
+					if (isset($merged_codes[ $code ])) {
313
+						continue;
314
+					} else {
315
+						$merged_codes[ $code ] = $label;
316
+					}
317
+				}
318
+			}
319
+			$valid_shortcodes = $merged_codes;
320
+		}
321
+
322
+		return $valid_shortcodes;
323
+	}
324
+
325
+
326
+	/**
327
+	 * Get Messenger object.
328
+	 *
329
+	 * @since 4.3.0
330
+	 * @deprecated 4.9.0
331
+	 * @param string $messenger messenger slug for the messenger object we want to retrieve.
332
+	 * @throws \EE_Error
333
+	 * @return EE_messenger
334
+	 */
335
+	public static function messenger_obj($messenger)
336
+	{
337
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
338
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
339
+		return $Message_Resource_Manager->get_messenger($messenger);
340
+	}
341
+
342
+
343
+	/**
344
+	 * get Message type object
345
+	 *
346
+	 * @since 4.3.0
347
+	 * @deprecated 4.9.0
348
+	 * @param string $message_type the slug for the message type object to retrieve
349
+	 * @throws \EE_Error
350
+	 * @return EE_message_type
351
+	 */
352
+	public static function message_type_obj($message_type)
353
+	{
354
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
355
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
356
+		return $Message_Resource_Manager->get_message_type($message_type);
357
+	}
358
+
359
+
360
+
361
+
362
+
363
+	/**
364
+	 * Given a message_type slug, will return whether that message type is active in the system or not.
365
+	 *
366
+	 * @since    4.3.0
367
+	 * @param  string   $message_type message type to check for.
368
+	 * @return boolean
369
+	 */
370
+	public static function is_mt_active($message_type)
371
+	{
372
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
373
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
374
+		$active_mts = $Message_Resource_Manager->list_of_active_message_types();
375
+		return in_array($message_type, $active_mts);
376
+	}
377
+
378
+
379
+
380
+	/**
381
+	 * Given a messenger slug, will return whether that messenger is active in the system or not.
382
+	 *
383
+	 * @since    4.3.0
384
+	 *
385
+	 * @param  string  $messenger slug for messenger to check.
386
+	 * @return boolean
387
+	 */
388
+	public static function is_messenger_active($messenger)
389
+	{
390
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
391
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
392
+		$active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
393
+		return $active_messenger instanceof EE_messenger ? true : false;
394
+	}
395
+
396
+
397
+
398
+	/**
399
+	 * Used to return active messengers array stored in the wp options table.
400
+	 * If no value is present in the option then an empty array is returned.
401
+	 *
402
+	 * @deprecated 4.9
403
+	 * @since 4.3.1
404
+	 *
405
+	 * @return array
406
+	 */
407
+	public static function get_active_messengers_in_db()
408
+	{
409
+		EE_Error::doing_it_wrong(
410
+			__METHOD__,
411
+			__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
412
+			'4.9.0'
413
+		);
414
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
415
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
416
+		return $Message_Resource_Manager->get_active_messengers_option();
417
+	}
418
+
419
+
420
+
421
+
422
+	/**
423
+	 * Used to update the active messengers array stored in the wp options table.
424
+	 *
425
+	 * @since 4.3.1
426
+	 * @deprecated 4.9.0
427
+	 *
428
+	 * @param array $data_to_save Incoming data to save.
429
+	 *
430
+	 * @return bool FALSE if not updated, TRUE if updated.
431
+	 */
432
+	public static function update_active_messengers_in_db($data_to_save)
433
+	{
434
+		EE_Error::doing_it_wrong(
435
+			__METHOD__,
436
+			__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
437
+			'4.9.0'
438
+		);
439
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
440
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
441
+		return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
442
+	}
443
+
444
+
445
+	/**
446
+	 * This does some validation of incoming params, determines what type of url is being prepped and returns the
447
+	 * appropriate url trigger
448
+	 *
449
+	 * @param EE_message_type $message_type
450
+	 * @param EE_Message $message
451
+	 * @param EE_Registration | null $registration  The registration object must be included if this
452
+	 *                                              is going to be a registration trigger url.
453
+	 * @param string $sending_messenger             The (optional) sending messenger for the url.
454
+	 *
455
+	 * @return string
456
+	 * @throws EE_Error
457
+	 */
458
+	public static function get_url_trigger(
459
+		EE_message_type $message_type,
460
+		EE_Message $message,
461
+		$registration = null,
462
+		$sending_messenger = ''
463
+	) {
464
+		// first determine if the url can be to the EE_Message object.
465
+		if (! $message_type->always_generate()) {
466
+			return EEH_MSG_Template::generate_browser_trigger($message);
467
+		}
468
+
469
+		// if $registration object is not valid then exit early because there's nothing that can be generated.
470
+		if (! $registration instanceof EE_Registration) {
471
+			throw new EE_Error(
472
+				__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
473
+			);
474
+		}
475
+
476
+		// validate given context
477
+		$contexts = $message_type->get_contexts();
478
+		if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
479
+			throw new EE_Error(
480
+				sprintf(
481
+					__('The context %s is not a valid context for %s.', 'event_espresso'),
482
+					$message->context(),
483
+					get_class($message_type)
484
+				)
485
+			);
486
+		}
487
+
488
+		// valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
489
+		if (! empty($sending_messenger)) {
490
+			$with_messengers = $message_type->with_messengers();
491
+			if (
492
+				! isset($with_messengers[ $message->messenger() ])
493
+				 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
494
+			) {
495
+				throw new EE_Error(
496
+					sprintf(
497
+						__(
498
+							'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
499
+							'event_espresso'
500
+						),
501
+						$sending_messenger,
502
+						get_class($message_type)
503
+					)
504
+				);
505
+			}
506
+		} else {
507
+			$sending_messenger = $message->messenger();
508
+		}
509
+		return EEH_MSG_Template::generate_url_trigger(
510
+			$sending_messenger,
511
+			$message->messenger(),
512
+			$message->context(),
513
+			$message->message_type(),
514
+			$registration,
515
+			$message->GRP_ID()
516
+		);
517
+	}
518
+
519
+
520
+	/**
521
+	 * This returns the url for triggering a in browser view of a specific EE_Message object.
522
+	 * @param EE_Message $message
523
+	 * @return string.
524
+	 */
525
+	public static function generate_browser_trigger(EE_Message $message)
526
+	{
527
+		$query_args = array(
528
+			'ee' => 'msg_browser_trigger',
529
+			'token' => $message->MSG_token()
530
+		);
531
+		return apply_filters(
532
+			'FHEE__EEH_MSG_Template__generate_browser_trigger',
533
+			add_query_arg($query_args, site_url()),
534
+			$message
535
+		);
536
+	}
537
+
538
+
539
+
540
+
541
+
542
+
543
+	/**
544
+	 * This returns the url for triggering an in browser view of the error saved on the incoming message object.
545
+	 * @param EE_Message $message
546
+	 * @return string
547
+	 */
548
+	public static function generate_error_display_trigger(EE_Message $message)
549
+	{
550
+		return apply_filters(
551
+			'FHEE__EEH_MSG_Template__generate_error_display_trigger',
552
+			add_query_arg(
553
+				array(
554
+					'ee' => 'msg_browser_error_trigger',
555
+					'token' => $message->MSG_token()
556
+				),
557
+				site_url()
558
+			),
559
+			$message
560
+		);
561
+	}
562
+
563
+
564
+
565
+
566
+
567
+
568
+	/**
569
+	 * This generates a url trigger for the msg_url_trigger route using the given arguments
570
+	 *
571
+	 * @param string          $sending_messenger    The sending messenger slug.
572
+	 * @param string          $generating_messenger The generating messenger slug.
573
+	 * @param string          $context              The context for the template.
574
+	 * @param string          $message_type         The message type slug
575
+	 * @param EE_Registration $registration
576
+	 * @param integer          $message_template_group id   The EE_Message_Template_Group ID for the template.
577
+	 * @param integer          $data_id     The id to the EE_Base_Class for getting the data used by the trigger.
578
+	 * @return string          The generated url.
579
+	 */
580
+	public static function generate_url_trigger(
581
+		$sending_messenger,
582
+		$generating_messenger,
583
+		$context,
584
+		$message_type,
585
+		EE_Registration $registration,
586
+		$message_template_group,
587
+		$data_id = 0
588
+	) {
589
+		$query_args = array(
590
+			'ee' => 'msg_url_trigger',
591
+			'snd_msgr' => $sending_messenger,
592
+			'gen_msgr' => $generating_messenger,
593
+			'message_type' => $message_type,
594
+			'context' => $context,
595
+			'token' => $registration->reg_url_link(),
596
+			'GRP_ID' => $message_template_group,
597
+			'id' => $data_id
598
+			);
599
+		$url = add_query_arg($query_args, get_home_url());
600
+
601
+		// made it here so now we can just get the url and filter it.  Filtered globally and by message type.
602
+		$url = apply_filters(
603
+			'FHEE__EEH_MSG_Template__generate_url_trigger',
604
+			$url,
605
+			$sending_messenger,
606
+			$generating_messenger,
607
+			$context,
608
+			$message_type,
609
+			$registration,
610
+			$message_template_group,
611
+			$data_id
612
+		);
613
+		return $url;
614
+	}
615
+
616
+
617
+
618
+
619
+	/**
620
+	 * Return the specific css for the action icon given.
621
+	 *
622
+	 * @since 4.9.0
623
+	 *
624
+	 * @param string $type  What action to return.
625
+	 * @return string
626
+	 */
627
+	public static function get_message_action_icon($type)
628
+	{
629
+		$action_icons = self::get_message_action_icons();
630
+		return isset($action_icons[ $type ]) ? $action_icons[ $type ] : '';
631
+	}
632
+
633
+
634
+	/**
635
+	 * This is used for retrieving the css classes used for the icons representing message actions.
636
+	 *
637
+	 * @since 4.9.0
638
+	 *
639
+	 * @return array
640
+	 */
641
+	public static function get_message_action_icons()
642
+	{
643
+		return apply_filters(
644
+			'FHEE__EEH_MSG_Template__message_action_icons',
645
+			array(
646
+				'view' => array(
647
+					'label' => __('View Message', 'event_espresso'),
648
+					'css_class' => 'dashicons dashicons-welcome-view-site',
649
+				),
650
+				'error' => array(
651
+					'label' => __('View Error Message', 'event_espresso'),
652
+					'css_class' => 'dashicons dashicons-info',
653
+				),
654
+				'see_notifications_for' => array(
655
+					'label' => __('View Related Messages', 'event_espresso'),
656
+					'css_class' => 'dashicons dashicons-megaphone',
657
+				),
658
+				'generate_now' => array(
659
+					'label' => __('Generate the message now.', 'event_espresso'),
660
+					'css_class' => 'dashicons dashicons-admin-tools',
661
+				),
662
+				'send_now' => array(
663
+					'label' => __('Send Immediately', 'event_espresso'),
664
+					'css_class' => 'dashicons dashicons-controls-forward',
665
+				),
666
+				'queue_for_resending' => array(
667
+					'label' => __('Queue for Resending', 'event_espresso'),
668
+					'css_class' => 'dashicons dashicons-controls-repeat',
669
+				),
670
+				'view_transaction' => array(
671
+					'label' => __('View related Transaction', 'event_espresso'),
672
+					'css_class' => 'dashicons dashicons-cart',
673
+				)
674
+			)
675
+		);
676
+	}
677
+
678
+
679
+	/**
680
+	 * This returns the url for a given action related to EE_Message.
681
+	 *
682
+	 * @since 4.9.0
683
+	 *
684
+	 * @param string $type  What type of action to return the url for.
685
+	 * @param EE_Message $message   Required for generating the correct url for some types.
686
+	 * @param array  $query_params   Any additional query params to be included with the generated url.
687
+	 *
688
+	 * @return string
689
+	 */
690
+	public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
691
+	{
692
+		$action_urls = self::get_message_action_urls($message, $query_params);
693
+		return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
694
+	}
695
+
696
+
697
+
698
+	/**
699
+	 * This returns all the current urls for EE_Message actions.
700
+	 *
701
+	 * @since 4.9.0
702
+	 *
703
+	 * @param  EE_Message   $message    The EE_Message object required to generate correct urls for some types.
704
+	 * @param  array    $query_params   Any additional query_params to be included with the generated url.
705
+	 *
706
+	 * @return array
707
+	 */
708
+	public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
709
+	{
710
+		EE_Registry::instance()->load_helper('URL');
711
+		// if $message is not an instance of EE_Message then let's just do a dummy.
712
+		$message = empty($message) ? EE_Message_Factory::create() : $message;
713
+		$action_urls =  apply_filters(
714
+			'FHEE__EEH_MSG_Template__get_message_action_url',
715
+			array(
716
+				'view' => EEH_MSG_Template::generate_browser_trigger($message),
717
+				'error' => EEH_MSG_Template::generate_error_display_trigger($message),
718
+				'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
719
+					array_merge(
720
+						array(
721
+							'page' => 'espresso_messages',
722
+							'action' => 'default',
723
+							'filterby' => 1,
724
+						),
725
+						$query_params
726
+					),
727
+					admin_url('admin.php')
728
+				),
729
+				'generate_now' => EEH_URL::add_query_args_and_nonce(
730
+					array(
731
+						'page' => 'espresso_messages',
732
+						'action' => 'generate_now',
733
+						'MSG_ID' => $message->ID()
734
+					),
735
+					admin_url('admin.php')
736
+				),
737
+				'send_now' => EEH_URL::add_query_args_and_nonce(
738
+					array(
739
+						'page' => 'espresso_messages',
740
+						'action' => 'send_now',
741
+						'MSG_ID' => $message->ID()
742
+					),
743
+					admin_url('admin.php')
744
+				),
745
+				'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
746
+					array(
747
+						'page' => 'espresso_messages',
748
+						'action' => 'queue_for_resending',
749
+						'MSG_ID' => $message->ID()
750
+					),
751
+					admin_url('admin.php')
752
+				),
753
+			)
754
+		);
755
+		if (
756
+			$message->TXN_ID() > 0
757
+			&& EE_Registry::instance()->CAP->current_user_can(
758
+				'ee_read_transaction',
759
+				'espresso_transactions_default',
760
+				$message->TXN_ID()
761
+			)
762
+		) {
763
+			$action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
764
+				array(
765
+					'page' => 'espresso_transactions',
766
+					'action' => 'view_transaction',
767
+					'TXN_ID' => $message->TXN_ID()
768
+				),
769
+				admin_url('admin.php')
770
+			);
771
+		} else {
772
+			$action_urls['view_transaction'] = '';
773
+		}
774
+		return $action_urls;
775
+	}
776
+
777
+
778
+	/**
779
+	 * This returns a generated link html including the icon used for the action link for EE_Message actions.
780
+	 *
781
+	 * @since 4.9.0
782
+	 *
783
+	 * @param string $type What type of action the link is for (if invalid type is passed in then an
784
+	 *                     empty string is returned)
785
+	 * @param EE_Message|null $message  The EE_Message object (required for some actions to generate correctly)
786
+	 * @param array           $query_params Any extra query params to include in the generated link.
787
+	 *
788
+	 * @return string
789
+	 */
790
+	public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
791
+	{
792
+		$url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
793
+		$icon_css = EEH_MSG_Template::get_message_action_icon($type);
794
+		$title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
795
+
796
+		if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
797
+			return '';
798
+		}
799
+
800
+		$icon_css['css_class'] .= esc_attr(
801
+			apply_filters(
802
+				'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
803
+				' js-ee-message-action-link ee-message-action-link-' . $type,
804
+				$type,
805
+				$message,
806
+				$query_params
807
+			)
808
+		);
809
+
810
+		return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
811
+	}
812
+
813
+
814
+
815
+
816
+
817
+	/**
818
+	 * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
819
+	 *
820
+	 * @since 4.9.0
821
+	 * @return array
822
+	 */
823
+	public static function reg_status_to_message_type_array()
824
+	{
825
+		return (array) apply_filters(
826
+			'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
827
+			array(
828
+				EEM_Registration::status_id_approved => 'registration',
829
+				EEM_Registration::status_id_pending_payment => 'pending_approval',
830
+				EEM_Registration::status_id_not_approved => 'not_approved_registration',
831
+				EEM_Registration::status_id_cancelled => 'cancelled_registration',
832
+				EEM_Registration::status_id_declined => 'declined_registration'
833
+			)
834
+		);
835
+	}
836
+
837
+
838
+
839
+
840
+	/**
841
+	 * This returns the corresponding registration message type slug to the given reg status. If there isn't a
842
+	 * match, then returns an empty string.
843
+	 *
844
+	 * @since 4.9.0
845
+	 * @param $reg_status
846
+	 * @return string
847
+	 */
848
+	public static function convert_reg_status_to_message_type($reg_status)
849
+	{
850
+		$reg_status_array = self::reg_status_to_message_type_array();
851
+		return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
852
+	}
853
+
854
+
855
+	/**
856
+	 * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
857
+	 *
858
+	 * @since 4.9.0
859
+	 * @return array
860
+	 */
861
+	public static function payment_status_to_message_type_array()
862
+	{
863
+		return (array) apply_filters(
864
+			'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
865
+			array(
866
+				EEM_Payment::status_id_approved => 'payment',
867
+				EEM_Payment::status_id_pending => 'payment_pending',
868
+				EEM_Payment::status_id_cancelled => 'payment_cancelled',
869
+				EEM_Payment::status_id_declined => 'payment_declined',
870
+				EEM_Payment::status_id_failed => 'payment_failed'
871
+			)
872
+		);
873
+	}
874
+
875
+
876
+
877
+
878
+	/**
879
+	 * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
880
+	 * an empty string is returned
881
+	 *
882
+	 * @since 4.9.0
883
+	 * @param $payment_status
884
+	 * @return string
885
+	 */
886
+	public static function convert_payment_status_to_message_type($payment_status)
887
+	{
888
+		$payment_status_array = self::payment_status_to_message_type_array();
889
+		return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
890
+	}
891
+
892
+
893
+	/**
894
+	 * This is used to retrieve the template pack for the given name.
895
+	 *
896
+	 * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
897
+	 *
898
+	 * @return EE_Messages_Template_Pack
899
+	 */
900
+	public static function get_template_pack($template_pack_name)
901
+	{
902
+		if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
903
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
904
+		}
905
+
906
+		// first see if in collection already
907
+		$template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
908
+
909
+		if ($template_pack instanceof EE_Messages_Template_Pack) {
910
+			return $template_pack;
911
+		}
912
+
913
+		// nope...let's get it.
914
+		// not set yet so let's attempt to get it.
915
+		$pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
916
+			' ',
917
+			'_',
918
+			ucwords(
919
+				str_replace('_', ' ', $template_pack_name)
920
+			)
921
+		);
922
+		if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
923
+			return self::get_template_pack('default');
924
+		} else {
925
+			$template_pack = new $pack_class_name();
926
+			self::$_template_pack_collection->add($template_pack);
927
+			return $template_pack;
928
+		}
929
+	}
930
+
931
+
932
+
933
+
934
+	/**
935
+	 * Globs template packs installed in core and returns the template pack collection with all installed template packs
936
+	 * in it.
937
+	 *
938
+	 * @since 4.9.0
939
+	 *
940
+	 * @return EE_Messages_Template_Pack_Collection
941
+	 */
942
+	public static function get_template_pack_collection()
943
+	{
944
+		$new_collection = false;
945
+		if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
946
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
947
+			$new_collection = true;
948
+		}
949
+
950
+		// glob the defaults directory for messages
951
+		$templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
952
+		foreach ($templates as $template_path) {
953
+			// grab folder name
954
+			$template = basename($template_path);
955
+
956
+			if (! $new_collection) {
957
+				// already have it?
958
+				if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
959
+					continue;
960
+				}
961
+			}
962
+
963
+			// setup classname.
964
+			$template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
965
+				' ',
966
+				'_',
967
+				ucwords(
968
+					str_replace(
969
+						'_',
970
+						' ',
971
+						$template
972
+					)
973
+				)
974
+			);
975
+			if (! class_exists($template_pack_class_name)) {
976
+				continue;
977
+			}
978
+			self::$_template_pack_collection->add(new $template_pack_class_name());
979
+		}
980
+
981
+		/**
982
+		 * Filter for plugins to add in any additional template packs
983
+		 * Note the filter name here is for backward compat, this used to be found in EED_Messages.
984
+		 */
985
+		$additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
986
+		foreach ((array) $additional_template_packs as $template_pack) {
987
+			if (
988
+				self::$_template_pack_collection->get_by_name(
989
+					$template_pack->dbref
990
+				) instanceof EE_Messages_Template_Pack
991
+			) {
992
+				continue;
993
+			}
994
+			self::$_template_pack_collection->add($template_pack);
995
+		}
996
+		return self::$_template_pack_collection;
997
+	}
998
+
999
+
1000
+
1001
+	/**
1002
+	 * This is a wrapper for the protected _create_new_templates function
1003
+	 *
1004
+	 * @param string $messenger_name
1005
+	 * @param string $message_type_name message type that the templates are being created for
1006
+	 * @param int    $GRP_ID
1007
+	 * @param bool   $global
1008
+	 * @return array
1009
+	 * @throws \EE_Error
1010
+	 */
1011
+	public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1012
+	{
1013
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1014
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1015
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1016
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1017
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1018
+			return array();
1019
+		}
1020
+		// whew made it this far!  Okay, let's go ahead and create the templates then
1021
+		return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1022
+	}
1023
+
1024
+
1025
+
1026
+	/**
1027
+	 * @param \EE_messenger    $messenger
1028
+	 * @param \EE_message_type $message_type
1029
+	 * @param                  $GRP_ID
1030
+	 * @param                  $global
1031
+	 * @return array|mixed
1032
+	 */
1033
+	protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1034
+	{
1035
+		// if we're creating a custom template then we don't need to use the defaults class
1036
+		if (! $global) {
1037
+			return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1038
+		}
1039
+		/** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1040
+		$Message_Template_Defaults = EE_Registry::factory(
1041
+			'EE_Messages_Template_Defaults',
1042
+			array( $messenger, $message_type, $GRP_ID )
1043
+		);
1044
+		// generate templates
1045
+		$success = $Message_Template_Defaults->create_new_templates();
1046
+
1047
+		// if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1048
+		// its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1049
+		// attempts.
1050
+		if (! $success) {
1051
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
1052
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1053
+			$message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1054
+		}
1055
+
1056
+		/**
1057
+		 * $success is in an array in the following format
1058
+		 * array(
1059
+		 *    'GRP_ID' => $new_grp_id,
1060
+		 *    'MTP_context' => $first_context_in_new_templates,
1061
+		 * )
1062
+		 */
1063
+		return $success;
1064
+	}
1065
+
1066
+
1067
+
1068
+	/**
1069
+	 * This creates a custom template using the incoming GRP_ID
1070
+	 *
1071
+	 * @param \EE_messenger    $messenger
1072
+	 * @param \EE_message_type $message_type
1073
+	 * @param  int             $GRP_ID      GRP_ID for the template_group being used as the base
1074
+	 * @return  array $success              This will be an array in the format:
1075
+	 *                                      array(
1076
+	 *                                          'GRP_ID' => $new_grp_id,
1077
+	 *                                          'MTP_context' => $first_context_in_created_template
1078
+	 *                                      )
1079
+	 * @access private
1080
+	 */
1081
+	private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1082
+	{
1083
+		// defaults
1084
+		$success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1085
+		// get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1086
+		$Message_Template_Group = empty($GRP_ID)
1087
+			? EEM_Message_Template_Group::instance()->get_one(
1088
+				array(
1089
+					array(
1090
+						'MTP_messenger'    => $messenger->name,
1091
+						'MTP_message_type' => $message_type->name,
1092
+						'MTP_is_global'    => true
1093
+					)
1094
+				)
1095
+			)
1096
+			: EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1097
+		// if we don't have a mtg at this point then we need to bail.
1098
+		if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1099
+			EE_Error::add_error(
1100
+				sprintf(
1101
+					__(
1102
+						'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1103
+						'event_espresso'
1104
+					),
1105
+					$GRP_ID
1106
+				),
1107
+				__FILE__,
1108
+				__FUNCTION__,
1109
+				__LINE__
1110
+			);
1111
+			return $success;
1112
+		}
1113
+		// let's get all the related message_template objects for this group.
1114
+		$message_templates = $Message_Template_Group->message_templates();
1115
+		// now we have what we need to setup the new template
1116
+		$new_mtg = clone $Message_Template_Group;
1117
+		$new_mtg->set('GRP_ID', 0);
1118
+		$new_mtg->set('MTP_is_global', false);
1119
+		$template_name = defined('DOING_AJAX') && ! empty($_POST['templateName'])
1120
+			? $_POST['templateName']
1121
+			: __(
1122
+				'New Custom Template',
1123
+				'event_espresso'
1124
+			);
1125
+		$template_description = defined("DOING_AJAX") && ! empty($_POST['templateDescription'])
1126
+			? $_POST['templateDescription']
1127
+			: sprintf(
1128
+				__(
1129
+					'This is a custom template that was created for the %s messenger and %s message type.',
1130
+					'event_espresso'
1131
+				),
1132
+				$new_mtg->messenger_obj()->label['singular'],
1133
+				$new_mtg->message_type_obj()->label['singular']
1134
+			);
1135
+		$new_mtg->set('MTP_name', $template_name);
1136
+		$new_mtg->set('MTP_description', $template_description);
1137
+		// remove ALL relations on this template group so they don't get saved!
1138
+		$new_mtg->_remove_relations('Message_Template');
1139
+		$new_mtg->save();
1140
+		$success['GRP_ID'] = $new_mtg->ID();
1141
+		$success['template_name'] = $template_name;
1142
+		// add new message templates and add relation to.
1143
+		foreach ($message_templates as $message_template) {
1144
+			if (! $message_template instanceof EE_Message_Template) {
1145
+				continue;
1146
+			}
1147
+			$new_message_template = clone $message_template;
1148
+			$new_message_template->set('MTP_ID', 0);
1149
+			$new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1150
+			$new_message_template->save();
1151
+			if (empty($success['MTP_context'])) {
1152
+				$success['MTP_context'] = $new_message_template->get('MTP_context');
1153
+			}
1154
+		}
1155
+		return $success;
1156
+	}
1157
+
1158
+
1159
+
1160
+	/**
1161
+	 * message_type_has_active_templates_for_messenger
1162
+	 *
1163
+	 * @param \EE_messenger    $messenger
1164
+	 * @param \EE_message_type $message_type
1165
+	 * @param bool             $global
1166
+	 * @return bool
1167
+	 */
1168
+	public static function message_type_has_active_templates_for_messenger(
1169
+		EE_messenger $messenger,
1170
+		EE_message_type $message_type,
1171
+		$global = false
1172
+	) {
1173
+		// is given message_type valid for given messenger (if this is not a global save)
1174
+		if ($global) {
1175
+			return true;
1176
+		}
1177
+		$active_templates = EEM_Message_Template_Group::instance()->count(
1178
+			array(
1179
+				array(
1180
+					'MTP_is_active'    => true,
1181
+					'MTP_messenger'    => $messenger->name,
1182
+					'MTP_message_type' => $message_type->name
1183
+				)
1184
+			)
1185
+		);
1186
+		if ($active_templates > 0) {
1187
+			return true;
1188
+		}
1189
+		EE_Error::add_error(
1190
+			sprintf(
1191
+				__(
1192
+					'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1193
+					'event_espresso'
1194
+				),
1195
+				$message_type->name,
1196
+				$messenger->name
1197
+			),
1198
+			__FILE__,
1199
+			__FUNCTION__,
1200
+			__LINE__
1201
+		);
1202
+		return false;
1203
+	}
1204
+
1205
+
1206
+
1207
+	/**
1208
+	 * get_fields
1209
+	 * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1210
+	 *
1211
+	 * @param  string $messenger_name    name of EE_messenger
1212
+	 * @param  string $message_type_name name of EE_message_type
1213
+	 * @return array
1214
+	 */
1215
+	public static function get_fields($messenger_name, $message_type_name)
1216
+	{
1217
+		$template_fields = array();
1218
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1219
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1220
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1221
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1222
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1223
+			return array();
1224
+		}
1225
+
1226
+		$excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1227
+
1228
+		// okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1229
+		foreach ($message_type->get_contexts() as $context => $details) {
1230
+			foreach ($messenger->get_template_fields() as $field => $value) {
1231
+				if (in_array($field, $excluded_fields_for_messenger, true)) {
1232
+					continue;
1233
+				}
1234
+				$template_fields[ $context ][ $field ] = $value;
1235
+			}
1236
+		}
1237
+		if (empty($template_fields)) {
1238
+			EE_Error::add_error(
1239
+				__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1240
+				__FILE__,
1241
+				__FUNCTION__,
1242
+				__LINE__
1243
+			);
1244
+			return array();
1245
+		}
1246
+		return $template_fields;
1247
+	}
1248 1248
 }
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
             }
89 89
             $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
90 90
 
91
-            if (! $new_message_template_group) {
91
+            if ( ! $new_message_template_group) {
92 92
                 continue;
93 93
             }
94 94
             $templates[] = $new_message_template_group;
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
                     )
120 120
                 )
121 121
             )
122
-            : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
122
+            : EEM_Message_Template::instance()->count(array(array('GRP_ID' => $GRP_ID)));
123 123
 
124 124
         return $count > 0;
125 125
     }
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
      */
138 138
     public static function update_to_active($messenger_names, $message_type_names)
139 139
     {
140
-        $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
141
-        $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
140
+        $messenger_names = is_array($messenger_names) ? $messenger_names : array($messenger_names);
141
+        $message_type_names = is_array($message_type_names) ? $message_type_names : array($message_type_names);
142 142
         return EEM_Message_Template_Group::instance()->update(
143
-            array( 'MTP_is_active' => 1 ),
143
+            array('MTP_is_active' => 1),
144 144
             array(
145 145
                 array(
146
-                    'MTP_messenger'     => array( 'IN', $messenger_names ),
147
-                    'MTP_message_type'  => array( 'IN', $message_type_names )
146
+                    'MTP_messenger'     => array('IN', $messenger_names),
147
+                    'MTP_message_type'  => array('IN', $message_type_names)
148 148
                 )
149 149
             )
150 150
         );
@@ -230,13 +230,13 @@  discard block
 block discarded – undo
230 230
         $messenger = $message_resource_manager->get_messenger($messenger);
231 231
 
232 232
         // if messenger isn't a EE_messenger resource then bail.
233
-        if (! $messenger instanceof EE_messenger) {
233
+        if ( ! $messenger instanceof EE_messenger) {
234 234
             return array();
235 235
         }
236 236
 
237 237
         // validate class for getting our list of shortcodes
238
-        $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
239
-        if (! class_exists($classname)) {
238
+        $classname = 'EE_Messages_'.$messenger_name.'_'.$mt_name.'_Validator';
239
+        if ( ! class_exists($classname)) {
240 240
             $msg[] = __('The Validator class was unable to load', 'event_espresso');
241 241
             $msg[] = sprintf(
242 242
                 __('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
@@ -252,44 +252,44 @@  discard block
 block discarded – undo
252 252
         // let's make sure we're only getting the shortcode part of the validators
253 253
         $shortcodes = array();
254 254
         foreach ($valid_shortcodes as $field => $validators) {
255
-            $shortcodes[ $field ] = $validators['shortcodes'];
255
+            $shortcodes[$field] = $validators['shortcodes'];
256 256
         }
257 257
         $valid_shortcodes = $shortcodes;
258 258
 
259 259
         // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
260
-        if (! empty($fields)) {
260
+        if ( ! empty($fields)) {
261 261
             $specified_shortcodes = array();
262 262
             foreach ($fields as $field) {
263
-                if (isset($valid_shortcodes[ $field ])) {
264
-                    $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
263
+                if (isset($valid_shortcodes[$field])) {
264
+                    $specified_shortcodes[$field] = $valid_shortcodes[$field];
265 265
                 }
266 266
             }
267 267
             $valid_shortcodes = $specified_shortcodes;
268 268
         }
269 269
 
270 270
         // if not merged then let's replace the fields with the localized fields
271
-        if (! $merged) {
271
+        if ( ! $merged) {
272 272
             // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
273 273
             $field_settings = $messenger->get_template_fields();
274 274
             $localized = array();
275 275
             foreach ($valid_shortcodes as $field => $shortcodes) {
276 276
                 // get localized field label
277
-                if (isset($field_settings[ $field ])) {
277
+                if (isset($field_settings[$field])) {
278 278
                     // possible that this is used as a main field.
279
-                    if (empty($field_settings[ $field ])) {
280
-                        if (isset($field_settings['extra'][ $field ])) {
281
-                            $_field = $field_settings['extra'][ $field ]['main']['label'];
279
+                    if (empty($field_settings[$field])) {
280
+                        if (isset($field_settings['extra'][$field])) {
281
+                            $_field = $field_settings['extra'][$field]['main']['label'];
282 282
                         } else {
283 283
                             $_field = $field;
284 284
                         }
285 285
                     } else {
286
-                        $_field = $field_settings[ $field ]['label'];
286
+                        $_field = $field_settings[$field]['label'];
287 287
                     }
288 288
                 } elseif (isset($field_settings['extra'])) {
289 289
                     // loop through extra "main fields" and see if any of their children have our field
290 290
                     foreach ($field_settings['extra'] as $main_field => $fields) {
291
-                        if (isset($fields[ $field ])) {
292
-                            $_field = $fields[ $field ]['label'];
291
+                        if (isset($fields[$field])) {
292
+                            $_field = $fields[$field]['label'];
293 293
                         } else {
294 294
                             $_field = $field;
295 295
                         }
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
                     $_field = $field;
299 299
                 }
300 300
                 if (isset($_field)) {
301
-                    $localized[ (string) $_field ] = $shortcodes;
301
+                    $localized[(string) $_field] = $shortcodes;
302 302
                 }
303 303
             }
304 304
             $valid_shortcodes = $localized;
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
             $merged_codes = array();
310 310
             foreach ($valid_shortcodes as $field => $shortcode) {
311 311
                 foreach ($shortcode as $code => $label) {
312
-                    if (isset($merged_codes[ $code ])) {
312
+                    if (isset($merged_codes[$code])) {
313 313
                         continue;
314 314
                     } else {
315
-                        $merged_codes[ $code ] = $label;
315
+                        $merged_codes[$code] = $label;
316 316
                     }
317 317
                 }
318 318
             }
@@ -462,12 +462,12 @@  discard block
 block discarded – undo
462 462
         $sending_messenger = ''
463 463
     ) {
464 464
         // first determine if the url can be to the EE_Message object.
465
-        if (! $message_type->always_generate()) {
465
+        if ( ! $message_type->always_generate()) {
466 466
             return EEH_MSG_Template::generate_browser_trigger($message);
467 467
         }
468 468
 
469 469
         // if $registration object is not valid then exit early because there's nothing that can be generated.
470
-        if (! $registration instanceof EE_Registration) {
470
+        if ( ! $registration instanceof EE_Registration) {
471 471
             throw new EE_Error(
472 472
                 __('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
473 473
             );
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 
476 476
         // validate given context
477 477
         $contexts = $message_type->get_contexts();
478
-        if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
478
+        if ($message->context() !== '' && ! isset($contexts[$message->context()])) {
479 479
             throw new EE_Error(
480 480
                 sprintf(
481 481
                     __('The context %s is not a valid context for %s.', 'event_espresso'),
@@ -486,11 +486,11 @@  discard block
 block discarded – undo
486 486
         }
487 487
 
488 488
         // valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
489
-        if (! empty($sending_messenger)) {
489
+        if ( ! empty($sending_messenger)) {
490 490
             $with_messengers = $message_type->with_messengers();
491 491
             if (
492
-                ! isset($with_messengers[ $message->messenger() ])
493
-                 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
492
+                ! isset($with_messengers[$message->messenger()])
493
+                 || ! in_array($sending_messenger, $with_messengers[$message->messenger()])
494 494
             ) {
495 495
                 throw new EE_Error(
496 496
                     sprintf(
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
     public static function get_message_action_icon($type)
628 628
     {
629 629
         $action_icons = self::get_message_action_icons();
630
-        return isset($action_icons[ $type ]) ? $action_icons[ $type ] : '';
630
+        return isset($action_icons[$type]) ? $action_icons[$type] : '';
631 631
     }
632 632
 
633 633
 
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
     public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
691 691
     {
692 692
         $action_urls = self::get_message_action_urls($message, $query_params);
693
-        return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
693
+        return isset($action_urls[$type]) ? $action_urls[$type] : '';
694 694
     }
695 695
 
696 696
 
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
         EE_Registry::instance()->load_helper('URL');
711 711
         // if $message is not an instance of EE_Message then let's just do a dummy.
712 712
         $message = empty($message) ? EE_Message_Factory::create() : $message;
713
-        $action_urls =  apply_filters(
713
+        $action_urls = apply_filters(
714 714
             'FHEE__EEH_MSG_Template__get_message_action_url',
715 715
             array(
716 716
                 'view' => EEH_MSG_Template::generate_browser_trigger($message),
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
     {
792 792
         $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
793 793
         $icon_css = EEH_MSG_Template::get_message_action_icon($type);
794
-        $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
794
+        $title = isset($icon_css['label']) ? 'title="'.$icon_css['label'].'"' : '';
795 795
 
796 796
         if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
797 797
             return '';
@@ -800,14 +800,14 @@  discard block
 block discarded – undo
800 800
         $icon_css['css_class'] .= esc_attr(
801 801
             apply_filters(
802 802
                 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
803
-                ' js-ee-message-action-link ee-message-action-link-' . $type,
803
+                ' js-ee-message-action-link ee-message-action-link-'.$type,
804 804
                 $type,
805 805
                 $message,
806 806
                 $query_params
807 807
             )
808 808
         );
809 809
 
810
-        return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
810
+        return '<a href="'.$url.'"'.$title.'><span class="'.esc_attr($icon_css['css_class']).'"></span></a>';
811 811
     }
812 812
 
813 813
 
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
     public static function convert_reg_status_to_message_type($reg_status)
849 849
     {
850 850
         $reg_status_array = self::reg_status_to_message_type_array();
851
-        return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
851
+        return isset($reg_status_array[$reg_status]) ? $reg_status_array[$reg_status] : '';
852 852
     }
853 853
 
854 854
 
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
     public static function convert_payment_status_to_message_type($payment_status)
887 887
     {
888 888
         $payment_status_array = self::payment_status_to_message_type_array();
889
-        return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
889
+        return isset($payment_status_array[$payment_status]) ? $payment_status_array[$payment_status] : '';
890 890
     }
891 891
 
892 892
 
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
      */
900 900
     public static function get_template_pack($template_pack_name)
901 901
     {
902
-        if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
902
+        if ( ! self::$_template_pack_collection instanceof EE_Object_Collection) {
903 903
             self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
904 904
         }
905 905
 
@@ -912,14 +912,14 @@  discard block
 block discarded – undo
912 912
 
913 913
         // nope...let's get it.
914 914
         // not set yet so let's attempt to get it.
915
-        $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
915
+        $pack_class_name = 'EE_Messages_Template_Pack_'.str_replace(
916 916
             ' ',
917 917
             '_',
918 918
             ucwords(
919 919
                 str_replace('_', ' ', $template_pack_name)
920 920
             )
921 921
         );
922
-        if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
922
+        if ( ! class_exists($pack_class_name) && $template_pack_name !== 'default') {
923 923
             return self::get_template_pack('default');
924 924
         } else {
925 925
             $template_pack = new $pack_class_name();
@@ -942,18 +942,18 @@  discard block
 block discarded – undo
942 942
     public static function get_template_pack_collection()
943 943
     {
944 944
         $new_collection = false;
945
-        if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
945
+        if ( ! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
946 946
             self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
947 947
             $new_collection = true;
948 948
         }
949 949
 
950 950
         // glob the defaults directory for messages
951
-        $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
951
+        $templates = glob(EE_LIBRARIES.'messages/defaults/*', GLOB_ONLYDIR);
952 952
         foreach ($templates as $template_path) {
953 953
             // grab folder name
954 954
             $template = basename($template_path);
955 955
 
956
-            if (! $new_collection) {
956
+            if ( ! $new_collection) {
957 957
                 // already have it?
958 958
                 if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
959 959
                     continue;
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
             }
962 962
 
963 963
             // setup classname.
964
-            $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
964
+            $template_pack_class_name = 'EE_Messages_Template_Pack_'.str_replace(
965 965
                 ' ',
966 966
                 '_',
967 967
                 ucwords(
@@ -972,7 +972,7 @@  discard block
 block discarded – undo
972 972
                     )
973 973
                 )
974 974
             );
975
-            if (! class_exists($template_pack_class_name)) {
975
+            if ( ! class_exists($template_pack_class_name)) {
976 976
                 continue;
977 977
             }
978 978
             self::$_template_pack_collection->add(new $template_pack_class_name());
@@ -1014,7 +1014,7 @@  discard block
 block discarded – undo
1014 1014
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1015 1015
         $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1016 1016
         $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1017
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1017
+        if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1018 1018
             return array();
1019 1019
         }
1020 1020
         // whew made it this far!  Okay, let's go ahead and create the templates then
@@ -1033,13 +1033,13 @@  discard block
 block discarded – undo
1033 1033
     protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1034 1034
     {
1035 1035
         // if we're creating a custom template then we don't need to use the defaults class
1036
-        if (! $global) {
1036
+        if ( ! $global) {
1037 1037
             return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1038 1038
         }
1039 1039
         /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1040 1040
         $Message_Template_Defaults = EE_Registry::factory(
1041 1041
             'EE_Messages_Template_Defaults',
1042
-            array( $messenger, $message_type, $GRP_ID )
1042
+            array($messenger, $message_type, $GRP_ID)
1043 1043
         );
1044 1044
         // generate templates
1045 1045
         $success = $Message_Template_Defaults->create_new_templates();
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
         // if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1048 1048
         // its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1049 1049
         // attempts.
1050
-        if (! $success) {
1050
+        if ( ! $success) {
1051 1051
             /** @var EE_Message_Resource_Manager $message_resource_manager */
1052 1052
             $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1053 1053
             $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
@@ -1081,7 +1081,7 @@  discard block
 block discarded – undo
1081 1081
     private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1082 1082
     {
1083 1083
         // defaults
1084
-        $success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1084
+        $success = array('GRP_ID' => null, 'MTP_context' => '');
1085 1085
         // get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1086 1086
         $Message_Template_Group = empty($GRP_ID)
1087 1087
             ? EEM_Message_Template_Group::instance()->get_one(
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
             )
1096 1096
             : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1097 1097
         // if we don't have a mtg at this point then we need to bail.
1098
-        if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1098
+        if ( ! $Message_Template_Group instanceof EE_Message_Template_Group) {
1099 1099
             EE_Error::add_error(
1100 1100
                 sprintf(
1101 1101
                     __(
@@ -1141,7 +1141,7 @@  discard block
 block discarded – undo
1141 1141
         $success['template_name'] = $template_name;
1142 1142
         // add new message templates and add relation to.
1143 1143
         foreach ($message_templates as $message_template) {
1144
-            if (! $message_template instanceof EE_Message_Template) {
1144
+            if ( ! $message_template instanceof EE_Message_Template) {
1145 1145
                 continue;
1146 1146
             }
1147 1147
             $new_message_template = clone $message_template;
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1220 1220
         $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1221 1221
         $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1222
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1222
+        if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1223 1223
             return array();
1224 1224
         }
1225 1225
 
@@ -1231,7 +1231,7 @@  discard block
 block discarded – undo
1231 1231
                 if (in_array($field, $excluded_fields_for_messenger, true)) {
1232 1232
                     continue;
1233 1233
                 }
1234
-                $template_fields[ $context ][ $field ] = $value;
1234
+                $template_fields[$context][$field] = $value;
1235 1235
             }
1236 1236
         }
1237 1237
         if (empty($template_fields)) {
Please login to merge, or discard this patch.
core/helpers/EEH_Template.helper.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
      * _find_common_base_path
309 309
      * given two paths, this determines if there is a common base path between the two
310 310
      *
311
-     * @param array $paths
311
+     * @param string[] $paths
312 312
      * @return string
313 313
      */
314 314
     protected static function _find_common_base_path($paths)
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
      * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
339 339
      * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
340 340
      *                                      not found or is not readable
341
-     * @return mixed string
341
+     * @return string string
342 342
      * @throws \DomainException
343 343
      */
344 344
     public static function display_template(
Please login to merge, or discard this patch.
Indentation   +964 added lines, -964 removed lines patch added patch discarded remove patch
@@ -5,35 +5,35 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\services\loaders\LoaderFactory;
6 6
 
7 7
 if (! function_exists('espresso_get_template_part')) {
8
-    /**
9
-     * espresso_get_template_part
10
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
11
-     * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
12
-     *
13
-     * @param string $slug The slug name for the generic template.
14
-     * @param string $name The name of the specialised template.
15
-     * @return string        the html output for the formatted money value
16
-     */
17
-    function espresso_get_template_part($slug = null, $name = null)
18
-    {
19
-        EEH_Template::get_template_part($slug, $name);
20
-    }
8
+	/**
9
+	 * espresso_get_template_part
10
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
11
+	 * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
12
+	 *
13
+	 * @param string $slug The slug name for the generic template.
14
+	 * @param string $name The name of the specialised template.
15
+	 * @return string        the html output for the formatted money value
16
+	 */
17
+	function espresso_get_template_part($slug = null, $name = null)
18
+	{
19
+		EEH_Template::get_template_part($slug, $name);
20
+	}
21 21
 }
22 22
 
23 23
 
24 24
 if (! function_exists('espresso_get_object_css_class')) {
25
-    /**
26
-     * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27
-     *
28
-     * @param EE_Base_Class $object the EE object the css class is being generated for
29
-     * @param  string       $prefix added to the beginning of the generated class
30
-     * @param  string       $suffix added to the end of the generated class
31
-     * @return string
32
-     */
33
-    function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
34
-    {
35
-        return EEH_Template::get_object_css_class($object, $prefix, $suffix);
36
-    }
25
+	/**
26
+	 * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27
+	 *
28
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
29
+	 * @param  string       $prefix added to the beginning of the generated class
30
+	 * @param  string       $suffix added to the end of the generated class
31
+	 * @return string
32
+	 */
33
+	function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
34
+	{
35
+		return EEH_Template::get_object_css_class($object, $prefix, $suffix);
36
+	}
37 37
 }
38 38
 
39 39
 
@@ -48,672 +48,672 @@  discard block
 block discarded – undo
48 48
 class EEH_Template
49 49
 {
50 50
 
51
-    private static $_espresso_themes = array();
52
-
53
-
54
-    /**
55
-     *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
56
-     *
57
-     * @return boolean
58
-     */
59
-    public static function is_espresso_theme()
60
-    {
61
-        return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
62
-    }
63
-
64
-    /**
65
-     *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
66
-     *    load it's functions.php file ( if not already loaded )
67
-     *
68
-     * @return void
69
-     */
70
-    public static function load_espresso_theme_functions()
71
-    {
72
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
74
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
75
-            }
76
-        }
77
-    }
78
-
79
-
80
-    /**
81
-     *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
82
-     *
83
-     * @return array
84
-     */
85
-    public static function get_espresso_themes()
86
-    {
87
-        if (empty(EEH_Template::$_espresso_themes)) {
88
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
89
-            if (empty($espresso_themes)) {
90
-                return array();
91
-            }
92
-            if (($key = array_search('global_assets', $espresso_themes)) !== false) {
93
-                unset($espresso_themes[ $key ]);
94
-            }
95
-            EEH_Template::$_espresso_themes = array();
96
-            foreach ($espresso_themes as $espresso_theme) {
97
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
98
-            }
99
-        }
100
-        return EEH_Template::$_espresso_themes;
101
-    }
102
-
103
-
104
-    /**
105
-     * EEH_Template::get_template_part
106
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
107
-     * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
108
-     * filtering based off of the entire template part name
109
-     *
110
-     * @param string $slug The slug name for the generic template.
111
-     * @param string $name The name of the specialised template.
112
-     * @param array  $template_args
113
-     * @param bool   $return_string
114
-     * @return string        the html output for the formatted money value
115
-     */
116
-    public static function get_template_part(
117
-        $slug = null,
118
-        $name = null,
119
-        $template_args = array(),
120
-        $return_string = false
121
-    ) {
122
-        do_action("get_template_part_{$slug}-{$name}", $slug, $name);
123
-        $templates = array();
124
-        $name      = (string) $name;
125
-        if ($name != '') {
126
-            $templates[] = "{$slug}-{$name}.php";
127
-        }
128
-        // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
129
-        if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
130
-            EEH_Template::locate_template($templates, $template_args, true, $return_string);
131
-        }
132
-    }
133
-
134
-
135
-    /**
136
-     *    locate_template
137
-     *    locate a template file by looking in the following places, in the following order:
138
-     *        <server path up to>/wp-content/themes/<current active WordPress theme>/
139
-     *        <assumed full absolute server path>
140
-     *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
141
-     *        <server path up to>/wp-content/uploads/espresso/templates/
142
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
143
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
144
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/
145
-     *    as soon as the template is found in one of these locations, it will be returned or loaded
146
-     *        Example:
147
-     *          You are using the WordPress Twenty Sixteen theme,
148
-     *        and you want to customize the "some-event.template.php" template,
149
-     *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
150
-     *          Assuming WP is installed on your server in the "/home/public_html/" folder,
151
-     *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
152
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
153
-     *        /relative/path/to/some-event.template.php
154
-     *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
155
-     *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
156
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
157
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
158
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
159
-     *          Had you passed an absolute path to your template that was in some other location,
160
-     *        ie: "/absolute/path/to/some-event.template.php"
161
-     *          then the search would have been :
162
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
163
-     *        /absolute/path/to/some-event.template.php
164
-     *          and stopped there upon finding it in the second location
165
-     *
166
-     * @param array|string $templates       array of template file names including extension (or just a single string)
167
-     * @param  array       $template_args   an array of arguments to be extracted for use in the template
168
-     * @param  boolean     $load            whether to pass the located template path on to the
169
-     *                                      EEH_Template::display_template() method or simply return it
170
-     * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
171
-     *                                      string
172
-     * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
173
-     *                                      generate a custom template or not. Used in places where you don't actually
174
-     *                                      load the template, you just want to know if there's a custom version of it.
175
-     * @return mixed
176
-     * @throws DomainException
177
-     * @throws InvalidArgumentException
178
-     * @throws InvalidDataTypeException
179
-     * @throws InvalidInterfaceException
180
-     */
181
-    public static function locate_template(
182
-        $templates = array(),
183
-        $template_args = array(),
184
-        $load = true,
185
-        $return_string = true,
186
-        $check_if_custom = false
187
-    ) {
188
-        // first use WP locate_template to check for template in the current theme folder
189
-        $template_path = locate_template($templates);
190
-
191
-        if ($check_if_custom && ! empty($template_path)) {
192
-            return true;
193
-        }
194
-
195
-        // not in the theme
196
-        if (empty($template_path)) {
197
-            // not even a template to look for ?
198
-            if (empty($templates)) {
199
-                // get post_type
200
-                $post_type = EE_Registry::instance()->REQ->get('post_type');
201
-                /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
202
-                $custom_post_types = LoaderFactory::getLoader()->getShared(
203
-                    'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
204
-                );
205
-                // get array of EE Custom Post Types
206
-                $EE_CPTs = $custom_post_types->getDefinitions();
207
-                // build template name based on request
208
-                if (isset($EE_CPTs[ $post_type ])) {
209
-                    $archive_or_single = is_archive() ? 'archive' : '';
210
-                    $archive_or_single = is_single() ? 'single' : $archive_or_single;
211
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
212
-                }
213
-            }
214
-            // currently active EE template theme
215
-            $current_theme = EE_Config::get_current_theme();
216
-
217
-            // array of paths to folders that may contain templates
218
-            $template_folder_paths = array(
219
-                // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
220
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
221
-                // then in the root of the /wp-content/uploads/espresso/templates/ folder
222
-                EVENT_ESPRESSO_TEMPLATE_DIR,
223
-            );
224
-
225
-            // add core plugin folders for checking only if we're not $check_if_custom
226
-            if (! $check_if_custom) {
227
-                $core_paths            = array(
228
-                    // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
229
-                    EE_PUBLIC . $current_theme,
230
-                    // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
231
-                    EE_TEMPLATES . $current_theme,
232
-                    // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
233
-                    EE_PLUGIN_DIR_PATH,
234
-                );
235
-                $template_folder_paths = array_merge($template_folder_paths, $core_paths);
236
-            }
237
-
238
-            // now filter that array
239
-            $template_folder_paths = apply_filters(
240
-                'FHEE__EEH_Template__locate_template__template_folder_paths',
241
-                $template_folder_paths
242
-            );
243
-            $templates             = is_array($templates) ? $templates : array($templates);
244
-            $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
245
-            // array to hold all possible template paths
246
-            $full_template_paths = array();
247
-
248
-            // loop through $templates
249
-            foreach ($templates as $template) {
250
-                // normalize directory separators
251
-                $template                      = EEH_File::standardise_directory_separators($template);
252
-                $file_name                     = basename($template);
253
-                $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
254
-                // while looping through all template folder paths
255
-                foreach ($template_folder_paths as $template_folder_path) {
256
-                    // normalize directory separators
257
-                    $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
258
-                    // determine if any common base path exists between the two paths
259
-                    $common_base_path = EEH_Template::_find_common_base_path(
260
-                        array($template_folder_path, $template_path_minus_file_name)
261
-                    );
262
-                    if ($common_base_path !== '') {
263
-                        // both paths have a common base, so just tack the filename onto our search path
264
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
265
-                    } else {
266
-                        // no common base path, so let's just concatenate
267
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
268
-                    }
269
-                    // build up our template locations array by adding our resolved paths
270
-                    $full_template_paths[] = $resolved_path;
271
-                }
272
-                // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
273
-                array_unshift($full_template_paths, $template);
274
-                // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
275
-                array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
276
-            }
277
-            // filter final array of full template paths
278
-            $full_template_paths = apply_filters(
279
-                'FHEE__EEH_Template__locate_template__full_template_paths',
280
-                $full_template_paths,
281
-                $file_name
282
-            );
283
-            // now loop through our final array of template location paths and check each location
284
-            foreach ((array) $full_template_paths as $full_template_path) {
285
-                if (is_readable($full_template_path)) {
286
-                    $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
287
-                    break;
288
-                }
289
-            }
290
-        }
291
-
292
-        // hook that can be used to display the full template path that will be used
293
-        do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
294
-
295
-        // if we got it and you want to see it...
296
-        if ($template_path && $load && ! $check_if_custom) {
297
-            if ($return_string) {
298
-                return EEH_Template::display_template($template_path, $template_args, true);
299
-            } else {
300
-                EEH_Template::display_template($template_path, $template_args, false);
301
-            }
302
-        }
303
-        return $check_if_custom && ! empty($template_path) ? true : $template_path;
304
-    }
305
-
306
-
307
-    /**
308
-     * _find_common_base_path
309
-     * given two paths, this determines if there is a common base path between the two
310
-     *
311
-     * @param array $paths
312
-     * @return string
313
-     */
314
-    protected static function _find_common_base_path($paths)
315
-    {
316
-        $last_offset      = 0;
317
-        $common_base_path = '';
318
-        while (($index = strpos($paths[0], '/', $last_offset)) !== false) {
319
-            $dir_length = $index - $last_offset + 1;
320
-            $directory  = substr($paths[0], $last_offset, $dir_length);
321
-            foreach ($paths as $path) {
322
-                if (substr($path, $last_offset, $dir_length) != $directory) {
323
-                    return $common_base_path;
324
-                }
325
-            }
326
-            $common_base_path .= $directory;
327
-            $last_offset = $index + 1;
328
-        }
329
-        return substr($common_base_path, 0, -1);
330
-    }
331
-
332
-
333
-    /**
334
-     * load and display a template
335
-     *
336
-     * @param bool|string $template_path server path to the file to be loaded, including file name and extension
337
-     * @param  array      $template_args an array of arguments to be extracted for use in the template
338
-     * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
339
-     * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
340
-     *                                      not found or is not readable
341
-     * @return mixed string
342
-     * @throws \DomainException
343
-     */
344
-    public static function display_template(
345
-        $template_path = false,
346
-        $template_args = array(),
347
-        $return_string = false,
348
-        $throw_exceptions = false
349
-    ) {
350
-
351
-        /**
352
-         * These two filters are intended for last minute changes to templates being loaded and/or template arg
353
-         * modifications.  NOTE... modifying these things can cause breakage as most templates running through
354
-         * the display_template method are templates we DON'T want modified (usually because of js
355
-         * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
356
-         * using this.
357
-         *
358
-         * @since 4.6.0
359
-         */
360
-        $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
361
-        $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
362
-
363
-        // you gimme nuttin - YOU GET NUTTIN !!
364
-        if (! $template_path || ! is_readable($template_path)) {
365
-            return '';
366
-        }
367
-        // if $template_args are not in an array, then make it so
368
-        if (! is_array($template_args) && ! is_object($template_args)) {
369
-            $template_args = array($template_args);
370
-        }
371
-        extract($template_args, EXTR_SKIP);
372
-        // ignore whether template is accessible ?
373
-        if ($throw_exceptions && ! is_readable($template_path)) {
374
-            throw new \DomainException(
375
-                esc_html__(
376
-                    'Invalid, unreadable, or missing file.',
377
-                    'event_espresso'
378
-                )
379
-            );
380
-        }
381
-
382
-
383
-        if ($return_string) {
384
-            // because we want to return a string, we are going to capture the output
385
-            ob_start();
386
-            include($template_path);
387
-            return ob_get_clean();
388
-        } else {
389
-            include($template_path);
390
-        }
391
-        return '';
392
-    }
393
-
394
-
395
-    /**
396
-     * get_object_css_class - attempts to generate a css class based on the type of EE object passed
397
-     *
398
-     * @param EE_Base_Class $object the EE object the css class is being generated for
399
-     * @param  string       $prefix added to the beginning of the generated class
400
-     * @param  string       $suffix added to the end of the generated class
401
-     * @return string
402
-     */
403
-    public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
404
-    {
405
-        // in the beginning...
406
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
407
-        // da muddle
408
-        $class = '';
409
-        // the end
410
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
411
-        // is the passed object an EE object ?
412
-        if ($object instanceof EE_Base_Class) {
413
-            // grab the exact type of object
414
-            $obj_class = get_class($object);
415
-            // depending on the type of object...
416
-            switch ($obj_class) {
417
-                // no specifics just yet...
418
-                default:
419
-                    $class = strtolower(str_replace('_', '-', $obj_class));
420
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
421
-            }
422
-        }
423
-        return $prefix . $class . $suffix;
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * EEH_Template::format_currency
430
-     * This helper takes a raw float value and formats it according to the default config country currency settings, or
431
-     * the country currency settings from the supplied country ISO code
432
-     *
433
-     * @param  float   $amount       raw money value
434
-     * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
435
-     * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
436
-     * @param string   $CNT_ISO      2 letter ISO code for a country
437
-     * @param string   $cur_code_span_class
438
-     * @return string        the html output for the formatted money value
439
-     * @throws \EE_Error
440
-     */
441
-    public static function format_currency(
442
-        $amount = null,
443
-        $return_raw = false,
444
-        $display_code = true,
445
-        $CNT_ISO = '',
446
-        $cur_code_span_class = 'currency-code'
447
-    ) {
448
-        // ensure amount was received
449
-        if ($amount === null) {
450
-            $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
451
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
452
-            return '';
453
-        }
454
-        // ensure amount is float
455
-        $amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
456
-        $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
457
-        // filter raw amount (allows 0.00 to be changed to "free" for example)
458
-        $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
459
-        // still a number or was amount converted to a string like "free" ?
460
-        if (is_float($amount_formatted)) {
461
-            // was a country ISO code passed ? if so generate currency config object for that country
462
-            $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
463
-            // verify results
464
-            if (! $mny instanceof EE_Currency_Config) {
465
-                // set default config country currency settings
466
-                $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
467
-                    ? EE_Registry::instance()->CFG->currency
468
-                    : new EE_Currency_Config();
469
-            }
470
-            // format float
471
-            $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
472
-            // add formatting ?
473
-            if (! $return_raw) {
474
-                // add currency sign
475
-                if ($mny->sign_b4) {
476
-                    if ($amount >= 0) {
477
-                        $amount_formatted = $mny->sign . $amount_formatted;
478
-                    } else {
479
-                        $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
480
-                    }
481
-                } else {
482
-                    $amount_formatted = $amount_formatted . $mny->sign;
483
-                }
484
-
485
-                // filter to allow global setting of display_code
486
-                $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
487
-
488
-                // add currency code ?
489
-                $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
490
-            }
491
-            // filter results
492
-            $amount_formatted = apply_filters(
493
-                'FHEE__EEH_Template__format_currency__amount_formatted',
494
-                $amount_formatted,
495
-                $mny,
496
-                $return_raw
497
-            );
498
-        }
499
-        // clean up vars
500
-        unset($mny);
501
-        // return formatted currency amount
502
-        return $amount_formatted;
503
-    }
504
-
505
-
506
-    /**
507
-     * This function is used for outputting the localized label for a given status id in the schema requested (and
508
-     * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
509
-     * related status model or model object (i.e. in documentation etc.)
510
-     *
511
-     * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
512
-     *                            match, then 'Unknown' will be returned.
513
-     * @param  boolean $plural    Whether to return plural or not
514
-     * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
515
-     * @return string             The localized label for the status id.
516
-     */
517
-    public static function pretty_status($status_id, $plural = false, $schema = 'upper')
518
-    {
519
-        /** @type EEM_Status $EEM_Status */
520
-        $EEM_Status = EE_Registry::instance()->load_model('Status');
521
-        $status     = $EEM_Status->localized_status(
522
-            array($status_id => __('unknown', 'event_espresso')),
523
-            $plural,
524
-            $schema
525
-        );
526
-        return $status[ $status_id ];
527
-    }
528
-
529
-
530
-    /**
531
-     * This helper just returns a button or link for the given parameters
532
-     *
533
-     * @param  string $url   the url for the link, note that `esc_url` will be called on it
534
-     * @param  string $label What is the label you want displayed for the button
535
-     * @param  string $class what class is used for the button (defaults to 'button-primary')
536
-     * @param string  $icon
537
-     * @param string  $title
538
-     * @return string the html output for the button
539
-     */
540
-    public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
541
-    {
542
-        $icon_html = '';
543
-        if (! empty($icon)) {
544
-            $dashicons = preg_split("(ee-icon |dashicons )", $icon);
545
-            $dashicons = array_filter($dashicons);
546
-            $count     = count($dashicons);
547
-            $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
548
-            foreach ($dashicons as $dashicon) {
549
-                $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
550
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
551
-            }
552
-            $icon_html .= $count > 1 ? '</span>' : '';
553
-        }
554
-        $label  = ! empty($icon) ? $icon_html . $label : $label;
555
-        $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
556
-        return $button;
557
-    }
558
-
559
-
560
-    /**
561
-     * This returns a generated link that will load the related help tab on admin pages.
562
-     *
563
-     * @param  string     $help_tab_id the id for the connected help tab
564
-     * @param bool|string $page        The page identifier for the page the help tab is on
565
-     * @param bool|string $action      The action (route) for the admin page the help tab is on.
566
-     * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
567
-     * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
568
-     * @return string              generated link
569
-     */
570
-    public static function get_help_tab_link(
571
-        $help_tab_id,
572
-        $page = false,
573
-        $action = false,
574
-        $icon_style = false,
575
-        $help_text = false
576
-    ) {
577
-
578
-        if (! $page) {
579
-            $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
580
-        }
581
-
582
-        if (! $action) {
583
-            $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
584
-        }
585
-
586
-        $action = empty($action) ? 'default' : $action;
587
-
588
-
589
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
590
-        $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
591
-        $help_text    = ! $help_text ? '' : $help_text;
592
-        return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__(
593
-            'Click to open the \'Help\' tab for more information about this feature.',
594
-            'event_espresso'
595
-        ) . '" > ' . $help_text . ' </a>';
596
-    }
597
-
598
-
599
-    /**
600
-     * This helper generates the html structure for the jquery joyride plugin with the given params.
601
-     *
602
-     * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
603
-     * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
604
-     * @param EE_Help_Tour
605
-     * @return string         html
606
-     */
607
-    public static function help_tour_stops_generator(EE_Help_Tour $tour)
608
-    {
609
-        $id    = $tour->get_slug();
610
-        $stops = $tour->get_stops();
611
-
612
-        $content = '<ol style="display:none" id="' . $id . '">';
613
-
614
-        foreach ($stops as $stop) {
615
-            $data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
616
-            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
617
-
618
-            // if container is set to modal then let's make sure we set the options accordingly
619
-            if (empty($data_id) && empty($data_class)) {
620
-                $stop['options']['modal']  = true;
621
-                $stop['options']['expose'] = true;
622
-            }
623
-
624
-            $custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
625
-            $button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
626
-            $inner_content = isset($stop['content']) ? $stop['content'] : '';
627
-
628
-            // options
629
-            if (isset($stop['options']) && is_array($stop['options'])) {
630
-                $options = ' data-options="';
631
-                foreach ($stop['options'] as $option => $value) {
632
-                    $options .= $option . ':' . $value . ';';
633
-                }
634
-                $options .= '"';
635
-            } else {
636
-                $options = '';
637
-            }
638
-
639
-            // let's put all together
640
-            $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
641
-        }
642
-
643
-        $content .= '</ol>';
644
-        return $content;
645
-    }
646
-
647
-
648
-    /**
649
-     * This is a helper method to generate a status legend for a given status array.
650
-     * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
651
-     * status_array.
652
-     *
653
-     * @param  array  $status_array  array of statuses that will make up the legend. In format:
654
-     *                               array(
655
-     *                               'status_item' => 'status_name'
656
-     *                               )
657
-     * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
658
-     *                               the legend.
659
-     * @throws EE_Error
660
-     * @return string               html structure for status.
661
-     */
662
-    public static function status_legend($status_array, $active_status = '')
663
-    {
664
-        if (! is_array($status_array)) {
665
-            throw new EE_Error(esc_html__(
666
-                'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
667
-                'event_espresso'
668
-            ));
669
-        }
670
-
671
-        $setup_array = array();
672
-        foreach ($status_array as $item => $status) {
673
-            $setup_array[ $item ] = array(
674
-                'class'  => 'ee-status-legend ee-status-legend-' . $status,
675
-                'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
676
-                'status' => $status,
677
-            );
678
-        }
679
-
680
-        $content = '<div class="ee-list-table-legend-container">' . "\n";
681
-        $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
682
-        $content .= '<dl class="ee-list-table-legend">' . "\n\t";
683
-        foreach ($setup_array as $item => $details) {
684
-            $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
685
-            $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
686
-            $content .= '<span class="ee-legend-item-wrap"><span class="' . $details['class'] . '"></span></span>' . "\n\t\t";
687
-            $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
688
-            $content .= '</dt>' . "\n";
689
-        }
690
-        $content .= '</dl>' . "\n";
691
-        $content .= '</div>' . "\n";
692
-        return $content;
693
-    }
694
-
695
-
696
-    /**
697
-     * Gets HTML for laying out a deeply-nested array (and objects) in a format
698
-     * that's nice for presenting in the wp admin
699
-     *
700
-     * @param mixed $data
701
-     * @return string
702
-     */
703
-    public static function layout_array_as_table($data)
704
-    {
705
-        if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
706
-            $data = (array) $data;
707
-        }
708
-        ob_start();
709
-        if (is_array($data)) {
710
-            if (EEH_Array::is_associative_array($data)) {
711
-                ?>
51
+	private static $_espresso_themes = array();
52
+
53
+
54
+	/**
55
+	 *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
56
+	 *
57
+	 * @return boolean
58
+	 */
59
+	public static function is_espresso_theme()
60
+	{
61
+		return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
62
+	}
63
+
64
+	/**
65
+	 *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
66
+	 *    load it's functions.php file ( if not already loaded )
67
+	 *
68
+	 * @return void
69
+	 */
70
+	public static function load_espresso_theme_functions()
71
+	{
72
+		if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
+			if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
74
+				require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
75
+			}
76
+		}
77
+	}
78
+
79
+
80
+	/**
81
+	 *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
82
+	 *
83
+	 * @return array
84
+	 */
85
+	public static function get_espresso_themes()
86
+	{
87
+		if (empty(EEH_Template::$_espresso_themes)) {
88
+			$espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
89
+			if (empty($espresso_themes)) {
90
+				return array();
91
+			}
92
+			if (($key = array_search('global_assets', $espresso_themes)) !== false) {
93
+				unset($espresso_themes[ $key ]);
94
+			}
95
+			EEH_Template::$_espresso_themes = array();
96
+			foreach ($espresso_themes as $espresso_theme) {
97
+				EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
98
+			}
99
+		}
100
+		return EEH_Template::$_espresso_themes;
101
+	}
102
+
103
+
104
+	/**
105
+	 * EEH_Template::get_template_part
106
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
107
+	 * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
108
+	 * filtering based off of the entire template part name
109
+	 *
110
+	 * @param string $slug The slug name for the generic template.
111
+	 * @param string $name The name of the specialised template.
112
+	 * @param array  $template_args
113
+	 * @param bool   $return_string
114
+	 * @return string        the html output for the formatted money value
115
+	 */
116
+	public static function get_template_part(
117
+		$slug = null,
118
+		$name = null,
119
+		$template_args = array(),
120
+		$return_string = false
121
+	) {
122
+		do_action("get_template_part_{$slug}-{$name}", $slug, $name);
123
+		$templates = array();
124
+		$name      = (string) $name;
125
+		if ($name != '') {
126
+			$templates[] = "{$slug}-{$name}.php";
127
+		}
128
+		// allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
129
+		if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
130
+			EEH_Template::locate_template($templates, $template_args, true, $return_string);
131
+		}
132
+	}
133
+
134
+
135
+	/**
136
+	 *    locate_template
137
+	 *    locate a template file by looking in the following places, in the following order:
138
+	 *        <server path up to>/wp-content/themes/<current active WordPress theme>/
139
+	 *        <assumed full absolute server path>
140
+	 *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
141
+	 *        <server path up to>/wp-content/uploads/espresso/templates/
142
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
143
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
144
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/
145
+	 *    as soon as the template is found in one of these locations, it will be returned or loaded
146
+	 *        Example:
147
+	 *          You are using the WordPress Twenty Sixteen theme,
148
+	 *        and you want to customize the "some-event.template.php" template,
149
+	 *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
150
+	 *          Assuming WP is installed on your server in the "/home/public_html/" folder,
151
+	 *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
152
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
153
+	 *        /relative/path/to/some-event.template.php
154
+	 *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
155
+	 *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
156
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
157
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
158
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
159
+	 *          Had you passed an absolute path to your template that was in some other location,
160
+	 *        ie: "/absolute/path/to/some-event.template.php"
161
+	 *          then the search would have been :
162
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
163
+	 *        /absolute/path/to/some-event.template.php
164
+	 *          and stopped there upon finding it in the second location
165
+	 *
166
+	 * @param array|string $templates       array of template file names including extension (or just a single string)
167
+	 * @param  array       $template_args   an array of arguments to be extracted for use in the template
168
+	 * @param  boolean     $load            whether to pass the located template path on to the
169
+	 *                                      EEH_Template::display_template() method or simply return it
170
+	 * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
171
+	 *                                      string
172
+	 * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
173
+	 *                                      generate a custom template or not. Used in places where you don't actually
174
+	 *                                      load the template, you just want to know if there's a custom version of it.
175
+	 * @return mixed
176
+	 * @throws DomainException
177
+	 * @throws InvalidArgumentException
178
+	 * @throws InvalidDataTypeException
179
+	 * @throws InvalidInterfaceException
180
+	 */
181
+	public static function locate_template(
182
+		$templates = array(),
183
+		$template_args = array(),
184
+		$load = true,
185
+		$return_string = true,
186
+		$check_if_custom = false
187
+	) {
188
+		// first use WP locate_template to check for template in the current theme folder
189
+		$template_path = locate_template($templates);
190
+
191
+		if ($check_if_custom && ! empty($template_path)) {
192
+			return true;
193
+		}
194
+
195
+		// not in the theme
196
+		if (empty($template_path)) {
197
+			// not even a template to look for ?
198
+			if (empty($templates)) {
199
+				// get post_type
200
+				$post_type = EE_Registry::instance()->REQ->get('post_type');
201
+				/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
202
+				$custom_post_types = LoaderFactory::getLoader()->getShared(
203
+					'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
204
+				);
205
+				// get array of EE Custom Post Types
206
+				$EE_CPTs = $custom_post_types->getDefinitions();
207
+				// build template name based on request
208
+				if (isset($EE_CPTs[ $post_type ])) {
209
+					$archive_or_single = is_archive() ? 'archive' : '';
210
+					$archive_or_single = is_single() ? 'single' : $archive_or_single;
211
+					$templates         = $archive_or_single . '-' . $post_type . '.php';
212
+				}
213
+			}
214
+			// currently active EE template theme
215
+			$current_theme = EE_Config::get_current_theme();
216
+
217
+			// array of paths to folders that may contain templates
218
+			$template_folder_paths = array(
219
+				// first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
220
+				EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
221
+				// then in the root of the /wp-content/uploads/espresso/templates/ folder
222
+				EVENT_ESPRESSO_TEMPLATE_DIR,
223
+			);
224
+
225
+			// add core plugin folders for checking only if we're not $check_if_custom
226
+			if (! $check_if_custom) {
227
+				$core_paths            = array(
228
+					// in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
229
+					EE_PUBLIC . $current_theme,
230
+					// in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
231
+					EE_TEMPLATES . $current_theme,
232
+					// or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
233
+					EE_PLUGIN_DIR_PATH,
234
+				);
235
+				$template_folder_paths = array_merge($template_folder_paths, $core_paths);
236
+			}
237
+
238
+			// now filter that array
239
+			$template_folder_paths = apply_filters(
240
+				'FHEE__EEH_Template__locate_template__template_folder_paths',
241
+				$template_folder_paths
242
+			);
243
+			$templates             = is_array($templates) ? $templates : array($templates);
244
+			$template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
245
+			// array to hold all possible template paths
246
+			$full_template_paths = array();
247
+
248
+			// loop through $templates
249
+			foreach ($templates as $template) {
250
+				// normalize directory separators
251
+				$template                      = EEH_File::standardise_directory_separators($template);
252
+				$file_name                     = basename($template);
253
+				$template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
254
+				// while looping through all template folder paths
255
+				foreach ($template_folder_paths as $template_folder_path) {
256
+					// normalize directory separators
257
+					$template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
258
+					// determine if any common base path exists between the two paths
259
+					$common_base_path = EEH_Template::_find_common_base_path(
260
+						array($template_folder_path, $template_path_minus_file_name)
261
+					);
262
+					if ($common_base_path !== '') {
263
+						// both paths have a common base, so just tack the filename onto our search path
264
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
265
+					} else {
266
+						// no common base path, so let's just concatenate
267
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
268
+					}
269
+					// build up our template locations array by adding our resolved paths
270
+					$full_template_paths[] = $resolved_path;
271
+				}
272
+				// if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
273
+				array_unshift($full_template_paths, $template);
274
+				// path to the directory of the current theme: /wp-content/themes/(current WP theme)/
275
+				array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
276
+			}
277
+			// filter final array of full template paths
278
+			$full_template_paths = apply_filters(
279
+				'FHEE__EEH_Template__locate_template__full_template_paths',
280
+				$full_template_paths,
281
+				$file_name
282
+			);
283
+			// now loop through our final array of template location paths and check each location
284
+			foreach ((array) $full_template_paths as $full_template_path) {
285
+				if (is_readable($full_template_path)) {
286
+					$template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
287
+					break;
288
+				}
289
+			}
290
+		}
291
+
292
+		// hook that can be used to display the full template path that will be used
293
+		do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
294
+
295
+		// if we got it and you want to see it...
296
+		if ($template_path && $load && ! $check_if_custom) {
297
+			if ($return_string) {
298
+				return EEH_Template::display_template($template_path, $template_args, true);
299
+			} else {
300
+				EEH_Template::display_template($template_path, $template_args, false);
301
+			}
302
+		}
303
+		return $check_if_custom && ! empty($template_path) ? true : $template_path;
304
+	}
305
+
306
+
307
+	/**
308
+	 * _find_common_base_path
309
+	 * given two paths, this determines if there is a common base path between the two
310
+	 *
311
+	 * @param array $paths
312
+	 * @return string
313
+	 */
314
+	protected static function _find_common_base_path($paths)
315
+	{
316
+		$last_offset      = 0;
317
+		$common_base_path = '';
318
+		while (($index = strpos($paths[0], '/', $last_offset)) !== false) {
319
+			$dir_length = $index - $last_offset + 1;
320
+			$directory  = substr($paths[0], $last_offset, $dir_length);
321
+			foreach ($paths as $path) {
322
+				if (substr($path, $last_offset, $dir_length) != $directory) {
323
+					return $common_base_path;
324
+				}
325
+			}
326
+			$common_base_path .= $directory;
327
+			$last_offset = $index + 1;
328
+		}
329
+		return substr($common_base_path, 0, -1);
330
+	}
331
+
332
+
333
+	/**
334
+	 * load and display a template
335
+	 *
336
+	 * @param bool|string $template_path server path to the file to be loaded, including file name and extension
337
+	 * @param  array      $template_args an array of arguments to be extracted for use in the template
338
+	 * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
339
+	 * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
340
+	 *                                      not found or is not readable
341
+	 * @return mixed string
342
+	 * @throws \DomainException
343
+	 */
344
+	public static function display_template(
345
+		$template_path = false,
346
+		$template_args = array(),
347
+		$return_string = false,
348
+		$throw_exceptions = false
349
+	) {
350
+
351
+		/**
352
+		 * These two filters are intended for last minute changes to templates being loaded and/or template arg
353
+		 * modifications.  NOTE... modifying these things can cause breakage as most templates running through
354
+		 * the display_template method are templates we DON'T want modified (usually because of js
355
+		 * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
356
+		 * using this.
357
+		 *
358
+		 * @since 4.6.0
359
+		 */
360
+		$template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
361
+		$template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
362
+
363
+		// you gimme nuttin - YOU GET NUTTIN !!
364
+		if (! $template_path || ! is_readable($template_path)) {
365
+			return '';
366
+		}
367
+		// if $template_args are not in an array, then make it so
368
+		if (! is_array($template_args) && ! is_object($template_args)) {
369
+			$template_args = array($template_args);
370
+		}
371
+		extract($template_args, EXTR_SKIP);
372
+		// ignore whether template is accessible ?
373
+		if ($throw_exceptions && ! is_readable($template_path)) {
374
+			throw new \DomainException(
375
+				esc_html__(
376
+					'Invalid, unreadable, or missing file.',
377
+					'event_espresso'
378
+				)
379
+			);
380
+		}
381
+
382
+
383
+		if ($return_string) {
384
+			// because we want to return a string, we are going to capture the output
385
+			ob_start();
386
+			include($template_path);
387
+			return ob_get_clean();
388
+		} else {
389
+			include($template_path);
390
+		}
391
+		return '';
392
+	}
393
+
394
+
395
+	/**
396
+	 * get_object_css_class - attempts to generate a css class based on the type of EE object passed
397
+	 *
398
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
399
+	 * @param  string       $prefix added to the beginning of the generated class
400
+	 * @param  string       $suffix added to the end of the generated class
401
+	 * @return string
402
+	 */
403
+	public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
404
+	{
405
+		// in the beginning...
406
+		$prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
407
+		// da muddle
408
+		$class = '';
409
+		// the end
410
+		$suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
411
+		// is the passed object an EE object ?
412
+		if ($object instanceof EE_Base_Class) {
413
+			// grab the exact type of object
414
+			$obj_class = get_class($object);
415
+			// depending on the type of object...
416
+			switch ($obj_class) {
417
+				// no specifics just yet...
418
+				default:
419
+					$class = strtolower(str_replace('_', '-', $obj_class));
420
+					$class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
421
+			}
422
+		}
423
+		return $prefix . $class . $suffix;
424
+	}
425
+
426
+
427
+
428
+	/**
429
+	 * EEH_Template::format_currency
430
+	 * This helper takes a raw float value and formats it according to the default config country currency settings, or
431
+	 * the country currency settings from the supplied country ISO code
432
+	 *
433
+	 * @param  float   $amount       raw money value
434
+	 * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
435
+	 * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
436
+	 * @param string   $CNT_ISO      2 letter ISO code for a country
437
+	 * @param string   $cur_code_span_class
438
+	 * @return string        the html output for the formatted money value
439
+	 * @throws \EE_Error
440
+	 */
441
+	public static function format_currency(
442
+		$amount = null,
443
+		$return_raw = false,
444
+		$display_code = true,
445
+		$CNT_ISO = '',
446
+		$cur_code_span_class = 'currency-code'
447
+	) {
448
+		// ensure amount was received
449
+		if ($amount === null) {
450
+			$msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
451
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
452
+			return '';
453
+		}
454
+		// ensure amount is float
455
+		$amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
456
+		$CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
457
+		// filter raw amount (allows 0.00 to be changed to "free" for example)
458
+		$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
459
+		// still a number or was amount converted to a string like "free" ?
460
+		if (is_float($amount_formatted)) {
461
+			// was a country ISO code passed ? if so generate currency config object for that country
462
+			$mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
463
+			// verify results
464
+			if (! $mny instanceof EE_Currency_Config) {
465
+				// set default config country currency settings
466
+				$mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
467
+					? EE_Registry::instance()->CFG->currency
468
+					: new EE_Currency_Config();
469
+			}
470
+			// format float
471
+			$amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
472
+			// add formatting ?
473
+			if (! $return_raw) {
474
+				// add currency sign
475
+				if ($mny->sign_b4) {
476
+					if ($amount >= 0) {
477
+						$amount_formatted = $mny->sign . $amount_formatted;
478
+					} else {
479
+						$amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
480
+					}
481
+				} else {
482
+					$amount_formatted = $amount_formatted . $mny->sign;
483
+				}
484
+
485
+				// filter to allow global setting of display_code
486
+				$display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
487
+
488
+				// add currency code ?
489
+				$amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
490
+			}
491
+			// filter results
492
+			$amount_formatted = apply_filters(
493
+				'FHEE__EEH_Template__format_currency__amount_formatted',
494
+				$amount_formatted,
495
+				$mny,
496
+				$return_raw
497
+			);
498
+		}
499
+		// clean up vars
500
+		unset($mny);
501
+		// return formatted currency amount
502
+		return $amount_formatted;
503
+	}
504
+
505
+
506
+	/**
507
+	 * This function is used for outputting the localized label for a given status id in the schema requested (and
508
+	 * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
509
+	 * related status model or model object (i.e. in documentation etc.)
510
+	 *
511
+	 * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
512
+	 *                            match, then 'Unknown' will be returned.
513
+	 * @param  boolean $plural    Whether to return plural or not
514
+	 * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
515
+	 * @return string             The localized label for the status id.
516
+	 */
517
+	public static function pretty_status($status_id, $plural = false, $schema = 'upper')
518
+	{
519
+		/** @type EEM_Status $EEM_Status */
520
+		$EEM_Status = EE_Registry::instance()->load_model('Status');
521
+		$status     = $EEM_Status->localized_status(
522
+			array($status_id => __('unknown', 'event_espresso')),
523
+			$plural,
524
+			$schema
525
+		);
526
+		return $status[ $status_id ];
527
+	}
528
+
529
+
530
+	/**
531
+	 * This helper just returns a button or link for the given parameters
532
+	 *
533
+	 * @param  string $url   the url for the link, note that `esc_url` will be called on it
534
+	 * @param  string $label What is the label you want displayed for the button
535
+	 * @param  string $class what class is used for the button (defaults to 'button-primary')
536
+	 * @param string  $icon
537
+	 * @param string  $title
538
+	 * @return string the html output for the button
539
+	 */
540
+	public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
541
+	{
542
+		$icon_html = '';
543
+		if (! empty($icon)) {
544
+			$dashicons = preg_split("(ee-icon |dashicons )", $icon);
545
+			$dashicons = array_filter($dashicons);
546
+			$count     = count($dashicons);
547
+			$icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
548
+			foreach ($dashicons as $dashicon) {
549
+				$type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
550
+				$icon_html .= '<span class="' . $type . $dashicon . '"></span>';
551
+			}
552
+			$icon_html .= $count > 1 ? '</span>' : '';
553
+		}
554
+		$label  = ! empty($icon) ? $icon_html . $label : $label;
555
+		$button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
556
+		return $button;
557
+	}
558
+
559
+
560
+	/**
561
+	 * This returns a generated link that will load the related help tab on admin pages.
562
+	 *
563
+	 * @param  string     $help_tab_id the id for the connected help tab
564
+	 * @param bool|string $page        The page identifier for the page the help tab is on
565
+	 * @param bool|string $action      The action (route) for the admin page the help tab is on.
566
+	 * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
567
+	 * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
568
+	 * @return string              generated link
569
+	 */
570
+	public static function get_help_tab_link(
571
+		$help_tab_id,
572
+		$page = false,
573
+		$action = false,
574
+		$icon_style = false,
575
+		$help_text = false
576
+	) {
577
+
578
+		if (! $page) {
579
+			$page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
580
+		}
581
+
582
+		if (! $action) {
583
+			$action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
584
+		}
585
+
586
+		$action = empty($action) ? 'default' : $action;
587
+
588
+
589
+		$help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
590
+		$icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
591
+		$help_text    = ! $help_text ? '' : $help_text;
592
+		return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__(
593
+			'Click to open the \'Help\' tab for more information about this feature.',
594
+			'event_espresso'
595
+		) . '" > ' . $help_text . ' </a>';
596
+	}
597
+
598
+
599
+	/**
600
+	 * This helper generates the html structure for the jquery joyride plugin with the given params.
601
+	 *
602
+	 * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
603
+	 * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
604
+	 * @param EE_Help_Tour
605
+	 * @return string         html
606
+	 */
607
+	public static function help_tour_stops_generator(EE_Help_Tour $tour)
608
+	{
609
+		$id    = $tour->get_slug();
610
+		$stops = $tour->get_stops();
611
+
612
+		$content = '<ol style="display:none" id="' . $id . '">';
613
+
614
+		foreach ($stops as $stop) {
615
+			$data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
616
+			$data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
617
+
618
+			// if container is set to modal then let's make sure we set the options accordingly
619
+			if (empty($data_id) && empty($data_class)) {
620
+				$stop['options']['modal']  = true;
621
+				$stop['options']['expose'] = true;
622
+			}
623
+
624
+			$custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
625
+			$button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
626
+			$inner_content = isset($stop['content']) ? $stop['content'] : '';
627
+
628
+			// options
629
+			if (isset($stop['options']) && is_array($stop['options'])) {
630
+				$options = ' data-options="';
631
+				foreach ($stop['options'] as $option => $value) {
632
+					$options .= $option . ':' . $value . ';';
633
+				}
634
+				$options .= '"';
635
+			} else {
636
+				$options = '';
637
+			}
638
+
639
+			// let's put all together
640
+			$content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
641
+		}
642
+
643
+		$content .= '</ol>';
644
+		return $content;
645
+	}
646
+
647
+
648
+	/**
649
+	 * This is a helper method to generate a status legend for a given status array.
650
+	 * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
651
+	 * status_array.
652
+	 *
653
+	 * @param  array  $status_array  array of statuses that will make up the legend. In format:
654
+	 *                               array(
655
+	 *                               'status_item' => 'status_name'
656
+	 *                               )
657
+	 * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
658
+	 *                               the legend.
659
+	 * @throws EE_Error
660
+	 * @return string               html structure for status.
661
+	 */
662
+	public static function status_legend($status_array, $active_status = '')
663
+	{
664
+		if (! is_array($status_array)) {
665
+			throw new EE_Error(esc_html__(
666
+				'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
667
+				'event_espresso'
668
+			));
669
+		}
670
+
671
+		$setup_array = array();
672
+		foreach ($status_array as $item => $status) {
673
+			$setup_array[ $item ] = array(
674
+				'class'  => 'ee-status-legend ee-status-legend-' . $status,
675
+				'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
676
+				'status' => $status,
677
+			);
678
+		}
679
+
680
+		$content = '<div class="ee-list-table-legend-container">' . "\n";
681
+		$content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
682
+		$content .= '<dl class="ee-list-table-legend">' . "\n\t";
683
+		foreach ($setup_array as $item => $details) {
684
+			$active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
685
+			$content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
686
+			$content .= '<span class="ee-legend-item-wrap"><span class="' . $details['class'] . '"></span></span>' . "\n\t\t";
687
+			$content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
688
+			$content .= '</dt>' . "\n";
689
+		}
690
+		$content .= '</dl>' . "\n";
691
+		$content .= '</div>' . "\n";
692
+		return $content;
693
+	}
694
+
695
+
696
+	/**
697
+	 * Gets HTML for laying out a deeply-nested array (and objects) in a format
698
+	 * that's nice for presenting in the wp admin
699
+	 *
700
+	 * @param mixed $data
701
+	 * @return string
702
+	 */
703
+	public static function layout_array_as_table($data)
704
+	{
705
+		if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
706
+			$data = (array) $data;
707
+		}
708
+		ob_start();
709
+		if (is_array($data)) {
710
+			if (EEH_Array::is_associative_array($data)) {
711
+				?>
712 712
                 <table class="widefat">
713 713
                     <tbody>
714 714
                     <?php
715
-                    foreach ($data as $data_key => $data_values) {
716
-                        ?>
715
+					foreach ($data as $data_key => $data_values) {
716
+						?>
717 717
                         <tr>
718 718
                             <td>
719 719
                                 <?php echo $data_key; ?>
@@ -723,293 +723,293 @@  discard block
 block discarded – undo
723 723
                             </td>
724 724
                         </tr>
725 725
                         <?php
726
-                    } ?>
726
+					} ?>
727 727
                     </tbody>
728 728
                 </table>
729 729
                 <?php
730
-            } else {
731
-                ?>
730
+			} else {
731
+				?>
732 732
                 <ul>
733 733
                     <?php
734
-                    foreach ($data as $datum) {
735
-                        echo "<li>";
736
-                        echo self::layout_array_as_table($datum);
737
-                        echo "</li>";
738
-                    } ?>
734
+					foreach ($data as $datum) {
735
+						echo "<li>";
736
+						echo self::layout_array_as_table($datum);
737
+						echo "</li>";
738
+					} ?>
739 739
                 </ul>
740 740
                 <?php
741
-            }
742
-        } else {
743
-            // simple value
744
-            echo esc_html($data);
745
-        }
746
-        return ob_get_clean();
747
-    }
748
-
749
-
750
-    /**
751
-     * wrapper for self::get_paging_html() that simply echos the generated paging html
752
-     *
753
-     * @since 4.4.0
754
-     * @see   self:get_paging_html() for argument docs.
755
-     * @param        $total_items
756
-     * @param        $current
757
-     * @param        $per_page
758
-     * @param        $url
759
-     * @param bool   $show_num_field
760
-     * @param string $paged_arg_name
761
-     * @param array  $items_label
762
-     * @return string
763
-     */
764
-    public static function paging_html(
765
-        $total_items,
766
-        $current,
767
-        $per_page,
768
-        $url,
769
-        $show_num_field = true,
770
-        $paged_arg_name = 'paged',
771
-        $items_label = array()
772
-    ) {
773
-        echo self::get_paging_html(
774
-            $total_items,
775
-            $current,
776
-            $per_page,
777
-            $url,
778
-            $show_num_field,
779
-            $paged_arg_name,
780
-            $items_label
781
-        );
782
-    }
783
-
784
-
785
-    /**
786
-     * A method for generating paging similar to WP_List_Table
787
-     *
788
-     * @since    4.4.0
789
-     * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
790
-     * @param  integer $total_items     How many total items there are to page.
791
-     * @param  integer $current         What the current page is.
792
-     * @param  integer $per_page        How many items per page.
793
-     * @param  string  $url             What the base url for page links is.
794
-     * @param  boolean $show_num_field  Whether to show the input for changing page number.
795
-     * @param  string  $paged_arg_name  The name of the key for the paged query argument.
796
-     * @param  array   $items_label     An array of singular/plural values for the items label:
797
-     *                                  array(
798
-     *                                  'single' => 'item',
799
-     *                                  'plural' => 'items'
800
-     *                                  )
801
-     * @return  string
802
-     */
803
-    public static function get_paging_html(
804
-        $total_items,
805
-        $current,
806
-        $per_page,
807
-        $url,
808
-        $show_num_field = true,
809
-        $paged_arg_name = 'paged',
810
-        $items_label = array()
811
-    ) {
812
-        $page_links     = array();
813
-        $disable_first  = $disable_last = '';
814
-        $total_items    = (int) $total_items;
815
-        $per_page       = (int) $per_page;
816
-        $current        = (int) $current;
817
-        $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
818
-
819
-        // filter items_label
820
-        $items_label = apply_filters(
821
-            'FHEE__EEH_Template__get_paging_html__items_label',
822
-            $items_label
823
-        );
824
-
825
-        if (
826
-            empty($items_label)
827
-            || ! is_array($items_label)
828
-            || ! isset($items_label['single'])
829
-            || ! isset($items_label['plural'])
830
-        ) {
831
-            $items_label = array(
832
-                'single' => __('1 item', 'event_espresso'),
833
-                'plural' => __('%s items', 'event_espresso'),
834
-            );
835
-        } else {
836
-            $items_label = array(
837
-                'single' => '1 ' . esc_html($items_label['single']),
838
-                'plural' => '%s ' . esc_html($items_label['plural']),
839
-            );
840
-        }
841
-
842
-        $total_pages = ceil($total_items / $per_page);
843
-
844
-        if ($total_pages <= 1) {
845
-            return '';
846
-        }
847
-
848
-        $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
849
-
850
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
851
-
852
-        if ($current === 1) {
853
-            $disable_first = ' disabled';
854
-        }
855
-        if ($current == $total_pages) {
856
-            $disable_last = ' disabled';
857
-        }
858
-
859
-        $page_links[] = sprintf(
860
-            "<a class='%s' title='%s' href='%s'>%s</a>",
861
-            'first-page' . $disable_first,
862
-            esc_attr__('Go to the first page', 'event_espresso'),
863
-            esc_url(remove_query_arg($paged_arg_name, $url)),
864
-            '&laquo;'
865
-        );
866
-
867
-        $page_links[] = sprintf(
868
-            '<a class="%s" title="%s" href="%s">%s</a>',
869
-            'prev-page' . $disable_first,
870
-            esc_attr__('Go to the previous page', 'event_espresso'),
871
-            esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
872
-            '&lsaquo;'
873
-        );
874
-
875
-        if (! $show_num_field) {
876
-            $html_current_page = $current;
877
-        } else {
878
-            $html_current_page = sprintf(
879
-                "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
880
-                esc_attr__('Current page', 'event_espresso'),
881
-                $current,
882
-                strlen($total_pages)
883
-            );
884
-        }
885
-
886
-        $html_total_pages = sprintf(
887
-            '<span class="total-pages">%s</span>',
888
-            number_format_i18n($total_pages)
889
-        );
890
-        $page_links[]     = sprintf(
891
-            _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
892
-            $html_current_page,
893
-            $html_total_pages,
894
-            '<span class="paging-input">',
895
-            '</span>'
896
-        );
897
-
898
-        $page_links[] = sprintf(
899
-            '<a class="%s" title="%s" href="%s">%s</a>',
900
-            'next-page' . $disable_last,
901
-            esc_attr__('Go to the next page', 'event_espresso'),
902
-            esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
903
-            '&rsaquo;'
904
-        );
905
-
906
-        $page_links[] = sprintf(
907
-            '<a class="%s" title="%s" href="%s">%s</a>',
908
-            'last-page' . $disable_last,
909
-            esc_attr__('Go to the last page', 'event_espresso'),
910
-            esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
911
-            '&raquo;'
912
-        );
913
-
914
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
915
-        // set page class
916
-        if ($total_pages) {
917
-            $page_class = $total_pages < 2 ? ' one-page' : '';
918
-        } else {
919
-            $page_class = ' no-pages';
920
-        }
921
-
922
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
923
-    }
924
-
925
-
926
-    /**
927
-     * @param string $wrap_class
928
-     * @param string $wrap_id
929
-     * @return string
930
-     */
931
-    public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
932
-    {
933
-        $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
934
-        if (
935
-            ! $admin &&
936
-            ! apply_filters(
937
-                'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
938
-                EE_Registry::instance()->CFG->admin->show_reg_footer
939
-            )
940
-        ) {
941
-            return '';
942
-        }
943
-        $tag        = $admin ? 'span' : 'div';
944
-        $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
945
-        $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
946
-        $attributes .= ! empty($wrap_class)
947
-            ? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
948
-            : ' class="powered-by-event-espresso-credit"';
949
-        $query_args = array_merge(
950
-            array(
951
-                'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
952
-                'utm_source'   => 'powered_by_event_espresso',
953
-                'utm_medium'   => 'link',
954
-                'utm_campaign' => 'powered_by',
955
-            ),
956
-            $query_args
957
-        );
958
-        $powered_by = apply_filters(
959
-            'FHEE__EEH_Template__powered_by_event_espresso_text',
960
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
961
-        );
962
-        $url        = add_query_arg($query_args, 'https://eventespresso.com/');
963
-        $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
964
-        return (string) apply_filters(
965
-            'FHEE__EEH_Template__powered_by_event_espresso__html',
966
-            sprintf(
967
-                esc_html_x(
968
-                    '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
969
-                    'Online event registration and ticketing powered by [link to eventespresso.com]',
970
-                    'event_espresso'
971
-                ),
972
-                "<{$tag}{$attributes}>",
973
-                "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
974
-                $admin ? '' : '<br />'
975
-            ),
976
-            $wrap_class,
977
-            $wrap_id
978
-        );
979
-    }
741
+			}
742
+		} else {
743
+			// simple value
744
+			echo esc_html($data);
745
+		}
746
+		return ob_get_clean();
747
+	}
748
+
749
+
750
+	/**
751
+	 * wrapper for self::get_paging_html() that simply echos the generated paging html
752
+	 *
753
+	 * @since 4.4.0
754
+	 * @see   self:get_paging_html() for argument docs.
755
+	 * @param        $total_items
756
+	 * @param        $current
757
+	 * @param        $per_page
758
+	 * @param        $url
759
+	 * @param bool   $show_num_field
760
+	 * @param string $paged_arg_name
761
+	 * @param array  $items_label
762
+	 * @return string
763
+	 */
764
+	public static function paging_html(
765
+		$total_items,
766
+		$current,
767
+		$per_page,
768
+		$url,
769
+		$show_num_field = true,
770
+		$paged_arg_name = 'paged',
771
+		$items_label = array()
772
+	) {
773
+		echo self::get_paging_html(
774
+			$total_items,
775
+			$current,
776
+			$per_page,
777
+			$url,
778
+			$show_num_field,
779
+			$paged_arg_name,
780
+			$items_label
781
+		);
782
+	}
783
+
784
+
785
+	/**
786
+	 * A method for generating paging similar to WP_List_Table
787
+	 *
788
+	 * @since    4.4.0
789
+	 * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
790
+	 * @param  integer $total_items     How many total items there are to page.
791
+	 * @param  integer $current         What the current page is.
792
+	 * @param  integer $per_page        How many items per page.
793
+	 * @param  string  $url             What the base url for page links is.
794
+	 * @param  boolean $show_num_field  Whether to show the input for changing page number.
795
+	 * @param  string  $paged_arg_name  The name of the key for the paged query argument.
796
+	 * @param  array   $items_label     An array of singular/plural values for the items label:
797
+	 *                                  array(
798
+	 *                                  'single' => 'item',
799
+	 *                                  'plural' => 'items'
800
+	 *                                  )
801
+	 * @return  string
802
+	 */
803
+	public static function get_paging_html(
804
+		$total_items,
805
+		$current,
806
+		$per_page,
807
+		$url,
808
+		$show_num_field = true,
809
+		$paged_arg_name = 'paged',
810
+		$items_label = array()
811
+	) {
812
+		$page_links     = array();
813
+		$disable_first  = $disable_last = '';
814
+		$total_items    = (int) $total_items;
815
+		$per_page       = (int) $per_page;
816
+		$current        = (int) $current;
817
+		$paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
818
+
819
+		// filter items_label
820
+		$items_label = apply_filters(
821
+			'FHEE__EEH_Template__get_paging_html__items_label',
822
+			$items_label
823
+		);
824
+
825
+		if (
826
+			empty($items_label)
827
+			|| ! is_array($items_label)
828
+			|| ! isset($items_label['single'])
829
+			|| ! isset($items_label['plural'])
830
+		) {
831
+			$items_label = array(
832
+				'single' => __('1 item', 'event_espresso'),
833
+				'plural' => __('%s items', 'event_espresso'),
834
+			);
835
+		} else {
836
+			$items_label = array(
837
+				'single' => '1 ' . esc_html($items_label['single']),
838
+				'plural' => '%s ' . esc_html($items_label['plural']),
839
+			);
840
+		}
841
+
842
+		$total_pages = ceil($total_items / $per_page);
843
+
844
+		if ($total_pages <= 1) {
845
+			return '';
846
+		}
847
+
848
+		$item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
849
+
850
+		$output = '<span class="displaying-num">' . $item_label . '</span>';
851
+
852
+		if ($current === 1) {
853
+			$disable_first = ' disabled';
854
+		}
855
+		if ($current == $total_pages) {
856
+			$disable_last = ' disabled';
857
+		}
858
+
859
+		$page_links[] = sprintf(
860
+			"<a class='%s' title='%s' href='%s'>%s</a>",
861
+			'first-page' . $disable_first,
862
+			esc_attr__('Go to the first page', 'event_espresso'),
863
+			esc_url(remove_query_arg($paged_arg_name, $url)),
864
+			'&laquo;'
865
+		);
866
+
867
+		$page_links[] = sprintf(
868
+			'<a class="%s" title="%s" href="%s">%s</a>',
869
+			'prev-page' . $disable_first,
870
+			esc_attr__('Go to the previous page', 'event_espresso'),
871
+			esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
872
+			'&lsaquo;'
873
+		);
874
+
875
+		if (! $show_num_field) {
876
+			$html_current_page = $current;
877
+		} else {
878
+			$html_current_page = sprintf(
879
+				"<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
880
+				esc_attr__('Current page', 'event_espresso'),
881
+				$current,
882
+				strlen($total_pages)
883
+			);
884
+		}
885
+
886
+		$html_total_pages = sprintf(
887
+			'<span class="total-pages">%s</span>',
888
+			number_format_i18n($total_pages)
889
+		);
890
+		$page_links[]     = sprintf(
891
+			_x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
892
+			$html_current_page,
893
+			$html_total_pages,
894
+			'<span class="paging-input">',
895
+			'</span>'
896
+		);
897
+
898
+		$page_links[] = sprintf(
899
+			'<a class="%s" title="%s" href="%s">%s</a>',
900
+			'next-page' . $disable_last,
901
+			esc_attr__('Go to the next page', 'event_espresso'),
902
+			esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
903
+			'&rsaquo;'
904
+		);
905
+
906
+		$page_links[] = sprintf(
907
+			'<a class="%s" title="%s" href="%s">%s</a>',
908
+			'last-page' . $disable_last,
909
+			esc_attr__('Go to the last page', 'event_espresso'),
910
+			esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
911
+			'&raquo;'
912
+		);
913
+
914
+		$output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
915
+		// set page class
916
+		if ($total_pages) {
917
+			$page_class = $total_pages < 2 ? ' one-page' : '';
918
+		} else {
919
+			$page_class = ' no-pages';
920
+		}
921
+
922
+		return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
923
+	}
924
+
925
+
926
+	/**
927
+	 * @param string $wrap_class
928
+	 * @param string $wrap_id
929
+	 * @return string
930
+	 */
931
+	public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
932
+	{
933
+		$admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
934
+		if (
935
+			! $admin &&
936
+			! apply_filters(
937
+				'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
938
+				EE_Registry::instance()->CFG->admin->show_reg_footer
939
+			)
940
+		) {
941
+			return '';
942
+		}
943
+		$tag        = $admin ? 'span' : 'div';
944
+		$attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
945
+		$wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
946
+		$attributes .= ! empty($wrap_class)
947
+			? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
948
+			: ' class="powered-by-event-espresso-credit"';
949
+		$query_args = array_merge(
950
+			array(
951
+				'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
952
+				'utm_source'   => 'powered_by_event_espresso',
953
+				'utm_medium'   => 'link',
954
+				'utm_campaign' => 'powered_by',
955
+			),
956
+			$query_args
957
+		);
958
+		$powered_by = apply_filters(
959
+			'FHEE__EEH_Template__powered_by_event_espresso_text',
960
+			$admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
961
+		);
962
+		$url        = add_query_arg($query_args, 'https://eventespresso.com/');
963
+		$url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
964
+		return (string) apply_filters(
965
+			'FHEE__EEH_Template__powered_by_event_espresso__html',
966
+			sprintf(
967
+				esc_html_x(
968
+					'%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
969
+					'Online event registration and ticketing powered by [link to eventespresso.com]',
970
+					'event_espresso'
971
+				),
972
+				"<{$tag}{$attributes}>",
973
+				"<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
974
+				$admin ? '' : '<br />'
975
+			),
976
+			$wrap_class,
977
+			$wrap_id
978
+		);
979
+	}
980 980
 }
981 981
 
982 982
 
983 983
 
984 984
 
985 985
 if (! function_exists('espresso_pagination')) {
986
-    /**
987
-     *    espresso_pagination
988
-     *
989
-     * @access    public
990
-     * @return    void
991
-     */
992
-    function espresso_pagination()
993
-    {
994
-        global $wp_query;
995
-        $big        = 999999999; // need an unlikely integer
996
-        $pagination = paginate_links(
997
-            array(
998
-                'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
999
-                'format'       => '?paged=%#%',
1000
-                'current'      => max(1, get_query_var('paged')),
1001
-                'total'        => $wp_query->max_num_pages,
1002
-                'show_all'     => true,
1003
-                'end_size'     => 10,
1004
-                'mid_size'     => 6,
1005
-                'prev_next'    => true,
1006
-                'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
1007
-                'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
1008
-                'type'         => 'plain',
1009
-                'add_args'     => false,
1010
-                'add_fragment' => '',
1011
-            )
1012
-        );
1013
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
1014
-    }
986
+	/**
987
+	 *    espresso_pagination
988
+	 *
989
+	 * @access    public
990
+	 * @return    void
991
+	 */
992
+	function espresso_pagination()
993
+	{
994
+		global $wp_query;
995
+		$big        = 999999999; // need an unlikely integer
996
+		$pagination = paginate_links(
997
+			array(
998
+				'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
999
+				'format'       => '?paged=%#%',
1000
+				'current'      => max(1, get_query_var('paged')),
1001
+				'total'        => $wp_query->max_num_pages,
1002
+				'show_all'     => true,
1003
+				'end_size'     => 10,
1004
+				'mid_size'     => 6,
1005
+				'prev_next'    => true,
1006
+				'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
1007
+				'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
1008
+				'type'         => 'plain',
1009
+				'add_args'     => false,
1010
+				'add_fragment' => '',
1011
+			)
1012
+		);
1013
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
1014
+	}
1015 1015
 }
1016 1016
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\exceptions\InvalidInterfaceException;
5 5
 use EventEspresso\core\services\loaders\LoaderFactory;
6 6
 
7
-if (! function_exists('espresso_get_template_part')) {
7
+if ( ! function_exists('espresso_get_template_part')) {
8 8
     /**
9 9
      * espresso_get_template_part
10 10
      * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 }
22 22
 
23 23
 
24
-if (! function_exists('espresso_get_object_css_class')) {
24
+if ( ! function_exists('espresso_get_object_css_class')) {
25 25
     /**
26 26
      * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27 27
      *
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public static function load_espresso_theme_functions()
71 71
     {
72
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
74
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
72
+        if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
73
+            if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php')) {
74
+                require_once(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php');
75 75
             }
76 76
         }
77 77
     }
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
     public static function get_espresso_themes()
86 86
     {
87 87
         if (empty(EEH_Template::$_espresso_themes)) {
88
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
88
+            $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR);
89 89
             if (empty($espresso_themes)) {
90 90
                 return array();
91 91
             }
92 92
             if (($key = array_search('global_assets', $espresso_themes)) !== false) {
93
-                unset($espresso_themes[ $key ]);
93
+                unset($espresso_themes[$key]);
94 94
             }
95 95
             EEH_Template::$_espresso_themes = array();
96 96
             foreach ($espresso_themes as $espresso_theme) {
97
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
97
+                EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
98 98
             }
99 99
         }
100 100
         return EEH_Template::$_espresso_themes;
@@ -205,10 +205,10 @@  discard block
 block discarded – undo
205 205
                 // get array of EE Custom Post Types
206 206
                 $EE_CPTs = $custom_post_types->getDefinitions();
207 207
                 // build template name based on request
208
-                if (isset($EE_CPTs[ $post_type ])) {
208
+                if (isset($EE_CPTs[$post_type])) {
209 209
                     $archive_or_single = is_archive() ? 'archive' : '';
210 210
                     $archive_or_single = is_single() ? 'single' : $archive_or_single;
211
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
211
+                    $templates         = $archive_or_single.'-'.$post_type.'.php';
212 212
                 }
213 213
             }
214 214
             // currently active EE template theme
@@ -217,18 +217,18 @@  discard block
 block discarded – undo
217 217
             // array of paths to folders that may contain templates
218 218
             $template_folder_paths = array(
219 219
                 // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
220
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
220
+                EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme,
221 221
                 // then in the root of the /wp-content/uploads/espresso/templates/ folder
222 222
                 EVENT_ESPRESSO_TEMPLATE_DIR,
223 223
             );
224 224
 
225 225
             // add core plugin folders for checking only if we're not $check_if_custom
226
-            if (! $check_if_custom) {
227
-                $core_paths            = array(
226
+            if ( ! $check_if_custom) {
227
+                $core_paths = array(
228 228
                     // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
229
-                    EE_PUBLIC . $current_theme,
229
+                    EE_PUBLIC.$current_theme,
230 230
                     // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
231
-                    EE_TEMPLATES . $current_theme,
231
+                    EE_TEMPLATES.$current_theme,
232 232
                     // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
233 233
                     EE_PLUGIN_DIR_PATH,
234 234
                 );
@@ -261,10 +261,10 @@  discard block
 block discarded – undo
261 261
                     );
262 262
                     if ($common_base_path !== '') {
263 263
                         // both paths have a common base, so just tack the filename onto our search path
264
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
264
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name;
265 265
                     } else {
266 266
                         // no common base path, so let's just concatenate
267
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
267
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template;
268 268
                     }
269 269
                     // build up our template locations array by adding our resolved paths
270 270
                     $full_template_paths[] = $resolved_path;
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
                 // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
273 273
                 array_unshift($full_template_paths, $template);
274 274
                 // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
275
-                array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
275
+                array_unshift($full_template_paths, get_stylesheet_directory().'/'.$file_name);
276 276
             }
277 277
             // filter final array of full template paths
278 278
             $full_template_paths = apply_filters(
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
         $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
362 362
 
363 363
         // you gimme nuttin - YOU GET NUTTIN !!
364
-        if (! $template_path || ! is_readable($template_path)) {
364
+        if ( ! $template_path || ! is_readable($template_path)) {
365 365
             return '';
366 366
         }
367 367
         // if $template_args are not in an array, then make it so
368
-        if (! is_array($template_args) && ! is_object($template_args)) {
368
+        if ( ! is_array($template_args) && ! is_object($template_args)) {
369 369
             $template_args = array($template_args);
370 370
         }
371 371
         extract($template_args, EXTR_SKIP);
@@ -403,11 +403,11 @@  discard block
 block discarded – undo
403 403
     public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
404 404
     {
405 405
         // in the beginning...
406
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
406
+        $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : '';
407 407
         // da muddle
408 408
         $class = '';
409 409
         // the end
410
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
410
+        $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : '';
411 411
         // is the passed object an EE object ?
412 412
         if ($object instanceof EE_Base_Class) {
413 413
             // grab the exact type of object
@@ -417,10 +417,10 @@  discard block
 block discarded – undo
417 417
                 // no specifics just yet...
418 418
                 default:
419 419
                     $class = strtolower(str_replace('_', '-', $obj_class));
420
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
420
+                    $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : '';
421 421
             }
422 422
         }
423
-        return $prefix . $class . $suffix;
423
+        return $prefix.$class.$suffix;
424 424
     }
425 425
 
426 426
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
             // was a country ISO code passed ? if so generate currency config object for that country
462 462
             $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
463 463
             // verify results
464
-            if (! $mny instanceof EE_Currency_Config) {
464
+            if ( ! $mny instanceof EE_Currency_Config) {
465 465
                 // set default config country currency settings
466 466
                 $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
467 467
                     ? EE_Registry::instance()->CFG->currency
@@ -470,23 +470,23 @@  discard block
 block discarded – undo
470 470
             // format float
471 471
             $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
472 472
             // add formatting ?
473
-            if (! $return_raw) {
473
+            if ( ! $return_raw) {
474 474
                 // add currency sign
475 475
                 if ($mny->sign_b4) {
476 476
                     if ($amount >= 0) {
477
-                        $amount_formatted = $mny->sign . $amount_formatted;
477
+                        $amount_formatted = $mny->sign.$amount_formatted;
478 478
                     } else {
479
-                        $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
479
+                        $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted);
480 480
                     }
481 481
                 } else {
482
-                    $amount_formatted = $amount_formatted . $mny->sign;
482
+                    $amount_formatted = $amount_formatted.$mny->sign;
483 483
                 }
484 484
 
485 485
                 // filter to allow global setting of display_code
486 486
                 $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
487 487
 
488 488
                 // add currency code ?
489
-                $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
489
+                $amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted;
490 490
             }
491 491
             // filter results
492 492
             $amount_formatted = apply_filters(
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
             $plural,
524 524
             $schema
525 525
         );
526
-        return $status[ $status_id ];
526
+        return $status[$status_id];
527 527
     }
528 528
 
529 529
 
@@ -540,19 +540,19 @@  discard block
 block discarded – undo
540 540
     public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
541 541
     {
542 542
         $icon_html = '';
543
-        if (! empty($icon)) {
543
+        if ( ! empty($icon)) {
544 544
             $dashicons = preg_split("(ee-icon |dashicons )", $icon);
545 545
             $dashicons = array_filter($dashicons);
546 546
             $count     = count($dashicons);
547 547
             $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
548 548
             foreach ($dashicons as $dashicon) {
549 549
                 $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
550
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
550
+                $icon_html .= '<span class="'.$type.$dashicon.'"></span>';
551 551
             }
552 552
             $icon_html .= $count > 1 ? '</span>' : '';
553 553
         }
554
-        $label  = ! empty($icon) ? $icon_html . $label : $label;
555
-        $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
554
+        $label  = ! empty($icon) ? $icon_html.$label : $label;
555
+        $button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.esc_url($url).'" class="'.$class.'" title="'.$title.'">'.$label.'</a>';
556 556
         return $button;
557 557
     }
558 558
 
@@ -575,24 +575,24 @@  discard block
 block discarded – undo
575 575
         $help_text = false
576 576
     ) {
577 577
 
578
-        if (! $page) {
578
+        if ( ! $page) {
579 579
             $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
580 580
         }
581 581
 
582
-        if (! $action) {
582
+        if ( ! $action) {
583 583
             $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
584 584
         }
585 585
 
586 586
         $action = empty($action) ? 'default' : $action;
587 587
 
588 588
 
589
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
589
+        $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id;
590 590
         $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
591 591
         $help_text    = ! $help_text ? '' : $help_text;
592
-        return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__(
592
+        return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__(
593 593
             'Click to open the \'Help\' tab for more information about this feature.',
594 594
             'event_espresso'
595
-        ) . '" > ' . $help_text . ' </a>';
595
+        ).'" > '.$help_text.' </a>';
596 596
     }
597 597
 
598 598
 
@@ -609,11 +609,11 @@  discard block
 block discarded – undo
609 609
         $id    = $tour->get_slug();
610 610
         $stops = $tour->get_stops();
611 611
 
612
-        $content = '<ol style="display:none" id="' . $id . '">';
612
+        $content = '<ol style="display:none" id="'.$id.'">';
613 613
 
614 614
         foreach ($stops as $stop) {
615
-            $data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
616
-            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
615
+            $data_id    = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : '';
616
+            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : '';
617 617
 
618 618
             // if container is set to modal then let's make sure we set the options accordingly
619 619
             if (empty($data_id) && empty($data_class)) {
@@ -621,15 +621,15 @@  discard block
 block discarded – undo
621 621
                 $stop['options']['expose'] = true;
622 622
             }
623 623
 
624
-            $custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
625
-            $button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
624
+            $custom_class  = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : '';
625
+            $button_text   = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : '';
626 626
             $inner_content = isset($stop['content']) ? $stop['content'] : '';
627 627
 
628 628
             // options
629 629
             if (isset($stop['options']) && is_array($stop['options'])) {
630 630
                 $options = ' data-options="';
631 631
                 foreach ($stop['options'] as $option => $value) {
632
-                    $options .= $option . ':' . $value . ';';
632
+                    $options .= $option.':'.$value.';';
633 633
                 }
634 634
                 $options .= '"';
635 635
             } else {
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
             }
638 638
 
639 639
             // let's put all together
640
-            $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
640
+            $content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>';
641 641
         }
642 642
 
643 643
         $content .= '</ol>';
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
      */
662 662
     public static function status_legend($status_array, $active_status = '')
663 663
     {
664
-        if (! is_array($status_array)) {
664
+        if ( ! is_array($status_array)) {
665 665
             throw new EE_Error(esc_html__(
666 666
                 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
667 667
                 'event_espresso'
@@ -670,25 +670,25 @@  discard block
 block discarded – undo
670 670
 
671 671
         $setup_array = array();
672 672
         foreach ($status_array as $item => $status) {
673
-            $setup_array[ $item ] = array(
674
-                'class'  => 'ee-status-legend ee-status-legend-' . $status,
673
+            $setup_array[$item] = array(
674
+                'class'  => 'ee-status-legend ee-status-legend-'.$status,
675 675
                 'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
676 676
                 'status' => $status,
677 677
             );
678 678
         }
679 679
 
680
-        $content = '<div class="ee-list-table-legend-container">' . "\n";
681
-        $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
682
-        $content .= '<dl class="ee-list-table-legend">' . "\n\t";
680
+        $content = '<div class="ee-list-table-legend-container">'."\n";
681
+        $content .= '<h4 class="status-legend-title">'.esc_html__('Status Legend', 'event_espresso').'</h4>'."\n";
682
+        $content .= '<dl class="ee-list-table-legend">'."\n\t";
683 683
         foreach ($setup_array as $item => $details) {
684 684
             $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
685
-            $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
686
-            $content .= '<span class="ee-legend-item-wrap"><span class="' . $details['class'] . '"></span></span>' . "\n\t\t";
687
-            $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
688
-            $content .= '</dt>' . "\n";
685
+            $content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t";
686
+            $content .= '<span class="ee-legend-item-wrap"><span class="'.$details['class'].'"></span></span>'."\n\t\t";
687
+            $content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t";
688
+            $content .= '</dt>'."\n";
689 689
         }
690
-        $content .= '</dl>' . "\n";
691
-        $content .= '</div>' . "\n";
690
+        $content .= '</dl>'."\n";
691
+        $content .= '</div>'."\n";
692 692
         return $content;
693 693
     }
694 694
 
@@ -834,8 +834,8 @@  discard block
 block discarded – undo
834 834
             );
835 835
         } else {
836 836
             $items_label = array(
837
-                'single' => '1 ' . esc_html($items_label['single']),
838
-                'plural' => '%s ' . esc_html($items_label['plural']),
837
+                'single' => '1 '.esc_html($items_label['single']),
838
+                'plural' => '%s '.esc_html($items_label['plural']),
839 839
             );
840 840
         }
841 841
 
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 
848 848
         $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
849 849
 
850
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
850
+        $output = '<span class="displaying-num">'.$item_label.'</span>';
851 851
 
852 852
         if ($current === 1) {
853 853
             $disable_first = ' disabled';
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 
859 859
         $page_links[] = sprintf(
860 860
             "<a class='%s' title='%s' href='%s'>%s</a>",
861
-            'first-page' . $disable_first,
861
+            'first-page'.$disable_first,
862 862
             esc_attr__('Go to the first page', 'event_espresso'),
863 863
             esc_url(remove_query_arg($paged_arg_name, $url)),
864 864
             '&laquo;'
@@ -866,13 +866,13 @@  discard block
 block discarded – undo
866 866
 
867 867
         $page_links[] = sprintf(
868 868
             '<a class="%s" title="%s" href="%s">%s</a>',
869
-            'prev-page' . $disable_first,
869
+            'prev-page'.$disable_first,
870 870
             esc_attr__('Go to the previous page', 'event_espresso'),
871 871
             esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
872 872
             '&lsaquo;'
873 873
         );
874 874
 
875
-        if (! $show_num_field) {
875
+        if ( ! $show_num_field) {
876 876
             $html_current_page = $current;
877 877
         } else {
878 878
             $html_current_page = sprintf(
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
             '<span class="total-pages">%s</span>',
888 888
             number_format_i18n($total_pages)
889 889
         );
890
-        $page_links[]     = sprintf(
890
+        $page_links[] = sprintf(
891 891
             _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
892 892
             $html_current_page,
893 893
             $html_total_pages,
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
 
898 898
         $page_links[] = sprintf(
899 899
             '<a class="%s" title="%s" href="%s">%s</a>',
900
-            'next-page' . $disable_last,
900
+            'next-page'.$disable_last,
901 901
             esc_attr__('Go to the next page', 'event_espresso'),
902 902
             esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
903 903
             '&rsaquo;'
@@ -905,13 +905,13 @@  discard block
 block discarded – undo
905 905
 
906 906
         $page_links[] = sprintf(
907 907
             '<a class="%s" title="%s" href="%s">%s</a>',
908
-            'last-page' . $disable_last,
908
+            'last-page'.$disable_last,
909 909
             esc_attr__('Go to the last page', 'event_espresso'),
910 910
             esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
911 911
             '&raquo;'
912 912
         );
913 913
 
914
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
914
+        $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>';
915 915
         // set page class
916 916
         if ($total_pages) {
917 917
             $page_class = $total_pages < 2 ? ' one-page' : '';
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
             $page_class = ' no-pages';
920 920
         }
921 921
 
922
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
922
+        return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>';
923 923
     }
924 924
 
925 925
 
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
         );
958 958
         $powered_by = apply_filters(
959 959
             'FHEE__EEH_Template__powered_by_event_espresso_text',
960
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
960
+            $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso'
961 961
         );
962 962
         $url        = add_query_arg($query_args, 'https://eventespresso.com/');
963 963
         $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
 
983 983
 
984 984
 
985
-if (! function_exists('espresso_pagination')) {
985
+if ( ! function_exists('espresso_pagination')) {
986 986
     /**
987 987
      *    espresso_pagination
988 988
      *
@@ -1010,6 +1010,6 @@  discard block
 block discarded – undo
1010 1010
                 'add_fragment' => '',
1011 1011
             )
1012 1012
         );
1013
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
1013
+        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : '';
1014 1014
     }
1015 1015
 }
1016 1016
\ No newline at end of file
Please login to merge, or discard this patch.
core/helpers/EEH_Template_Validator.helper.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
     /**
131 131
      * For verifying that a variable is indeed an array, else throw an EE_Error
132 132
      * @param type $variable_to_test
133
-     * @param type $variable_name
133
+     * @param string $variable_name
134 134
      * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty'
135 135
      * @return void
136 136
      * @throws EE_Error
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      * for verifying that a variable is one of the string optiosn supplied
162 162
      * @param mixed $variable_to_test
163 163
      * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages
164
-     * @param array $string_options an array of acceptable values
164
+     * @param string[] $string_options an array of acceptable values
165 165
      * @return void
166 166
      * @throws EE_Error
167 167
      */
Please login to merge, or discard this patch.
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -29,152 +29,152 @@
 block discarded – undo
29 29
 
30 30
 
31 31
 
32
-    /**
33
-     * Throws an EE_Error if $variabel_to_test isn't an array of objects of class $class_name
34
-     * @param mixed $variable_to_test
35
-     * @param string $name_of_variable helpful in throwing intelligent errors
36
-     * @param string $class_name eg EE_Answer, EE_Transaction, etc.
37
-     * @param string $allow_null one of 'allow_null', or 'do_not_allow_null'
38
-     * @return void
39
-     * @throws EE_Error (indirectly)
40
-     */
41
-    public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
42
-    {
43
-        if (!WP_DEBUG) {
44
-            return;
45
-        }
46
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
47
-        if ('allow_null' == $allow_null && is_null($variable_to_test)) {
48
-            return;
49
-        }
50
-        self::verify_is_array($variable_to_test, $name_of_variable);
51
-        foreach ($variable_to_test as $key => $array_element) {
52
-            self::verify_instanceof($array_element, $key, $class_name);
53
-        }
54
-    }
55
-
56
-
57
-
58
-
59
-
60
-    /**
61
-     * throws an EE_Error if $variable_to_test is null
62
-     * @param mixed $variable_to_test
63
-     * @param string $name_of_variable helpful for throwing intelligent errors
64
-     * @return void
65
-     * @throws EE_Error
66
-     */
67
-    public static function verify_isnt_null($variable_to_test, $name_of_variable)
68
-    {
69
-        if (!WP_DEBUG) {
70
-            return;
71
-        }
72
-        if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != false) {
73
-            $error[] = __('Variable named %s is null.', 'event_espresso');
74
-            $error[] = __("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso');
75
-            throw new EE_Error(sprintf(implode(",", $error), $name_of_variable, $name_of_variable));
76
-        }
77
-    }
78
-
79
-    /**
80
-     * When WP_DEBUG is activted, throws an error if $expression_to_test is false.
81
-     * @param boolean $expression_to_test
82
-     * @param string $expression_string_representation a string representation of your expression
83
-     * for example, if your expression were $var1==23, then this should be '$var1==23'
84
-     * @return void
85
-     * @throws EE_Error
86
-     */
87
-    public static function verify_is_true($expression_to_test, $expression_string_representation)
88
-    {
89
-        if (!WP_DEBUG) {
90
-            return;
91
-        }
92
-        if (!$expression_to_test) {
93
-            $error[] = __('Template error.', 'event_espresso');
94
-            $error[] = __("%s evaluated to false, but it must be true!", 'event_espresso');
95
-            throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
96
-        }
97
-    }
98
-
99
-
100
-
101
-
102
-
103
-    /**
104
-     * For verifying that a variable is indeed an object of class $class_name
105
-     * @param mixed $variable_to_test
106
-     * @param string $name_of_variable helpful when throwing errors
107
-     * @param string $class_name eg, EE_Answer,
108
-     * @return void
109
-     * @throws EE_Error
110
-     */
111
-    public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
112
-    {
113
-        if (!WP_DEBUG) {
114
-            return;
115
-        }
116
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
117
-        if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
118
-            return;
119
-        }
120
-        if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
121
-            $msg[] = __('Variable %s is not of the correct type.', 'event_espresso');
122
-            $msg[] = __("It should be of type %s", 'event_espresso');
123
-            throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
124
-        }
125
-    }
126
-
127
-
128
-
129
-
130
-
131
-    /**
132
-     * For verifying that a variable is indeed an array, else throw an EE_Error
133
-     * @param type $variable_to_test
134
-     * @param type $variable_name
135
-     * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty'
136
-     * @return void
137
-     * @throws EE_Error
138
-     */
139
-    public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
140
-    {
141
-        if (!WP_DEBUG) {
142
-            return;
143
-        }
144
-        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
145
-        if (empty($variable_to_test) && 'allow_empty' == $allow_empty) {
146
-            return;
147
-        }
148
-        if (!is_array($variable_to_test)) {
149
-            $error[] = __('Variable %s should be an array, but it is not.', 'event_espresso');
150
-            $error[] = __("Its value is, instead '%s'", 'event_espresso');
151
-            throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
152
-        }
153
-    }
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-    /**
162
-     * for verifying that a variable is one of the string optiosn supplied
163
-     * @param mixed $variable_to_test
164
-     * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages
165
-     * @param array $string_options an array of acceptable values
166
-     * @return void
167
-     * @throws EE_Error
168
-     */
169
-    public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
170
-    {
171
-        if (!WP_DEBUG) {
172
-            return;
173
-        }
174
-        if (!in_array($variable_to_test, $string_options)) {
175
-            $msg[0] = __('Malconfigured template.', 'event_espresso');
176
-            $msg[1] = __("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
177
-            throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
178
-        }
179
-    }
32
+	/**
33
+	 * Throws an EE_Error if $variabel_to_test isn't an array of objects of class $class_name
34
+	 * @param mixed $variable_to_test
35
+	 * @param string $name_of_variable helpful in throwing intelligent errors
36
+	 * @param string $class_name eg EE_Answer, EE_Transaction, etc.
37
+	 * @param string $allow_null one of 'allow_null', or 'do_not_allow_null'
38
+	 * @return void
39
+	 * @throws EE_Error (indirectly)
40
+	 */
41
+	public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
42
+	{
43
+		if (!WP_DEBUG) {
44
+			return;
45
+		}
46
+		self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
47
+		if ('allow_null' == $allow_null && is_null($variable_to_test)) {
48
+			return;
49
+		}
50
+		self::verify_is_array($variable_to_test, $name_of_variable);
51
+		foreach ($variable_to_test as $key => $array_element) {
52
+			self::verify_instanceof($array_element, $key, $class_name);
53
+		}
54
+	}
55
+
56
+
57
+
58
+
59
+
60
+	/**
61
+	 * throws an EE_Error if $variable_to_test is null
62
+	 * @param mixed $variable_to_test
63
+	 * @param string $name_of_variable helpful for throwing intelligent errors
64
+	 * @return void
65
+	 * @throws EE_Error
66
+	 */
67
+	public static function verify_isnt_null($variable_to_test, $name_of_variable)
68
+	{
69
+		if (!WP_DEBUG) {
70
+			return;
71
+		}
72
+		if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != false) {
73
+			$error[] = __('Variable named %s is null.', 'event_espresso');
74
+			$error[] = __("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso');
75
+			throw new EE_Error(sprintf(implode(",", $error), $name_of_variable, $name_of_variable));
76
+		}
77
+	}
78
+
79
+	/**
80
+	 * When WP_DEBUG is activted, throws an error if $expression_to_test is false.
81
+	 * @param boolean $expression_to_test
82
+	 * @param string $expression_string_representation a string representation of your expression
83
+	 * for example, if your expression were $var1==23, then this should be '$var1==23'
84
+	 * @return void
85
+	 * @throws EE_Error
86
+	 */
87
+	public static function verify_is_true($expression_to_test, $expression_string_representation)
88
+	{
89
+		if (!WP_DEBUG) {
90
+			return;
91
+		}
92
+		if (!$expression_to_test) {
93
+			$error[] = __('Template error.', 'event_espresso');
94
+			$error[] = __("%s evaluated to false, but it must be true!", 'event_espresso');
95
+			throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
96
+		}
97
+	}
98
+
99
+
100
+
101
+
102
+
103
+	/**
104
+	 * For verifying that a variable is indeed an object of class $class_name
105
+	 * @param mixed $variable_to_test
106
+	 * @param string $name_of_variable helpful when throwing errors
107
+	 * @param string $class_name eg, EE_Answer,
108
+	 * @return void
109
+	 * @throws EE_Error
110
+	 */
111
+	public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
112
+	{
113
+		if (!WP_DEBUG) {
114
+			return;
115
+		}
116
+		self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
117
+		if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
118
+			return;
119
+		}
120
+		if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
121
+			$msg[] = __('Variable %s is not of the correct type.', 'event_espresso');
122
+			$msg[] = __("It should be of type %s", 'event_espresso');
123
+			throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
124
+		}
125
+	}
126
+
127
+
128
+
129
+
130
+
131
+	/**
132
+	 * For verifying that a variable is indeed an array, else throw an EE_Error
133
+	 * @param type $variable_to_test
134
+	 * @param type $variable_name
135
+	 * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty'
136
+	 * @return void
137
+	 * @throws EE_Error
138
+	 */
139
+	public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
140
+	{
141
+		if (!WP_DEBUG) {
142
+			return;
143
+		}
144
+		self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
145
+		if (empty($variable_to_test) && 'allow_empty' == $allow_empty) {
146
+			return;
147
+		}
148
+		if (!is_array($variable_to_test)) {
149
+			$error[] = __('Variable %s should be an array, but it is not.', 'event_espresso');
150
+			$error[] = __("Its value is, instead '%s'", 'event_espresso');
151
+			throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
152
+		}
153
+	}
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+	/**
162
+	 * for verifying that a variable is one of the string optiosn supplied
163
+	 * @param mixed $variable_to_test
164
+	 * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages
165
+	 * @param array $string_options an array of acceptable values
166
+	 * @return void
167
+	 * @throws EE_Error
168
+	 */
169
+	public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
170
+	{
171
+		if (!WP_DEBUG) {
172
+			return;
173
+		}
174
+		if (!in_array($variable_to_test, $string_options)) {
175
+			$msg[0] = __('Malconfigured template.', 'event_espresso');
176
+			$msg[1] = __("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
177
+			throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
178
+		}
179
+	}
180 180
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
42 42
     {
43
-        if (!WP_DEBUG) {
43
+        if ( ! WP_DEBUG) {
44 44
             return;
45 45
         }
46
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
46
+        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null'));
47 47
         if ('allow_null' == $allow_null && is_null($variable_to_test)) {
48 48
             return;
49 49
         }
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public static function verify_isnt_null($variable_to_test, $name_of_variable)
68 68
     {
69
-        if (!WP_DEBUG) {
69
+        if ( ! WP_DEBUG) {
70 70
             return;
71 71
         }
72 72
         if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != false) {
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public static function verify_is_true($expression_to_test, $expression_string_representation)
88 88
     {
89
-        if (!WP_DEBUG) {
89
+        if ( ! WP_DEBUG) {
90 90
             return;
91 91
         }
92
-        if (!$expression_to_test) {
92
+        if ( ! $expression_to_test) {
93 93
             $error[] = __('Template error.', 'event_espresso');
94 94
             $error[] = __("%s evaluated to false, but it must be true!", 'event_espresso');
95 95
             throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
@@ -110,14 +110,14 @@  discard block
 block discarded – undo
110 110
      */
111 111
     public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
112 112
     {
113
-        if (!WP_DEBUG) {
113
+        if ( ! WP_DEBUG) {
114 114
             return;
115 115
         }
116
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
116
+        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null'));
117 117
         if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
118 118
             return;
119 119
         }
120
-        if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
120
+        if ($variable_to_test == null || ! ($variable_to_test instanceof $class_name)) {
121 121
             $msg[] = __('Variable %s is not of the correct type.', 'event_espresso');
122 122
             $msg[] = __("It should be of type %s", 'event_espresso');
123 123
             throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
@@ -138,14 +138,14 @@  discard block
 block discarded – undo
138 138
      */
139 139
     public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
140 140
     {
141
-        if (!WP_DEBUG) {
141
+        if ( ! WP_DEBUG) {
142 142
             return;
143 143
         }
144
-        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
144
+        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty', 'do_not_allow_empty'));
145 145
         if (empty($variable_to_test) && 'allow_empty' == $allow_empty) {
146 146
             return;
147 147
         }
148
-        if (!is_array($variable_to_test)) {
148
+        if ( ! is_array($variable_to_test)) {
149 149
             $error[] = __('Variable %s should be an array, but it is not.', 'event_espresso');
150 150
             $error[] = __("Its value is, instead '%s'", 'event_espresso');
151 151
             throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
170 170
     {
171
-        if (!WP_DEBUG) {
171
+        if ( ! WP_DEBUG) {
172 172
             return;
173 173
         }
174
-        if (!in_array($variable_to_test, $string_options)) {
174
+        if ( ! in_array($variable_to_test, $string_options)) {
175 175
             $msg[0] = __('Malconfigured template.', 'event_espresso');
176 176
             $msg[1] = __("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
177 177
             throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
Please login to merge, or discard this patch.
form_sections/strategies/display/EE_Select_Display_Strategy.strategy.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@
 block discarded – undo
87 87
      * Checks if that value is the one selected
88 88
      *
89 89
      * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML.
90
-     * @return string
90
+     * @return boolean
91 91
      */
92 92
     protected function _check_if_option_selected($option_value)
93 93
     {
Please login to merge, or discard this patch.
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -15,78 +15,78 @@
 block discarded – undo
15 15
 class EE_Select_Display_Strategy extends EE_Display_Strategy_Base
16 16
 {
17 17
 
18
-    /**
19
-     *
20
-     * @throws EE_Error
21
-     * @return string of html to display the field
22
-     */
23
-    public function display()
24
-    {
25
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
26
-            throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso')));
27
-        }
18
+	/**
19
+	 *
20
+	 * @throws EE_Error
21
+	 * @return string of html to display the field
22
+	 */
23
+	public function display()
24
+	{
25
+		if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
26
+			throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso')));
27
+		}
28 28
 
29
-        $html = EEH_HTML::nl(0, 'select');
30
-        $html .= '<select';
31
-        $html .= $this->_attributes_string(
32
-            $this->_standard_attributes_array()
33
-        );
34
-        $html .= '>';
29
+		$html = EEH_HTML::nl(0, 'select');
30
+		$html .= '<select';
31
+		$html .= $this->_attributes_string(
32
+			$this->_standard_attributes_array()
33
+		);
34
+		$html .= '>';
35 35
 
36
-        if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
37
-            EEH_HTML::indent(1, 'optgroup');
38
-            foreach ($this->_input->options() as $opt_group_label => $opt_group) {
39
-                if (! empty($opt_group_label)) {
40
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
41
-                }
42
-                EEH_HTML::indent(1, 'option');
43
-                $html .= $this->_display_options($opt_group);
44
-                EEH_HTML::indent(-1, 'option');
45
-                if (! empty($opt_group_label)) {
46
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>';
47
-                }
48
-            }
49
-            EEH_HTML::indent(-1, 'optgroup');
50
-        } else {
51
-            $html .= $this->_display_options($this->_input->options());
52
-        }
36
+		if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
37
+			EEH_HTML::indent(1, 'optgroup');
38
+			foreach ($this->_input->options() as $opt_group_label => $opt_group) {
39
+				if (! empty($opt_group_label)) {
40
+					$html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
41
+				}
42
+				EEH_HTML::indent(1, 'option');
43
+				$html .= $this->_display_options($opt_group);
44
+				EEH_HTML::indent(-1, 'option');
45
+				if (! empty($opt_group_label)) {
46
+					$html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>';
47
+				}
48
+			}
49
+			EEH_HTML::indent(-1, 'optgroup');
50
+		} else {
51
+			$html .= $this->_display_options($this->_input->options());
52
+		}
53 53
 
54
-        $html .= EEH_HTML::nl(0, 'select') . '</select>';
55
-        return $html;
56
-    }
54
+		$html .= EEH_HTML::nl(0, 'select') . '</select>';
55
+		return $html;
56
+	}
57 57
 
58 58
 
59 59
 
60
-    /**
61
-     * Displays a flat list of options as option tags
62
-     * @param array $options
63
-     * @return string
64
-     */
65
-    protected function _display_options($options)
66
-    {
67
-        $html = '';
68
-        EEH_HTML::indent(1, 'option');
69
-        foreach ($options as $value => $display_text) {
70
-            // even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123",
71
-            // PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string
72
-            $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value);
73
-            $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : '';
74
-            $html .= EEH_HTML::nl(0, 'option') . '<option value="' . esc_attr($unnormalized_value) . '"' . $selected . '>' . $display_text . '</option>';
75
-        }
76
-        EEH_HTML::indent(-1, 'option');
77
-        return $html;
78
-    }
60
+	/**
61
+	 * Displays a flat list of options as option tags
62
+	 * @param array $options
63
+	 * @return string
64
+	 */
65
+	protected function _display_options($options)
66
+	{
67
+		$html = '';
68
+		EEH_HTML::indent(1, 'option');
69
+		foreach ($options as $value => $display_text) {
70
+			// even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123",
71
+			// PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string
72
+			$unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value);
73
+			$selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : '';
74
+			$html .= EEH_HTML::nl(0, 'option') . '<option value="' . esc_attr($unnormalized_value) . '"' . $selected . '>' . $display_text . '</option>';
75
+		}
76
+		EEH_HTML::indent(-1, 'option');
77
+		return $html;
78
+	}
79 79
 
80 80
 
81 81
 
82
-    /**
83
-     * Checks if that value is the one selected
84
-     *
85
-     * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML.
86
-     * @return string
87
-     */
88
-    protected function _check_if_option_selected($option_value)
89
-    {
90
-        return $option_value === $this->_input->raw_value();
91
-    }
82
+	/**
83
+	 * Checks if that value is the one selected
84
+	 *
85
+	 * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML.
86
+	 * @return string
87
+	 */
88
+	protected function _check_if_option_selected($option_value)
89
+	{
90
+		return $option_value === $this->_input->raw_value();
91
+	}
92 92
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      */
23 23
     public function display()
24 24
     {
25
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
25
+        if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) {
26 26
             throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso')));
27 27
         }
28 28
 
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
         if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
37 37
             EEH_HTML::indent(1, 'optgroup');
38 38
             foreach ($this->_input->options() as $opt_group_label => $opt_group) {
39
-                if (! empty($opt_group_label)) {
40
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
39
+                if ( ! empty($opt_group_label)) {
40
+                    $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">';
41 41
                 }
42 42
                 EEH_HTML::indent(1, 'option');
43 43
                 $html .= $this->_display_options($opt_group);
44 44
                 EEH_HTML::indent(-1, 'option');
45
-                if (! empty($opt_group_label)) {
46
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>';
45
+                if ( ! empty($opt_group_label)) {
46
+                    $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>';
47 47
                 }
48 48
             }
49 49
             EEH_HTML::indent(-1, 'optgroup');
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
             $html .= $this->_display_options($this->_input->options());
52 52
         }
53 53
 
54
-        $html .= EEH_HTML::nl(0, 'select') . '</select>';
54
+        $html .= EEH_HTML::nl(0, 'select').'</select>';
55 55
         return $html;
56 56
     }
57 57
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
             // PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string
72 72
             $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value);
73 73
             $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : '';
74
-            $html .= EEH_HTML::nl(0, 'option') . '<option value="' . esc_attr($unnormalized_value) . '"' . $selected . '>' . $display_text . '</option>';
74
+            $html .= EEH_HTML::nl(0, 'option').'<option value="'.esc_attr($unnormalized_value).'"'.$selected.'>'.$display_text.'</option>';
75 75
         }
76 76
         EEH_HTML::indent(-1, 'option');
77 77
         return $html;
Please login to merge, or discard this patch.
strategies/validation/EE_Float_Validation_Strategy.strategy.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
     /**
28 28
      *
29 29
      * @param $normalized_value
30
-     * @return bool
30
+     * @return boolean|null
31 31
      */
32 32
     public function validate($normalized_value)
33 33
     {
Please login to merge, or discard this patch.
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -12,36 +12,36 @@
 block discarded – undo
12 12
 class EE_Float_Validation_Strategy extends EE_Validation_Strategy_Base
13 13
 {
14 14
 
15
-    /**
16
-     * @param null $validation_error_message
17
-     */
18
-    public function __construct($validation_error_message = null)
19
-    {
20
-        if (! $validation_error_message) {
21
-            $validation_error_message = sprintf(__("Only numeric characters, commas, periods, and spaces, please!", "event_espresso"));
22
-        }
23
-        parent::__construct($validation_error_message);
24
-    }
25
-
26
-
27
-
28
-    /**
29
-     *
30
-     * @param $normalized_value
31
-     * @return bool
32
-     */
33
-    public function validate($normalized_value)
34
-    {
35
-        // errors should have been detected by the normalization strategy
36
-    }
37
-
38
-
39
-
40
-    /**
41
-     * @return array
42
-     */
43
-    public function get_jquery_validation_rule_array()
44
-    {
45
-        return array('number' => true, 'messages' => array( 'number' => $this->get_validation_error_message() ) );
46
-    }
15
+	/**
16
+	 * @param null $validation_error_message
17
+	 */
18
+	public function __construct($validation_error_message = null)
19
+	{
20
+		if (! $validation_error_message) {
21
+			$validation_error_message = sprintf(__("Only numeric characters, commas, periods, and spaces, please!", "event_espresso"));
22
+		}
23
+		parent::__construct($validation_error_message);
24
+	}
25
+
26
+
27
+
28
+	/**
29
+	 *
30
+	 * @param $normalized_value
31
+	 * @return bool
32
+	 */
33
+	public function validate($normalized_value)
34
+	{
35
+		// errors should have been detected by the normalization strategy
36
+	}
37
+
38
+
39
+
40
+	/**
41
+	 * @return array
42
+	 */
43
+	public function get_jquery_validation_rule_array()
44
+	{
45
+		return array('number' => true, 'messages' => array( 'number' => $this->get_validation_error_message() ) );
46
+	}
47 47
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
      */
18 18
     public function __construct($validation_error_message = null)
19 19
     {
20
-        if (! $validation_error_message) {
20
+        if ( ! $validation_error_message) {
21 21
             $validation_error_message = sprintf(__("Only numeric characters, commas, periods, and spaces, please!", "event_espresso"));
22 22
         }
23 23
         parent::__construct($validation_error_message);
@@ -42,6 +42,6 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function get_jquery_validation_rule_array()
44 44
     {
45
-        return array('number' => true, 'messages' => array( 'number' => $this->get_validation_error_message() ) );
45
+        return array('number' => true, 'messages' => array('number' => $this->get_validation_error_message()));
46 46
     }
47 47
 }
Please login to merge, or discard this patch.
line_item_display/EE_Admin_Table_Line_Item_Display_Strategy.strategy.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      * This is used to output a single
50 50
      * @param EE_Line_Item $line_item
51 51
      * @param array        $options
52
-     * @return mixed
52
+     * @return string
53 53
      */
54 54
     public function display_line_item(EE_Line_Item $line_item, $options = array())
55 55
     {
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      *
167 167
      * @param EE_Line_Item $line_item
168 168
      * @param array        $options
169
-     * @return mixed
169
+     * @return string
170 170
      */
171 171
     protected function _item_row(EE_Line_Item $line_item, $options = array())
172 172
     {
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
      *
265 265
      * @param EE_Line_Item $line_item
266 266
      * @param array        $options
267
-     * @return mixed
267
+     * @return string
268 268
      */
269 269
     protected function _sub_item_row(EE_Line_Item $line_item, $options = array())
270 270
     {
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      *
280 280
      * @param EE_Line_Item $line_item
281 281
      * @param array        $options
282
-     * @return mixed
282
+     * @return string
283 283
      */
284 284
     protected function _tax_row(EE_Line_Item $line_item, $options = array())
285 285
     {
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
      * @param EE_Line_Item $line_item
304 304
      * @param string       $text
305 305
      * @param array        $options
306
-     * @return mixed
306
+     * @return string
307 307
      */
308 308
     protected function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
309 309
     {
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
      *
319 319
      * @param EE_Line_Item $line_item
320 320
      * @param array        $options
321
-     * @return mixed
321
+     * @return string
322 322
      */
323 323
     protected function _total_row(EE_Line_Item $line_item, $options = array())
324 324
     {
Please login to merge, or discard this patch.
Indentation   +328 added lines, -328 removed lines patch added patch discarded remove patch
@@ -14,332 +14,332 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    /**
18
-     * whether to display the taxes row or not
19
-     * @type bool $_show_taxes
20
-     */
21
-    protected $_show_taxes = false;
22
-
23
-    /**
24
-     * html for any tax rows
25
-     * @type string $_show_taxes
26
-     */
27
-    protected $_taxes_html = '';
28
-
29
-
30
-    /**
31
-     * total amount including tax we can bill for at this time
32
-     * @type float $_grand_total
33
-     */
34
-    protected $_grand_total = 0.00;
35
-
36
-
37
-
38
-    /**
39
-     * @return float
40
-     */
41
-    public function grand_total()
42
-    {
43
-        return $this->_grand_total;
44
-    }
45
-
46
-
47
-
48
-    /**
49
-     * This is used to output a single
50
-     * @param EE_Line_Item $line_item
51
-     * @param array        $options
52
-     * @return mixed
53
-     */
54
-    public function display_line_item(EE_Line_Item $line_item, $options = array())
55
-    {
56
-
57
-        $html = '';
58
-        // set some default options and merge with incoming
59
-        $default_options = array(
60
-            'odd' => true,
61
-            'use_table_wrapper' => true,
62
-            'table_css_class' => 'admin-primary-mbox-tbl',
63
-            'taxes_tr_css_class' => 'admin-primary-mbox-taxes-tr',
64
-            'total_tr_css_class' => 'admin-primary-mbox-total-tr'
65
-        );
66
-        $options = array_merge($default_options, (array) $options);
67
-
68
-        switch ($line_item->type()) {
69
-            case EEM_Line_Item::type_line_item:
70
-                // item row
71
-                $html .= $this->_item_row($line_item, $options);
72
-                break;
73
-
74
-            case EEM_Line_Item::type_sub_line_item:
75
-                $html .= $this->_sub_item_row($line_item, $options);
76
-                break;
77
-
78
-            case EEM_Line_Item::type_sub_total:
79
-                if ($line_item->quantity() === 0) {
80
-                    return $html;
81
-                }
82
-                // loop through children
83
-                $child_line_items = $line_item->children();
84
-                // loop through children
85
-                foreach ($child_line_items as $child_line_item) {
86
-                    // recursively feed children back into this method
87
-                    $html .= $this->display_line_item($child_line_item, $options);
88
-                }
89
-                $html .= $this->_sub_total_row($line_item, $options);
90
-                break;
91
-
92
-            case EEM_Line_Item::type_tax:
93
-                if ($this->_show_taxes) {
94
-                    $this->_taxes_html .= $this->_tax_row($line_item, $options);
95
-                }
96
-                break;
97
-
98
-            case EEM_Line_Item::type_tax_sub_total:
99
-                foreach ($line_item->children() as $child_line_item) {
100
-                    if ($child_line_item->type() == EEM_Line_Item::type_tax) {
101
-                        $this->display_line_item($child_line_item, $options);
102
-                    }
103
-                }
104
-                break;
105
-
106
-            case EEM_Line_Item::type_total:
107
-                // determine whether to display taxes or not
108
-                $this->_show_taxes = $line_item->get_total_tax() > 0 ? true : false;
109
-                // get all child line items
110
-                $children = $line_item->children();
111
-
112
-                // loop thru all non-tax child line items
113
-                foreach ($children as $child_line_item) {
114
-                        $html .= $this->display_line_item($child_line_item, $options);
115
-                }
116
-
117
-                $html .= $this->_taxes_html;
118
-                $html .= $this->_total_row($line_item, $options);
119
-                if ($options['use_table_wrapper']) {
120
-                    $html = $this->_table_header($options) . $html . $this->_table_footer($options);
121
-                }
122
-                break;
123
-        }
124
-
125
-        return $html;
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * Table header for display.
132
-     * @since   4.8
133
-     * @param array $options
134
-     * @return string
135
-     */
136
-    protected function _table_header($options)
137
-    {
138
-        $html = EEH_HTML::table('', '', $options['table_css_class']);
139
-        $html .= EEH_HTML::thead();
140
-        $html .= EEH_HTML::tr();
141
-        $html .= EEH_HTML::th(__('Name', 'event_espresso'), '', 'jst-left');
142
-        $html .= EEH_HTML::th(__('Type', 'event_espresso'), '', 'jst-left');
143
-        $html .= EEH_HTML::th(__('Amount', 'event_espresso'), '', 'jst-cntr');
144
-        $html .= EEH_HTML::th(__('Qty', 'event_espresso'), '', 'jst-cntr');
145
-        $html .= EEH_HTML::th(__('Line Total', 'event_espresso'), '', 'jst-cntr');
146
-        $html .= EEH_HTML::tbody();
147
-        return $html;
148
-    }
149
-
150
-
151
-    /**
152
-     * Table footer for display
153
-     * @since 4.8
154
-     * @param array $options array of options for the table.
155
-     * @return string
156
-     */
157
-    protected function _table_footer($options)
158
-    {
159
-        return EEH_HTML::tbodyx() .  EEH_HTML::tablex();
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     *    _item_row
166
-     *
167
-     * @param EE_Line_Item $line_item
168
-     * @param array        $options
169
-     * @return mixed
170
-     */
171
-    protected function _item_row(EE_Line_Item $line_item, $options = array())
172
-    {
173
-        $line_item_related_object = $line_item->get_object();
174
-        $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->get_object() : null;
175
-        // start of row
176
-        $row_class = $options['odd'] ? 'item odd' : 'item';
177
-        $html = EEH_HTML::tr('', '', $row_class);
178
-
179
-
180
-        // Name Column
181
-        $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : '';
182
-
183
-        // related object scope.
184
-        $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object ? $parent_line_item_related_object->name() : '';
185
-        $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->name() : $parent_related_object_name;
186
-        $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links ? $parent_line_item_related_object->get_admin_details_link() : '';
187
-
188
-
189
-        $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name();
190
-        $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html;
191
-        $name_html .= $line_item->is_taxable() ? ' *' : '';
192
-        // maybe preface with icon?
193
-        $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html;
194
-        $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>';
195
-        $name_html .=  sprintf(
196
-            _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'),
197
-            '<span class="ee-line-item-related-parent-object">',
198
-            $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : __('Item:', 'event_espresso'),
199
-            $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name,
200
-            '</span>'
201
-        );
202
-
203
-        $name_html = apply_filters(
204
-            'FHEE__EE_Admin_Table_Line_Item_Display_Strategy___item_row__name_html',
205
-            $name_html,
206
-            $line_item,
207
-            $options
208
-        );
209
-
210
-        $html .= EEH_HTML::td($name_html, '', 'jst-left');
211
-        // Type Column
212
-        $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : '';
213
-        $type_html .= $this->_get_cancellations($line_item);
214
-        $type_html .= $line_item->OBJ_type() ? '<br />' : '';
215
-        $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : '';
216
-        $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(__('Code: %s', 'event_espresso'), $code) . '</span>' : '';
217
-        $html .= EEH_HTML::td($type_html, '', 'jst-left');
218
-
219
-
220
-        // Amount Column
221
-        if ($line_item->is_percent()) {
222
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght');
223
-        } else {
224
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght');
225
-        }
226
-
227
-        // QTY column
228
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'jst-rght');
229
-
230
-        // total column
231
-        $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
232
-
233
-        // finish things off and return
234
-        $html .= EEH_HTML::trx();
235
-        return $html;
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     *    _get_cancellations
242
-     *
243
-     * @param EE_Line_Item $line_item
244
-     * @return string
245
-     */
246
-    protected function _get_cancellations(EE_Line_Item $line_item)
247
-    {
248
-        $html = '';
249
-        $cancellations = $line_item->get_cancellations();
250
-        $cancellation = reset($cancellations);
251
-        // \EEH_Debug_Tools::printr( $cancellation, '$cancellation', __FILE__, __LINE__ );
252
-        if ($cancellation instanceof EE_Line_Item) {
253
-            $html .= ' <span class="ee-line-item-id">';
254
-            $html .= sprintf(
255
-                _n(
256
-                    '(%1$s Cancellation)',
257
-                    '(%1$s Cancellations)',
258
-                    $cancellation->quantity(),
259
-                    'event_espresso'
260
-                ),
261
-                $cancellation->quantity()
262
-            );
263
-            $html .= '</span>';
264
-        }
265
-        return $html;
266
-    }
267
-
268
-
269
-
270
-    /**
271
-     *  _sub_item_row
272
-     *
273
-     * @param EE_Line_Item $line_item
274
-     * @param array        $options
275
-     * @return mixed
276
-     */
277
-    protected function _sub_item_row(EE_Line_Item $line_item, $options = array())
278
-    {
279
-        // for now we're not showing sub-items
280
-        return '';
281
-    }
282
-
283
-
284
-
285
-    /**
286
-     *  _tax_row
287
-     *
288
-     * @param EE_Line_Item $line_item
289
-     * @param array        $options
290
-     * @return mixed
291
-     */
292
-    protected function _tax_row(EE_Line_Item $line_item, $options = array())
293
-    {
294
-        // start of row
295
-        $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr');
296
-        // name th
297
-        $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"');
298
-        // total th
299
-        $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
300
-        // end of row
301
-        $html .= EEH_HTML::trx();
302
-        return $html;
303
-    }
304
-
305
-
306
-
307
-
308
-    /**
309
-     *  _total_row
310
-     *
311
-     * @param EE_Line_Item $line_item
312
-     * @param string       $text
313
-     * @param array        $options
314
-     * @return mixed
315
-     */
316
-    protected function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
317
-    {
318
-        // currently not showing subtotal row
319
-        return '';
320
-    }
321
-
322
-
323
-
324
-    /**
325
-     *  _total_row
326
-     *
327
-     * @param EE_Line_Item $line_item
328
-     * @param array        $options
329
-     * @return mixed
330
-     */
331
-    protected function _total_row(EE_Line_Item $line_item, $options = array())
332
-    {
333
-        // start of row
334
-        $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr');
335
-        // Total th label
336
-        $total_label = sprintf(__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
337
-        $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"');
338
-        // total th
339
-
340
-        $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
341
-        // end of row
342
-        $html .= EEH_HTML::trx();
343
-        return $html;
344
-    }
17
+	/**
18
+	 * whether to display the taxes row or not
19
+	 * @type bool $_show_taxes
20
+	 */
21
+	protected $_show_taxes = false;
22
+
23
+	/**
24
+	 * html for any tax rows
25
+	 * @type string $_show_taxes
26
+	 */
27
+	protected $_taxes_html = '';
28
+
29
+
30
+	/**
31
+	 * total amount including tax we can bill for at this time
32
+	 * @type float $_grand_total
33
+	 */
34
+	protected $_grand_total = 0.00;
35
+
36
+
37
+
38
+	/**
39
+	 * @return float
40
+	 */
41
+	public function grand_total()
42
+	{
43
+		return $this->_grand_total;
44
+	}
45
+
46
+
47
+
48
+	/**
49
+	 * This is used to output a single
50
+	 * @param EE_Line_Item $line_item
51
+	 * @param array        $options
52
+	 * @return mixed
53
+	 */
54
+	public function display_line_item(EE_Line_Item $line_item, $options = array())
55
+	{
56
+
57
+		$html = '';
58
+		// set some default options and merge with incoming
59
+		$default_options = array(
60
+			'odd' => true,
61
+			'use_table_wrapper' => true,
62
+			'table_css_class' => 'admin-primary-mbox-tbl',
63
+			'taxes_tr_css_class' => 'admin-primary-mbox-taxes-tr',
64
+			'total_tr_css_class' => 'admin-primary-mbox-total-tr'
65
+		);
66
+		$options = array_merge($default_options, (array) $options);
67
+
68
+		switch ($line_item->type()) {
69
+			case EEM_Line_Item::type_line_item:
70
+				// item row
71
+				$html .= $this->_item_row($line_item, $options);
72
+				break;
73
+
74
+			case EEM_Line_Item::type_sub_line_item:
75
+				$html .= $this->_sub_item_row($line_item, $options);
76
+				break;
77
+
78
+			case EEM_Line_Item::type_sub_total:
79
+				if ($line_item->quantity() === 0) {
80
+					return $html;
81
+				}
82
+				// loop through children
83
+				$child_line_items = $line_item->children();
84
+				// loop through children
85
+				foreach ($child_line_items as $child_line_item) {
86
+					// recursively feed children back into this method
87
+					$html .= $this->display_line_item($child_line_item, $options);
88
+				}
89
+				$html .= $this->_sub_total_row($line_item, $options);
90
+				break;
91
+
92
+			case EEM_Line_Item::type_tax:
93
+				if ($this->_show_taxes) {
94
+					$this->_taxes_html .= $this->_tax_row($line_item, $options);
95
+				}
96
+				break;
97
+
98
+			case EEM_Line_Item::type_tax_sub_total:
99
+				foreach ($line_item->children() as $child_line_item) {
100
+					if ($child_line_item->type() == EEM_Line_Item::type_tax) {
101
+						$this->display_line_item($child_line_item, $options);
102
+					}
103
+				}
104
+				break;
105
+
106
+			case EEM_Line_Item::type_total:
107
+				// determine whether to display taxes or not
108
+				$this->_show_taxes = $line_item->get_total_tax() > 0 ? true : false;
109
+				// get all child line items
110
+				$children = $line_item->children();
111
+
112
+				// loop thru all non-tax child line items
113
+				foreach ($children as $child_line_item) {
114
+						$html .= $this->display_line_item($child_line_item, $options);
115
+				}
116
+
117
+				$html .= $this->_taxes_html;
118
+				$html .= $this->_total_row($line_item, $options);
119
+				if ($options['use_table_wrapper']) {
120
+					$html = $this->_table_header($options) . $html . $this->_table_footer($options);
121
+				}
122
+				break;
123
+		}
124
+
125
+		return $html;
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * Table header for display.
132
+	 * @since   4.8
133
+	 * @param array $options
134
+	 * @return string
135
+	 */
136
+	protected function _table_header($options)
137
+	{
138
+		$html = EEH_HTML::table('', '', $options['table_css_class']);
139
+		$html .= EEH_HTML::thead();
140
+		$html .= EEH_HTML::tr();
141
+		$html .= EEH_HTML::th(__('Name', 'event_espresso'), '', 'jst-left');
142
+		$html .= EEH_HTML::th(__('Type', 'event_espresso'), '', 'jst-left');
143
+		$html .= EEH_HTML::th(__('Amount', 'event_espresso'), '', 'jst-cntr');
144
+		$html .= EEH_HTML::th(__('Qty', 'event_espresso'), '', 'jst-cntr');
145
+		$html .= EEH_HTML::th(__('Line Total', 'event_espresso'), '', 'jst-cntr');
146
+		$html .= EEH_HTML::tbody();
147
+		return $html;
148
+	}
149
+
150
+
151
+	/**
152
+	 * Table footer for display
153
+	 * @since 4.8
154
+	 * @param array $options array of options for the table.
155
+	 * @return string
156
+	 */
157
+	protected function _table_footer($options)
158
+	{
159
+		return EEH_HTML::tbodyx() .  EEH_HTML::tablex();
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 *    _item_row
166
+	 *
167
+	 * @param EE_Line_Item $line_item
168
+	 * @param array        $options
169
+	 * @return mixed
170
+	 */
171
+	protected function _item_row(EE_Line_Item $line_item, $options = array())
172
+	{
173
+		$line_item_related_object = $line_item->get_object();
174
+		$parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->get_object() : null;
175
+		// start of row
176
+		$row_class = $options['odd'] ? 'item odd' : 'item';
177
+		$html = EEH_HTML::tr('', '', $row_class);
178
+
179
+
180
+		// Name Column
181
+		$name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : '';
182
+
183
+		// related object scope.
184
+		$parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object ? $parent_line_item_related_object->name() : '';
185
+		$parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->name() : $parent_related_object_name;
186
+		$parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links ? $parent_line_item_related_object->get_admin_details_link() : '';
187
+
188
+
189
+		$name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name();
190
+		$name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html;
191
+		$name_html .= $line_item->is_taxable() ? ' *' : '';
192
+		// maybe preface with icon?
193
+		$name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html;
194
+		$name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>';
195
+		$name_html .=  sprintf(
196
+			_x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'),
197
+			'<span class="ee-line-item-related-parent-object">',
198
+			$line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : __('Item:', 'event_espresso'),
199
+			$parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name,
200
+			'</span>'
201
+		);
202
+
203
+		$name_html = apply_filters(
204
+			'FHEE__EE_Admin_Table_Line_Item_Display_Strategy___item_row__name_html',
205
+			$name_html,
206
+			$line_item,
207
+			$options
208
+		);
209
+
210
+		$html .= EEH_HTML::td($name_html, '', 'jst-left');
211
+		// Type Column
212
+		$type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : '';
213
+		$type_html .= $this->_get_cancellations($line_item);
214
+		$type_html .= $line_item->OBJ_type() ? '<br />' : '';
215
+		$code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : '';
216
+		$type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(__('Code: %s', 'event_espresso'), $code) . '</span>' : '';
217
+		$html .= EEH_HTML::td($type_html, '', 'jst-left');
218
+
219
+
220
+		// Amount Column
221
+		if ($line_item->is_percent()) {
222
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght');
223
+		} else {
224
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght');
225
+		}
226
+
227
+		// QTY column
228
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'jst-rght');
229
+
230
+		// total column
231
+		$html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
232
+
233
+		// finish things off and return
234
+		$html .= EEH_HTML::trx();
235
+		return $html;
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 *    _get_cancellations
242
+	 *
243
+	 * @param EE_Line_Item $line_item
244
+	 * @return string
245
+	 */
246
+	protected function _get_cancellations(EE_Line_Item $line_item)
247
+	{
248
+		$html = '';
249
+		$cancellations = $line_item->get_cancellations();
250
+		$cancellation = reset($cancellations);
251
+		// \EEH_Debug_Tools::printr( $cancellation, '$cancellation', __FILE__, __LINE__ );
252
+		if ($cancellation instanceof EE_Line_Item) {
253
+			$html .= ' <span class="ee-line-item-id">';
254
+			$html .= sprintf(
255
+				_n(
256
+					'(%1$s Cancellation)',
257
+					'(%1$s Cancellations)',
258
+					$cancellation->quantity(),
259
+					'event_espresso'
260
+				),
261
+				$cancellation->quantity()
262
+			);
263
+			$html .= '</span>';
264
+		}
265
+		return $html;
266
+	}
267
+
268
+
269
+
270
+	/**
271
+	 *  _sub_item_row
272
+	 *
273
+	 * @param EE_Line_Item $line_item
274
+	 * @param array        $options
275
+	 * @return mixed
276
+	 */
277
+	protected function _sub_item_row(EE_Line_Item $line_item, $options = array())
278
+	{
279
+		// for now we're not showing sub-items
280
+		return '';
281
+	}
282
+
283
+
284
+
285
+	/**
286
+	 *  _tax_row
287
+	 *
288
+	 * @param EE_Line_Item $line_item
289
+	 * @param array        $options
290
+	 * @return mixed
291
+	 */
292
+	protected function _tax_row(EE_Line_Item $line_item, $options = array())
293
+	{
294
+		// start of row
295
+		$html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr');
296
+		// name th
297
+		$html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"');
298
+		// total th
299
+		$html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
300
+		// end of row
301
+		$html .= EEH_HTML::trx();
302
+		return $html;
303
+	}
304
+
305
+
306
+
307
+
308
+	/**
309
+	 *  _total_row
310
+	 *
311
+	 * @param EE_Line_Item $line_item
312
+	 * @param string       $text
313
+	 * @param array        $options
314
+	 * @return mixed
315
+	 */
316
+	protected function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
317
+	{
318
+		// currently not showing subtotal row
319
+		return '';
320
+	}
321
+
322
+
323
+
324
+	/**
325
+	 *  _total_row
326
+	 *
327
+	 * @param EE_Line_Item $line_item
328
+	 * @param array        $options
329
+	 * @return mixed
330
+	 */
331
+	protected function _total_row(EE_Line_Item $line_item, $options = array())
332
+	{
333
+		// start of row
334
+		$html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr');
335
+		// Total th label
336
+		$total_label = sprintf(__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
337
+		$html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"');
338
+		// total th
339
+
340
+		$html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
341
+		// end of row
342
+		$html .= EEH_HTML::trx();
343
+		return $html;
344
+	}
345 345
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
                 $html .= $this->_taxes_html;
118 118
                 $html .= $this->_total_row($line_item, $options);
119 119
                 if ($options['use_table_wrapper']) {
120
-                    $html = $this->_table_header($options) . $html . $this->_table_footer($options);
120
+                    $html = $this->_table_header($options).$html.$this->_table_footer($options);
121 121
                 }
122 122
                 break;
123 123
         }
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      */
157 157
     protected function _table_footer($options)
158 158
     {
159
-        return EEH_HTML::tbodyx() .  EEH_HTML::tablex();
159
+        return EEH_HTML::tbodyx().EEH_HTML::tablex();
160 160
     }
161 161
 
162 162
 
@@ -187,16 +187,16 @@  discard block
 block discarded – undo
187 187
 
188 188
 
189 189
         $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name();
190
-        $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html;
190
+        $name_html = $name_link ? '<a href="'.$name_link.'">'.$name_html.'</a>' : $name_html;
191 191
         $name_html .= $line_item->is_taxable() ? ' *' : '';
192 192
         // maybe preface with icon?
193
-        $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html;
194
-        $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>';
195
-        $name_html .=  sprintf(
193
+        $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon().$name_html : $name_html;
194
+        $name_html = '<span class="ee-line-item-name linked">'.$name_html.'</span><br>';
195
+        $name_html .= sprintf(
196 196
             _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'),
197 197
             '<span class="ee-line-item-related-parent-object">',
198 198
             $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : __('Item:', 'event_espresso'),
199
-            $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name,
199
+            $parent_related_object_link ? '<a href="'.$parent_related_object_link.'">'.$parent_related_object_name.'</a>' : $parent_related_object_name,
200 200
             '</span>'
201 201
         );
202 202
 
@@ -213,13 +213,13 @@  discard block
 block discarded – undo
213 213
         $type_html .= $this->_get_cancellations($line_item);
214 214
         $type_html .= $line_item->OBJ_type() ? '<br />' : '';
215 215
         $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : '';
216
-        $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(__('Code: %s', 'event_espresso'), $code) . '</span>' : '';
216
+        $type_html .= ! empty($code) ? '<span class="ee-line-item-id">'.sprintf(__('Code: %s', 'event_espresso'), $code).'</span>' : '';
217 217
         $html .= EEH_HTML::td($type_html, '', 'jst-left');
218 218
 
219 219
 
220 220
         // Amount Column
221 221
         if ($line_item->is_percent()) {
222
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght');
222
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'jst-rght');
223 223
         } else {
224 224
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght');
225 225
         }
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
         // start of row
295 295
         $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr');
296 296
         // name th
297
-        $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"');
297
+        $html .= EEH_HTML::th($line_item->name().'('.$line_item->get_pretty('LIN_percent').'%)', '', 'jst-rght', '', ' colspan="4"');
298 298
         // total th
299 299
         $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
300 300
         // end of row
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
         // start of row
334 334
         $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr');
335 335
         // Total th label
336
-        $total_label = sprintf(__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
336
+        $total_label = sprintf(__('Transaction Total %s', 'event_espresso'), '('.EE_Registry::instance()->CFG->currency->code.')');
337 337
         $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"');
338 338
         // total th
339 339
 
Please login to merge, or discard this patch.
line_item_display/EE_Default_Line_Item_Display_Strategy.strategy.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     /**
59 59
      * @param EE_Line_Item $line_item
60 60
      * @param array        $options
61
-     * @return mixed
61
+     * @return string
62 62
      */
63 63
     public function display_line_item(EE_Line_Item $line_item, $options = array())
64 64
     {
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
      *
135 135
      * @param EE_Line_Item $line_item
136 136
      * @param array        $options
137
-     * @return mixed
137
+     * @return string
138 138
      */
139 139
     private function _item_row(EE_Line_Item $line_item, $options = array())
140 140
     {
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      *
190 190
      * @param EE_Line_Item $line_item
191 191
      * @param array        $options
192
-     * @return mixed
192
+     * @return string
193 193
      */
194 194
     private function _sub_item_row(EE_Line_Item $line_item, $options = array())
195 195
     {
Please login to merge, or discard this patch.
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -1,225 +1,225 @@
 block discarded – undo
1 1
 <?php
2 2
  /**
3
- *
4
- * Class EE_Default_Line_Item_Display_Strategy
5
- *
6
- * Description
7
- *
8
- * @package         Event Espresso
9
- * @subpackage    core
10
- * @author              Brent Christensen
11
- *
12
- *
13
- */
3
+  *
4
+  * Class EE_Default_Line_Item_Display_Strategy
5
+  *
6
+  * Description
7
+  *
8
+  * @package         Event Espresso
9
+  * @subpackage    core
10
+  * @author              Brent Christensen
11
+  *
12
+  *
13
+  */
14 14
 
15 15
 class EE_Default_Line_Item_Display_Strategy implements EEI_Line_Item_Display
16 16
 {
17 17
 
18
-    /**
19
-     * total amount of tax to apply
20
-     * @type float $_tax_rate
21
-     */
22
-    private $_tax_rate = 0;
23
-
24
-    /**
25
-     * total amount including tax we can bill for at this time
26
-     * @type float $_grand_total
27
-     */
28
-    private $_grand_total = 0.00;
29
-
30
-    /**
31
-     * total number of items being billed for
32
-     * @type int $_total_items
33
-     */
34
-    private $_total_items = 0;
35
-
36
-
37
-
38
-    /**
39
-     * @return float
40
-     */
41
-    public function grand_total()
42
-    {
43
-        return $this->_grand_total;
44
-    }
45
-
46
-
47
-
48
-    /**
49
-     * @return int
50
-     */
51
-    public function total_items()
52
-    {
53
-        return $this->_total_items;
54
-    }
55
-
56
-
57
-
58
-    /**
59
-     * @param EE_Line_Item $line_item
60
-     * @param array        $options
61
-     * @return mixed
62
-     */
63
-    public function display_line_item(EE_Line_Item $line_item, $options = array())
64
-    {
65
-
66
-        $html = '';
67
-        // set some default options and merge with incoming
68
-        $default_options = array(
69
-            'show_desc' => true,  //    TRUE        FALSE
70
-            'odd' => false
71
-        );
72
-        $options = array_merge($default_options, (array) $options);
73
-
74
-        switch ($line_item->type()) {
75
-            case EEM_Line_Item::type_line_item:
76
-                // item row
77
-                $html .= $this->_item_row($line_item, $options);
78
-                // got any kids?
79
-                foreach ($line_item->children() as $child_line_item) {
80
-                    $this->display_line_item($child_line_item, $options);
81
-                }
82
-                break;
83
-
84
-            case EEM_Line_Item::type_sub_line_item:
85
-                $html .= $this->_sub_item_row($line_item, $options);
86
-                break;
87
-
88
-            case EEM_Line_Item::type_sub_total:
89
-                break;
90
-
91
-            case EEM_Line_Item::type_tax:
92
-                $this->_tax_rate += $line_item->percent();
93
-                break;
94
-
95
-            case EEM_Line_Item::type_tax_sub_total:
96
-                foreach ($line_item->children() as $child_line_item) {
97
-                    if ($child_line_item->type() == EEM_Line_Item::type_tax) {
98
-                        // recursively feed children back into this method
99
-                        $this->display_line_item($child_line_item, $options);
100
-                    }
101
-                }
102
-                break;
103
-
104
-            case EEM_Line_Item::type_total:
105
-                // get all child line items
106
-                $children = $line_item->children();
107
-                if ($options['set_tax_rate'] === true) {
108
-                    // loop thru tax child line items just to determine tax rate
109
-                    foreach ($children as $child_line_item) {
110
-                        if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) {
111
-                            // recursively feed children back into this method
112
-                            $this->display_line_item($child_line_item, $options);
113
-                        }
114
-                    }
115
-                } else {
116
-                    // now loop thru all non-tax child line items
117
-                    foreach ($children as $child_line_item) {
118
-                        if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) {
119
-                            // recursively feed children back into this method
120
-                            $html .= $this->display_line_item($child_line_item, $options);
121
-                        }
122
-                    }
123
-                }
124
-                break;
125
-        }
126
-
127
-        return $html;
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     *  _total_row
134
-     *
135
-     * @param EE_Line_Item $line_item
136
-     * @param array        $options
137
-     * @return mixed
138
-     */
139
-    private function _item_row(EE_Line_Item $line_item, $options = array())
140
-    {
141
-        // start of row
142
-        $row_class = $options['odd'] ? 'item odd' : 'item';
143
-        $html = EEH_HTML::tr('', '', $row_class);
144
-        // name && desc
145
-        $name_and_desc = apply_filters(
146
-            'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__name',
147
-            $line_item->name(),
148
-            $line_item
149
-        );
150
-        $name_and_desc .= apply_filters(
151
-            'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc',
152
-            ( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ),
153
-            $line_item,
154
-            $options
155
-        );
156
-        if ($line_item->is_taxable()) {
157
-            $ticket_price_includes_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes
158
-                ? esc_html__('* price includes taxes', 'event_espresso')
159
-                : esc_html__('* price does not include taxes', 'event_espresso');
160
-            $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
161
-                  . $ticket_price_includes_taxes
162
-                  . '</span>';
163
-        }
164
-
165
-        // name td
166
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
167
-        // quantity td
168
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
169
-        $tax_rate = $line_item->is_taxable()
170
-                    && EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes
171
-            ? 1 + ( $this->_tax_rate / 100 )
172
-            : 1;
173
-        // price td
174
-        $unit_price = apply_filters(
175
-            'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__unit_price',
176
-            EEH_Template::format_currency($line_item->unit_price() * $tax_rate, false, false),
177
-            $line_item,
178
-            $tax_rate
179
-        );
180
-        $html .= EEH_HTML::td($unit_price, '', 'item_c jst-rght');
181
-        // total td
182
-        $total = apply_filters(
183
-            'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__total',
184
-            EEH_Template::format_currency($line_item->unit_price() * $line_item->quantity() * $tax_rate, false, false),
185
-            $line_item,
186
-            $tax_rate
187
-        );
188
-        $html .= EEH_HTML::td($total, '', 'item_r jst-rght');
189
-        // end of row
190
-        $html .= EEH_HTML::trx();
191
-
192
-        return $html;
193
-    }
194
-
195
-
196
-
197
-    /**
198
-     *  _sub_item_row
199
-     *
200
-     * @param EE_Line_Item $line_item
201
-     * @param array        $options
202
-     * @return mixed
203
-     */
204
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array())
205
-    {
206
-        // start of row
207
-        $html = EEH_HTML::tr('', 'item sub-item-row');
208
-        // name && desc
209
-        $name_and_desc = $line_item->name();
210
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '';
211
-        // name td
212
-        $html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item');
213
-        // discount/surcharge td
214
-        if ($line_item->is_percent()) {
215
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
216
-        } else {
217
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
218
-        }
219
-        // total td
220
-        $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'item_r jst-rght');
221
-        // end of row
222
-        $html .= EEH_HTML::trx();
223
-        return $html;
224
-    }
18
+	/**
19
+	 * total amount of tax to apply
20
+	 * @type float $_tax_rate
21
+	 */
22
+	private $_tax_rate = 0;
23
+
24
+	/**
25
+	 * total amount including tax we can bill for at this time
26
+	 * @type float $_grand_total
27
+	 */
28
+	private $_grand_total = 0.00;
29
+
30
+	/**
31
+	 * total number of items being billed for
32
+	 * @type int $_total_items
33
+	 */
34
+	private $_total_items = 0;
35
+
36
+
37
+
38
+	/**
39
+	 * @return float
40
+	 */
41
+	public function grand_total()
42
+	{
43
+		return $this->_grand_total;
44
+	}
45
+
46
+
47
+
48
+	/**
49
+	 * @return int
50
+	 */
51
+	public function total_items()
52
+	{
53
+		return $this->_total_items;
54
+	}
55
+
56
+
57
+
58
+	/**
59
+	 * @param EE_Line_Item $line_item
60
+	 * @param array        $options
61
+	 * @return mixed
62
+	 */
63
+	public function display_line_item(EE_Line_Item $line_item, $options = array())
64
+	{
65
+
66
+		$html = '';
67
+		// set some default options and merge with incoming
68
+		$default_options = array(
69
+			'show_desc' => true,  //    TRUE        FALSE
70
+			'odd' => false
71
+		);
72
+		$options = array_merge($default_options, (array) $options);
73
+
74
+		switch ($line_item->type()) {
75
+			case EEM_Line_Item::type_line_item:
76
+				// item row
77
+				$html .= $this->_item_row($line_item, $options);
78
+				// got any kids?
79
+				foreach ($line_item->children() as $child_line_item) {
80
+					$this->display_line_item($child_line_item, $options);
81
+				}
82
+				break;
83
+
84
+			case EEM_Line_Item::type_sub_line_item:
85
+				$html .= $this->_sub_item_row($line_item, $options);
86
+				break;
87
+
88
+			case EEM_Line_Item::type_sub_total:
89
+				break;
90
+
91
+			case EEM_Line_Item::type_tax:
92
+				$this->_tax_rate += $line_item->percent();
93
+				break;
94
+
95
+			case EEM_Line_Item::type_tax_sub_total:
96
+				foreach ($line_item->children() as $child_line_item) {
97
+					if ($child_line_item->type() == EEM_Line_Item::type_tax) {
98
+						// recursively feed children back into this method
99
+						$this->display_line_item($child_line_item, $options);
100
+					}
101
+				}
102
+				break;
103
+
104
+			case EEM_Line_Item::type_total:
105
+				// get all child line items
106
+				$children = $line_item->children();
107
+				if ($options['set_tax_rate'] === true) {
108
+					// loop thru tax child line items just to determine tax rate
109
+					foreach ($children as $child_line_item) {
110
+						if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) {
111
+							// recursively feed children back into this method
112
+							$this->display_line_item($child_line_item, $options);
113
+						}
114
+					}
115
+				} else {
116
+					// now loop thru all non-tax child line items
117
+					foreach ($children as $child_line_item) {
118
+						if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) {
119
+							// recursively feed children back into this method
120
+							$html .= $this->display_line_item($child_line_item, $options);
121
+						}
122
+					}
123
+				}
124
+				break;
125
+		}
126
+
127
+		return $html;
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 *  _total_row
134
+	 *
135
+	 * @param EE_Line_Item $line_item
136
+	 * @param array        $options
137
+	 * @return mixed
138
+	 */
139
+	private function _item_row(EE_Line_Item $line_item, $options = array())
140
+	{
141
+		// start of row
142
+		$row_class = $options['odd'] ? 'item odd' : 'item';
143
+		$html = EEH_HTML::tr('', '', $row_class);
144
+		// name && desc
145
+		$name_and_desc = apply_filters(
146
+			'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__name',
147
+			$line_item->name(),
148
+			$line_item
149
+		);
150
+		$name_and_desc .= apply_filters(
151
+			'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc',
152
+			( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ),
153
+			$line_item,
154
+			$options
155
+		);
156
+		if ($line_item->is_taxable()) {
157
+			$ticket_price_includes_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes
158
+				? esc_html__('* price includes taxes', 'event_espresso')
159
+				: esc_html__('* price does not include taxes', 'event_espresso');
160
+			$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
161
+				  . $ticket_price_includes_taxes
162
+				  . '</span>';
163
+		}
164
+
165
+		// name td
166
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l');
167
+		// quantity td
168
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
169
+		$tax_rate = $line_item->is_taxable()
170
+					&& EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes
171
+			? 1 + ( $this->_tax_rate / 100 )
172
+			: 1;
173
+		// price td
174
+		$unit_price = apply_filters(
175
+			'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__unit_price',
176
+			EEH_Template::format_currency($line_item->unit_price() * $tax_rate, false, false),
177
+			$line_item,
178
+			$tax_rate
179
+		);
180
+		$html .= EEH_HTML::td($unit_price, '', 'item_c jst-rght');
181
+		// total td
182
+		$total = apply_filters(
183
+			'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__total',
184
+			EEH_Template::format_currency($line_item->unit_price() * $line_item->quantity() * $tax_rate, false, false),
185
+			$line_item,
186
+			$tax_rate
187
+		);
188
+		$html .= EEH_HTML::td($total, '', 'item_r jst-rght');
189
+		// end of row
190
+		$html .= EEH_HTML::trx();
191
+
192
+		return $html;
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 *  _sub_item_row
199
+	 *
200
+	 * @param EE_Line_Item $line_item
201
+	 * @param array        $options
202
+	 * @return mixed
203
+	 */
204
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array())
205
+	{
206
+		// start of row
207
+		$html = EEH_HTML::tr('', 'item sub-item-row');
208
+		// name && desc
209
+		$name_and_desc = $line_item->name();
210
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '';
211
+		// name td
212
+		$html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item');
213
+		// discount/surcharge td
214
+		if ($line_item->is_percent()) {
215
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
216
+		} else {
217
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
218
+		}
219
+		// total td
220
+		$html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'item_r jst-rght');
221
+		// end of row
222
+		$html .= EEH_HTML::trx();
223
+		return $html;
224
+	}
225 225
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
         $html = '';
67 67
         // set some default options and merge with incoming
68 68
         $default_options = array(
69
-            'show_desc' => true,  //    TRUE        FALSE
69
+            'show_desc' => true, //    TRUE        FALSE
70 70
             'odd' => false
71 71
         );
72 72
         $options = array_merge($default_options, (array) $options);
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         );
150 150
         $name_and_desc .= apply_filters(
151 151
             'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc',
152
-            ( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ),
152
+            ($options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' : ''),
153 153
             $line_item,
154 154
             $options
155 155
         );
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
         $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
169 169
         $tax_rate = $line_item->is_taxable()
170 170
                     && EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes
171
-            ? 1 + ( $this->_tax_rate / 100 )
171
+            ? 1 + ($this->_tax_rate / 100)
172 172
             : 1;
173 173
         // price td
174 174
         $unit_price = apply_filters(
@@ -207,12 +207,12 @@  discard block
 block discarded – undo
207 207
         $html = EEH_HTML::tr('', 'item sub-item-row');
208 208
         // name && desc
209 209
         $name_and_desc = $line_item->name();
210
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '';
210
+        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' : '';
211 211
         // name td
212 212
         $html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item');
213 213
         // discount/surcharge td
214 214
         if ($line_item->is_percent()) {
215
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
215
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c');
216 216
         } else {
217 217
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
218 218
         }
Please login to merge, or discard this patch.
line_item_display/EE_Invoice_Line_Item_Display_Strategy.strategy.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
     /**
18 18
      * @param EE_Line_Item $line_item
19 19
      * @param array        $options
20
-     * @return mixed
20
+     * @return string
21 21
      */
22 22
     public function display_line_item(EE_Line_Item $line_item, $options = array())
23 23
     {
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      *
93 93
      * @param EE_Line_Item $line_item
94 94
      * @param array        $options
95
-     * @return mixed
95
+     * @return string
96 96
      */
97 97
     private function _item_row(EE_Line_Item $line_item, $options = array())
98 98
     {
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      *
123 123
      * @param EE_Line_Item $line_item
124 124
      * @param array        $options
125
-     * @return mixed
125
+     * @return string
126 126
      */
127 127
     private function _sub_item_row(EE_Line_Item $line_item, $options = array())
128 128
     {
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      *
154 154
      * @param EE_Line_Item $line_item
155 155
      * @param array        $options
156
-     * @return mixed
156
+     * @return string
157 157
      */
158 158
     private function _tax_row(EE_Line_Item $line_item, $options = array())
159 159
     {
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      * @param EE_Line_Item $line_item
181 181
      * @param string       $text
182 182
      * @param array        $options
183
-     * @return mixed
183
+     * @return string
184 184
      */
185 185
     private function _total_row(EE_Line_Item $line_item, $text = '', $options = array())
186 186
     {
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      *  _separator_row
206 206
      *
207 207
      * @param array        $options
208
-     * @return mixed
208
+     * @return string
209 209
      */
210 210
     private function _separator_row($options = array())
211 211
     {
Please login to merge, or discard this patch.
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -1,222 +1,222 @@
 block discarded – undo
1 1
 <?php
2 2
  /**
3
- *
4
- * Class EE_Invoice_Line_Item_Display_Strategy
5
- *
6
- * Description
7
- *
8
- * @package         Event Espresso
9
- * @subpackage    core
10
- * @author              Brent Christensen
11
- *
12
- *
13
- */
3
+  *
4
+  * Class EE_Invoice_Line_Item_Display_Strategy
5
+  *
6
+  * Description
7
+  *
8
+  * @package         Event Espresso
9
+  * @subpackage    core
10
+  * @author              Brent Christensen
11
+  *
12
+  *
13
+  */
14 14
 class EE_Invoice_Line_Item_Display_Strategy implements EEI_Line_Item_Display
15 15
 {
16 16
 
17
-    /**
18
-     * @param EE_Line_Item $line_item
19
-     * @param array        $options
20
-     * @return mixed
21
-     */
22
-    public function display_line_item(EE_Line_Item $line_item, $options = array())
23
-    {
24
-
25
-        $html = '';
26
-        // set some default options and merge with incoming
27
-        $default_options = array(
28
-            'show_desc' => true,
29
-            'odd' => false
30
-        );
31
-        $options = array_merge($default_options, (array) $options);
32
-
33
-        switch ($line_item->type()) {
34
-            case EEM_Line_Item::type_total:
35
-                // loop thru children
36
-                foreach ($line_item->children() as $child_line_item) {
37
-                    // recursively feed children back into this method
38
-                    $html .= $this->display_line_item($child_line_item, $options);
39
-                }
40
-                $html .= $this->_separator_row($options);
41
-                $html .= $this->_total_row($line_item, __('Total', 'event_espresso'), $options);
42
-                break;
43
-
44
-
45
-            case EEM_Line_Item::type_sub_total:
46
-                // loop thru children
47
-                foreach ($line_item->children() as $child_line_item) {
48
-                    // recursively feed children back into this method
49
-                    $html .= $this->display_line_item($child_line_item, $options);
50
-                }
51
-                $html .= $this->_total_row($line_item, __('Sub-Total', 'event_espresso'), $options);
52
-                break;
53
-
54
-
55
-            case EEM_Line_Item::type_tax_sub_total:
56
-                // loop thru children
57
-                foreach ($line_item->children() as $child_line_item) {
58
-                    // recursively feed children back into this method
59
-                    $html .= $this->display_line_item($child_line_item, $options);
60
-                }
61
-                $html .= $this->_total_row($line_item, __('Tax Total', 'event_espresso'), $options);
62
-                break;
63
-
64
-
65
-            case EEM_Line_Item::type_line_item:
66
-                // item row
67
-                $html .= $this->_item_row($line_item, $options);
68
-                // got any kids?
69
-                foreach ($line_item->children() as $child_line_item) {
70
-                    $this->display_line_item($child_line_item, $options);
71
-                }
72
-                break;
73
-
74
-
75
-            case EEM_Line_Item::type_sub_line_item:
76
-                $html .= $this->_sub_item_row($line_item, $options);
77
-                break;
78
-
79
-
80
-            case EEM_Line_Item::type_tax:
81
-                $html .= $this->_tax_row($line_item, $options);
82
-                break;
83
-        }
84
-
85
-        return $html;
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     *  _total_row
92
-     *
93
-     * @param EE_Line_Item $line_item
94
-     * @param array        $options
95
-     * @return mixed
96
-     */
97
-    private function _item_row(EE_Line_Item $line_item, $options = array())
98
-    {
99
-        // start of row
100
-        $row_class = $options['odd'] ? 'item odd' : 'item';
101
-        $html = EEH_HTML::tr('', $row_class);
102
-        // name td
103
-        $html .= EEH_HTML::td($line_item->name(), '', 'item_l');
104
-        // desc td
105
-        $html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
106
-        // quantity td
107
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l');
108
-        // price td
109
-        $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c');
110
-        // total td
111
-        $total = $line_item->is_taxable() ? $line_item->total_no_code() . '*' : $line_item->total_no_code();
112
-        $html .= EEH_HTML::td($total, '', 'item_r');
113
-        // end of row
114
-        $html .= EEH_HTML::trx();
115
-        return $html;
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     *  _sub_item_row
122
-     *
123
-     * @param EE_Line_Item $line_item
124
-     * @param array        $options
125
-     * @return mixed
126
-     */
127
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array())
128
-    {
129
-        // start of row
130
-        $html = EEH_HTML::tr('', 'item sub-item-row');
131
-        // name td
132
-        $html .= EEH_HTML::td($line_item->name(), '', 'item_l sub-item');
133
-        // desc td
134
-        $html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
135
-        $html .= EEH_HTML::td() . EEH_HTML::tdx();
136
-        // discount/surcharge td
137
-        if ($line_item->is_percent()) {
138
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
139
-        } else {
140
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c');
141
-        }
142
-        // total td
143
-        $html .= EEH_HTML::td($line_item->total_no_code(), '', 'item_r');
144
-        // end of row
145
-        $html .= EEH_HTML::trx();
146
-        return $html;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     *  _tax_row
153
-     *
154
-     * @param EE_Line_Item $line_item
155
-     * @param array        $options
156
-     * @return mixed
157
-     */
158
-    private function _tax_row(EE_Line_Item $line_item, $options = array())
159
-    {
160
-        // start of row
161
-        $html = EEH_HTML::tr('', 'item sub-item tax-total');
162
-        // name td
163
-        $html .= EEH_HTML::td($line_item->name(), '', 'item_l sub-item');
164
-        // desc td
165
-        $html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
166
-        // percent td
167
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c', '', ' colspan="2"');
168
-        // total td
169
-        $html .= EEH_HTML::td($line_item->total_no_code(), '', 'item_r');
170
-        // end of row
171
-        $html .= EEH_HTML::trx();
172
-        return $html;
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     *  _total_row
179
-     *
180
-     * @param EE_Line_Item $line_item
181
-     * @param string       $text
182
-     * @param array        $options
183
-     * @return mixed
184
-     */
185
-    private function _total_row(EE_Line_Item $line_item, $text = '', $options = array())
186
-    {
187
-        // colspan
188
-        $colspan = $options['show_desc'] ? ' colspan="2"' : '';
189
-        // start of row
190
-        $html = EEH_HTML::tr('', '', 'total_tr odd');
191
-        // empty td
192
-        $html .= EEH_HTML::td(EEH_HTML::nbsp(), '', '', '', $colspan);
193
-        // total td
194
-        $html .= EEH_HTML::td($text, '', 'total_currency total', '', $colspan);
195
-        // total td
196
-        $html .= EEH_HTML::td($line_item->total_no_code(), '', 'total');
197
-        // end of row
198
-        $html .= EEH_HTML::trx();
199
-        return $html;
200
-    }
201
-
202
-
203
-
204
-    /**
205
-     *  _separator_row
206
-     *
207
-     * @param array        $options
208
-     * @return mixed
209
-     */
210
-    private function _separator_row($options = array())
211
-    {
212
-        // colspan
213
-        $colspan = $options['show_desc'] ? ' colspan="5"' : ' colspan="4"';
214
-        // start of row
215
-        $html = EEH_HTML::tr(EEH_HTML::td('<hr>', '', '', '', $colspan));
17
+	/**
18
+	 * @param EE_Line_Item $line_item
19
+	 * @param array        $options
20
+	 * @return mixed
21
+	 */
22
+	public function display_line_item(EE_Line_Item $line_item, $options = array())
23
+	{
24
+
25
+		$html = '';
26
+		// set some default options and merge with incoming
27
+		$default_options = array(
28
+			'show_desc' => true,
29
+			'odd' => false
30
+		);
31
+		$options = array_merge($default_options, (array) $options);
32
+
33
+		switch ($line_item->type()) {
34
+			case EEM_Line_Item::type_total:
35
+				// loop thru children
36
+				foreach ($line_item->children() as $child_line_item) {
37
+					// recursively feed children back into this method
38
+					$html .= $this->display_line_item($child_line_item, $options);
39
+				}
40
+				$html .= $this->_separator_row($options);
41
+				$html .= $this->_total_row($line_item, __('Total', 'event_espresso'), $options);
42
+				break;
43
+
44
+
45
+			case EEM_Line_Item::type_sub_total:
46
+				// loop thru children
47
+				foreach ($line_item->children() as $child_line_item) {
48
+					// recursively feed children back into this method
49
+					$html .= $this->display_line_item($child_line_item, $options);
50
+				}
51
+				$html .= $this->_total_row($line_item, __('Sub-Total', 'event_espresso'), $options);
52
+				break;
53
+
54
+
55
+			case EEM_Line_Item::type_tax_sub_total:
56
+				// loop thru children
57
+				foreach ($line_item->children() as $child_line_item) {
58
+					// recursively feed children back into this method
59
+					$html .= $this->display_line_item($child_line_item, $options);
60
+				}
61
+				$html .= $this->_total_row($line_item, __('Tax Total', 'event_espresso'), $options);
62
+				break;
63
+
64
+
65
+			case EEM_Line_Item::type_line_item:
66
+				// item row
67
+				$html .= $this->_item_row($line_item, $options);
68
+				// got any kids?
69
+				foreach ($line_item->children() as $child_line_item) {
70
+					$this->display_line_item($child_line_item, $options);
71
+				}
72
+				break;
73
+
74
+
75
+			case EEM_Line_Item::type_sub_line_item:
76
+				$html .= $this->_sub_item_row($line_item, $options);
77
+				break;
78
+
79
+
80
+			case EEM_Line_Item::type_tax:
81
+				$html .= $this->_tax_row($line_item, $options);
82
+				break;
83
+		}
84
+
85
+		return $html;
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 *  _total_row
92
+	 *
93
+	 * @param EE_Line_Item $line_item
94
+	 * @param array        $options
95
+	 * @return mixed
96
+	 */
97
+	private function _item_row(EE_Line_Item $line_item, $options = array())
98
+	{
99
+		// start of row
100
+		$row_class = $options['odd'] ? 'item odd' : 'item';
101
+		$html = EEH_HTML::tr('', $row_class);
102
+		// name td
103
+		$html .= EEH_HTML::td($line_item->name(), '', 'item_l');
104
+		// desc td
105
+		$html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
106
+		// quantity td
107
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l');
108
+		// price td
109
+		$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c');
110
+		// total td
111
+		$total = $line_item->is_taxable() ? $line_item->total_no_code() . '*' : $line_item->total_no_code();
112
+		$html .= EEH_HTML::td($total, '', 'item_r');
113
+		// end of row
114
+		$html .= EEH_HTML::trx();
115
+		return $html;
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 *  _sub_item_row
122
+	 *
123
+	 * @param EE_Line_Item $line_item
124
+	 * @param array        $options
125
+	 * @return mixed
126
+	 */
127
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array())
128
+	{
129
+		// start of row
130
+		$html = EEH_HTML::tr('', 'item sub-item-row');
131
+		// name td
132
+		$html .= EEH_HTML::td($line_item->name(), '', 'item_l sub-item');
133
+		// desc td
134
+		$html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
135
+		$html .= EEH_HTML::td() . EEH_HTML::tdx();
136
+		// discount/surcharge td
137
+		if ($line_item->is_percent()) {
138
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
139
+		} else {
140
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c');
141
+		}
142
+		// total td
143
+		$html .= EEH_HTML::td($line_item->total_no_code(), '', 'item_r');
144
+		// end of row
145
+		$html .= EEH_HTML::trx();
146
+		return $html;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 *  _tax_row
153
+	 *
154
+	 * @param EE_Line_Item $line_item
155
+	 * @param array        $options
156
+	 * @return mixed
157
+	 */
158
+	private function _tax_row(EE_Line_Item $line_item, $options = array())
159
+	{
160
+		// start of row
161
+		$html = EEH_HTML::tr('', 'item sub-item tax-total');
162
+		// name td
163
+		$html .= EEH_HTML::td($line_item->name(), '', 'item_l sub-item');
164
+		// desc td
165
+		$html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
166
+		// percent td
167
+		$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c', '', ' colspan="2"');
168
+		// total td
169
+		$html .= EEH_HTML::td($line_item->total_no_code(), '', 'item_r');
170
+		// end of row
171
+		$html .= EEH_HTML::trx();
172
+		return $html;
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 *  _total_row
179
+	 *
180
+	 * @param EE_Line_Item $line_item
181
+	 * @param string       $text
182
+	 * @param array        $options
183
+	 * @return mixed
184
+	 */
185
+	private function _total_row(EE_Line_Item $line_item, $text = '', $options = array())
186
+	{
187
+		// colspan
188
+		$colspan = $options['show_desc'] ? ' colspan="2"' : '';
189
+		// start of row
190
+		$html = EEH_HTML::tr('', '', 'total_tr odd');
191
+		// empty td
192
+		$html .= EEH_HTML::td(EEH_HTML::nbsp(), '', '', '', $colspan);
193
+		// total td
194
+		$html .= EEH_HTML::td($text, '', 'total_currency total', '', $colspan);
195
+		// total td
196
+		$html .= EEH_HTML::td($line_item->total_no_code(), '', 'total');
197
+		// end of row
198
+		$html .= EEH_HTML::trx();
199
+		return $html;
200
+	}
201
+
202
+
203
+
204
+	/**
205
+	 *  _separator_row
206
+	 *
207
+	 * @param array        $options
208
+	 * @return mixed
209
+	 */
210
+	private function _separator_row($options = array())
211
+	{
212
+		// colspan
213
+		$colspan = $options['show_desc'] ? ' colspan="5"' : ' colspan="4"';
214
+		// start of row
215
+		$html = EEH_HTML::tr(EEH_HTML::td('<hr>', '', '', '', $colspan));
216 216
 //      // separator td
217 217
 //      $html .= EEH_HTML::td( '<hr>', '',  '',  '',  $colspan );
218 218
 //      // end of row
219 219
 //      $html .= EEH_HTML::trx();
220
-        return $html;
221
-    }
220
+		return $html;
221
+	}
222 222
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
         // price td
109 109
         $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c');
110 110
         // total td
111
-        $total = $line_item->is_taxable() ? $line_item->total_no_code() . '*' : $line_item->total_no_code();
111
+        $total = $line_item->is_taxable() ? $line_item->total_no_code().'*' : $line_item->total_no_code();
112 112
         $html .= EEH_HTML::td($total, '', 'item_r');
113 113
         // end of row
114 114
         $html .= EEH_HTML::trx();
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
         $html .= EEH_HTML::td($line_item->name(), '', 'item_l sub-item');
133 133
         // desc td
134 134
         $html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
135
-        $html .= EEH_HTML::td() . EEH_HTML::tdx();
135
+        $html .= EEH_HTML::td().EEH_HTML::tdx();
136 136
         // discount/surcharge td
137 137
         if ($line_item->is_percent()) {
138
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
138
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c');
139 139
         } else {
140 140
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c');
141 141
         }
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         // desc td
165 165
         $html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
166 166
         // percent td
167
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c', '', ' colspan="2"');
167
+        $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c', '', ' colspan="2"');
168 168
         // total td
169 169
         $html .= EEH_HTML::td($line_item->total_no_code(), '', 'item_r');
170 170
         // end of row
Please login to merge, or discard this patch.