Timber - Version 0.16.8

Version Description

  • You can now retrieve prev/next posts within the same category (post.next('category').title, etc.). (thanks @slimndap)
  • Fixed issue with letterboxing images when WP is installed in a subdirectory ( @wesrice)
  • Fix for images stored inside custom content path (@mmikkel)
  • Cleaned-up some things in Timber Starter theme (@southernfriedbb, @jarednova)
Download this release

Release Info

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

Code changes from version 0.16.7 to 0.16.8

functions/functions-twig.php CHANGED
@@ -166,9 +166,15 @@ function hexrgb($hexstr) {
166
 
167
  function wp_resize_letterbox($src, $w, $h, $color = '#000000') {
168
  //$old_file = TimberHelper::get_full_path($src);
 
169
  $urlinfo = parse_url($src);
 
 
 
 
170
  $old_file = ABSPATH.$urlinfo['path'];
171
  $new_file = TimberImageHelper::get_letterbox_file_path($urlinfo['path'], $w, $h);
 
172
  $new_file_rel = TimberImageHelper::get_letterbox_file_rel($urlinfo['path'], $w, $h);
173
  $new_file_boxed = str_replace('-lb-', '-lbox-', $new_file);
174
  if (file_exists($new_file_boxed)) {
166
 
167
  function wp_resize_letterbox($src, $w, $h, $color = '#000000') {
168
  //$old_file = TimberHelper::get_full_path($src);
169
+ $abspath = substr(ABSPATH, 0, -1);
170
  $urlinfo = parse_url($src);
171
+ if( $_SERVER['DOCUMENT_ROOT'] != $abspath ) {
172
+ $subdir = str_replace($_SERVER['DOCUMENT_ROOT'].'/', '', $abspath);
173
+ $urlinfo['path'] = str_replace('/'.$subdir.'/', '', $urlinfo['path']);
174
+ }
175
  $old_file = ABSPATH.$urlinfo['path'];
176
  $new_file = TimberImageHelper::get_letterbox_file_path($urlinfo['path'], $w, $h);
177
+ $urlinfo = parse_url($src);
178
  $new_file_rel = TimberImageHelper::get_letterbox_file_rel($urlinfo['path'], $w, $h);
179
  $new_file_boxed = str_replace('-lb-', '-lbox-', $new_file);
180
  if (file_exists($new_file_boxed)) {
functions/timber-helper.php CHANGED
@@ -484,10 +484,10 @@ class TimberHelper {
484
  if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) {
485
  $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
486
  $link = str_replace('%#%', $n, $link);
 
487
  if ( $add_args ) {
488
- $link = add_query_arg( $add_args, $link );
489
  }
490
- $link = trailingslashit($link).ltrim($add_fragment, '/');
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 ) {
484
  if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) {
485
  $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
486
  $link = str_replace('%#%', $n, $link);
487
+ $link = trailingslashit($link).ltrim($add_fragment, '/');
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 ) {
functions/timber-image-helper.php CHANGED
@@ -91,7 +91,7 @@
91
  if (empty($src)){
92
  return '';
93
  }
94
- if (strstr($src, 'http') && !strstr($src, home_url())) {
95
  $src = self::sideload_image($src);
96
  }
97
  $abs = false;
@@ -105,14 +105,14 @@
105
  $dir = $path_parts['dirname'];
106
  $newbase = $basename . '-r-' . $w . 'x' . $h;
107
  $new_path = $dir . '/' . $newbase . '.' . $ext;
108
- $new_path = str_replace(site_url(), '', $new_path);
109
- $new_root_path = ABSPATH . $new_path;
110
- $old_root_path = ABSPATH . str_replace(site_url(), '', $src);
111
  $old_root_path = str_replace('//', '/', $old_root_path);
112
  $new_root_path = str_replace('//', '/', $new_root_path);
113
  if (file_exists($new_root_path)) {
114
  if ($abs){
115
- return untrailingslashit(site_url()).$new_path;
116
  } else {
117
  return TimberHelper::preslashit($new_path);
118
  }
@@ -151,7 +151,7 @@
151
  error_log(print_r($result, true));
152
  }
153
  if ($abs){
154
- return untrailingslashit(site_url()).$new_path;
155
  }
156
  return $new_path;
157
  } else if (isset($image->error_data['error_loading_image'])) {
91
  if (empty($src)){
92
  return '';
93
  }
94
+ if (strstr($src, 'http') && !strstr($src, content_url())) {
95
  $src = self::sideload_image($src);
96
  }
97
  $abs = false;
105
  $dir = $path_parts['dirname'];
106
  $newbase = $basename . '-r-' . $w . 'x' . $h;
107
  $new_path = $dir . '/' . $newbase . '.' . $ext;
108
+ $new_path = str_replace(content_url(), '', $new_path);
109
+ $new_root_path = WP_CONTENT_DIR . $new_path;
110
+ $old_root_path = WP_CONTENT_DIR . str_replace(content_url(), '', $src);
111
  $old_root_path = str_replace('//', '/', $old_root_path);
112
  $new_root_path = str_replace('//', '/', $new_root_path);
113
  if (file_exists($new_root_path)) {
114
  if ($abs){
115
+ return untrailingslashit(content_url()).$new_path;
116
  } else {
117
  return TimberHelper::preslashit($new_path);
118
  }
151
  error_log(print_r($result, true));
152
  }
153
  if ($abs){
154
+ return untrailingslashit(content_url()).$new_path;
155
  }
156
  return $new_path;
157
  } else if (isset($image->error_data['error_loading_image'])) {
functions/timber-post.php CHANGED
@@ -238,19 +238,26 @@ class TimberPost extends TimberCore {
238
  return $this->get_permalink();
239
  }
240
 
241
- function get_next() {
242
- if (!isset($this->_next)){
243
  global $post;
244
- $this->_next = null;
245
  $old_global = $post;
246
  $post = $this;
247
- $adjacent = get_adjacent_post(false, '', false);
 
 
 
 
 
248
  if ($adjacent){
249
- $this->_next = new $this->PostClass($adjacent);
 
 
250
  }
251
  $post = $old_global;
252
  }
253
- return $this->_next;
254
  }
255
 
256
  public function get_pagination(){
@@ -290,23 +297,30 @@ class TimberPost extends TimberCore {
290
  return '';
291
  }
292
 
293
- public function get_path() {
294
  return TimberHelper::get_rel_url($this->get_link());
295
  }
296
 
297
- function get_prev() {
298
- if (!isset($this->_prev)){
299
  global $post;
300
- $this->_prev = null;
301
  $old_global = $post;
302
  $post = $this;
303
- $adjacent = get_adjacent_post(false, '', true);
 
 
 
 
 
304
  if ($adjacent){
305
- $this->_prev = new $this->PostClass($adjacent);
 
 
306
  }
307
  $post = $old_global;
308
  }
309
- return $this->_prev;
310
  }
311
 
312
  function get_parent() {
@@ -622,8 +636,8 @@ class TimberPost extends TimberCore {
622
  return $this->get_field($field_name);
623
  }
624
 
625
- public function next() {
626
- return $this->get_next();
627
  }
628
 
629
  public function pagination(){
@@ -642,8 +656,8 @@ class TimberPost extends TimberCore {
642
  return $this->get_permalink();
643
  }
644
 
645
- public function prev() {
646
- return $this->get_prev();
647
  }
648
 
649
  public function terms($tax = '') {
238
  return $this->get_permalink();
239
  }
240
 
241
+ function get_next($by_taxonomy = false) {
242
+ if (!isset($this->_next) || !isset($this->_next[$by_taxonomy])){
243
  global $post;
244
+ $this->_next = array();
245
  $old_global = $post;
246
  $post = $this;
247
+ if ($by_taxonomy == 'category' || $by_taxonomy == 'categories'){
248
+ $in_same_cat = true;
249
+ } else {
250
+ $in_same_cat = false;
251
+ }
252
+ $adjacent = get_adjacent_post($in_same_cat, '', false);
253
  if ($adjacent){
254
+ $this->_next[$by_taxonomy] = new $this->PostClass($adjacent);
255
+ } else {
256
+ $this->_next[$by_taxonomy] = false;
257
  }
258
  $post = $old_global;
259
  }
260
+ return $this->_next[$by_taxonomy];
261
  }
262
 
263
  public function get_pagination(){
297
  return '';
298
  }
299
 
300
+ function get_path() {
301
  return TimberHelper::get_rel_url($this->get_link());
302
  }
303
 
304
+ function get_prev($by_taxonomy = false) {
305
+ if (!isset($this->_prev) || !isset($this->_prev[$by_taxonomy])){
306
  global $post;
307
+ $this->_prev = array();
308
  $old_global = $post;
309
  $post = $this;
310
+ if ($by_taxonomy == 'category' || $by_taxonomy == 'categories'){
311
+ $in_same_cat = true;
312
+ } else {
313
+ $in_same_cat = false;
314
+ }
315
+ $adjacent = get_adjacent_post($in_same_cat, '', true);
316
  if ($adjacent){
317
+ $this->_prev[$by_taxonomy] = new $this->PostClass($adjacent);
318
+ } else {
319
+ $this->_prev[$by_taxonomy] = false;
320
  }
321
  $post = $old_global;
322
  }
323
+ return $this->_prev[$by_taxonomy];
324
  }
325
 
326
  function get_parent() {
636
  return $this->get_field($field_name);
637
  }
638
 
639
+ public function next($in_same_cat = false) {
640
+ return $this->get_next($in_same_cat);
641
  }
642
 
643
  public function pagination(){
656
  return $this->get_permalink();
657
  }
658
 
659
+ public function prev($in_same_cat = false) {
660
+ return $this->get_prev($in_same_cat);
661
  }
662
 
663
  public function terms($tax = '') {
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.5
5
- Stable tag: 0.16.7
6
- Tested up to: 3.8.0
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -41,6 +41,13 @@ Timber is great for any WordPress developer who cares about writing good, mainta
41
 
42
  == Changelog ==
43
 
 
 
 
 
 
 
 
44
  = 0.16.7 =
45
  * Fixed issue with image heights on external images (thanks @AndrewDuthie)
46
  * Added new filter for timber_compile_result (thanks @parisholley)
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.5
5
+ Stable tag: 0.16.8
6
+ Tested up to: 3.8.1
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
41
 
42
  == Changelog ==
43
 
44
+ = 0.16.8 =
45
+ * You can now retrieve prev/next posts within the same category (post.next('category').title, etc.). (thanks @slimndap)
46
+ * Fixed issue with letterboxing images when WP is installed in a subdirectory ( @wesrice)
47
+ * Fix for images stored inside custom content path (@mmikkel)
48
+ * Cleaned-up some things in Timber Starter theme (@southernfriedbb, @jarednova)
49
+
50
+
51
  = 0.16.7 =
52
  * Fixed issue with image heights on external images (thanks @AndrewDuthie)
53
  * Added new filter for timber_compile_result (thanks @parisholley)
timber-starter-theme/index.php CHANGED
@@ -23,6 +23,6 @@
23
  if (is_home()){
24
  array_unshift($templates, 'home.twig');
25
  }
26
- Timber::render('index.twig', $context);
27
 
28
 
23
  if (is_home()){
24
  array_unshift($templates, 'home.twig');
25
  }
26
+ Timber::render($templates, $context);
27
 
28
 
timber-starter-theme/views/html-header.twig CHANGED
@@ -1,15 +1,15 @@
1
  <!doctype html>
2
- <!--[if lt IE 7]><html class="no-js ie ie6 lt-ie9 lt-ie8 lt-ie7" {{language_attributes}}> <![endif]-->
3
- <!--[if IE 7]><html class="no-js ie ie7 lt-ie9 lt-ie8" {{language_attributes}}> <![endif]-->
4
- <!--[if IE 8]><html class="no-js ie ie8 lt-ie9" {{language_attributes}}> <![endif]-->
5
- <!--[if gt IE 8]><!--><html class="no-js" {{language_attributes}}> <!--<![endif]-->
6
  <head>
7
- <meta charset="{{ bloginfo('charset') }}" />
8
  <title>{{wp_title}}</title>
9
- <meta name="description" content="{{ bloginfo('description') }}">
10
- <link rel="stylesheet" href="{{ stylesheet_uri }}" type="text/css" media="screen" />
11
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
12
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
13
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
14
- <link rel="pingback" href="{{ bloginfo('pingback_url') }}" />
15
  {{function('wp_head')}}
1
  <!doctype html>
2
+ <!--[if lt IE 7]><html class="no-js ie ie6 lt-ie9 lt-ie8 lt-ie7" {{site.language_attributes}}> <![endif]-->
3
+ <!--[if IE 7]><html class="no-js ie ie7 lt-ie9 lt-ie8" {{site.language_attributes}}> <![endif]-->
4
+ <!--[if IE 8]><html class="no-js ie ie8 lt-ie9" {{site.language_attributes}}> <![endif]-->
5
+ <!--[if gt IE 8]><!--><html class="no-js" {{site.language_attributes}}> <!--<![endif]-->
6
  <head>
7
+ <meta charset="{{site.charset}}" />
8
  <title>{{wp_title}}</title>
9
+ <meta name="description" content="{{site.description}}">
10
+ <link rel="stylesheet" href="{{site.theme.link}}/style.css" type="text/css" media="screen" />
11
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
12
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
13
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
14
+ <link rel="pingback" href="{{site.pingback_url}}" />
15
  {{function('wp_head')}}
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.16.7
8
  Author URI: http://upstatement.com/
9
  */
10
 
@@ -345,6 +345,7 @@ class Timber {
345
  $data['template_uri'] = get_template_directory_uri();
346
  $data['theme'] = new TimberTheme();
347
  $data['site'] = new TimberSite();
 
348
  $data = apply_filters('timber_context', $data);
349
  return $data;
350
  }
@@ -531,8 +532,13 @@ class Timber {
531
  global $paged;
532
  $args['total'] = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']);
533
  if (strlen(trim(get_option('permalink_structure')))){
 
 
 
 
 
534
  $args['format'] = 'page/%#%';
535
- $args['base'] = trailingslashit(get_pagenum_link(0)).'%_%';
536
  } else {
537
  $big = 999999999;
538
  $args['base'] = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) );
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.16.8
8
  Author URI: http://upstatement.com/
9
  */
10
 
345
  $data['template_uri'] = get_template_directory_uri();
346
  $data['theme'] = new TimberTheme();
347
  $data['site'] = new TimberSite();
348
+ $data['site']->theme = $data['theme'];
349
  $data = apply_filters('timber_context', $data);
350
  return $data;
351
  }
532
  global $paged;
533
  $args['total'] = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']);
534
  if (strlen(trim(get_option('permalink_structure')))){
535
+ $url = explode('?', get_pagenum_link(0));
536
+ if (isset($url[1])){
537
+ parse_str($url[1], $query);
538
+ $args['add_args'] = $query;
539
+ }
540
  $args['format'] = 'page/%#%';
541
+ $args['base'] = trailingslashit($url[0]).'%_%';
542
  } else {
543
  $big = 999999999;
544
  $args['base'] = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) );