Timber - Version 0.16.6

Version Description

  • Router plays nice with installs in subdirectories (thanks @TerminalPixel)
  • ACF Timber now initializes on Init (thanks @Zerek)
  • Composer is updated (thanks @Rarst)
  • $autoescape bug fixed (thanks @ParisHolley)
  • You can now select a term ID from a specific taxonomy (thanks @mgmartel)
  • added stripshortcodes filter
  • TimberMenuItems now have is_external method
  • Other misc bugs
Download this release

Release Info

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

Code changes from version 0.16.5 to 0.16.6

README.md CHANGED
@@ -56,7 +56,7 @@ Timber is great for any WordPress developer who cares about writing good, mainta
56
  * [**Twig**](https://github.com/fabpot/Twig) The template language used by Timber.
57
 
58
  #### Should I use it?
59
- Well, it's **free**! And it's GPL-licensed, so use in personal or commercial work. Just don't re-sell it.
60
 
61
  #### Upgrade Notes
62
  Twig is no longer a submodule, just a part of the repo. If you have trouble pulling, just delete the `Twig` folder. Then you should be good.
56
  * [**Twig**](https://github.com/fabpot/Twig) The template language used by Timber.
57
 
58
  #### Should I use it?
59
+ Well, it's **free**! And it's GPL-licensed, so use in personal or commercial work. Just don't re-sell it. Timber is still in development. While much has been stabalized since the first major push back in June 2013, you should expect some breaking changes as development progresses towards a version 1.0
60
 
61
  #### Upgrade Notes
62
  Twig is no longer a submodule, just a part of the repo. If you have trouble pulling, just delete the `Twig` folder. Then you should be good.
functions/functions-twig.php CHANGED
@@ -25,6 +25,7 @@ class TimberTwig {
25
  $twig->addFilter('print_a', new Twig_Filter_Function('twig_print_a'));
26
 
27
  /* other filters */
 
28
  $twig->addFilter('array', new Twig_Filter_Function(array($this, 'to_array')));
29
  $twig->addFilter('excerpt', new Twig_Filter_Function('twig_make_excerpt'));
30
  $twig->addFilter('function', new Twig_Filter_Function(array($this, 'exec_function')));
@@ -41,6 +42,10 @@ class TimberTwig {
41
  return TimberHelper::get_rel_url($link, true);
42
  }));
43
 
 
 
 
 
44
  /* actions and filters */
45
  $twig->addFunction(new Twig_SimpleFunction('action', function(){
46
  call_user_func_array('do_action', func_get_args());
25
  $twig->addFilter('print_a', new Twig_Filter_Function('twig_print_a'));
26
 
27
  /* other filters */
28
+ $twig->addFilter('stripshortcodes', new Twig_Filter_Function('strip_shortcodes'));
29
  $twig->addFilter('array', new Twig_Filter_Function(array($this, 'to_array')));
30
  $twig->addFilter('excerpt', new Twig_Filter_Function('twig_make_excerpt'));
31
  $twig->addFilter('function', new Twig_Filter_Function(array($this, 'exec_function')));
42
  return TimberHelper::get_rel_url($link, true);
43
  }));
44
 
45
+ $twig->addFilter('truncate', new Twig_Filter_Function(function($text, $len){
46
+ return TimberHelper::trim_words($text, $len);
47
+ }));
48
+
49
  /* actions and filters */
50
  $twig->addFunction(new Twig_SimpleFunction('action', function(){
51
  call_user_func_array('do_action', func_get_args());
functions/integrations/acf-timber.php CHANGED
@@ -47,9 +47,9 @@
47
  return get_field($field, 'user_'.$uid);
48
  }
49
  }
50
- add_action( 'plugins_loaded', function(){
51
  if (class_exists('ACF')){
52
  new ACFTimber();
53
  }
54
  });
55
-
47
  return get_field($field, 'user_'.$uid);
48
  }
49
  }
50
+ add_action( 'init', function(){
51
  if (class_exists('ACF')){
52
  new ACFTimber();
53
  }
54
  });
55
+
functions/timber-archives.php CHANGED
@@ -1,16 +1,20 @@
1
  <?php
2
  class TimberArchives extends TimberCore {
3
- function __construct($args){
4
- $this->init($args);
 
 
 
5
  }
6
 
7
- function init($args){
 
8
  $this->items = $this->get_items($args);
9
  }
10
 
11
  function get_archives_link($url, $text) {
12
  $ret['text'] = $ret['title'] = $ret['name'] = wptexturize($text);
13
- $ret['url'] = $ret['link'] = esc_url($url);
14
  return $ret;
15
  }
16
 
@@ -28,7 +32,7 @@ class TimberArchives extends TimberCore {
28
  foreach ( (array) $results as $result) {
29
  $url = get_year_link($result->year);
30
  $text = sprintf('%d', $result->year);
31
- $output[] = self::get_archives_link($url, $text);
32
  }
33
  }
34
  return $output;
@@ -62,9 +66,9 @@ class TimberArchives extends TimberCore {
62
  $text = sprintf(__('%1$s'), $wp_locale->get_month($result->month));
63
  }
64
  if ($nested){
65
- $output[$result->year][] = self::get_archives_link($url, $text);
66
  } else {
67
- $output[] = self::get_archives_link($url, $text);
68
  }
69
  }
70
  }
@@ -162,7 +166,7 @@ class TimberArchives extends TimberCore {
162
  $url = get_day_link($result->year, $result->month, $result->dayofmonth);
163
  $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth);
164
  $text = mysql2date($archive_day_date_format, $date);
165
- $output[] = self::get_archives_link($url, $text);
166
  }
167
  }
168
  } elseif ( 'weekly' == $type ) {
@@ -186,7 +190,7 @@ class TimberArchives extends TimberCore {
186
  $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
187
  $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);
188
  $text = $arc_week_start . $archive_week_separator . $arc_week_end;
189
- $output[] = self::get_archives_link($url, $text);
190
  }
191
  }
192
  }
1
  <?php
2
  class TimberArchives extends TimberCore {
3
+
4
+ var $base = '';
5
+
6
+ function __construct($args, $base = ''){
7
+ $this->init($args, $base);
8
  }
9
 
10
+ function init($args, $base = ''){
11
+ $this->base = $base;
12
  $this->items = $this->get_items($args);
13
  }
14
 
15
  function get_archives_link($url, $text) {
16
  $ret['text'] = $ret['title'] = $ret['name'] = wptexturize($text);
17
+ $ret['url'] = $ret['link'] = esc_url(TimberHelper::prepend_to_url($url, $this->base));
18
  return $ret;
19
  }
20
 
32
  foreach ( (array) $results as $result) {
33
  $url = get_year_link($result->year);
34
  $text = sprintf('%d', $result->year);
35
+ $output[] = $this->get_archives_link($url, $text);
36
  }
37
  }
38
  return $output;
66
  $text = sprintf(__('%1$s'), $wp_locale->get_month($result->month));
67
  }
68
  if ($nested){
69
+ $output[$result->year][] = $this->get_archives_link($url, $text);
70
  } else {
71
+ $output[] = $this->get_archives_link($url, $text);
72
  }
73
  }
74
  }
166
  $url = get_day_link($result->year, $result->month, $result->dayofmonth);
167
  $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth);
168
  $text = mysql2date($archive_day_date_format, $date);
169
+ $output[] = $this->get_archives_link($url, $text);
170
  }
171
  }
172
  } elseif ( 'weekly' == $type ) {
190
  $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
191
  $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);
192
  $text = $arc_week_start . $archive_week_separator . $arc_week_end;
193
+ $output[] = $this->get_archives_link($url, $text);
194
  }
195
  }
196
  }
functions/timber-helper.php CHANGED
@@ -8,7 +8,11 @@ class TimberHelper {
8
  $disable_transients = WP_DISABLE_TRANSIENTS;
9
  }
10
  $data = null;
11
- if (is_callable($callback) && (false === ($data = get_transient($slug)) || $disable_transients)){
 
 
 
 
12
  $cache_lock_slug = $slug.'_lock';
13
 
14
  if (get_transient($cache_lock_slug)){
@@ -103,6 +107,9 @@ class TimberHelper {
103
  return false;
104
  }
105
 
 
 
 
106
  public static function get_rel_url($url, $force = false){
107
  if (!strstr($url, $_SERVER['HTTP_HOST']) && !$force){
108
  return $url;
@@ -119,6 +126,24 @@ class TimberHelper {
119
  return str_replace(ABSPATH, '', $src);
120
  }
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  public static function download_url($url, $timeout = 300) {
123
  if (!$url) {
124
  return new WP_Error('http_no_url', __('Invalid URL Provided.'));
@@ -270,7 +295,7 @@ class TimberHelper {
270
  public static function get_posts_by_meta($key, $value) {
271
  global $wpdb;
272
  $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s", $key, $value);
273
- $results = $wpdb->col($query);
274
  $pids = array();
275
  foreach ($results as $result) {
276
  if (get_post($result)) {
@@ -388,6 +413,15 @@ class TimberHelper {
388
  return ($i % 2) != 0;
389
  }
390
 
 
 
 
 
 
 
 
 
 
391
  public static function twitterify($ret) {
392
  $ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
393
  $ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
8
  $disable_transients = WP_DISABLE_TRANSIENTS;
9
  }
10
  $data = null;
11
+ if ($transient_time === false){
12
+ $data = $callback();
13
+ return $data;
14
+ }
15
+ if (is_callable($callback) && (false === ($data = get_transient($slug)) || $disable_transients) && $transient_time !== false){
16
  $cache_lock_slug = $slug.'_lock';
17
 
18
  if (get_transient($cache_lock_slug)){
107
  return false;
108
  }
109
 
110
+ /* URL Stuff
111
+ ======================== */
112
+
113
  public static function get_rel_url($url, $force = false){
114
  if (!strstr($url, $_SERVER['HTTP_HOST']) && !$force){
115
  return $url;
126
  return str_replace(ABSPATH, '', $src);
127
  }
128
 
129
+ public static function remove_double_slashes($url){
130
+ $url = str_replace('//', '/', $url);
131
+ if (strstr($url, 'http:') && !strstr($url, 'http://')){
132
+ $url = str_replace('http:/', 'http://', $url);
133
+ }
134
+ return $url;
135
+ }
136
+
137
+ public static function prepend_to_url($url, $path){
138
+ if (strstr(strtolower($url), 'http')){
139
+ $url_parts = parse_url($url);
140
+ $url = $url_parts['scheme'].'://'.$url_parts['host'].$path.$url_parts['path'];
141
+ } else {
142
+ $url = $url.$path;
143
+ }
144
+ return self::remove_double_slashes($url);
145
+ }
146
+
147
  public static function download_url($url, $timeout = 300) {
148
  if (!$url) {
149
  return new WP_Error('http_no_url', __('Invalid URL Provided.'));
295
  public static function get_posts_by_meta($key, $value) {
296
  global $wpdb;
297
  $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s", $key, $value);
298
+ $results = $wpdb->get_col($query);
299
  $pids = array();
300
  foreach ($results as $result) {
301
  if (get_post($result)) {
413
  return ($i % 2) != 0;
414
  }
415
 
416
+ public static function is_external($url){
417
+ $has_http = strstr(strtolower($url), 'http');
418
+ $on_domain = strstr($url, $_SERVER['HTTP_HOST']);
419
+ if ($has_http && !$on_domain){
420
+ return true;
421
+ }
422
+ return false;
423
+ }
424
+
425
  public static function twitterify($ret) {
426
  $ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
427
  $ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
functions/timber-image-helper.php CHANGED
@@ -56,7 +56,10 @@
56
  $file = parse_url($file);
57
  $path_parts = pathinfo($file['path']);
58
  $basename = md5($filename);
59
- $ext = $path_parts['extension'];
 
 
 
60
  return $dir . '/' . $basename. '.' . $ext;
61
  }
62
 
56
  $file = parse_url($file);
57
  $path_parts = pathinfo($file['path']);
58
  $basename = md5($filename);
59
+ $ext = 'jpg';
60
+ if (isset($path_parts['extension'])){
61
+ $ext = $path_parts['extension'];
62
+ }
63
  return $dir . '/' . $basename. '.' . $ext;
64
  }
65
 
functions/timber-menu.php CHANGED
@@ -162,25 +162,36 @@ class TimberMenuItem extends TimberCore {
162
  return false;
163
  }
164
 
 
 
 
 
 
 
 
165
  /* Aliases */
166
 
167
- function children(){
168
  return $this->get_children();
169
  }
170
 
171
- function link(){
 
 
 
 
172
  return $this->get_link();
173
  }
174
 
175
- function path(){
176
  return $this->get_path();
177
  }
178
 
179
- function permalink(){
180
  return $this->get_link();
181
  }
182
 
183
- function get_permalink(){
184
  return $this->get_link();
185
  }
186
  }
162
  return false;
163
  }
164
 
165
+ function is_external(){
166
+ if ($this->type != 'custom'){
167
+ return false;
168
+ }
169
+ return TimberHelper::is_external($this->url);
170
+ }
171
+
172
  /* Aliases */
173
 
174
+ public function children(){
175
  return $this->get_children();
176
  }
177
 
178
+ public function external(){
179
+ return $this->is_external();
180
+ }
181
+
182
+ public function link(){
183
  return $this->get_link();
184
  }
185
 
186
+ public function path(){
187
  return $this->get_path();
188
  }
189
 
190
+ public function permalink(){
191
  return $this->get_link();
192
  }
193
 
194
+ public function get_permalink(){
195
  return $this->get_link();
196
  }
197
  }
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.5
5
- Stable tag: 0.16.4
6
  Tested up to: 3.8.0
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
@@ -41,6 +41,16 @@ Timber is great for any WordPress developer who cares about writing good, mainta
41
 
42
  == Changelog ==
43
 
 
 
 
 
 
 
 
 
 
 
44
  = 0.16.5 =
45
  * print_a lives! added methods for TimberPost
46
  * quick fix on TimberPost::content which was generating warning
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.5
5
+ Stable tag: 0.16.6
6
  Tested up to: 3.8.0
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
41
 
42
  == Changelog ==
43
 
44
+ = 0.16.6 =
45
+ * Router plays nice with installs in subdirectories (thanks @TerminalPixel)
46
+ * ACF Timber now initializes on Init (thanks @Zerek)
47
+ * Composer is updated (thanks @Rarst)
48
+ * $autoescape bug fixed (thanks @ParisHolley)
49
+ * You can now select a term ID from a specific taxonomy (thanks @mgmartel)
50
+ * added stripshortcodes filter
51
+ * TimberMenuItems now have is_external method
52
+ * Other misc bugs
53
+
54
  = 0.16.5 =
55
  * print_a lives! added methods for TimberPost
56
  * quick fix on TimberPost::content which was generating warning
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.5
8
  Author URI: http://upstatement.com/
9
  */
10
 
@@ -59,6 +59,7 @@ class Timber {
59
  public static $dirname = 'views';
60
  public static $cache = false;
61
  public static $auto_meta = true;
 
62
 
63
  protected $router;
64
 
@@ -301,7 +302,7 @@ class Timber {
301
  }
302
  $terms = get_terms($taxonomies, $args);
303
  foreach($terms as &$term){
304
- $term = new $TermClass($term->term_id);
305
  }
306
  return $terms;
307
  }
@@ -443,7 +444,16 @@ class Timber {
443
  require_once(__DIR__.'/functions/router/Route.php');
444
  if (class_exists('Router')){
445
  $timber->router = new Router();
446
- $timber->router->setBasePath('/');
 
 
 
 
 
 
 
 
 
447
  }
448
  }
449
  if (class_exists('Router')){
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.6
8
  Author URI: http://upstatement.com/
9
  */
10
 
59
  public static $dirname = 'views';
60
  public static $cache = false;
61
  public static $auto_meta = true;
62
+ public static $autoescape = false;
63
 
64
  protected $router;
65
 
302
  }
303
  $terms = get_terms($taxonomies, $args);
304
  foreach($terms as &$term){
305
+ $term = new $TermClass($term->term_id, $term->taxonomy);
306
  }
307
  return $terms;
308
  }
444
  require_once(__DIR__.'/functions/router/Route.php');
445
  if (class_exists('Router')){
446
  $timber->router = new Router();
447
+ $site_url = get_bloginfo('url');
448
+ $site_url_parts = explode('/', $site_url);
449
+ $site_url_parts = array_slice($site_url_parts, 3);
450
+ $base_path = implode('/', $site_url_parts);
451
+ if (!$base_path || strpos($route, $base_path) === 0) {
452
+ $base_path = '/';
453
+ } else {
454
+ $base_path = '/' . $base_path . '/';
455
+ }
456
+ $timber->router->setBasePath($base_path);
457
  }
458
  }
459
  if (class_exists('Router')){