Completed
Pull Request — master (#892)
by Jared
02:40
created
lib/integrations/wpcli-timber.php 3 patches
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
      *    wp timber clear_cache_twig
26 26
      *
27 27
      */
28
-    function clear_cache_twig(){
28
+    function clear_cache_twig() {
29 29
         $clear = TimberCommand::clear_cache_twig();
30
-        if ($clear){
30
+        if ($clear) {
31 31
             WP_CLI::success('Cleared contents of twig cache');
32 32
         } else {
33 33
             WP_CLI::warning('Failed to clear twig cache');
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     function clear_cache_timber() {
46 46
         $clear = TimberCommand::clear_cache_timber();
47 47
         $message = 'Failed to clear timber cache';
48
-        if ($clear){
48
+        if ($clear) {
49 49
             $message = "Cleared contents of Timber's Cache";
50 50
             WP_CLI::success($message);
51 51
         } else {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 if (!class_exists('WP_CLI_Command')) {
3
-	return;
3
+    return;
4 4
 }
5 5
 
6 6
 class Timber_WP_CLI_Command extends WP_CLI_Command {
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!class_exists('WP_CLI_Command')) {
2
+if ( !class_exists('WP_CLI_Command') ) {
3 3
 	return;
4 4
 }
5 5
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      *    wp timber clear_cache
14 14
      *
15 15
      */
16
-    public function clear_cache($mode = 'all') {
16
+    public function clear_cache( $mode = 'all' ) {
17 17
         TimberCommand::clear_cache($mode);
18 18
     }
19 19
 
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
      *    wp timber clear_cache_twig
26 26
      *
27 27
      */
28
-    function clear_cache_twig(){
28
+    function clear_cache_twig() {
29 29
         $clear = TimberCommand::clear_cache_twig();
30
-        if ($clear){
30
+        if ( $clear ) {
31 31
             WP_CLI::success('Cleared contents of twig cache');
32 32
         } else {
33 33
             WP_CLI::warning('Failed to clear twig cache');
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     function clear_cache_timber() {
46 46
         $clear = TimberCommand::clear_cache_timber();
47 47
         $message = 'Failed to clear timber cache';
48
-        if ($clear){
48
+        if ( $clear ) {
49 49
             $message = "Cleared contents of Timber's Cache";
50 50
             WP_CLI::success($message);
51 51
         } else {
Please login to merge, or discard this patch.
lib/timber-archives.php 3 patches
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@
 block discarded – undo
133 133
 		$show_year = $r['show_year'];
134 134
 		//will need to specify which year we're looking for
135 135
 		$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts "
136
-			. "FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) "
136
+			. "from $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) "
137 137
 			. "ORDER BY post_date $order $limit";
138 138
 		$key = md5($query);
139 139
 		$key = "wp_get_archives:$key:$last_changed";
Please login to merge, or discard this patch.
Indentation   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -32,284 +32,284 @@
 block discarded – undo
32 32
  */
33 33
 class TimberArchives extends TimberCore {
34 34
 
35
-	public $base = '';
36
-	/**
37
-	 * @api
38
-	 * @var array the items of the archives to iterate through and markup for your page
39
-	 */
40
-	public $items;
35
+    public $base = '';
36
+    /**
37
+     * @api
38
+     * @var array the items of the archives to iterate through and markup for your page
39
+     */
40
+    public $items;
41 41
 
42
-	/**
43
-	 * @api
44
-	 * @param $args array of arguments {
45
-	 *     @type bool show_year => false
46
-	 *     @type string
47
-	 *     @type string type => 'monthly-nested'
48
-	 *     @type int limit => -1
49
-	 *     @type bool show_post_count => false
50
-	 *     @type string order => 'DESC'
51
-	 *     @type string post_type => 'post'
52
-	 *     @type bool show_year => false
53
-	 *     @type bool nested => false
54
-	 * }
55
-	 * @param string $base any additional paths that need to be prepended to the URLs that are generated, for example: "tags"
56
-	 */
57
-	function __construct( $args = null, $base = '' ) {
58
-		$this->init($args, $base);
59
-	}
42
+    /**
43
+     * @api
44
+     * @param $args array of arguments {
45
+     *     @type bool show_year => false
46
+     *     @type string
47
+     *     @type string type => 'monthly-nested'
48
+     *     @type int limit => -1
49
+     *     @type bool show_post_count => false
50
+     *     @type string order => 'DESC'
51
+     *     @type string post_type => 'post'
52
+     *     @type bool show_year => false
53
+     *     @type bool nested => false
54
+     * }
55
+     * @param string $base any additional paths that need to be prepended to the URLs that are generated, for example: "tags"
56
+     */
57
+    function __construct( $args = null, $base = '' ) {
58
+        $this->init($args, $base);
59
+    }
60 60
 
61
-	/**
62
-	 * @internal
63
-	 * @param array|string $args
64
-	 * @param string $base
65
-	 */
66
-	function init( $args = null, $base = '' ) {
67
-		$this->base = $base;
68
-		$this->items = $this->get_items($args);
69
-	}
61
+    /**
62
+     * @internal
63
+     * @param array|string $args
64
+     * @param string $base
65
+     */
66
+    function init( $args = null, $base = '' ) {
67
+        $this->base = $base;
68
+        $this->items = $this->get_items($args);
69
+    }
70 70
 
71
-	/**
72
-	 * @internal
73
-	 * @param string $url
74
-	 * @param string $text
75
-	 * @return mixed
76
-	 */
77
-	protected function get_archives_link( $url, $text ) {
78
-		$ret = array();
79
-		$ret['text'] = $ret['title'] = $ret['name'] = wptexturize($text);
80
-		$ret['url'] = $ret['link'] = esc_url(TimberURLHelper::prepend_to_url($url, $this->base));
81
-		return $ret;
82
-	}
71
+    /**
72
+     * @internal
73
+     * @param string $url
74
+     * @param string $text
75
+     * @return mixed
76
+     */
77
+    protected function get_archives_link( $url, $text ) {
78
+        $ret = array();
79
+        $ret['text'] = $ret['title'] = $ret['name'] = wptexturize($text);
80
+        $ret['url'] = $ret['link'] = esc_url(TimberURLHelper::prepend_to_url($url, $this->base));
81
+        return $ret;
82
+    }
83 83
 
84
-	/**
85
-	 * @internal
86
-	 * @param array $args
87
-	 * @param string $last_changed
88
-	 * @param string $join
89
-	 * @param string $where
90
-	 * @param string $order
91
-	 * @param string $limit
92
-	 * @return array
93
-	 */
94
-	protected function get_items_yearly( $args, $last_changed, $join, $where, $order, $limit ) {
95
-		global $wpdb;
96
-		$output = array();
97
-		$query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM {$wpdb->posts} $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
98
-		$key = md5($query);
99
-		$key = "wp_get_archives:$key:$last_changed";
100
-		if (!$results = wp_cache_get($key, 'posts')) {
101
-			$results = $wpdb->get_results($query);
102
-			wp_cache_set($key, $results, 'posts');
103
-		}
104
-		if ($results) {
105
-			foreach ( (array)$results as $result ) {
106
-				$url = get_year_link( $result->year );
107
-				$text = sprintf('%d', $result->year);
108
-				$output[] = $this->get_archives_link($url, $text);
109
-			}
110
-		}
111
-		return $output;
112
-	}
84
+    /**
85
+     * @internal
86
+     * @param array $args
87
+     * @param string $last_changed
88
+     * @param string $join
89
+     * @param string $where
90
+     * @param string $order
91
+     * @param string $limit
92
+     * @return array
93
+     */
94
+    protected function get_items_yearly( $args, $last_changed, $join, $where, $order, $limit ) {
95
+        global $wpdb;
96
+        $output = array();
97
+        $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM {$wpdb->posts} $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
98
+        $key = md5($query);
99
+        $key = "wp_get_archives:$key:$last_changed";
100
+        if (!$results = wp_cache_get($key, 'posts')) {
101
+            $results = $wpdb->get_results($query);
102
+            wp_cache_set($key, $results, 'posts');
103
+        }
104
+        if ($results) {
105
+            foreach ( (array)$results as $result ) {
106
+                $url = get_year_link( $result->year );
107
+                $text = sprintf('%d', $result->year);
108
+                $output[] = $this->get_archives_link($url, $text);
109
+            }
110
+        }
111
+        return $output;
112
+    }
113 113
 
114
-	/**
115
-	 * @internal
116
-	 * @param array|string $args
117
-	 * @param string $last_changed
118
-	 * @param string $join
119
-	 * @param string $where
120
-	 * @param string $order
121
-	 * @param int $limit
122
-	 * @param bool $nested
123
-	 * @return array
124
-	 */
125
-	protected function get_items_monthly( $args, $last_changed, $join, $where, $order, $limit = 1000, $nested = true ) {
126
-		global $wpdb, $wp_locale;
127
-		$output = array();
128
-		$defaults = array(
129
-			'show_year' => false,
130
-		);
131
-		$r = wp_parse_args($args, $defaults);
114
+    /**
115
+     * @internal
116
+     * @param array|string $args
117
+     * @param string $last_changed
118
+     * @param string $join
119
+     * @param string $where
120
+     * @param string $order
121
+     * @param int $limit
122
+     * @param bool $nested
123
+     * @return array
124
+     */
125
+    protected function get_items_monthly( $args, $last_changed, $join, $where, $order, $limit = 1000, $nested = true ) {
126
+        global $wpdb, $wp_locale;
127
+        $output = array();
128
+        $defaults = array(
129
+            'show_year' => false,
130
+        );
131
+        $r = wp_parse_args($args, $defaults);
132 132
 
133
-		$show_year = $r['show_year'];
134
-		//will need to specify which year we're looking for
135
-		$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts "
136
-			. "FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) "
137
-			. "ORDER BY post_date $order $limit";
138
-		$key = md5($query);
139
-		$key = "wp_get_archives:$key:$last_changed";
140
-		if (!$results = wp_cache_get($key, 'posts')) {
141
-			$results = $wpdb->get_results($query);
142
-			wp_cache_set($key, $results, 'posts');
143
-		}
144
-		if ($results) {
145
-			foreach ((array)$results as $result) {
146
-				$url = get_month_link($result->year, $result->month);
147
-				if ($show_year && !$nested) {
148
-					$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year);
149
-				} else {
150
-					$text = sprintf(__('%1$s'), $wp_locale->get_month($result->month));
151
-				}
152
-				if ($nested) {
153
-					$output[$result->year][] = $this->get_archives_link($url, $text);
154
-				} else {
155
-					$output[] = $this->get_archives_link($url, $text);
156
-				}
157
-			}
158
-		}
159
-		if ($nested) {
160
-			$out2 = array();
161
-			foreach ($output as $year => $months) {
162
-				$out2[] = array('name' => $year, 'children' => $months);
163
-			}
164
-			return $out2;
165
-		}
166
-		return $output;
167
-	}
133
+        $show_year = $r['show_year'];
134
+        //will need to specify which year we're looking for
135
+        $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts "
136
+            . "FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) "
137
+            . "ORDER BY post_date $order $limit";
138
+        $key = md5($query);
139
+        $key = "wp_get_archives:$key:$last_changed";
140
+        if (!$results = wp_cache_get($key, 'posts')) {
141
+            $results = $wpdb->get_results($query);
142
+            wp_cache_set($key, $results, 'posts');
143
+        }
144
+        if ($results) {
145
+            foreach ((array)$results as $result) {
146
+                $url = get_month_link($result->year, $result->month);
147
+                if ($show_year && !$nested) {
148
+                    $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year);
149
+                } else {
150
+                    $text = sprintf(__('%1$s'), $wp_locale->get_month($result->month));
151
+                }
152
+                if ($nested) {
153
+                    $output[$result->year][] = $this->get_archives_link($url, $text);
154
+                } else {
155
+                    $output[] = $this->get_archives_link($url, $text);
156
+                }
157
+            }
158
+        }
159
+        if ($nested) {
160
+            $out2 = array();
161
+            foreach ($output as $year => $months) {
162
+                $out2[] = array('name' => $year, 'children' => $months);
163
+            }
164
+            return $out2;
165
+        }
166
+        return $output;
167
+    }
168 168
 
169
-	/**
170
-	 * @api
171
-	 * @param array|string $args
172
-	 * @return array|string
173
-	 */
174
-	function get_items( $args = null ) {
175
-		global $wpdb;
169
+    /**
170
+     * @api
171
+     * @param array|string $args
172
+     * @return array|string
173
+     */
174
+    function get_items( $args = null ) {
175
+        global $wpdb;
176 176
 
177
-		$defaults = array(
178
-			'type' => 'monthly-nested',
179
-			'limit' => '',
180
-			'show_post_count' => false,
181
-			'order' => 'DESC',
182
-			'post_type' => 'post',
183
-			'show_year' => false,
184
-			'nested' => false
185
-		);
177
+        $defaults = array(
178
+            'type' => 'monthly-nested',
179
+            'limit' => '',
180
+            'show_post_count' => false,
181
+            'order' => 'DESC',
182
+            'post_type' => 'post',
183
+            'show_year' => false,
184
+            'nested' => false
185
+        );
186 186
 
187
-		$args = wp_parse_args($args, $defaults);
188
-		$post_type = $args['post_type'];
189
-		$order = $args['order'];
190
-		$nested = $args['nested'];
191
-		$type = $args['type'];
192
-		$limit = '';
193
-		if ( $type == 'yearlymonthly' || $type == 'yearmonth' ) {
194
-			$type = 'monthly-nested';
195
-		}
196
-		if ( $type == 'monthly-nested' ) {
197
-			$nested = true;
198
-		}
187
+        $args = wp_parse_args($args, $defaults);
188
+        $post_type = $args['post_type'];
189
+        $order = $args['order'];
190
+        $nested = $args['nested'];
191
+        $type = $args['type'];
192
+        $limit = '';
193
+        if ( $type == 'yearlymonthly' || $type == 'yearmonth' ) {
194
+            $type = 'monthly-nested';
195
+        }
196
+        if ( $type == 'monthly-nested' ) {
197
+            $nested = true;
198
+        }
199 199
 
200
-		if ( !empty($args['limit']) ) {
201
-			$limit = absint($limit);
202
-			$limit = ' LIMIT ' . $limit;
203
-		}
200
+        if ( !empty($args['limit']) ) {
201
+            $limit = absint($limit);
202
+            $limit = ' LIMIT ' . $limit;
203
+        }
204 204
 
205
-		$order = strtoupper($order);
206
-		if ( $order !== 'ASC' ) {
207
-			$order = 'DESC';
208
-		}
205
+        $order = strtoupper($order);
206
+        if ( $order !== 'ASC' ) {
207
+            $order = 'DESC';
208
+        }
209 209
 
210
-		// this is what will separate dates on weekly archive links
211
-		$archive_week_separator = '&#8211;';
210
+        // this is what will separate dates on weekly archive links
211
+        $archive_week_separator = '&#8211;';
212 212
 
213
-		// over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
214
-		$archive_date_format_over_ride = 0;
213
+        // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
214
+        $archive_date_format_over_ride = 0;
215 215
 
216
-		// options for daily archive (only if you over-ride the general date format)
217
-		$archive_day_date_format = 'Y/m/d';
216
+        // options for daily archive (only if you over-ride the general date format)
217
+        $archive_day_date_format = 'Y/m/d';
218 218
 
219
-		// options for weekly archive (only if you over-ride the general date format)
220
-		$archive_week_start_date_format = 'Y/m/d';
221
-		$archive_week_end_date_format = 'Y/m/d';
219
+        // options for weekly archive (only if you over-ride the general date format)
220
+        $archive_week_start_date_format = 'Y/m/d';
221
+        $archive_week_end_date_format = 'Y/m/d';
222 222
 
223
-		if (!$archive_date_format_over_ride) {
224
-			$archive_day_date_format = get_option('date_format');
225
-			$archive_week_start_date_format = get_option('date_format');
226
-			$archive_week_end_date_format = get_option('date_format');
227
-		}
223
+        if (!$archive_date_format_over_ride) {
224
+            $archive_day_date_format = get_option('date_format');
225
+            $archive_week_start_date_format = get_option('date_format');
226
+            $archive_week_end_date_format = get_option('date_format');
227
+        }
228 228
 
229
-		$where = $wpdb->prepare('WHERE post_type = "%s" AND post_status = "publish"', $post_type);
230
-		$where = apply_filters('getarchives_where', $where, $args);
231
-		$join = apply_filters('getarchives_join', '', $args);
229
+        $where = $wpdb->prepare('WHERE post_type = "%s" AND post_status = "publish"', $post_type);
230
+        $where = apply_filters('getarchives_where', $where, $args);
231
+        $join = apply_filters('getarchives_join', '', $args);
232 232
 
233
-		$output = array();
234
-		$last_changed = wp_cache_get('last_changed', 'posts');
235
-		if (!$last_changed) {
236
-			$last_changed = microtime();
237
-			wp_cache_set('last_changed', $last_changed, 'posts');
238
-		}
239
-		if ( 'monthly' == $type ) {
240
-			$output = $this->get_items_monthly($args, $last_changed, $join, $where, $order, $limit, $nested);
241
-		} elseif ( 'yearly' == $type ) {
242
-			$output = $this->get_items_yearly($args, $last_changed, $join, $where, $order, $limit);
243
-		} elseif ( 'monthly-nested' == $type ) {
244
-			$output = $this->get_items_monthly($args, $last_changed, $join, $where, $order, $limit);
245
-		} elseif ( 'daily' == $type ) {
246
-			$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
247
-			$key = md5($query);
248
-			$key = "wp_get_archives:$key:$last_changed";
249
-			if (!$results = wp_cache_get($key, 'posts')) {
250
-				$results = $wpdb->get_results($query);
251
-				$cache = array();
252
-				$cache[$key] = $results;
253
-				wp_cache_set($key, $results, 'posts');
254
-			}
255
-			if ( $results ) {
256
-				foreach ( (array)$results as $result ) {
257
-					$url = get_day_link($result->year, $result->month, $result->dayofmonth);
258
-					$date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth);
259
-					$text = mysql2date($archive_day_date_format, $date);
260
-					$output[] = $this->get_archives_link($url, $text);
261
-				}
262
-			}
263
-		} elseif ( 'weekly' == $type ) {
264
-			$week = _wp_mysql_week('`post_date`');
265
-			$query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, "
266
-				. "count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
267
-			$key = md5($query);
268
-			$key = "wp_get_archives:$key:$last_changed";
269
-			if (!$results = wp_cache_get($key, 'posts')) {
270
-				$results = $wpdb->get_results($query);
271
-				wp_cache_set($key, $results, 'posts');
272
-			}
273
-			$arc_w_last = '';
274
-			if ( $results ) {
275
-				foreach ( (array)$results as $result ) {
276
-					if ( $result->week != $arc_w_last ) {
277
-						$arc_year = $result->yr;
278
-						$arc_w_last = $result->week;
279
-						$arc_week = get_weekstartend($result->yyyymmdd, get_option('start_of_week'));
280
-						$arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
281
-						$arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
282
-						$url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&amp;', '=', $result->week);
283
-						$text = $arc_week_start . $archive_week_separator . $arc_week_end;
284
-						$output[] = $this->get_archives_link($url, $text);
285
-					}
286
-				}
287
-			}
288
-		} elseif ( 'postbypost' == $type || 'alpha' == $type ) {
289
-			$orderby = 'alpha' == $type ? 'post_title ASC ' : 'post_date DESC ';
290
-			$query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
291
-			$key = md5($query);
292
-			$key = "wp_get_archives:$key:$last_changed";
293
-			if ( !$results = wp_cache_get($key, 'posts') ) {
294
-				$results = $wpdb->get_results($query);
295
-				wp_cache_set($key, $results, 'posts');
296
-			}
297
-			if ( $results ) {
298
-				foreach ( (array)$results as $result ) {
299
-					if ($result->post_date != '0000-00-00 00:00:00') {
300
-						$url = get_permalink($result);
301
-						if ($result->post_title) {
302
-							/** This filter is documented in wp-includes/post-template.php */
303
-							$text = strip_tags(apply_filters('the_title', $result->post_title, $result->ID));
304
-						} else {
305
-							$text = $result->ID;
306
-						}
307
-						$output[] = $this->get_archives_link($url, $text);
308
-					}
309
-				}
310
-			}
311
-		}
312
-		return $output;
313
-	}
233
+        $output = array();
234
+        $last_changed = wp_cache_get('last_changed', 'posts');
235
+        if (!$last_changed) {
236
+            $last_changed = microtime();
237
+            wp_cache_set('last_changed', $last_changed, 'posts');
238
+        }
239
+        if ( 'monthly' == $type ) {
240
+            $output = $this->get_items_monthly($args, $last_changed, $join, $where, $order, $limit, $nested);
241
+        } elseif ( 'yearly' == $type ) {
242
+            $output = $this->get_items_yearly($args, $last_changed, $join, $where, $order, $limit);
243
+        } elseif ( 'monthly-nested' == $type ) {
244
+            $output = $this->get_items_monthly($args, $last_changed, $join, $where, $order, $limit);
245
+        } elseif ( 'daily' == $type ) {
246
+            $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
247
+            $key = md5($query);
248
+            $key = "wp_get_archives:$key:$last_changed";
249
+            if (!$results = wp_cache_get($key, 'posts')) {
250
+                $results = $wpdb->get_results($query);
251
+                $cache = array();
252
+                $cache[$key] = $results;
253
+                wp_cache_set($key, $results, 'posts');
254
+            }
255
+            if ( $results ) {
256
+                foreach ( (array)$results as $result ) {
257
+                    $url = get_day_link($result->year, $result->month, $result->dayofmonth);
258
+                    $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth);
259
+                    $text = mysql2date($archive_day_date_format, $date);
260
+                    $output[] = $this->get_archives_link($url, $text);
261
+                }
262
+            }
263
+        } elseif ( 'weekly' == $type ) {
264
+            $week = _wp_mysql_week('`post_date`');
265
+            $query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, "
266
+                . "count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
267
+            $key = md5($query);
268
+            $key = "wp_get_archives:$key:$last_changed";
269
+            if (!$results = wp_cache_get($key, 'posts')) {
270
+                $results = $wpdb->get_results($query);
271
+                wp_cache_set($key, $results, 'posts');
272
+            }
273
+            $arc_w_last = '';
274
+            if ( $results ) {
275
+                foreach ( (array)$results as $result ) {
276
+                    if ( $result->week != $arc_w_last ) {
277
+                        $arc_year = $result->yr;
278
+                        $arc_w_last = $result->week;
279
+                        $arc_week = get_weekstartend($result->yyyymmdd, get_option('start_of_week'));
280
+                        $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
281
+                        $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
282
+                        $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&amp;', '=', $result->week);
283
+                        $text = $arc_week_start . $archive_week_separator . $arc_week_end;
284
+                        $output[] = $this->get_archives_link($url, $text);
285
+                    }
286
+                }
287
+            }
288
+        } elseif ( 'postbypost' == $type || 'alpha' == $type ) {
289
+            $orderby = 'alpha' == $type ? 'post_title ASC ' : 'post_date DESC ';
290
+            $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
291
+            $key = md5($query);
292
+            $key = "wp_get_archives:$key:$last_changed";
293
+            if ( !$results = wp_cache_get($key, 'posts') ) {
294
+                $results = $wpdb->get_results($query);
295
+                wp_cache_set($key, $results, 'posts');
296
+            }
297
+            if ( $results ) {
298
+                foreach ( (array)$results as $result ) {
299
+                    if ($result->post_date != '0000-00-00 00:00:00') {
300
+                        $url = get_permalink($result);
301
+                        if ($result->post_title) {
302
+                            /** This filter is documented in wp-includes/post-template.php */
303
+                            $text = strip_tags(apply_filters('the_title', $result->post_title, $result->ID));
304
+                        } else {
305
+                            $text = $result->ID;
306
+                        }
307
+                        $output[] = $this->get_archives_link($url, $text);
308
+                    }
309
+                }
310
+            }
311
+        }
312
+        return $output;
313
+    }
314 314
 
315 315
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
 		$query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM {$wpdb->posts} $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
98 98
 		$key = md5($query);
99 99
 		$key = "wp_get_archives:$key:$last_changed";
100
-		if (!$results = wp_cache_get($key, 'posts')) {
100
+		if ( !$results = wp_cache_get($key, 'posts') ) {
101 101
 			$results = $wpdb->get_results($query);
102 102
 			wp_cache_set($key, $results, 'posts');
103 103
 		}
104
-		if ($results) {
105
-			foreach ( (array)$results as $result ) {
106
-				$url = get_year_link( $result->year );
104
+		if ( $results ) {
105
+			foreach ( (array) $results as $result ) {
106
+				$url = get_year_link($result->year);
107 107
 				$text = sprintf('%d', $result->year);
108 108
 				$output[] = $this->get_archives_link($url, $text);
109 109
 			}
@@ -137,28 +137,28 @@  discard block
 block discarded – undo
137 137
 			. "ORDER BY post_date $order $limit";
138 138
 		$key = md5($query);
139 139
 		$key = "wp_get_archives:$key:$last_changed";
140
-		if (!$results = wp_cache_get($key, 'posts')) {
140
+		if ( !$results = wp_cache_get($key, 'posts') ) {
141 141
 			$results = $wpdb->get_results($query);
142 142
 			wp_cache_set($key, $results, 'posts');
143 143
 		}
144
-		if ($results) {
145
-			foreach ((array)$results as $result) {
144
+		if ( $results ) {
145
+			foreach ( (array) $results as $result ) {
146 146
 				$url = get_month_link($result->year, $result->month);
147
-				if ($show_year && !$nested) {
147
+				if ( $show_year && !$nested ) {
148 148
 					$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year);
149 149
 				} else {
150 150
 					$text = sprintf(__('%1$s'), $wp_locale->get_month($result->month));
151 151
 				}
152
-				if ($nested) {
152
+				if ( $nested ) {
153 153
 					$output[$result->year][] = $this->get_archives_link($url, $text);
154 154
 				} else {
155 155
 					$output[] = $this->get_archives_link($url, $text);
156 156
 				}
157 157
 			}
158 158
 		}
159
-		if ($nested) {
159
+		if ( $nested ) {
160 160
 			$out2 = array();
161
-			foreach ($output as $year => $months) {
161
+			foreach ( $output as $year => $months ) {
162 162
 				$out2[] = array('name' => $year, 'children' => $months);
163 163
 			}
164 164
 			return $out2;
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 		$archive_week_start_date_format = 'Y/m/d';
221 221
 		$archive_week_end_date_format = 'Y/m/d';
222 222
 
223
-		if (!$archive_date_format_over_ride) {
223
+		if ( !$archive_date_format_over_ride ) {
224 224
 			$archive_day_date_format = get_option('date_format');
225 225
 			$archive_week_start_date_format = get_option('date_format');
226 226
 			$archive_week_end_date_format = get_option('date_format');
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 
233 233
 		$output = array();
234 234
 		$last_changed = wp_cache_get('last_changed', 'posts');
235
-		if (!$last_changed) {
235
+		if ( !$last_changed ) {
236 236
 			$last_changed = microtime();
237 237
 			wp_cache_set('last_changed', $last_changed, 'posts');
238 238
 		}
@@ -246,14 +246,14 @@  discard block
 block discarded – undo
246 246
 			$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
247 247
 			$key = md5($query);
248 248
 			$key = "wp_get_archives:$key:$last_changed";
249
-			if (!$results = wp_cache_get($key, 'posts')) {
249
+			if ( !$results = wp_cache_get($key, 'posts') ) {
250 250
 				$results = $wpdb->get_results($query);
251 251
 				$cache = array();
252 252
 				$cache[$key] = $results;
253 253
 				wp_cache_set($key, $results, 'posts');
254 254
 			}
255 255
 			if ( $results ) {
256
-				foreach ( (array)$results as $result ) {
256
+				foreach ( (array) $results as $result ) {
257 257
 					$url = get_day_link($result->year, $result->month, $result->dayofmonth);
258 258
 					$date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth);
259 259
 					$text = mysql2date($archive_day_date_format, $date);
@@ -266,13 +266,13 @@  discard block
 block discarded – undo
266 266
 				. "count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
267 267
 			$key = md5($query);
268 268
 			$key = "wp_get_archives:$key:$last_changed";
269
-			if (!$results = wp_cache_get($key, 'posts')) {
269
+			if ( !$results = wp_cache_get($key, 'posts') ) {
270 270
 				$results = $wpdb->get_results($query);
271 271
 				wp_cache_set($key, $results, 'posts');
272 272
 			}
273 273
 			$arc_w_last = '';
274 274
 			if ( $results ) {
275
-				foreach ( (array)$results as $result ) {
275
+				foreach ( (array) $results as $result ) {
276 276
 					if ( $result->week != $arc_w_last ) {
277 277
 						$arc_year = $result->yr;
278 278
 						$arc_w_last = $result->week;
@@ -295,10 +295,10 @@  discard block
 block discarded – undo
295 295
 				wp_cache_set($key, $results, 'posts');
296 296
 			}
297 297
 			if ( $results ) {
298
-				foreach ( (array)$results as $result ) {
299
-					if ($result->post_date != '0000-00-00 00:00:00') {
298
+				foreach ( (array) $results as $result ) {
299
+					if ( $result->post_date != '0000-00-00 00:00:00' ) {
300 300
 						$url = get_permalink($result);
301
-						if ($result->post_title) {
301
+						if ( $result->post_title ) {
302 302
 							/** This filter is documented in wp-includes/post-template.php */
303 303
 							$text = strip_tags(apply_filters('the_title', $result->post_title, $result->ID));
304 304
 						} else {
Please login to merge, or discard this patch.
lib/timber-core.php 3 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
             foreach ( $info as $key => $value ) {
64 64
                 if ( !empty( $key ) && $force ) {
65 65
                     $this->$key = $value;
66
-                } else if ( !empty( $key ) && !method_exists($this, $key) ){
66
+                } else if ( !empty( $key ) && !method_exists($this, $key) ) {
67 67
                     $this->$key = $value;
68 68
                 }
69 69
             }
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,9 +32,9 @@
 block discarded – undo
32 32
      * @return mixed
33 33
      */
34 34
     function __get( $field ) {
35
-    	if ( property_exists($this, $field) ) {
36
-    		return $this->$field;
37
-    	}
35
+        if ( property_exists($this, $field) ) {
36
+            return $this->$field;
37
+        }
38 38
         if ( method_exists($this, 'meta') && $meta_value = $this->meta( $field ) ) {
39 39
             return $this->$field = $meta_value;
40 40
         }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      * @return boolean
13 13
      */
14 14
     function __isset( $field ) {
15
-        if ( isset( $this->$field ) ) {
15
+        if ( isset($this->$field) ) {
16 16
             return $this->$field;
17 17
         }
18 18
         return false;
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      * @return mixed
24 24
      */
25 25
     function __call( $field, $args ) {
26
-        return $this->__get( $field );
26
+        return $this->__get($field);
27 27
     }
28 28
 
29 29
     /**
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
     	if ( property_exists($this, $field) ) {
36 36
     		return $this->$field;
37 37
     	}
38
-        if ( method_exists($this, 'meta') && $meta_value = $this->meta( $field ) ) {
38
+        if ( method_exists($this, 'meta') && $meta_value = $this->meta($field) ) {
39 39
             return $this->$field = $meta_value;
40 40
         }
41 41
         if ( method_exists($this, $field) ) {
@@ -56,14 +56,14 @@  discard block
 block discarded – undo
56 56
      * @param array|object $info an object or array you want to grab data from to attach to the Timber object
57 57
      */
58 58
     function import( $info, $force = false ) {
59
-        if ( is_object( $info ) ) {
60
-            $info = get_object_vars( $info );
59
+        if ( is_object($info) ) {
60
+            $info = get_object_vars($info);
61 61
         }
62
-        if ( is_array( $info ) ) {
62
+        if ( is_array($info) ) {
63 63
             foreach ( $info as $key => $value ) {
64
-                if ( !empty( $key ) && $force ) {
64
+                if ( !empty($key) && $force ) {
65 65
                     $this->$key = $value;
66
-                } else if ( !empty( $key ) && !method_exists($this, $key) ){
66
+                } else if ( !empty($key) && !method_exists($this, $key) ) {
67 67
                     $this->$key = $value;
68 68
                 }
69 69
             }
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      * @param mixed   $value
78 78
      */
79 79
     function update( $key, $value ) {
80
-        update_metadata( $this->object_type, $this->ID, $key, $value );
80
+        update_metadata($this->object_type, $this->ID, $key, $value);
81 81
     }
82 82
 
83 83
     /**
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
      * @return bool
95 95
      */
96 96
     function can_edit() {
97
-        if ( !function_exists( 'current_user_can' ) ) {
97
+        if ( !function_exists('current_user_can') ) {
98 98
             return false;
99 99
         }
100
-        if ( current_user_can( 'edit_post', $this->ID ) ) {
100
+        if ( current_user_can('edit_post', $this->ID) ) {
101 101
             return true;
102 102
         }
103 103
         return false;
Please login to merge, or discard this patch.
lib/timber-integrations.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,16 +7,16 @@
 block discarded – undo
7 7
 class TimberIntegrations {
8 8
     public static function init() {
9 9
 
10
-        add_action( 'init', array( __CLASS__, 'maybe_init_acftimber' ) );
10
+        add_action('init', array(__CLASS__, 'maybe_init_acftimber'));
11 11
 
12
-        if ( class_exists( 'WP_CLI_Command' ) ) {
13
-            WP_CLI::add_command( 'timber', 'Timber_WP_CLI_Command' );
12
+        if ( class_exists('WP_CLI_Command') ) {
13
+            WP_CLI::add_command('timber', 'Timber_WP_CLI_Command');
14 14
         }
15 15
     }
16 16
 
17 17
     public static function maybe_init_acftimber() {
18 18
 
19
-        if ( class_exists( 'ACF' ) ) {
19
+        if ( class_exists('ACF') ) {
20 20
             new ACFTimber();
21 21
         }
22 22
 
Please login to merge, or discard this patch.
lib/timber-loader.php 3 patches
Braces   +20 added lines, -21 removed lines patch added patch discarded remove patch
@@ -258,7 +258,7 @@  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 264
 		if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 			return true;
278 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
 		}
@@ -348,14 +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)
352
-			$value = get_transient($trans_key);
353
-
354
-		elseif (self::CACHE_SITE_TRANSIENT === $cache_mode)
355
-			$value = get_site_transient($trans_key);
356
-
357
-		elseif (self::CACHE_OBJECT === $cache_mode && $object_cache)
358
-			$value = wp_cache_get($key, $group);
351
+		if (self::CACHE_TRANSIENT === $cache_mode) {
352
+					$value = get_transient($trans_key);
353
+		} elseif (self::CACHE_SITE_TRANSIENT === $cache_mode) {
354
+					$value = get_site_transient($trans_key);
355
+		} elseif (self::CACHE_OBJECT === $cache_mode && $object_cache) {
356
+					$value = wp_cache_get($key, $group);
357
+		}
359 358
 
360 359
 		return $value;
361 360
 	}
@@ -375,20 +374,20 @@  discard block
 block discarded – undo
375 374
 			$object_cache = true;
376 375
 		}
377 376
 
378
-		if ((int)$expires < 1)
379
-			$expires = 0;
377
+		if ((int)$expires < 1) {
378
+					$expires = 0;
379
+		}
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)
385
-			set_transient($trans_key, $value, $expires);
386
-
387
-		elseif (self::CACHE_SITE_TRANSIENT === $cache_mode)
388
-			set_site_transient($trans_key, $value, $expires);
389
-
390
-		elseif (self::CACHE_OBJECT === $cache_mode && $object_cache)
391
-			wp_cache_set($key, $value, $group, $expires);
384
+		if (self::CACHE_TRANSIENT === $cache_mode) {
385
+					set_transient($trans_key, $value, $expires);
386
+		} elseif (self::CACHE_SITE_TRANSIENT === $cache_mode) {
387
+					set_site_transient($trans_key, $value, $expires);
388
+		} elseif (self::CACHE_OBJECT === $cache_mode && $object_cache) {
389
+					wp_cache_set($key, $value, $group, $expires);
390
+		}
392 391
 
393 392
 		return $value;
394 393
 	}
Please login to merge, or discard this patch.
Indentation   +407 added lines, -407 removed lines patch added patch discarded remove patch
@@ -2,412 +2,412 @@
 block discarded – undo
2 2
 
3 3
 class TimberLoader {
4 4
 
5
-	const CACHEGROUP = 'timberloader';
6
-
7
-	const TRANS_KEY_LEN = 50;
8
-
9
-	const CACHE_NONE = 'none';
10
-	const CACHE_OBJECT = 'cache';
11
-	const CACHE_TRANSIENT = 'transient';
12
-	const CACHE_SITE_TRANSIENT = 'site-transient';
13
-	const CACHE_USE_DEFAULT = 'default';
14
-
15
-	public static $cache_modes = array(
16
-		self::CACHE_NONE,
17
-		self::CACHE_OBJECT,
18
-		self::CACHE_TRANSIENT,
19
-		self::CACHE_SITE_TRANSIENT
20
-	);
21
-
22
-	protected $cache_mode = self::CACHE_TRANSIENT;
23
-
24
-	public $locations;
25
-
26
-	/**
27
-	 * @param bool|string   $caller the calling directory or false
28
-	 */
29
-	function __construct($caller = false) {
30
-		$this->locations = $this->get_locations($caller);
31
-		$this->cache_mode = apply_filters('timber_cache_mode', $this->cache_mode);
32
-		$this->cache_mode = apply_filters('timber/cache/mode', $this->cache_mode);
33
-	}
34
-
35
-	/**
36
-	 * @param string        $file
37
-	 * @param array         $data
38
-	 * @param bool          $expires
39
-	 * @param string        $cache_mode
40
-	 * @return bool|string
41
-	 */
42
-	function render($file, $data = null, $expires = false, $cache_mode = self::CACHE_USE_DEFAULT) {
43
-		// Different $expires if user is anonymous or logged in
44
-		if (is_array($expires)) {
45
-			if (is_user_logged_in() && isset($expires[1])) {
46
-				$expires = $expires[1];
47
-			} else {
48
-				$expires = $expires[0];
49
-			}
50
-		}
51
-
52
-		$key = null;
53
-		$output = false;
54
-		if (false !== $expires) {
55
-			ksort($data);
56
-			$key = md5($file . json_encode($data));
57
-			$output = $this->get_cache($key, self::CACHEGROUP, $cache_mode);
58
-		}
59
-
60
-		if (false === $output || null === $output) {
61
-			$twig = $this->get_twig();
62
-			if (strlen($file)) {
63
-				$loader = $this->get_loader();
64
-				$result = $loader->getCacheKey($file);
65
-				do_action('timber_loader_render_file', $result);
66
-			}
67
-			$data = apply_filters('timber_loader_render_data', $data);
68
-			$data = apply_filters('timber/loader/render_data', $data);
69
-			$output = $twig->render($file, $data);
70
-		}
71
-
72
-		if (false !== $output && false !== $expires && null !== $key) {
73
-			$this->set_cache($key, $output, self::CACHEGROUP, $expires, $cache_mode);
74
-		}
75
-		$output = apply_filters('timber_output', $output);
76
-		return apply_filters('timber/output', $output);
77
-	}
78
-
79
-	/**
80
-	 * @param array $filenames
81
-	 * @return bool
82
-	 */
83
-	public function choose_template($filenames) {
84
-		if (is_array($filenames)) {
85
-			/* its an array so we have to figure out which one the dev wants */
86
-			foreach ($filenames as $filename) {
87
-				if (self::template_exists($filename)) {
88
-					return $filename;
89
-				}
90
-			}
91
-			return $filenames[0];
92
-		}
93
-		return $filenames;
94
-	}
95
-
96
-	/**
97
-	 * @param string $file
98
-	 * @return bool
99
-	 */
100
-	protected function template_exists($file) {
101
-		foreach ($this->locations as $dir) {
102
-			$look_for = trailingslashit($dir) . $file;
103
-			if (file_exists($look_for)) {
104
-				return true;
105
-			}
106
-		}
107
-		return false;
108
-	}
109
-
110
-	/**
111
-	 * @return array
112
-	 */
113
-	function get_locations_theme() {
114
-		$theme_locs = array();
115
-		$child_loc = get_stylesheet_directory();
116
-		$parent_loc = get_template_directory();
117
-		if (DIRECTORY_SEPARATOR == '\\') {
118
-			$child_loc = str_replace('/', '\\', $child_loc);
119
-			$parent_loc = str_replace('/', '\\', $parent_loc);
120
-		}
121
-		$theme_locs[] = $child_loc;
122
-		foreach ($this->get_locations_theme_dir() as $dirname) {
123
-			$theme_locs[] = trailingslashit($child_loc) . trailingslashit($dirname);
124
-		}
125
-		if ($child_loc != $parent_loc) {
126
-			$theme_locs[] = $parent_loc;
127
-			foreach ($this->get_locations_theme_dir() as $dirname) {
128
-				$theme_locs[] = trailingslashit($parent_loc) . trailingslashit($dirname);
129
-			}
130
-		}
131
-		//now make sure theres a trailing slash on everything
132
-		$theme_locs = array_map('trailingslashit', $theme_locs);
133
-		return $theme_locs;
134
-	}
135
-
136
-	/**
137
-	 * returns an array of the directory inside themes that holds twig files
138
-	 * @return string[] the names of directores, ie: array('templats', 'views');
139
-	 */
140
-	private function get_locations_theme_dir() {
141
-		if (is_string(Timber::$dirname)) {
142
-			return array(Timber::$dirname);
143
-		}
144
-		return Timber::$dirname;
145
-	}
146
-
147
-	/**
148
-	 * @return array
149
-	 */
150
-	function get_locations_user() {
151
-		$locs = array();
152
-		if (isset(Timber::$locations)) {
153
-			if (is_string(Timber::$locations)) {
154
-				Timber::$locations = array(Timber::$locations);
155
-			}
156
-			foreach (Timber::$locations as $tloc) {
157
-				$tloc = realpath($tloc);
158
-				if (is_dir($tloc)) {
159
-					$locs[] = $tloc;
160
-				}
161
-			}
162
-		}
163
-		return $locs;
164
-	}
165
-
166
-	/**
167
-	 * @param bool|string   $caller the calling directory
168
-	 * @return array
169
-	 */
170
-	function get_locations_caller($caller = false) {
171
-		$locs = array();
172
-		if ($caller && is_string($caller)) {
173
-			$caller = trailingslashit($caller);
174
-			if (is_dir($caller)) {
175
-				$locs[] = $caller;
176
-			}
177
-			foreach ($this->get_locations_theme_dir() as $dirname) {
178
-				$caller_sub = $caller . trailingslashit($dirname);
179
-				if (is_dir($caller_sub)) {
180
-					$locs[] = $caller_sub;
181
-				}
182
-			}
183
-		}
184
-		return $locs;
185
-	}
186
-
187
-	/**
188
-	 * @param bool|string   $caller the calling directory (or false)
189
-	 * @return array
190
-	 */
191
-	function get_locations($caller = false) {
192
-		//prioirty: user locations, caller (but not theme), child theme, parent theme, caller
193
-		$locs = array();
194
-		$locs = array_merge($locs, $this->get_locations_user());
195
-		$locs = array_merge($locs, $this->get_locations_caller($caller));
196
-		//remove themes from caller
197
-		$locs = array_diff($locs, $this->get_locations_theme());
198
-		$locs = array_merge($locs, $this->get_locations_theme());
199
-		$locs = array_merge($locs, $this->get_locations_caller($caller));
200
-		$locs = array_unique($locs);
201
-		$locs = apply_filters('timber_locations', $locs);
202
-		$locs = apply_filters('timber/locations', $locs);
203
-		return $locs;
204
-	}
205
-
206
-	/**
207
-	 * @return Twig_Loader_Filesystem
208
-	 */
209
-	function get_loader() {
210
-		$paths = array();
211
-		foreach ($this->locations as $loc) {
212
-			$loc = realpath($loc);
213
-			if (is_dir($loc)) {
214
-				$loc = realpath($loc);
215
-				$paths[] = $loc;
216
-			} else {
217
-				//error_log($loc.' is not a directory');
218
-			}
219
-		}
220
-		if (!ini_get('open_basedir')) {
221
-			$paths[] = '/';
222
-		} else {
223
-			$paths[] = ABSPATH;
224
-		}
225
-		$paths = apply_filters('timber/loader/paths', $paths);
226
-		$loader = new Twig_Loader_Filesystem($paths);
227
-		return $loader;
228
-	}
229
-
230
-	/**
231
-	 * @return Twig_Environment
232
-	 */
233
-	function get_twig() {
234
-		$loader = $this->get_loader();
235
-		$params = array('debug' => WP_DEBUG, 'autoescape' => false);
236
-		if (isset(Timber::$autoescape)) {
237
-			$params['autoescape'] = Timber::$autoescape;
238
-		}
239
-		if (Timber::$cache === true) {
240
-			Timber::$twig_cache = true;
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)) {
245
-				mkdir($twig_cache_loc, 0777, true);
246
-			}
247
-			$params['cache'] = $twig_cache_loc;
248
-		}
249
-		$twig = new Twig_Environment($loader, $params);
250
-		if ( WP_DEBUG ) {
251
-			$twig->addExtension(new Twig_Extension_Debug());
252
-		}
253
-		$twig->addExtension($this->_get_cache_extension());
254
-
255
-		$twig = apply_filters('twig_apply_filters', $twig);
256
-		$twig = apply_filters('timber/twig/filters', $twig);
257
-		$twig = apply_filters('timber/loader/twig', $twig);
258
-		return $twig;
259
-	}
260
-
261
-	public function clear_cache_timber($cache_mode = self::CACHE_USE_DEFAULT){
262
-		//_transient_timberloader
263
-		$object_cache = false;
264
-		if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
265
-			$object_cache = true;
266
-		}
267
-		$cache_mode = $this->_get_cache_mode($cache_mode);
268
-		if (self::CACHE_TRANSIENT === $cache_mode) {
269
-			global $wpdb;
270
-			$query = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE '%s'", '_transient_timberloader_%');
271
-			$wpdb->query( $query );
272
-			return true;
273
-		} else if (self::CACHE_SITE_TRANSIENT === $cache_mode) {
274
-			global $wpdb;
275
-			$query = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE '%s'", '_transient_timberloader_%');
276
-			$wpdb->query( $query );
277
-			return true;
278
-		} else if (self::CACHE_OBJECT === $cache_mode && $object_cache) {
279
-			global $wp_object_cache;
280
-			if (isset($wp_object_cache->cache[self::CACHEGROUP])){
281
-				unset($wp_object_cache->cache[self::CACHEGROUP]);
282
-				return true;
283
-			}
284
-		}
285
-		return false;
286
-	}
287
-
288
-	public function clear_cache_twig() {
289
-		$twig = $this->get_twig();
290
-		$twig->clearCacheFiles();
291
-		$cache = $twig->getCache();
292
-		if ($cache){
293
-			self::rrmdir($twig->getCache());
294
-			return true;
295
-		}
296
-		return false;
297
-	}
298
-
299
-	/**
300
-	 * @param string|false $dirPath
301
-	 */
302
-	public static function rrmdir($dirPath) {
303
-		if (! is_dir($dirPath)) {
304
-			throw new InvalidArgumentException("$dirPath must be a directory");
305
-		}
306
-		if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
307
-			$dirPath .= '/';
308
-		}
309
-		$files = glob($dirPath . '*', GLOB_MARK);
310
-		foreach ($files as $file) {
311
-			if (is_dir($file)) {
312
-				self::rrmdir($file);
313
-			} else {
314
-				unlink($file);
315
-			}
316
-		}
317
-		rmdir($dirPath);
318
-	}
319
-
320
-	/**
321
-	 * @return \Asm89\Twig\CacheExtension\Extension
322
-	 */
323
-	private function _get_cache_extension() {
324
-
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 );
329
-
330
-		return $cache_extension;
331
-	}
332
-
333
-	/**
334
-	 * @param string $key
335
-	 * @param string $group
336
-	 * @param string $cache_mode
337
-	 * @return bool
338
-	 */
339
-	public function get_cache($key, $group = self::CACHEGROUP, $cache_mode = self::CACHE_USE_DEFAULT) {
340
-		$object_cache = false;
341
-
342
-		if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
343
-			$object_cache = true;
344
-		}
345
-
346
-		$cache_mode = $this->_get_cache_mode($cache_mode);
347
-
348
-		$value = false;
349
-
350
-		$trans_key = substr($group . '_' . $key, 0, self::TRANS_KEY_LEN);
351
-		if (self::CACHE_TRANSIENT === $cache_mode)
352
-			$value = get_transient($trans_key);
353
-
354
-		elseif (self::CACHE_SITE_TRANSIENT === $cache_mode)
355
-			$value = get_site_transient($trans_key);
356
-
357
-		elseif (self::CACHE_OBJECT === $cache_mode && $object_cache)
358
-			$value = wp_cache_get($key, $group);
359
-
360
-		return $value;
361
-	}
362
-
363
-	/**
364
-	 * @param string $key
365
-	 * @param string|boolean $value
366
-	 * @param string $group
367
-	 * @param int $expires
368
-	 * @param string $cache_mode
369
-	 * @return string|boolean
370
-	 */
371
-	public function set_cache($key, $value, $group = self::CACHEGROUP, $expires = 0, $cache_mode = self::CACHE_USE_DEFAULT) {
372
-		$object_cache = false;
373
-
374
-		if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
375
-			$object_cache = true;
376
-		}
377
-
378
-		if ((int)$expires < 1)
379
-			$expires = 0;
380
-
381
-		$cache_mode = self::_get_cache_mode($cache_mode);
382
-		$trans_key = substr($group . '_' . $key, 0, self::TRANS_KEY_LEN);
383
-
384
-		if (self::CACHE_TRANSIENT === $cache_mode)
385
-			set_transient($trans_key, $value, $expires);
386
-
387
-		elseif (self::CACHE_SITE_TRANSIENT === $cache_mode)
388
-			set_site_transient($trans_key, $value, $expires);
389
-
390
-		elseif (self::CACHE_OBJECT === $cache_mode && $object_cache)
391
-			wp_cache_set($key, $value, $group, $expires);
392
-
393
-		return $value;
394
-	}
395
-
396
-	/**
397
-	 * @param string $cache_mode
398
-	 * @return string
399
-	 */
400
-	private function _get_cache_mode($cache_mode) {
401
-		if (empty($cache_mode) || self::CACHE_USE_DEFAULT === $cache_mode) {
402
-			$cache_mode = $this->cache_mode;
403
-		}
404
-
405
-		// Fallback if self::$cache_mode did not get a valid value
406
-		if (!in_array($cache_mode, self::$cache_modes)) {
407
-			$cache_mode = self::CACHE_OBJECT;
408
-		}
409
-
410
-		return $cache_mode;
411
-	}
5
+    const CACHEGROUP = 'timberloader';
6
+
7
+    const TRANS_KEY_LEN = 50;
8
+
9
+    const CACHE_NONE = 'none';
10
+    const CACHE_OBJECT = 'cache';
11
+    const CACHE_TRANSIENT = 'transient';
12
+    const CACHE_SITE_TRANSIENT = 'site-transient';
13
+    const CACHE_USE_DEFAULT = 'default';
14
+
15
+    public static $cache_modes = array(
16
+        self::CACHE_NONE,
17
+        self::CACHE_OBJECT,
18
+        self::CACHE_TRANSIENT,
19
+        self::CACHE_SITE_TRANSIENT
20
+    );
21
+
22
+    protected $cache_mode = self::CACHE_TRANSIENT;
23
+
24
+    public $locations;
25
+
26
+    /**
27
+     * @param bool|string   $caller the calling directory or false
28
+     */
29
+    function __construct($caller = false) {
30
+        $this->locations = $this->get_locations($caller);
31
+        $this->cache_mode = apply_filters('timber_cache_mode', $this->cache_mode);
32
+        $this->cache_mode = apply_filters('timber/cache/mode', $this->cache_mode);
33
+    }
34
+
35
+    /**
36
+     * @param string        $file
37
+     * @param array         $data
38
+     * @param bool          $expires
39
+     * @param string        $cache_mode
40
+     * @return bool|string
41
+     */
42
+    function render($file, $data = null, $expires = false, $cache_mode = self::CACHE_USE_DEFAULT) {
43
+        // Different $expires if user is anonymous or logged in
44
+        if (is_array($expires)) {
45
+            if (is_user_logged_in() && isset($expires[1])) {
46
+                $expires = $expires[1];
47
+            } else {
48
+                $expires = $expires[0];
49
+            }
50
+        }
51
+
52
+        $key = null;
53
+        $output = false;
54
+        if (false !== $expires) {
55
+            ksort($data);
56
+            $key = md5($file . json_encode($data));
57
+            $output = $this->get_cache($key, self::CACHEGROUP, $cache_mode);
58
+        }
59
+
60
+        if (false === $output || null === $output) {
61
+            $twig = $this->get_twig();
62
+            if (strlen($file)) {
63
+                $loader = $this->get_loader();
64
+                $result = $loader->getCacheKey($file);
65
+                do_action('timber_loader_render_file', $result);
66
+            }
67
+            $data = apply_filters('timber_loader_render_data', $data);
68
+            $data = apply_filters('timber/loader/render_data', $data);
69
+            $output = $twig->render($file, $data);
70
+        }
71
+
72
+        if (false !== $output && false !== $expires && null !== $key) {
73
+            $this->set_cache($key, $output, self::CACHEGROUP, $expires, $cache_mode);
74
+        }
75
+        $output = apply_filters('timber_output', $output);
76
+        return apply_filters('timber/output', $output);
77
+    }
78
+
79
+    /**
80
+     * @param array $filenames
81
+     * @return bool
82
+     */
83
+    public function choose_template($filenames) {
84
+        if (is_array($filenames)) {
85
+            /* its an array so we have to figure out which one the dev wants */
86
+            foreach ($filenames as $filename) {
87
+                if (self::template_exists($filename)) {
88
+                    return $filename;
89
+                }
90
+            }
91
+            return $filenames[0];
92
+        }
93
+        return $filenames;
94
+    }
95
+
96
+    /**
97
+     * @param string $file
98
+     * @return bool
99
+     */
100
+    protected function template_exists($file) {
101
+        foreach ($this->locations as $dir) {
102
+            $look_for = trailingslashit($dir) . $file;
103
+            if (file_exists($look_for)) {
104
+                return true;
105
+            }
106
+        }
107
+        return false;
108
+    }
109
+
110
+    /**
111
+     * @return array
112
+     */
113
+    function get_locations_theme() {
114
+        $theme_locs = array();
115
+        $child_loc = get_stylesheet_directory();
116
+        $parent_loc = get_template_directory();
117
+        if (DIRECTORY_SEPARATOR == '\\') {
118
+            $child_loc = str_replace('/', '\\', $child_loc);
119
+            $parent_loc = str_replace('/', '\\', $parent_loc);
120
+        }
121
+        $theme_locs[] = $child_loc;
122
+        foreach ($this->get_locations_theme_dir() as $dirname) {
123
+            $theme_locs[] = trailingslashit($child_loc) . trailingslashit($dirname);
124
+        }
125
+        if ($child_loc != $parent_loc) {
126
+            $theme_locs[] = $parent_loc;
127
+            foreach ($this->get_locations_theme_dir() as $dirname) {
128
+                $theme_locs[] = trailingslashit($parent_loc) . trailingslashit($dirname);
129
+            }
130
+        }
131
+        //now make sure theres a trailing slash on everything
132
+        $theme_locs = array_map('trailingslashit', $theme_locs);
133
+        return $theme_locs;
134
+    }
135
+
136
+    /**
137
+     * returns an array of the directory inside themes that holds twig files
138
+     * @return string[] the names of directores, ie: array('templats', 'views');
139
+     */
140
+    private function get_locations_theme_dir() {
141
+        if (is_string(Timber::$dirname)) {
142
+            return array(Timber::$dirname);
143
+        }
144
+        return Timber::$dirname;
145
+    }
146
+
147
+    /**
148
+     * @return array
149
+     */
150
+    function get_locations_user() {
151
+        $locs = array();
152
+        if (isset(Timber::$locations)) {
153
+            if (is_string(Timber::$locations)) {
154
+                Timber::$locations = array(Timber::$locations);
155
+            }
156
+            foreach (Timber::$locations as $tloc) {
157
+                $tloc = realpath($tloc);
158
+                if (is_dir($tloc)) {
159
+                    $locs[] = $tloc;
160
+                }
161
+            }
162
+        }
163
+        return $locs;
164
+    }
165
+
166
+    /**
167
+     * @param bool|string   $caller the calling directory
168
+     * @return array
169
+     */
170
+    function get_locations_caller($caller = false) {
171
+        $locs = array();
172
+        if ($caller && is_string($caller)) {
173
+            $caller = trailingslashit($caller);
174
+            if (is_dir($caller)) {
175
+                $locs[] = $caller;
176
+            }
177
+            foreach ($this->get_locations_theme_dir() as $dirname) {
178
+                $caller_sub = $caller . trailingslashit($dirname);
179
+                if (is_dir($caller_sub)) {
180
+                    $locs[] = $caller_sub;
181
+                }
182
+            }
183
+        }
184
+        return $locs;
185
+    }
186
+
187
+    /**
188
+     * @param bool|string   $caller the calling directory (or false)
189
+     * @return array
190
+     */
191
+    function get_locations($caller = false) {
192
+        //prioirty: user locations, caller (but not theme), child theme, parent theme, caller
193
+        $locs = array();
194
+        $locs = array_merge($locs, $this->get_locations_user());
195
+        $locs = array_merge($locs, $this->get_locations_caller($caller));
196
+        //remove themes from caller
197
+        $locs = array_diff($locs, $this->get_locations_theme());
198
+        $locs = array_merge($locs, $this->get_locations_theme());
199
+        $locs = array_merge($locs, $this->get_locations_caller($caller));
200
+        $locs = array_unique($locs);
201
+        $locs = apply_filters('timber_locations', $locs);
202
+        $locs = apply_filters('timber/locations', $locs);
203
+        return $locs;
204
+    }
205
+
206
+    /**
207
+     * @return Twig_Loader_Filesystem
208
+     */
209
+    function get_loader() {
210
+        $paths = array();
211
+        foreach ($this->locations as $loc) {
212
+            $loc = realpath($loc);
213
+            if (is_dir($loc)) {
214
+                $loc = realpath($loc);
215
+                $paths[] = $loc;
216
+            } else {
217
+                //error_log($loc.' is not a directory');
218
+            }
219
+        }
220
+        if (!ini_get('open_basedir')) {
221
+            $paths[] = '/';
222
+        } else {
223
+            $paths[] = ABSPATH;
224
+        }
225
+        $paths = apply_filters('timber/loader/paths', $paths);
226
+        $loader = new Twig_Loader_Filesystem($paths);
227
+        return $loader;
228
+    }
229
+
230
+    /**
231
+     * @return Twig_Environment
232
+     */
233
+    function get_twig() {
234
+        $loader = $this->get_loader();
235
+        $params = array('debug' => WP_DEBUG, 'autoescape' => false);
236
+        if (isset(Timber::$autoescape)) {
237
+            $params['autoescape'] = Timber::$autoescape;
238
+        }
239
+        if (Timber::$cache === true) {
240
+            Timber::$twig_cache = true;
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)) {
245
+                mkdir($twig_cache_loc, 0777, true);
246
+            }
247
+            $params['cache'] = $twig_cache_loc;
248
+        }
249
+        $twig = new Twig_Environment($loader, $params);
250
+        if ( WP_DEBUG ) {
251
+            $twig->addExtension(new Twig_Extension_Debug());
252
+        }
253
+        $twig->addExtension($this->_get_cache_extension());
254
+
255
+        $twig = apply_filters('twig_apply_filters', $twig);
256
+        $twig = apply_filters('timber/twig/filters', $twig);
257
+        $twig = apply_filters('timber/loader/twig', $twig);
258
+        return $twig;
259
+    }
260
+
261
+    public function clear_cache_timber($cache_mode = self::CACHE_USE_DEFAULT){
262
+        //_transient_timberloader
263
+        $object_cache = false;
264
+        if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
265
+            $object_cache = true;
266
+        }
267
+        $cache_mode = $this->_get_cache_mode($cache_mode);
268
+        if (self::CACHE_TRANSIENT === $cache_mode) {
269
+            global $wpdb;
270
+            $query = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE '%s'", '_transient_timberloader_%');
271
+            $wpdb->query( $query );
272
+            return true;
273
+        } else if (self::CACHE_SITE_TRANSIENT === $cache_mode) {
274
+            global $wpdb;
275
+            $query = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE '%s'", '_transient_timberloader_%');
276
+            $wpdb->query( $query );
277
+            return true;
278
+        } else if (self::CACHE_OBJECT === $cache_mode && $object_cache) {
279
+            global $wp_object_cache;
280
+            if (isset($wp_object_cache->cache[self::CACHEGROUP])){
281
+                unset($wp_object_cache->cache[self::CACHEGROUP]);
282
+                return true;
283
+            }
284
+        }
285
+        return false;
286
+    }
287
+
288
+    public function clear_cache_twig() {
289
+        $twig = $this->get_twig();
290
+        $twig->clearCacheFiles();
291
+        $cache = $twig->getCache();
292
+        if ($cache){
293
+            self::rrmdir($twig->getCache());
294
+            return true;
295
+        }
296
+        return false;
297
+    }
298
+
299
+    /**
300
+     * @param string|false $dirPath
301
+     */
302
+    public static function rrmdir($dirPath) {
303
+        if (! is_dir($dirPath)) {
304
+            throw new InvalidArgumentException("$dirPath must be a directory");
305
+        }
306
+        if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
307
+            $dirPath .= '/';
308
+        }
309
+        $files = glob($dirPath . '*', GLOB_MARK);
310
+        foreach ($files as $file) {
311
+            if (is_dir($file)) {
312
+                self::rrmdir($file);
313
+            } else {
314
+                unlink($file);
315
+            }
316
+        }
317
+        rmdir($dirPath);
318
+    }
319
+
320
+    /**
321
+     * @return \Asm89\Twig\CacheExtension\Extension
322
+     */
323
+    private function _get_cache_extension() {
324
+
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 );
329
+
330
+        return $cache_extension;
331
+    }
332
+
333
+    /**
334
+     * @param string $key
335
+     * @param string $group
336
+     * @param string $cache_mode
337
+     * @return bool
338
+     */
339
+    public function get_cache($key, $group = self::CACHEGROUP, $cache_mode = self::CACHE_USE_DEFAULT) {
340
+        $object_cache = false;
341
+
342
+        if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
343
+            $object_cache = true;
344
+        }
345
+
346
+        $cache_mode = $this->_get_cache_mode($cache_mode);
347
+
348
+        $value = false;
349
+
350
+        $trans_key = substr($group . '_' . $key, 0, self::TRANS_KEY_LEN);
351
+        if (self::CACHE_TRANSIENT === $cache_mode)
352
+            $value = get_transient($trans_key);
353
+
354
+        elseif (self::CACHE_SITE_TRANSIENT === $cache_mode)
355
+            $value = get_site_transient($trans_key);
356
+
357
+        elseif (self::CACHE_OBJECT === $cache_mode && $object_cache)
358
+            $value = wp_cache_get($key, $group);
359
+
360
+        return $value;
361
+    }
362
+
363
+    /**
364
+     * @param string $key
365
+     * @param string|boolean $value
366
+     * @param string $group
367
+     * @param int $expires
368
+     * @param string $cache_mode
369
+     * @return string|boolean
370
+     */
371
+    public function set_cache($key, $value, $group = self::CACHEGROUP, $expires = 0, $cache_mode = self::CACHE_USE_DEFAULT) {
372
+        $object_cache = false;
373
+
374
+        if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
375
+            $object_cache = true;
376
+        }
377
+
378
+        if ((int)$expires < 1)
379
+            $expires = 0;
380
+
381
+        $cache_mode = self::_get_cache_mode($cache_mode);
382
+        $trans_key = substr($group . '_' . $key, 0, self::TRANS_KEY_LEN);
383
+
384
+        if (self::CACHE_TRANSIENT === $cache_mode)
385
+            set_transient($trans_key, $value, $expires);
386
+
387
+        elseif (self::CACHE_SITE_TRANSIENT === $cache_mode)
388
+            set_site_transient($trans_key, $value, $expires);
389
+
390
+        elseif (self::CACHE_OBJECT === $cache_mode && $object_cache)
391
+            wp_cache_set($key, $value, $group, $expires);
392
+
393
+        return $value;
394
+    }
395
+
396
+    /**
397
+     * @param string $cache_mode
398
+     * @return string
399
+     */
400
+    private function _get_cache_mode($cache_mode) {
401
+        if (empty($cache_mode) || self::CACHE_USE_DEFAULT === $cache_mode) {
402
+            $cache_mode = $this->cache_mode;
403
+        }
404
+
405
+        // Fallback if self::$cache_mode did not get a valid value
406
+        if (!in_array($cache_mode, self::$cache_modes)) {
407
+            $cache_mode = self::CACHE_OBJECT;
408
+        }
409
+
410
+        return $cache_mode;
411
+    }
412 412
 
413 413
 }
Please login to merge, or discard this patch.
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	/**
27 27
 	 * @param bool|string   $caller the calling directory or false
28 28
 	 */
29
-	function __construct($caller = false) {
29
+	function __construct( $caller = false ) {
30 30
 		$this->locations = $this->get_locations($caller);
31 31
 		$this->cache_mode = apply_filters('timber_cache_mode', $this->cache_mode);
32 32
 		$this->cache_mode = apply_filters('timber/cache/mode', $this->cache_mode);
@@ -39,10 +39,10 @@  discard block
 block discarded – undo
39 39
 	 * @param string        $cache_mode
40 40
 	 * @return bool|string
41 41
 	 */
42
-	function render($file, $data = null, $expires = false, $cache_mode = self::CACHE_USE_DEFAULT) {
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);
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 	 * @param array $filenames
81 81
 	 * @return bool
82 82
 	 */
83
-	public function choose_template($filenames) {
84
-		if (is_array($filenames)) {
83
+	public function choose_template( $filenames ) {
84
+		if ( is_array($filenames) ) {
85 85
 			/* its an array so we have to figure out which one the dev wants */
86
-			foreach ($filenames as $filename) {
87
-				if (self::template_exists($filename)) {
86
+			foreach ( $filenames as $filename ) {
87
+				if ( self::template_exists($filename) ) {
88 88
 					return $filename;
89 89
 				}
90 90
 			}
@@ -97,10 +97,10 @@  discard block
 block discarded – undo
97 97
 	 * @param string $file
98 98
 	 * @return bool
99 99
 	 */
100
-	protected function template_exists($file) {
101
-		foreach ($this->locations as $dir) {
100
+	protected function template_exists( $file ) {
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,17 +114,17 @@  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
 		}
121 121
 		$theme_locs[] = $child_loc;
122
-		foreach ($this->get_locations_theme_dir() as $dirname) {
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
-			foreach ($this->get_locations_theme_dir() as $dirname) {
127
+			foreach ( $this->get_locations_theme_dir() as $dirname ) {
128 128
 				$theme_locs[] = trailingslashit($parent_loc) . trailingslashit($dirname);
129 129
 			}
130 130
 		}
@@ -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
-			foreach (Timber::$locations as $tloc) {
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
 			}
@@ -167,16 +167,16 @@  discard block
 block discarded – undo
167 167
 	 * @param bool|string   $caller the calling directory
168 168
 	 * @return array
169 169
 	 */
170
-	function get_locations_caller($caller = false) {
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
-			foreach ($this->get_locations_theme_dir() as $dirname) {
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
 			}
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 * @param bool|string   $caller the calling directory (or false)
189 189
 	 * @return array
190 190
 	 */
191
-	function get_locations($caller = false) {
191
+	function get_locations( $caller = false ) {
192 192
 		//prioirty: user locations, caller (but not theme), child theme, parent theme, caller
193 193
 		$locs = array();
194 194
 		$locs = array_merge($locs, $this->get_locations_user());
@@ -208,16 +208,16 @@  discard block
 block discarded – undo
208 208
 	 */
209 209
 	function get_loader() {
210 210
 		$paths = array();
211
-		foreach ($this->locations as $loc) {
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
 		}
@@ -299,16 +299,16 @@  discard block
 block discarded – undo
299 299
 	/**
300 300
 	 * @param string|false $dirPath
301 301
 	 */
302
-	public static function rrmdir($dirPath) {
303
-		if (! is_dir($dirPath)) {
302
+	public static function rrmdir( $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
-		foreach ($files as $file) {
311
-			if (is_dir($file)) {
310
+		foreach ( $files as $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
 	}
@@ -336,10 +336,10 @@  discard block
 block discarded – undo
336 336
 	 * @param string $cache_mode
337 337
 	 * @return bool
338 338
 	 */
339
-	public function get_cache($key, $group = self::CACHEGROUP, $cache_mode = self::CACHE_USE_DEFAULT) {
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;
@@ -368,26 +368,26 @@  discard block
 block discarded – undo
368 368
 	 * @param string $cache_mode
369 369
 	 * @return string|boolean
370 370
 	 */
371
-	public function set_cache($key, $value, $group = self::CACHEGROUP, $expires = 0, $cache_mode = self::CACHE_USE_DEFAULT) {
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;
@@ -397,13 +397,13 @@  discard block
 block discarded – undo
397 397
 	 * @param string $cache_mode
398 398
 	 * @return string
399 399
 	 */
400
-	private function _get_cache_mode($cache_mode) {
401
-		if (empty($cache_mode) || self::CACHE_USE_DEFAULT === $cache_mode) {
400
+	private function _get_cache_mode( $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.
lib/timber-post-getter.php 4 patches
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 			$query = false;
38 38
 		}
39 39
 
40
-		if (is_object($query) && !is_a($query, 'WP_Query') ){
40
+		if (is_object($query) && !is_a($query, 'WP_Query') ) {
41 41
 			// The only object other than a query is a type of post object
42 42
 			$query = array( $query );
43 43
 		}
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
 		}
53 53
 	}
54 54
 
55
-	static function get_pids($query){
55
+	static function get_pids($query) {
56 56
 		$posts = self::get_posts($query);
57 57
 		$pids = array();
58
-		foreach($posts as $post){
59
-			if (isset($post->ID)){
58
+		foreach($posts as $post) {
59
+			if (isset($post->ID)) {
60 60
 				$pids[] = $post->ID;
61 61
 			}
62 62
 		}
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 * @param string|array $arg
90 90
 	 * @return bool
91 91
 	 */
92
-	static function is_post_class_or_class_map($arg){
92
+	static function is_post_class_or_class_map($arg) {
93 93
 		if (is_string($arg) && class_exists($arg)) {
94 94
 			return true;
95 95
 		}
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -606,7 +606,7 @@
 block discarded – undo
606 606
 	 * Is post class or class map.
607 607
 	 *
608 608
 	 * @param string|array $args
609
-	 * @return bool
609
+	 * @return boolean|null
610 610
 	 * @deprecated since 0.20.0
611 611
 	 */
612 612
 	public static function is_post_class_or_class_map( $args ) {
Please login to merge, or discard this patch.
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -2,103 +2,103 @@
 block discarded – undo
2 2
 
3 3
 class TimberPostGetter {
4 4
 
5
-	/**
6
-	 * @param mixed $query
7
-	 * @param string $PostClass
8
-	 * @return array|bool|null
9
-	 */
10
-	static function get_post($query = false, $PostClass = 'TimberPost') {
11
-		$posts = self::get_posts( $query, $PostClass );
12
-		if ( $post = reset($posts ) ) {
13
-			return $post;
14
-		}
15
-	}
5
+    /**
6
+     * @param mixed $query
7
+     * @param string $PostClass
8
+     * @return array|bool|null
9
+     */
10
+    static function get_post($query = false, $PostClass = 'TimberPost') {
11
+        $posts = self::get_posts( $query, $PostClass );
12
+        if ( $post = reset($posts ) ) {
13
+            return $post;
14
+        }
15
+    }
16 16
 
17
-	static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) {
18
-		$posts = self::query_posts( $query, $PostClass );
19
-		return apply_filters('timber_post_getter_get_posts', $posts->get_posts( $return_collection ));
20
-	}
17
+    static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) {
18
+        $posts = self::query_posts( $query, $PostClass );
19
+        return apply_filters('timber_post_getter_get_posts', $posts->get_posts( $return_collection ));
20
+    }
21 21
 
22
-	static function query_post( $query = false, $PostClass = 'TimberPost' ) {
23
-		$posts = self::query_posts( $query, $PostClass );
24
-		if ( method_exists($posts, 'current') && $post = $posts->current() ) {
25
-			return $post;
26
-		}
27
-	}
22
+    static function query_post( $query = false, $PostClass = 'TimberPost' ) {
23
+        $posts = self::query_posts( $query, $PostClass );
24
+        if ( method_exists($posts, 'current') && $post = $posts->current() ) {
25
+            return $post;
26
+        }
27
+    }
28 28
 
29
-	/**
30
-	 * @param mixed $query
31
-	 * @param string $PostClass
32
-	 * @return array|bool|null
33
-	 */
34
-	static function query_posts($query = false, $PostClass = 'TimberPost' ) {
35
-		if (self::is_post_class_or_class_map($query)) {
36
-			$PostClass = $query;
37
-			$query = false;
38
-		}
29
+    /**
30
+     * @param mixed $query
31
+     * @param string $PostClass
32
+     * @return array|bool|null
33
+     */
34
+    static function query_posts($query = false, $PostClass = 'TimberPost' ) {
35
+        if (self::is_post_class_or_class_map($query)) {
36
+            $PostClass = $query;
37
+            $query = false;
38
+        }
39 39
 
40
-		if (is_object($query) && !is_a($query, 'WP_Query') ){
41
-			// The only object other than a query is a type of post object
42
-			$query = array( $query );
43
-		}
40
+        if (is_object($query) && !is_a($query, 'WP_Query') ){
41
+            // The only object other than a query is a type of post object
42
+            $query = array( $query );
43
+        }
44 44
 
45
-		if ( is_array( $query ) && count( $query ) && isset( $query[0] ) && is_object( $query[0] ) ) {
46
-			// We have an array of post objects that already have data
47
-			return new TimberPostsCollection( $query, $PostClass );
48
-		} else {
49
-			// We have a query (of sorts) to work with
50
-			$tqi = new TimberQueryIterator( $query, $PostClass );
51
-			return $tqi;
52
-		}
53
-	}
45
+        if ( is_array( $query ) && count( $query ) && isset( $query[0] ) && is_object( $query[0] ) ) {
46
+            // We have an array of post objects that already have data
47
+            return new TimberPostsCollection( $query, $PostClass );
48
+        } else {
49
+            // We have a query (of sorts) to work with
50
+            $tqi = new TimberQueryIterator( $query, $PostClass );
51
+            return $tqi;
52
+        }
53
+    }
54 54
 
55
-	static function get_pids($query){
56
-		$posts = self::get_posts($query);
57
-		$pids = array();
58
-		foreach($posts as $post){
59
-			if (isset($post->ID)){
60
-				$pids[] = $post->ID;
61
-			}
62
-		}
63
-		return $pids;
64
-	}
55
+    static function get_pids($query){
56
+        $posts = self::get_posts($query);
57
+        $pids = array();
58
+        foreach($posts as $post){
59
+            if (isset($post->ID)){
60
+                $pids[] = $post->ID;
61
+            }
62
+        }
63
+        return $pids;
64
+    }
65 65
 
66
-	static function loop_to_id() {
67
-		if (!self::wp_query_has_posts()) { return false; }
66
+    static function loop_to_id() {
67
+        if (!self::wp_query_has_posts()) { return false; }
68 68
 
69
-		global $wp_query;
70
-		$post_num = property_exists($wp_query, 'current_post')
71
-				  ? $wp_query->current_post + 1
72
-				  : 0
73
-				  ;
69
+        global $wp_query;
70
+        $post_num = property_exists($wp_query, 'current_post')
71
+                  ? $wp_query->current_post + 1
72
+                  : 0
73
+                    ;
74 74
 
75
-		if (!isset($wp_query->posts[$post_num])) { return false; }
75
+        if (!isset($wp_query->posts[$post_num])) { return false; }
76 76
 
77
-		return $wp_query->posts[$post_num]->ID;
78
-	}
77
+        return $wp_query->posts[$post_num]->ID;
78
+    }
79 79
 
80
-	/**
81
-	 * @return bool
82
-	 */
83
-	static function wp_query_has_posts() {
84
-		global $wp_query;
85
-		return ($wp_query && property_exists($wp_query, 'posts') && $wp_query->posts);
86
-	}
80
+    /**
81
+     * @return bool
82
+     */
83
+    static function wp_query_has_posts() {
84
+        global $wp_query;
85
+        return ($wp_query && property_exists($wp_query, 'posts') && $wp_query->posts);
86
+    }
87 87
 
88
-	/**
89
-	 * @param string|array $arg
90
-	 * @return bool
91
-	 */
92
-	static function is_post_class_or_class_map($arg){
93
-		if (is_string($arg) && class_exists($arg)) {
94
-			return true;
95
-		}
96
-		if (is_array($arg)) {
97
-			foreach ($arg as $item) {
98
-				if (is_string($item) && (class_exists($item) && is_subclass_of($item, 'TimberPost'))) {
99
-					return true;
100
-				}
101
-			}
102
-		}
103
-	}
88
+    /**
89
+     * @param string|array $arg
90
+     * @return bool
91
+     */
92
+    static function is_post_class_or_class_map($arg){
93
+        if (is_string($arg) && class_exists($arg)) {
94
+            return true;
95
+        }
96
+        if (is_array($arg)) {
97
+            foreach ($arg as $item) {
98
+                if (is_string($item) && (class_exists($item) && is_subclass_of($item, 'TimberPost'))) {
99
+                    return true;
100
+                }
101
+            }
102
+        }
103
+    }
104 104
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -7,20 +7,20 @@  discard block
 block discarded – undo
7 7
 	 * @param string $PostClass
8 8
 	 * @return array|bool|null
9 9
 	 */
10
-	static function get_post($query = false, $PostClass = 'TimberPost') {
11
-		$posts = self::get_posts( $query, $PostClass );
12
-		if ( $post = reset($posts ) ) {
10
+	static function get_post( $query = false, $PostClass = 'TimberPost' ) {
11
+		$posts = self::get_posts($query, $PostClass);
12
+		if ( $post = reset($posts) ) {
13 13
 			return $post;
14 14
 		}
15 15
 	}
16 16
 
17 17
 	static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) {
18
-		$posts = self::query_posts( $query, $PostClass );
19
-		return apply_filters('timber_post_getter_get_posts', $posts->get_posts( $return_collection ));
18
+		$posts = self::query_posts($query, $PostClass);
19
+		return apply_filters('timber_post_getter_get_posts', $posts->get_posts($return_collection));
20 20
 	}
21 21
 
22 22
 	static function query_post( $query = false, $PostClass = 'TimberPost' ) {
23
-		$posts = self::query_posts( $query, $PostClass );
23
+		$posts = self::query_posts($query, $PostClass);
24 24
 		if ( method_exists($posts, 'current') && $post = $posts->current() ) {
25 25
 			return $post;
26 26
 		}
@@ -31,32 +31,32 @@  discard block
 block discarded – undo
31 31
 	 * @param string $PostClass
32 32
 	 * @return array|bool|null
33 33
 	 */
34
-	static function query_posts($query = false, $PostClass = 'TimberPost' ) {
35
-		if (self::is_post_class_or_class_map($query)) {
34
+	static function query_posts( $query = false, $PostClass = 'TimberPost' ) {
35
+		if ( self::is_post_class_or_class_map($query) ) {
36 36
 			$PostClass = $query;
37 37
 			$query = false;
38 38
 		}
39 39
 
40
-		if (is_object($query) && !is_a($query, 'WP_Query') ){
40
+		if ( is_object($query) && !is_a($query, 'WP_Query') ) {
41 41
 			// The only object other than a query is a type of post object
42
-			$query = array( $query );
42
+			$query = array($query);
43 43
 		}
44 44
 
45
-		if ( is_array( $query ) && count( $query ) && isset( $query[0] ) && is_object( $query[0] ) ) {
45
+		if ( is_array($query) && count($query) && isset($query[0]) && is_object($query[0]) ) {
46 46
 			// We have an array of post objects that already have data
47
-			return new TimberPostsCollection( $query, $PostClass );
47
+			return new TimberPostsCollection($query, $PostClass);
48 48
 		} else {
49 49
 			// We have a query (of sorts) to work with
50
-			$tqi = new TimberQueryIterator( $query, $PostClass );
50
+			$tqi = new TimberQueryIterator($query, $PostClass);
51 51
 			return $tqi;
52 52
 		}
53 53
 	}
54 54
 
55
-	static function get_pids($query){
55
+	static function get_pids( $query ) {
56 56
 		$posts = self::get_posts($query);
57 57
 		$pids = array();
58
-		foreach($posts as $post){
59
-			if (isset($post->ID)){
58
+		foreach ( $posts as $post ) {
59
+			if ( isset($post->ID) ) {
60 60
 				$pids[] = $post->ID;
61 61
 			}
62 62
 		}
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	}
65 65
 
66 66
 	static function loop_to_id() {
67
-		if (!self::wp_query_has_posts()) { return false; }
67
+		if ( !self::wp_query_has_posts() ) { return false; }
68 68
 
69 69
 		global $wp_query;
70 70
 		$post_num = property_exists($wp_query, 'current_post')
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 				  : 0
73 73
 				  ;
74 74
 
75
-		if (!isset($wp_query->posts[$post_num])) { return false; }
75
+		if ( !isset($wp_query->posts[$post_num]) ) { return false; }
76 76
 
77 77
 		return $wp_query->posts[$post_num]->ID;
78 78
 	}
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
 	 * @param string|array $arg
90 90
 	 * @return bool
91 91
 	 */
92
-	static function is_post_class_or_class_map($arg){
93
-		if (is_string($arg) && class_exists($arg)) {
92
+	static function is_post_class_or_class_map( $arg ) {
93
+		if ( is_string($arg) && class_exists($arg) ) {
94 94
 			return true;
95 95
 		}
96
-		if (is_array($arg)) {
97
-			foreach ($arg as $item) {
98
-				if (is_string($item) && (class_exists($item) && is_subclass_of($item, 'TimberPost'))) {
96
+		if ( is_array($arg) ) {
97
+			foreach ( $arg as $item ) {
98
+				if ( is_string($item) && (class_exists($item) && is_subclass_of($item, 'TimberPost')) ) {
99 99
 					return true;
100 100
 				}
101 101
 			}
Please login to merge, or discard this patch.
lib/timber-posts-collection.php 3 patches
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,14 +1,15 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Exit if accessed directly
4
-if ( !defined( 'ABSPATH' ) )
4
+if ( !defined( 'ABSPATH' ) ) {
5 5
     exit;
6
+}
6 7
 
7 8
 class TimberPostsCollection extends ArrayObject {
8 9
 
9 10
     public function __construct( $posts = array(), $post_class = 'TimberPost' ) {
10 11
         $returned_posts = array();
11
-        if ( is_null( $posts ) ){
12
+        if ( is_null( $posts ) ) {
12 13
             $posts = array();
13 14
         }
14 15
         foreach ( $posts as $post_object ) {
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -51,10 +51,10 @@
 block discarded – undo
51 51
         return $this->getArrayCopy();
52 52
     }
53 53
 
54
-     /**
55
-     * @param array $posts
56
-     * @return array
57
-     */
54
+        /**
55
+         * @param array $posts
56
+         * @return array
57
+         */
58 58
     static function maybe_set_preview( $posts ) {
59 59
         if ( is_array( $posts ) && isset( $_GET['preview'] ) && $_GET['preview']
60 60
                && isset( $_GET['preview_id'] ) && $_GET['preview_id']
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1,50 +1,50 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Exit if accessed directly
4
-if ( !defined( 'ABSPATH' ) )
4
+if ( !defined('ABSPATH') )
5 5
     exit;
6 6
 
7 7
 class TimberPostsCollection extends ArrayObject {
8 8
 
9 9
     public function __construct( $posts = array(), $post_class = 'TimberPost' ) {
10 10
         $returned_posts = array();
11
-        if ( is_null( $posts ) ){
11
+        if ( is_null($posts) ) {
12 12
             $posts = array();
13 13
         }
14 14
         foreach ( $posts as $post_object ) {
15 15
             $post_class_use = $post_class;
16 16
 
17
-            if ( is_array( $post_class ) ) {
18
-                $post_type      = get_post_type( $post_object );
17
+            if ( is_array($post_class) ) {
18
+                $post_type      = get_post_type($post_object);
19 19
                 $post_class_use = 'TimberPost';
20 20
 
21
-                if ( isset( $post_class[$post_type] ) ) {
21
+                if ( isset($post_class[$post_type]) ) {
22 22
                     $post_class_use = $post_class[$post_type];
23 23
 
24 24
                 } else {
25
-                    if ( is_array( $post_class ) ) {
26
-                        TimberHelper::error_log( $post_type . ' of ' . $post_object->ID . ' not found in ' . print_r( $post_class, true ) );
25
+                    if ( is_array($post_class) ) {
26
+                        TimberHelper::error_log($post_type . ' of ' . $post_object->ID . ' not found in ' . print_r($post_class, true));
27 27
                     } else {
28
-                        TimberHelper::error_log( $post_type . ' not found in ' . $post_class );
28
+                        TimberHelper::error_log($post_type . ' not found in ' . $post_class);
29 29
                     }
30 30
                 }
31 31
             }
32 32
 
33 33
             // Don't create yet another object if $post_object is already of the right type
34
-            if ( is_a( $post_object, $post_class_use ) ) {
34
+            if ( is_a($post_object, $post_class_use) ) {
35 35
                 $post = $post_object;
36 36
             } else {
37
-                $post = new $post_class_use( $post_object );
37
+                $post = new $post_class_use($post_object);
38 38
             }
39 39
 
40
-            if ( isset( $post->ID ) ) {
40
+            if ( isset($post->ID) ) {
41 41
                 $returned_posts[] = $post;
42 42
             }
43 43
         }
44 44
 
45 45
         $returned_posts = self::maybe_set_preview($returned_posts);
46 46
 
47
-        parent::__construct( $returned_posts, $flags = 0, 'TimberPostsIterator' );
47
+        parent::__construct($returned_posts, $flags = 0, 'TimberPostsIterator');
48 48
     }
49 49
 
50 50
     public function get_posts() {
@@ -56,16 +56,16 @@  discard block
 block discarded – undo
56 56
      * @return array
57 57
      */
58 58
     static function maybe_set_preview( $posts ) {
59
-        if ( is_array( $posts ) && isset( $_GET['preview'] ) && $_GET['preview']
60
-               && isset( $_GET['preview_id'] ) && $_GET['preview_id']
61
-               && current_user_can( 'edit_post', $_GET['preview_id'] ) ) {
59
+        if ( is_array($posts) && isset($_GET['preview']) && $_GET['preview']
60
+               && isset($_GET['preview_id']) && $_GET['preview_id']
61
+               && current_user_can('edit_post', $_GET['preview_id']) ) {
62 62
             // No need to check the nonce, that already happened in _show_post_preview on init
63 63
 
64 64
             $preview_id = $_GET['preview_id'];
65
-            foreach( $posts as &$post ) {
66
-                if ( is_object( $post ) && $post->ID == $preview_id ) {
65
+            foreach ( $posts as &$post ) {
66
+                if ( is_object($post) && $post->ID == $preview_id ) {
67 67
                     // Based on _set_preview( $post ), but adds import_custom
68
-                    $preview = wp_get_post_autosave( $preview_id );
68
+                    $preview = wp_get_post_autosave($preview_id);
69 69
                     if ( is_object($preview) ) {
70 70
 
71 71
                         $preview = sanitize_post($preview);
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
                         $post->post_content = $preview->post_content;
74 74
                         $post->post_title = $preview->post_title;
75 75
                         $post->post_excerpt = $preview->post_excerpt;
76
-                        $post->import_custom( $preview_id );
76
+                        $post->import_custom($preview_id);
77 77
 
78
-                        add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
78
+                        add_filter('get_the_terms', '_wp_preview_terms_filter', 10, 3);
79 79
                     }
80 80
                 }
81 81
             }
Please login to merge, or discard this patch.
lib/timber-query-iterator.php 3 patches
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( !defined( 'ABSPATH' ) )
3
+if ( !defined( 'ABSPATH' ) ) {
4 4
     exit;
5
+}
5 6
 
6 7
 class TimberQueryIterator implements Iterator {
7 8
 
@@ -15,8 +16,9 @@  discard block
 block discarded – undo
15 16
 
16 17
     public function __construct( $query = false, $posts_class = 'TimberPost' ) {
17 18
         add_action( 'pre_get_posts', array($this, 'fix_number_posts_wp_quirk' ));
18
-        if ( $posts_class )
19
-            $this->_posts_class = $posts_class;
19
+        if ( $posts_class ) {
20
+                    $this->_posts_class = $posts_class;
21
+        }
20 22
 
21 23
         if ( is_a( $query, 'WP_Query' ) ) {
22 24
             // We got a full-fledged WP Query, look no further!
@@ -55,7 +57,7 @@  discard block
 block discarded – undo
55 57
     }
56 58
 
57 59
     public function get_posts( $return_collection = false ) {
58
-        if (isset($this->_query->posts)){
60
+        if (isset($this->_query->posts)) {
59 61
             $posts = new TimberPostsCollection( $this->_query->posts, $this->_posts_class );
60 62
             return ( $return_collection ) ? $posts : $posts->get_posts();
61 63
         }
@@ -65,8 +67,9 @@  discard block
 block discarded – undo
65 67
     // GET POSTS
66 68
     //
67 69
     public static function get_query_from_array_of_ids( $query = array() ) {
68
-        if ( !is_array( $query ) || !count( $query ) )
69
-            return null;
70
+        if ( !is_array( $query ) || !count( $query ) ) {
71
+                    return null;
72
+        }
70 73
 
71 74
         return new WP_Query( array(
72 75
                 'post_type'=> 'any',
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -145,10 +145,10 @@
 block discarded – undo
145 145
      * @return WP_Query
146 146
      */
147 147
     static function handle_maybe_custom_posts_page( $query ) {
148
-    	if ($custom_posts_page = get_option('page_for_posts')) {
149
-        	if ( isset($query->query['p']) && $query->query['p'] == $custom_posts_page ) {
150
-        		return new WP_Query(array('post_type' => 'post'));
151
-        	}
148
+        if ($custom_posts_page = get_option('page_for_posts')) {
149
+            if ( isset($query->query['p']) && $query->query['p'] == $custom_posts_page ) {
150
+                return new WP_Query(array('post_type' => 'post'));
151
+            }
152 152
         }
153 153
         return $query;
154 154
     }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( !defined( 'ABSPATH' ) )
3
+if ( !defined('ABSPATH') )
4 4
     exit;
5 5
 
6 6
 class TimberQueryIterator implements Iterator {
@@ -14,37 +14,37 @@  discard block
 block discarded – undo
14 14
     private $_posts_class = 'TimberPost';
15 15
 
16 16
     public function __construct( $query = false, $posts_class = 'TimberPost' ) {
17
-        add_action( 'pre_get_posts', array($this, 'fix_number_posts_wp_quirk' ));
17
+        add_action('pre_get_posts', array($this, 'fix_number_posts_wp_quirk'));
18 18
         if ( $posts_class )
19 19
             $this->_posts_class = $posts_class;
20 20
 
21
-        if ( is_a( $query, 'WP_Query' ) ) {
21
+        if ( is_a($query, 'WP_Query') ) {
22 22
             // We got a full-fledged WP Query, look no further!
23 23
             $the_query = $query;
24 24
 
25 25
         } elseif ( false === $query ) {
26 26
             // If query is explicitly set to false, use the main loop
27 27
             global $wp_query;
28
-            $the_query =& $wp_query;
28
+            $the_query = & $wp_query;
29 29
             //if we're on a custom posts page?
30 30
             $the_query = self::handle_maybe_custom_posts_page($the_query);
31
-        } elseif ( TimberHelper::is_array_assoc( $query ) || ( is_string( $query ) && strstr( $query, '=' ) ) ) {
31
+        } elseif ( TimberHelper::is_array_assoc($query) || (is_string($query) && strstr($query, '=')) ) {
32 32
             // We have a regularly formed WP query string or array to use
33
-            $the_query = new WP_Query( $query );
33
+            $the_query = new WP_Query($query);
34 34
 
35
-        } elseif ( is_numeric( $query ) || is_string( $query ) ) {
35
+        } elseif ( is_numeric($query) || is_string($query) ) {
36 36
             // We have what could be a post name or post ID to pull out
37
-            $the_query = self::get_query_from_string( $query );
37
+            $the_query = self::get_query_from_string($query);
38 38
 
39
-        } elseif ( is_array( $query ) && count( $query ) && ( is_integer( $query[0] ) || is_string( $query[0] ) ) ) {
39
+        } elseif ( is_array($query) && count($query) && (is_integer($query[0]) || is_string($query[0])) ) {
40 40
             // We have a list of pids (post IDs) to extract from
41
-            $the_query = self::get_query_from_array_of_ids( $query );
42
-        } elseif ( is_array($query) && empty($query)) {
41
+            $the_query = self::get_query_from_array_of_ids($query);
42
+        } elseif ( is_array($query) && empty($query) ) {
43 43
             // it's an empty array
44 44
             $the_query = array();
45 45
         } else {
46
-            TimberHelper::error_log( 'I have failed you! in ' . basename( __FILE__ ) . '::' . __LINE__ );
47
-            TimberHelper::error_log( $query );
46
+            TimberHelper::error_log('I have failed you! in ' . basename(__FILE__) . '::' . __LINE__);
47
+            TimberHelper::error_log($query);
48 48
 
49 49
             // We have failed hard, at least let get something.
50 50
             $the_query = new WP_Query();
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
     }
56 56
 
57 57
     public function get_posts( $return_collection = false ) {
58
-        if (isset($this->_query->posts)){
59
-            $posts = new TimberPostsCollection( $this->_query->posts, $this->_posts_class );
60
-            return ( $return_collection ) ? $posts : $posts->get_posts();
58
+        if ( isset($this->_query->posts) ) {
59
+            $posts = new TimberPostsCollection($this->_query->posts, $this->_posts_class);
60
+            return ($return_collection) ? $posts : $posts->get_posts();
61 61
         }
62 62
     }
63 63
 
@@ -65,38 +65,38 @@  discard block
 block discarded – undo
65 65
     // GET POSTS
66 66
     //
67 67
     public static function get_query_from_array_of_ids( $query = array() ) {
68
-        if ( !is_array( $query ) || !count( $query ) )
68
+        if ( !is_array($query) || !count($query) )
69 69
             return null;
70 70
 
71
-        return new WP_Query( array(
71
+        return new WP_Query(array(
72 72
                 'post_type'=> 'any',
73 73
                 'ignore_sticky_posts' => true,
74 74
                 'post__in' => $query,
75 75
                 'orderby'  => 'post__in',
76 76
                 'nopaging' => true
77
-            ) );
77
+            ));
78 78
     }
79 79
 
80 80
     public static function get_query_from_string( $string = '' ) {
81 81
         $post_type = false;
82 82
 
83
-        if ( is_string( $string ) && strstr( $string, '#' ) ) {
83
+        if ( is_string($string) && strstr($string, '#') ) {
84 84
             //we have a post_type directive here
85
-            list( $post_type, $string ) = explode( '#', $string );
85
+            list($post_type, $string) = explode('#', $string);
86 86
         }
87 87
 
88 88
         $query = array(
89
-            'post_type' => ( $post_type ) ? $post_type : 'any'
89
+            'post_type' => ($post_type) ? $post_type : 'any'
90 90
         );
91 91
 
92
-        if ( is_numeric( $string ) ) {
92
+        if ( is_numeric($string) ) {
93 93
             $query['p'] = $string;
94 94
 
95 95
         } else {
96 96
             $query['name'] = $string;
97 97
         }
98 98
 
99
-        return new WP_Query( $query );
99
+        return new WP_Query($query);
100 100
     }
101 101
 
102 102
     //
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 
115 115
         // Sets up the global post, but also return the post, for use in Twig template
116 116
         $posts_class = $this->_posts_class;
117
-        return new $posts_class( $post );
117
+        return new $posts_class($post);
118 118
     }
119 119
 
120 120
     /**
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
 
133 133
     //get_posts users numberposts
134 134
     static function fix_number_posts_wp_quirk( $query ) {
135
-        if (isset($query->query) && isset($query->query['numberposts'])
136
-                && !isset($query->query['posts_per_page'])) {
137
-            $query->set( 'posts_per_page', $query->query['numberposts'] );
135
+        if ( isset($query->query) && isset($query->query['numberposts'])
136
+                && !isset($query->query['posts_per_page']) ) {
137
+            $query->set('posts_per_page', $query->query['numberposts']);
138 138
         }
139 139
         return $query;
140 140
     }
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
      * @return WP_Query
146 146
      */
147 147
     static function handle_maybe_custom_posts_page( $query ) {
148
-    	if ($custom_posts_page = get_option('page_for_posts')) {
148
+    	if ( $custom_posts_page = get_option('page_for_posts') ) {
149 149
         	if ( isset($query->query['p']) && $query->query['p'] == $custom_posts_page ) {
150 150
         		return new WP_Query(array('post_type' => 'post'));
151 151
         	}
Please login to merge, or discard this patch.
lib/timber-term.php 3 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@
 block discarded – undo
116 116
 			//echo 'bad call using '.$tid;
117 117
 			//TimberHelper::error_log(debug_backtrace());
118 118
 		}
119
-		if ( isset($term->ID) ){
119
+		if ( isset($term->ID) ) {
120 120
 			$term->id = $term->ID;
121 121
 			$this->import($term);
122 122
 			if ( isset($term->term_id) ) {
Please login to merge, or discard this patch.
Indentation   +387 added lines, -387 removed lines patch added patch discarded remove patch
@@ -32,398 +32,398 @@
 block discarded – undo
32 32
  */
33 33
 class TimberTerm extends TimberCore implements TimberCoreInterface {
34 34
 
35
-	public $PostClass = 'TimberPost';
36
-	public $TermClass = 'TimberTerm';
37
-
38
-	public $object_type = 'term';
39
-	public static $representation = 'term';
40
-
41
-	public $_children;
42
-	/**
43
-	 * @api
44
-	 * @var string the human-friendly name of the term (ex: French Cuisine)
45
-	 */
46
-	public $name;
47
-	/**
48
-	 * @api
49
-	 * @var strng the WordPress taxonomy slug (ex: `post_tag` or `actors`)
50
-	 */
51
-	public $taxonomy;
52
-
53
-	/**
54
-	 * @param int $tid
55
-	 * @param string $tax
56
-	 */
57
-	public function __construct( $tid = null, $tax = '' ) {
58
-		if ($tid === null) {
59
-			$tid = $this->get_term_from_query();
60
-		}
61
-		if (strlen($tax)) {
62
-			$this->taxonomy = $tax;
63
-		}
64
-		$this->init($tid);
65
-	}
66
-
67
-	/**
68
-	 * @return string
69
-	 */
70
-	public function __toString() {
71
-		return $this->name;
72
-	}
73
-
74
-	/**
75
-	 * @param $tid
76
-	 * @param $taxonomy
77
-	 *
78
-	 * @return static
79
-	 */
80
-	public static function from( $tid, $taxonomy ) {
81
-		return new static($tid, $taxonomy);
82
-	}
83
-
84
-
85
-	/* Setup
35
+    public $PostClass = 'TimberPost';
36
+    public $TermClass = 'TimberTerm';
37
+
38
+    public $object_type = 'term';
39
+    public static $representation = 'term';
40
+
41
+    public $_children;
42
+    /**
43
+     * @api
44
+     * @var string the human-friendly name of the term (ex: French Cuisine)
45
+     */
46
+    public $name;
47
+    /**
48
+     * @api
49
+     * @var strng the WordPress taxonomy slug (ex: `post_tag` or `actors`)
50
+     */
51
+    public $taxonomy;
52
+
53
+    /**
54
+     * @param int $tid
55
+     * @param string $tax
56
+     */
57
+    public function __construct( $tid = null, $tax = '' ) {
58
+        if ($tid === null) {
59
+            $tid = $this->get_term_from_query();
60
+        }
61
+        if (strlen($tax)) {
62
+            $this->taxonomy = $tax;
63
+        }
64
+        $this->init($tid);
65
+    }
66
+
67
+    /**
68
+     * @return string
69
+     */
70
+    public function __toString() {
71
+        return $this->name;
72
+    }
73
+
74
+    /**
75
+     * @param $tid
76
+     * @param $taxonomy
77
+     *
78
+     * @return static
79
+     */
80
+    public static function from( $tid, $taxonomy ) {
81
+        return new static($tid, $taxonomy);
82
+    }
83
+
84
+
85
+    /* Setup
86 86
 	===================== */
87 87
 
88
-	/**
89
-	 * @internal
90
-	 * @return integer
91
-	 */
92
-	protected function get_term_from_query() {
93
-		global $wp_query;
94
-		if ( isset($wp_query->queried_object) ) {
95
-			$qo = $wp_query->queried_object;
96
-			if (isset($qo->term_id)) {
97
-				return $qo->term_id;
98
-			}
99
-		}
100
-		if ( isset($wp_query->tax_query->queries[0]['terms'][0]) ) {
101
-			return $wp_query->tax_query->queries[0]['terms'][0];
102
-		}
103
-	}
104
-
105
-	/**
106
-	 * @internal
107
-	 * @param int $tid
108
-	 */
109
-	protected function init( $tid ) {
110
-		$term = $this->get_term($tid);
111
-		if ( isset($term->id) ) {
112
-			$term->ID = $term->id;
113
-		} else if ( isset($term->term_id) ) {
114
-			$term->ID = $term->term_id;
115
-		} else if ( is_string($tid) ) {
116
-			//echo 'bad call using '.$tid;
117
-			//TimberHelper::error_log(debug_backtrace());
118
-		}
119
-		if ( isset($term->ID) ){
120
-			$term->id = $term->ID;
121
-			$this->import($term);
122
-			if ( isset($term->term_id) ) {
123
-				$custom = $this->get_term_meta($term->term_id);
124
-				$this->import($custom);
125
-			}
126
-		}
127
-	}
128
-
129
-	/**
130
-	 * @internal
131
-	 * @param int $tid
132
-	 * @return array
133
-	 */
134
-	protected function get_term_meta($tid) {
135
-		$customs = array();
136
-		$customs = apply_filters('timber_term_get_meta', $customs, $tid, $this);
137
-		return apply_filters('timber/term/meta', $customs, $tid, $this);
138
-	}
139
-
140
-	/**
141
-	 * @internal
142
-	 * @param int $tid
143
-	 * @return mixed
144
-	 */
145
-	protected function get_term( $tid ) {
146
-		if ( is_object($tid) || is_array($tid) ) {
147
-			return $tid;
148
-		}
149
-		$tid = self::get_tid($tid);
150
-
151
-		if ( isset($this->taxonomy) && strlen($this->taxonomy) ) {
152
-			return get_term($tid, $this->taxonomy);
153
-		} else {
154
-			global $wpdb;
155
-			$query = $wpdb->prepare("SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $tid);
156
-			$tax = $wpdb->get_var($query);
157
-			if (isset($tax) && strlen($tax)) {
158
-				$this->taxonomy = $tax;
159
-				return get_term($tid, $tax);
160
-			}
161
-		}
162
-		return null;
163
-	}
164
-
165
-	/**
166
-	 * @internal
167
-	 * @param int $tid
168
-	 * @return int
169
-	 */
170
-	protected function get_tid( $tid ) {
171
-		global $wpdb;
172
-		if ( is_numeric($tid) ) {
173
-			return $tid;
174
-		}
175
-		if ( gettype($tid) == 'object' ) {
176
-			$tid = $tid->term_id;
177
-		}
178
-		if ( is_numeric($tid) ) {
179
-			$query = $wpdb->prepare("SELECT * FROM $wpdb->terms WHERE term_id = %d", $tid);
180
-		} else {
181
-			$query = $wpdb->prepare("SELECT * FROM $wpdb->terms WHERE slug = %s", $tid);
182
-		}
183
-		$result = $wpdb->get_row($query);
184
-		if ( isset($result->term_id) ) {
185
-			$result->ID = $result->term_id;
186
-			$result->id = $result->term_id;
187
-			return $result->ID;
188
-		}
189
-		return 0;
190
-	}
191
-
192
-	/* Public methods
88
+    /**
89
+     * @internal
90
+     * @return integer
91
+     */
92
+    protected function get_term_from_query() {
93
+        global $wp_query;
94
+        if ( isset($wp_query->queried_object) ) {
95
+            $qo = $wp_query->queried_object;
96
+            if (isset($qo->term_id)) {
97
+                return $qo->term_id;
98
+            }
99
+        }
100
+        if ( isset($wp_query->tax_query->queries[0]['terms'][0]) ) {
101
+            return $wp_query->tax_query->queries[0]['terms'][0];
102
+        }
103
+    }
104
+
105
+    /**
106
+     * @internal
107
+     * @param int $tid
108
+     */
109
+    protected function init( $tid ) {
110
+        $term = $this->get_term($tid);
111
+        if ( isset($term->id) ) {
112
+            $term->ID = $term->id;
113
+        } else if ( isset($term->term_id) ) {
114
+            $term->ID = $term->term_id;
115
+        } else if ( is_string($tid) ) {
116
+            //echo 'bad call using '.$tid;
117
+            //TimberHelper::error_log(debug_backtrace());
118
+        }
119
+        if ( isset($term->ID) ){
120
+            $term->id = $term->ID;
121
+            $this->import($term);
122
+            if ( isset($term->term_id) ) {
123
+                $custom = $this->get_term_meta($term->term_id);
124
+                $this->import($custom);
125
+            }
126
+        }
127
+    }
128
+
129
+    /**
130
+     * @internal
131
+     * @param int $tid
132
+     * @return array
133
+     */
134
+    protected function get_term_meta($tid) {
135
+        $customs = array();
136
+        $customs = apply_filters('timber_term_get_meta', $customs, $tid, $this);
137
+        return apply_filters('timber/term/meta', $customs, $tid, $this);
138
+    }
139
+
140
+    /**
141
+     * @internal
142
+     * @param int $tid
143
+     * @return mixed
144
+     */
145
+    protected function get_term( $tid ) {
146
+        if ( is_object($tid) || is_array($tid) ) {
147
+            return $tid;
148
+        }
149
+        $tid = self::get_tid($tid);
150
+
151
+        if ( isset($this->taxonomy) && strlen($this->taxonomy) ) {
152
+            return get_term($tid, $this->taxonomy);
153
+        } else {
154
+            global $wpdb;
155
+            $query = $wpdb->prepare("SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $tid);
156
+            $tax = $wpdb->get_var($query);
157
+            if (isset($tax) && strlen($tax)) {
158
+                $this->taxonomy = $tax;
159
+                return get_term($tid, $tax);
160
+            }
161
+        }
162
+        return null;
163
+    }
164
+
165
+    /**
166
+     * @internal
167
+     * @param int $tid
168
+     * @return int
169
+     */
170
+    protected function get_tid( $tid ) {
171
+        global $wpdb;
172
+        if ( is_numeric($tid) ) {
173
+            return $tid;
174
+        }
175
+        if ( gettype($tid) == 'object' ) {
176
+            $tid = $tid->term_id;
177
+        }
178
+        if ( is_numeric($tid) ) {
179
+            $query = $wpdb->prepare("SELECT * FROM $wpdb->terms WHERE term_id = %d", $tid);
180
+        } else {
181
+            $query = $wpdb->prepare("SELECT * FROM $wpdb->terms WHERE slug = %s", $tid);
182
+        }
183
+        $result = $wpdb->get_row($query);
184
+        if ( isset($result->term_id) ) {
185
+            $result->ID = $result->term_id;
186
+            $result->id = $result->term_id;
187
+            return $result->ID;
188
+        }
189
+        return 0;
190
+    }
191
+
192
+    /* Public methods
193 193
 	===================== */
194 194
 
195
-	/**
196
-	 * @internal
197
-	 * @return string
198
-	 */
199
-	public function get_edit_url() {
200
-		return get_edit_term_link($this->ID, $this->taxonomy);
201
-	}
202
-
203
-	/**
204
-	 * @internal
205
-	 * @param string $field_name
206
-	 * @return string
207
-	 */
208
-	public function get_meta_field( $field_name ) {
209
-		if (!isset($this->$field_name)) {
210
-			$field_value = '';
211
-			$field_value = apply_filters('timber_term_get_meta_field', $field_value, $this->ID, $field_name, $this);
212
-			$field_value = apply_filters('timber/term/meta/field', $field_value, $this->ID, $field_name, $this);
213
-			$this->$field_name = $field_value;
214
-		}
215
-		return $this->$field_name;
216
-	}
217
-
218
-	/**
219
-	 * @internal
220
-	 * @return string
221
-	 */
222
-	public function get_path() {
223
-		$link = $this->get_link();
224
-		$rel = TimberURLHelper::get_rel_url($link, true);
225
-		$rel = apply_filters('timber_term_path', $rel, $this);
226
-		return apply_filters('timber/term/path', $rel, $this);
227
-	}
228
-
229
-	/**
230
-	 * @internal
231
-	 * @return string
232
-	 */
233
-	public function get_link() {
234
-		$link = get_term_link($this);
235
-		$link = apply_filters('timber_term_link', $link, $this);
236
-		return apply_filters('timber/term/link', $link, $this);
237
-	}
238
-
239
-	/**
240
-	 * Get Posts that have been "tagged" with the particular term
241
-	 * @internal
242
-	 * @param int $numberposts
243
-	 * @param string $post_type
244
-	 * @param string $PostClass
245
-	 * @return array|bool|null
246
-	 */
247
-	public function get_posts( $numberposts = 10, $post_type = 'any', $PostClass = '' ) {
248
-		if (!strlen($PostClass)) {
249
-			$PostClass = $this->PostClass;
250
-		}
251
-		$default_tax_query = array(array(
252
-			'field' => 'id',
253
-			'terms' => $this->ID,
254
-			'taxonomy' => $this->taxonomy,
255
-		));
256
-		if ( is_string($numberposts) && strstr($numberposts, '=') ) {
257
-			$args = $numberposts;
258
-			$new_args = array();
259
-			parse_str($args, $new_args);
260
-			$args = $new_args;
261
-			$args['tax_query'] = $default_tax_query;
262
-			if (!isset($args['post_type'])) {
263
-				$args['post_type'] = 'any';
264
-			}
265
-			if (class_exists($post_type)) {
266
-				$PostClass = $post_type;
267
-			}
268
-		} else if ( is_array($numberposts) ) {
269
-			//they sent us an array already baked
270
-			$args = $numberposts;
271
-			if ( !isset($args['tax_query']) ) {
272
-				$args['tax_query'] = $default_tax_query;
273
-			}
274
-			if ( class_exists($post_type) ) {
275
-				$PostClass = $post_type;
276
-			}
277
-			if ( !isset($args['post_type']) ) {
278
-				$args['post_type'] = 'any';
279
-			}
280
-		} else {
281
-			$args = array(
282
-				'numberposts' => $numberposts,
283
-				'tax_query' => $default_tax_query,
284
-				'post_type' => $post_type
285
-			);
286
-		}
287
-		return Timber::get_posts($args, $PostClass);
288
-	}
289
-
290
-	/**
291
-	 * @internal
292
-	 * @return array
293
-	 */
294
-	public function get_children() {
295
-		if ( !isset($this->_children) ) {
296
-			$children = get_term_children($this->ID, $this->taxonomy);
297
-			foreach ($children as &$child) {
298
-				$child = new TimberTerm($child);
299
-			}
300
-			$this->_children = $children;
301
-		}
302
-		return $this->_children;
303
-	}
304
-
305
-	/**
306
-	 *
307
-	 *
308
-	 * @param string  $key
309
-	 * @param mixed   $value
310
-	 */
311
-	function update( $key, $value ) {
312
-		$value = apply_filters( 'timber_term_set_meta', $value, $key, $this->ID, $this );
313
-		$this->$key = $value;
314
-	}
315
-
316
-	/* Alias
195
+    /**
196
+     * @internal
197
+     * @return string
198
+     */
199
+    public function get_edit_url() {
200
+        return get_edit_term_link($this->ID, $this->taxonomy);
201
+    }
202
+
203
+    /**
204
+     * @internal
205
+     * @param string $field_name
206
+     * @return string
207
+     */
208
+    public function get_meta_field( $field_name ) {
209
+        if (!isset($this->$field_name)) {
210
+            $field_value = '';
211
+            $field_value = apply_filters('timber_term_get_meta_field', $field_value, $this->ID, $field_name, $this);
212
+            $field_value = apply_filters('timber/term/meta/field', $field_value, $this->ID, $field_name, $this);
213
+            $this->$field_name = $field_value;
214
+        }
215
+        return $this->$field_name;
216
+    }
217
+
218
+    /**
219
+     * @internal
220
+     * @return string
221
+     */
222
+    public function get_path() {
223
+        $link = $this->get_link();
224
+        $rel = TimberURLHelper::get_rel_url($link, true);
225
+        $rel = apply_filters('timber_term_path', $rel, $this);
226
+        return apply_filters('timber/term/path', $rel, $this);
227
+    }
228
+
229
+    /**
230
+     * @internal
231
+     * @return string
232
+     */
233
+    public function get_link() {
234
+        $link = get_term_link($this);
235
+        $link = apply_filters('timber_term_link', $link, $this);
236
+        return apply_filters('timber/term/link', $link, $this);
237
+    }
238
+
239
+    /**
240
+     * Get Posts that have been "tagged" with the particular term
241
+     * @internal
242
+     * @param int $numberposts
243
+     * @param string $post_type
244
+     * @param string $PostClass
245
+     * @return array|bool|null
246
+     */
247
+    public function get_posts( $numberposts = 10, $post_type = 'any', $PostClass = '' ) {
248
+        if (!strlen($PostClass)) {
249
+            $PostClass = $this->PostClass;
250
+        }
251
+        $default_tax_query = array(array(
252
+            'field' => 'id',
253
+            'terms' => $this->ID,
254
+            'taxonomy' => $this->taxonomy,
255
+        ));
256
+        if ( is_string($numberposts) && strstr($numberposts, '=') ) {
257
+            $args = $numberposts;
258
+            $new_args = array();
259
+            parse_str($args, $new_args);
260
+            $args = $new_args;
261
+            $args['tax_query'] = $default_tax_query;
262
+            if (!isset($args['post_type'])) {
263
+                $args['post_type'] = 'any';
264
+            }
265
+            if (class_exists($post_type)) {
266
+                $PostClass = $post_type;
267
+            }
268
+        } else if ( is_array($numberposts) ) {
269
+            //they sent us an array already baked
270
+            $args = $numberposts;
271
+            if ( !isset($args['tax_query']) ) {
272
+                $args['tax_query'] = $default_tax_query;
273
+            }
274
+            if ( class_exists($post_type) ) {
275
+                $PostClass = $post_type;
276
+            }
277
+            if ( !isset($args['post_type']) ) {
278
+                $args['post_type'] = 'any';
279
+            }
280
+        } else {
281
+            $args = array(
282
+                'numberposts' => $numberposts,
283
+                'tax_query' => $default_tax_query,
284
+                'post_type' => $post_type
285
+            );
286
+        }
287
+        return Timber::get_posts($args, $PostClass);
288
+    }
289
+
290
+    /**
291
+     * @internal
292
+     * @return array
293
+     */
294
+    public function get_children() {
295
+        if ( !isset($this->_children) ) {
296
+            $children = get_term_children($this->ID, $this->taxonomy);
297
+            foreach ($children as &$child) {
298
+                $child = new TimberTerm($child);
299
+            }
300
+            $this->_children = $children;
301
+        }
302
+        return $this->_children;
303
+    }
304
+
305
+    /**
306
+     *
307
+     *
308
+     * @param string  $key
309
+     * @param mixed   $value
310
+     */
311
+    function update( $key, $value ) {
312
+        $value = apply_filters( 'timber_term_set_meta', $value, $key, $this->ID, $this );
313
+        $this->$key = $value;
314
+    }
315
+
316
+    /* Alias
317 317
 	====================== */
318 318
 
319
-	/**
320
-	 * @api
321
-	 * @return array
322
-	 */
323
-	public function children() {
324
-		return $this->get_children();
325
-	}
326
-
327
-	/**
328
-	 * @api
329
-	 * @return string
330
-	 */
331
-	public function description() {
332
-		$prefix = '<p>';
333
-		$suffix = '</p>';
334
-		$desc = term_description( $this->ID, $this->taxonomy );
335
-		if (substr($desc, 0, strlen($prefix)) == $prefix) {
336
-    		$desc = substr($desc, strlen($prefix));
337
-		}
338
-		$desc = preg_replace('/'. preg_quote('</p>', '/') . '$/', '', $desc);
339
-		return trim($desc);
340
-	}
341
-
342
-	/**
343
-	 * @api
344
-	 * @return string
345
-	 */
346
-	public function edit_link() {
347
-		return $this->get_edit_url();
348
-	}
349
-
350
-	/**
351
-	 * @internal
352
-	 * @deprecated 0.21.8 use TimberTerm::link() instead
353
-	 * @return string
354
-	 */
355
-	public function get_url() {
356
-		return $this->get_link();
357
-	}
358
-
359
-	/**
360
-	 * @api
361
-	 * @return string
362
-	 */
363
-	public function link() {
364
-		return $this->get_link();
365
-	}
366
-
367
-	/**
368
-	 * @api
369
-	 * @param string $field_name
370
-	 * @return string
371
-	 */
372
-	public function meta( $field_name ) {
373
-		return $this->get_meta_field($field_name);
374
-	}
375
-
376
-	/**
377
-	 * @api
378
-	 * @return string
379
-	 */
380
-	public function path() {
381
-		return $this->get_path();
382
-	}
383
-
384
-	/**
385
-	 * @api
386
-	 * @param int $numberposts_or_args
387
-	 * @param string $post_type_or_class
388
-	 * @param string $post_class
389
-	 * @example
390
-	 * ```twig
391
-	 * <h4>Recent posts in {{term.name}}</h4>
392
-	 * <ul>
393
-	 * {% for post in term.posts(3, 'post') %}
394
-	 *     <li><a href="{{post.link}}">{{post.title}}</a></li>
395
-	 * {% endfor %}
396
-	 * </ul>
397
-	 * ```
398
-	 * @return array|bool|null
399
-	 */
400
-	public function posts( $numberposts_or_args = 10, $post_type_or_class = 'any', $post_class = '' ) {
401
-		return $this->get_posts($numberposts_or_args, $post_type_or_class, $post_class);
402
-	}
403
-
404
-	/**
405
-	 * @api
406
-	 * @return string
407
-	 */
408
-	public function title() {
409
-		return $this->name;
410
-	}
411
-
412
-	/**
413
-	 * @deprecated 0.21.9 use TimberTerm::link() instead
414
-	 * @return string
415
-	 */
416
-	public function url() {
417
-		return $this->get_url();
418
-	}
419
-
420
-	/**
421
-	 * @deprecated 0.20.0 this was a dumb idea
422
-	 * @param int $i
423
-	 * @return string
424
-	 */
425
-	function get_page( $i ) {
426
-		return $this->get_path() . '/page/' . $i;
427
-	}
319
+    /**
320
+     * @api
321
+     * @return array
322
+     */
323
+    public function children() {
324
+        return $this->get_children();
325
+    }
326
+
327
+    /**
328
+     * @api
329
+     * @return string
330
+     */
331
+    public function description() {
332
+        $prefix = '<p>';
333
+        $suffix = '</p>';
334
+        $desc = term_description( $this->ID, $this->taxonomy );
335
+        if (substr($desc, 0, strlen($prefix)) == $prefix) {
336
+            $desc = substr($desc, strlen($prefix));
337
+        }
338
+        $desc = preg_replace('/'. preg_quote('</p>', '/') . '$/', '', $desc);
339
+        return trim($desc);
340
+    }
341
+
342
+    /**
343
+     * @api
344
+     * @return string
345
+     */
346
+    public function edit_link() {
347
+        return $this->get_edit_url();
348
+    }
349
+
350
+    /**
351
+     * @internal
352
+     * @deprecated 0.21.8 use TimberTerm::link() instead
353
+     * @return string
354
+     */
355
+    public function get_url() {
356
+        return $this->get_link();
357
+    }
358
+
359
+    /**
360
+     * @api
361
+     * @return string
362
+     */
363
+    public function link() {
364
+        return $this->get_link();
365
+    }
366
+
367
+    /**
368
+     * @api
369
+     * @param string $field_name
370
+     * @return string
371
+     */
372
+    public function meta( $field_name ) {
373
+        return $this->get_meta_field($field_name);
374
+    }
375
+
376
+    /**
377
+     * @api
378
+     * @return string
379
+     */
380
+    public function path() {
381
+        return $this->get_path();
382
+    }
383
+
384
+    /**
385
+     * @api
386
+     * @param int $numberposts_or_args
387
+     * @param string $post_type_or_class
388
+     * @param string $post_class
389
+     * @example
390
+     * ```twig
391
+     * <h4>Recent posts in {{term.name}}</h4>
392
+     * <ul>
393
+     * {% for post in term.posts(3, 'post') %}
394
+     *     <li><a href="{{post.link}}">{{post.title}}</a></li>
395
+     * {% endfor %}
396
+     * </ul>
397
+     * ```
398
+     * @return array|bool|null
399
+     */
400
+    public function posts( $numberposts_or_args = 10, $post_type_or_class = 'any', $post_class = '' ) {
401
+        return $this->get_posts($numberposts_or_args, $post_type_or_class, $post_class);
402
+    }
403
+
404
+    /**
405
+     * @api
406
+     * @return string
407
+     */
408
+    public function title() {
409
+        return $this->name;
410
+    }
411
+
412
+    /**
413
+     * @deprecated 0.21.9 use TimberTerm::link() instead
414
+     * @return string
415
+     */
416
+    public function url() {
417
+        return $this->get_url();
418
+    }
419
+
420
+    /**
421
+     * @deprecated 0.20.0 this was a dumb idea
422
+     * @param int $i
423
+     * @return string
424
+     */
425
+    function get_page( $i ) {
426
+        return $this->get_path() . '/page/' . $i;
427
+    }
428 428
 
429 429
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
 	 * @param string $tax
56 56
 	 */
57 57
 	public function __construct( $tid = null, $tax = '' ) {
58
-		if ($tid === null) {
58
+		if ( $tid === null ) {
59 59
 			$tid = $this->get_term_from_query();
60 60
 		}
61
-		if (strlen($tax)) {
61
+		if ( strlen($tax) ) {
62 62
 			$this->taxonomy = $tax;
63 63
 		}
64 64
 		$this->init($tid);
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		global $wp_query;
94 94
 		if ( isset($wp_query->queried_object) ) {
95 95
 			$qo = $wp_query->queried_object;
96
-			if (isset($qo->term_id)) {
96
+			if ( isset($qo->term_id) ) {
97 97
 				return $qo->term_id;
98 98
 			}
99 99
 		}
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 			//echo 'bad call using '.$tid;
117 117
 			//TimberHelper::error_log(debug_backtrace());
118 118
 		}
119
-		if ( isset($term->ID) ){
119
+		if ( isset($term->ID) ) {
120 120
 			$term->id = $term->ID;
121 121
 			$this->import($term);
122 122
 			if ( isset($term->term_id) ) {
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 	 * @param int $tid
132 132
 	 * @return array
133 133
 	 */
134
-	protected function get_term_meta($tid) {
134
+	protected function get_term_meta( $tid ) {
135 135
 		$customs = array();
136 136
 		$customs = apply_filters('timber_term_get_meta', $customs, $tid, $this);
137 137
 		return apply_filters('timber/term/meta', $customs, $tid, $this);
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 			global $wpdb;
155 155
 			$query = $wpdb->prepare("SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $tid);
156 156
 			$tax = $wpdb->get_var($query);
157
-			if (isset($tax) && strlen($tax)) {
157
+			if ( isset($tax) && strlen($tax) ) {
158 158
 				$this->taxonomy = $tax;
159 159
 				return get_term($tid, $tax);
160 160
 			}
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 	 * @return string
207 207
 	 */
208 208
 	public function get_meta_field( $field_name ) {
209
-		if (!isset($this->$field_name)) {
209
+		if ( !isset($this->$field_name) ) {
210 210
 			$field_value = '';
211 211
 			$field_value = apply_filters('timber_term_get_meta_field', $field_value, $this->ID, $field_name, $this);
212 212
 			$field_value = apply_filters('timber/term/meta/field', $field_value, $this->ID, $field_name, $this);
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 * @return array|bool|null
246 246
 	 */
247 247
 	public function get_posts( $numberposts = 10, $post_type = 'any', $PostClass = '' ) {
248
-		if (!strlen($PostClass)) {
248
+		if ( !strlen($PostClass) ) {
249 249
 			$PostClass = $this->PostClass;
250 250
 		}
251 251
 		$default_tax_query = array(array(
@@ -259,10 +259,10 @@  discard block
 block discarded – undo
259 259
 			parse_str($args, $new_args);
260 260
 			$args = $new_args;
261 261
 			$args['tax_query'] = $default_tax_query;
262
-			if (!isset($args['post_type'])) {
262
+			if ( !isset($args['post_type']) ) {
263 263
 				$args['post_type'] = 'any';
264 264
 			}
265
-			if (class_exists($post_type)) {
265
+			if ( class_exists($post_type) ) {
266 266
 				$PostClass = $post_type;
267 267
 			}
268 268
 		} else if ( is_array($numberposts) ) {
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 	public function get_children() {
295 295
 		if ( !isset($this->_children) ) {
296 296
 			$children = get_term_children($this->ID, $this->taxonomy);
297
-			foreach ($children as &$child) {
297
+			foreach ( $children as &$child ) {
298 298
 				$child = new TimberTerm($child);
299 299
 			}
300 300
 			$this->_children = $children;
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	 * @param mixed   $value
310 310
 	 */
311 311
 	function update( $key, $value ) {
312
-		$value = apply_filters( 'timber_term_set_meta', $value, $key, $this->ID, $this );
312
+		$value = apply_filters('timber_term_set_meta', $value, $key, $this->ID, $this);
313 313
 		$this->$key = $value;
314 314
 	}
315 315
 
@@ -331,11 +331,11 @@  discard block
 block discarded – undo
331 331
 	public function description() {
332 332
 		$prefix = '<p>';
333 333
 		$suffix = '</p>';
334
-		$desc = term_description( $this->ID, $this->taxonomy );
335
-		if (substr($desc, 0, strlen($prefix)) == $prefix) {
334
+		$desc = term_description($this->ID, $this->taxonomy);
335
+		if ( substr($desc, 0, strlen($prefix)) == $prefix ) {
336 336
     		$desc = substr($desc, strlen($prefix));
337 337
 		}
338
-		$desc = preg_replace('/'. preg_quote('</p>', '/') . '$/', '', $desc);
338
+		$desc = preg_replace('/' . preg_quote('</p>', '/') . '$/', '', $desc);
339 339
 		return trim($desc);
340 340
 	}
341 341
 
Please login to merge, or discard this patch.