@@ -15,286 +15,286 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * instance of the EE_System object |
|
20 | - * |
|
21 | - * @var $_instance |
|
22 | - * @access private |
|
23 | - */ |
|
24 | - private static $_instance = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * $_autoloaders |
|
28 | - * @var array $_autoloaders |
|
29 | - * @access private |
|
30 | - */ |
|
31 | - private static $_autoloaders; |
|
32 | - |
|
33 | - /** |
|
34 | - * set to "paths" to display autoloader class => path mappings |
|
35 | - * set to "times" to display autoloader loading times |
|
36 | - * set to "all" to display both |
|
37 | - * |
|
38 | - * @var string $debug |
|
39 | - * @access private |
|
40 | - */ |
|
41 | - public static $debug = false; |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * class constructor |
|
47 | - * |
|
48 | - * @access private |
|
49 | - * @return \EEH_Autoloader |
|
50 | - */ |
|
51 | - private function __construct() |
|
52 | - { |
|
53 | - if (self::$_autoloaders === null) { |
|
54 | - self::$_autoloaders = array(); |
|
55 | - $this->_register_custom_autoloaders(); |
|
56 | - spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @access public |
|
64 | - * @return EEH_Autoloader |
|
65 | - */ |
|
66 | - public static function instance() |
|
67 | - { |
|
68 | - // check if class object is instantiated |
|
69 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
70 | - self::$_instance = new self(); |
|
71 | - } |
|
72 | - return self::$_instance; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * espresso_autoloader |
|
79 | - * |
|
80 | - * @access public |
|
81 | - * @param $class_name |
|
82 | - * @internal param $className |
|
83 | - * @internal param string $class_name - simple class name ie: session |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public static function espresso_autoloader($class_name) |
|
87 | - { |
|
88 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
89 | - require_once(self::$_autoloaders[ $class_name ]); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * register_autoloader |
|
97 | - * |
|
98 | - * @access public |
|
99 | - * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
100 | - * @param bool $read_check true if we need to check whether the file is readable or not. |
|
101 | - * @param bool $debug **deprecated** |
|
102 | - * @throws \EE_Error |
|
103 | - */ |
|
104 | - public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
105 | - { |
|
106 | - $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
107 | - foreach ($class_paths as $class => $path) { |
|
108 | - // don't give up! you gotta... |
|
109 | - // get some class |
|
110 | - if (empty($class)) { |
|
111 | - throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path)); |
|
112 | - } |
|
113 | - // one day you will find the path young grasshopper |
|
114 | - if (empty($path)) { |
|
115 | - throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class)); |
|
116 | - } |
|
117 | - // is file readable ? |
|
118 | - if ($read_check && ! is_readable($path)) { |
|
119 | - throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
|
120 | - } |
|
121 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
122 | - self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), DS, $path); |
|
123 | - if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
124 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * get_autoloaders |
|
135 | - * |
|
136 | - * @access public |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public static function get_autoloaders() |
|
140 | - { |
|
141 | - return self::$_autoloaders; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * register core, model and class 'autoloaders' |
|
149 | - * |
|
150 | - * @access private |
|
151 | - * @return void |
|
152 | - */ |
|
153 | - private function _register_custom_autoloaders() |
|
154 | - { |
|
155 | - EEH_Autoloader::$debug = ''; |
|
156 | - \EEH_Autoloader::register_helpers_autoloaders(); |
|
157 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
158 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
159 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
160 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
161 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
162 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
163 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
164 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
165 | - EEH_Debug_Tools::instance()->show_times(); |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * register core, model and class 'autoloaders' |
|
173 | - * |
|
174 | - * @access public |
|
175 | - */ |
|
176 | - public static function register_helpers_autoloaders() |
|
177 | - { |
|
178 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * register core, model and class 'autoloaders' |
|
186 | - * |
|
187 | - * @access public |
|
188 | - * @return void |
|
189 | - */ |
|
190 | - public static function register_form_sections_autoloaders() |
|
191 | - { |
|
192 | - // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * register core, model and class 'autoloaders' |
|
200 | - * |
|
201 | - * @access public |
|
202 | - * @return void |
|
203 | - */ |
|
204 | - public static function register_line_item_display_autoloaders() |
|
205 | - { |
|
206 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * register core, model and class 'autoloaders' |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @return void |
|
217 | - */ |
|
218 | - public static function register_line_item_filter_autoloaders() |
|
219 | - { |
|
220 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * register template part 'autoloaders' |
|
228 | - * |
|
229 | - * @access public |
|
230 | - * @return void |
|
231 | - */ |
|
232 | - public static function register_template_part_autoloaders() |
|
233 | - { |
|
234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
241 | - * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
242 | - * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly. |
|
243 | - * Yes this has to scan the directory for files, but it only does it once -- not on EACH |
|
244 | - * time the autoloader is used |
|
245 | - * |
|
246 | - * @param string $folder name, with or without trailing /, doesn't matter |
|
247 | - * @param bool $recursive |
|
248 | - * @param bool $debug **deprecated** |
|
249 | - * @throws \EE_Error |
|
250 | - */ |
|
251 | - public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) |
|
252 | - { |
|
253 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
254 | - EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
255 | - } |
|
256 | - // make sure last char is a / |
|
257 | - $folder .= $folder[ strlen($folder)-1 ] !== DS ? DS : ''; |
|
258 | - $class_to_filepath_map = array(); |
|
259 | - $exclude = array( 'index' ); |
|
260 | - // get all the files in that folder that end in php |
|
261 | - $filepaths = glob($folder.'*'); |
|
262 | - |
|
263 | - if (empty($filepaths)) { |
|
264 | - return; |
|
265 | - } |
|
266 | - |
|
267 | - foreach ($filepaths as $filepath) { |
|
268 | - if (substr($filepath, -4, 4) === '.php') { |
|
269 | - $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
270 | - if (! in_array($class_name, $exclude)) { |
|
271 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
272 | - } |
|
273 | - } elseif ($recursive) { |
|
274 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
275 | - } |
|
276 | - } |
|
277 | - // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
278 | - self::register_autoloader($class_to_filepath_map, false, $debug); |
|
279 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
280 | - EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
281 | - } |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * add_alias |
|
288 | - * register additional autoloader based on variation of the classname for an existing autoloader |
|
289 | - * |
|
290 | - * @access public |
|
291 | - * @param string $class_name - simple class name ie: EE_Session |
|
292 | - * @param string $alias - variation on class name ie: EE_session, session, etc |
|
293 | - */ |
|
294 | - public static function add_alias($class_name, $alias) |
|
295 | - { |
|
296 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
297 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
298 | - } |
|
299 | - } |
|
18 | + /** |
|
19 | + * instance of the EE_System object |
|
20 | + * |
|
21 | + * @var $_instance |
|
22 | + * @access private |
|
23 | + */ |
|
24 | + private static $_instance = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * $_autoloaders |
|
28 | + * @var array $_autoloaders |
|
29 | + * @access private |
|
30 | + */ |
|
31 | + private static $_autoloaders; |
|
32 | + |
|
33 | + /** |
|
34 | + * set to "paths" to display autoloader class => path mappings |
|
35 | + * set to "times" to display autoloader loading times |
|
36 | + * set to "all" to display both |
|
37 | + * |
|
38 | + * @var string $debug |
|
39 | + * @access private |
|
40 | + */ |
|
41 | + public static $debug = false; |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * class constructor |
|
47 | + * |
|
48 | + * @access private |
|
49 | + * @return \EEH_Autoloader |
|
50 | + */ |
|
51 | + private function __construct() |
|
52 | + { |
|
53 | + if (self::$_autoloaders === null) { |
|
54 | + self::$_autoloaders = array(); |
|
55 | + $this->_register_custom_autoloaders(); |
|
56 | + spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @access public |
|
64 | + * @return EEH_Autoloader |
|
65 | + */ |
|
66 | + public static function instance() |
|
67 | + { |
|
68 | + // check if class object is instantiated |
|
69 | + if (! self::$_instance instanceof EEH_Autoloader) { |
|
70 | + self::$_instance = new self(); |
|
71 | + } |
|
72 | + return self::$_instance; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * espresso_autoloader |
|
79 | + * |
|
80 | + * @access public |
|
81 | + * @param $class_name |
|
82 | + * @internal param $className |
|
83 | + * @internal param string $class_name - simple class name ie: session |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public static function espresso_autoloader($class_name) |
|
87 | + { |
|
88 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
89 | + require_once(self::$_autoloaders[ $class_name ]); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * register_autoloader |
|
97 | + * |
|
98 | + * @access public |
|
99 | + * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
100 | + * @param bool $read_check true if we need to check whether the file is readable or not. |
|
101 | + * @param bool $debug **deprecated** |
|
102 | + * @throws \EE_Error |
|
103 | + */ |
|
104 | + public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
105 | + { |
|
106 | + $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
107 | + foreach ($class_paths as $class => $path) { |
|
108 | + // don't give up! you gotta... |
|
109 | + // get some class |
|
110 | + if (empty($class)) { |
|
111 | + throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path)); |
|
112 | + } |
|
113 | + // one day you will find the path young grasshopper |
|
114 | + if (empty($path)) { |
|
115 | + throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class)); |
|
116 | + } |
|
117 | + // is file readable ? |
|
118 | + if ($read_check && ! is_readable($path)) { |
|
119 | + throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
|
120 | + } |
|
121 | + if (! isset(self::$_autoloaders[ $class ])) { |
|
122 | + self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), DS, $path); |
|
123 | + if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
124 | + EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * get_autoloaders |
|
135 | + * |
|
136 | + * @access public |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public static function get_autoloaders() |
|
140 | + { |
|
141 | + return self::$_autoloaders; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * register core, model and class 'autoloaders' |
|
149 | + * |
|
150 | + * @access private |
|
151 | + * @return void |
|
152 | + */ |
|
153 | + private function _register_custom_autoloaders() |
|
154 | + { |
|
155 | + EEH_Autoloader::$debug = ''; |
|
156 | + \EEH_Autoloader::register_helpers_autoloaders(); |
|
157 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
158 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
159 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
160 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
161 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
162 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
163 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
164 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
165 | + EEH_Debug_Tools::instance()->show_times(); |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * register core, model and class 'autoloaders' |
|
173 | + * |
|
174 | + * @access public |
|
175 | + */ |
|
176 | + public static function register_helpers_autoloaders() |
|
177 | + { |
|
178 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * register core, model and class 'autoloaders' |
|
186 | + * |
|
187 | + * @access public |
|
188 | + * @return void |
|
189 | + */ |
|
190 | + public static function register_form_sections_autoloaders() |
|
191 | + { |
|
192 | + // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * register core, model and class 'autoloaders' |
|
200 | + * |
|
201 | + * @access public |
|
202 | + * @return void |
|
203 | + */ |
|
204 | + public static function register_line_item_display_autoloaders() |
|
205 | + { |
|
206 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * register core, model and class 'autoloaders' |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @return void |
|
217 | + */ |
|
218 | + public static function register_line_item_filter_autoloaders() |
|
219 | + { |
|
220 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * register template part 'autoloaders' |
|
228 | + * |
|
229 | + * @access public |
|
230 | + * @return void |
|
231 | + */ |
|
232 | + public static function register_template_part_autoloaders() |
|
233 | + { |
|
234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
241 | + * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
242 | + * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly. |
|
243 | + * Yes this has to scan the directory for files, but it only does it once -- not on EACH |
|
244 | + * time the autoloader is used |
|
245 | + * |
|
246 | + * @param string $folder name, with or without trailing /, doesn't matter |
|
247 | + * @param bool $recursive |
|
248 | + * @param bool $debug **deprecated** |
|
249 | + * @throws \EE_Error |
|
250 | + */ |
|
251 | + public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) |
|
252 | + { |
|
253 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
254 | + EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
255 | + } |
|
256 | + // make sure last char is a / |
|
257 | + $folder .= $folder[ strlen($folder)-1 ] !== DS ? DS : ''; |
|
258 | + $class_to_filepath_map = array(); |
|
259 | + $exclude = array( 'index' ); |
|
260 | + // get all the files in that folder that end in php |
|
261 | + $filepaths = glob($folder.'*'); |
|
262 | + |
|
263 | + if (empty($filepaths)) { |
|
264 | + return; |
|
265 | + } |
|
266 | + |
|
267 | + foreach ($filepaths as $filepath) { |
|
268 | + if (substr($filepath, -4, 4) === '.php') { |
|
269 | + $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
270 | + if (! in_array($class_name, $exclude)) { |
|
271 | + $class_to_filepath_map [ $class_name ] = $filepath; |
|
272 | + } |
|
273 | + } elseif ($recursive) { |
|
274 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
275 | + } |
|
276 | + } |
|
277 | + // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
278 | + self::register_autoloader($class_to_filepath_map, false, $debug); |
|
279 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
280 | + EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
281 | + } |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * add_alias |
|
288 | + * register additional autoloader based on variation of the classname for an existing autoloader |
|
289 | + * |
|
290 | + * @access public |
|
291 | + * @param string $class_name - simple class name ie: EE_Session |
|
292 | + * @param string $alias - variation on class name ie: EE_session, session, etc |
|
293 | + */ |
|
294 | + public static function add_alias($class_name, $alias) |
|
295 | + { |
|
296 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
297 | + self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
298 | + } |
|
299 | + } |
|
300 | 300 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | if (self::$_autoloaders === null) { |
54 | 54 | self::$_autoloaders = array(); |
55 | 55 | $this->_register_custom_autoloaders(); |
56 | - spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
56 | + spl_autoload_register(array($this, 'espresso_autoloader')); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public static function instance() |
67 | 67 | { |
68 | 68 | // check if class object is instantiated |
69 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
69 | + if ( ! self::$_instance instanceof EEH_Autoloader) { |
|
70 | 70 | self::$_instance = new self(); |
71 | 71 | } |
72 | 72 | return self::$_instance; |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public static function espresso_autoloader($class_name) |
87 | 87 | { |
88 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
89 | - require_once(self::$_autoloaders[ $class_name ]); |
|
88 | + if (isset(self::$_autoloaders[$class_name])) { |
|
89 | + require_once(self::$_autoloaders[$class_name]); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
105 | 105 | { |
106 | - $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
106 | + $class_paths = is_array($class_paths) ? $class_paths : array($class_paths); |
|
107 | 107 | foreach ($class_paths as $class => $path) { |
108 | 108 | // don't give up! you gotta... |
109 | 109 | // get some class |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | if ($read_check && ! is_readable($path)) { |
119 | 119 | throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
120 | 120 | } |
121 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
122 | - self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), DS, $path); |
|
123 | - if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
124 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
121 | + if ( ! isset(self::$_autoloaders[$class])) { |
|
122 | + self::$_autoloaders[$class] = str_replace(array('/', '\\'), DS, $path); |
|
123 | + if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) { |
|
124 | + EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | } |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | { |
155 | 155 | EEH_Autoloader::$debug = ''; |
156 | 156 | \EEH_Autoloader::register_helpers_autoloaders(); |
157 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
157 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces'); |
|
158 | 158 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
159 | 159 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
160 | 160 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
161 | 161 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
162 | 162 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
163 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
163 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages'); |
|
164 | 164 | if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
165 | 165 | EEH_Debug_Tools::instance()->show_times(); |
166 | 166 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | */ |
204 | 204 | public static function register_line_item_display_autoloaders() |
205 | 205 | { |
206 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
206 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public static function register_line_item_filter_autoloaders() |
219 | 219 | { |
220 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
220 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | public static function register_template_part_autoloaders() |
233 | 233 | { |
234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
255 | 255 | } |
256 | 256 | // make sure last char is a / |
257 | - $folder .= $folder[ strlen($folder)-1 ] !== DS ? DS : ''; |
|
257 | + $folder .= $folder[strlen($folder) - 1] !== DS ? DS : ''; |
|
258 | 258 | $class_to_filepath_map = array(); |
259 | - $exclude = array( 'index' ); |
|
259 | + $exclude = array('index'); |
|
260 | 260 | // get all the files in that folder that end in php |
261 | 261 | $filepaths = glob($folder.'*'); |
262 | 262 | |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | foreach ($filepaths as $filepath) { |
268 | 268 | if (substr($filepath, -4, 4) === '.php') { |
269 | 269 | $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
270 | - if (! in_array($class_name, $exclude)) { |
|
271 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
270 | + if ( ! in_array($class_name, $exclude)) { |
|
271 | + $class_to_filepath_map [$class_name] = $filepath; |
|
272 | 272 | } |
273 | 273 | } elseif ($recursive) { |
274 | 274 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
@@ -293,8 +293,8 @@ discard block |
||
293 | 293 | */ |
294 | 294 | public static function add_alias($class_name, $alias) |
295 | 295 | { |
296 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
297 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
296 | + if (isset(self::$_autoloaders[$class_name])) { |
|
297 | + self::$_autoloaders[$alias] = self::$_autoloaders[$class_name]; |
|
298 | 298 | } |
299 | 299 | } |
300 | 300 | } |
@@ -11,131 +11,131 @@ |
||
11 | 11 | class EEH_Class_Tools |
12 | 12 | { |
13 | 13 | |
14 | - public static $i = 0; |
|
15 | - public static $file_line = null; |
|
14 | + public static $i = 0; |
|
15 | + public static $file_line = null; |
|
16 | 16 | |
17 | - /** |
|
18 | - * get_called_class - for PHP versions < 5.3 |
|
19 | - * |
|
20 | - * @access public |
|
21 | - * @author origins: http://stackoverflow.com/a/1542045 |
|
22 | - * return string |
|
23 | - */ |
|
24 | - public static function get_called_class() |
|
25 | - { |
|
26 | - $backtrace = debug_backtrace(); |
|
27 | - if (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['class']) && ! isset($backtrace[2]['file'])) { |
|
28 | - return $backtrace[2]['class']; |
|
29 | - } elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) { |
|
30 | - return $backtrace[3]['class']; |
|
31 | - } elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) { |
|
32 | - if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) { |
|
33 | - self::$i++; |
|
34 | - } else { |
|
35 | - self::$i = 0; |
|
36 | - self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line']; |
|
37 | - } |
|
38 | - // was class method called via call_user_func ? |
|
39 | - if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) { |
|
40 | - if (isset($backtrace[2]['args'][0]) && isset($backtrace[2]['args'][0][0])) { |
|
41 | - $called_class = $backtrace[2]['args'][0][0]; |
|
42 | - // is it an EE function ? |
|
43 | - if (strpos($called_class, 'EE') === 0) { |
|
44 | - $prefix_chars = strpos($called_class, '_') + 1; |
|
45 | - $prefix = substr($called_class, 0, $prefix_chars); |
|
46 | - $classname = substr($called_class, $prefix_chars, strlen($called_class)); |
|
47 | - $classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname)))); |
|
48 | - return $classname; |
|
49 | - } |
|
50 | - } |
|
51 | - } else { |
|
52 | - $lines = file($backtrace[2]['file']); |
|
53 | - preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line']-1 ], $matches); |
|
54 | - if (isset($matches[1]) && isset($matches[1][ self::$i ])) { |
|
55 | - return $matches[1][ self::$i ]; |
|
56 | - } |
|
57 | - } |
|
58 | - } |
|
59 | - return false; |
|
60 | - } |
|
17 | + /** |
|
18 | + * get_called_class - for PHP versions < 5.3 |
|
19 | + * |
|
20 | + * @access public |
|
21 | + * @author origins: http://stackoverflow.com/a/1542045 |
|
22 | + * return string |
|
23 | + */ |
|
24 | + public static function get_called_class() |
|
25 | + { |
|
26 | + $backtrace = debug_backtrace(); |
|
27 | + if (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['class']) && ! isset($backtrace[2]['file'])) { |
|
28 | + return $backtrace[2]['class']; |
|
29 | + } elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) { |
|
30 | + return $backtrace[3]['class']; |
|
31 | + } elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) { |
|
32 | + if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) { |
|
33 | + self::$i++; |
|
34 | + } else { |
|
35 | + self::$i = 0; |
|
36 | + self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line']; |
|
37 | + } |
|
38 | + // was class method called via call_user_func ? |
|
39 | + if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) { |
|
40 | + if (isset($backtrace[2]['args'][0]) && isset($backtrace[2]['args'][0][0])) { |
|
41 | + $called_class = $backtrace[2]['args'][0][0]; |
|
42 | + // is it an EE function ? |
|
43 | + if (strpos($called_class, 'EE') === 0) { |
|
44 | + $prefix_chars = strpos($called_class, '_') + 1; |
|
45 | + $prefix = substr($called_class, 0, $prefix_chars); |
|
46 | + $classname = substr($called_class, $prefix_chars, strlen($called_class)); |
|
47 | + $classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname)))); |
|
48 | + return $classname; |
|
49 | + } |
|
50 | + } |
|
51 | + } else { |
|
52 | + $lines = file($backtrace[2]['file']); |
|
53 | + preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line']-1 ], $matches); |
|
54 | + if (isset($matches[1]) && isset($matches[1][ self::$i ])) { |
|
55 | + return $matches[1][ self::$i ]; |
|
56 | + } |
|
57 | + } |
|
58 | + } |
|
59 | + return false; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * get_class_names_for_all_callbacks_on_hook |
|
67 | - * returns an array of names for all classes that have methods registered as callbacks for the given action or filter hook |
|
68 | - * @access public |
|
69 | - * @param string $hook |
|
70 | - * @return array |
|
71 | - */ |
|
72 | - public static function get_class_names_for_all_callbacks_on_hook($hook = null) |
|
73 | - { |
|
74 | - global $wp_filter; |
|
75 | - $class_names = array(); |
|
76 | - // are any callbacks registered for this hook ? |
|
77 | - if (isset($wp_filter[ $hook ])) { |
|
78 | - // loop thru all of the callbacks attached to the deprecated hookpoint |
|
79 | - foreach ($wp_filter[ $hook ] as $priority) { |
|
80 | - foreach ($priority as $callback) { |
|
81 | - // is the callback a non-static class method ? |
|
82 | - if (isset($callback['function']) && is_array($callback['function'])) { |
|
83 | - if (isset($callback['function'][0]) && is_object($callback['function'][0])) { |
|
84 | - $class_names[] = get_class($callback['function'][0]); |
|
85 | - } |
|
86 | - // test for static method |
|
87 | - } elseif (strpos($callback['function'], '::') !== false) { |
|
88 | - $class = explode('::', $callback['function']); |
|
89 | - $class_names[] = $class[0]; |
|
90 | - } else { |
|
91 | - // just a function |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
96 | - return $class_names; |
|
97 | - } |
|
65 | + /** |
|
66 | + * get_class_names_for_all_callbacks_on_hook |
|
67 | + * returns an array of names for all classes that have methods registered as callbacks for the given action or filter hook |
|
68 | + * @access public |
|
69 | + * @param string $hook |
|
70 | + * @return array |
|
71 | + */ |
|
72 | + public static function get_class_names_for_all_callbacks_on_hook($hook = null) |
|
73 | + { |
|
74 | + global $wp_filter; |
|
75 | + $class_names = array(); |
|
76 | + // are any callbacks registered for this hook ? |
|
77 | + if (isset($wp_filter[ $hook ])) { |
|
78 | + // loop thru all of the callbacks attached to the deprecated hookpoint |
|
79 | + foreach ($wp_filter[ $hook ] as $priority) { |
|
80 | + foreach ($priority as $callback) { |
|
81 | + // is the callback a non-static class method ? |
|
82 | + if (isset($callback['function']) && is_array($callback['function'])) { |
|
83 | + if (isset($callback['function'][0]) && is_object($callback['function'][0])) { |
|
84 | + $class_names[] = get_class($callback['function'][0]); |
|
85 | + } |
|
86 | + // test for static method |
|
87 | + } elseif (strpos($callback['function'], '::') !== false) { |
|
88 | + $class = explode('::', $callback['function']); |
|
89 | + $class_names[] = $class[0]; |
|
90 | + } else { |
|
91 | + // just a function |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | + return $class_names; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | 100 | |
101 | 101 | |
102 | - /** |
|
103 | - * property_exists() with fallback for PHP versions < 5.3 |
|
104 | - * @access public |
|
105 | - * @param mixed object | string $class |
|
106 | - * @param string $property |
|
107 | - * @return boolean |
|
108 | - */ |
|
109 | - public static function has_property($class = null, $property = null) |
|
110 | - { |
|
111 | - // if $class or $property don't exist, then get out, cuz that would be like... fatal dude |
|
112 | - if (empty($class) || empty($property)) { |
|
113 | - return false; |
|
114 | - } |
|
115 | - // if your hosting company doesn't cut the mustard |
|
116 | - if (version_compare(PHP_VERSION, '5.3.0') < 0) { |
|
117 | - // just in case $class is an actual instantiated object |
|
118 | - if (is_object($class)) { |
|
119 | - return isset($class->{$property}) ? true : false; |
|
120 | - } else { |
|
121 | - // use reflection for < PHP 5.3 to get details using just the class name |
|
122 | - $reflector = new ReflectionClass($class); |
|
123 | - return $reflector->hasProperty($property); |
|
124 | - } |
|
125 | - } else { |
|
126 | - // or try regular property exists method which works as expected in PHP 5.3+ |
|
127 | - return property_exists($class, $property); |
|
128 | - } |
|
129 | - } |
|
102 | + /** |
|
103 | + * property_exists() with fallback for PHP versions < 5.3 |
|
104 | + * @access public |
|
105 | + * @param mixed object | string $class |
|
106 | + * @param string $property |
|
107 | + * @return boolean |
|
108 | + */ |
|
109 | + public static function has_property($class = null, $property = null) |
|
110 | + { |
|
111 | + // if $class or $property don't exist, then get out, cuz that would be like... fatal dude |
|
112 | + if (empty($class) || empty($property)) { |
|
113 | + return false; |
|
114 | + } |
|
115 | + // if your hosting company doesn't cut the mustard |
|
116 | + if (version_compare(PHP_VERSION, '5.3.0') < 0) { |
|
117 | + // just in case $class is an actual instantiated object |
|
118 | + if (is_object($class)) { |
|
119 | + return isset($class->{$property}) ? true : false; |
|
120 | + } else { |
|
121 | + // use reflection for < PHP 5.3 to get details using just the class name |
|
122 | + $reflector = new ReflectionClass($class); |
|
123 | + return $reflector->hasProperty($property); |
|
124 | + } |
|
125 | + } else { |
|
126 | + // or try regular property exists method which works as expected in PHP 5.3+ |
|
127 | + return property_exists($class, $property); |
|
128 | + } |
|
129 | + } |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | // if PHP version < 5.3 |
133 | 133 | if (! function_exists('get_called_class')) { |
134 | - /** |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - function get_called_class() |
|
138 | - { |
|
139 | - return EEH_Class_Tools::get_called_class(); |
|
140 | - } |
|
134 | + /** |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + function get_called_class() |
|
138 | + { |
|
139 | + return EEH_Class_Tools::get_called_class(); |
|
140 | + } |
|
141 | 141 | } |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | } elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) { |
30 | 30 | return $backtrace[3]['class']; |
31 | 31 | } elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) { |
32 | - if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) { |
|
32 | + if (self::$file_line == $backtrace[2]['file'].$backtrace[2]['line']) { |
|
33 | 33 | self::$i++; |
34 | 34 | } else { |
35 | 35 | self::$i = 0; |
36 | - self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line']; |
|
36 | + self::$file_line = $backtrace[2]['file'].$backtrace[2]['line']; |
|
37 | 37 | } |
38 | 38 | // was class method called via call_user_func ? |
39 | 39 | if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) { |
@@ -44,15 +44,15 @@ discard block |
||
44 | 44 | $prefix_chars = strpos($called_class, '_') + 1; |
45 | 45 | $prefix = substr($called_class, 0, $prefix_chars); |
46 | 46 | $classname = substr($called_class, $prefix_chars, strlen($called_class)); |
47 | - $classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname)))); |
|
47 | + $classname = $prefix.str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname)))); |
|
48 | 48 | return $classname; |
49 | 49 | } |
50 | 50 | } |
51 | 51 | } else { |
52 | 52 | $lines = file($backtrace[2]['file']); |
53 | - preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line']-1 ], $matches); |
|
54 | - if (isset($matches[1]) && isset($matches[1][ self::$i ])) { |
|
55 | - return $matches[1][ self::$i ]; |
|
53 | + preg_match_all('/([a-zA-Z0-9\_]+)::'.$backtrace[2]['function'].'/', $lines[$backtrace[2]['line'] - 1], $matches); |
|
54 | + if (isset($matches[1]) && isset($matches[1][self::$i])) { |
|
55 | + return $matches[1][self::$i]; |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | } |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | global $wp_filter; |
75 | 75 | $class_names = array(); |
76 | 76 | // are any callbacks registered for this hook ? |
77 | - if (isset($wp_filter[ $hook ])) { |
|
77 | + if (isset($wp_filter[$hook])) { |
|
78 | 78 | // loop thru all of the callbacks attached to the deprecated hookpoint |
79 | - foreach ($wp_filter[ $hook ] as $priority) { |
|
79 | + foreach ($wp_filter[$hook] as $priority) { |
|
80 | 80 | foreach ($priority as $callback) { |
81 | 81 | // is the callback a non-static class method ? |
82 | 82 | if (isset($callback['function']) && is_array($callback['function'])) { |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | } |
131 | 131 | |
132 | 132 | // if PHP version < 5.3 |
133 | -if (! function_exists('get_called_class')) { |
|
133 | +if ( ! function_exists('get_called_class')) { |
|
134 | 134 | /** |
135 | 135 | * @return string |
136 | 136 | */ |
@@ -14,152 +14,152 @@ |
||
14 | 14 | class EEH_Sideloader extends EEH_Base |
15 | 15 | { |
16 | 16 | |
17 | - private $_upload_to; |
|
18 | - private $_upload_from; |
|
19 | - private $_permissions; |
|
20 | - private $_new_file_name; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * constructor allows the user to set the properties on the sideloader on construct. However, there are also setters for doing so. |
|
25 | - * |
|
26 | - * @access public |
|
27 | - * @param array $init array fo initializing the sideloader if keys match the properties. |
|
28 | - */ |
|
29 | - public function __construct($init = array()) |
|
30 | - { |
|
31 | - $this->_init($init); |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * sets the properties for class either to defaults or using incoming initialization array |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @param array $init array on init (keys match properties others ignored) |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - private function _init($init) |
|
43 | - { |
|
44 | - $defaults = array( |
|
45 | - '_upload_to' => $this->_get_wp_uploads_dir(), |
|
46 | - '_upload_from' => '', |
|
47 | - '_permissions' => 0644, |
|
48 | - '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default' |
|
49 | - ); |
|
50 | - |
|
51 | - $props = array_merge($defaults, $init); |
|
52 | - |
|
53 | - foreach ($props as $key => $val) { |
|
54 | - if (EEH_Class_Tools::has_property($this, $key)) { |
|
55 | - $this->{$key} = $val; |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - // make sure we include the required wp file for needed functions |
|
60 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - // utilities |
|
65 | - private function _get_wp_uploads_dir() |
|
66 | - { |
|
67 | - } |
|
68 | - |
|
69 | - // setters |
|
70 | - public function set_upload_to($upload_to_folder) |
|
71 | - { |
|
72 | - $this->_upload_to = $upload_to_folder; |
|
73 | - } |
|
74 | - public function set_upload_from($upload_from_folder) |
|
75 | - { |
|
76 | - $this->_upload_from_folder = $upload_from_folder; |
|
77 | - } |
|
78 | - public function set_permissions($permissions) |
|
79 | - { |
|
80 | - $this->_permissions = $permissions; |
|
81 | - } |
|
82 | - public function set_new_file_name($new_file_name) |
|
83 | - { |
|
84 | - $this->_new_file_name = $new_file_name; |
|
85 | - } |
|
86 | - |
|
87 | - // getters |
|
88 | - public function get_upload_to() |
|
89 | - { |
|
90 | - return $this->_upload_to; |
|
91 | - } |
|
92 | - public function get_upload_from() |
|
93 | - { |
|
94 | - return $this->_upload_from; |
|
95 | - } |
|
96 | - public function get_permissions() |
|
97 | - { |
|
98 | - return $this->_permissions; |
|
99 | - } |
|
100 | - public function get_new_file_name() |
|
101 | - { |
|
102 | - return $this->_new_file_name; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - // upload methods |
|
107 | - public function sideload() |
|
108 | - { |
|
109 | - // setup temp dir |
|
110 | - $temp_file = wp_tempnam($this->_upload_from); |
|
111 | - |
|
112 | - if (!$temp_file) { |
|
113 | - EE_Error::add_error(__('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
114 | - return false; |
|
115 | - } |
|
116 | - |
|
117 | - do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
|
118 | - |
|
119 | - $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file); |
|
120 | - |
|
121 | - $response = wp_safe_remote_get($this->_upload_from, $wp_remote_args); |
|
122 | - |
|
123 | - if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { |
|
124 | - unlink($temp_file); |
|
125 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
126 | - EE_Error::add_error(sprintf(__('Unable to upload the file. Either the path given to upload from is incorrect, or something else happened. Here is the response returned:<br />%s<br />Here is the path given: %s', 'event_espresso'), var_export($response, true), $this->_upload_from), __FILE__, __FUNCTION__, __LINE__); |
|
127 | - } |
|
128 | - return false; |
|
129 | - } |
|
130 | - |
|
131 | - // possible md5 check |
|
132 | - $content_md5 = wp_remote_retrieve_header($response, 'content-md5'); |
|
133 | - if ($content_md5) { |
|
134 | - $md5_check = verify_file_md5($temp_file, $content_md5); |
|
135 | - if (is_wp_error($md5_check)) { |
|
136 | - unlink($temp_file); |
|
137 | - EE_Error::add_error($md5_check->get_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
138 | - return false; |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - $file = $temp_file; |
|
143 | - |
|
144 | - // now we have the file, let's get it in the right directory with the right name. |
|
145 | - $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this); |
|
146 | - |
|
147 | - // move file in |
|
148 | - if (false === @ rename($file, $path)) { |
|
149 | - unlink($temp_file); |
|
150 | - EE_Error::add_error(sprintf(__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'), $path), __FILE__, __FUNCTION__, __LINE__); |
|
151 | - return false; |
|
152 | - } |
|
153 | - |
|
154 | - // set permissions |
|
155 | - $permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this); |
|
156 | - chmod($path, $permissions); |
|
157 | - |
|
158 | - // that's it. let's allow for actions after file uploaded. |
|
159 | - do_action('AHEE__EE_Sideloader__sideload_after', $this, $path); |
|
160 | - |
|
161 | - // unlink tempfile |
|
162 | - @unlink($temp_file); |
|
163 | - return true; |
|
164 | - } |
|
17 | + private $_upload_to; |
|
18 | + private $_upload_from; |
|
19 | + private $_permissions; |
|
20 | + private $_new_file_name; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * constructor allows the user to set the properties on the sideloader on construct. However, there are also setters for doing so. |
|
25 | + * |
|
26 | + * @access public |
|
27 | + * @param array $init array fo initializing the sideloader if keys match the properties. |
|
28 | + */ |
|
29 | + public function __construct($init = array()) |
|
30 | + { |
|
31 | + $this->_init($init); |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * sets the properties for class either to defaults or using incoming initialization array |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @param array $init array on init (keys match properties others ignored) |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + private function _init($init) |
|
43 | + { |
|
44 | + $defaults = array( |
|
45 | + '_upload_to' => $this->_get_wp_uploads_dir(), |
|
46 | + '_upload_from' => '', |
|
47 | + '_permissions' => 0644, |
|
48 | + '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default' |
|
49 | + ); |
|
50 | + |
|
51 | + $props = array_merge($defaults, $init); |
|
52 | + |
|
53 | + foreach ($props as $key => $val) { |
|
54 | + if (EEH_Class_Tools::has_property($this, $key)) { |
|
55 | + $this->{$key} = $val; |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + // make sure we include the required wp file for needed functions |
|
60 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + // utilities |
|
65 | + private function _get_wp_uploads_dir() |
|
66 | + { |
|
67 | + } |
|
68 | + |
|
69 | + // setters |
|
70 | + public function set_upload_to($upload_to_folder) |
|
71 | + { |
|
72 | + $this->_upload_to = $upload_to_folder; |
|
73 | + } |
|
74 | + public function set_upload_from($upload_from_folder) |
|
75 | + { |
|
76 | + $this->_upload_from_folder = $upload_from_folder; |
|
77 | + } |
|
78 | + public function set_permissions($permissions) |
|
79 | + { |
|
80 | + $this->_permissions = $permissions; |
|
81 | + } |
|
82 | + public function set_new_file_name($new_file_name) |
|
83 | + { |
|
84 | + $this->_new_file_name = $new_file_name; |
|
85 | + } |
|
86 | + |
|
87 | + // getters |
|
88 | + public function get_upload_to() |
|
89 | + { |
|
90 | + return $this->_upload_to; |
|
91 | + } |
|
92 | + public function get_upload_from() |
|
93 | + { |
|
94 | + return $this->_upload_from; |
|
95 | + } |
|
96 | + public function get_permissions() |
|
97 | + { |
|
98 | + return $this->_permissions; |
|
99 | + } |
|
100 | + public function get_new_file_name() |
|
101 | + { |
|
102 | + return $this->_new_file_name; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + // upload methods |
|
107 | + public function sideload() |
|
108 | + { |
|
109 | + // setup temp dir |
|
110 | + $temp_file = wp_tempnam($this->_upload_from); |
|
111 | + |
|
112 | + if (!$temp_file) { |
|
113 | + EE_Error::add_error(__('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
114 | + return false; |
|
115 | + } |
|
116 | + |
|
117 | + do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
|
118 | + |
|
119 | + $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file); |
|
120 | + |
|
121 | + $response = wp_safe_remote_get($this->_upload_from, $wp_remote_args); |
|
122 | + |
|
123 | + if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { |
|
124 | + unlink($temp_file); |
|
125 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
126 | + EE_Error::add_error(sprintf(__('Unable to upload the file. Either the path given to upload from is incorrect, or something else happened. Here is the response returned:<br />%s<br />Here is the path given: %s', 'event_espresso'), var_export($response, true), $this->_upload_from), __FILE__, __FUNCTION__, __LINE__); |
|
127 | + } |
|
128 | + return false; |
|
129 | + } |
|
130 | + |
|
131 | + // possible md5 check |
|
132 | + $content_md5 = wp_remote_retrieve_header($response, 'content-md5'); |
|
133 | + if ($content_md5) { |
|
134 | + $md5_check = verify_file_md5($temp_file, $content_md5); |
|
135 | + if (is_wp_error($md5_check)) { |
|
136 | + unlink($temp_file); |
|
137 | + EE_Error::add_error($md5_check->get_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
138 | + return false; |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + $file = $temp_file; |
|
143 | + |
|
144 | + // now we have the file, let's get it in the right directory with the right name. |
|
145 | + $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this); |
|
146 | + |
|
147 | + // move file in |
|
148 | + if (false === @ rename($file, $path)) { |
|
149 | + unlink($temp_file); |
|
150 | + EE_Error::add_error(sprintf(__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'), $path), __FILE__, __FUNCTION__, __LINE__); |
|
151 | + return false; |
|
152 | + } |
|
153 | + |
|
154 | + // set permissions |
|
155 | + $permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this); |
|
156 | + chmod($path, $permissions); |
|
157 | + |
|
158 | + // that's it. let's allow for actions after file uploaded. |
|
159 | + do_action('AHEE__EE_Sideloader__sideload_after', $this, $path); |
|
160 | + |
|
161 | + // unlink tempfile |
|
162 | + @unlink($temp_file); |
|
163 | + return true; |
|
164 | + } |
|
165 | 165 | } //end EEH_Template class |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | '_upload_to' => $this->_get_wp_uploads_dir(), |
46 | 46 | '_upload_from' => '', |
47 | 47 | '_permissions' => 0644, |
48 | - '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default' |
|
48 | + '_new_file_name' => 'EE_Sideloader_'.uniqid().'.default' |
|
49 | 49 | ); |
50 | 50 | |
51 | 51 | $props = array_merge($defaults, $init); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | // make sure we include the required wp file for needed functions |
60 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
60 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | |
@@ -109,14 +109,14 @@ discard block |
||
109 | 109 | // setup temp dir |
110 | 110 | $temp_file = wp_tempnam($this->_upload_from); |
111 | 111 | |
112 | - if (!$temp_file) { |
|
112 | + if ( ! $temp_file) { |
|
113 | 113 | EE_Error::add_error(__('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
114 | 114 | return false; |
115 | 115 | } |
116 | 116 | |
117 | 117 | do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
118 | 118 | |
119 | - $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file); |
|
119 | + $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array('timeout' => 500, 'stream' => true, 'filename' => $temp_file), $this, $temp_file); |
|
120 | 120 | |
121 | 121 | $response = wp_safe_remote_get($this->_upload_from, $wp_remote_args); |
122 | 122 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $file = $temp_file; |
143 | 143 | |
144 | 144 | // now we have the file, let's get it in the right directory with the right name. |
145 | - $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this); |
|
145 | + $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to.$this->_new_file_name, $this); |
|
146 | 146 | |
147 | 147 | // move file in |
148 | 148 | if (false === @ rename($file, $path)) { |
@@ -21,202 +21,202 @@ |
||
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * assembles and returns the html structure for tabs |
|
26 | - * |
|
27 | - * @static |
|
28 | - * @param array $tabs_contents an array of the content for each tab [required] |
|
29 | - * @param array $tabs_names an unassociative array of names for each tab [optional] - if this isn't included then we use the indexes for $tabs_content as the tab names) |
|
30 | - * @param bool $small_tabs |
|
31 | - * @param bool $tabs_content |
|
32 | - * @return string the assembled html string containing the tabbed content for display. |
|
33 | - * @throws \EE_Error |
|
34 | - */ |
|
35 | - public static function display($tabs_contents, $tabs_names = array(), $small_tabs = true, $tabs_content = true) |
|
36 | - { |
|
37 | - |
|
38 | - // first check if $tabs_names is not empty then the count must match the count of $tabs_content otherwise we've got a problem houston |
|
39 | - if (!empty($tabs_names) && ( count((array) $tabs_names) != count((array) $tabs_content) )) { |
|
40 | - throw new EE_Error(__('The count for $tabs_names and $tabs_content does not match.', 'event_espresso')); |
|
41 | - } |
|
42 | - |
|
43 | - // make sure we've got incoming data setup properly |
|
44 | - $tabs = !empty($tabs_names) ? (array) $tabs_names : array_keys((array) $tabs_contents); |
|
45 | - $tabs_content = !empty($tabs_names) ? array_combine((array) $tabs_names, (array) $tabs_content) : $tabs_contents; |
|
46 | - |
|
47 | - $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n"; |
|
48 | - $all_tabs_content = ''; |
|
49 | - |
|
50 | - $index = 0; |
|
51 | - foreach ($tabs as $tab) { |
|
52 | - $active = $index === 0 ? true : false; |
|
53 | - $all_tabs .= self::tab($tab, $active); |
|
54 | - $all_tabs_content .= self::tab_content($tab, $tabs_content[ $tab ], $active); |
|
55 | - $index++; |
|
56 | - } |
|
57 | - /* |
|
24 | + /** |
|
25 | + * assembles and returns the html structure for tabs |
|
26 | + * |
|
27 | + * @static |
|
28 | + * @param array $tabs_contents an array of the content for each tab [required] |
|
29 | + * @param array $tabs_names an unassociative array of names for each tab [optional] - if this isn't included then we use the indexes for $tabs_content as the tab names) |
|
30 | + * @param bool $small_tabs |
|
31 | + * @param bool $tabs_content |
|
32 | + * @return string the assembled html string containing the tabbed content for display. |
|
33 | + * @throws \EE_Error |
|
34 | + */ |
|
35 | + public static function display($tabs_contents, $tabs_names = array(), $small_tabs = true, $tabs_content = true) |
|
36 | + { |
|
37 | + |
|
38 | + // first check if $tabs_names is not empty then the count must match the count of $tabs_content otherwise we've got a problem houston |
|
39 | + if (!empty($tabs_names) && ( count((array) $tabs_names) != count((array) $tabs_content) )) { |
|
40 | + throw new EE_Error(__('The count for $tabs_names and $tabs_content does not match.', 'event_espresso')); |
|
41 | + } |
|
42 | + |
|
43 | + // make sure we've got incoming data setup properly |
|
44 | + $tabs = !empty($tabs_names) ? (array) $tabs_names : array_keys((array) $tabs_contents); |
|
45 | + $tabs_content = !empty($tabs_names) ? array_combine((array) $tabs_names, (array) $tabs_content) : $tabs_contents; |
|
46 | + |
|
47 | + $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n"; |
|
48 | + $all_tabs_content = ''; |
|
49 | + |
|
50 | + $index = 0; |
|
51 | + foreach ($tabs as $tab) { |
|
52 | + $active = $index === 0 ? true : false; |
|
53 | + $all_tabs .= self::tab($tab, $active); |
|
54 | + $all_tabs_content .= self::tab_content($tab, $tabs_content[ $tab ], $active); |
|
55 | + $index++; |
|
56 | + } |
|
57 | + /* |
|
58 | 58 | sample content for testing |
59 | 59 | |
60 | 60 | $all_tabs .= '<a class="nav-tab" rel="ee-tab-anothertab" href="#anothertab">Another Tab</a>'; |
61 | 61 | $all_tabs_content .= '<div class="nav-tab-content hidden" id="ee-tab-anothertab">This is just some sample content to show another tab<div style="clear:both"></div></div>'; |
62 | 62 | //end sample content /**/ |
63 | 63 | |
64 | - $all_tabs .= '</h2>'; |
|
65 | - |
|
66 | - $tab_container_class = $small_tabs ? 'ee-nav-tabs ee-nav-tabs-small' : 'ee-nav-tabs'; |
|
67 | - |
|
68 | - return '<div class="'. $tab_container_class . '">' . "\n\t" . $all_tabs . $all_tabs_content . "\n" . '</div>'; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * display_admin_nav_tabs |
|
75 | - * this returns the properly formatted tab html for EE_Admin_Pages. |
|
76 | - * We are expecting an array of tabs in the following format |
|
77 | - * array( |
|
78 | - * 'nav_tab_name' => array( |
|
79 | - * 'url' => 'url for tab', |
|
80 | - * 'link_text' => 'tab text', |
|
81 | - * 'css_class' => 'tab class' //including the nav-tab-active class if its active |
|
82 | - * ) |
|
83 | - * ) |
|
84 | - * |
|
85 | - * @access public |
|
86 | - * @static |
|
87 | - * @param array $nav_tabs tab array for nav tabs |
|
88 | - * @return string |
|
89 | - * @throws \EE_Error |
|
90 | - */ |
|
91 | - public static function display_admin_nav_tabs($nav_tabs = array()) |
|
92 | - { |
|
93 | - if (empty($nav_tabs)) { |
|
94 | - throw new EE_Error(__('Nav Tabs cannot be generated because the tab array is missing', 'event_espresso')); |
|
95 | - } |
|
96 | - |
|
97 | - $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n"; |
|
98 | - foreach ($nav_tabs as $slug => $tab) { |
|
99 | - $all_tabs .= self::tab($slug, false, $tab['link_text'], $tab['url'], $tab['css_class']); |
|
100 | - } |
|
101 | - $all_tabs .= '</h2>'; |
|
102 | - return $all_tabs; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * this simply returns a single tab given a tab name & content |
|
107 | - * @param string $name name of tab |
|
108 | - * @param bool $active true=tab active, false=tab not active |
|
109 | - * @param bool|string $nice_name if string given then this value will be used for the tab link text. |
|
110 | - * @param bool|string $url If url given then tabs will be generated linking to the url. |
|
111 | - * @param bool|string $css If string given then the generated tab will include that as the class. |
|
112 | - * @return string html for tab |
|
113 | - */ |
|
114 | - private static function tab($name, $active = false, $nice_name = false, $url = false, $css = false) |
|
115 | - { |
|
116 | - $name = str_replace(' ', '-', $name); |
|
117 | - $class = $active ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
118 | - $class = $css ? $class . ' ' . $css : $class; |
|
119 | - $nice_name = $nice_name ? $nice_name : ucwords(preg_replace('/(-|_)/', ' ', $name)); |
|
120 | - $url = $url ? $url : '#' . $name; |
|
121 | - $tab = '<a class="' . $class . '" rel="ee-tab-' . $name . '" href="' . $url . '">' . $nice_name . '</a>' . "\n\t"; |
|
122 | - return $tab; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * this just returns the properly formatted tab content for our tab box. |
|
129 | - * |
|
130 | - * @param string $name name of tab (used for selector) |
|
131 | - * @param string $tab_content content of tab |
|
132 | - * @param bool $active |
|
133 | - * @return string html for content area |
|
134 | - */ |
|
135 | - private static function tab_content($name, $tab_content, $active = false) |
|
136 | - { |
|
137 | - $class = $active ? 'nav-tab-content' : 'nav-tab-content hidden'; |
|
138 | - $name = str_replace(' ', '-', $name); |
|
139 | - $content = "\t" . '<div class="'. $class . '" id="ee-tab-' . $name . '">' . "\n"; |
|
140 | - $content .= "\t" . $tab_content . "\n"; |
|
141 | - $content .= '<div style="clear:both"></div></div>'; |
|
142 | - return $content; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** HORIZONTAL TEXT LINKS **/ |
|
148 | - |
|
149 | - /** |
|
150 | - * This will take in an array of link items and spit out a formatted list of links that can be used to navigate to items. |
|
151 | - * There is a corresponding js file that can be loaded to dynamically display containers with the same id as the href -ref. |
|
152 | - * |
|
153 | - * @param array $item_array formatted array of items. Format: |
|
154 | - * array( |
|
155 | - * 'label' => __('localized label displayed'), |
|
156 | - * 'class' => 'class_for_item', |
|
157 | - * 'href' => '#some_item_id', //url/bookmark for item. If you include a bookmark the js will used this to show the container div. |
|
158 | - * 'title' => __('localized text for the title attribute of the link'), |
|
159 | - * 'slug' => 'slug_used_for_reference' |
|
160 | - * ) |
|
161 | - * @param string $container_class class used for main container |
|
162 | - * @param string $sep you can add in what is used as a separator between each link (or leave blank for none) |
|
163 | - * @param string $default You can include a string for the item that will receive the "item_display" class for the js. |
|
164 | - * @return string a html snippet of of all the formatted link elements. |
|
165 | - */ |
|
166 | - public static function tab_text_links($item_array, $container_class = '', $sep = '|', $default = '') |
|
167 | - { |
|
168 | - $item_array = apply_filters('FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class); |
|
169 | - if (!is_array($item_array) || empty($item_array)) { |
|
170 | - return false; // get out we don't have even the basic thing we need! |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - $defaults = array( |
|
175 | - 'label' => __('Item', 'event_espresso'), |
|
176 | - 'class' => '', |
|
177 | - 'href' => '', |
|
178 | - 'title' => esc_attr__('Link for Item', 'event_espresso'), |
|
179 | - 'slug' => 'item_slug' |
|
180 | - ); |
|
181 | - $container_class = !empty($container_class) ? 'ee-text-links ' . $container_class : 'ee-text-links'; |
|
182 | - $list = '<ul class="' . $container_class . '">'; |
|
183 | - |
|
184 | - $ci = 1; |
|
185 | - foreach ($item_array as $item) { |
|
186 | - $item = wp_parse_args($item, $defaults); |
|
187 | - $item['class'] = !empty($default) && $default == $item['slug'] ? 'item_display ' . $item['class'] : $item['class']; |
|
188 | - $list .= self::_text_link_item($item); |
|
189 | - if (!empty($sep) && $ci != count($item_array)) { |
|
190 | - $list .= self::_text_link_item($sep); |
|
191 | - } |
|
192 | - $ci++; |
|
193 | - } |
|
194 | - |
|
195 | - $list .= '</ul>'; |
|
196 | - return $list; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - private static function _text_link_item($item) |
|
202 | - { |
|
203 | - // if this isn't an array then we're doing a separator |
|
204 | - if (!is_array($item)) { |
|
205 | - $label = $item; |
|
206 | - $class = 'ee-text-link-sep'; |
|
207 | - $href = ''; |
|
208 | - $title = ''; |
|
209 | - } else { |
|
210 | - extract($item); |
|
211 | - } |
|
212 | - |
|
213 | - $class = $class != 'ee-text-link-sep' ? 'class="ee-text-link-li ' . $class . '"' : 'class="ee-text-link-sep"'; |
|
214 | - |
|
215 | - $content = '<li ' . $class . '>'; |
|
216 | - $content .= !empty($href) ? '<a class="ee-text-link" href="#' . $href . '" title="' . $title . '">' : ''; |
|
217 | - $content .= $label; |
|
218 | - $content .= !empty($href) ? '</a>' : ''; |
|
219 | - $content .= '</li>'; |
|
220 | - return $content; |
|
221 | - } |
|
64 | + $all_tabs .= '</h2>'; |
|
65 | + |
|
66 | + $tab_container_class = $small_tabs ? 'ee-nav-tabs ee-nav-tabs-small' : 'ee-nav-tabs'; |
|
67 | + |
|
68 | + return '<div class="'. $tab_container_class . '">' . "\n\t" . $all_tabs . $all_tabs_content . "\n" . '</div>'; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * display_admin_nav_tabs |
|
75 | + * this returns the properly formatted tab html for EE_Admin_Pages. |
|
76 | + * We are expecting an array of tabs in the following format |
|
77 | + * array( |
|
78 | + * 'nav_tab_name' => array( |
|
79 | + * 'url' => 'url for tab', |
|
80 | + * 'link_text' => 'tab text', |
|
81 | + * 'css_class' => 'tab class' //including the nav-tab-active class if its active |
|
82 | + * ) |
|
83 | + * ) |
|
84 | + * |
|
85 | + * @access public |
|
86 | + * @static |
|
87 | + * @param array $nav_tabs tab array for nav tabs |
|
88 | + * @return string |
|
89 | + * @throws \EE_Error |
|
90 | + */ |
|
91 | + public static function display_admin_nav_tabs($nav_tabs = array()) |
|
92 | + { |
|
93 | + if (empty($nav_tabs)) { |
|
94 | + throw new EE_Error(__('Nav Tabs cannot be generated because the tab array is missing', 'event_espresso')); |
|
95 | + } |
|
96 | + |
|
97 | + $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n"; |
|
98 | + foreach ($nav_tabs as $slug => $tab) { |
|
99 | + $all_tabs .= self::tab($slug, false, $tab['link_text'], $tab['url'], $tab['css_class']); |
|
100 | + } |
|
101 | + $all_tabs .= '</h2>'; |
|
102 | + return $all_tabs; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * this simply returns a single tab given a tab name & content |
|
107 | + * @param string $name name of tab |
|
108 | + * @param bool $active true=tab active, false=tab not active |
|
109 | + * @param bool|string $nice_name if string given then this value will be used for the tab link text. |
|
110 | + * @param bool|string $url If url given then tabs will be generated linking to the url. |
|
111 | + * @param bool|string $css If string given then the generated tab will include that as the class. |
|
112 | + * @return string html for tab |
|
113 | + */ |
|
114 | + private static function tab($name, $active = false, $nice_name = false, $url = false, $css = false) |
|
115 | + { |
|
116 | + $name = str_replace(' ', '-', $name); |
|
117 | + $class = $active ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
118 | + $class = $css ? $class . ' ' . $css : $class; |
|
119 | + $nice_name = $nice_name ? $nice_name : ucwords(preg_replace('/(-|_)/', ' ', $name)); |
|
120 | + $url = $url ? $url : '#' . $name; |
|
121 | + $tab = '<a class="' . $class . '" rel="ee-tab-' . $name . '" href="' . $url . '">' . $nice_name . '</a>' . "\n\t"; |
|
122 | + return $tab; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * this just returns the properly formatted tab content for our tab box. |
|
129 | + * |
|
130 | + * @param string $name name of tab (used for selector) |
|
131 | + * @param string $tab_content content of tab |
|
132 | + * @param bool $active |
|
133 | + * @return string html for content area |
|
134 | + */ |
|
135 | + private static function tab_content($name, $tab_content, $active = false) |
|
136 | + { |
|
137 | + $class = $active ? 'nav-tab-content' : 'nav-tab-content hidden'; |
|
138 | + $name = str_replace(' ', '-', $name); |
|
139 | + $content = "\t" . '<div class="'. $class . '" id="ee-tab-' . $name . '">' . "\n"; |
|
140 | + $content .= "\t" . $tab_content . "\n"; |
|
141 | + $content .= '<div style="clear:both"></div></div>'; |
|
142 | + return $content; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** HORIZONTAL TEXT LINKS **/ |
|
148 | + |
|
149 | + /** |
|
150 | + * This will take in an array of link items and spit out a formatted list of links that can be used to navigate to items. |
|
151 | + * There is a corresponding js file that can be loaded to dynamically display containers with the same id as the href -ref. |
|
152 | + * |
|
153 | + * @param array $item_array formatted array of items. Format: |
|
154 | + * array( |
|
155 | + * 'label' => __('localized label displayed'), |
|
156 | + * 'class' => 'class_for_item', |
|
157 | + * 'href' => '#some_item_id', //url/bookmark for item. If you include a bookmark the js will used this to show the container div. |
|
158 | + * 'title' => __('localized text for the title attribute of the link'), |
|
159 | + * 'slug' => 'slug_used_for_reference' |
|
160 | + * ) |
|
161 | + * @param string $container_class class used for main container |
|
162 | + * @param string $sep you can add in what is used as a separator between each link (or leave blank for none) |
|
163 | + * @param string $default You can include a string for the item that will receive the "item_display" class for the js. |
|
164 | + * @return string a html snippet of of all the formatted link elements. |
|
165 | + */ |
|
166 | + public static function tab_text_links($item_array, $container_class = '', $sep = '|', $default = '') |
|
167 | + { |
|
168 | + $item_array = apply_filters('FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class); |
|
169 | + if (!is_array($item_array) || empty($item_array)) { |
|
170 | + return false; // get out we don't have even the basic thing we need! |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + $defaults = array( |
|
175 | + 'label' => __('Item', 'event_espresso'), |
|
176 | + 'class' => '', |
|
177 | + 'href' => '', |
|
178 | + 'title' => esc_attr__('Link for Item', 'event_espresso'), |
|
179 | + 'slug' => 'item_slug' |
|
180 | + ); |
|
181 | + $container_class = !empty($container_class) ? 'ee-text-links ' . $container_class : 'ee-text-links'; |
|
182 | + $list = '<ul class="' . $container_class . '">'; |
|
183 | + |
|
184 | + $ci = 1; |
|
185 | + foreach ($item_array as $item) { |
|
186 | + $item = wp_parse_args($item, $defaults); |
|
187 | + $item['class'] = !empty($default) && $default == $item['slug'] ? 'item_display ' . $item['class'] : $item['class']; |
|
188 | + $list .= self::_text_link_item($item); |
|
189 | + if (!empty($sep) && $ci != count($item_array)) { |
|
190 | + $list .= self::_text_link_item($sep); |
|
191 | + } |
|
192 | + $ci++; |
|
193 | + } |
|
194 | + |
|
195 | + $list .= '</ul>'; |
|
196 | + return $list; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + private static function _text_link_item($item) |
|
202 | + { |
|
203 | + // if this isn't an array then we're doing a separator |
|
204 | + if (!is_array($item)) { |
|
205 | + $label = $item; |
|
206 | + $class = 'ee-text-link-sep'; |
|
207 | + $href = ''; |
|
208 | + $title = ''; |
|
209 | + } else { |
|
210 | + extract($item); |
|
211 | + } |
|
212 | + |
|
213 | + $class = $class != 'ee-text-link-sep' ? 'class="ee-text-link-li ' . $class . '"' : 'class="ee-text-link-sep"'; |
|
214 | + |
|
215 | + $content = '<li ' . $class . '>'; |
|
216 | + $content .= !empty($href) ? '<a class="ee-text-link" href="#' . $href . '" title="' . $title . '">' : ''; |
|
217 | + $content .= $label; |
|
218 | + $content .= !empty($href) ? '</a>' : ''; |
|
219 | + $content .= '</li>'; |
|
220 | + return $content; |
|
221 | + } |
|
222 | 222 | } |
@@ -36,22 +36,22 @@ discard block |
||
36 | 36 | { |
37 | 37 | |
38 | 38 | // first check if $tabs_names is not empty then the count must match the count of $tabs_content otherwise we've got a problem houston |
39 | - if (!empty($tabs_names) && ( count((array) $tabs_names) != count((array) $tabs_content) )) { |
|
39 | + if ( ! empty($tabs_names) && (count((array) $tabs_names) != count((array) $tabs_content))) { |
|
40 | 40 | throw new EE_Error(__('The count for $tabs_names and $tabs_content does not match.', 'event_espresso')); |
41 | 41 | } |
42 | 42 | |
43 | 43 | // make sure we've got incoming data setup properly |
44 | - $tabs = !empty($tabs_names) ? (array) $tabs_names : array_keys((array) $tabs_contents); |
|
45 | - $tabs_content = !empty($tabs_names) ? array_combine((array) $tabs_names, (array) $tabs_content) : $tabs_contents; |
|
44 | + $tabs = ! empty($tabs_names) ? (array) $tabs_names : array_keys((array) $tabs_contents); |
|
45 | + $tabs_content = ! empty($tabs_names) ? array_combine((array) $tabs_names, (array) $tabs_content) : $tabs_contents; |
|
46 | 46 | |
47 | - $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n"; |
|
47 | + $all_tabs = '<h2 class="nav-tab-wrapper">'."\n"; |
|
48 | 48 | $all_tabs_content = ''; |
49 | 49 | |
50 | 50 | $index = 0; |
51 | 51 | foreach ($tabs as $tab) { |
52 | 52 | $active = $index === 0 ? true : false; |
53 | 53 | $all_tabs .= self::tab($tab, $active); |
54 | - $all_tabs_content .= self::tab_content($tab, $tabs_content[ $tab ], $active); |
|
54 | + $all_tabs_content .= self::tab_content($tab, $tabs_content[$tab], $active); |
|
55 | 55 | $index++; |
56 | 56 | } |
57 | 57 | /* |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | $tab_container_class = $small_tabs ? 'ee-nav-tabs ee-nav-tabs-small' : 'ee-nav-tabs'; |
67 | 67 | |
68 | - return '<div class="'. $tab_container_class . '">' . "\n\t" . $all_tabs . $all_tabs_content . "\n" . '</div>'; |
|
68 | + return '<div class="'.$tab_container_class.'">'."\n\t".$all_tabs.$all_tabs_content."\n".'</div>'; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | throw new EE_Error(__('Nav Tabs cannot be generated because the tab array is missing', 'event_espresso')); |
95 | 95 | } |
96 | 96 | |
97 | - $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n"; |
|
97 | + $all_tabs = '<h2 class="nav-tab-wrapper">'."\n"; |
|
98 | 98 | foreach ($nav_tabs as $slug => $tab) { |
99 | 99 | $all_tabs .= self::tab($slug, false, $tab['link_text'], $tab['url'], $tab['css_class']); |
100 | 100 | } |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | { |
116 | 116 | $name = str_replace(' ', '-', $name); |
117 | 117 | $class = $active ? 'nav-tab nav-tab-active' : 'nav-tab'; |
118 | - $class = $css ? $class . ' ' . $css : $class; |
|
118 | + $class = $css ? $class.' '.$css : $class; |
|
119 | 119 | $nice_name = $nice_name ? $nice_name : ucwords(preg_replace('/(-|_)/', ' ', $name)); |
120 | - $url = $url ? $url : '#' . $name; |
|
121 | - $tab = '<a class="' . $class . '" rel="ee-tab-' . $name . '" href="' . $url . '">' . $nice_name . '</a>' . "\n\t"; |
|
120 | + $url = $url ? $url : '#'.$name; |
|
121 | + $tab = '<a class="'.$class.'" rel="ee-tab-'.$name.'" href="'.$url.'">'.$nice_name.'</a>'."\n\t"; |
|
122 | 122 | return $tab; |
123 | 123 | } |
124 | 124 | |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | { |
137 | 137 | $class = $active ? 'nav-tab-content' : 'nav-tab-content hidden'; |
138 | 138 | $name = str_replace(' ', '-', $name); |
139 | - $content = "\t" . '<div class="'. $class . '" id="ee-tab-' . $name . '">' . "\n"; |
|
140 | - $content .= "\t" . $tab_content . "\n"; |
|
139 | + $content = "\t".'<div class="'.$class.'" id="ee-tab-'.$name.'">'."\n"; |
|
140 | + $content .= "\t".$tab_content."\n"; |
|
141 | 141 | $content .= '<div style="clear:both"></div></div>'; |
142 | 142 | return $content; |
143 | 143 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | public static function tab_text_links($item_array, $container_class = '', $sep = '|', $default = '') |
167 | 167 | { |
168 | 168 | $item_array = apply_filters('FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class); |
169 | - if (!is_array($item_array) || empty($item_array)) { |
|
169 | + if ( ! is_array($item_array) || empty($item_array)) { |
|
170 | 170 | return false; // get out we don't have even the basic thing we need! |
171 | 171 | } |
172 | 172 | |
@@ -178,15 +178,15 @@ discard block |
||
178 | 178 | 'title' => esc_attr__('Link for Item', 'event_espresso'), |
179 | 179 | 'slug' => 'item_slug' |
180 | 180 | ); |
181 | - $container_class = !empty($container_class) ? 'ee-text-links ' . $container_class : 'ee-text-links'; |
|
182 | - $list = '<ul class="' . $container_class . '">'; |
|
181 | + $container_class = ! empty($container_class) ? 'ee-text-links '.$container_class : 'ee-text-links'; |
|
182 | + $list = '<ul class="'.$container_class.'">'; |
|
183 | 183 | |
184 | 184 | $ci = 1; |
185 | 185 | foreach ($item_array as $item) { |
186 | 186 | $item = wp_parse_args($item, $defaults); |
187 | - $item['class'] = !empty($default) && $default == $item['slug'] ? 'item_display ' . $item['class'] : $item['class']; |
|
187 | + $item['class'] = ! empty($default) && $default == $item['slug'] ? 'item_display '.$item['class'] : $item['class']; |
|
188 | 188 | $list .= self::_text_link_item($item); |
189 | - if (!empty($sep) && $ci != count($item_array)) { |
|
189 | + if ( ! empty($sep) && $ci != count($item_array)) { |
|
190 | 190 | $list .= self::_text_link_item($sep); |
191 | 191 | } |
192 | 192 | $ci++; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | private static function _text_link_item($item) |
202 | 202 | { |
203 | 203 | // if this isn't an array then we're doing a separator |
204 | - if (!is_array($item)) { |
|
204 | + if ( ! is_array($item)) { |
|
205 | 205 | $label = $item; |
206 | 206 | $class = 'ee-text-link-sep'; |
207 | 207 | $href = ''; |
@@ -210,12 +210,12 @@ discard block |
||
210 | 210 | extract($item); |
211 | 211 | } |
212 | 212 | |
213 | - $class = $class != 'ee-text-link-sep' ? 'class="ee-text-link-li ' . $class . '"' : 'class="ee-text-link-sep"'; |
|
213 | + $class = $class != 'ee-text-link-sep' ? 'class="ee-text-link-li '.$class.'"' : 'class="ee-text-link-sep"'; |
|
214 | 214 | |
215 | - $content = '<li ' . $class . '>'; |
|
216 | - $content .= !empty($href) ? '<a class="ee-text-link" href="#' . $href . '" title="' . $title . '">' : ''; |
|
215 | + $content = '<li '.$class.'>'; |
|
216 | + $content .= ! empty($href) ? '<a class="ee-text-link" href="#'.$href.'" title="'.$title.'">' : ''; |
|
217 | 217 | $content .= $label; |
218 | - $content .= !empty($href) ? '</a>' : ''; |
|
218 | + $content .= ! empty($href) ? '</a>' : ''; |
|
219 | 219 | $content .= '</li>'; |
220 | 220 | return $content; |
221 | 221 | } |
@@ -12,221 +12,221 @@ |
||
12 | 12 | class EEH_Money extends EEH_Base |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * This removes all localized money formatting from the incoming value |
|
17 | - * Note: uses this site's currency settings for deciding what is considered a |
|
18 | - * "thousands separator" (usually the character "," ) |
|
19 | - * and what is a "decimal mark" (usually the character ".") |
|
20 | - * |
|
21 | - * @param int|float|string $money_value |
|
22 | - * @param string $CNT_ISO |
|
23 | - * @return float |
|
24 | - * @throws EE_Error |
|
25 | - */ |
|
26 | - public static function strip_localized_money_formatting($money_value, $CNT_ISO = '') |
|
27 | - { |
|
28 | - $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
29 | - $money_value = str_replace( |
|
30 | - array( |
|
31 | - $currency_config->thsnds, |
|
32 | - $currency_config->dec_mrk, |
|
33 | - ), |
|
34 | - array( |
|
35 | - '', // remove thousands separator |
|
36 | - '.', // convert decimal mark to what PHP expects |
|
37 | - ), |
|
38 | - $money_value |
|
39 | - ); |
|
40 | - $money_value = filter_var( |
|
41 | - $money_value, |
|
42 | - FILTER_SANITIZE_NUMBER_FLOAT, |
|
43 | - FILTER_FLAG_ALLOW_FRACTION |
|
44 | - ); |
|
45 | - return $money_value; |
|
46 | - } |
|
15 | + /** |
|
16 | + * This removes all localized money formatting from the incoming value |
|
17 | + * Note: uses this site's currency settings for deciding what is considered a |
|
18 | + * "thousands separator" (usually the character "," ) |
|
19 | + * and what is a "decimal mark" (usually the character ".") |
|
20 | + * |
|
21 | + * @param int|float|string $money_value |
|
22 | + * @param string $CNT_ISO |
|
23 | + * @return float |
|
24 | + * @throws EE_Error |
|
25 | + */ |
|
26 | + public static function strip_localized_money_formatting($money_value, $CNT_ISO = '') |
|
27 | + { |
|
28 | + $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
29 | + $money_value = str_replace( |
|
30 | + array( |
|
31 | + $currency_config->thsnds, |
|
32 | + $currency_config->dec_mrk, |
|
33 | + ), |
|
34 | + array( |
|
35 | + '', // remove thousands separator |
|
36 | + '.', // convert decimal mark to what PHP expects |
|
37 | + ), |
|
38 | + $money_value |
|
39 | + ); |
|
40 | + $money_value = filter_var( |
|
41 | + $money_value, |
|
42 | + FILTER_SANITIZE_NUMBER_FLOAT, |
|
43 | + FILTER_FLAG_ALLOW_FRACTION |
|
44 | + ); |
|
45 | + return $money_value; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * This converts an incoming localized money value into a standard float item (to three decimal places) |
|
51 | - * Only use this if you know the $money_value follows your currency configuration's |
|
52 | - * settings. Note: this uses this site's currency settings for deciding what is considered a |
|
53 | - * "thousands separator" (usually the character "," ) |
|
54 | - * and what is a "decimal mark" (usually the character ".") |
|
55 | - * |
|
56 | - * @param int|string $money_value |
|
57 | - * @return float |
|
58 | - * @throws EE_Error |
|
59 | - */ |
|
60 | - public static function convert_to_float_from_localized_money($money_value) |
|
61 | - { |
|
62 | - // float it! and round to three decimal places |
|
63 | - return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3); |
|
64 | - } |
|
49 | + /** |
|
50 | + * This converts an incoming localized money value into a standard float item (to three decimal places) |
|
51 | + * Only use this if you know the $money_value follows your currency configuration's |
|
52 | + * settings. Note: this uses this site's currency settings for deciding what is considered a |
|
53 | + * "thousands separator" (usually the character "," ) |
|
54 | + * and what is a "decimal mark" (usually the character ".") |
|
55 | + * |
|
56 | + * @param int|string $money_value |
|
57 | + * @return float |
|
58 | + * @throws EE_Error |
|
59 | + */ |
|
60 | + public static function convert_to_float_from_localized_money($money_value) |
|
61 | + { |
|
62 | + // float it! and round to three decimal places |
|
63 | + return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * For comparing floats. Default operator is '=', but see the $operator below for all options. |
|
69 | - * This should be used to compare floats instead of normal '==' because floats |
|
70 | - * are inherently imprecise, and so you can sometimes have two floats that appear to be identical |
|
71 | - * but actually differ by 0.00000001. |
|
72 | - * |
|
73 | - * @see http://biostall.com/php-function-to-compare-floating-point-numbers |
|
74 | - * @param float $float1 |
|
75 | - * @param float $float2 |
|
76 | - * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne |
|
77 | - * @return bool whether the equation is true or false |
|
78 | - * @throws EE_Error |
|
79 | - */ |
|
80 | - public static function compare_floats($float1, $float2, $operator = '=') |
|
81 | - { |
|
82 | - // Check numbers to 5 digits of precision |
|
83 | - $epsilon = 0.00001; |
|
84 | - $float1 = (float) $float1; |
|
85 | - $float2 = (float) $float2; |
|
86 | - switch ($operator) { |
|
87 | - // equal |
|
88 | - case "=": |
|
89 | - case "==": |
|
90 | - case "===": |
|
91 | - case "eq": |
|
92 | - if (abs($float1 - $float2) < $epsilon) { |
|
93 | - return true; |
|
94 | - } |
|
95 | - break; |
|
96 | - // less than |
|
97 | - case "<": |
|
98 | - case "lt": |
|
99 | - if (abs($float1 - $float2) < $epsilon) { |
|
100 | - return false; |
|
101 | - } else { |
|
102 | - if ($float1 < $float2) { |
|
103 | - return true; |
|
104 | - } |
|
105 | - } |
|
106 | - break; |
|
107 | - // less than or equal |
|
108 | - case "<=": |
|
109 | - case "lte": |
|
110 | - if (self::compare_floats($float1, $float2, '<') || self::compare_floats($float1, $float2, '=')) { |
|
111 | - return true; |
|
112 | - } |
|
113 | - break; |
|
114 | - // greater than |
|
115 | - case ">": |
|
116 | - case "gt": |
|
117 | - if (abs($float1 - $float2) < $epsilon) { |
|
118 | - return false; |
|
119 | - } else { |
|
120 | - if ($float1 > $float2) { |
|
121 | - return true; |
|
122 | - } |
|
123 | - } |
|
124 | - break; |
|
125 | - // greater than or equal |
|
126 | - case ">=": |
|
127 | - case "gte": |
|
128 | - if (self::compare_floats($float1, $float2, '>') || self::compare_floats($float1, $float2, '=')) { |
|
129 | - return true; |
|
130 | - } |
|
131 | - break; |
|
132 | - case "<>": |
|
133 | - case "!=": |
|
134 | - case "ne": |
|
135 | - if (abs($float1 - $float2) > $epsilon) { |
|
136 | - return true; |
|
137 | - } |
|
138 | - break; |
|
139 | - default: |
|
140 | - throw new EE_Error( |
|
141 | - sprintf( |
|
142 | - __( |
|
143 | - "Unknown operator %s in EEH_Money::compare_floats()", |
|
144 | - 'event_espresso' |
|
145 | - ), |
|
146 | - $operator |
|
147 | - ) |
|
148 | - ); |
|
149 | - } |
|
150 | - return false; |
|
151 | - } |
|
67 | + /** |
|
68 | + * For comparing floats. Default operator is '=', but see the $operator below for all options. |
|
69 | + * This should be used to compare floats instead of normal '==' because floats |
|
70 | + * are inherently imprecise, and so you can sometimes have two floats that appear to be identical |
|
71 | + * but actually differ by 0.00000001. |
|
72 | + * |
|
73 | + * @see http://biostall.com/php-function-to-compare-floating-point-numbers |
|
74 | + * @param float $float1 |
|
75 | + * @param float $float2 |
|
76 | + * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne |
|
77 | + * @return bool whether the equation is true or false |
|
78 | + * @throws EE_Error |
|
79 | + */ |
|
80 | + public static function compare_floats($float1, $float2, $operator = '=') |
|
81 | + { |
|
82 | + // Check numbers to 5 digits of precision |
|
83 | + $epsilon = 0.00001; |
|
84 | + $float1 = (float) $float1; |
|
85 | + $float2 = (float) $float2; |
|
86 | + switch ($operator) { |
|
87 | + // equal |
|
88 | + case "=": |
|
89 | + case "==": |
|
90 | + case "===": |
|
91 | + case "eq": |
|
92 | + if (abs($float1 - $float2) < $epsilon) { |
|
93 | + return true; |
|
94 | + } |
|
95 | + break; |
|
96 | + // less than |
|
97 | + case "<": |
|
98 | + case "lt": |
|
99 | + if (abs($float1 - $float2) < $epsilon) { |
|
100 | + return false; |
|
101 | + } else { |
|
102 | + if ($float1 < $float2) { |
|
103 | + return true; |
|
104 | + } |
|
105 | + } |
|
106 | + break; |
|
107 | + // less than or equal |
|
108 | + case "<=": |
|
109 | + case "lte": |
|
110 | + if (self::compare_floats($float1, $float2, '<') || self::compare_floats($float1, $float2, '=')) { |
|
111 | + return true; |
|
112 | + } |
|
113 | + break; |
|
114 | + // greater than |
|
115 | + case ">": |
|
116 | + case "gt": |
|
117 | + if (abs($float1 - $float2) < $epsilon) { |
|
118 | + return false; |
|
119 | + } else { |
|
120 | + if ($float1 > $float2) { |
|
121 | + return true; |
|
122 | + } |
|
123 | + } |
|
124 | + break; |
|
125 | + // greater than or equal |
|
126 | + case ">=": |
|
127 | + case "gte": |
|
128 | + if (self::compare_floats($float1, $float2, '>') || self::compare_floats($float1, $float2, '=')) { |
|
129 | + return true; |
|
130 | + } |
|
131 | + break; |
|
132 | + case "<>": |
|
133 | + case "!=": |
|
134 | + case "ne": |
|
135 | + if (abs($float1 - $float2) > $epsilon) { |
|
136 | + return true; |
|
137 | + } |
|
138 | + break; |
|
139 | + default: |
|
140 | + throw new EE_Error( |
|
141 | + sprintf( |
|
142 | + __( |
|
143 | + "Unknown operator %s in EEH_Money::compare_floats()", |
|
144 | + 'event_espresso' |
|
145 | + ), |
|
146 | + $operator |
|
147 | + ) |
|
148 | + ); |
|
149 | + } |
|
150 | + return false; |
|
151 | + } |
|
152 | 152 | |
153 | 153 | |
154 | - /** |
|
155 | - * This returns a localized format string suitable for jQplot. |
|
156 | - * |
|
157 | - * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
158 | - * Otherwise will use currency settings for current active country on site. |
|
159 | - * @return string |
|
160 | - * @throws EE_Error |
|
161 | - */ |
|
162 | - public static function get_format_for_jqplot($CNT_ISO = '') |
|
163 | - { |
|
164 | - // default format |
|
165 | - $format = 'f'; |
|
166 | - $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
167 | - // first get the decimal place and number of places |
|
168 | - $format = "%'." . $currency_config->dec_plc . $format; |
|
169 | - // currency symbol on right side. |
|
170 | - $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
171 | - return $format; |
|
172 | - } |
|
154 | + /** |
|
155 | + * This returns a localized format string suitable for jQplot. |
|
156 | + * |
|
157 | + * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
158 | + * Otherwise will use currency settings for current active country on site. |
|
159 | + * @return string |
|
160 | + * @throws EE_Error |
|
161 | + */ |
|
162 | + public static function get_format_for_jqplot($CNT_ISO = '') |
|
163 | + { |
|
164 | + // default format |
|
165 | + $format = 'f'; |
|
166 | + $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
167 | + // first get the decimal place and number of places |
|
168 | + $format = "%'." . $currency_config->dec_plc . $format; |
|
169 | + // currency symbol on right side. |
|
170 | + $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
171 | + return $format; |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | - /** |
|
176 | - * This returns a localized format string suitable for usage with the Google Charts API format param. |
|
177 | - * |
|
178 | - * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
179 | - * Otherwise will use currency settings for current active country on site. |
|
180 | - * Note: GoogleCharts uses ICU pattern set |
|
181 | - * (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) |
|
182 | - * @return string |
|
183 | - * @throws EE_Error |
|
184 | - */ |
|
185 | - public static function get_format_for_google_charts($CNT_ISO = '') |
|
186 | - { |
|
187 | - $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
188 | - $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0'); |
|
189 | - // first get the decimal place and number of places |
|
190 | - $format = '#,##0.' . $decimal_places_placeholder; |
|
191 | - // currency symbol on right side. |
|
192 | - $format = $currency_config->sign_b4 |
|
193 | - ? $currency_config->sign . $format |
|
194 | - : $format |
|
195 | - . $currency_config->sign; |
|
196 | - $formatterObject = array( |
|
197 | - 'decimalSymbol' => $currency_config->dec_mrk, |
|
198 | - 'groupingSymbol' => $currency_config->thsnds, |
|
199 | - 'fractionDigits' => $currency_config->dec_plc, |
|
200 | - ); |
|
201 | - if ($currency_config->sign_b4) { |
|
202 | - $formatterObject['prefix'] = $currency_config->sign; |
|
203 | - } else { |
|
204 | - $formatterObject['suffix'] = $currency_config->sign; |
|
205 | - } |
|
206 | - return array( |
|
207 | - 'format' => $format, |
|
208 | - 'formatterObject' => $formatterObject, |
|
209 | - ); |
|
210 | - } |
|
175 | + /** |
|
176 | + * This returns a localized format string suitable for usage with the Google Charts API format param. |
|
177 | + * |
|
178 | + * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
179 | + * Otherwise will use currency settings for current active country on site. |
|
180 | + * Note: GoogleCharts uses ICU pattern set |
|
181 | + * (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) |
|
182 | + * @return string |
|
183 | + * @throws EE_Error |
|
184 | + */ |
|
185 | + public static function get_format_for_google_charts($CNT_ISO = '') |
|
186 | + { |
|
187 | + $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
188 | + $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0'); |
|
189 | + // first get the decimal place and number of places |
|
190 | + $format = '#,##0.' . $decimal_places_placeholder; |
|
191 | + // currency symbol on right side. |
|
192 | + $format = $currency_config->sign_b4 |
|
193 | + ? $currency_config->sign . $format |
|
194 | + : $format |
|
195 | + . $currency_config->sign; |
|
196 | + $formatterObject = array( |
|
197 | + 'decimalSymbol' => $currency_config->dec_mrk, |
|
198 | + 'groupingSymbol' => $currency_config->thsnds, |
|
199 | + 'fractionDigits' => $currency_config->dec_plc, |
|
200 | + ); |
|
201 | + if ($currency_config->sign_b4) { |
|
202 | + $formatterObject['prefix'] = $currency_config->sign; |
|
203 | + } else { |
|
204 | + $formatterObject['suffix'] = $currency_config->sign; |
|
205 | + } |
|
206 | + return array( |
|
207 | + 'format' => $format, |
|
208 | + 'formatterObject' => $formatterObject, |
|
209 | + ); |
|
210 | + } |
|
211 | 211 | |
212 | 212 | |
213 | - /** |
|
214 | - * @param string $CNT_ISO |
|
215 | - * @return EE_Currency_Config|null |
|
216 | - * @throws EE_Error |
|
217 | - */ |
|
218 | - public static function get_currency_config($CNT_ISO = '') |
|
219 | - { |
|
220 | - // if CNT_ISO passed lets try to get currency settings for it. |
|
221 | - $currency_config = $CNT_ISO !== '' |
|
222 | - ? new EE_Currency_Config($CNT_ISO) |
|
223 | - : null; |
|
224 | - // default currency settings for site if not set |
|
225 | - if (! $currency_config instanceof EE_Currency_Config) { |
|
226 | - $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
227 | - ? EE_Registry::instance()->CFG->currency |
|
228 | - : new EE_Currency_Config(); |
|
229 | - } |
|
230 | - return $currency_config; |
|
231 | - } |
|
213 | + /** |
|
214 | + * @param string $CNT_ISO |
|
215 | + * @return EE_Currency_Config|null |
|
216 | + * @throws EE_Error |
|
217 | + */ |
|
218 | + public static function get_currency_config($CNT_ISO = '') |
|
219 | + { |
|
220 | + // if CNT_ISO passed lets try to get currency settings for it. |
|
221 | + $currency_config = $CNT_ISO !== '' |
|
222 | + ? new EE_Currency_Config($CNT_ISO) |
|
223 | + : null; |
|
224 | + // default currency settings for site if not set |
|
225 | + if (! $currency_config instanceof EE_Currency_Config) { |
|
226 | + $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
227 | + ? EE_Registry::instance()->CFG->currency |
|
228 | + : new EE_Currency_Config(); |
|
229 | + } |
|
230 | + return $currency_config; |
|
231 | + } |
|
232 | 232 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | ), |
38 | 38 | $money_value |
39 | 39 | ); |
40 | - $money_value = filter_var( |
|
40 | + $money_value = filter_var( |
|
41 | 41 | $money_value, |
42 | 42 | FILTER_SANITIZE_NUMBER_FLOAT, |
43 | 43 | FILTER_FLAG_ALLOW_FRACTION |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | $format = 'f'; |
166 | 166 | $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
167 | 167 | // first get the decimal place and number of places |
168 | - $format = "%'." . $currency_config->dec_plc . $format; |
|
168 | + $format = "%'.".$currency_config->dec_plc.$format; |
|
169 | 169 | // currency symbol on right side. |
170 | - $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
170 | + $format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign; |
|
171 | 171 | return $format; |
172 | 172 | } |
173 | 173 | |
@@ -187,10 +187,10 @@ discard block |
||
187 | 187 | $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
188 | 188 | $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0'); |
189 | 189 | // first get the decimal place and number of places |
190 | - $format = '#,##0.' . $decimal_places_placeholder; |
|
190 | + $format = '#,##0.'.$decimal_places_placeholder; |
|
191 | 191 | // currency symbol on right side. |
192 | - $format = $currency_config->sign_b4 |
|
193 | - ? $currency_config->sign . $format |
|
192 | + $format = $currency_config->sign_b4 |
|
193 | + ? $currency_config->sign.$format |
|
194 | 194 | : $format |
195 | 195 | . $currency_config->sign; |
196 | 196 | $formatterObject = array( |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | ? new EE_Currency_Config($CNT_ISO) |
223 | 223 | : null; |
224 | 224 | // default currency settings for site if not set |
225 | - if (! $currency_config instanceof EE_Currency_Config) { |
|
225 | + if ( ! $currency_config instanceof EE_Currency_Config) { |
|
226 | 226 | $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
227 | 227 | ? EE_Registry::instance()->CFG->currency |
228 | 228 | : new EE_Currency_Config(); |
@@ -12,262 +12,262 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * generates JSON-based linked data for an event |
|
17 | - * |
|
18 | - * @param EE_Event $event |
|
19 | - * @throws EE_Error |
|
20 | - */ |
|
21 | - public static function add_json_linked_data_for_event(EE_Event $event) |
|
22 | - { |
|
23 | - // Check we have a valid datetime for the event |
|
24 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | - return; |
|
26 | - } |
|
27 | - |
|
28 | - $template_args = array( |
|
29 | - 'event_permalink' => '', |
|
30 | - 'event_name' => '', |
|
31 | - 'event_description' => '', |
|
32 | - 'event_start' => '', |
|
33 | - 'event_end' => '', |
|
34 | - 'currency' => '', |
|
35 | - 'event_tickets' => array(), |
|
36 | - 'venue_name' => '', |
|
37 | - 'venue_url' => '', |
|
38 | - 'venue_locality' => '', |
|
39 | - 'venue_region' => '', |
|
40 | - 'event_image' => '', |
|
41 | - ); |
|
42 | - $template_args['event_permalink'] = $event->get_permalink(); |
|
43 | - $template_args['event_name'] = $event->name(); |
|
44 | - $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
45 | - // clone datetime so that date formats don't override those for the original datetime |
|
46 | - $primary_datetime = clone $event->primary_datetime(); |
|
47 | - $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
48 | - $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
49 | - unset($primary_datetime); |
|
50 | - $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
51 | - foreach ($event->tickets() as $original_ticket) { |
|
52 | - // clone tickets so that date formats don't override those for the original ticket |
|
53 | - $ticket= clone $original_ticket; |
|
54 | - $ID = $ticket->ID(); |
|
55 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
56 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
57 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
58 | - $ticket->price(), |
|
59 | - EE_Registry::instance()->CFG->currency->dec_plc, |
|
60 | - EE_Registry::instance()->CFG->currency->dec_mrk, |
|
61 | - EE_Registry::instance()->CFG->currency->thsnds |
|
62 | - ); |
|
63 | - unset($ticket); |
|
64 | - } |
|
65 | - $VNU_ID = espresso_venue_id(); |
|
66 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
67 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
68 | - $template_args['venue_name'] = get_the_title($VNU_ID); |
|
69 | - $template_args['venue_url'] = get_permalink($VNU_ID); |
|
70 | - $template_args['venue_locality'] = $venue->city(); |
|
71 | - $template_args['venue_region'] = $venue->state_name(); |
|
72 | - } |
|
73 | - $template_args['event_image'] = $event->feature_image_url(); |
|
74 | - $template_args = apply_filters( |
|
75 | - 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
76 | - $template_args, |
|
77 | - $event, |
|
78 | - $VNU_ID |
|
79 | - ); |
|
80 | - extract($template_args, EXTR_OVERWRITE); |
|
81 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * location |
|
87 | - * The location of the event, organization or action. |
|
88 | - * Should include the Venue name AND schema formatted address info |
|
89 | - * |
|
90 | - * @access public |
|
91 | - * @param string $location |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public static function location($location = null) |
|
95 | - { |
|
96 | - return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
97 | - . $location |
|
98 | - . '</div>' : ''; |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * name |
|
105 | - * The name of the Event or Venue. |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @param string $name |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public static function name($name = null) |
|
112 | - { |
|
113 | - return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * streetAddress |
|
120 | - * The street address. For example, 1600 Amphitheatre Pkwy. |
|
121 | - * |
|
122 | - * @access public |
|
123 | - * @param EEI_Address $obj_with_address |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public static function streetAddress(EEI_Address $obj_with_address = null) |
|
127 | - { |
|
128 | - return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
129 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * postOfficeBoxNumber |
|
136 | - * The post office box number for PO box addresses. |
|
137 | - * |
|
138 | - * @access public |
|
139 | - * @param EEI_Address $obj_with_address |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) |
|
143 | - { |
|
144 | - // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
145 | - if (preg_match( |
|
146 | - "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
147 | - $obj_with_address->address2() |
|
148 | - ) ) { |
|
149 | - return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
150 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
151 | - } else { |
|
152 | - return $obj_with_address->address2(); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * addressLocality |
|
160 | - * The locality (city, town, etc). For example, Mountain View. |
|
161 | - * |
|
162 | - * @access public |
|
163 | - * @param EEI_Address $obj_with_address |
|
164 | - * @return string |
|
165 | - */ |
|
166 | - public static function addressLocality(EEI_Address $obj_with_address = null) |
|
167 | - { |
|
168 | - return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
169 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * addressRegion |
|
176 | - * The region (state, province, etc). For example, CA. |
|
177 | - * |
|
178 | - * @access public |
|
179 | - * @param EEI_Address $obj_with_address |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public static function addressRegion(EEI_Address $obj_with_address = null) |
|
183 | - { |
|
184 | - $state = $obj_with_address->state_name(); |
|
185 | - if (! empty($state)) { |
|
186 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
187 | - } else { |
|
188 | - return ''; |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * addressCountry |
|
196 | - * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
197 | - * |
|
198 | - * @access public |
|
199 | - * @param EEI_Address $obj_with_address |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public static function addressCountry(EEI_Address $obj_with_address = null) |
|
203 | - { |
|
204 | - $country = $obj_with_address->country_name(); |
|
205 | - if (! empty($country)) { |
|
206 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
207 | - } else { |
|
208 | - return ''; |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * postalCode |
|
216 | - * The postal code. For example, 94043. |
|
217 | - * |
|
218 | - * @access public |
|
219 | - * @param EEI_Address $obj_with_address |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public static function postalCode(EEI_Address $obj_with_address = null) |
|
223 | - { |
|
224 | - return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
225 | - . $obj_with_address->zip() |
|
226 | - . '</span>' : ''; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * telephone |
|
233 | - * The telephone number. |
|
234 | - * |
|
235 | - * @access public |
|
236 | - * @param string $phone_nmbr |
|
237 | - * @return string |
|
238 | - */ |
|
239 | - public static function telephone($phone_nmbr = null) |
|
240 | - { |
|
241 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
242 | - : ''; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * URL |
|
249 | - * URL of the item as a clickable link |
|
250 | - * |
|
251 | - * @access public |
|
252 | - * @param string $url - the URL that the link will resolve to |
|
253 | - * @param string $text - the text that will be used for the visible link |
|
254 | - * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
255 | - * @return string (link) |
|
256 | - */ |
|
257 | - public static function url($url = null, $text = null, $attributes = array()) |
|
258 | - { |
|
259 | - // Check the URL includes a scheme |
|
260 | - $parsed_url = parse_url($url); |
|
261 | - if (empty($parsed_url['scheme'])) { |
|
262 | - $url = 'http://' . ltrim($url, '/'); |
|
263 | - } |
|
264 | - |
|
265 | - $atts = ''; |
|
266 | - foreach ($attributes as $attribute => $value) { |
|
267 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
268 | - } |
|
269 | - $text = $text !== null && $text !== '' ? $text : $url; |
|
270 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
271 | - : ''; |
|
272 | - } |
|
15 | + /** |
|
16 | + * generates JSON-based linked data for an event |
|
17 | + * |
|
18 | + * @param EE_Event $event |
|
19 | + * @throws EE_Error |
|
20 | + */ |
|
21 | + public static function add_json_linked_data_for_event(EE_Event $event) |
|
22 | + { |
|
23 | + // Check we have a valid datetime for the event |
|
24 | + if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | + return; |
|
26 | + } |
|
27 | + |
|
28 | + $template_args = array( |
|
29 | + 'event_permalink' => '', |
|
30 | + 'event_name' => '', |
|
31 | + 'event_description' => '', |
|
32 | + 'event_start' => '', |
|
33 | + 'event_end' => '', |
|
34 | + 'currency' => '', |
|
35 | + 'event_tickets' => array(), |
|
36 | + 'venue_name' => '', |
|
37 | + 'venue_url' => '', |
|
38 | + 'venue_locality' => '', |
|
39 | + 'venue_region' => '', |
|
40 | + 'event_image' => '', |
|
41 | + ); |
|
42 | + $template_args['event_permalink'] = $event->get_permalink(); |
|
43 | + $template_args['event_name'] = $event->name(); |
|
44 | + $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
45 | + // clone datetime so that date formats don't override those for the original datetime |
|
46 | + $primary_datetime = clone $event->primary_datetime(); |
|
47 | + $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
48 | + $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
49 | + unset($primary_datetime); |
|
50 | + $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
51 | + foreach ($event->tickets() as $original_ticket) { |
|
52 | + // clone tickets so that date formats don't override those for the original ticket |
|
53 | + $ticket= clone $original_ticket; |
|
54 | + $ID = $ticket->ID(); |
|
55 | + $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
56 | + $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
57 | + $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
58 | + $ticket->price(), |
|
59 | + EE_Registry::instance()->CFG->currency->dec_plc, |
|
60 | + EE_Registry::instance()->CFG->currency->dec_mrk, |
|
61 | + EE_Registry::instance()->CFG->currency->thsnds |
|
62 | + ); |
|
63 | + unset($ticket); |
|
64 | + } |
|
65 | + $VNU_ID = espresso_venue_id(); |
|
66 | + if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
67 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
68 | + $template_args['venue_name'] = get_the_title($VNU_ID); |
|
69 | + $template_args['venue_url'] = get_permalink($VNU_ID); |
|
70 | + $template_args['venue_locality'] = $venue->city(); |
|
71 | + $template_args['venue_region'] = $venue->state_name(); |
|
72 | + } |
|
73 | + $template_args['event_image'] = $event->feature_image_url(); |
|
74 | + $template_args = apply_filters( |
|
75 | + 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
76 | + $template_args, |
|
77 | + $event, |
|
78 | + $VNU_ID |
|
79 | + ); |
|
80 | + extract($template_args, EXTR_OVERWRITE); |
|
81 | + include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * location |
|
87 | + * The location of the event, organization or action. |
|
88 | + * Should include the Venue name AND schema formatted address info |
|
89 | + * |
|
90 | + * @access public |
|
91 | + * @param string $location |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public static function location($location = null) |
|
95 | + { |
|
96 | + return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
97 | + . $location |
|
98 | + . '</div>' : ''; |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * name |
|
105 | + * The name of the Event or Venue. |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @param string $name |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public static function name($name = null) |
|
112 | + { |
|
113 | + return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * streetAddress |
|
120 | + * The street address. For example, 1600 Amphitheatre Pkwy. |
|
121 | + * |
|
122 | + * @access public |
|
123 | + * @param EEI_Address $obj_with_address |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public static function streetAddress(EEI_Address $obj_with_address = null) |
|
127 | + { |
|
128 | + return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
129 | + ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * postOfficeBoxNumber |
|
136 | + * The post office box number for PO box addresses. |
|
137 | + * |
|
138 | + * @access public |
|
139 | + * @param EEI_Address $obj_with_address |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) |
|
143 | + { |
|
144 | + // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
145 | + if (preg_match( |
|
146 | + "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
147 | + $obj_with_address->address2() |
|
148 | + ) ) { |
|
149 | + return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
150 | + ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
151 | + } else { |
|
152 | + return $obj_with_address->address2(); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * addressLocality |
|
160 | + * The locality (city, town, etc). For example, Mountain View. |
|
161 | + * |
|
162 | + * @access public |
|
163 | + * @param EEI_Address $obj_with_address |
|
164 | + * @return string |
|
165 | + */ |
|
166 | + public static function addressLocality(EEI_Address $obj_with_address = null) |
|
167 | + { |
|
168 | + return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
169 | + ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * addressRegion |
|
176 | + * The region (state, province, etc). For example, CA. |
|
177 | + * |
|
178 | + * @access public |
|
179 | + * @param EEI_Address $obj_with_address |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public static function addressRegion(EEI_Address $obj_with_address = null) |
|
183 | + { |
|
184 | + $state = $obj_with_address->state_name(); |
|
185 | + if (! empty($state)) { |
|
186 | + return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
187 | + } else { |
|
188 | + return ''; |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * addressCountry |
|
196 | + * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
197 | + * |
|
198 | + * @access public |
|
199 | + * @param EEI_Address $obj_with_address |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public static function addressCountry(EEI_Address $obj_with_address = null) |
|
203 | + { |
|
204 | + $country = $obj_with_address->country_name(); |
|
205 | + if (! empty($country)) { |
|
206 | + return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
207 | + } else { |
|
208 | + return ''; |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * postalCode |
|
216 | + * The postal code. For example, 94043. |
|
217 | + * |
|
218 | + * @access public |
|
219 | + * @param EEI_Address $obj_with_address |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public static function postalCode(EEI_Address $obj_with_address = null) |
|
223 | + { |
|
224 | + return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
225 | + . $obj_with_address->zip() |
|
226 | + . '</span>' : ''; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * telephone |
|
233 | + * The telephone number. |
|
234 | + * |
|
235 | + * @access public |
|
236 | + * @param string $phone_nmbr |
|
237 | + * @return string |
|
238 | + */ |
|
239 | + public static function telephone($phone_nmbr = null) |
|
240 | + { |
|
241 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
242 | + : ''; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * URL |
|
249 | + * URL of the item as a clickable link |
|
250 | + * |
|
251 | + * @access public |
|
252 | + * @param string $url - the URL that the link will resolve to |
|
253 | + * @param string $text - the text that will be used for the visible link |
|
254 | + * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
255 | + * @return string (link) |
|
256 | + */ |
|
257 | + public static function url($url = null, $text = null, $attributes = array()) |
|
258 | + { |
|
259 | + // Check the URL includes a scheme |
|
260 | + $parsed_url = parse_url($url); |
|
261 | + if (empty($parsed_url['scheme'])) { |
|
262 | + $url = 'http://' . ltrim($url, '/'); |
|
263 | + } |
|
264 | + |
|
265 | + $atts = ''; |
|
266 | + foreach ($attributes as $attribute => $value) { |
|
267 | + $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
268 | + } |
|
269 | + $text = $text !== null && $text !== '' ? $text : $url; |
|
270 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
271 | + : ''; |
|
272 | + } |
|
273 | 273 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | public static function add_json_linked_data_for_event(EE_Event $event) |
22 | 22 | { |
23 | 23 | // Check we have a valid datetime for the event |
24 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
24 | + if ( ! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | 25 | return; |
26 | 26 | } |
27 | 27 | |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
51 | 51 | foreach ($event->tickets() as $original_ticket) { |
52 | 52 | // clone tickets so that date formats don't override those for the original ticket |
53 | - $ticket= clone $original_ticket; |
|
53 | + $ticket = clone $original_ticket; |
|
54 | 54 | $ID = $ticket->ID(); |
55 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
56 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
57 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
55 | + $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
56 | + $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
57 | + $template_args['event_tickets'][$ID]['price'] = number_format( |
|
58 | 58 | $ticket->price(), |
59 | 59 | EE_Registry::instance()->CFG->currency->dec_plc, |
60 | 60 | EE_Registry::instance()->CFG->currency->dec_mrk, |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | unset($ticket); |
64 | 64 | } |
65 | 65 | $VNU_ID = espresso_venue_id(); |
66 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
66 | + if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
67 | 67 | $venue = EEH_Venue_View::get_venue($VNU_ID); |
68 | 68 | $template_args['venue_name'] = get_the_title($VNU_ID); |
69 | 69 | $template_args['venue_url'] = get_permalink($VNU_ID); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $VNU_ID |
79 | 79 | ); |
80 | 80 | extract($template_args, EXTR_OVERWRITE); |
81 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
81 | + include EE_TEMPLATES.'json_linked_data_for_event.template.php'; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public static function name($name = null) |
112 | 112 | { |
113 | - return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
113 | + return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : ''; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | public static function streetAddress(EEI_Address $obj_with_address = null) |
127 | 127 | { |
128 | 128 | return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
129 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
129 | + ? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : ''; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | if (preg_match( |
146 | 146 | "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
147 | 147 | $obj_with_address->address2() |
148 | - ) ) { |
|
148 | + )) { |
|
149 | 149 | return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
150 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
150 | + ? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : ''; |
|
151 | 151 | } else { |
152 | 152 | return $obj_with_address->address2(); |
153 | 153 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | public static function addressLocality(EEI_Address $obj_with_address = null) |
167 | 167 | { |
168 | 168 | return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
169 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
169 | + ? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : ''; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | |
@@ -182,8 +182,8 @@ discard block |
||
182 | 182 | public static function addressRegion(EEI_Address $obj_with_address = null) |
183 | 183 | { |
184 | 184 | $state = $obj_with_address->state_name(); |
185 | - if (! empty($state)) { |
|
186 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
185 | + if ( ! empty($state)) { |
|
186 | + return '<span itemprop="addressRegion">'.$state.'</span>'; |
|
187 | 187 | } else { |
188 | 188 | return ''; |
189 | 189 | } |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | public static function addressCountry(EEI_Address $obj_with_address = null) |
203 | 203 | { |
204 | 204 | $country = $obj_with_address->country_name(); |
205 | - if (! empty($country)) { |
|
206 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
205 | + if ( ! empty($country)) { |
|
206 | + return '<span itemprop="addressCountry">'.$country.'</span>'; |
|
207 | 207 | } else { |
208 | 208 | return ''; |
209 | 209 | } |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | */ |
239 | 239 | public static function telephone($phone_nmbr = null) |
240 | 240 | { |
241 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
241 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>' |
|
242 | 242 | : ''; |
243 | 243 | } |
244 | 244 | |
@@ -259,15 +259,15 @@ discard block |
||
259 | 259 | // Check the URL includes a scheme |
260 | 260 | $parsed_url = parse_url($url); |
261 | 261 | if (empty($parsed_url['scheme'])) { |
262 | - $url = 'http://' . ltrim($url, '/'); |
|
262 | + $url = 'http://'.ltrim($url, '/'); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | $atts = ''; |
266 | 266 | foreach ($attributes as $attribute => $value) { |
267 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
267 | + $atts .= ' '.$attribute.'="'.$value.'"'; |
|
268 | 268 | } |
269 | 269 | $text = $text !== null && $text !== '' ? $text : $url; |
270 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
270 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="'.$url.'"'.$atts.'>'.$text.'</a>' |
|
271 | 271 | : ''; |
272 | 272 | } |
273 | 273 | } |
@@ -13,70 +13,70 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * $CPT - the current page, if it utilizes CPTs |
|
18 | - * |
|
19 | - * @var object |
|
20 | - * @access protected |
|
21 | - */ |
|
22 | - protected $CPT = null; |
|
16 | + /** |
|
17 | + * $CPT - the current page, if it utilizes CPTs |
|
18 | + * |
|
19 | + * @var object |
|
20 | + * @access protected |
|
21 | + */ |
|
22 | + protected $CPT = null; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * class constructor |
|
27 | - * |
|
28 | - * @access private |
|
29 | - * @param array $arguments |
|
30 | - * @return \EE_CPT_Default_Strategy |
|
31 | - */ |
|
32 | - public function __construct($arguments = array()) |
|
33 | - { |
|
34 | - $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null; |
|
35 | - } |
|
25 | + /** |
|
26 | + * class constructor |
|
27 | + * |
|
28 | + * @access private |
|
29 | + * @param array $arguments |
|
30 | + * @return \EE_CPT_Default_Strategy |
|
31 | + */ |
|
32 | + public function __construct($arguments = array()) |
|
33 | + { |
|
34 | + $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * pre_get_posts |
|
40 | - * |
|
41 | - * @access public |
|
42 | - * @param \WP_Query $WP_Query |
|
43 | - * @return \WP_Query |
|
44 | - */ |
|
45 | - public function pre_get_posts(WP_Query $WP_Query) |
|
46 | - { |
|
47 | - if (! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) { |
|
48 | - return $WP_Query; |
|
49 | - } |
|
50 | - return $WP_Query; |
|
51 | - } |
|
38 | + /** |
|
39 | + * pre_get_posts |
|
40 | + * |
|
41 | + * @access public |
|
42 | + * @param \WP_Query $WP_Query |
|
43 | + * @return \WP_Query |
|
44 | + */ |
|
45 | + public function pre_get_posts(WP_Query $WP_Query) |
|
46 | + { |
|
47 | + if (! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) { |
|
48 | + return $WP_Query; |
|
49 | + } |
|
50 | + return $WP_Query; |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * wp |
|
56 | - * |
|
57 | - * @access public |
|
58 | - * @param \WP_Post[] $posts |
|
59 | - * @param \WP_Query $WP_Query |
|
60 | - * @return \WP_Post[] |
|
61 | - */ |
|
62 | - public function the_posts($posts, WP_Query $WP_Query) |
|
63 | - { |
|
64 | - return $posts; |
|
65 | - } |
|
54 | + /** |
|
55 | + * wp |
|
56 | + * |
|
57 | + * @access public |
|
58 | + * @param \WP_Post[] $posts |
|
59 | + * @param \WP_Query $WP_Query |
|
60 | + * @return \WP_Post[] |
|
61 | + */ |
|
62 | + public function the_posts($posts, WP_Query $WP_Query) |
|
63 | + { |
|
64 | + return $posts; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * get_EE_post_type_metadata |
|
70 | - * |
|
71 | - * @access public |
|
72 | - * @param mixed $meta_value |
|
73 | - * @param int $post_id |
|
74 | - * @param string $meta_key |
|
75 | - * @param string $single |
|
76 | - * @return mixed |
|
77 | - */ |
|
78 | - public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single) |
|
79 | - { |
|
80 | - return $meta_value; |
|
81 | - } |
|
68 | + /** |
|
69 | + * get_EE_post_type_metadata |
|
70 | + * |
|
71 | + * @access public |
|
72 | + * @param mixed $meta_value |
|
73 | + * @param int $post_id |
|
74 | + * @param string $meta_key |
|
75 | + * @param string $single |
|
76 | + * @return mixed |
|
77 | + */ |
|
78 | + public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single) |
|
79 | + { |
|
80 | + return $meta_value; |
|
81 | + } |
|
82 | 82 | } |
@@ -44,7 +44,7 @@ |
||
44 | 44 | */ |
45 | 45 | public function pre_get_posts(WP_Query $WP_Query) |
46 | 46 | { |
47 | - if (! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) { |
|
47 | + if ( ! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) { |
|
48 | 48 | return $WP_Query; |
49 | 49 | } |
50 | 50 | return $WP_Query; |
@@ -24,39 +24,39 @@ |
||
24 | 24 | class EE_CPT_Attendee_Strategy |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * $CPT - the current page, if it utilizes CPTs |
|
29 | - * |
|
30 | - * @var array |
|
31 | - * @access protected |
|
32 | - */ |
|
33 | - protected $CPT = null; |
|
27 | + /** |
|
28 | + * $CPT - the current page, if it utilizes CPTs |
|
29 | + * |
|
30 | + * @var array |
|
31 | + * @access protected |
|
32 | + */ |
|
33 | + protected $CPT = null; |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * class constructor |
|
38 | - * |
|
39 | - * @access public |
|
40 | - * @param array $arguments |
|
41 | - * @return \EE_CPT_Attendee_Strategy |
|
42 | - */ |
|
43 | - public function __construct($arguments = array()) |
|
44 | - { |
|
45 | - $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null; |
|
46 | - $WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null; |
|
47 | - } |
|
36 | + /** |
|
37 | + * class constructor |
|
38 | + * |
|
39 | + * @access public |
|
40 | + * @param array $arguments |
|
41 | + * @return \EE_CPT_Attendee_Strategy |
|
42 | + */ |
|
43 | + public function __construct($arguments = array()) |
|
44 | + { |
|
45 | + $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null; |
|
46 | + $WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * the_posts |
|
52 | - * |
|
53 | - * @access public |
|
54 | - * @param $posts |
|
55 | - * @param WP_Query $wp_query |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function the_posts($posts, WP_Query $wp_query) |
|
59 | - { |
|
60 | - return $posts; |
|
61 | - } |
|
50 | + /** |
|
51 | + * the_posts |
|
52 | + * |
|
53 | + * @access public |
|
54 | + * @param $posts |
|
55 | + * @param WP_Query $wp_query |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function the_posts($posts, WP_Query $wp_query) |
|
59 | + { |
|
60 | + return $posts; |
|
61 | + } |
|
62 | 62 | } |
@@ -12,54 +12,54 @@ |
||
12 | 12 | class EE_CPT_Venue_Strategy |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * $CPT - the current page, if it utilizes CPTs |
|
17 | - * |
|
18 | - * @var array |
|
19 | - * @access protected |
|
20 | - */ |
|
21 | - protected $CPT = null; |
|
15 | + /** |
|
16 | + * $CPT - the current page, if it utilizes CPTs |
|
17 | + * |
|
18 | + * @var array |
|
19 | + * @access protected |
|
20 | + */ |
|
21 | + protected $CPT = null; |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * class constructor |
|
26 | - * |
|
27 | - * @access public |
|
28 | - * @param array $arguments |
|
29 | - * @return \EE_CPT_Venue_Strategy |
|
30 | - */ |
|
31 | - public function __construct($arguments = array()) |
|
32 | - { |
|
33 | - $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null; |
|
34 | - $WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null; |
|
35 | - if ($WP_Query instanceof WP_Query && ! $WP_Query->is_tag) { |
|
36 | - $WP_Query->is_espresso_venue_single = is_singular() |
|
37 | - && isset($WP_Query->query->post_type) |
|
38 | - && $WP_Query->query->post_type == 'espresso_venues'; |
|
39 | - $WP_Query->is_espresso_venue_archive = is_post_type_archive('espresso_venues') ? true : false; |
|
40 | - $WP_Query->is_espresso_venue_taxonomy = is_tax('espresso_venue_categories') ? true : false; |
|
41 | - } |
|
42 | - add_filter('the_posts', array($this, 'the_posts'), 1, 2); |
|
43 | - } |
|
24 | + /** |
|
25 | + * class constructor |
|
26 | + * |
|
27 | + * @access public |
|
28 | + * @param array $arguments |
|
29 | + * @return \EE_CPT_Venue_Strategy |
|
30 | + */ |
|
31 | + public function __construct($arguments = array()) |
|
32 | + { |
|
33 | + $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null; |
|
34 | + $WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null; |
|
35 | + if ($WP_Query instanceof WP_Query && ! $WP_Query->is_tag) { |
|
36 | + $WP_Query->is_espresso_venue_single = is_singular() |
|
37 | + && isset($WP_Query->query->post_type) |
|
38 | + && $WP_Query->query->post_type == 'espresso_venues'; |
|
39 | + $WP_Query->is_espresso_venue_archive = is_post_type_archive('espresso_venues') ? true : false; |
|
40 | + $WP_Query->is_espresso_venue_taxonomy = is_tax('espresso_venue_categories') ? true : false; |
|
41 | + } |
|
42 | + add_filter('the_posts', array($this, 'the_posts'), 1, 2); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * the_posts |
|
48 | - * |
|
49 | - * @access public |
|
50 | - * @param $posts |
|
51 | - * @param WP_Query $wp_query |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function the_posts($posts, WP_Query $wp_query) |
|
55 | - { |
|
56 | - // automagically load the EEH_Venue_View helper so that it's functions are available |
|
57 | - if (isset(EE_Registry::instance()->CFG->map_settings->use_google_maps) |
|
58 | - && EE_Registry::instance()->CFG->map_settings->use_google_maps |
|
59 | - ) { |
|
60 | - EEH_Maps::espresso_google_map_js(); |
|
61 | - } |
|
62 | - remove_filter('the_posts', array($this, 'the_posts'), 1, 2); |
|
63 | - return $posts; |
|
64 | - } |
|
46 | + /** |
|
47 | + * the_posts |
|
48 | + * |
|
49 | + * @access public |
|
50 | + * @param $posts |
|
51 | + * @param WP_Query $wp_query |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function the_posts($posts, WP_Query $wp_query) |
|
55 | + { |
|
56 | + // automagically load the EEH_Venue_View helper so that it's functions are available |
|
57 | + if (isset(EE_Registry::instance()->CFG->map_settings->use_google_maps) |
|
58 | + && EE_Registry::instance()->CFG->map_settings->use_google_maps |
|
59 | + ) { |
|
60 | + EEH_Maps::espresso_google_map_js(); |
|
61 | + } |
|
62 | + remove_filter('the_posts', array($this, 'the_posts'), 1, 2); |
|
63 | + return $posts; |
|
64 | + } |
|
65 | 65 | } |