Completed
Pull Request — master (#892)
by Jared
02:40
created
timber.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,11 +14,11 @@
 block discarded – undo
14 14
 // we look for Composer files first in the plugins dir.
15 15
 // then in the wp-content dir (site install).
16 16
 // and finally in the current themes directories.
17
-if (   file_exists( $composer_autoload = __DIR__ . '/vendor/autoload.php' ) /* check in self */
18
-    || file_exists( $composer_autoload = WP_CONTENT_DIR.'/vendor/autoload.php') /* check in wp-content */
19
-    || file_exists( $composer_autoload = plugin_dir_path( __FILE__ ).'vendor/autoload.php') /* check in plugin directory */
20
-    || file_exists( $composer_autoload = get_stylesheet_directory().'/vendor/autoload.php') /* check in child theme */
21
-    || file_exists( $composer_autoload = get_template_directory().'/vendor/autoload.php') /* check in parent theme */
17
+if ( file_exists($composer_autoload = __DIR__ . '/vendor/autoload.php') /* check in self */
18
+    || file_exists($composer_autoload = WP_CONTENT_DIR . '/vendor/autoload.php') /* check in wp-content */
19
+    || file_exists($composer_autoload = plugin_dir_path(__FILE__) . 'vendor/autoload.php') /* check in plugin directory */
20
+    || file_exists($composer_autoload = get_stylesheet_directory() . '/vendor/autoload.php') /* check in child theme */
21
+    || file_exists($composer_autoload = get_template_directory() . '/vendor/autoload.php') /* check in parent theme */
22 22
 ) {
23 23
     require_once $composer_autoload;
24 24
 }
Please login to merge, or discard this patch.
lib/timber-request.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -3,32 +3,32 @@
 block discarded – undo
3 3
  * TimberRequest exposes $_GET and $_POST to the context
4 4
  */
5 5
 class TimberRequest extends TimberCore implements TimberCoreInterface {
6
-	public $post = array();
7
-	public $get = array();
6
+    public $post = array();
7
+    public $get = array();
8 8
 	
9
-	/**
10
-	 * Constructs a TimberRequest object
11
-	 * @example
12
-	 */
13
-	function __construct() {
14
-		$this->init();
15
-	}
16
-	/**
17
-	 * @internal
18
-	 */
19
-	protected function init() {
20
-		$this->post = $_POST;
21
-		$this->get = $_GET;
22
-	}
9
+    /**
10
+     * Constructs a TimberRequest object
11
+     * @example
12
+     */
13
+    function __construct() {
14
+        $this->init();
15
+    }
16
+    /**
17
+     * @internal
18
+     */
19
+    protected function init() {
20
+        $this->post = $_POST;
21
+        $this->get = $_GET;
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
-	/**
29
-	 * @return boolean
30
-	 */
31
-	public function __isset( $field ) {}
28
+    /**
29
+     * @return boolean
30
+     */
31
+    public function __isset( $field ) {}
32 32
 
33
-	public function meta( $key ) {}
33
+    public function meta( $key ) {}
34 34
 }
Please login to merge, or discard this patch.
lib/timber.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -345,7 +345,7 @@
 block discarded – undo
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 ) );
Please login to merge, or discard this patch.
Indentation   +442 added lines, -442 removed lines patch added patch discarded remove patch
@@ -17,468 +17,468 @@
 block discarded – undo
17 17
  */
18 18
 class Timber {
19 19
 
20
-	public static $locations;
21
-	public static $dirname;
22
-	public static $twig_cache = false;
23
-	public static $cache = false;
24
-	public static $auto_meta = true;
25
-	public static $autoescape = false;
26
-
27
-	/**
28
-	 * @codeCoverageIgnore
29
-	 */
30
-	public function __construct() {
31
-		if ( !defined('ABSPATH') ) {
32
-			return;
33
-		}
34
-		$this->test_compatibility();
35
-		$this->init_constants();
36
-		$this->init();
37
-	}
38
-
39
-	/**
40
-	 * Tests whether we can use Timber
41
-	 * @codeCoverageIgnore
42
-	 * @return
43
-	 */
44
-	protected function test_compatibility() {
45
-		if ( is_admin() || $_SERVER['PHP_SELF'] == '/wp-login.php' ) {
46
-			return;
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 );
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 );
53
-		}
54
-	}
55
-
56
-	function init_constants() {
57
-		defined( "TIMBER_LOC" ) or define( "TIMBER_LOC", realpath( dirname(__DIR__) ) );
58
-	}
59
-
60
-	/**
61
-	 * @codeCoverageIgnore
62
-	 */
63
-	protected function init() {
64
-		TimberTwig::init();
65
-		TimberRoutes::init( $this );
66
-		TimberImageHelper::init();
67
-		TimberAdmin::init();
68
-		TimberIntegrations::init();
69
-	}
70
-
71
-	/* Post Retrieval Routine
20
+    public static $locations;
21
+    public static $dirname;
22
+    public static $twig_cache = false;
23
+    public static $cache = false;
24
+    public static $auto_meta = true;
25
+    public static $autoescape = false;
26
+
27
+    /**
28
+     * @codeCoverageIgnore
29
+     */
30
+    public function __construct() {
31
+        if ( !defined('ABSPATH') ) {
32
+            return;
33
+        }
34
+        $this->test_compatibility();
35
+        $this->init_constants();
36
+        $this->init();
37
+    }
38
+
39
+    /**
40
+     * Tests whether we can use Timber
41
+     * @codeCoverageIgnore
42
+     * @return
43
+     */
44
+    protected function test_compatibility() {
45
+        if ( is_admin() || $_SERVER['PHP_SELF'] == '/wp-login.php' ) {
46
+            return;
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 );
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 );
53
+        }
54
+    }
55
+
56
+    function init_constants() {
57
+        defined( "TIMBER_LOC" ) or define( "TIMBER_LOC", realpath( dirname(__DIR__) ) );
58
+    }
59
+
60
+    /**
61
+     * @codeCoverageIgnore
62
+     */
63
+    protected function init() {
64
+        TimberTwig::init();
65
+        TimberRoutes::init( $this );
66
+        TimberImageHelper::init();
67
+        TimberAdmin::init();
68
+        TimberIntegrations::init();
69
+    }
70
+
71
+    /* Post Retrieval Routine
72 72
 	================================ */
73 73
 
74
-	/**
75
-	 * Get post.
76
-	 *
77
-	 * @param mixed   $query
78
-	 * @param string  $PostClass
79
-	 * @return array|bool|null
80
-	 */
81
-	public static function get_post( $query = false, $PostClass = 'TimberPost' ) {
82
-		return TimberPostGetter::get_post( $query, $PostClass );
83
-	}
84
-
85
-	/**
86
-	 * Get posts.
87
-	 *
88
-	 * @param mixed   $query
89
-	 * @param string  $PostClass
90
-	 * @return array|bool|null
91
-	 */
92
-	public static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) {
93
-		return TimberPostGetter::get_posts( $query, $PostClass, $return_collection );
94
-	}
95
-
96
-	/**
97
-	 * Query post.
98
-	 *
99
-	 * @param mixed   $query
100
-	 * @param string  $PostClass
101
-	 * @return array|bool|null
102
-	 */
103
-	public static function query_post( $query = false, $PostClass = 'TimberPost' ) {
104
-		return TimberPostGetter::query_post( $query, $PostClass );
105
-	}
106
-
107
-	/**
108
-	 * Query posts.
109
-	 *
110
-	 * @param mixed   $query
111
-	 * @param string  $PostClass
112
-	 * @return array|bool|null
113
-	 */
114
-	public static function query_posts( $query = false, $PostClass = 'TimberPost' ) {
115
-		return TimberPostGetter::query_posts( $query, $PostClass );
116
-	}
117
-
118
-	/**
119
-	 * WP_Query has posts.
120
-	 *
121
-	 * @return bool
122
-	 * @deprecated since 0.20.0
123
-	 */
124
-	static function wp_query_has_posts() {
125
-		return TimberPostGetter::wp_query_has_posts();
126
-	}
127
-
128
-	/* Term Retrieval
74
+    /**
75
+     * Get post.
76
+     *
77
+     * @param mixed   $query
78
+     * @param string  $PostClass
79
+     * @return array|bool|null
80
+     */
81
+    public static function get_post( $query = false, $PostClass = 'TimberPost' ) {
82
+        return TimberPostGetter::get_post( $query, $PostClass );
83
+    }
84
+
85
+    /**
86
+     * Get posts.
87
+     *
88
+     * @param mixed   $query
89
+     * @param string  $PostClass
90
+     * @return array|bool|null
91
+     */
92
+    public static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) {
93
+        return TimberPostGetter::get_posts( $query, $PostClass, $return_collection );
94
+    }
95
+
96
+    /**
97
+     * Query post.
98
+     *
99
+     * @param mixed   $query
100
+     * @param string  $PostClass
101
+     * @return array|bool|null
102
+     */
103
+    public static function query_post( $query = false, $PostClass = 'TimberPost' ) {
104
+        return TimberPostGetter::query_post( $query, $PostClass );
105
+    }
106
+
107
+    /**
108
+     * Query posts.
109
+     *
110
+     * @param mixed   $query
111
+     * @param string  $PostClass
112
+     * @return array|bool|null
113
+     */
114
+    public static function query_posts( $query = false, $PostClass = 'TimberPost' ) {
115
+        return TimberPostGetter::query_posts( $query, $PostClass );
116
+    }
117
+
118
+    /**
119
+     * WP_Query has posts.
120
+     *
121
+     * @return bool
122
+     * @deprecated since 0.20.0
123
+     */
124
+    static function wp_query_has_posts() {
125
+        return TimberPostGetter::wp_query_has_posts();
126
+    }
127
+
128
+    /* Term Retrieval
129 129
 	================================ */
130 130
 
131
-	/**
132
-	 * Get terms.
133
-	 *
134
-	 * @param string|array $args
135
-	 * @param array   $maybe_args
136
-	 * @param string  $TermClass
137
-	 * @return mixed
138
-	 */
139
-	public static function get_terms( $args = null, $maybe_args = array(), $TermClass = 'TimberTerm' ) {
140
-		return TimberTermGetter::get_terms( $args, $maybe_args, $TermClass );
141
-	}
142
-
143
-	/* Site Retrieval
131
+    /**
132
+     * Get terms.
133
+     *
134
+     * @param string|array $args
135
+     * @param array   $maybe_args
136
+     * @param string  $TermClass
137
+     * @return mixed
138
+     */
139
+    public static function get_terms( $args = null, $maybe_args = array(), $TermClass = 'TimberTerm' ) {
140
+        return TimberTermGetter::get_terms( $args, $maybe_args, $TermClass );
141
+    }
142
+
143
+    /* Site Retrieval
144 144
 	================================ */
145 145
 
146
-	/**
147
-	 * Get sites.
148
-	 *
149
-	 * @param array|bool $blog_ids
150
-	 * @return array
151
-	 */
152
-	public static function get_sites( $blog_ids = false ) {
153
-		if ( !is_array( $blog_ids ) ) {
154
-			global $wpdb;
155
-			$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC" );
156
-		}
157
-		$return = array();
158
-		foreach ( $blog_ids as $blog_id ) {
159
-			$return[] = new TimberSite( $blog_id );
160
-		}
161
-		return $return;
162
-	}
163
-
164
-
165
-	/*  Template Setup and Display
146
+    /**
147
+     * Get sites.
148
+     *
149
+     * @param array|bool $blog_ids
150
+     * @return array
151
+     */
152
+    public static function get_sites( $blog_ids = false ) {
153
+        if ( !is_array( $blog_ids ) ) {
154
+            global $wpdb;
155
+            $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC" );
156
+        }
157
+        $return = array();
158
+        foreach ( $blog_ids as $blog_id ) {
159
+            $return[] = new TimberSite( $blog_id );
160
+        }
161
+        return $return;
162
+    }
163
+
164
+
165
+    /*  Template Setup and Display
166 166
 	================================ */
167 167
 
168
-	/**
169
-	 * Get context.
170
-	 *
171
-	 * @return array
172
-	 */
173
-	public static function get_context() {
174
-		$data = array();
175
-		$data['http_host'] = 'http://' . TimberURLHelper::get_host();
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() );
180
-
181
-		$data['site'] = new TimberSite();
182
-		$data['request'] = new TimberRequest();
183
-		$data['theme'] = $data['site']->theme;
184
-
185
-		$data['posts'] = Timber::query_posts();
186
-
187
-		$data = apply_filters( 'timber_context', $data );
188
-		$data = apply_filters( 'timber/context', $data );
189
-		return $data;
190
-	}
191
-
192
-	/**
193
-	 * Compile function.
194
-	 *
195
-	 * @param array   $filenames
196
-	 * @param array   $data
197
-	 * @param bool    $expires
198
-	 * @param string  $cache_mode
199
-	 * @param bool    $via_render
200
-	 * @return bool|string
201
-	 */
202
-	public static function compile( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT, $via_render = false ) {
203
-		$caller = self::get_calling_script_dir();
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 );
208
-		$output = '';
209
-		if ( is_null( $data ) ) {
210
-			$data = array();
211
-		}
212
-		if ( strlen( $file ) ) {
213
-			if ( $via_render ) {
214
-				$file = apply_filters( 'timber_render_file', $file );
215
-				$data = apply_filters( 'timber_render_data', $data );
216
-			} else {
217
-				$file = apply_filters( 'timber_compile_file', $file );
218
-				$data = apply_filters( 'timber_compile_data', $data );
219
-			}
220
-			$output = $loader->render( $file, $data, $expires, $cache_mode );
221
-		}
222
-		do_action( 'timber_compile_done' );
223
-		return $output;
224
-	}
225
-
226
-	/**
227
-	 * Compile string.
228
-	 *
229
-	 * @param string  $string a string with twig variables.
230
-	 * @param array   $data   an array with data in it.
231
-	 * @return  bool|string
232
-	 */
233
-	public static function compile_string( $string, $data = array() ) {
234
-		$dummy_loader = new TimberLoader();
235
-		$dummy_loader->get_twig();
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 );
241
-	}
242
-
243
-	/**
244
-	 * Fetch function.
245
-	 *
246
-	 * @param array   $filenames
247
-	 * @param array   $data
248
-	 * @param bool    $expires
249
-	 * @param string  $cache_mode
250
-	 * @return bool|string
251
-	 */
252
-	public static function fetch( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT ) {
253
-		if ( $expires === true ) {
254
-			//if this is reading as true; the user probably is using the old $echo param
255
-			//so we should move all vars up by a spot
256
-			$expires = $cache_mode;
257
-			$cache_mode = TimberLoader::CACHE_USE_DEFAULT;
258
-		}
259
-		$output = self::compile( $filenames, $data, $expires, $cache_mode, true );
260
-		$output = apply_filters( 'timber_compile_result', $output );
261
-		return $output;
262
-	}
263
-
264
-	/**
265
-	 * Render function.
266
-	 *
267
-	 * @param array   $filenames
268
-	 * @param array   $data
269
-	 * @param bool    $expires
270
-	 * @param string  $cache_mode
271
-	 * @return bool|string
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 );
275
-		echo $output;
276
-		return $output;
277
-	}
278
-
279
-	/**
280
-	 * Render string.
281
-	 *
282
-	 * @param string  $string a string with twig variables.
283
-	 * @param array   $data   an array with data in it.
284
-	 * @return  bool|string
285
-	 */
286
-	public static function render_string( $string, $data = array() ) {
287
-		$compiled = self::compile_string( $string, $data );
288
-		echo $compiled;
289
-		return $compiled;
290
-	}
291
-
292
-
293
-	/*  Sidebar
168
+    /**
169
+     * Get context.
170
+     *
171
+     * @return array
172
+     */
173
+    public static function get_context() {
174
+        $data = array();
175
+        $data['http_host'] = 'http://' . TimberURLHelper::get_host();
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() );
180
+
181
+        $data['site'] = new TimberSite();
182
+        $data['request'] = new TimberRequest();
183
+        $data['theme'] = $data['site']->theme;
184
+
185
+        $data['posts'] = Timber::query_posts();
186
+
187
+        $data = apply_filters( 'timber_context', $data );
188
+        $data = apply_filters( 'timber/context', $data );
189
+        return $data;
190
+    }
191
+
192
+    /**
193
+     * Compile function.
194
+     *
195
+     * @param array   $filenames
196
+     * @param array   $data
197
+     * @param bool    $expires
198
+     * @param string  $cache_mode
199
+     * @param bool    $via_render
200
+     * @return bool|string
201
+     */
202
+    public static function compile( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT, $via_render = false ) {
203
+        $caller = self::get_calling_script_dir();
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 );
208
+        $output = '';
209
+        if ( is_null( $data ) ) {
210
+            $data = array();
211
+        }
212
+        if ( strlen( $file ) ) {
213
+            if ( $via_render ) {
214
+                $file = apply_filters( 'timber_render_file', $file );
215
+                $data = apply_filters( 'timber_render_data', $data );
216
+            } else {
217
+                $file = apply_filters( 'timber_compile_file', $file );
218
+                $data = apply_filters( 'timber_compile_data', $data );
219
+            }
220
+            $output = $loader->render( $file, $data, $expires, $cache_mode );
221
+        }
222
+        do_action( 'timber_compile_done' );
223
+        return $output;
224
+    }
225
+
226
+    /**
227
+     * Compile string.
228
+     *
229
+     * @param string  $string a string with twig variables.
230
+     * @param array   $data   an array with data in it.
231
+     * @return  bool|string
232
+     */
233
+    public static function compile_string( $string, $data = array() ) {
234
+        $dummy_loader = new TimberLoader();
235
+        $dummy_loader->get_twig();
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 );
241
+    }
242
+
243
+    /**
244
+     * Fetch function.
245
+     *
246
+     * @param array   $filenames
247
+     * @param array   $data
248
+     * @param bool    $expires
249
+     * @param string  $cache_mode
250
+     * @return bool|string
251
+     */
252
+    public static function fetch( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT ) {
253
+        if ( $expires === true ) {
254
+            //if this is reading as true; the user probably is using the old $echo param
255
+            //so we should move all vars up by a spot
256
+            $expires = $cache_mode;
257
+            $cache_mode = TimberLoader::CACHE_USE_DEFAULT;
258
+        }
259
+        $output = self::compile( $filenames, $data, $expires, $cache_mode, true );
260
+        $output = apply_filters( 'timber_compile_result', $output );
261
+        return $output;
262
+    }
263
+
264
+    /**
265
+     * Render function.
266
+     *
267
+     * @param array   $filenames
268
+     * @param array   $data
269
+     * @param bool    $expires
270
+     * @param string  $cache_mode
271
+     * @return bool|string
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 );
275
+        echo $output;
276
+        return $output;
277
+    }
278
+
279
+    /**
280
+     * Render string.
281
+     *
282
+     * @param string  $string a string with twig variables.
283
+     * @param array   $data   an array with data in it.
284
+     * @return  bool|string
285
+     */
286
+    public static function render_string( $string, $data = array() ) {
287
+        $compiled = self::compile_string( $string, $data );
288
+        echo $compiled;
289
+        return $compiled;
290
+    }
291
+
292
+
293
+    /*  Sidebar
294 294
 	================================ */
295 295
 
296
-	/**
297
-	 * Get sidebar.
298
-	 *
299
-	 * @param string  $sidebar
300
-	 * @param array   $data
301
-	 * @return bool|string
302
-	 */
303
-	public static function get_sidebar( $sidebar = '', $data = array() ) {
304
-		if ( $sidebar == '' ) {
305
-			$sidebar = 'sidebar.php';
306
-		}
307
-		if ( strstr( strtolower( $sidebar ), '.php' ) ) {
308
-			return self::get_sidebar_from_php( $sidebar, $data );
309
-		}
310
-		return self::compile( $sidebar, $data );
311
-	}
312
-
313
-	/**
314
-	 * Get sidebar from PHP
315
-	 *
316
-	 * @param string  $sidebar
317
-	 * @param array   $data
318
-	 * @return string
319
-	 */
320
-	public static function get_sidebar_from_php( $sidebar = '', $data ) {
321
-		$caller = self::get_calling_script_dir();
322
-		$loader = new TimberLoader();
323
-		$uris = $loader->get_locations( $caller );
324
-		ob_start();
325
-		$found = false;
326
-		foreach ( $uris as $uri ) {
327
-			if ( file_exists( trailingslashit( $uri ) . $sidebar ) ) {
328
-				include trailingslashit( $uri ) . $sidebar;
329
-				$found = true;
330
-				break;
331
-			}
332
-		}
333
-		if ( !$found ) {
334
-			TimberHelper::error_log( 'error loading your sidebar, check to make sure the file exists' );
335
-		}
336
-		$ret = ob_get_contents();
337
-		ob_end_clean();
338
-		return $ret;
339
-	}
340
-
341
-	/* Widgets
296
+    /**
297
+     * Get sidebar.
298
+     *
299
+     * @param string  $sidebar
300
+     * @param array   $data
301
+     * @return bool|string
302
+     */
303
+    public static function get_sidebar( $sidebar = '', $data = array() ) {
304
+        if ( $sidebar == '' ) {
305
+            $sidebar = 'sidebar.php';
306
+        }
307
+        if ( strstr( strtolower( $sidebar ), '.php' ) ) {
308
+            return self::get_sidebar_from_php( $sidebar, $data );
309
+        }
310
+        return self::compile( $sidebar, $data );
311
+    }
312
+
313
+    /**
314
+     * Get sidebar from PHP
315
+     *
316
+     * @param string  $sidebar
317
+     * @param array   $data
318
+     * @return string
319
+     */
320
+    public static function get_sidebar_from_php( $sidebar = '', $data ) {
321
+        $caller = self::get_calling_script_dir();
322
+        $loader = new TimberLoader();
323
+        $uris = $loader->get_locations( $caller );
324
+        ob_start();
325
+        $found = false;
326
+        foreach ( $uris as $uri ) {
327
+            if ( file_exists( trailingslashit( $uri ) . $sidebar ) ) {
328
+                include trailingslashit( $uri ) . $sidebar;
329
+                $found = true;
330
+                break;
331
+            }
332
+        }
333
+        if ( !$found ) {
334
+            TimberHelper::error_log( 'error loading your sidebar, check to make sure the file exists' );
335
+        }
336
+        $ret = ob_get_contents();
337
+        ob_end_clean();
338
+        return $ret;
339
+    }
340
+
341
+    /* Widgets
342 342
 	================================ */
343 343
 
344
-	/**
345
-	 * Get widgets.
346
-	 *
347
-	 * @param int     $widget_id
348
-	 * @return TimberFunctionWrapper
349
-	 */
350
-	public static function get_widgets( $widget_id ) {
351
-		return trim( TimberHelper::function_wrapper( 'dynamic_sidebar', array( $widget_id ), true ) );
352
-	}
344
+    /**
345
+     * Get widgets.
346
+     *
347
+     * @param int     $widget_id
348
+     * @return TimberFunctionWrapper
349
+     */
350
+    public static function get_widgets( $widget_id ) {
351
+        return trim( TimberHelper::function_wrapper( 'dynamic_sidebar', array( $widget_id ), true ) );
352
+    }
353 353
 
354 354
 
355
-	/*  Routes
355
+    /*  Routes
356 356
 	================================ */
357 357
 
358
-	/**
359
-	 * Add route.
360
-	 *
361
-	 * @param string  $route
362
-	 * @param callable $callback
363
-	 * @param array   $args
364
-	 * @deprecated since 0.20.0
365
-	 */
366
-	public static function add_route( $route, $callback, $args = array() ) {
367
-		Routes::map( $route, $callback, $args );
368
-	}
369
-
370
-	/**
371
-	 * Load template.
372
-	 *
373
-	 * @deprecated since 0.20.0
374
-	 */
375
-	public static function load_template( $template, $query = false, $status_code = 200, $tparams = false ) {
376
-		return Routes::load( $template, $tparams, $query, $status_code );
377
-	}
378
-
379
-	/**
380
-	 * Load view.
381
-	 *
382
-	 * @deprecated since 0.20.2
383
-	 */
384
-	public static function load_view( $template, $query = false, $status_code = 200, $tparams = false ) {
385
-		return Routes::load( $template, $tparams, $query, $status_code );
386
-	}
387
-
388
-
389
-	/*  Pagination
358
+    /**
359
+     * Add route.
360
+     *
361
+     * @param string  $route
362
+     * @param callable $callback
363
+     * @param array   $args
364
+     * @deprecated since 0.20.0
365
+     */
366
+    public static function add_route( $route, $callback, $args = array() ) {
367
+        Routes::map( $route, $callback, $args );
368
+    }
369
+
370
+    /**
371
+     * Load template.
372
+     *
373
+     * @deprecated since 0.20.0
374
+     */
375
+    public static function load_template( $template, $query = false, $status_code = 200, $tparams = false ) {
376
+        return Routes::load( $template, $tparams, $query, $status_code );
377
+    }
378
+
379
+    /**
380
+     * Load view.
381
+     *
382
+     * @deprecated since 0.20.2
383
+     */
384
+    public static function load_view( $template, $query = false, $status_code = 200, $tparams = false ) {
385
+        return Routes::load( $template, $tparams, $query, $status_code );
386
+    }
387
+
388
+
389
+    /*  Pagination
390 390
 	================================ */
391 391
 
392
-	/**
393
-	 * Get pagination.
394
-	 *
395
-	 * @param array   $prefs
396
-	 * @return array mixed
397
-	 */
398
-	public static function get_pagination( $prefs = array() ) {
399
-		global $wp_query;
400
-		global $paged;
401
-		global $wp_rewrite;
402
-		$args = array();
403
-		$args['total'] = ceil( $wp_query->found_posts / $wp_query->query_vars['posts_per_page'] );
404
-		if ( $wp_rewrite->using_permalinks() ) {
405
-			$url = explode( '?', get_pagenum_link( 0 ) );
406
-			if ( isset( $url[1] ) ) {
407
-				parse_str( $url[1], $query );
408
-				$args['add_args'] = $query;
409
-			}
410
-			$args['format'] = 'page/%#%';
411
-			$args['base'] = trailingslashit( $url[0] ).'%_%';
412
-		} else {
413
-			$big = 999999999;
414
-			$args['base'] = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) );
415
-		}
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 ) ) {
420
-			$args['mid_size'] = $prefs - 2;
421
-		} else {
422
-			$args = array_merge( $args, $prefs );
423
-		}
424
-		$data = array();
425
-		$data['current'] = $args['current'];
426
-		$data['total'] = $args['total'];
427
-		$data['pages'] = TimberHelper::paginate_links( $args );
428
-		$next = get_next_posts_page_link( $args['total'] );
429
-		if ( $next ) {
430
-			$data['next'] = array( 'link' => untrailingslashit( $next ), 'class' => 'page-numbers next' );
431
-		}
432
-		$prev = previous_posts( false );
433
-		if ( $prev ) {
434
-			$data['prev'] = array( 'link' => untrailingslashit( $prev ), 'class' => 'page-numbers prev' );
435
-		}
436
-		if ( $paged < 2 ) {
437
-			$data['prev'] = '';
438
-		}
439
-		return $data;
440
-	}
441
-
442
-	/*  Utility
392
+    /**
393
+     * Get pagination.
394
+     *
395
+     * @param array   $prefs
396
+     * @return array mixed
397
+     */
398
+    public static function get_pagination( $prefs = array() ) {
399
+        global $wp_query;
400
+        global $paged;
401
+        global $wp_rewrite;
402
+        $args = array();
403
+        $args['total'] = ceil( $wp_query->found_posts / $wp_query->query_vars['posts_per_page'] );
404
+        if ( $wp_rewrite->using_permalinks() ) {
405
+            $url = explode( '?', get_pagenum_link( 0 ) );
406
+            if ( isset( $url[1] ) ) {
407
+                parse_str( $url[1], $query );
408
+                $args['add_args'] = $query;
409
+            }
410
+            $args['format'] = 'page/%#%';
411
+            $args['base'] = trailingslashit( $url[0] ).'%_%';
412
+        } else {
413
+            $big = 999999999;
414
+            $args['base'] = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) );
415
+        }
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 ) ) {
420
+            $args['mid_size'] = $prefs - 2;
421
+        } else {
422
+            $args = array_merge( $args, $prefs );
423
+        }
424
+        $data = array();
425
+        $data['current'] = $args['current'];
426
+        $data['total'] = $args['total'];
427
+        $data['pages'] = TimberHelper::paginate_links( $args );
428
+        $next = get_next_posts_page_link( $args['total'] );
429
+        if ( $next ) {
430
+            $data['next'] = array( 'link' => untrailingslashit( $next ), 'class' => 'page-numbers next' );
431
+        }
432
+        $prev = previous_posts( false );
433
+        if ( $prev ) {
434
+            $data['prev'] = array( 'link' => untrailingslashit( $prev ), 'class' => 'page-numbers prev' );
435
+        }
436
+        if ( $paged < 2 ) {
437
+            $data['prev'] = '';
438
+        }
439
+        return $data;
440
+    }
441
+
442
+    /*  Utility
443 443
 	================================ */
444 444
 
445
-	/**
446
-	 * Get calling script dir.
447
-	 *
448
-	 * @return string
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 );
454
-			$dir = $pathinfo['dirname'];
455
-			return $dir;
456
-		}
457
-	}
458
-
459
-	/**
460
-	 * Get calling script file.
461
-	 *
462
-	 * @param int     $offset
463
-	 * @return string|null
464
-	 * @deprecated since 0.20.0
465
-	 */
466
-	public static function get_calling_script_file( $offset = 0 ) {
467
-		$caller = null;
468
-		$backtrace = debug_backtrace();
469
-		$i = 0;
470
-		foreach ( $backtrace as $trace ) {
471
-			if ( array_key_exists('file', $trace) && $trace['file'] != __FILE__ ) {
472
-				$caller = $trace['file'];
473
-				break;
474
-			}
475
-			$i++;
476
-		}
477
-		if ( $offset ) {
478
-			$caller = $backtrace[$i + $offset]['file'];
479
-		}
480
-		return $caller;
481
-	}
445
+    /**
446
+     * Get calling script dir.
447
+     *
448
+     * @return string
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 );
454
+            $dir = $pathinfo['dirname'];
455
+            return $dir;
456
+        }
457
+    }
458
+
459
+    /**
460
+     * Get calling script file.
461
+     *
462
+     * @param int     $offset
463
+     * @return string|null
464
+     * @deprecated since 0.20.0
465
+     */
466
+    public static function get_calling_script_file( $offset = 0 ) {
467
+        $caller = null;
468
+        $backtrace = debug_backtrace();
469
+        $i = 0;
470
+        foreach ( $backtrace as $trace ) {
471
+            if ( array_key_exists('file', $trace) && $trace['file'] != __FILE__ ) {
472
+                $caller = $trace['file'];
473
+                break;
474
+            }
475
+            $i++;
476
+        }
477
+        if ( $offset ) {
478
+            $caller = $backtrace[$i + $offset]['file'];
479
+        }
480
+        return $caller;
481
+    }
482 482
 
483 483
 
484 484
 }
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -45,16 +45,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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();
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 * @return array|bool|null
80 80
 	 */
81 81
 	public static function get_post( $query = false, $PostClass = 'TimberPost' ) {
82
-		return TimberPostGetter::get_post( $query, $PostClass );
82
+		return TimberPostGetter::get_post($query, $PostClass);
83 83
 	}
84 84
 
85 85
 	/**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 * @return array|bool|null
91 91
 	 */
92 92
 	public static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) {
93
-		return TimberPostGetter::get_posts( $query, $PostClass, $return_collection );
93
+		return TimberPostGetter::get_posts($query, $PostClass, $return_collection);
94 94
 	}
95 95
 
96 96
 	/**
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	 * @return array|bool|null
102 102
 	 */
103 103
 	public static function query_post( $query = false, $PostClass = 'TimberPost' ) {
104
-		return TimberPostGetter::query_post( $query, $PostClass );
104
+		return TimberPostGetter::query_post($query, $PostClass);
105 105
 	}
106 106
 
107 107
 	/**
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 * @return array|bool|null
113 113
 	 */
114 114
 	public static function query_posts( $query = false, $PostClass = 'TimberPost' ) {
115
-		return TimberPostGetter::query_posts( $query, $PostClass );
115
+		return TimberPostGetter::query_posts($query, $PostClass);
116 116
 	}
117 117
 
118 118
 	/**
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 * @return mixed
138 138
 	 */
139 139
 	public static function get_terms( $args = null, $maybe_args = array(), $TermClass = 'TimberTerm' ) {
140
-		return TimberTermGetter::get_terms( $args, $maybe_args, $TermClass );
140
+		return TimberTermGetter::get_terms($args, $maybe_args, $TermClass);
141 141
 	}
142 142
 
143 143
 	/* Site Retrieval
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
 	 * @return array
151 151
 	 */
152 152
 	public static function get_sites( $blog_ids = false ) {
153
-		if ( !is_array( $blog_ids ) ) {
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
 block discarded – undo
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
 block discarded – undo
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
 
@@ -202,24 +202,24 @@  discard block
 block discarded – undo
202 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
 
@@ -234,10 +234,10 @@  discard block
 block discarded – undo
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
 	/**
@@ -256,8 +256,8 @@  discard block
 block discarded – undo
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
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 	 * @return bool|string
272 272
 	 */
273 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 );
274
+		$output = static::fetch($filenames, $data, $expires, $cache_mode);
275 275
 		echo $output;
276 276
 		return $output;
277 277
 	}
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	 * @return  bool|string
285 285
 	 */
286 286
 	public static function render_string( $string, $data = array() ) {
287
-		$compiled = self::compile_string( $string, $data );
287
+		$compiled = self::compile_string($string, $data);
288 288
 		echo $compiled;
289 289
 		return $compiled;
290 290
 	}
@@ -304,10 +304,10 @@  discard block
 block discarded – undo
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
 	/**
@@ -320,18 +320,18 @@  discard block
 block discarded – undo
320 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();
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 	 * @return TimberFunctionWrapper
349 349
 	 */
350 350
 	public static function get_widgets( $widget_id ) {
351
-		return trim( TimberHelper::function_wrapper( 'dynamic_sidebar', array( $widget_id ), true ) );
351
+		return trim(TimberHelper::function_wrapper('dynamic_sidebar', array($widget_id), true));
352 352
 	}
353 353
 
354 354
 
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
 	 * @deprecated since 0.20.0
365 365
 	 */
366 366
 	public static function add_route( $route, $callback, $args = array() ) {
367
-		Routes::map( $route, $callback, $args );
367
+		Routes::map($route, $callback, $args);
368 368
 	}
369 369
 
370 370
 	/**
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
 	 * @deprecated since 0.20.0
374 374
 	 */
375 375
 	public static function load_template( $template, $query = false, $status_code = 200, $tparams = false ) {
376
-		return Routes::load( $template, $tparams, $query, $status_code );
376
+		return Routes::load($template, $tparams, $query, $status_code);
377 377
 	}
378 378
 
379 379
 	/**
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 	 * @deprecated since 0.20.2
383 383
 	 */
384 384
 	public static function load_view( $template, $query = false, $status_code = 200, $tparams = false ) {
385
-		return Routes::load( $template, $tparams, $query, $status_code );
385
+		return Routes::load($template, $tparams, $query, $status_code);
386 386
 	}
387 387
 
388 388
 
@@ -400,38 +400,38 @@  discard block
 block discarded – undo
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'] = '';
@@ -448,9 +448,9 @@  discard block
 block discarded – undo
448 448
 	 * @return string
449 449
 	 */
450 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 );
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
 		}
Please login to merge, or discard this patch.
lib/timber-site.php 2 patches
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -18,242 +18,242 @@
 block discarded – undo
18 18
  */
19 19
 class TimberSite extends TimberCore implements TimberCoreInterface {
20 20
 
21
-	/**
22
-	 * @api
23
-	 * @var string the admin email address set in the WP admin panel
24
-	 */
25
-	public $admin_email;
26
-	public $blogname;
27
-	/**
28
-	 * @api
29
-	 * @var string
30
-	 */
31
-	public $charset;
21
+    /**
22
+     * @api
23
+     * @var string the admin email address set in the WP admin panel
24
+     */
25
+    public $admin_email;
26
+    public $blogname;
27
+    /**
28
+     * @api
29
+     * @var string
30
+     */
31
+    public $charset;
32 32
 
33
-	/**
34
-	 * @api
35
-	 * @var string
36
-	 */
37
-	public $description;
38
-	/**
39
-	 * @api
40
-	 * @var int the ID of a site in multisite
41
-	 */
42
-	public $id;
43
-	/**
44
-	 * @api
45
-	 * @var string the language setting ex: en-US
46
-	 */
47
-	public $language;
48
-	/**
49
-	 * @api
50
-	 * @var string of language attributes for usage in the <html> tag
51
-	 */
52
-	public $language_attributes;
53
-	/**
54
-	 * @api
55
-	 * @var bool true if multisite, false if plain ole' WordPress
56
-	 */
57
-	public $multisite;
33
+    /**
34
+     * @api
35
+     * @var string
36
+     */
37
+    public $description;
38
+    /**
39
+     * @api
40
+     * @var int the ID of a site in multisite
41
+     */
42
+    public $id;
43
+    /**
44
+     * @api
45
+     * @var string the language setting ex: en-US
46
+     */
47
+    public $language;
48
+    /**
49
+     * @api
50
+     * @var string of language attributes for usage in the <html> tag
51
+     */
52
+    public $language_attributes;
53
+    /**
54
+     * @api
55
+     * @var bool true if multisite, false if plain ole' WordPress
56
+     */
57
+    public $multisite;
58 58
 
59
-	/**
60
-	 * @api
61
-	 * @var string
62
-	 */
63
-	public $name;
59
+    /**
60
+     * @api
61
+     * @var string
62
+     */
63
+    public $name;
64 64
 
65
-	/** @api
66
-	 * @var string for people who like trackback spam
67
-	*/
68
-	public $pingback_url;
69
-	public $siteurl;
70
-	/**
71
-	 * @api
72
-	 * @var [TimberTheme](#TimberTheme)
73
-	 */
74
-	public $theme;
75
-	/**
76
-	 * @api
77
-	 * @var string
78
-	 */
79
-	public $title;
80
-	public $url;
65
+    /** @api
66
+     * @var string for people who like trackback spam
67
+     */
68
+    public $pingback_url;
69
+    public $siteurl;
70
+    /**
71
+     * @api
72
+     * @var [TimberTheme](#TimberTheme)
73
+     */
74
+    public $theme;
75
+    /**
76
+     * @api
77
+     * @var string
78
+     */
79
+    public $title;
80
+    public $url;
81 81
 
82
-	/**
83
-	 * @api
84
-	 * @var string
85
-	 */
82
+    /**
83
+     * @api
84
+     * @var string
85
+     */
86 86
 
87
-	public $rdf;
88
-	public $rss;
89
-	public $rss2;
90
-	public $atom;
87
+    public $rdf;
88
+    public $rss;
89
+    public $rss2;
90
+    public $atom;
91 91
 	
92
-	/**
93
-	 * Constructs a TimberSite object
94
-	 * @example
95
-	 * ```php
96
-	 * //multisite setup
97
-	 * $site = new TimberSite(1);
98
-	 * $site_two = new TimberSite("My Cool Site");
99
-	 * //non-multisite
100
-	 * $site = new TimberSite();
101
-	 * ```
102
-	 * @param string|int $site_name_or_id
103
-	 */
104
-	function __construct( $site_name_or_id = null ) {
105
-		$this->init();
106
-		if ( is_multisite() ) {
107
-			$this->init_as_multisite( $site_name_or_id );
108
-		} else {
109
-			$this->init_as_singlesite();
110
-		}
111
-	}
92
+    /**
93
+     * Constructs a TimberSite object
94
+     * @example
95
+     * ```php
96
+     * //multisite setup
97
+     * $site = new TimberSite(1);
98
+     * $site_two = new TimberSite("My Cool Site");
99
+     * //non-multisite
100
+     * $site = new TimberSite();
101
+     * ```
102
+     * @param string|int $site_name_or_id
103
+     */
104
+    function __construct( $site_name_or_id = null ) {
105
+        $this->init();
106
+        if ( is_multisite() ) {
107
+            $this->init_as_multisite( $site_name_or_id );
108
+        } else {
109
+            $this->init_as_singlesite();
110
+        }
111
+    }
112 112
 
113
-	/**
114
-	 * @internal
115
-	 * @param string|int $site_name_or_id
116
-	 */
117
-	protected function init_as_multisite( $site_name_or_id ) {
118
-		if ( $site_name_or_id === null ) {
119
-			//this is necessary for some reason, otherwise returns 1 all the time
120
-			if ( is_multisite() ) {
121
-				restore_current_blog();
122
-				$site_name_or_id = get_current_blog_id();
123
-			}
124
-		}
125
-		$info = get_blog_details( $site_name_or_id );
126
-		$this->import( $info );
127
-		$this->ID = $info->blog_id;
128
-		$this->id = $this->ID;
129
-		$this->name = $this->blogname;
130
-		$this->title = $this->blogname;
131
-		$this->url = $this->siteurl;
132
-		$theme_slug = get_blog_option( $info->blog_id, 'stylesheet' );
133
-		$this->theme = new TimberTheme( $theme_slug );
134
-		$this->description = get_blog_option( $info->blog_id, 'blogdescription' );
135
-		$this->admin_email = get_blog_option( $info->blog_id, 'admin_email' );
136
-		$this->multisite = true;
137
-	}
113
+    /**
114
+     * @internal
115
+     * @param string|int $site_name_or_id
116
+     */
117
+    protected function init_as_multisite( $site_name_or_id ) {
118
+        if ( $site_name_or_id === null ) {
119
+            //this is necessary for some reason, otherwise returns 1 all the time
120
+            if ( is_multisite() ) {
121
+                restore_current_blog();
122
+                $site_name_or_id = get_current_blog_id();
123
+            }
124
+        }
125
+        $info = get_blog_details( $site_name_or_id );
126
+        $this->import( $info );
127
+        $this->ID = $info->blog_id;
128
+        $this->id = $this->ID;
129
+        $this->name = $this->blogname;
130
+        $this->title = $this->blogname;
131
+        $this->url = $this->siteurl;
132
+        $theme_slug = get_blog_option( $info->blog_id, 'stylesheet' );
133
+        $this->theme = new TimberTheme( $theme_slug );
134
+        $this->description = get_blog_option( $info->blog_id, 'blogdescription' );
135
+        $this->admin_email = get_blog_option( $info->blog_id, 'admin_email' );
136
+        $this->multisite = true;
137
+    }
138 138
 
139
-	/**
140
-	 * Executed for single-blog sites
141
-	 * @internal
142
-	 */
143
-	protected function init_as_singlesite() {
144
-		$this->admin_email = get_bloginfo( 'admin_email' );
145
-		$this->name = get_bloginfo( 'name' );
146
-		$this->title = $this->name;
147
-		$this->description = get_bloginfo( 'description' );
148
-		$this->url = get_bloginfo( 'url' );
149
-		$this->theme = new TimberTheme();
150
-		$this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' );
151
-		$this->multisite = false;
152
-	}
139
+    /**
140
+     * Executed for single-blog sites
141
+     * @internal
142
+     */
143
+    protected function init_as_singlesite() {
144
+        $this->admin_email = get_bloginfo( 'admin_email' );
145
+        $this->name = get_bloginfo( 'name' );
146
+        $this->title = $this->name;
147
+        $this->description = get_bloginfo( 'description' );
148
+        $this->url = get_bloginfo( 'url' );
149
+        $this->theme = new TimberTheme();
150
+        $this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' );
151
+        $this->multisite = false;
152
+    }
153 153
 
154
-	/**
155
-	 * Executed for all types of sites: both multisite and "regular"
156
-	 * @internal
157
-	 */
158
-	protected function init() {
159
-		$this->rdf = get_bloginfo( 'rdf_url' );
160
-		$this->rss = get_bloginfo( 'rss_url' );
161
-		$this->rss2 = get_bloginfo( 'rss2_url' );
162
-		$this->atom = get_bloginfo( 'atom_url' );
163
-		$this->language = get_bloginfo( 'language' );
164
-		$this->charset = get_bloginfo( 'charset' );
165
-		$this->pingback = get_bloginfo( 'pingback_url' );
166
-		$this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' );
167
-		/* deprecated benath this comment */
168
-		$this->pingback_url = get_bloginfo( 'pingback_url' );
169
-	}
154
+    /**
155
+     * Executed for all types of sites: both multisite and "regular"
156
+     * @internal
157
+     */
158
+    protected function init() {
159
+        $this->rdf = get_bloginfo( 'rdf_url' );
160
+        $this->rss = get_bloginfo( 'rss_url' );
161
+        $this->rss2 = get_bloginfo( 'rss2_url' );
162
+        $this->atom = get_bloginfo( 'atom_url' );
163
+        $this->language = get_bloginfo( 'language' );
164
+        $this->charset = get_bloginfo( 'charset' );
165
+        $this->pingback = get_bloginfo( 'pingback_url' );
166
+        $this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' );
167
+        /* deprecated benath this comment */
168
+        $this->pingback_url = get_bloginfo( 'pingback_url' );
169
+    }
170 170
 
171
-	/**
172
-	 *
173
-	 *
174
-	 * @param string  $field
175
-	 * @return mixed
176
-	 */
177
-	function __get( $field ) {
178
-		if ( !isset( $this->$field ) ) {
179
-			if ( is_multisite() ) {
180
-				$this->$field = get_blog_option( $this->ID, $field );
181
-			} else {
182
-				$this->$field = get_option( $field );
183
-			}
184
-		}
185
-		return $this->$field;
186
-	}
171
+    /**
172
+     *
173
+     *
174
+     * @param string  $field
175
+     * @return mixed
176
+     */
177
+    function __get( $field ) {
178
+        if ( !isset( $this->$field ) ) {
179
+            if ( is_multisite() ) {
180
+                $this->$field = get_blog_option( $this->ID, $field );
181
+            } else {
182
+                $this->$field = get_option( $field );
183
+            }
184
+        }
185
+        return $this->$field;
186
+    }
187 187
 
188
-	/**
189
-	 * @deprecated 0.21.9
190
-	 * @internal
191
-	 * @return string
192
-	 */
193
-	function get_link() {
194
-		return $this->link();
195
-	}
188
+    /**
189
+     * @deprecated 0.21.9
190
+     * @internal
191
+     * @return string
192
+     */
193
+    function get_link() {
194
+        return $this->link();
195
+    }
196 196
 
197
-	/**
198
-	 * @deprecated 0.21.9
199
-	 * @internal
200
-	 * @return string
201
-	 */
202
-	function get_url() {
203
-		return $this->get_link();
204
-	}
197
+    /**
198
+     * @deprecated 0.21.9
199
+     * @internal
200
+     * @return string
201
+     */
202
+    function get_url() {
203
+        return $this->get_link();
204
+    }
205 205
 
206
-	/**
207
-	 * Returns the link to the site's home.
208
-	 * @example
209
-	 * ```twig
210
-	 * <a href="{{ site.link }}" title="Home">
211
-	 * 	  <img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
212
-	 * </a>
213
-	 * ```
214
-	 * ```html
215
-	 * <a href="http://example.org" title="Home">
216
-	 * 	  <img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
217
-	 * </a>
218
-	 * ```
219
-	 * @api
220
-	 * @return string
221
-	 */
222
-	public function link() {
223
-		return $this->url;
224
-	}
206
+    /**
207
+     * Returns the link to the site's home.
208
+     * @example
209
+     * ```twig
210
+     * <a href="{{ site.link }}" title="Home">
211
+     * 	  <img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
212
+     * </a>
213
+     * ```
214
+     * ```html
215
+     * <a href="http://example.org" title="Home">
216
+     * 	  <img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
217
+     * </a>
218
+     * ```
219
+     * @api
220
+     * @return string
221
+     */
222
+    public function link() {
223
+        return $this->url;
224
+    }
225 225
 
226
-	/**
227
-	 * @ignore
228
-	 */
229
-	public function meta( $field ) {
230
-		return $this->__get( $field );
231
-	}
226
+    /**
227
+     * @ignore
228
+     */
229
+    public function meta( $field ) {
230
+        return $this->__get( $field );
231
+    }
232 232
 
233
-	/**
234
-	 *
235
-	 * @ignore
236
-	 * @param string  $key
237
-	 * @param mixed   $value
238
-	 */
239
-	public function update( $key, $value ) {
240
-		$value = apply_filters( 'timber_site_set_meta', $value, $key, $this->ID, $this );
241
-		if ( is_multisite() ) {
242
-			update_blog_option( $this->ID, $key, $value );
243
-		} else {
244
-			update_option( $key, $value );
245
-		}
246
-		$this->$key = $value;
247
-	}
233
+    /**
234
+     *
235
+     * @ignore
236
+     * @param string  $key
237
+     * @param mixed   $value
238
+     */
239
+    public function update( $key, $value ) {
240
+        $value = apply_filters( 'timber_site_set_meta', $value, $key, $this->ID, $this );
241
+        if ( is_multisite() ) {
242
+            update_blog_option( $this->ID, $key, $value );
243
+        } else {
244
+            update_option( $key, $value );
245
+        }
246
+        $this->$key = $value;
247
+    }
248 248
 
249
-	/**
250
-	 *
251
-	 * @api
252
-	 * @see TimberSite::link
253
-	 * @return string
254
-	 */
255
-	function url() {
256
-		return $this->get_link();
257
-	}
249
+    /**
250
+     *
251
+     * @api
252
+     * @see TimberSite::link
253
+     * @return string
254
+     */
255
+    function url() {
256
+        return $this->get_link();
257
+    }
258 258
 
259 259
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	function __construct( $site_name_or_id = null ) {
105 105
 		$this->init();
106 106
 		if ( is_multisite() ) {
107
-			$this->init_as_multisite( $site_name_or_id );
107
+			$this->init_as_multisite($site_name_or_id);
108 108
 		} else {
109 109
 			$this->init_as_singlesite();
110 110
 		}
@@ -122,17 +122,17 @@  discard block
 block discarded – undo
122 122
 				$site_name_or_id = get_current_blog_id();
123 123
 			}
124 124
 		}
125
-		$info = get_blog_details( $site_name_or_id );
126
-		$this->import( $info );
125
+		$info = get_blog_details($site_name_or_id);
126
+		$this->import($info);
127 127
 		$this->ID = $info->blog_id;
128 128
 		$this->id = $this->ID;
129 129
 		$this->name = $this->blogname;
130 130
 		$this->title = $this->blogname;
131 131
 		$this->url = $this->siteurl;
132
-		$theme_slug = get_blog_option( $info->blog_id, 'stylesheet' );
133
-		$this->theme = new TimberTheme( $theme_slug );
134
-		$this->description = get_blog_option( $info->blog_id, 'blogdescription' );
135
-		$this->admin_email = get_blog_option( $info->blog_id, 'admin_email' );
132
+		$theme_slug = get_blog_option($info->blog_id, 'stylesheet');
133
+		$this->theme = new TimberTheme($theme_slug);
134
+		$this->description = get_blog_option($info->blog_id, 'blogdescription');
135
+		$this->admin_email = get_blog_option($info->blog_id, 'admin_email');
136 136
 		$this->multisite = true;
137 137
 	}
138 138
 
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 	 * @internal
142 142
 	 */
143 143
 	protected function init_as_singlesite() {
144
-		$this->admin_email = get_bloginfo( 'admin_email' );
145
-		$this->name = get_bloginfo( 'name' );
144
+		$this->admin_email = get_bloginfo('admin_email');
145
+		$this->name = get_bloginfo('name');
146 146
 		$this->title = $this->name;
147
-		$this->description = get_bloginfo( 'description' );
148
-		$this->url = get_bloginfo( 'url' );
147
+		$this->description = get_bloginfo('description');
148
+		$this->url = get_bloginfo('url');
149 149
 		$this->theme = new TimberTheme();
150
-		$this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' );
150
+		$this->language_attributes = TimberHelper::function_wrapper('language_attributes');
151 151
 		$this->multisite = false;
152 152
 	}
153 153
 
@@ -156,16 +156,16 @@  discard block
 block discarded – undo
156 156
 	 * @internal
157 157
 	 */
158 158
 	protected function init() {
159
-		$this->rdf = get_bloginfo( 'rdf_url' );
160
-		$this->rss = get_bloginfo( 'rss_url' );
161
-		$this->rss2 = get_bloginfo( 'rss2_url' );
162
-		$this->atom = get_bloginfo( 'atom_url' );
163
-		$this->language = get_bloginfo( 'language' );
164
-		$this->charset = get_bloginfo( 'charset' );
165
-		$this->pingback = get_bloginfo( 'pingback_url' );
166
-		$this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' );
159
+		$this->rdf = get_bloginfo('rdf_url');
160
+		$this->rss = get_bloginfo('rss_url');
161
+		$this->rss2 = get_bloginfo('rss2_url');
162
+		$this->atom = get_bloginfo('atom_url');
163
+		$this->language = get_bloginfo('language');
164
+		$this->charset = get_bloginfo('charset');
165
+		$this->pingback = get_bloginfo('pingback_url');
166
+		$this->language_attributes = TimberHelper::function_wrapper('language_attributes');
167 167
 		/* deprecated benath this comment */
168
-		$this->pingback_url = get_bloginfo( 'pingback_url' );
168
+		$this->pingback_url = get_bloginfo('pingback_url');
169 169
 	}
170 170
 
171 171
 	/**
@@ -175,11 +175,11 @@  discard block
 block discarded – undo
175 175
 	 * @return mixed
176 176
 	 */
177 177
 	function __get( $field ) {
178
-		if ( !isset( $this->$field ) ) {
178
+		if ( !isset($this->$field) ) {
179 179
 			if ( is_multisite() ) {
180
-				$this->$field = get_blog_option( $this->ID, $field );
180
+				$this->$field = get_blog_option($this->ID, $field);
181 181
 			} else {
182
-				$this->$field = get_option( $field );
182
+				$this->$field = get_option($field);
183 183
 			}
184 184
 		}
185 185
 		return $this->$field;
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 * @ignore
228 228
 	 */
229 229
 	public function meta( $field ) {
230
-		return $this->__get( $field );
230
+		return $this->__get($field);
231 231
 	}
232 232
 
233 233
 	/**
@@ -237,11 +237,11 @@  discard block
 block discarded – undo
237 237
 	 * @param mixed   $value
238 238
 	 */
239 239
 	public function update( $key, $value ) {
240
-		$value = apply_filters( 'timber_site_set_meta', $value, $key, $this->ID, $this );
240
+		$value = apply_filters('timber_site_set_meta', $value, $key, $this->ID, $this);
241 241
 		if ( is_multisite() ) {
242
-			update_blog_option( $this->ID, $key, $value );
242
+			update_blog_option($this->ID, $key, $value);
243 243
 		} else {
244
-			update_option( $key, $value );
244
+			update_option($key, $value);
245 245
 		}
246 246
 		$this->$key = $value;
247 247
 	}
Please login to merge, or discard this patch.
lib/image/timber-image-operation-letterbox.php 2 patches
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -10,98 +10,98 @@
 block discarded – undo
10 10
  */
11 11
 class TimberImageOperationLetterbox extends TimberImageOperation {
12 12
 
13
-	private $w, $h, $color;
13
+    private $w, $h, $color;
14 14
 
15
-	/**
16
-	 * @param int    $w     width of result image
17
-	 * @param int    $h     height
18
-	 * @param string $color hex string, for color of padding bands
19
-	 */
20
-	function __construct($w, $h, $color) {
21
-		$this->w = $w;
22
-		$this->h = $h;
23
-		$this->color = $color;
24
-	}
15
+    /**
16
+     * @param int    $w     width of result image
17
+     * @param int    $h     height
18
+     * @param string $color hex string, for color of padding bands
19
+     */
20
+    function __construct($w, $h, $color) {
21
+        $this->w = $w;
22
+        $this->h = $h;
23
+        $this->color = $color;
24
+    }
25 25
 
26
-	/**
27
-	 * @param   string    $src_filename     the basename of the file (ex: my-awesome-pic)
28
-	 * @param   string    $src_extension    the extension (ex: .jpg)
29
-	 * @return  string    the final filename to be used
30
-	 *                    (ex: my-awesome-pic-lbox-300x200-FF3366.jpg)
31
-	 */
32
-	public function filename($src_filename, $src_extension) {
33
-		$color = str_replace( '#', '', $this->color );
34
-		$newbase = $src_filename . '-lbox-' . $this->w . 'x' . $this->h . '-' . $color;
35
-		$new_name = $newbase . '.' . $src_extension;
36
-		return $new_name;
37
-	}
26
+    /**
27
+     * @param   string    $src_filename     the basename of the file (ex: my-awesome-pic)
28
+     * @param   string    $src_extension    the extension (ex: .jpg)
29
+     * @return  string    the final filename to be used
30
+     *                    (ex: my-awesome-pic-lbox-300x200-FF3366.jpg)
31
+     */
32
+    public function filename($src_filename, $src_extension) {
33
+        $color = str_replace( '#', '', $this->color );
34
+        $newbase = $src_filename . '-lbox-' . $this->w . 'x' . $this->h . '-' . $color;
35
+        $new_name = $newbase . '.' . $src_extension;
36
+        return $new_name;
37
+    }
38 38
 
39
-	/**
40
-	 * Performs the actual image manipulation,
41
-	 * including saving the target file.
42
-	 *
43
-	 * @param  string $load_filename filepath (not URL) to source file
44
-	 *                               (ex: /src/var/www/wp-content/uploads/my-pic.jpg)
45
-	 * @param  string $save_filename filepath (not URL) where result file should be saved
46
-	 *                               (ex: /src/var/www/wp-content/uploads/my-pic-lbox-300x200-FF3366.jpg)
47
-	 * @return bool                  true if everything went fine, false otherwise
48
-	 */
49
-	public function run($load_filename, $save_filename) {
50
-		$w = $this->w;
51
-		$h = $this->h;
39
+    /**
40
+     * Performs the actual image manipulation,
41
+     * including saving the target file.
42
+     *
43
+     * @param  string $load_filename filepath (not URL) to source file
44
+     *                               (ex: /src/var/www/wp-content/uploads/my-pic.jpg)
45
+     * @param  string $save_filename filepath (not URL) where result file should be saved
46
+     *                               (ex: /src/var/www/wp-content/uploads/my-pic-lbox-300x200-FF3366.jpg)
47
+     * @return bool                  true if everything went fine, false otherwise
48
+     */
49
+    public function run($load_filename, $save_filename) {
50
+        $w = $this->w;
51
+        $h = $this->h;
52 52
 
53
-		$bg = imagecreatetruecolor( $w, $h );
54
-		$c = self::hexrgb( $this->color );
55
-		$bgColor = imagecolorallocate( $bg, $c['red'], $c['green'], $c['blue'] );
56
-		imagefill( $bg, 0, 0, $bgColor );
57
-		$image = wp_get_image_editor( $load_filename );
58
-		if ( !is_wp_error( $image ) ) {
59
-			$current_size = $image->get_size();
60
-			$quality = $image->get_quality();
61
-			$ow = $current_size['width'];
62
-			$oh = $current_size['height'];
63
-			$new_aspect = $w / $h;
64
-			$old_aspect = $ow / $oh;
65
-			if ( $new_aspect > $old_aspect ) {
66
-				//taller than goal
67
-				$h_scale = $h / $oh;
68
-				$owt = $ow * $h_scale;
69
-				$y = 0;
70
-				$x = $w / 2 - $owt / 2;
71
-				$oht = $h;
72
-				$image->crop( 0, 0, $ow, $oh, $owt, $oht );
73
-			} else {
74
-				$w_scale = $w / $ow;
75
-				$oht = $oh * $w_scale;
76
-				$x = 0;
77
-				$y = $h / 2 - $oht / 2;
78
-				$owt = $w;
79
-				$image->crop( 0, 0, $ow, $oh, $owt, $oht );
80
-			}
81
-			$result = $image->save( $save_filename );
82
-			$func = 'imagecreatefromjpeg';
83
-			$save_func = 'imagejpeg';
84
-			$ext = pathinfo( $save_filename, PATHINFO_EXTENSION );
85
-			if ( $ext == 'gif' ) {
86
-				$func = 'imagecreatefromgif';
87
-				$save_func = 'imagegif';
88
-			} else if ( $ext == 'png' ) {
89
-				$func = 'imagecreatefrompng';
90
-				$save_func = 'imagepng';
91
-				if ($quality > 9) {
92
-					$quality = $quality/10;
93
-					$quality = round(10 - $quality);
94
-				}
95
-			}
96
-			$image = $func( $save_filename );
97
-			imagecopy( $bg, $image, $x, $y, 0, 0, $owt, $oht );
98
-			if ($save_func === 'imagegif') {
99
-				return $save_func( $bg, $save_filename );
100
-			}
101
-			return $save_func( $bg, $save_filename, $quality );
102
-		} else {
103
-			TimberHelper::error_log( $image );
104
-		}
105
-		return false;
106
-	}
53
+        $bg = imagecreatetruecolor( $w, $h );
54
+        $c = self::hexrgb( $this->color );
55
+        $bgColor = imagecolorallocate( $bg, $c['red'], $c['green'], $c['blue'] );
56
+        imagefill( $bg, 0, 0, $bgColor );
57
+        $image = wp_get_image_editor( $load_filename );
58
+        if ( !is_wp_error( $image ) ) {
59
+            $current_size = $image->get_size();
60
+            $quality = $image->get_quality();
61
+            $ow = $current_size['width'];
62
+            $oh = $current_size['height'];
63
+            $new_aspect = $w / $h;
64
+            $old_aspect = $ow / $oh;
65
+            if ( $new_aspect > $old_aspect ) {
66
+                //taller than goal
67
+                $h_scale = $h / $oh;
68
+                $owt = $ow * $h_scale;
69
+                $y = 0;
70
+                $x = $w / 2 - $owt / 2;
71
+                $oht = $h;
72
+                $image->crop( 0, 0, $ow, $oh, $owt, $oht );
73
+            } else {
74
+                $w_scale = $w / $ow;
75
+                $oht = $oh * $w_scale;
76
+                $x = 0;
77
+                $y = $h / 2 - $oht / 2;
78
+                $owt = $w;
79
+                $image->crop( 0, 0, $ow, $oh, $owt, $oht );
80
+            }
81
+            $result = $image->save( $save_filename );
82
+            $func = 'imagecreatefromjpeg';
83
+            $save_func = 'imagejpeg';
84
+            $ext = pathinfo( $save_filename, PATHINFO_EXTENSION );
85
+            if ( $ext == 'gif' ) {
86
+                $func = 'imagecreatefromgif';
87
+                $save_func = 'imagegif';
88
+            } else if ( $ext == 'png' ) {
89
+                $func = 'imagecreatefrompng';
90
+                $save_func = 'imagepng';
91
+                if ($quality > 9) {
92
+                    $quality = $quality/10;
93
+                    $quality = round(10 - $quality);
94
+                }
95
+            }
96
+            $image = $func( $save_filename );
97
+            imagecopy( $bg, $image, $x, $y, 0, 0, $owt, $oht );
98
+            if ($save_func === 'imagegif') {
99
+                return $save_func( $bg, $save_filename );
100
+            }
101
+            return $save_func( $bg, $save_filename, $quality );
102
+        } else {
103
+            TimberHelper::error_log( $image );
104
+        }
105
+        return false;
106
+    }
107 107
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 	 * @param int    $h     height
18 18
 	 * @param string $color hex string, for color of padding bands
19 19
 	 */
20
-	function __construct($w, $h, $color) {
20
+	function __construct( $w, $h, $color ) {
21 21
 		$this->w = $w;
22 22
 		$this->h = $h;
23 23
 		$this->color = $color;
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
 	 * @return  string    the final filename to be used
30 30
 	 *                    (ex: my-awesome-pic-lbox-300x200-FF3366.jpg)
31 31
 	 */
32
-	public function filename($src_filename, $src_extension) {
33
-		$color = str_replace( '#', '', $this->color );
32
+	public function filename( $src_filename, $src_extension ) {
33
+		$color = str_replace('#', '', $this->color);
34 34
 		$newbase = $src_filename . '-lbox-' . $this->w . 'x' . $this->h . '-' . $color;
35 35
 		$new_name = $newbase . '.' . $src_extension;
36 36
 		return $new_name;
@@ -46,16 +46,16 @@  discard block
 block discarded – undo
46 46
 	 *                               (ex: /src/var/www/wp-content/uploads/my-pic-lbox-300x200-FF3366.jpg)
47 47
 	 * @return bool                  true if everything went fine, false otherwise
48 48
 	 */
49
-	public function run($load_filename, $save_filename) {
49
+	public function run( $load_filename, $save_filename ) {
50 50
 		$w = $this->w;
51 51
 		$h = $this->h;
52 52
 
53
-		$bg = imagecreatetruecolor( $w, $h );
54
-		$c = self::hexrgb( $this->color );
55
-		$bgColor = imagecolorallocate( $bg, $c['red'], $c['green'], $c['blue'] );
56
-		imagefill( $bg, 0, 0, $bgColor );
57
-		$image = wp_get_image_editor( $load_filename );
58
-		if ( !is_wp_error( $image ) ) {
53
+		$bg = imagecreatetruecolor($w, $h);
54
+		$c = self::hexrgb($this->color);
55
+		$bgColor = imagecolorallocate($bg, $c['red'], $c['green'], $c['blue']);
56
+		imagefill($bg, 0, 0, $bgColor);
57
+		$image = wp_get_image_editor($load_filename);
58
+		if ( !is_wp_error($image) ) {
59 59
 			$current_size = $image->get_size();
60 60
 			$quality = $image->get_quality();
61 61
 			$ow = $current_size['width'];
@@ -69,38 +69,38 @@  discard block
 block discarded – undo
69 69
 				$y = 0;
70 70
 				$x = $w / 2 - $owt / 2;
71 71
 				$oht = $h;
72
-				$image->crop( 0, 0, $ow, $oh, $owt, $oht );
72
+				$image->crop(0, 0, $ow, $oh, $owt, $oht);
73 73
 			} else {
74 74
 				$w_scale = $w / $ow;
75 75
 				$oht = $oh * $w_scale;
76 76
 				$x = 0;
77 77
 				$y = $h / 2 - $oht / 2;
78 78
 				$owt = $w;
79
-				$image->crop( 0, 0, $ow, $oh, $owt, $oht );
79
+				$image->crop(0, 0, $ow, $oh, $owt, $oht);
80 80
 			}
81
-			$result = $image->save( $save_filename );
81
+			$result = $image->save($save_filename);
82 82
 			$func = 'imagecreatefromjpeg';
83 83
 			$save_func = 'imagejpeg';
84
-			$ext = pathinfo( $save_filename, PATHINFO_EXTENSION );
84
+			$ext = pathinfo($save_filename, PATHINFO_EXTENSION);
85 85
 			if ( $ext == 'gif' ) {
86 86
 				$func = 'imagecreatefromgif';
87 87
 				$save_func = 'imagegif';
88 88
 			} else if ( $ext == 'png' ) {
89 89
 				$func = 'imagecreatefrompng';
90 90
 				$save_func = 'imagepng';
91
-				if ($quality > 9) {
92
-					$quality = $quality/10;
91
+				if ( $quality > 9 ) {
92
+					$quality = $quality / 10;
93 93
 					$quality = round(10 - $quality);
94 94
 				}
95 95
 			}
96
-			$image = $func( $save_filename );
97
-			imagecopy( $bg, $image, $x, $y, 0, 0, $owt, $oht );
98
-			if ($save_func === 'imagegif') {
99
-				return $save_func( $bg, $save_filename );
96
+			$image = $func($save_filename);
97
+			imagecopy($bg, $image, $x, $y, 0, 0, $owt, $oht);
98
+			if ( $save_func === 'imagegif' ) {
99
+				return $save_func($bg, $save_filename);
100 100
 			}
101
-			return $save_func( $bg, $save_filename, $quality );
101
+			return $save_func($bg, $save_filename, $quality);
102 102
 		} else {
103
-			TimberHelper::error_log( $image );
103
+			TimberHelper::error_log($image);
104 104
 		}
105 105
 		return false;
106 106
 	}
Please login to merge, or discard this patch.
lib/image/timber-image-operation-tojpg.php 2 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -7,68 +7,68 @@
 block discarded – undo
7 7
  */
8 8
 class TimberImageOperationToJpg extends TimberImageOperation {
9 9
 
10
-	private $color;
10
+    private $color;
11 11
 
12
-	/**
13
-	 * @param string $color hex string of color to use for transparent zones
14
-	 */
15
-	function __construct($color) {
16
-		$this->color = $color;
17
-	}
12
+    /**
13
+     * @param string $color hex string of color to use for transparent zones
14
+     */
15
+    function __construct($color) {
16
+        $this->color = $color;
17
+    }
18 18
 
19
-	/**
20
-	 * @param   string    $src_filename     the basename of the file (ex: my-awesome-pic)
21
-	 * @param   string    $src_extension    ignored
22
-	 * @return  string    the final filename to be used (ex: my-awesome-pic.jpg)
23
-	 */
24
-	function filename($src_filename, $src_extension = 'jpg') {
25
-		$new_name = $src_filename . '.jpg';
26
-		return $new_name;
27
-	}
19
+    /**
20
+     * @param   string    $src_filename     the basename of the file (ex: my-awesome-pic)
21
+     * @param   string    $src_extension    ignored
22
+     * @return  string    the final filename to be used (ex: my-awesome-pic.jpg)
23
+     */
24
+    function filename($src_filename, $src_extension = 'jpg') {
25
+        $new_name = $src_filename . '.jpg';
26
+        return $new_name;
27
+    }
28 28
 
29
-	/**
30
-	 * Performs the actual image manipulation,
31
-	 * including saving the target file.
32
-	 *
33
-	 * @param  string $load_filename filepath (not URL) to source file (ex: /src/var/www/wp-content/uploads/my-pic.jpg)
34
-	 * @param  string $save_filename filepath (not URL) where result file should be saved
35
-	 *                               (ex: /src/var/www/wp-content/uploads/my-pic.png)
36
-	 * @return bool                  true if everything went fine, false otherwise
37
-	 */
38
-	function run($load_filename, $save_filename) {
39
-		$input = self::image_create( $load_filename );
40
-		list( $width, $height ) = getimagesize( $load_filename );
41
-		$output = imagecreatetruecolor( $width, $height );
42
-		$c = self::hexrgb( $this->color );
43
-		$color = imagecolorallocate( $output, $c['red'], $c['green'], $c['blue'] );
44
-		imagefilledrectangle( $output, 0, 0, $width, $height, $color );
45
-		imagecopy( $output, $input, 0, 0, 0, 0, $width, $height );
46
-		imagejpeg( $output, $save_filename );
47
-		return true;
48
-	}
29
+    /**
30
+     * Performs the actual image manipulation,
31
+     * including saving the target file.
32
+     *
33
+     * @param  string $load_filename filepath (not URL) to source file (ex: /src/var/www/wp-content/uploads/my-pic.jpg)
34
+     * @param  string $save_filename filepath (not URL) where result file should be saved
35
+     *                               (ex: /src/var/www/wp-content/uploads/my-pic.png)
36
+     * @return bool                  true if everything went fine, false otherwise
37
+     */
38
+    function run($load_filename, $save_filename) {
39
+        $input = self::image_create( $load_filename );
40
+        list( $width, $height ) = getimagesize( $load_filename );
41
+        $output = imagecreatetruecolor( $width, $height );
42
+        $c = self::hexrgb( $this->color );
43
+        $color = imagecolorallocate( $output, $c['red'], $c['green'], $c['blue'] );
44
+        imagefilledrectangle( $output, 0, 0, $width, $height, $color );
45
+        imagecopy( $output, $input, 0, 0, 0, 0, $width, $height );
46
+        imagejpeg( $output, $save_filename );
47
+        return true;
48
+    }
49 49
 
50
-	/**
51
-	 * @param string $filename
52
-	 * @return resource an image identifier representing the image obtained from the given filename
53
-	 *                  will return the same data type regardless of whether the source is gif or png
54
-	 */
55
-	function image_create( $filename, $ext = 'auto' ) {
56
-		if ( $ext == 'auto' ) {
57
-			$ext = wp_check_filetype($filename);
58
-			if (isset($ext['ext'])) {
59
-				$ext = $ext['ext'];
60
-			}
61
-		}
62
-		$ext = strtolower($ext);
63
-		if ( $ext == 'gif' ) {
64
-			return imagecreatefromgif($filename);
65
-		}
66
-		if ( $ext == 'png' ) {
67
-			return imagecreatefrompng($filename);
68
-		}
69
-		if ( $ext == 'jpg' || $ext == 'jpeg' ) {
70
-			return imagecreatefromjpeg($filename);
71
-		}
72
-		throw new InvalidArgumentException( 'image_create only accepts PNG, GIF and JPGs. File extension was: '.$ext );
73
-	}
50
+    /**
51
+     * @param string $filename
52
+     * @return resource an image identifier representing the image obtained from the given filename
53
+     *                  will return the same data type regardless of whether the source is gif or png
54
+     */
55
+    function image_create( $filename, $ext = 'auto' ) {
56
+        if ( $ext == 'auto' ) {
57
+            $ext = wp_check_filetype($filename);
58
+            if (isset($ext['ext'])) {
59
+                $ext = $ext['ext'];
60
+            }
61
+        }
62
+        $ext = strtolower($ext);
63
+        if ( $ext == 'gif' ) {
64
+            return imagecreatefromgif($filename);
65
+        }
66
+        if ( $ext == 'png' ) {
67
+            return imagecreatefrompng($filename);
68
+        }
69
+        if ( $ext == 'jpg' || $ext == 'jpeg' ) {
70
+            return imagecreatefromjpeg($filename);
71
+        }
72
+        throw new InvalidArgumentException( 'image_create only accepts PNG, GIF and JPGs. File extension was: '.$ext );
73
+    }
74 74
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 	/**
13 13
 	 * @param string $color hex string of color to use for transparent zones
14 14
 	 */
15
-	function __construct($color) {
15
+	function __construct( $color ) {
16 16
 		$this->color = $color;
17 17
 	}
18 18
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 * @param   string    $src_extension    ignored
22 22
 	 * @return  string    the final filename to be used (ex: my-awesome-pic.jpg)
23 23
 	 */
24
-	function filename($src_filename, $src_extension = 'jpg') {
24
+	function filename( $src_filename, $src_extension = 'jpg' ) {
25 25
 		$new_name = $src_filename . '.jpg';
26 26
 		return $new_name;
27 27
 	}
@@ -35,15 +35,15 @@  discard block
 block discarded – undo
35 35
 	 *                               (ex: /src/var/www/wp-content/uploads/my-pic.png)
36 36
 	 * @return bool                  true if everything went fine, false otherwise
37 37
 	 */
38
-	function run($load_filename, $save_filename) {
39
-		$input = self::image_create( $load_filename );
40
-		list( $width, $height ) = getimagesize( $load_filename );
41
-		$output = imagecreatetruecolor( $width, $height );
42
-		$c = self::hexrgb( $this->color );
43
-		$color = imagecolorallocate( $output, $c['red'], $c['green'], $c['blue'] );
44
-		imagefilledrectangle( $output, 0, 0, $width, $height, $color );
45
-		imagecopy( $output, $input, 0, 0, 0, 0, $width, $height );
46
-		imagejpeg( $output, $save_filename );
38
+	function run( $load_filename, $save_filename ) {
39
+		$input = self::image_create($load_filename);
40
+		list($width, $height) = getimagesize($load_filename);
41
+		$output = imagecreatetruecolor($width, $height);
42
+		$c = self::hexrgb($this->color);
43
+		$color = imagecolorallocate($output, $c['red'], $c['green'], $c['blue']);
44
+		imagefilledrectangle($output, 0, 0, $width, $height, $color);
45
+		imagecopy($output, $input, 0, 0, 0, 0, $width, $height);
46
+		imagejpeg($output, $save_filename);
47 47
 		return true;
48 48
 	}
49 49
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	function image_create( $filename, $ext = 'auto' ) {
56 56
 		if ( $ext == 'auto' ) {
57 57
 			$ext = wp_check_filetype($filename);
58
-			if (isset($ext['ext'])) {
58
+			if ( isset($ext['ext']) ) {
59 59
 				$ext = $ext['ext'];
60 60
 			}
61 61
 		}
@@ -69,6 +69,6 @@  discard block
 block discarded – undo
69 69
 		if ( $ext == 'jpg' || $ext == 'jpeg' ) {
70 70
 			return imagecreatefromjpeg($filename);
71 71
 		}
72
-		throw new InvalidArgumentException( 'image_create only accepts PNG, GIF and JPGs. File extension was: '.$ext );
72
+		throw new InvalidArgumentException('image_create only accepts PNG, GIF and JPGs. File extension was: ' . $ext);
73 73
 	}
74 74
 }
Please login to merge, or discard this patch.
lib/image/timber-image-operation.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -1,49 +1,49 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Each image filter is represented by a subclass of this class,m
4
- * and each filter call is a new instance, with call arguments as properties.
5
- * 
6
- * Only 3 methods need to be implemented:
7
- * - constructor, storing all filter arguments
8
- * - filename
9
- * - run
10
- */
3
+     * Each image filter is represented by a subclass of this class,m
4
+     * and each filter call is a new instance, with call arguments as properties.
5
+     * 
6
+     * Only 3 methods need to be implemented:
7
+     * - constructor, storing all filter arguments
8
+     * - filename
9
+     * - run
10
+     */
11 11
 abstract class TimberImageOperation {
12
-	/**
13
-	 * Builds the result filename, based on source filename and extension
14
-	 * 
15
-	 * @param  string $src_filename  source filename (excluding extension and path)
16
-	 * @param  string $src_extension source file extension
17
-	 * @return string                resulting filename (including extension but excluding path)
18
-	 *                               ex: my-awesome-file.jpg
19
-	 */
20
-	public abstract function filename($src_filename, $src_extension);
12
+    /**
13
+     * Builds the result filename, based on source filename and extension
14
+     * 
15
+     * @param  string $src_filename  source filename (excluding extension and path)
16
+     * @param  string $src_extension source file extension
17
+     * @return string                resulting filename (including extension but excluding path)
18
+     *                               ex: my-awesome-file.jpg
19
+     */
20
+    public abstract function filename($src_filename, $src_extension);
21 21
 
22
-	/**
23
-	 * Performs the actual image manipulation,
24
-	 * including saving the target file.
25
-	 * 
26
-	 * @param  string $load_filename filepath (not URL) to source file
27
-	 * @param  string $save_filename filepath (not URL) where result file should be saved
28
-	 * @return bool                  true if everything went fine, false otherwise
29
-	 */
30
-	public abstract function run($load_filename, $save_filename);
22
+    /**
23
+     * Performs the actual image manipulation,
24
+     * including saving the target file.
25
+     * 
26
+     * @param  string $load_filename filepath (not URL) to source file
27
+     * @param  string $save_filename filepath (not URL) where result file should be saved
28
+     * @return bool                  true if everything went fine, false otherwise
29
+     */
30
+    public abstract function run($load_filename, $save_filename);
31 31
 
32
-	/**
33
-	 * Helper method to convert hex string to rgb array
34
-	 * 
35
-	 * @param  string $hexstr hex color string (like '#FF1455')
36
-	 * @return array          array('red', 'green', 'blue') to int
37
-	 *                        ex: array('red' => 255, 'green' => 20, 'blue' => 85);
38
-	 */
39
-	public static function hexrgb( $hexstr ) {
40
-		if ( !strstr( $hexstr, '#' ) ) {
41
-			$hexstr = '#' . $hexstr;
42
-		}
43
-		if ( strlen( $hexstr ) == 4 ) {
44
-			$hexstr = '#' . $hexstr[1] . $hexstr[1] . $hexstr[2] . $hexstr[2] . $hexstr[3] . $hexstr[3];
45
-		}
46
-		$int = hexdec( $hexstr );
47
-		return array( "red" => 0xFF & ( $int >> 0x10 ), "green" => 0xFF & ( $int >> 0x8 ), "blue" => 0xFF & $int );
48
-	}
32
+    /**
33
+     * Helper method to convert hex string to rgb array
34
+     * 
35
+     * @param  string $hexstr hex color string (like '#FF1455')
36
+     * @return array          array('red', 'green', 'blue') to int
37
+     *                        ex: array('red' => 255, 'green' => 20, 'blue' => 85);
38
+     */
39
+    public static function hexrgb( $hexstr ) {
40
+        if ( !strstr( $hexstr, '#' ) ) {
41
+            $hexstr = '#' . $hexstr;
42
+        }
43
+        if ( strlen( $hexstr ) == 4 ) {
44
+            $hexstr = '#' . $hexstr[1] . $hexstr[1] . $hexstr[2] . $hexstr[2] . $hexstr[3] . $hexstr[3];
45
+        }
46
+        $int = hexdec( $hexstr );
47
+        return array( "red" => 0xFF & ( $int >> 0x10 ), "green" => 0xFF & ( $int >> 0x8 ), "blue" => 0xFF & $int );
48
+    }
49 49
 }
50 50
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 	 * @return string                resulting filename (including extension but excluding path)
18 18
 	 *                               ex: my-awesome-file.jpg
19 19
 	 */
20
-	public abstract function filename($src_filename, $src_extension);
20
+	public abstract function filename( $src_filename, $src_extension );
21 21
 
22 22
 	/**
23 23
 	 * Performs the actual image manipulation,
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	 * @param  string $save_filename filepath (not URL) where result file should be saved
28 28
 	 * @return bool                  true if everything went fine, false otherwise
29 29
 	 */
30
-	public abstract function run($load_filename, $save_filename);
30
+	public abstract function run( $load_filename, $save_filename );
31 31
 
32 32
 	/**
33 33
 	 * Helper method to convert hex string to rgb array
@@ -37,13 +37,13 @@  discard block
 block discarded – undo
37 37
 	 *                        ex: array('red' => 255, 'green' => 20, 'blue' => 85);
38 38
 	 */
39 39
 	public static function hexrgb( $hexstr ) {
40
-		if ( !strstr( $hexstr, '#' ) ) {
40
+		if ( !strstr($hexstr, '#') ) {
41 41
 			$hexstr = '#' . $hexstr;
42 42
 		}
43
-		if ( strlen( $hexstr ) == 4 ) {
43
+		if ( strlen($hexstr) == 4 ) {
44 44
 			$hexstr = '#' . $hexstr[1] . $hexstr[1] . $hexstr[2] . $hexstr[2] . $hexstr[3] . $hexstr[3];
45 45
 		}
46
-		$int = hexdec( $hexstr );
47
-		return array( "red" => 0xFF & ( $int >> 0x10 ), "green" => 0xFF & ( $int >> 0x8 ), "blue" => 0xFF & $int );
46
+		$int = hexdec($hexstr);
47
+		return array("red" => 0xFF & ($int >> 0x10), "green" => 0xFF & ($int >> 0x8), "blue" => 0xFF & $int);
48 48
 	}
49 49
 }
50 50
\ No newline at end of file
Please login to merge, or discard this patch.
lib/timber-twig.php 2 patches
Indentation   +341 added lines, -341 removed lines patch added patch discarded remove patch
@@ -2,346 +2,346 @@
 block discarded – undo
2 2
 
3 3
 class TimberTwig {
4 4
 
5
-	public static $dir_name;
6
-
7
-	/**
8
-	 * @codeCoverageIgnore
9
-	 */
10
-	public static function init() {
11
-		new TimberTwig();
12
-	}
13
-
14
-	/**
15
-	 * @codeCoverageIgnore
16
-	 */
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' ) );
20
-	}
21
-
22
-	/**
23
-	 * These are all deprecated and will be removed in 0.21.0
24
-	 *
25
-	 * @param Twig_Environment $twig
26
-	 * @deprecated since 0.20.7
27
-	 * @return Twig_Environment
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 = ' '){
35
-			return twig_join_filter($arr, $glue);
36
-		} ) );
37
-		return $twig;
38
-	}
39
-
40
-	/**
41
-	 *
42
-	 *
43
-	 * @param Twig_Environment $twig
44
-	 * @return Twig_Environment
45
-	 */
46
-	function add_timber_filters( $twig ) {
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' ) ) );
52
-
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
-				} ) );
63
-
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
-				} ) );
85
-
86
-		/* actions and filters */
87
-		$twig->addFunction( new Twig_SimpleFunction( 'action', function ( $context ) {
88
-					$args = func_get_args();
89
-					array_shift( $args );
90
-					$args[] = $context;
91
-					call_user_func_array( 'do_action', $args );
92
-				}, array( 'needs_context' => true ) ) );
93
-
94
-		$twig->addFilter( new Twig_SimpleFilter( 'apply_filters', function () {
95
-					$args = func_get_args();
96
-					$tag = current( array_splice( $args, 1, 1 ) );
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' ) ) );
102
-
103
-		$twig->addFunction( new Twig_SimpleFunction( 'shortcode', 'do_shortcode' ) );
104
-
105
-		/* TimberObjects */
106
-		$twig->addFunction( new Twig_SimpleFunction( 'TimberPost', function ( $pid, $PostClass = 'TimberPost' ) {
107
-					if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
108
-						foreach ( $pid as &$p ) {
109
-							$p = new $PostClass( $p );
110
-						}
111
-						return $pid;
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 ) ) {
117
-						foreach ( $pid as &$p ) {
118
-							$p = new $ImageClass( $p );
119
-						}
120
-						return $pid;
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 ) ) {
126
-						foreach ( $pid as &$p ) {
127
-							$p = new $TermClass( $p );
128
-						}
129
-						return $pid;
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 ) ) {
135
-						foreach ( $pid as &$p ) {
136
-							$p = new $UserClass( $p );
137
-						}
138
-						return $pid;
139
-					}
140
-					return new $UserClass( $pid );
141
-				} ) );
142
-
143
-		/* TimberObjects Alias */
144
-		$twig->addFunction( new Twig_SimpleFunction( 'Post', function ( $pid, $PostClass = 'TimberPost' ) {
145
-					if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
146
-						foreach ( $pid as &$p ) {
147
-							$p = new $PostClass( $p );
148
-						}
149
-						return $pid;
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 ) ) {
155
-						foreach ( $pid as &$p ) {
156
-							$p = new $ImageClass( $p );
157
-						}
158
-						return $pid;
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 ) ) {
164
-						foreach ( $pid as &$p ) {
165
-							$p = new $TermClass( $p );
166
-						}
167
-						return $pid;
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 ) ) {
173
-						foreach ( $pid as &$p ) {
174
-							$p = new $UserClass( $p );
175
-						}
176
-						return $pid;
177
-					}
178
-					return new $UserClass( $pid );
179
-				} ) );
180
-
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
-				} ) );
188
-		/* get_twig is deprecated, use timber/twig */
189
-		$twig = apply_filters( 'get_twig', $twig );
190
-		$twig = apply_filters( 'timber/twig', $twig );
191
-		return $twig;
192
-	}
193
-
194
-	/**
195
-	 *
196
-	 *
197
-	 * @param mixed   $arr
198
-	 * @return array
199
-	 */
200
-	function to_array( $arr ) {
201
-		if ( is_array( $arr ) ) {
202
-			return $arr;
203
-		}
204
-		$arr = array( $arr );
205
-		return $arr;
206
-	}
207
-
208
-	/**
209
-	 *
210
-	 *
211
-	 * @param string  $function_name
212
-	 * @return mixed
213
-	 */
214
-	function exec_function( $function_name ) {
215
-		$args = func_get_args();
216
-		array_shift( $args );
217
-		if ( is_string($function_name) ) {
218
-			$function_name = trim( $function_name );
219
-		}
220
-		return call_user_func_array( $function_name, ( $args ) );
221
-	}
222
-
223
-	/**
224
-	 *
225
-	 *
226
-	 * @param string  $content
227
-	 * @return string
228
-	 */
229
-	function twig_pretags( $content ) {
230
-		return preg_replace_callback( '|<pre.*>(.*)</pre|isU', array( &$this, 'convert_pre_entities' ), $content );
231
-	}
232
-
233
-	/**
234
-	 *
235
-	 *
236
-	 * @param array   $matches
237
-	 * @return string
238
-	 */
239
-	function convert_pre_entities( $matches ) {
240
-		return str_replace( $matches[1], htmlentities( $matches[1] ), $matches[0] );
241
-	}
242
-
243
-	/**
244
-	 * @param mixed   $body_classes
245
-	 * @deprecated 0.20.7
246
-	 * @return string
247
-	 */
248
-	function body_class( $body_classes ) {
249
-		ob_start();
250
-		if ( is_array( $body_classes ) ) {
251
-			$body_classes = explode( ' ', $body_classes );
252
-		}
253
-		body_class( $body_classes );
254
-		$return = ob_get_contents();
255
-		ob_end_clean();
256
-		return $return;
257
-	}
258
-
259
-	/**
260
-	 *
261
-	 *
262
-	 * @param string  $date
263
-	 * @param string  $format (optional)
264
-	 * @return string
265
-	 */
266
-	function intl_date( $date, $format = null ) {
267
-		if ( $format === null ) {
268
-			$format = get_option( 'date_format' );
269
-		}
270
-
271
-		if ( $date instanceof DateTime ) {
272
-			$timestamp = $date->getTimestamp() + $date->getOffset();
273
-		} else if (is_numeric( $date ) && strtotime( $date ) === false ) {
274
-			$timestamp = intval( $date );
275
-		} else {
276
-			$timestamp = strtotime( $date );
277
-		}
278
-
279
-		return date_i18n( $format, $timestamp );
280
-	}
281
-
282
-	//debug
283
-
284
-	/**
285
-	 *
286
-	 *
287
-	 * @param mixed   $obj
288
-	 * @param bool    $methods
289
-	 * @deprecated since 0.20.7
290
-	 * @return string
291
-	 */
292
-	function object_docs( $obj, $methods = true ) {
293
-		$class = get_class( $obj );
294
-		$properties = (array)$obj;
295
-		if ( $methods ) {
296
-			/** @var array $methods */
297
-			$methods = $obj->get_method_values();
298
-		}
299
-		$rets = array_merge( $properties, $methods );
300
-		ksort( $rets );
301
-		$str = print_r( $rets, true );
302
-		$str = str_replace( 'Array', $class . ' Object', $str );
303
-		return $str;
304
-	}
305
-
306
-	/**
307
-	 * @param int|string $from
308
-	 * @param int|string $to
309
-	 * @param string $format_past
310
-	 * @param string $format_future
311
-	 * @return string
312
-	 */
313
-	function time_ago( $from, $to = null, $format_past = '%s ago', $format_future = '%s from now' ) {
314
-		$to = $to === null ? time() : $to;
315
-		$to = is_int( $to ) ? $to : strtotime( $to );
316
-		$from = is_int( $from ) ? $from : strtotime( $from );
317
-
318
-		if ( $from < $to ) {
319
-			return sprintf( $format_past, human_time_diff( $from, $to ) );
320
-		} else {
321
-			return sprintf( $format_future, human_time_diff( $to, $from ) );
322
-		}
323
-	}
324
-
325
-	/**
326
-	 * @param array $arr
327
-	 * @param string $first_delimiter
328
-	 * @param string $second_delimiter
329
-	 * @return string
330
-	 */
331
-	function add_list_separators( $arr, $first_delimiter = ',', $second_delimiter = 'and' ) {
332
-		$length = count( $arr );
333
-		$list = '';
334
-		foreach( $arr as $index => $item ) {
335
-			if ( $index < $length - 2 ) {
336
-				$delimiter = $first_delimiter.' ';
337
-			} elseif ( $index == $length - 2 ) {
338
-				$delimiter = ' '.$second_delimiter.' ';
339
-			} else {
340
-				$delimiter = '';
341
-			}
342
-			$list = $list.$item.$delimiter;
343
-		}
344
-		return $list;
345
-	}
5
+    public static $dir_name;
6
+
7
+    /**
8
+     * @codeCoverageIgnore
9
+     */
10
+    public static function init() {
11
+        new TimberTwig();
12
+    }
13
+
14
+    /**
15
+     * @codeCoverageIgnore
16
+     */
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' ) );
20
+    }
21
+
22
+    /**
23
+     * These are all deprecated and will be removed in 0.21.0
24
+     *
25
+     * @param Twig_Environment $twig
26
+     * @deprecated since 0.20.7
27
+     * @return Twig_Environment
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 = ' '){
35
+            return twig_join_filter($arr, $glue);
36
+        } ) );
37
+        return $twig;
38
+    }
39
+
40
+    /**
41
+     *
42
+     *
43
+     * @param Twig_Environment $twig
44
+     * @return Twig_Environment
45
+     */
46
+    function add_timber_filters( $twig ) {
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' ) ) );
52
+
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
+                } ) );
63
+
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
+                } ) );
85
+
86
+        /* actions and filters */
87
+        $twig->addFunction( new Twig_SimpleFunction( 'action', function ( $context ) {
88
+                    $args = func_get_args();
89
+                    array_shift( $args );
90
+                    $args[] = $context;
91
+                    call_user_func_array( 'do_action', $args );
92
+                }, array( 'needs_context' => true ) ) );
93
+
94
+        $twig->addFilter( new Twig_SimpleFilter( 'apply_filters', function () {
95
+                    $args = func_get_args();
96
+                    $tag = current( array_splice( $args, 1, 1 ) );
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' ) ) );
102
+
103
+        $twig->addFunction( new Twig_SimpleFunction( 'shortcode', 'do_shortcode' ) );
104
+
105
+        /* TimberObjects */
106
+        $twig->addFunction( new Twig_SimpleFunction( 'TimberPost', function ( $pid, $PostClass = 'TimberPost' ) {
107
+                    if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
108
+                        foreach ( $pid as &$p ) {
109
+                            $p = new $PostClass( $p );
110
+                        }
111
+                        return $pid;
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 ) ) {
117
+                        foreach ( $pid as &$p ) {
118
+                            $p = new $ImageClass( $p );
119
+                        }
120
+                        return $pid;
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 ) ) {
126
+                        foreach ( $pid as &$p ) {
127
+                            $p = new $TermClass( $p );
128
+                        }
129
+                        return $pid;
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 ) ) {
135
+                        foreach ( $pid as &$p ) {
136
+                            $p = new $UserClass( $p );
137
+                        }
138
+                        return $pid;
139
+                    }
140
+                    return new $UserClass( $pid );
141
+                } ) );
142
+
143
+        /* TimberObjects Alias */
144
+        $twig->addFunction( new Twig_SimpleFunction( 'Post', function ( $pid, $PostClass = 'TimberPost' ) {
145
+                    if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
146
+                        foreach ( $pid as &$p ) {
147
+                            $p = new $PostClass( $p );
148
+                        }
149
+                        return $pid;
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 ) ) {
155
+                        foreach ( $pid as &$p ) {
156
+                            $p = new $ImageClass( $p );
157
+                        }
158
+                        return $pid;
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 ) ) {
164
+                        foreach ( $pid as &$p ) {
165
+                            $p = new $TermClass( $p );
166
+                        }
167
+                        return $pid;
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 ) ) {
173
+                        foreach ( $pid as &$p ) {
174
+                            $p = new $UserClass( $p );
175
+                        }
176
+                        return $pid;
177
+                    }
178
+                    return new $UserClass( $pid );
179
+                } ) );
180
+
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
+                } ) );
188
+        /* get_twig is deprecated, use timber/twig */
189
+        $twig = apply_filters( 'get_twig', $twig );
190
+        $twig = apply_filters( 'timber/twig', $twig );
191
+        return $twig;
192
+    }
193
+
194
+    /**
195
+     *
196
+     *
197
+     * @param mixed   $arr
198
+     * @return array
199
+     */
200
+    function to_array( $arr ) {
201
+        if ( is_array( $arr ) ) {
202
+            return $arr;
203
+        }
204
+        $arr = array( $arr );
205
+        return $arr;
206
+    }
207
+
208
+    /**
209
+     *
210
+     *
211
+     * @param string  $function_name
212
+     * @return mixed
213
+     */
214
+    function exec_function( $function_name ) {
215
+        $args = func_get_args();
216
+        array_shift( $args );
217
+        if ( is_string($function_name) ) {
218
+            $function_name = trim( $function_name );
219
+        }
220
+        return call_user_func_array( $function_name, ( $args ) );
221
+    }
222
+
223
+    /**
224
+     *
225
+     *
226
+     * @param string  $content
227
+     * @return string
228
+     */
229
+    function twig_pretags( $content ) {
230
+        return preg_replace_callback( '|<pre.*>(.*)</pre|isU', array( &$this, 'convert_pre_entities' ), $content );
231
+    }
232
+
233
+    /**
234
+     *
235
+     *
236
+     * @param array   $matches
237
+     * @return string
238
+     */
239
+    function convert_pre_entities( $matches ) {
240
+        return str_replace( $matches[1], htmlentities( $matches[1] ), $matches[0] );
241
+    }
242
+
243
+    /**
244
+     * @param mixed   $body_classes
245
+     * @deprecated 0.20.7
246
+     * @return string
247
+     */
248
+    function body_class( $body_classes ) {
249
+        ob_start();
250
+        if ( is_array( $body_classes ) ) {
251
+            $body_classes = explode( ' ', $body_classes );
252
+        }
253
+        body_class( $body_classes );
254
+        $return = ob_get_contents();
255
+        ob_end_clean();
256
+        return $return;
257
+    }
258
+
259
+    /**
260
+     *
261
+     *
262
+     * @param string  $date
263
+     * @param string  $format (optional)
264
+     * @return string
265
+     */
266
+    function intl_date( $date, $format = null ) {
267
+        if ( $format === null ) {
268
+            $format = get_option( 'date_format' );
269
+        }
270
+
271
+        if ( $date instanceof DateTime ) {
272
+            $timestamp = $date->getTimestamp() + $date->getOffset();
273
+        } else if (is_numeric( $date ) && strtotime( $date ) === false ) {
274
+            $timestamp = intval( $date );
275
+        } else {
276
+            $timestamp = strtotime( $date );
277
+        }
278
+
279
+        return date_i18n( $format, $timestamp );
280
+    }
281
+
282
+    //debug
283
+
284
+    /**
285
+     *
286
+     *
287
+     * @param mixed   $obj
288
+     * @param bool    $methods
289
+     * @deprecated since 0.20.7
290
+     * @return string
291
+     */
292
+    function object_docs( $obj, $methods = true ) {
293
+        $class = get_class( $obj );
294
+        $properties = (array)$obj;
295
+        if ( $methods ) {
296
+            /** @var array $methods */
297
+            $methods = $obj->get_method_values();
298
+        }
299
+        $rets = array_merge( $properties, $methods );
300
+        ksort( $rets );
301
+        $str = print_r( $rets, true );
302
+        $str = str_replace( 'Array', $class . ' Object', $str );
303
+        return $str;
304
+    }
305
+
306
+    /**
307
+     * @param int|string $from
308
+     * @param int|string $to
309
+     * @param string $format_past
310
+     * @param string $format_future
311
+     * @return string
312
+     */
313
+    function time_ago( $from, $to = null, $format_past = '%s ago', $format_future = '%s from now' ) {
314
+        $to = $to === null ? time() : $to;
315
+        $to = is_int( $to ) ? $to : strtotime( $to );
316
+        $from = is_int( $from ) ? $from : strtotime( $from );
317
+
318
+        if ( $from < $to ) {
319
+            return sprintf( $format_past, human_time_diff( $from, $to ) );
320
+        } else {
321
+            return sprintf( $format_future, human_time_diff( $to, $from ) );
322
+        }
323
+    }
324
+
325
+    /**
326
+     * @param array $arr
327
+     * @param string $first_delimiter
328
+     * @param string $second_delimiter
329
+     * @return string
330
+     */
331
+    function add_list_separators( $arr, $first_delimiter = ',', $second_delimiter = 'and' ) {
332
+        $length = count( $arr );
333
+        $list = '';
334
+        foreach( $arr as $index => $item ) {
335
+            if ( $index < $length - 2 ) {
336
+                $delimiter = $first_delimiter.' ';
337
+            } elseif ( $index == $length - 2 ) {
338
+                $delimiter = ' '.$second_delimiter.' ';
339
+            } else {
340
+                $delimiter = '';
341
+            }
342
+            $list = $list.$item.$delimiter;
343
+        }
344
+        return $list;
345
+    }
346 346
 
347 347
 }
Please login to merge, or discard this patch.
Spacing   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
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
 	/**
@@ -27,13 +27,13 @@  discard block
 block discarded – undo
27 27
 	 * @return Twig_Environment
28 28
 	 */
29 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 = ' '){
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
 
@@ -45,149 +45,149 @@  discard block
 block discarded – undo
45 45
 	 */
46 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
 
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
 	 * @return array
199 199
 	 */
200 200
 	function to_array( $arr ) {
201
-		if ( is_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
 
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
 	 */
214 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
 	/**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 * @return string
228 228
 	 */
229 229
 	function twig_pretags( $content ) {
230
-		return preg_replace_callback( '|<pre.*>(.*)</pre|isU', array( &$this, 'convert_pre_entities' ), $content );
230
+		return preg_replace_callback('|<pre.*>(.*)</pre|isU', array(&$this, 'convert_pre_entities'), $content);
231 231
 	}
232 232
 
233 233
 	/**
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 	 * @return string
238 238
 	 */
239 239
 	function convert_pre_entities( $matches ) {
240
-		return str_replace( $matches[1], htmlentities( $matches[1] ), $matches[0] );
240
+		return str_replace($matches[1], htmlentities($matches[1]), $matches[0]);
241 241
 	}
242 242
 
243 243
 	/**
@@ -247,10 +247,10 @@  discard block
 block discarded – undo
247 247
 	 */
248 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;
@@ -265,18 +265,18 @@  discard block
 block discarded – undo
265 265
 	 */
266 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
@@ -290,16 +290,16 @@  discard block
 block discarded – undo
290 290
 	 * @return string
291 291
 	 */
292 292
 	function object_docs( $obj, $methods = true ) {
293
-		$class = get_class( $obj );
294
-		$properties = (array)$obj;
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
 
@@ -312,13 +312,13 @@  discard block
 block discarded – undo
312 312
 	 */
313 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
 
@@ -329,17 +329,17 @@  discard block
 block discarded – undo
329 329
 	 * @return string
330 330
 	 */
331 331
 	function add_list_separators( $arr, $first_delimiter = ',', $second_delimiter = 'and' ) {
332
-		$length = count( $arr );
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
 	}
Please login to merge, or discard this patch.
lib/timber-admin.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -6,21 +6,21 @@
 block discarded – undo
6 6
         return add_filter( 'plugin_row_meta', array( __CLASS__, 'meta_links' ), 10, 2 );
7 7
     }
8 8
 
9
-	/**
10
-	 * @param array   $links
11
-	 * @param string  $file
12
-	 * @return array
13
-	 */
14
-	public static function meta_links( $links, $file ) {
15
-		if ( strstr( $file, '/timber.php' ) ) {
16
-			unset($links[2]);
17
-			$links[] = '<a href="/wp-admin/plugin-install.php?tab=plugin-information&amp;plugin=timber-library&amp;TB_iframe=true&amp;width=600&amp;height=550" class="thickbox" aria-label="More information about Timber" data-title="Timber">View details</a>';
18
-			$links[] = '<a href="http://upstatement.com/timber" target="_blank">Homepage</a>';
19
-			$links[] = '<a href="https://github.com/jarednova/timber/wiki" target="_blank">Documentation</a>';
20
-			$links[] = '<a href="https://github.com/jarednova/timber/wiki/getting-started" target="_blank">Starter Guide</a>';
21
-			return $links;
22
-		}
23
-		return $links;
24
-	}
9
+    /**
10
+     * @param array   $links
11
+     * @param string  $file
12
+     * @return array
13
+     */
14
+    public static function meta_links( $links, $file ) {
15
+        if ( strstr( $file, '/timber.php' ) ) {
16
+            unset($links[2]);
17
+            $links[] = '<a href="/wp-admin/plugin-install.php?tab=plugin-information&amp;plugin=timber-library&amp;TB_iframe=true&amp;width=600&amp;height=550" class="thickbox" aria-label="More information about Timber" data-title="Timber">View details</a>';
18
+            $links[] = '<a href="http://upstatement.com/timber" target="_blank">Homepage</a>';
19
+            $links[] = '<a href="https://github.com/jarednova/timber/wiki" target="_blank">Documentation</a>';
20
+            $links[] = '<a href="https://github.com/jarednova/timber/wiki/getting-started" target="_blank">Starter Guide</a>';
21
+            return $links;
22
+        }
23
+        return $links;
24
+    }
25 25
 
26 26
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 class TimberAdmin {
4 4
 
5 5
     public static function init() {
6
-        return add_filter( 'plugin_row_meta', array( __CLASS__, 'meta_links' ), 10, 2 );
6
+        return add_filter('plugin_row_meta', array(__CLASS__, 'meta_links'), 10, 2);
7 7
     }
8 8
 
9 9
 	/**
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 	 * @return array
13 13
 	 */
14 14
 	public static function meta_links( $links, $file ) {
15
-		if ( strstr( $file, '/timber.php' ) ) {
15
+		if ( strstr($file, '/timber.php') ) {
16 16
 			unset($links[2]);
17 17
 			$links[] = '<a href="/wp-admin/plugin-install.php?tab=plugin-information&amp;plugin=timber-library&amp;TB_iframe=true&amp;width=600&amp;height=550" class="thickbox" aria-label="More information about Timber" data-title="Timber">View details</a>';
18 18
 			$links[] = '<a href="http://upstatement.com/timber" target="_blank">Homepage</a>';
Please login to merge, or discard this patch.