Completed
Push — master ( fdd09c...cca8a6 )
by Jared
02:55
created
lib/timber-post.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 * @param mixed $pid
169 169
 	 */
170 170
 	public function __construct($pid = null) {
171
-		$pid = $this->determine_id( $pid );
171
+		$pid = $this->determine_id($pid);
172 172
 		$this->init($pid);
173 173
 	}
174 174
 
@@ -188,13 +188,13 @@  discard block
 block discarded – undo
188 188
 			&& get_class($wp_query->queried_object) == 'WP_Post'
189 189
 			) {
190 190
 			$pid = $wp_query->queried_object_id;
191
-		} else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id )  {
191
+		} else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id ) {
192 192
 			//hack for static page as home page
193 193
 			$pid = $wp_query->queried_object_id;
194 194
 		} else if ( $pid === null ) {
195 195
 			$gtid = false;
196 196
 			$maybe_post = get_post();
197
-			if ( isset($maybe_post->ID) ){
197
+			if ( isset($maybe_post->ID) ) {
198 198
 				$gtid = true;
199 199
 			}
200 200
 			if ( $gtid ) {
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	 * @param string $field
261 261
 	 * @param mixed $value
262 262
 	 */
263
-	public function update( $field, $value ) {
263
+	public function update($field, $value) {
264 264
 		if ( isset($this->ID) ) {
265 265
 			update_post_meta($this->ID, $field, $value);
266 266
 			$this->$field = $value;
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	 * @param mixed $pid
276 276
 	 * @return WP_Post on success
277 277
 	 */
278
-	protected function prepare_post_info( $pid = 0 ) {
278
+	protected function prepare_post_info($pid = 0) {
279 279
 		if ( is_string($pid) || is_numeric($pid) || (is_object($pid) && !isset($pid->post_title)) || $pid === 0 ) {
280 280
 			$pid = self::check_post_id($pid);
281 281
 			$post = get_post($pid);
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 	 * @internal
298 298
 	 * @return integer ID number of a post
299 299
 	 */
300
-	protected function check_post_id( $pid ) {
300
+	protected function check_post_id($pid) {
301 301
 		if ( is_numeric($pid) && $pid === 0 ) {
302 302
 			$pid = get_the_ID();
303 303
 			return $pid;
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 		global $wpdb;
324 324
 		$query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s LIMIT 1", $post_name);
325 325
 		$result = $wpdb->get_row($query);
326
-		if (!$result) {
326
+		if ( !$result ) {
327 327
 			return null;
328 328
 		}
329 329
 		return $result->ID;
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 				$text = TimberHelper::trim_words($text, $len, false);
363 363
 				$trimmed = true;
364 364
 			}
365
-			$text = do_shortcode( $text );
365
+			$text = do_shortcode($text);
366 366
 		}
367 367
 		if ( !strlen($text) ) {
368 368
 			$text = TimberHelper::trim_words($this->get_content(), $len, false);
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
 			}
392 392
 			$read_more_class = apply_filters('timber/post/get_preview/read_more_class', "read-more");
393 393
 			if ( $readmore && isset($readmore_matches) && !empty($readmore_matches[1]) ) {
394
-				$text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore_matches[1]) . '</a>';
394
+				$text .= ' <a href="' . $this->get_permalink() . '" class="' . $read_more_class . '">' . trim($readmore_matches[1]) . '</a>';
395 395
 			} elseif ( $readmore ) {
396
-				$text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore) . '</a>';
396
+				$text .= ' <a href="' . $this->get_permalink() . '" class="' . $read_more_class . '">' . trim($readmore) . '</a>';
397 397
 			}
398
-			if ( !$strip && $last_p_tag && ( strpos($text, '<p>') || strpos($text, '<p ') ) ) {
398
+			if ( !$strip && $last_p_tag && (strpos($text, '<p>') || strpos($text, '<p ')) ) {
399 399
 				$text .= '</p>';
400 400
 			}
401 401
 		}
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 	 * @internal
408 408
 	 * @param bool|int $pid a post ID number
409 409
 	 */
410
-	function import_custom( $pid = false ) {
410
+	function import_custom($pid = false) {
411 411
 		if ( !$pid ) {
412 412
 			$pid = $this->ID;
413 413
 		}
@@ -422,13 +422,13 @@  discard block
 block discarded – undo
422 422
 	 * @param int $pid
423 423
 	 * @return array
424 424
 	 */
425
-	protected function get_post_custom( $pid ) {
425
+	protected function get_post_custom($pid) {
426 426
 		apply_filters('timber_post_get_meta_pre', array(), $pid, $this);
427 427
 		$customs = get_post_custom($pid);
428 428
 		if ( !is_array($customs) || empty($customs) ) {
429 429
 			return array();
430 430
 		}
431
-		foreach ( $customs as $key => $value ) {
431
+		foreach ($customs as $key => $value) {
432 432
 			if ( is_array($value) && count($value) == 1 && isset($value[0]) ) {
433 433
 				$value = $value[0];
434 434
 			}
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 	 * @param bool $taxonomy
483 483
 	 * @return TimberPost|boolean
484 484
 	 */
485
-	function get_next( $taxonomy = false ) {
485
+	function get_next($taxonomy = false) {
486 486
 		if ( !isset($this->_next) || !isset($this->_next[$taxonomy]) ) {
487 487
 			global $post;
488 488
 			$this->_next = array();
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 		$post = $this;
514 514
 		$ret = array();
515 515
 		if ( $multipage ) {
516
-			for ( $i = 1; $i <= $numpages; $i++ ) {
516
+			for ($i = 1; $i <= $numpages; $i++) {
517 517
 				$link = self::get_wp_link_page($i);
518 518
 				$data = array('name' => $i, 'title' => $i, 'text' => $i, 'link' => $link);
519 519
 				if ( $i == $page ) {
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 	 * @param bool $taxonomy
566 566
 	 * @return TimberPost|boolean
567 567
 	 */
568
-	function get_prev( $taxonomy = false ) {
568
+	function get_prev($taxonomy = false) {
569 569
 		if ( isset($this->_prev) && isset($this->_prev[$taxonomy]) ) {
570 570
 			return $this->_prev[$taxonomy];
571 571
 		}
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 		$post->slug = $post->post_name;
633 633
 		$customs = $this->get_post_custom($post->ID);
634 634
 		$post->custom = $customs;
635
-		$post = (object) array_merge((array)$customs, (array)$post);
635
+		$post = (object) array_merge((array) $customs, (array) $post);
636 636
 		return $post;
637 637
 	}
638 638
 
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
 	 * @param string $use
644 644
 	 * @return string
645 645
 	 */
646
-	function get_display_date( $use = 'post_date' ) {
646
+	function get_display_date($use = 'post_date') {
647 647
 		return date(get_option('date_format'), strtotime($this->$use));
648 648
 	}
649 649
 
@@ -653,9 +653,9 @@  discard block
 block discarded – undo
653 653
 	 * @param  string $date_format
654 654
 	 * @return string
655 655
 	 */
656
-	function get_date( $date_format = '' ) {
656
+	function get_date($date_format = '') {
657 657
 		$df = $date_format ? $date_format : get_option('date_format');
658
-		$the_date = (string)mysql2date($df, $this->post_date);
658
+		$the_date = (string) mysql2date($df, $this->post_date);
659 659
 		return apply_filters('get_the_date', $the_date, $df);
660 660
 	}
661 661
 
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 	 * @param  string $date_format
665 665
 	 * @return string
666 666
 	 */
667
-	function get_modified_date( $date_format = '' ) {
667
+	function get_modified_date($date_format = '') {
668 668
 		$df = $date_format ? $date_format : get_option('date_format');
669 669
 		$the_time = $this->get_modified_time($df);
670 670
 		return apply_filters('get_the_modified_date', $the_time, $date_format);
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
 	 * @param  string $time_format
676 676
 	 * @return string
677 677
 	 */
678
-	function get_modified_time( $time_format = '' ) {
678
+	function get_modified_time($time_format = '') {
679 679
 		$tf = $time_format ? $time_format : get_option('time_format');
680 680
 		$the_time = get_post_modified_time($tf, false, $this->ID, true);
681 681
 		return apply_filters('get_the_modified_time', $the_time, $time_format);
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
 	 * @param bool|string 	$childPostClass
689 689
 	 * @return array
690 690
 	 */
691
-	function get_children( $post_type = 'any', $childPostClass = false ) {
691
+	function get_children($post_type = 'any', $childPostClass = false) {
692 692
 		if ( $childPostClass === false ) {
693 693
 			$childPostClass = $this->PostClass;
694 694
 		}
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
 			$post_type = $this->post_type;
697 697
 		}
698 698
 		$children = get_children('post_parent=' . $this->ID . '&post_type=' . $post_type . '&numberposts=-1&orderby=menu_order title&order=ASC');
699
-		foreach ( $children as &$child ) {
699
+		foreach ($children as &$child) {
700 700
 			$child = new $childPostClass($child->ID);
701 701
 		}
702 702
 		$children = array_values($children);
@@ -732,20 +732,20 @@  discard block
 block discarded – undo
732 732
 		}
733 733
 
734 734
 		if ( $user_ID ) {
735
-			$args['include_unapproved'] = array( $user_ID );
736
-		} elseif ( ! empty( $comment_author_email ) ) {
737
-			$args['include_unapproved'] = array( $comment_author_email );
735
+			$args['include_unapproved'] = array($user_ID);
736
+		} elseif ( !empty($comment_author_email) ) {
737
+			$args['include_unapproved'] = array($comment_author_email);
738 738
 		}
739 739
 
740 740
 		$comments = get_comments($args);
741 741
 		$timber_comments = array();
742 742
 
743 743
 		if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
744
-			set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
744
+			set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1);
745 745
 			$overridden_cpage = true;
746 746
 		}
747 747
 
748
-		foreach($comments as $key => &$comment) {
748
+		foreach ($comments as $key => &$comment) {
749 749
 			$timber_comment = new $CommentClass($comment);
750 750
 			$timber_comment->reply_link = $this->TimberComment_reply_link($comment->comment_ID, $this->ID);
751 751
 			$timber_comments[$timber_comment->id] = $timber_comment;
@@ -753,22 +753,22 @@  discard block
 block discarded – undo
753 753
 
754 754
 		// Build a flattened (depth=1) comment tree
755 755
 		$comments_tree = array();
756
-		foreach( $timber_comments as $key => $comment ) {
757
-			if ( ! $comment->is_child() ) {
756
+		foreach ($timber_comments as $key => $comment) {
757
+			if ( !$comment->is_child() ) {
758 758
 				continue;
759 759
 			}
760 760
 
761 761
 			$tree_element = $comment;
762 762
 			do {
763 763
 				$tree_element = $timber_comments[$tree_element->comment_parent];
764
-			} while( $tree_element->is_child() );
764
+			} while ($tree_element->is_child());
765 765
 
766 766
 			$comments_tree[$tree_element->id][] = $comment->id;
767 767
 		}
768 768
 
769 769
 		// Add child comments to the relative "super parents"
770
-		foreach($comments_tree as $comment_parent => $comment_children) {
771
-			foreach($comment_children as $comment_child) {
770
+		foreach ($comments_tree as $comment_parent => $comment_children) {
771
+			foreach ($comment_children as $comment_child) {
772 772
 				$timber_comments[$comment_parent]->children[] = $timber_comments[$comment_child];
773 773
 				unset($timber_comments[$comment_child]);
774 774
 			}
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
 	 * @param string $TermClass
809 809
 	 * @return array
810 810
 	 */
811
-	function get_terms( $tax = '', $merge = true, $TermClass = '' ) {
811
+	function get_terms($tax = '', $merge = true, $TermClass = '') {
812 812
 
813 813
 		$TermClass = $TermClass ?: $this->TermClass;
814 814
 
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
 			$taxonomies = $tax;
820 820
 		}
821 821
 		if ( is_string($tax) ) {
822
-			if ( in_array($tax, array('all','any','')) ) {
822
+			if ( in_array($tax, array('all', 'any', '')) ) {
823 823
 				$taxonomies = get_object_taxonomies($this->post_type);
824 824
 			} else {
825 825
 				$taxonomies = array($tax);
@@ -828,8 +828,8 @@  discard block
 block discarded – undo
828 828
 
829 829
 		$term_class_objects = array();
830 830
 
831
-		foreach ( $taxonomies as $taxonomy ) {
832
-			if ( in_array($taxonomy, array('tag','tags')) ) {
831
+		foreach ($taxonomies as $taxonomy) {
832
+			if ( in_array($taxonomy, array('tag', 'tags')) ) {
833 833
 				$taxonomy = 'post_tag';
834 834
 			}
835 835
 			if ( $taxonomy == 'categories' ) {
@@ -866,11 +866,11 @@  discard block
 block discarded – undo
866 866
 	 * @param string $taxonomy
867 867
 	 * @return bool
868 868
 	 */
869
-	function has_term( $term_name_or_id, $taxonomy = 'all' ) {
869
+	function has_term($term_name_or_id, $taxonomy = 'all') {
870 870
 		if ( $taxonomy == 'all' || $taxonomy == 'any' ) {
871 871
 			$taxes = get_object_taxonomies($this->post_type, 'names');
872 872
 			$ret = false;
873
-			foreach ( $taxes as $tax ) {
873
+			foreach ($taxes as $tax) {
874 874
 				if ( has_term($term_name_or_id, $tax, $this->ID) ) {
875 875
 					$ret = true;
876 876
 					break;
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
 	 * @param string $field
886 886
 	 * @return TimberImage
887 887
 	 */
888
-	function get_image( $field ) {
888
+	function get_image($field) {
889 889
 		return new $this->ImageClass($this->$field);
890 890
 	}
891 891
 
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
 	 * @param int $page
936 936
 	 * @return string
937 937
 	 */
938
-	function get_content( $len = 0, $page = 0 ) {
938
+	function get_content($len = 0, $page = 0) {
939 939
 		if ( $len == 0 && $page == 0 && $this->_content ) {
940 940
 			return $this->_content;
941 941
 		}
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
 	 * @param string $field_name
993 993
 	 * @return mixed
994 994
 	 */
995
-	public function get_field( $field_name ) {
995
+	public function get_field($field_name) {
996 996
 		$value = apply_filters('timber_post_get_meta_field_pre', null, $this->ID, $field_name, $this);
997 997
 		if ( $value === null ) {
998 998
 			$value = get_post_meta($this->ID, $field_name);
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
 	/**
1011 1011
 	 * @param string $field_name
1012 1012
 	 */
1013
-	function import_field( $field_name ) {
1013
+	function import_field($field_name) {
1014 1014
 		$this->$field_name = $this->get_field($field_name);
1015 1015
 	}
1016 1016
 
@@ -1041,13 +1041,13 @@  discard block
 block discarded – undo
1041 1041
 	 * ```
1042 1042
 	 * @return string a space-seperated list of classes
1043 1043
 	 */
1044
-	public function post_class( $class='' ) {
1044
+	public function post_class($class = '') {
1045 1045
 		global $post;
1046 1046
 		$old_global_post = $post;
1047 1047
 		$post = $this;
1048 1048
 		$class_array = get_post_class($class, $this->ID);
1049 1049
 		$post = $old_global_post;
1050
-		if ( is_array($class_array) ){
1050
+		if ( is_array($class_array) ) {
1051 1051
 			return implode(' ', $class_array);
1052 1052
 		}
1053 1053
 		return $class_array;
@@ -1149,8 +1149,8 @@  discard block
 block discarded – undo
1149 1149
 	 * @param string|bool $childPostClass _optional_ a custom post class (ex: 'MyTimberPost') to return the objects as. By default (false) it will use TimberPost::$post_class value.
1150 1150
 	 * @return array
1151 1151
 	 */
1152
-	public function children( $post_type = 'any', $childPostClass = false ) {
1153
-		return $this->get_children( $post_type, $childPostClass );
1152
+	public function children($post_type = 'any', $childPostClass = false) {
1153
+		return $this->get_children($post_type, $childPostClass);
1154 1154
 	}
1155 1155
 
1156 1156
 	/**
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
 	 * ```
1175 1175
 	 * @return bool|array
1176 1176
 	 */
1177
-	public function comments( $count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment' ) {
1177
+	public function comments($count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment') {
1178 1178
 		return $this->get_comments($count, $order, $type, $status, $CommentClass);
1179 1179
 	}
1180 1180
 
@@ -1191,7 +1191,7 @@  discard block
 block discarded – undo
1191 1191
 	 * @param int $page
1192 1192
 	 * @return string
1193 1193
 	 */
1194
-	public function content( $page = 0 ) {
1194
+	public function content($page = 0) {
1195 1195
 		return $this->get_content(0, $page);
1196 1196
 	}
1197 1197
 
@@ -1220,7 +1220,7 @@  discard block
 block discarded – undo
1220 1220
 	 * @param string $date_format
1221 1221
 	 * @return string
1222 1222
 	 */
1223
-	public function date( $date_format = '' ) {
1223
+	public function date($date_format = '') {
1224 1224
 		return $this->get_date($date_format);
1225 1225
 	}
1226 1226
 
@@ -1242,9 +1242,9 @@  discard block
 block discarded – undo
1242 1242
 	 * @param string $time_format
1243 1243
 	 * @return string
1244 1244
 	 */
1245
-	public function time( $time_format = '' ) {
1245
+	public function time($time_format = '') {
1246 1246
 		$tf = $time_format ? $time_format : get_option('time_format');
1247
-	 	$the_time = (string)mysql2date($tf, $this->post_date);
1247
+	 	$the_time = (string) mysql2date($tf, $this->post_date);
1248 1248
 	 	return apply_filters('get_the_time', $the_time, $tf);
1249 1249
 	}
1250 1250
 
@@ -1280,7 +1280,7 @@  discard block
 block discarded – undo
1280 1280
 	 * @param string $field_name
1281 1281
 	 * @return mixed
1282 1282
 	 */
1283
-	public function meta( $field_name = null ) {
1283
+	public function meta($field_name = null) {
1284 1284
 		if ( $field_name === null ) {
1285 1285
 			//on the off-chance the field is actually named meta
1286 1286
 			$field_name = 'meta';
@@ -1291,7 +1291,7 @@  discard block
 block discarded – undo
1291 1291
 	/**
1292 1292
 	 * @return string
1293 1293
 	 */
1294
-	public function name(){
1294
+	public function name() {
1295 1295
 		return $this->title();
1296 1296
 	}
1297 1297
 
@@ -1299,7 +1299,7 @@  discard block
 block discarded – undo
1299 1299
 	 * @param string $date_format
1300 1300
 	 * @return string
1301 1301
 	 */
1302
-	public function modified_date( $date_format = '' ) {
1302
+	public function modified_date($date_format = '') {
1303 1303
 		return $this->get_modified_date($date_format);
1304 1304
 	}
1305 1305
 
@@ -1307,7 +1307,7 @@  discard block
 block discarded – undo
1307 1307
 	 * @param string $time_format
1308 1308
 	 * @return string
1309 1309
 	 */
1310
-	public function modified_time( $time_format = '' ) {
1310
+	public function modified_time($time_format = '') {
1311 1311
 		return $this->get_modified_time($time_format);
1312 1312
 	}
1313 1313
 
@@ -1316,7 +1316,7 @@  discard block
 block discarded – undo
1316 1316
 	 * @param bool $in_same_cat
1317 1317
 	 * @return mixed
1318 1318
 	 */
1319
-	public function next( $in_same_cat = false ) {
1319
+	public function next($in_same_cat = false) {
1320 1320
 		return $this->get_next($in_same_cat);
1321 1321
 	}
1322 1322
 
@@ -1374,7 +1374,7 @@  discard block
 block discarded – undo
1374 1374
 	 * @param bool $in_same_cat
1375 1375
 	 * @return mixed
1376 1376
 	 */
1377
-	public function prev( $in_same_cat = false ) {
1377
+	public function prev($in_same_cat = false) {
1378 1378
 		return $this->get_prev($in_same_cat);
1379 1379
 	}
1380 1380
 
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
 	 * @param bool $merge Should the resulting array be one big one (true)? Or should it be an array of sub-arrays for each taxonomy (false)?
1387 1387
 	 * @return array
1388 1388
 	 */
1389
-	public function terms( $tax = '', $merge = true ) {
1389
+	public function terms($tax = '', $merge = true) {
1390 1390
 		return $this->get_terms($tax, $merge);
1391 1391
 	}
1392 1392
 
Please login to merge, or discard this patch.
lib/timber-loader.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	function render($file, $data = null, $expires = false, $cache_mode = self::CACHE_USE_DEFAULT) {
43 43
 		// Different $expires if user is anonymous or logged in
44
-		if (is_array($expires)) {
45
-			if (is_user_logged_in() && isset($expires[1])) {
44
+		if ( is_array($expires) ) {
45
+			if ( is_user_logged_in() && isset($expires[1]) ) {
46 46
 				$expires = $expires[1];
47 47
 			} else {
48 48
 				$expires = $expires[0];
@@ -51,15 +51,15 @@  discard block
 block discarded – undo
51 51
 
52 52
 		$key = null;
53 53
 		$output = false;
54
-		if (false !== $expires) {
54
+		if ( false !== $expires ) {
55 55
 			ksort($data);
56 56
 			$key = md5($file . json_encode($data));
57 57
 			$output = $this->get_cache($key, self::CACHEGROUP, $cache_mode);
58 58
 		}
59 59
 
60
-		if (false === $output || null === $output) {
60
+		if ( false === $output || null === $output ) {
61 61
 			$twig = $this->get_twig();
62
-			if (strlen($file)) {
62
+			if ( strlen($file) ) {
63 63
 				$loader = $this->get_loader();
64 64
 				$result = $loader->getCacheKey($file);
65 65
 				do_action('timber_loader_render_file', $result);
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 			$output = $twig->render($file, $data);
70 70
 		}
71 71
 
72
-		if (false !== $output && false !== $expires && null !== $key) {
72
+		if ( false !== $output && false !== $expires && null !== $key ) {
73 73
 			$this->set_cache($key, $output, self::CACHEGROUP, $expires, $cache_mode);
74 74
 		}
75 75
 		$output = apply_filters('timber_output', $output);
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 	 * @return bool
82 82
 	 */
83 83
 	public function choose_template($filenames) {
84
-		if (is_array($filenames)) {
84
+		if ( is_array($filenames) ) {
85 85
 			/* its an array so we have to figure out which one the dev wants */
86 86
 			foreach ($filenames as $filename) {
87
-				if (self::template_exists($filename)) {
87
+				if ( self::template_exists($filename) ) {
88 88
 					return $filename;
89 89
 				}
90 90
 			}
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	protected function template_exists($file) {
101 101
 		foreach ($this->locations as $dir) {
102 102
 			$look_for = trailingslashit($dir) . $file;
103
-			if (file_exists($look_for)) {
103
+			if ( file_exists($look_for) ) {
104 104
 				return true;
105 105
 			}
106 106
 		}
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 		$theme_locs = array();
115 115
 		$child_loc = get_stylesheet_directory();
116 116
 		$parent_loc = get_template_directory();
117
-		if (DIRECTORY_SEPARATOR == '\\') {
117
+		if ( DIRECTORY_SEPARATOR == '\\' ) {
118 118
 			$child_loc = str_replace('/', '\\', $child_loc);
119 119
 			$parent_loc = str_replace('/', '\\', $parent_loc);
120 120
 		}
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 		foreach ($this->get_locations_theme_dir() as $dirname) {
123 123
 			$theme_locs[] = trailingslashit($child_loc) . trailingslashit($dirname);
124 124
 		}
125
-		if ($child_loc != $parent_loc) {
125
+		if ( $child_loc != $parent_loc ) {
126 126
 			$theme_locs[] = $parent_loc;
127 127
 			foreach ($this->get_locations_theme_dir() as $dirname) {
128 128
 				$theme_locs[] = trailingslashit($parent_loc) . trailingslashit($dirname);
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	 * @return string[] the names of directores, ie: array('templats', 'views');
139 139
 	 */
140 140
 	private function get_locations_theme_dir() {
141
-		if (is_string(Timber::$dirname)) {
141
+		if ( is_string(Timber::$dirname) ) {
142 142
 			return array(Timber::$dirname);
143 143
 		}
144 144
 		return Timber::$dirname;
@@ -149,13 +149,13 @@  discard block
 block discarded – undo
149 149
 	 */
150 150
 	function get_locations_user() {
151 151
 		$locs = array();
152
-		if (isset(Timber::$locations)) {
153
-			if (is_string(Timber::$locations)) {
152
+		if ( isset(Timber::$locations) ) {
153
+			if ( is_string(Timber::$locations) ) {
154 154
 				Timber::$locations = array(Timber::$locations);
155 155
 			}
156 156
 			foreach (Timber::$locations as $tloc) {
157 157
 				$tloc = realpath($tloc);
158
-				if (is_dir($tloc)) {
158
+				if ( is_dir($tloc) ) {
159 159
 					$locs[] = $tloc;
160 160
 				}
161 161
 			}
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
 	 */
170 170
 	function get_locations_caller($caller = false) {
171 171
 		$locs = array();
172
-		if ($caller && is_string($caller)) {
172
+		if ( $caller && is_string($caller) ) {
173 173
 			$caller = trailingslashit($caller);
174
-			if (is_dir($caller)) {
174
+			if ( is_dir($caller) ) {
175 175
 				$locs[] = $caller;
176 176
 			}
177 177
 			foreach ($this->get_locations_theme_dir() as $dirname) {
178 178
 				$caller_sub = $caller . trailingslashit($dirname);
179
-				if (is_dir($caller_sub)) {
179
+				if ( is_dir($caller_sub) ) {
180 180
 					$locs[] = $caller_sub;
181 181
 				}
182 182
 			}
@@ -210,14 +210,14 @@  discard block
 block discarded – undo
210 210
 		$paths = array();
211 211
 		foreach ($this->locations as $loc) {
212 212
 			$loc = realpath($loc);
213
-			if (is_dir($loc)) {
213
+			if ( is_dir($loc) ) {
214 214
 				$loc = realpath($loc);
215 215
 				$paths[] = $loc;
216 216
 			} else {
217 217
 				//error_log($loc.' is not a directory');
218 218
 			}
219 219
 		}
220
-		if (!ini_get('open_basedir')) {
220
+		if ( !ini_get('open_basedir') ) {
221 221
 			$paths[] = '/';
222 222
 		} else {
223 223
 			$paths[] = ABSPATH;
@@ -233,15 +233,15 @@  discard block
 block discarded – undo
233 233
 	function get_twig() {
234 234
 		$loader = $this->get_loader();
235 235
 		$params = array('debug' => WP_DEBUG, 'autoescape' => false);
236
-		if (isset(Timber::$autoescape)) {
236
+		if ( isset(Timber::$autoescape) ) {
237 237
 			$params['autoescape'] = Timber::$autoescape;
238 238
 		}
239
-		if (Timber::$cache === true) {
239
+		if ( Timber::$cache === true ) {
240 240
 			Timber::$twig_cache = true;
241 241
 		}
242
-		if (Timber::$twig_cache) {
243
-			$twig_cache_loc = apply_filters( 'timber/cache/location', TIMBER_LOC . '/cache/twig' );
244
-			if (!file_exists($twig_cache_loc)) {
242
+		if ( Timber::$twig_cache ) {
243
+			$twig_cache_loc = apply_filters('timber/cache/location', TIMBER_LOC . '/cache/twig');
244
+			if ( !file_exists($twig_cache_loc) ) {
245 245
 				mkdir($twig_cache_loc, 0777, true);
246 246
 			}
247 247
 			$params['cache'] = $twig_cache_loc;
@@ -258,26 +258,26 @@  discard block
 block discarded – undo
258 258
 		return $twig;
259 259
 	}
260 260
 
261
-	public function clear_cache_timber($cache_mode = self::CACHE_USE_DEFAULT){
261
+	public function clear_cache_timber($cache_mode = self::CACHE_USE_DEFAULT) {
262 262
 		//_transient_timberloader
263 263
 		$object_cache = false;
264
-		if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
264
+		if ( isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache']) ) {
265 265
 			$object_cache = true;
266 266
 		}
267 267
 		$cache_mode = $this->_get_cache_mode($cache_mode);
268
-		if (self::CACHE_TRANSIENT === $cache_mode) {
268
+		if ( self::CACHE_TRANSIENT === $cache_mode ) {
269 269
 			global $wpdb;
270 270
 			$query = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE '%s'", '_transient_timberloader_%');
271
-			$wpdb->query( $query );
271
+			$wpdb->query($query);
272 272
 			return true;
273
-		} else if (self::CACHE_SITE_TRANSIENT === $cache_mode) {
273
+		} else if ( self::CACHE_SITE_TRANSIENT === $cache_mode ) {
274 274
 			global $wpdb;
275 275
 			$query = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE '%s'", '_transient_timberloader_%');
276
-			$wpdb->query( $query );
276
+			$wpdb->query($query);
277 277
 			return true;
278
-		} else if (self::CACHE_OBJECT === $cache_mode && $object_cache) {
278
+		} else if ( self::CACHE_OBJECT === $cache_mode && $object_cache ) {
279 279
 			global $wp_object_cache;
280
-			if (isset($wp_object_cache->cache[self::CACHEGROUP])){
280
+			if ( isset($wp_object_cache->cache[self::CACHEGROUP]) ) {
281 281
 				unset($wp_object_cache->cache[self::CACHEGROUP]);
282 282
 				return true;
283 283
 			}
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 		$twig = $this->get_twig();
290 290
 		$twig->clearCacheFiles();
291 291
 		$cache = $twig->getCache();
292
-		if ($cache){
292
+		if ( $cache ) {
293 293
 			self::rrmdir($twig->getCache());
294 294
 			return true;
295 295
 		}
@@ -300,15 +300,15 @@  discard block
 block discarded – undo
300 300
 	 * @param string|false $dirPath
301 301
 	 */
302 302
 	public static function rrmdir($dirPath) {
303
-		if (! is_dir($dirPath)) {
303
+		if ( !is_dir($dirPath) ) {
304 304
 			throw new InvalidArgumentException("$dirPath must be a directory");
305 305
 		}
306
-		if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
306
+		if ( substr($dirPath, strlen($dirPath) - 1, 1) != '/' ) {
307 307
 			$dirPath .= '/';
308 308
 		}
309 309
 		$files = glob($dirPath . '*', GLOB_MARK);
310 310
 		foreach ($files as $file) {
311
-			if (is_dir($file)) {
311
+			if ( is_dir($file) ) {
312 312
 				self::rrmdir($file);
313 313
 			} else {
314 314
 				unlink($file);
@@ -323,9 +323,9 @@  discard block
 block discarded – undo
323 323
 	private function _get_cache_extension() {
324 324
 
325 325
 		$key_generator   = new \Timber\Cache\KeyGenerator();
326
-		$cache_provider  = new \Timber\Cache\WPObjectCacheAdapter( $this );
327
-		$cache_strategy  = new \Asm89\Twig\CacheExtension\CacheStrategy\GenerationalCacheStrategy( $cache_provider, $key_generator );
328
-		$cache_extension = new \Asm89\Twig\CacheExtension\Extension( $cache_strategy );
326
+		$cache_provider  = new \Timber\Cache\WPObjectCacheAdapter($this);
327
+		$cache_strategy  = new \Asm89\Twig\CacheExtension\CacheStrategy\GenerationalCacheStrategy($cache_provider, $key_generator);
328
+		$cache_extension = new \Asm89\Twig\CacheExtension\Extension($cache_strategy);
329 329
 
330 330
 		return $cache_extension;
331 331
 	}
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 	public function get_cache($key, $group = self::CACHEGROUP, $cache_mode = self::CACHE_USE_DEFAULT) {
340 340
 		$object_cache = false;
341 341
 
342
-		if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
342
+		if ( isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache']) ) {
343 343
 			$object_cache = true;
344 344
 		}
345 345
 
@@ -348,13 +348,13 @@  discard block
 block discarded – undo
348 348
 		$value = false;
349 349
 
350 350
 		$trans_key = substr($group . '_' . $key, 0, self::TRANS_KEY_LEN);
351
-		if (self::CACHE_TRANSIENT === $cache_mode)
351
+		if ( self::CACHE_TRANSIENT === $cache_mode )
352 352
 			$value = get_transient($trans_key);
353 353
 
354
-		elseif (self::CACHE_SITE_TRANSIENT === $cache_mode)
354
+		elseif ( self::CACHE_SITE_TRANSIENT === $cache_mode )
355 355
 			$value = get_site_transient($trans_key);
356 356
 
357
-		elseif (self::CACHE_OBJECT === $cache_mode && $object_cache)
357
+		elseif ( self::CACHE_OBJECT === $cache_mode && $object_cache )
358 358
 			$value = wp_cache_get($key, $group);
359 359
 
360 360
 		return $value;
@@ -371,23 +371,23 @@  discard block
 block discarded – undo
371 371
 	public function set_cache($key, $value, $group = self::CACHEGROUP, $expires = 0, $cache_mode = self::CACHE_USE_DEFAULT) {
372 372
 		$object_cache = false;
373 373
 
374
-		if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
374
+		if ( isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache']) ) {
375 375
 			$object_cache = true;
376 376
 		}
377 377
 
378
-		if ((int)$expires < 1)
378
+		if ( (int) $expires < 1 )
379 379
 			$expires = 0;
380 380
 
381 381
 		$cache_mode = self::_get_cache_mode($cache_mode);
382 382
 		$trans_key = substr($group . '_' . $key, 0, self::TRANS_KEY_LEN);
383 383
 
384
-		if (self::CACHE_TRANSIENT === $cache_mode)
384
+		if ( self::CACHE_TRANSIENT === $cache_mode )
385 385
 			set_transient($trans_key, $value, $expires);
386 386
 
387
-		elseif (self::CACHE_SITE_TRANSIENT === $cache_mode)
387
+		elseif ( self::CACHE_SITE_TRANSIENT === $cache_mode )
388 388
 			set_site_transient($trans_key, $value, $expires);
389 389
 
390
-		elseif (self::CACHE_OBJECT === $cache_mode && $object_cache)
390
+		elseif ( self::CACHE_OBJECT === $cache_mode && $object_cache )
391 391
 			wp_cache_set($key, $value, $group, $expires);
392 392
 
393 393
 		return $value;
@@ -398,12 +398,12 @@  discard block
 block discarded – undo
398 398
 	 * @return string
399 399
 	 */
400 400
 	private function _get_cache_mode($cache_mode) {
401
-		if (empty($cache_mode) || self::CACHE_USE_DEFAULT === $cache_mode) {
401
+		if ( empty($cache_mode) || self::CACHE_USE_DEFAULT === $cache_mode ) {
402 402
 			$cache_mode = $this->cache_mode;
403 403
 		}
404 404
 
405 405
 		// Fallback if self::$cache_mode did not get a valid value
406
-		if (!in_array($cache_mode, self::$cache_modes)) {
406
+		if ( !in_array($cache_mode, self::$cache_modes) ) {
407 407
 			$cache_mode = self::CACHE_OBJECT;
408 408
 		}
409 409
 
Please login to merge, or discard this patch.