Timber - Version 0.17.2

Version Description

  • TimberPost::children() now sorts by menu_order, title as WordPress core does (thanks @aduth)
  • Fixed an occaisonal warning (thanks @matthewsoares)
  • TimberImage::alt() now returns your image's alt tag info from WordPress (thanks @jnweaver)
  • In the router, non-404 headers are forced asap (thanks @mgmartel)
  • Router now accepts + signs in paths
Download this release

Release Info

Developer jarednova
Plugin Icon 128x128 Timber
Version 0.17.2
Comparing to
See all releases

Code changes from version 0.17.1 to 0.17.2

functions/router/Route.php CHANGED
@@ -85,10 +85,9 @@ class Route {
85
 
86
  private function substituteFilter($matches) {
87
  if (isset($matches[1]) && isset($this->filters[$matches[1]])) {
88
- return $this->filters[$matches[1]];
89
- }
90
-
91
- return "([\w-]+)";
92
  }
93
 
94
  public function getParameters() {
85
 
86
  private function substituteFilter($matches) {
87
  if (isset($matches[1]) && isset($this->filters[$matches[1]])) {
88
+ return $this->filters[$matches[1]];
89
+ }
90
+ return "([\w-+]+)";
 
91
  }
92
 
93
  public function getParameters() {
functions/timber-helper.php CHANGED
@@ -199,30 +199,10 @@ class TimberHelper {
199
  return $newargs;
200
  }
201
 
202
- public static function get_json($url) {
203
- $data = self::get_curl($url);
204
- return json_decode($data);
205
- }
206
-
207
- public static function get_curl($url) {
208
- $ch = curl_init();
209
- curl_setopt($ch, CURLOPT_URL, $url);
210
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
211
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
212
- $content = curl_exec($ch);
213
- curl_close($ch);
214
- return $content;
215
- }
216
-
217
  public static function get_wp_title() {
218
  return wp_title('|', false, 'right');
219
  }
220
 
221
- public static function force_update_option($option, $value) {
222
- global $wpdb;
223
- $wpdb->query("UPDATE $wpdb->options SET option_value = '$value' WHERE option_name = '$option'");
224
- }
225
-
226
  public static function get_current_url() {
227
  $pageURL = "http://";
228
  if (isset($_SERVER['HTTPS']) && $_SERVER["HTTPS"] == "on"){
@@ -478,7 +458,7 @@ class TimberHelper {
478
  for ( $n = 1; $n <= $total; $n++ ) {
479
  $n_display = number_format_i18n($n);
480
  if ( $n == $current ) {
481
- $page_links[] = array('class' => 'page-number page-numbers current', 'title' => $n_display, 'text' => $n_display, 'name' => $n_display);
482
  $dots = true;
483
  } else {
484
  if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) {
@@ -488,7 +468,7 @@ class TimberHelper {
488
  if ( $add_args ) {
489
  $link = rtrim(add_query_arg( $add_args, $link ), '/');
490
  }
491
- $page_links[] = array('class' => 'page-number page-numbers', 'link' => esc_url( apply_filters( 'paginate_links', $link ) ), 'title' => $n_display);
492
  $dots = true;
493
  } elseif ( $dots && !$show_all ) {
494
  $page_links[] = array('class' => 'dots', 'title' => __( '&hellip;' ));
199
  return $newargs;
200
  }
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  public static function get_wp_title() {
203
  return wp_title('|', false, 'right');
204
  }
205
 
 
 
 
 
 
206
  public static function get_current_url() {
207
  $pageURL = "http://";
208
  if (isset($_SERVER['HTTPS']) && $_SERVER["HTTPS"] == "on"){
458
  for ( $n = 1; $n <= $total; $n++ ) {
459
  $n_display = number_format_i18n($n);
460
  if ( $n == $current ) {
461
+ $page_links[] = array('class' => 'page-number page-numbers current', 'title' => $n_display, 'text' => $n_display, 'name' => $n_display, 'current' => true);
462
  $dots = true;
463
  } else {
464
  if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) {
468
  if ( $add_args ) {
469
  $link = rtrim(add_query_arg( $add_args, $link ), '/');
470
  }
471
+ $page_links[] = array('class' => 'page-number page-numbers', 'link' => esc_url( apply_filters( 'paginate_links', $link ) ), 'title' => $n_display, 'current' => $current == $n);
472
  $dots = true;
473
  } elseif ( $dots && !$show_all ) {
474
  $page_links[] = array('class' => 'dots', 'title' => __( '&hellip;' ));
functions/timber-image-helper.php CHANGED
@@ -115,7 +115,6 @@
115
  $old_root_path = WP_CONTENT_DIR . str_replace(content_url(), '', $src);
116
  $old_root_path = str_replace('//', '/', $old_root_path);
117
  $new_root_path = str_replace('//', '/', $new_root_path);
118
- error_log('make me an image');
119
  if ( file_exists($new_root_path) ) {
120
  if ( $force_resize ) {
121
  // Force resize - warning: will regenerate the image on every pageload, use for testing purposes only!
115
  $old_root_path = WP_CONTENT_DIR . str_replace(content_url(), '', $src);
116
  $old_root_path = str_replace('//', '/', $old_root_path);
117
  $new_root_path = str_replace('//', '/', $new_root_path);
 
118
  if ( file_exists($new_root_path) ) {
119
  if ( $force_resize ) {
120
  // Force resize - warning: will regenerate the image on every pageload, use for testing purposes only!
functions/timber-image.php CHANGED
@@ -93,6 +93,11 @@ class TimberImage extends TimberCore {
93
  return new $this->PostClass($this->post_parent);
94
  }
95
 
 
 
 
 
 
96
  function init($iid) {
97
  if (!is_numeric($iid) && is_string($iid)) {
98
  if (strstr($iid, '://')) {
@@ -183,4 +188,8 @@ class TimberImage extends TimberCore {
183
  public function width(){
184
  return $this->get_width();
185
  }
 
 
 
 
186
  }
93
  return new $this->PostClass($this->post_parent);
94
  }
95
 
96
+ function get_alt() {
97
+ $alt = trim(strip_tags(get_post_meta($this->ID, '_wp_attachment_image_alt', true)));
98
+ return $alt;
99
+ }
100
+
101
  function init($iid) {
102
  if (!is_numeric($iid) && is_string($iid)) {
103
  if (strstr($iid, '://')) {
188
  public function width(){
189
  return $this->get_width();
190
  }
191
+
192
+ public function alt(){
193
+ return $this->get_alt();
194
+ }
195
  }
functions/timber-menu.php CHANGED
@@ -144,6 +144,7 @@ class TimberMenuItem extends TimberCore {
144
  function add_child($item) {
145
  if (!$this->has_child_class){
146
  $this->add_class('menu-item-has-children');
 
147
  }
148
  if (!isset($this->children)) {
149
  $this->children = array();
@@ -194,4 +195,4 @@ class TimberMenuItem extends TimberCore {
194
  public function get_permalink(){
195
  return $this->get_link();
196
  }
197
- }
144
  function add_child($item) {
145
  if (!$this->has_child_class){
146
  $this->add_class('menu-item-has-children');
147
+ $this->has_child_class = true;
148
  }
149
  if (!isset($this->children)) {
150
  $this->children = array();
195
  public function get_permalink(){
196
  return $this->get_link();
197
  }
198
+ }
functions/timber-post.php CHANGED
@@ -125,6 +125,9 @@ class TimberPost extends TimberCore {
125
  global $wpdb;
126
  $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s LIMIT 1", $post_name);
127
  $result = $wpdb->get_row($query);
 
 
 
128
  return $result->ID;
129
  }
130
 
@@ -365,7 +368,7 @@ class TimberPost extends TimberCore {
365
  if ($post_type == 'parent') {
366
  $post_type = $this->post_type;
367
  }
368
- $children = get_children('post_parent=' . $this->ID . '&post_type=' . $post_type);
369
  foreach ($children as &$child) {
370
  $child = new $childPostClass($child->ID);
371
  }
125
  global $wpdb;
126
  $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s LIMIT 1", $post_name);
127
  $result = $wpdb->get_row($query);
128
+ if (!$result) {
129
+ return null;
130
+ }
131
  return $result->ID;
132
  }
133
 
368
  if ($post_type == 'parent') {
369
  $post_type = $this->post_type;
370
  }
371
+ $children = get_children('post_parent=' . $this->ID . '&post_type=' . $post_type . '&numberposts=-1&orderby=menu_order title&order=ASC');
372
  foreach ($children as &$child) {
373
  $child = new $childPostClass($child->ID);
374
  }
functions/timber-site.php CHANGED
@@ -22,6 +22,7 @@
22
  $this->ID = $info->blog_id;
23
  $this->name = $this->blogname;
24
  $this->title = $this->blogname;
 
25
  $theme_slug = get_blog_option($info->blog_id, 'stylesheet');
26
  $this->theme = new TimberTheme($theme_slug);
27
  $this->description = get_blog_option($info->blog_id, 'blogdescription');
22
  $this->ID = $info->blog_id;
23
  $this->name = $this->blogname;
24
  $this->title = $this->blogname;
25
+ $this->url = $this->siteurl;
26
  $theme_slug = get_blog_option($info->blog_id, 'stylesheet');
27
  $this->theme = new TimberTheme($theme_slug);
28
  $this->description = get_blog_option($info->blog_id, 'blogdescription');
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
  === Timber ===
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
- Requires at least: 3.5
5
- Stable tag: 0.17.1
6
  Tested up to: 3.8.1
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
@@ -41,6 +41,13 @@ Timber is great for any WordPress developer who cares about writing good, mainta
41
 
42
  == Changelog ==
43
 
 
 
 
 
 
 
 
44
  = 0.17.1 =
45
  * Hotfix on timber-admin error
46
 
1
  === Timber ===
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
+ Requires at least: 3.7
5
+ Stable tag: 0.17.2
6
  Tested up to: 3.8.1
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
41
 
42
  == Changelog ==
43
 
44
+ = 0.17.2 =
45
+ * TimberPost::children() now sorts by menu_order, title as WordPress core does (thanks @aduth)
46
+ * Fixed an occaisonal warning (thanks @matthewsoares)
47
+ * TimberImage::alt() now returns your image's alt tag info from WordPress (thanks @jnweaver)
48
+ * In the router, non-404 headers are forced asap (thanks @mgmartel)
49
+ * Router now accepts + signs in paths
50
+
51
  = 0.17.1 =
52
  * Hotfix on timber-admin error
53
 
timber.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Timber
4
  Plugin URI: http://timber.upstatement.com
5
  Description: The WordPress Timber Library allows you to write themes using the power Twig templates
6
  Author: Jared Novack + Upstatement
7
- Version: 0.17.1
8
  Author URI: http://upstatement.com/
9
  */
10
 
@@ -115,19 +115,19 @@ class Timber {
115
  }
116
  if (TimberHelper::is_array_assoc($query) || (is_string($query) && strstr($query, '='))) {
117
  // we have a regularly formed WP query string or array to use
118
- return self::get_posts_from_wp_query($query, $PostClass);
119
  } else if (is_string($query) && !is_integer($query)) {
120
  // we have what could be a post name to pull out
121
- return self::get_posts_from_slug($query, $PostClass);
122
  } else if (is_array($query) && count($query) && (is_integer($query[0]) || is_string($query[0]))) {
123
  // we have a list of pids (post IDs) to extract from
124
- return self::get_posts_from_array_of_ids($query, $PostClass);
125
  } else if (is_array($query) && count($query) && isset($query[0]) && is_object($query[0])) {
126
  // maybe its an array of post objects that already have data
127
- return self::handle_post_results($query, $PostClass);
128
  } else if (have_posts()) {
129
  //lets just use the default WordPress current query
130
- return self::get_posts_from_loop($PostClass);
131
  } else if (!$query) {
132
  //okay, everything failed lets just return some posts so that the user has something to work with
133
  //this turns out to cause all kinds of awful behavior
@@ -136,8 +136,10 @@ class Timber {
136
  } else {
137
  TimberHelper::error_log('I have failed you! in timber.php::94');
138
  TimberHelper::error_log($query);
 
139
  }
140
- return $query;
 
141
  }
142
 
143
  public static function get_pids($query = null) {
@@ -236,6 +238,41 @@ class Timber {
236
  return $post->ID;
237
  }
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
 
240
  /* Deprecated
241
  ================================ */
@@ -489,11 +526,11 @@ class Timber {
489
  if ($query->is_main_query()){
490
  $query->is_404 = false;
491
  }
492
- });
493
  add_action('template_redirect', function(){
494
  global $wp_query;
495
  $wp_query->is_404 = false;
496
- });
497
  }
498
  }
499
 
4
  Plugin URI: http://timber.upstatement.com
5
  Description: The WordPress Timber Library allows you to write themes using the power Twig templates
6
  Author: Jared Novack + Upstatement
7
+ Version: 0.17.2
8
  Author URI: http://upstatement.com/
9
  */
10
 
115
  }
116
  if (TimberHelper::is_array_assoc($query) || (is_string($query) && strstr($query, '='))) {
117
  // we have a regularly formed WP query string or array to use
118
+ $posts = self::get_posts_from_wp_query($query, $PostClass);
119
  } else if (is_string($query) && !is_integer($query)) {
120
  // we have what could be a post name to pull out
121
+ $posts = self::get_posts_from_slug($query, $PostClass);
122
  } else if (is_array($query) && count($query) && (is_integer($query[0]) || is_string($query[0]))) {
123
  // we have a list of pids (post IDs) to extract from
124
+ $posts = self::get_posts_from_array_of_ids($query, $PostClass);
125
  } else if (is_array($query) && count($query) && isset($query[0]) && is_object($query[0])) {
126
  // maybe its an array of post objects that already have data
127
+ $posts = self::handle_post_results($query, $PostClass);
128
  } else if (have_posts()) {
129
  //lets just use the default WordPress current query
130
+ $posts = self::get_posts_from_loop($PostClass);
131
  } else if (!$query) {
132
  //okay, everything failed lets just return some posts so that the user has something to work with
133
  //this turns out to cause all kinds of awful behavior
136
  } else {
137
  TimberHelper::error_log('I have failed you! in timber.php::94');
138
  TimberHelper::error_log($query);
139
+ return $query;
140
  }
141
+
142
+ return self::maybe_set_preview( $posts );
143
  }
144
 
145
  public static function get_pids($query = null) {
238
  return $post->ID;
239
  }
240
 
241
+ /* Post Previews
242
+ ================================ */
243
+
244
+ public static function maybe_set_preview( $posts ) {
245
+ if ( is_array( $posts ) && isset( $_GET['preview'] ) && $_GET['preview']
246
+ && isset( $_GET['preview_id'] ) && $_GET['preview_id']
247
+ && current_user_can( 'edit_post', $_GET['preview_id'] ) ) {
248
+
249
+ // No need to check the nonce, that already happened in _show_post_preview on init
250
+
251
+ $preview_id = $_GET['preview_id'];
252
+ foreach( $posts as &$post ) {
253
+ if ( is_object( $post ) && $post->ID == $preview_id ) {
254
+ // Based on _set_preview( $post ), but adds import_custom
255
+ $preview = wp_get_post_autosave( $preview_id );
256
+
257
+ if ( is_object($preview) ) {
258
+
259
+ $preview = sanitize_post($preview);
260
+
261
+ $post->post_content = $preview->post_content;
262
+ $post->post_title = $preview->post_title;
263
+ $post->post_excerpt = $preview->post_excerpt;
264
+ $post->import_custom( $preview_id );
265
+
266
+ add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
267
+ }
268
+ }
269
+ }
270
+
271
+ }
272
+
273
+ return $posts;
274
+ }
275
+
276
 
277
  /* Deprecated
278
  ================================ */
526
  if ($query->is_main_query()){
527
  $query->is_404 = false;
528
  }
529
+ },1);
530
  add_action('template_redirect', function(){
531
  global $wp_query;
532
  $wp_query->is_404 = false;
533
+ },1);
534
  }
535
  }
536