@@ -26,7 +26,7 @@ |
||
26 | 26 | public function __get( $field ) {} |
27 | 27 | |
28 | 28 | /** |
29 | - * @return boolean |
|
29 | + * @return boolean|null |
|
30 | 30 | */ |
31 | 31 | public function __isset( $field ) {} |
32 | 32 |
@@ -21,14 +21,14 @@ |
||
21 | 21 | $this->get = $_GET; |
22 | 22 | } |
23 | 23 | |
24 | - public function __call( $field, $args ) {} |
|
24 | + public function __call($field, $args) {} |
|
25 | 25 | |
26 | - public function __get( $field ) {} |
|
26 | + public function __get($field) {} |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @return boolean |
30 | 30 | */ |
31 | - public function __isset( $field ) {} |
|
31 | + public function __isset($field) {} |
|
32 | 32 | |
33 | - public function meta( $key ) {} |
|
33 | + public function meta($key) {} |
|
34 | 34 | } |
@@ -28,7 +28,9 @@ |
||
28 | 28 | $this->_class = $function[0]; |
29 | 29 | } |
30 | 30 | |
31 | - if( is_string( $function[1] ) ) $this->_function = $function[1]; |
|
31 | + if( is_string( $function[1] ) ) { |
|
32 | + $this->_function = $function[1]; |
|
33 | + } |
|
32 | 34 | } else { |
33 | 35 | $this->_function = $function; |
34 | 36 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | public function __toString() { |
11 | 11 | try { |
12 | - return (string)$this->call(); |
|
12 | + return (string) $this->call(); |
|
13 | 13 | } catch (Exception $e) { |
14 | 14 | return 'Caught exception: ' . $e->getMessage() . "\n"; |
15 | 15 | } |
@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | * @param array $args |
23 | 23 | * @param bool $return_output_buffer |
24 | 24 | */ |
25 | - public function __construct( $function, $args = array(), $return_output_buffer = false ) { |
|
26 | - if( is_array( $function ) ) { |
|
27 | - if( (is_string( $function[0] ) && class_exists( $function[0] ) ) || gettype( $function[0] ) === 'object' ) { |
|
25 | + public function __construct($function, $args = array(), $return_output_buffer = false) { |
|
26 | + if ( is_array($function) ) { |
|
27 | + if ( (is_string($function[0]) && class_exists($function[0])) || gettype($function[0]) === 'object' ) { |
|
28 | 28 | $this->_class = $function[0]; |
29 | 29 | } |
30 | 30 | |
31 | - if( is_string( $function[1] ) ) $this->_function = $function[1]; |
|
31 | + if ( is_string($function[1]) ) $this->_function = $function[1]; |
|
32 | 32 | } else { |
33 | 33 | $this->_function = $function; |
34 | 34 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $this->_args = $args; |
37 | 37 | $this->_use_ob = $return_output_buffer; |
38 | 38 | |
39 | - add_filter( 'get_twig', array( &$this, 'add_to_twig' ) ); |
|
39 | + add_filter('get_twig', array(&$this, 'add_to_twig')); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -45,12 +45,12 @@ discard block |
||
45 | 45 | * @param Twig_Environment $twig |
46 | 46 | * @return Twig_Environment |
47 | 47 | */ |
48 | - public function add_to_twig( $twig ) { |
|
48 | + public function add_to_twig($twig) { |
|
49 | 49 | $wrapper = $this; |
50 | 50 | |
51 | - $twig->addFunction( new Twig_SimpleFunction( $this->_function, function () use ( $wrapper ) { |
|
52 | - return call_user_func_array( array( $wrapper, 'call' ), func_get_args() ); |
|
53 | - } ) ); |
|
51 | + $twig->addFunction(new Twig_SimpleFunction($this->_function, function() use ($wrapper) { |
|
52 | + return call_user_func_array(array($wrapper, 'call'), func_get_args()); |
|
53 | + } )); |
|
54 | 54 | |
55 | 55 | return $twig; |
56 | 56 | } |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | * @return string |
62 | 62 | */ |
63 | 63 | public function call() { |
64 | - $args = $this->_parse_args( func_get_args(), $this->_args ); |
|
65 | - $callable = ( isset( $this->_class ) ) ? array( $this->_class, $this->_function ) : $this->_function; |
|
64 | + $args = $this->_parse_args(func_get_args(), $this->_args); |
|
65 | + $callable = (isset($this->_class)) ? array($this->_class, $this->_function) : $this->_function; |
|
66 | 66 | |
67 | 67 | if ( $this->_use_ob ) { |
68 | - return TimberHelper::ob_function( $callable, $args ); |
|
68 | + return TimberHelper::ob_function($callable, $args); |
|
69 | 69 | } else { |
70 | - return call_user_func_array( $callable, $args ); |
|
70 | + return call_user_func_array($callable, $args); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | * @param array $defaults |
79 | 79 | * @return array |
80 | 80 | */ |
81 | - private function _parse_args( $args, $defaults ) { |
|
82 | - $_arg = reset( $defaults ); |
|
81 | + private function _parse_args($args, $defaults) { |
|
82 | + $_arg = reset($defaults); |
|
83 | 83 | |
84 | 84 | foreach ( $args as $index => $arg ) { |
85 | - $defaults[$index] = is_null( $arg ) ? $_arg : $arg; |
|
86 | - $_arg = next( $defaults ); |
|
85 | + $defaults[$index] = is_null($arg) ? $_arg : $arg; |
|
86 | + $_arg = next($defaults); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | return $defaults; |
@@ -345,7 +345,7 @@ |
||
345 | 345 | * Get widgets. |
346 | 346 | * |
347 | 347 | * @param int $widget_id |
348 | - * @return TimberFunctionWrapper |
|
348 | + * @return string |
|
349 | 349 | */ |
350 | 350 | public static function get_widgets( $widget_id ) { |
351 | 351 | return trim( TimberHelper::function_wrapper( 'dynamic_sidebar', array( $widget_id ), true ) ); |
@@ -45,16 +45,16 @@ discard block |
||
45 | 45 | if ( is_admin() || $_SERVER['PHP_SELF'] == '/wp-login.php' ) { |
46 | 46 | return; |
47 | 47 | } |
48 | - if ( version_compare( phpversion(), '5.3.0', '<' ) && !is_admin() ) { |
|
49 | - trigger_error( 'Timber requires PHP 5.3.0 or greater. You have '.phpversion(), E_USER_ERROR ); |
|
48 | + if ( version_compare(phpversion(), '5.3.0', '<') && !is_admin() ) { |
|
49 | + trigger_error('Timber requires PHP 5.3.0 or greater. You have ' . phpversion(), E_USER_ERROR); |
|
50 | 50 | } |
51 | - if ( !class_exists( 'Twig_Autoloader' ) ) { |
|
52 | - trigger_error( 'You have not run "composer install" to download required dependencies for Timber, you can read more on https://github.com/jarednova/timber#installation', E_USER_ERROR ); |
|
51 | + if ( !class_exists('Twig_Autoloader') ) { |
|
52 | + trigger_error('You have not run "composer install" to download required dependencies for Timber, you can read more on https://github.com/jarednova/timber#installation', E_USER_ERROR); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
56 | 56 | function init_constants() { |
57 | - defined( "TIMBER_LOC" ) or define( "TIMBER_LOC", realpath( dirname(__DIR__) ) ); |
|
57 | + defined("TIMBER_LOC") or define("TIMBER_LOC", realpath(dirname(__DIR__))); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | protected function init() { |
64 | 64 | TimberTwig::init(); |
65 | - TimberRoutes::init( $this ); |
|
65 | + TimberRoutes::init($this); |
|
66 | 66 | TimberImageHelper::init(); |
67 | 67 | TimberAdmin::init(); |
68 | 68 | TimberIntegrations::init(); |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | * @param string $PostClass |
79 | 79 | * @return array|bool|null |
80 | 80 | */ |
81 | - public static function get_post( $query = false, $PostClass = 'TimberPost' ) { |
|
82 | - return TimberPostGetter::get_post( $query, $PostClass ); |
|
81 | + public static function get_post($query = false, $PostClass = 'TimberPost') { |
|
82 | + return TimberPostGetter::get_post($query, $PostClass); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | * @param string $PostClass |
90 | 90 | * @return array|bool|null |
91 | 91 | */ |
92 | - public static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) { |
|
93 | - return TimberPostGetter::get_posts( $query, $PostClass, $return_collection ); |
|
92 | + public static function get_posts($query = false, $PostClass = 'TimberPost', $return_collection = false) { |
|
93 | + return TimberPostGetter::get_posts($query, $PostClass, $return_collection); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | * @param string $PostClass |
101 | 101 | * @return array|bool|null |
102 | 102 | */ |
103 | - public static function query_post( $query = false, $PostClass = 'TimberPost' ) { |
|
104 | - return TimberPostGetter::query_post( $query, $PostClass ); |
|
103 | + public static function query_post($query = false, $PostClass = 'TimberPost') { |
|
104 | + return TimberPostGetter::query_post($query, $PostClass); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | * @param string $PostClass |
112 | 112 | * @return array|bool|null |
113 | 113 | */ |
114 | - public static function query_posts( $query = false, $PostClass = 'TimberPost' ) { |
|
115 | - return TimberPostGetter::query_posts( $query, $PostClass ); |
|
114 | + public static function query_posts($query = false, $PostClass = 'TimberPost') { |
|
115 | + return TimberPostGetter::query_posts($query, $PostClass); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * @param string $TermClass |
137 | 137 | * @return mixed |
138 | 138 | */ |
139 | - public static function get_terms( $args = null, $maybe_args = array(), $TermClass = 'TimberTerm' ) { |
|
140 | - return TimberTermGetter::get_terms( $args, $maybe_args, $TermClass ); |
|
139 | + public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm') { |
|
140 | + return TimberTermGetter::get_terms($args, $maybe_args, $TermClass); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /* Site Retrieval |
@@ -149,14 +149,14 @@ discard block |
||
149 | 149 | * @param array|bool $blog_ids |
150 | 150 | * @return array |
151 | 151 | */ |
152 | - public static function get_sites( $blog_ids = false ) { |
|
153 | - if ( !is_array( $blog_ids ) ) { |
|
152 | + public static function get_sites($blog_ids = false) { |
|
153 | + if ( !is_array($blog_ids) ) { |
|
154 | 154 | global $wpdb; |
155 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC" ); |
|
155 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC"); |
|
156 | 156 | } |
157 | 157 | $return = array(); |
158 | 158 | foreach ( $blog_ids as $blog_id ) { |
159 | - $return[] = new TimberSite( $blog_id ); |
|
159 | + $return[] = new TimberSite($blog_id); |
|
160 | 160 | } |
161 | 161 | return $return; |
162 | 162 | } |
@@ -174,9 +174,9 @@ discard block |
||
174 | 174 | $data = array(); |
175 | 175 | $data['http_host'] = 'http://' . TimberURLHelper::get_host(); |
176 | 176 | $data['wp_title'] = TimberHelper::get_wp_title(); |
177 | - $data['wp_head'] = TimberHelper::function_wrapper( 'wp_head' ); |
|
178 | - $data['wp_footer'] = TimberHelper::function_wrapper( 'wp_footer' ); |
|
179 | - $data['body_class'] = implode( ' ', get_body_class() ); |
|
177 | + $data['wp_head'] = TimberHelper::function_wrapper('wp_head'); |
|
178 | + $data['wp_footer'] = TimberHelper::function_wrapper('wp_footer'); |
|
179 | + $data['body_class'] = implode(' ', get_body_class()); |
|
180 | 180 | |
181 | 181 | $data['site'] = new TimberSite(); |
182 | 182 | $data['request'] = new TimberRequest(); |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | |
185 | 185 | $data['posts'] = Timber::query_posts(); |
186 | 186 | |
187 | - $data = apply_filters( 'timber_context', $data ); |
|
188 | - $data = apply_filters( 'timber/context', $data ); |
|
187 | + $data = apply_filters('timber_context', $data); |
|
188 | + $data = apply_filters('timber/context', $data); |
|
189 | 189 | return $data; |
190 | 190 | } |
191 | 191 | |
@@ -199,27 +199,27 @@ discard block |
||
199 | 199 | * @param bool $via_render |
200 | 200 | * @return bool|string |
201 | 201 | */ |
202 | - public static function compile( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT, $via_render = false ) { |
|
202 | + public static function compile($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT, $via_render = false) { |
|
203 | 203 | $caller = self::get_calling_script_dir(); |
204 | 204 | $caller_file = self::get_calling_script_file(); |
205 | - $caller_file = apply_filters( 'timber_calling_php_file', $caller_file ); |
|
206 | - $loader = new TimberLoader( $caller ); |
|
207 | - $file = $loader->choose_template( $filenames ); |
|
205 | + $caller_file = apply_filters('timber_calling_php_file', $caller_file); |
|
206 | + $loader = new TimberLoader($caller); |
|
207 | + $file = $loader->choose_template($filenames); |
|
208 | 208 | $output = ''; |
209 | - if ( is_null( $data ) ) { |
|
209 | + if ( is_null($data) ) { |
|
210 | 210 | $data = array(); |
211 | 211 | } |
212 | - if ( strlen( $file ) ) { |
|
212 | + if ( strlen($file) ) { |
|
213 | 213 | if ( $via_render ) { |
214 | - $file = apply_filters( 'timber_render_file', $file ); |
|
215 | - $data = apply_filters( 'timber_render_data', $data ); |
|
214 | + $file = apply_filters('timber_render_file', $file); |
|
215 | + $data = apply_filters('timber_render_data', $data); |
|
216 | 216 | } else { |
217 | - $file = apply_filters( 'timber_compile_file', $file ); |
|
218 | - $data = apply_filters( 'timber_compile_data', $data ); |
|
217 | + $file = apply_filters('timber_compile_file', $file); |
|
218 | + $data = apply_filters('timber_compile_data', $data); |
|
219 | 219 | } |
220 | - $output = $loader->render( $file, $data, $expires, $cache_mode ); |
|
220 | + $output = $loader->render($file, $data, $expires, $cache_mode); |
|
221 | 221 | } |
222 | - do_action( 'timber_compile_done' ); |
|
222 | + do_action('timber_compile_done'); |
|
223 | 223 | return $output; |
224 | 224 | } |
225 | 225 | |
@@ -230,14 +230,14 @@ discard block |
||
230 | 230 | * @param array $data an array with data in it. |
231 | 231 | * @return bool|string |
232 | 232 | */ |
233 | - public static function compile_string( $string, $data = array() ) { |
|
233 | + public static function compile_string($string, $data = array()) { |
|
234 | 234 | $dummy_loader = new TimberLoader(); |
235 | 235 | $dummy_loader->get_twig(); |
236 | 236 | $loader = new Twig_Loader_String(); |
237 | - $twig = new Twig_Environment( $loader ); |
|
238 | - $twig = apply_filters( 'timber/twig/filters', $twig ); |
|
239 | - $twig = apply_filters( 'twig_apply_filters', $twig ); |
|
240 | - return $twig->render( $string, $data ); |
|
237 | + $twig = new Twig_Environment($loader); |
|
238 | + $twig = apply_filters('timber/twig/filters', $twig); |
|
239 | + $twig = apply_filters('twig_apply_filters', $twig); |
|
240 | + return $twig->render($string, $data); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -249,15 +249,15 @@ discard block |
||
249 | 249 | * @param string $cache_mode |
250 | 250 | * @return bool|string |
251 | 251 | */ |
252 | - public static function fetch( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT ) { |
|
252 | + public static function fetch($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT) { |
|
253 | 253 | if ( $expires === true ) { |
254 | 254 | //if this is reading as true; the user probably is using the old $echo param |
255 | 255 | //so we should move all vars up by a spot |
256 | 256 | $expires = $cache_mode; |
257 | 257 | $cache_mode = TimberLoader::CACHE_USE_DEFAULT; |
258 | 258 | } |
259 | - $output = self::compile( $filenames, $data, $expires, $cache_mode, true ); |
|
260 | - $output = apply_filters( 'timber_compile_result', $output ); |
|
259 | + $output = self::compile($filenames, $data, $expires, $cache_mode, true); |
|
260 | + $output = apply_filters('timber_compile_result', $output); |
|
261 | 261 | return $output; |
262 | 262 | } |
263 | 263 | |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | * @param string $cache_mode |
271 | 271 | * @return bool|string |
272 | 272 | */ |
273 | - public static function render( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT ) { |
|
274 | - $output = static::fetch( $filenames, $data, $expires, $cache_mode ); |
|
273 | + public static function render($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT) { |
|
274 | + $output = static::fetch($filenames, $data, $expires, $cache_mode); |
|
275 | 275 | echo $output; |
276 | 276 | return $output; |
277 | 277 | } |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | * @param array $data an array with data in it. |
284 | 284 | * @return bool|string |
285 | 285 | */ |
286 | - public static function render_string( $string, $data = array() ) { |
|
287 | - $compiled = self::compile_string( $string, $data ); |
|
286 | + public static function render_string($string, $data = array()) { |
|
287 | + $compiled = self::compile_string($string, $data); |
|
288 | 288 | echo $compiled; |
289 | 289 | return $compiled; |
290 | 290 | } |
@@ -300,14 +300,14 @@ discard block |
||
300 | 300 | * @param array $data |
301 | 301 | * @return bool|string |
302 | 302 | */ |
303 | - public static function get_sidebar( $sidebar = '', $data = array() ) { |
|
303 | + public static function get_sidebar($sidebar = '', $data = array()) { |
|
304 | 304 | if ( $sidebar == '' ) { |
305 | 305 | $sidebar = 'sidebar.php'; |
306 | 306 | } |
307 | - if ( strstr( strtolower( $sidebar ), '.php' ) ) { |
|
308 | - return self::get_sidebar_from_php( $sidebar, $data ); |
|
307 | + if ( strstr(strtolower($sidebar), '.php') ) { |
|
308 | + return self::get_sidebar_from_php($sidebar, $data); |
|
309 | 309 | } |
310 | - return self::compile( $sidebar, $data ); |
|
310 | + return self::compile($sidebar, $data); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -317,21 +317,21 @@ discard block |
||
317 | 317 | * @param array $data |
318 | 318 | * @return string |
319 | 319 | */ |
320 | - public static function get_sidebar_from_php( $sidebar = '', $data ) { |
|
320 | + public static function get_sidebar_from_php($sidebar = '', $data) { |
|
321 | 321 | $caller = self::get_calling_script_dir(); |
322 | 322 | $loader = new TimberLoader(); |
323 | - $uris = $loader->get_locations( $caller ); |
|
323 | + $uris = $loader->get_locations($caller); |
|
324 | 324 | ob_start(); |
325 | 325 | $found = false; |
326 | 326 | foreach ( $uris as $uri ) { |
327 | - if ( file_exists( trailingslashit( $uri ) . $sidebar ) ) { |
|
328 | - include trailingslashit( $uri ) . $sidebar; |
|
327 | + if ( file_exists(trailingslashit($uri) . $sidebar) ) { |
|
328 | + include trailingslashit($uri) . $sidebar; |
|
329 | 329 | $found = true; |
330 | 330 | break; |
331 | 331 | } |
332 | 332 | } |
333 | 333 | if ( !$found ) { |
334 | - TimberHelper::error_log( 'error loading your sidebar, check to make sure the file exists' ); |
|
334 | + TimberHelper::error_log('error loading your sidebar, check to make sure the file exists'); |
|
335 | 335 | } |
336 | 336 | $ret = ob_get_contents(); |
337 | 337 | ob_end_clean(); |
@@ -347,8 +347,8 @@ discard block |
||
347 | 347 | * @param int $widget_id |
348 | 348 | * @return TimberFunctionWrapper |
349 | 349 | */ |
350 | - public static function get_widgets( $widget_id ) { |
|
351 | - return trim( TimberHelper::function_wrapper( 'dynamic_sidebar', array( $widget_id ), true ) ); |
|
350 | + public static function get_widgets($widget_id) { |
|
351 | + return trim(TimberHelper::function_wrapper('dynamic_sidebar', array($widget_id), true)); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | |
@@ -363,8 +363,8 @@ discard block |
||
363 | 363 | * @param array $args |
364 | 364 | * @deprecated since 0.20.0 |
365 | 365 | */ |
366 | - public static function add_route( $route, $callback, $args = array() ) { |
|
367 | - Routes::map( $route, $callback, $args ); |
|
366 | + public static function add_route($route, $callback, $args = array()) { |
|
367 | + Routes::map($route, $callback, $args); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @deprecated since 0.20.0 |
374 | 374 | */ |
375 | - public static function load_template( $template, $query = false, $status_code = 200, $tparams = false ) { |
|
376 | - return Routes::load( $template, $tparams, $query, $status_code ); |
|
375 | + public static function load_template($template, $query = false, $status_code = 200, $tparams = false) { |
|
376 | + return Routes::load($template, $tparams, $query, $status_code); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
@@ -381,8 +381,8 @@ discard block |
||
381 | 381 | * |
382 | 382 | * @deprecated since 0.20.2 |
383 | 383 | */ |
384 | - public static function load_view( $template, $query = false, $status_code = 200, $tparams = false ) { |
|
385 | - return Routes::load( $template, $tparams, $query, $status_code ); |
|
384 | + public static function load_view($template, $query = false, $status_code = 200, $tparams = false) { |
|
385 | + return Routes::load($template, $tparams, $query, $status_code); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | |
@@ -395,43 +395,43 @@ discard block |
||
395 | 395 | * @param array $prefs |
396 | 396 | * @return array mixed |
397 | 397 | */ |
398 | - public static function get_pagination( $prefs = array() ) { |
|
398 | + public static function get_pagination($prefs = array()) { |
|
399 | 399 | global $wp_query; |
400 | 400 | global $paged; |
401 | 401 | global $wp_rewrite; |
402 | 402 | $args = array(); |
403 | - $args['total'] = ceil( $wp_query->found_posts / $wp_query->query_vars['posts_per_page'] ); |
|
403 | + $args['total'] = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']); |
|
404 | 404 | if ( $wp_rewrite->using_permalinks() ) { |
405 | - $url = explode( '?', get_pagenum_link( 0 ) ); |
|
406 | - if ( isset( $url[1] ) ) { |
|
407 | - parse_str( $url[1], $query ); |
|
405 | + $url = explode('?', get_pagenum_link(0)); |
|
406 | + if ( isset($url[1]) ) { |
|
407 | + parse_str($url[1], $query); |
|
408 | 408 | $args['add_args'] = $query; |
409 | 409 | } |
410 | 410 | $args['format'] = 'page/%#%'; |
411 | - $args['base'] = trailingslashit( $url[0] ).'%_%'; |
|
411 | + $args['base'] = trailingslashit($url[0]) . '%_%'; |
|
412 | 412 | } else { |
413 | 413 | $big = 999999999; |
414 | - $args['base'] = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ); |
|
414 | + $args['base'] = str_replace($big, '%#%', esc_url(get_pagenum_link($big))); |
|
415 | 415 | } |
416 | 416 | $args['type'] = 'array'; |
417 | - $args['current'] = max( 1, get_query_var( 'paged' ) ); |
|
418 | - $args['mid_size'] = max( 9 - $args['current'], 3 ); |
|
419 | - if ( is_int( $prefs ) ) { |
|
417 | + $args['current'] = max(1, get_query_var('paged')); |
|
418 | + $args['mid_size'] = max(9 - $args['current'], 3); |
|
419 | + if ( is_int($prefs) ) { |
|
420 | 420 | $args['mid_size'] = $prefs - 2; |
421 | 421 | } else { |
422 | - $args = array_merge( $args, $prefs ); |
|
422 | + $args = array_merge($args, $prefs); |
|
423 | 423 | } |
424 | 424 | $data = array(); |
425 | 425 | $data['current'] = $args['current']; |
426 | 426 | $data['total'] = $args['total']; |
427 | - $data['pages'] = TimberHelper::paginate_links( $args ); |
|
428 | - $next = get_next_posts_page_link( $args['total'] ); |
|
427 | + $data['pages'] = TimberHelper::paginate_links($args); |
|
428 | + $next = get_next_posts_page_link($args['total']); |
|
429 | 429 | if ( $next ) { |
430 | - $data['next'] = array( 'link' => untrailingslashit( $next ), 'class' => 'page-numbers next' ); |
|
430 | + $data['next'] = array('link' => untrailingslashit($next), 'class' => 'page-numbers next'); |
|
431 | 431 | } |
432 | - $prev = previous_posts( false ); |
|
432 | + $prev = previous_posts(false); |
|
433 | 433 | if ( $prev ) { |
434 | - $data['prev'] = array( 'link' => untrailingslashit( $prev ), 'class' => 'page-numbers prev' ); |
|
434 | + $data['prev'] = array('link' => untrailingslashit($prev), 'class' => 'page-numbers prev'); |
|
435 | 435 | } |
436 | 436 | if ( $paged < 2 ) { |
437 | 437 | $data['prev'] = ''; |
@@ -447,10 +447,10 @@ discard block |
||
447 | 447 | * |
448 | 448 | * @return string |
449 | 449 | */ |
450 | - public static function get_calling_script_dir( $offset = 0 ) { |
|
451 | - $caller = self::get_calling_script_file( $offset ); |
|
452 | - if ( !is_null( $caller ) ) { |
|
453 | - $pathinfo = pathinfo( $caller ); |
|
450 | + public static function get_calling_script_dir($offset = 0) { |
|
451 | + $caller = self::get_calling_script_file($offset); |
|
452 | + if ( !is_null($caller) ) { |
|
453 | + $pathinfo = pathinfo($caller); |
|
454 | 454 | $dir = $pathinfo['dirname']; |
455 | 455 | return $dir; |
456 | 456 | } |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | * @return string|null |
464 | 464 | * @deprecated since 0.20.0 |
465 | 465 | */ |
466 | - public static function get_calling_script_file( $offset = 0 ) { |
|
466 | + public static function get_calling_script_file($offset = 0) { |
|
467 | 467 | $caller = null; |
468 | 468 | $backtrace = debug_backtrace(); |
469 | 469 | $i = 0; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $args['include'] = $args['term_id']; |
65 | 65 | } |
66 | 66 | $terms = get_terms($taxonomies, $args); |
67 | - foreach ($terms as &$term) { |
|
67 | + foreach ( $terms as &$term ) { |
|
68 | 68 | $term = new $TermClass($term->term_id, $term->taxonomy); |
69 | 69 | } |
70 | 70 | return $terms; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | if ( is_string($taxs) ) { |
169 | 169 | $taxs = array($taxs); |
170 | 170 | } |
171 | - foreach ($taxs as &$tax) { |
|
171 | + foreach ( $taxs as &$tax ) { |
|
172 | 172 | if ( $tax == 'tags' || $tax == 'tag' ) { |
173 | 173 | $tax = 'post_tag'; |
174 | 174 | } else if ( $tax == 'categories' ) { |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | function init($cid) { |
56 | 56 | $comment_data = $cid; |
57 | - if (is_integer($cid)) { |
|
57 | + if ( is_integer($cid) ) { |
|
58 | 58 | $comment_data = get_comment($cid); |
59 | 59 | } |
60 | 60 | $this->import($comment_data); |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | * @return TimberUser |
87 | 87 | */ |
88 | 88 | public function author() { |
89 | - if ($this->user_id) { |
|
89 | + if ( $this->user_id ) { |
|
90 | 90 | return new TimberUser($this->user_id); |
91 | 91 | } else { |
92 | 92 | $author = new TimberUser(0); |
93 | - if (isset($this->comment_author) && $this->comment_author) { |
|
93 | + if ( isset($this->comment_author) && $this->comment_author ) { |
|
94 | 94 | $author->name = $this->comment_author; |
95 | 95 | } else { |
96 | 96 | $author->name = 'Anonymous'; |
@@ -114,21 +114,21 @@ discard block |
||
114 | 114 | * @return bool|mixed|string |
115 | 115 | */ |
116 | 116 | public function avatar($size = 92, $default = '') { |
117 | - if (!get_option('show_avatars')) { |
|
117 | + if ( !get_option('show_avatars') ) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | - if (!is_numeric($size)) { |
|
120 | + if ( !is_numeric($size) ) { |
|
121 | 121 | $size = '92'; |
122 | 122 | } |
123 | 123 | |
124 | 124 | $email = $this->avatar_email(); |
125 | 125 | $email_hash = ''; |
126 | - if (!empty($email)) { |
|
126 | + if ( !empty($email) ) { |
|
127 | 127 | $email_hash = md5(strtolower(trim($email))); |
128 | 128 | } |
129 | 129 | $host = $this->avatar_host($email_hash); |
130 | 130 | $default = $this->avatar_default($default, $email, $size, $host); |
131 | - if (!empty($email)) { |
|
131 | + if ( !empty($email) ) { |
|
132 | 132 | $avatar = $this->avatar_out($default, $host, $email_hash, $size); |
133 | 133 | } else { |
134 | 134 | $avatar = $default; |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | * ``` |
180 | 180 | * @return string |
181 | 181 | */ |
182 | - public function date( $date_format = '' ) { |
|
182 | + public function date($date_format = '') { |
|
183 | 183 | $df = $date_format ? $date_format : get_option('date_format'); |
184 | - $the_date = (string)mysql2date($df, $this->comment_date); |
|
184 | + $the_date = (string) mysql2date($df, $this->comment_date); |
|
185 | 185 | return apply_filters('get_comment_date ', $the_date, $df); |
186 | 186 | } |
187 | 187 | |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | * ``` |
205 | 205 | * @return string |
206 | 206 | */ |
207 | - public function time( $time_format = '' ) { |
|
207 | + public function time($time_format = '') { |
|
208 | 208 | $tf = $time_format ? $time_format : get_option('time_format'); |
209 | - $the_time = (string)mysql2date($tf, $this->comment_date); |
|
209 | + $the_time = (string) mysql2date($tf, $this->comment_date); |
|
210 | 210 | return apply_filters('get_comment_time', $the_time, $tf); |
211 | 211 | } |
212 | 212 | |
@@ -232,14 +232,14 @@ discard block |
||
232 | 232 | * @return mixed |
233 | 233 | */ |
234 | 234 | protected function get_meta_fields($comment_id = null) { |
235 | - if ($comment_id === null) { |
|
235 | + if ( $comment_id === null ) { |
|
236 | 236 | $comment_id = $this->ID; |
237 | 237 | } |
238 | 238 | //Could not find a WP function to fetch all comment meta data, so I made one. |
239 | 239 | apply_filters('timber_comment_get_meta_pre', array(), $comment_id); |
240 | 240 | $comment_metas = get_comment_meta($comment_id); |
241 | - foreach ($comment_metas as &$cm) { |
|
242 | - if (is_array($cm) && count($cm) == 1) { |
|
241 | + foreach ( $comment_metas as &$cm ) { |
|
242 | + if ( is_array($cm) && count($cm) == 1 ) { |
|
243 | 243 | $cm = $cm[0]; |
244 | 244 | } |
245 | 245 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | */ |
255 | 255 | protected function get_meta_field($field_name) { |
256 | 256 | $value = apply_filters('timber_comment_get_meta_field_pre', null, $this->ID, $field_name, $this); |
257 | - if ($value === null) { |
|
257 | + if ( $value === null ) { |
|
258 | 258 | $value = get_comment_meta($this->ID, $field_name, true); |
259 | 259 | } |
260 | 260 | $value = apply_filters('timber_comment_get_meta_field', $value, $this->ID, $field_name, $this); |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | * @api |
268 | 268 | * @return string |
269 | 269 | */ |
270 | - public function reply_link( $reply_text = 'Reply' ) { |
|
270 | + public function reply_link($reply_text = 'Reply') { |
|
271 | 271 | if ( is_singular() && comments_open() && get_option('thread_comments') ) { |
272 | - wp_enqueue_script( 'comment-reply' ); |
|
272 | + wp_enqueue_script('comment-reply'); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | // Get the comments depth option from the admin panel |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | 'max_depth' => $max_depth, |
285 | 285 | ); |
286 | 286 | |
287 | - return get_comment_reply_link( $args, $this->ID, $this->post_id ); |
|
287 | + return get_comment_reply_link($args, $this->ID, $this->post_id); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /* AVATAR Stuff |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | * @return string |
296 | 296 | */ |
297 | 297 | protected function avatar_email() { |
298 | - $id = (int)$this->user_id; |
|
298 | + $id = (int) $this->user_id; |
|
299 | 299 | $user = get_userdata($id); |
300 | - if ($user) { |
|
300 | + if ( $user ) { |
|
301 | 301 | $email = $user->user_email; |
302 | 302 | } else { |
303 | 303 | $email = $this->comment_author_email; |
@@ -311,10 +311,10 @@ discard block |
||
311 | 311 | * @return string |
312 | 312 | */ |
313 | 313 | protected function avatar_host($email_hash) { |
314 | - if (is_ssl()) { |
|
314 | + if ( is_ssl() ) { |
|
315 | 315 | $host = 'https://secure.gravatar.com'; |
316 | 316 | } else { |
317 | - if (!empty($email_hash)) { |
|
317 | + if ( !empty($email_hash) ) { |
|
318 | 318 | $host = sprintf("http://%d.gravatar.com", (hexdec($email_hash[0]) % 2)); |
319 | 319 | } else { |
320 | 320 | $host = 'http://0.gravatar.com'; |
@@ -333,28 +333,28 @@ discard block |
||
333 | 333 | * @return string |
334 | 334 | */ |
335 | 335 | protected function avatar_default($default, $email, $size, $host) { |
336 | - if (substr($default, 0, 1) == '/') { |
|
336 | + if ( substr($default, 0, 1) == '/' ) { |
|
337 | 337 | $default = home_url() . $default; |
338 | 338 | } |
339 | 339 | |
340 | - if (empty($default)) { |
|
340 | + if ( empty($default) ) { |
|
341 | 341 | $avatar_default = get_option('avatar_default'); |
342 | - if (empty($avatar_default)) { |
|
342 | + if ( empty($avatar_default) ) { |
|
343 | 343 | $default = 'mystery'; |
344 | 344 | } else { |
345 | 345 | $default = $avatar_default; |
346 | 346 | } |
347 | 347 | } |
348 | - if ('mystery' == $default) { |
|
348 | + if ( 'mystery' == $default ) { |
|
349 | 349 | $default = $host . '/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size; |
350 | 350 | // ad516503a11cd5ca435acc9bb6523536 == md5('[email protected]') |
351 | - } else if ('blank' == $default) { |
|
351 | + } else if ( 'blank' == $default ) { |
|
352 | 352 | $default = $email ? 'blank' : includes_url('images/blank.gif'); |
353 | - } else if (!empty($email) && 'gravatar_default' == $default) { |
|
353 | + } else if ( !empty($email) && 'gravatar_default' == $default ) { |
|
354 | 354 | $default = ''; |
355 | - } else if ('gravatar_default' == $default) { |
|
355 | + } else if ( 'gravatar_default' == $default ) { |
|
356 | 356 | $default = $host . '/avatar/?s=' . $size; |
357 | - } else if (empty($email) && !strstr($default, 'http://')) { |
|
357 | + } else if ( empty($email) && !strstr($default, 'http://') ) { |
|
358 | 358 | $default = $host . '/avatar/?d=' . $default . '&s=' . $size; |
359 | 359 | } |
360 | 360 | return $default; |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | protected function avatar_out($default, $host, $email_hash, $size) { |
372 | 372 | $out = $host . '/avatar/' . $email_hash . '?s=' . $size . '&d=' . urlencode($default); |
373 | 373 | $rating = get_option('avatar_rating'); |
374 | - if (!empty($rating)) { |
|
374 | + if ( !empty($rating) ) { |
|
375 | 375 | $out .= '&r=' . $rating; |
376 | 376 | } |
377 | 377 | return str_replace('&', '&', esc_url($out)); |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | * @codeCoverageIgnore |
16 | 16 | */ |
17 | 17 | function __construct() { |
18 | - add_action( 'timber/twig/filters', array( $this, 'add_timber_filters_deprecated' ) ); |
|
19 | - add_action( 'timber/twig/filters', array( $this, 'add_timber_filters' ) ); |
|
18 | + add_action('timber/twig/filters', array($this, 'add_timber_filters_deprecated')); |
|
19 | + add_action('timber/twig/filters', array($this, 'add_timber_filters')); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | * @deprecated since 0.20.7 |
27 | 27 | * @return Twig_Environment |
28 | 28 | */ |
29 | - function add_timber_filters_deprecated( $twig ) { |
|
30 | - $twig->addFilter( new Twig_SimpleFilter( 'get_src_from_attachment_id', 'twig_get_src_from_attachment_id' ) ); |
|
31 | - $twig->addFilter( new Twig_SimpleFilter( 'wp_body_class', array( $this, 'body_class' ) ) ); |
|
32 | - $twig->addFilter( new Twig_SimpleFilter( 'twitterify', array( 'TimberHelper', 'twitterify' ) ) ); |
|
33 | - $twig->addFilter( new Twig_SimpleFilter( 'twitterfy', array( 'TimberHelper', 'twitterify' ) ) ); |
|
34 | - $twig->addFilter( new Twig_SimpleFilter( 'string', function($arr, $glue = ' '){ |
|
29 | + function add_timber_filters_deprecated($twig) { |
|
30 | + $twig->addFilter(new Twig_SimpleFilter('get_src_from_attachment_id', 'twig_get_src_from_attachment_id')); |
|
31 | + $twig->addFilter(new Twig_SimpleFilter('wp_body_class', array($this, 'body_class'))); |
|
32 | + $twig->addFilter(new Twig_SimpleFilter('twitterify', array('TimberHelper', 'twitterify'))); |
|
33 | + $twig->addFilter(new Twig_SimpleFilter('twitterfy', array('TimberHelper', 'twitterify'))); |
|
34 | + $twig->addFilter(new Twig_SimpleFilter('string', function($arr, $glue = ' ') { |
|
35 | 35 | return twig_join_filter($arr, $glue); |
36 | - } ) ); |
|
36 | + } )); |
|
37 | 37 | return $twig; |
38 | 38 | } |
39 | 39 | |
@@ -43,151 +43,151 @@ discard block |
||
43 | 43 | * @param Twig_Environment $twig |
44 | 44 | * @return Twig_Environment |
45 | 45 | */ |
46 | - function add_timber_filters( $twig ) { |
|
46 | + function add_timber_filters($twig) { |
|
47 | 47 | /* image filters */ |
48 | - $twig->addFilter( new Twig_SimpleFilter( 'resize', array( 'TimberImageHelper', 'resize' ) ) ); |
|
49 | - $twig->addFilter( new Twig_SimpleFilter( 'retina', array( 'TimberImageHelper', 'retina_resize' ) ) ); |
|
50 | - $twig->addFilter( new Twig_SimpleFilter( 'letterbox', array( 'TimberImageHelper', 'letterbox' ) ) ); |
|
51 | - $twig->addFilter( new Twig_SimpleFilter( 'tojpg', array( 'TimberImageHelper', 'img_to_jpg' ) ) ); |
|
48 | + $twig->addFilter(new Twig_SimpleFilter('resize', array('TimberImageHelper', 'resize'))); |
|
49 | + $twig->addFilter(new Twig_SimpleFilter('retina', array('TimberImageHelper', 'retina_resize'))); |
|
50 | + $twig->addFilter(new Twig_SimpleFilter('letterbox', array('TimberImageHelper', 'letterbox'))); |
|
51 | + $twig->addFilter(new Twig_SimpleFilter('tojpg', array('TimberImageHelper', 'img_to_jpg'))); |
|
52 | 52 | |
53 | 53 | /* debugging filters */ |
54 | - $twig->addFilter( new Twig_SimpleFilter( 'docs', 'twig_object_docs' ) ); |
|
55 | - $twig->addFilter( new Twig_SimpleFilter( 'get_class', 'get_class' ) ); |
|
56 | - $twig->addFilter( new Twig_SimpleFilter( 'get_type', 'get_type' ) ); |
|
57 | - $twig->addFilter( new Twig_SimpleFilter( 'print_r', function( $arr ) { |
|
58 | - return print_r( $arr, true ); |
|
59 | - } ) ); |
|
60 | - $twig->addFilter( new Twig_SimpleFilter( 'print_a', function( $arr ) { |
|
61 | - return '<pre>' . self::object_docs( $arr, true ) . '</pre>'; |
|
62 | - } ) ); |
|
54 | + $twig->addFilter(new Twig_SimpleFilter('docs', 'twig_object_docs')); |
|
55 | + $twig->addFilter(new Twig_SimpleFilter('get_class', 'get_class')); |
|
56 | + $twig->addFilter(new Twig_SimpleFilter('get_type', 'get_type')); |
|
57 | + $twig->addFilter(new Twig_SimpleFilter('print_r', function($arr) { |
|
58 | + return print_r($arr, true); |
|
59 | + } )); |
|
60 | + $twig->addFilter(new Twig_SimpleFilter('print_a', function($arr) { |
|
61 | + return '<pre>' . self::object_docs($arr, true) . '</pre>'; |
|
62 | + } )); |
|
63 | 63 | |
64 | 64 | /* other filters */ |
65 | - $twig->addFilter( new Twig_SimpleFilter( 'stripshortcodes', 'strip_shortcodes' ) ); |
|
66 | - $twig->addFilter( new Twig_SimpleFilter( 'array', array( $this, 'to_array' ) ) ); |
|
67 | - $twig->addFilter( new Twig_SimpleFilter( 'excerpt', 'wp_trim_words' ) ); |
|
68 | - $twig->addFilter( new Twig_SimpleFilter( 'function', array( $this, 'exec_function' ) ) ); |
|
69 | - $twig->addFilter( new Twig_SimpleFilter( 'pretags', array( $this, 'twig_pretags' ) ) ); |
|
70 | - $twig->addFilter( new Twig_SimpleFilter( 'sanitize', 'sanitize_title' ) ); |
|
71 | - $twig->addFilter( new Twig_SimpleFilter( 'shortcodes', 'do_shortcode' ) ); |
|
72 | - $twig->addFilter( new Twig_SimpleFilter( 'time_ago', array( $this, 'time_ago' ) ) ); |
|
73 | - $twig->addFilter( new Twig_SimpleFilter( 'wpautop', 'wpautop' ) ); |
|
74 | - $twig->addFilter( new Twig_SimpleFilter( 'list', array( $this, 'add_list_separators' ) ) ); |
|
75 | - |
|
76 | - $twig->addFilter( new Twig_SimpleFilter( 'relative', function ( $link ) { |
|
77 | - return TimberURLHelper::get_rel_url( $link, true ); |
|
78 | - } ) ); |
|
79 | - |
|
80 | - $twig->addFilter( new Twig_SimpleFilter( 'date', array( $this, 'intl_date' ) ) ); |
|
81 | - |
|
82 | - $twig->addFilter( new Twig_SimpleFilter( 'truncate', function ( $text, $len ) { |
|
83 | - return TimberHelper::trim_words( $text, $len ); |
|
84 | - } ) ); |
|
65 | + $twig->addFilter(new Twig_SimpleFilter('stripshortcodes', 'strip_shortcodes')); |
|
66 | + $twig->addFilter(new Twig_SimpleFilter('array', array($this, 'to_array'))); |
|
67 | + $twig->addFilter(new Twig_SimpleFilter('excerpt', 'wp_trim_words')); |
|
68 | + $twig->addFilter(new Twig_SimpleFilter('function', array($this, 'exec_function'))); |
|
69 | + $twig->addFilter(new Twig_SimpleFilter('pretags', array($this, 'twig_pretags'))); |
|
70 | + $twig->addFilter(new Twig_SimpleFilter('sanitize', 'sanitize_title')); |
|
71 | + $twig->addFilter(new Twig_SimpleFilter('shortcodes', 'do_shortcode')); |
|
72 | + $twig->addFilter(new Twig_SimpleFilter('time_ago', array($this, 'time_ago'))); |
|
73 | + $twig->addFilter(new Twig_SimpleFilter('wpautop', 'wpautop')); |
|
74 | + $twig->addFilter(new Twig_SimpleFilter('list', array($this, 'add_list_separators'))); |
|
75 | + |
|
76 | + $twig->addFilter(new Twig_SimpleFilter('relative', function($link) { |
|
77 | + return TimberURLHelper::get_rel_url($link, true); |
|
78 | + } )); |
|
79 | + |
|
80 | + $twig->addFilter(new Twig_SimpleFilter('date', array($this, 'intl_date'))); |
|
81 | + |
|
82 | + $twig->addFilter(new Twig_SimpleFilter('truncate', function($text, $len) { |
|
83 | + return TimberHelper::trim_words($text, $len); |
|
84 | + } )); |
|
85 | 85 | |
86 | 86 | /* actions and filters */ |
87 | - $twig->addFunction( new Twig_SimpleFunction( 'action', function ( $context ) { |
|
87 | + $twig->addFunction(new Twig_SimpleFunction('action', function($context) { |
|
88 | 88 | $args = func_get_args(); |
89 | - array_shift( $args ); |
|
89 | + array_shift($args); |
|
90 | 90 | $args[] = $context; |
91 | - call_user_func_array( 'do_action', $args ); |
|
92 | - }, array( 'needs_context' => true ) ) ); |
|
91 | + call_user_func_array('do_action', $args); |
|
92 | + }, array('needs_context' => true))); |
|
93 | 93 | |
94 | - $twig->addFilter( new Twig_SimpleFilter( 'apply_filters', function () { |
|
94 | + $twig->addFilter(new Twig_SimpleFilter('apply_filters', function() { |
|
95 | 95 | $args = func_get_args(); |
96 | - $tag = current( array_splice( $args, 1, 1 ) ); |
|
96 | + $tag = current(array_splice($args, 1, 1)); |
|
97 | 97 | |
98 | - return apply_filters_ref_array( $tag, $args ); |
|
99 | - } ) ); |
|
100 | - $twig->addFunction( new Twig_SimpleFunction( 'function', array( &$this, 'exec_function' ) ) ); |
|
101 | - $twig->addFunction( new Twig_SimpleFunction( 'fn', array( &$this, 'exec_function' ) ) ); |
|
98 | + return apply_filters_ref_array($tag, $args); |
|
99 | + } )); |
|
100 | + $twig->addFunction(new Twig_SimpleFunction('function', array(&$this, 'exec_function'))); |
|
101 | + $twig->addFunction(new Twig_SimpleFunction('fn', array(&$this, 'exec_function'))); |
|
102 | 102 | |
103 | - $twig->addFunction( new Twig_SimpleFunction( 'shortcode', 'do_shortcode' ) ); |
|
103 | + $twig->addFunction(new Twig_SimpleFunction('shortcode', 'do_shortcode')); |
|
104 | 104 | |
105 | 105 | /* TimberObjects */ |
106 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberPost', function ( $pid, $PostClass = 'TimberPost' ) { |
|
107 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
106 | + $twig->addFunction(new Twig_SimpleFunction('TimberPost', function($pid, $PostClass = 'TimberPost') { |
|
107 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
108 | 108 | foreach ( $pid as &$p ) { |
109 | - $p = new $PostClass( $p ); |
|
109 | + $p = new $PostClass($p); |
|
110 | 110 | } |
111 | 111 | return $pid; |
112 | 112 | } |
113 | - return new $PostClass( $pid ); |
|
114 | - } ) ); |
|
115 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberImage', function ( $pid, $ImageClass = 'TimberImage' ) { |
|
116 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
113 | + return new $PostClass($pid); |
|
114 | + } )); |
|
115 | + $twig->addFunction(new Twig_SimpleFunction('TimberImage', function($pid, $ImageClass = 'TimberImage') { |
|
116 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
117 | 117 | foreach ( $pid as &$p ) { |
118 | - $p = new $ImageClass( $p ); |
|
118 | + $p = new $ImageClass($p); |
|
119 | 119 | } |
120 | 120 | return $pid; |
121 | 121 | } |
122 | - return new $ImageClass( $pid ); |
|
123 | - } ) ); |
|
124 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberTerm', function ( $pid, $TermClass = 'TimberTerm' ) { |
|
125 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
122 | + return new $ImageClass($pid); |
|
123 | + } )); |
|
124 | + $twig->addFunction(new Twig_SimpleFunction('TimberTerm', function($pid, $TermClass = 'TimberTerm') { |
|
125 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
126 | 126 | foreach ( $pid as &$p ) { |
127 | - $p = new $TermClass( $p ); |
|
127 | + $p = new $TermClass($p); |
|
128 | 128 | } |
129 | 129 | return $pid; |
130 | 130 | } |
131 | - return new $TermClass( $pid ); |
|
132 | - } ) ); |
|
133 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberUser', function ( $pid, $UserClass = 'TimberUser' ) { |
|
134 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
131 | + return new $TermClass($pid); |
|
132 | + } )); |
|
133 | + $twig->addFunction(new Twig_SimpleFunction('TimberUser', function($pid, $UserClass = 'TimberUser') { |
|
134 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
135 | 135 | foreach ( $pid as &$p ) { |
136 | - $p = new $UserClass( $p ); |
|
136 | + $p = new $UserClass($p); |
|
137 | 137 | } |
138 | 138 | return $pid; |
139 | 139 | } |
140 | - return new $UserClass( $pid ); |
|
141 | - } ) ); |
|
140 | + return new $UserClass($pid); |
|
141 | + } )); |
|
142 | 142 | |
143 | 143 | /* TimberObjects Alias */ |
144 | - $twig->addFunction( new Twig_SimpleFunction( 'Post', function ( $pid, $PostClass = 'TimberPost' ) { |
|
145 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
144 | + $twig->addFunction(new Twig_SimpleFunction('Post', function($pid, $PostClass = 'TimberPost') { |
|
145 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
146 | 146 | foreach ( $pid as &$p ) { |
147 | - $p = new $PostClass( $p ); |
|
147 | + $p = new $PostClass($p); |
|
148 | 148 | } |
149 | 149 | return $pid; |
150 | 150 | } |
151 | - return new $PostClass( $pid ); |
|
152 | - } ) ); |
|
153 | - $twig->addFunction( new Twig_SimpleFunction( 'Image', function ( $pid, $ImageClass = 'TimberImage' ) { |
|
154 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
151 | + return new $PostClass($pid); |
|
152 | + } )); |
|
153 | + $twig->addFunction(new Twig_SimpleFunction('Image', function($pid, $ImageClass = 'TimberImage') { |
|
154 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
155 | 155 | foreach ( $pid as &$p ) { |
156 | - $p = new $ImageClass( $p ); |
|
156 | + $p = new $ImageClass($p); |
|
157 | 157 | } |
158 | 158 | return $pid; |
159 | 159 | } |
160 | - return new $ImageClass( $pid ); |
|
161 | - } ) ); |
|
162 | - $twig->addFunction( new Twig_SimpleFunction( 'Term', function ( $pid, $TermClass = 'TimberTerm' ) { |
|
163 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
160 | + return new $ImageClass($pid); |
|
161 | + } )); |
|
162 | + $twig->addFunction(new Twig_SimpleFunction('Term', function($pid, $TermClass = 'TimberTerm') { |
|
163 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
164 | 164 | foreach ( $pid as &$p ) { |
165 | - $p = new $TermClass( $p ); |
|
165 | + $p = new $TermClass($p); |
|
166 | 166 | } |
167 | 167 | return $pid; |
168 | 168 | } |
169 | - return new $TermClass( $pid ); |
|
170 | - } ) ); |
|
171 | - $twig->addFunction( new Twig_SimpleFunction( 'User', function ( $pid, $UserClass = 'TimberUser' ) { |
|
172 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
169 | + return new $TermClass($pid); |
|
170 | + } )); |
|
171 | + $twig->addFunction(new Twig_SimpleFunction('User', function($pid, $UserClass = 'TimberUser') { |
|
172 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
173 | 173 | foreach ( $pid as &$p ) { |
174 | - $p = new $UserClass( $p ); |
|
174 | + $p = new $UserClass($p); |
|
175 | 175 | } |
176 | 176 | return $pid; |
177 | 177 | } |
178 | - return new $UserClass( $pid ); |
|
179 | - } ) ); |
|
178 | + return new $UserClass($pid); |
|
179 | + } )); |
|
180 | 180 | |
181 | 181 | /* bloginfo and translate */ |
182 | - $twig->addFunction( 'bloginfo', new Twig_SimpleFunction( 'bloginfo', function ( $show = '', $filter = 'raw' ) { |
|
183 | - return get_bloginfo( $show, $filter ); |
|
184 | - } ) ); |
|
185 | - $twig->addFunction( '__', new Twig_SimpleFunction( '__', function ( $text, $domain = 'default' ) { |
|
186 | - return __( $text, $domain ); |
|
187 | - } ) ); |
|
182 | + $twig->addFunction('bloginfo', new Twig_SimpleFunction('bloginfo', function($show = '', $filter = 'raw') { |
|
183 | + return get_bloginfo($show, $filter); |
|
184 | + } )); |
|
185 | + $twig->addFunction('__', new Twig_SimpleFunction('__', function($text, $domain = 'default') { |
|
186 | + return __($text, $domain); |
|
187 | + } )); |
|
188 | 188 | /* get_twig is deprecated, use timber/twig */ |
189 | - $twig = apply_filters( 'get_twig', $twig ); |
|
190 | - $twig = apply_filters( 'timber/twig', $twig ); |
|
189 | + $twig = apply_filters('get_twig', $twig); |
|
190 | + $twig = apply_filters('timber/twig', $twig); |
|
191 | 191 | return $twig; |
192 | 192 | } |
193 | 193 | |
@@ -197,11 +197,11 @@ discard block |
||
197 | 197 | * @param mixed $arr |
198 | 198 | * @return array |
199 | 199 | */ |
200 | - function to_array( $arr ) { |
|
201 | - if ( is_array( $arr ) ) { |
|
200 | + function to_array($arr) { |
|
201 | + if ( is_array($arr) ) { |
|
202 | 202 | return $arr; |
203 | 203 | } |
204 | - $arr = array( $arr ); |
|
204 | + $arr = array($arr); |
|
205 | 205 | return $arr; |
206 | 206 | } |
207 | 207 | |
@@ -211,13 +211,13 @@ discard block |
||
211 | 211 | * @param string $function_name |
212 | 212 | * @return mixed |
213 | 213 | */ |
214 | - function exec_function( $function_name ) { |
|
214 | + function exec_function($function_name) { |
|
215 | 215 | $args = func_get_args(); |
216 | - array_shift( $args ); |
|
216 | + array_shift($args); |
|
217 | 217 | if ( is_string($function_name) ) { |
218 | - $function_name = trim( $function_name ); |
|
218 | + $function_name = trim($function_name); |
|
219 | 219 | } |
220 | - return call_user_func_array( $function_name, ( $args ) ); |
|
220 | + return call_user_func_array($function_name, ($args)); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | * @param string $content |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - function twig_pretags( $content ) { |
|
230 | - return preg_replace_callback( '|<pre.*>(.*)</pre|isU', array( &$this, 'convert_pre_entities' ), $content ); |
|
229 | + function twig_pretags($content) { |
|
230 | + return preg_replace_callback('|<pre.*>(.*)</pre|isU', array(&$this, 'convert_pre_entities'), $content); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | * @param array $matches |
237 | 237 | * @return string |
238 | 238 | */ |
239 | - function convert_pre_entities( $matches ) { |
|
240 | - return str_replace( $matches[1], htmlentities( $matches[1] ), $matches[0] ); |
|
239 | + function convert_pre_entities($matches) { |
|
240 | + return str_replace($matches[1], htmlentities($matches[1]), $matches[0]); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -245,12 +245,12 @@ discard block |
||
245 | 245 | * @deprecated 0.20.7 |
246 | 246 | * @return string |
247 | 247 | */ |
248 | - function body_class( $body_classes ) { |
|
248 | + function body_class($body_classes) { |
|
249 | 249 | ob_start(); |
250 | - if ( is_array( $body_classes ) ) { |
|
251 | - $body_classes = explode( ' ', $body_classes ); |
|
250 | + if ( is_array($body_classes) ) { |
|
251 | + $body_classes = explode(' ', $body_classes); |
|
252 | 252 | } |
253 | - body_class( $body_classes ); |
|
253 | + body_class($body_classes); |
|
254 | 254 | $return = ob_get_contents(); |
255 | 255 | ob_end_clean(); |
256 | 256 | return $return; |
@@ -263,20 +263,20 @@ discard block |
||
263 | 263 | * @param string $format (optional) |
264 | 264 | * @return string |
265 | 265 | */ |
266 | - function intl_date( $date, $format = null ) { |
|
266 | + function intl_date($date, $format = null) { |
|
267 | 267 | if ( $format === null ) { |
268 | - $format = get_option( 'date_format' ); |
|
268 | + $format = get_option('date_format'); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | if ( $date instanceof DateTime ) { |
272 | 272 | $timestamp = $date->getTimestamp() + $date->getOffset(); |
273 | - } else if (is_numeric( $date ) && strtotime( $date ) === false ) { |
|
274 | - $timestamp = intval( $date ); |
|
273 | + } else if ( is_numeric($date) && strtotime($date) === false ) { |
|
274 | + $timestamp = intval($date); |
|
275 | 275 | } else { |
276 | - $timestamp = strtotime( $date ); |
|
276 | + $timestamp = strtotime($date); |
|
277 | 277 | } |
278 | 278 | |
279 | - return date_i18n( $format, $timestamp ); |
|
279 | + return date_i18n($format, $timestamp); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | //debug |
@@ -289,17 +289,17 @@ discard block |
||
289 | 289 | * @deprecated since 0.20.7 |
290 | 290 | * @return string |
291 | 291 | */ |
292 | - function object_docs( $obj, $methods = true ) { |
|
293 | - $class = get_class( $obj ); |
|
294 | - $properties = (array)$obj; |
|
292 | + function object_docs($obj, $methods = true) { |
|
293 | + $class = get_class($obj); |
|
294 | + $properties = (array) $obj; |
|
295 | 295 | if ( $methods ) { |
296 | 296 | /** @var array $methods */ |
297 | 297 | $methods = $obj->get_method_values(); |
298 | 298 | } |
299 | - $rets = array_merge( $properties, $methods ); |
|
300 | - ksort( $rets ); |
|
301 | - $str = print_r( $rets, true ); |
|
302 | - $str = str_replace( 'Array', $class . ' Object', $str ); |
|
299 | + $rets = array_merge($properties, $methods); |
|
300 | + ksort($rets); |
|
301 | + $str = print_r($rets, true); |
|
302 | + $str = str_replace('Array', $class . ' Object', $str); |
|
303 | 303 | return $str; |
304 | 304 | } |
305 | 305 | |
@@ -310,15 +310,15 @@ discard block |
||
310 | 310 | * @param string $format_future |
311 | 311 | * @return string |
312 | 312 | */ |
313 | - function time_ago( $from, $to = null, $format_past = '%s ago', $format_future = '%s from now' ) { |
|
313 | + function time_ago($from, $to = null, $format_past = '%s ago', $format_future = '%s from now') { |
|
314 | 314 | $to = $to === null ? time() : $to; |
315 | - $to = is_int( $to ) ? $to : strtotime( $to ); |
|
316 | - $from = is_int( $from ) ? $from : strtotime( $from ); |
|
315 | + $to = is_int($to) ? $to : strtotime($to); |
|
316 | + $from = is_int($from) ? $from : strtotime($from); |
|
317 | 317 | |
318 | 318 | if ( $from < $to ) { |
319 | - return sprintf( $format_past, human_time_diff( $from, $to ) ); |
|
319 | + return sprintf($format_past, human_time_diff($from, $to)); |
|
320 | 320 | } else { |
321 | - return sprintf( $format_future, human_time_diff( $to, $from ) ); |
|
321 | + return sprintf($format_future, human_time_diff($to, $from)); |
|
322 | 322 | } |
323 | 323 | } |
324 | 324 | |
@@ -328,18 +328,18 @@ discard block |
||
328 | 328 | * @param string $second_delimiter |
329 | 329 | * @return string |
330 | 330 | */ |
331 | - function add_list_separators( $arr, $first_delimiter = ',', $second_delimiter = 'and' ) { |
|
332 | - $length = count( $arr ); |
|
331 | + function add_list_separators($arr, $first_delimiter = ',', $second_delimiter = 'and') { |
|
332 | + $length = count($arr); |
|
333 | 333 | $list = ''; |
334 | - foreach( $arr as $index => $item ) { |
|
334 | + foreach ( $arr as $index => $item ) { |
|
335 | 335 | if ( $index < $length - 2 ) { |
336 | - $delimiter = $first_delimiter.' '; |
|
336 | + $delimiter = $first_delimiter . ' '; |
|
337 | 337 | } elseif ( $index == $length - 2 ) { |
338 | - $delimiter = ' '.$second_delimiter.' '; |
|
338 | + $delimiter = ' ' . $second_delimiter . ' '; |
|
339 | 339 | } else { |
340 | 340 | $delimiter = ''; |
341 | 341 | } |
342 | - $list = $list.$item.$delimiter; |
|
342 | + $list = $list . $item . $delimiter; |
|
343 | 343 | } |
344 | 344 | return $list; |
345 | 345 | } |
@@ -158,7 +158,7 @@ |
||
158 | 158 | $um = get_user_meta($this->ID); |
159 | 159 | } |
160 | 160 | $custom = array(); |
161 | - foreach ($um as $key => $value) { |
|
161 | + foreach ( $um as $key => $value ) { |
|
162 | 162 | if ( is_array($value) && count($value) == 1 ) { |
163 | 163 | $value = $value[0]; |
164 | 164 | } |