Timber - Version 0.13.5

Version Description

  • Added comprehensive support for actions and filters (thanks @mgmartel)
  • Rewrote routing to template to be 100% harmonious with WordPress (thanks again @mgmartel)
  • Fix to some pagination errors when using a custom rewrite on a taxonomy (thanks to @kylehotchkiss)
  • Fixed issue with stripping the ellipses on a preview (thanks to @bryanscode)
  • Functions now work more logically, example: {{function('my_special_function', 'arg1')}}
Download this release

Release Info

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

Code changes from version 0.13.0 to 0.13.5

functions/functions-twig.php CHANGED
@@ -36,8 +36,21 @@ class TimberTwig {
36
  $twig->addFilter('twitterfy', new Twig_Filter_Function(array('WPHelper', 'twitterify')));
37
  $twig->addFilter('wp_body_class', new Twig_Filter_Function('twig_body_class'));
38
  $twig->addFilter('wpautop', new Twig_Filter_Function('wpautop'));
39
-
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  $twig->addFunction('bloginfo', new Twig_SimpleFunction('bloginfo', function($show = '', $filter = 'raw'){
42
  return get_bloginfo($show, $filter);
43
  }));
36
  $twig->addFilter('twitterfy', new Twig_Filter_Function(array('WPHelper', 'twitterify')));
37
  $twig->addFilter('wp_body_class', new Twig_Filter_Function('twig_body_class'));
38
  $twig->addFilter('wpautop', new Twig_Filter_Function('wpautop'));
 
39
 
40
+ /* actions and filters */
41
+ $twig->addFunction(new Twig_SimpleFunction('action', function(){
42
+ call_user_func_array('do_action', func_get_args());
43
+ }));
44
+ $twig->addFilter( new Twig_SimpleFilter('apply_filters', function(){
45
+ $args = func_get_args();
46
+ $tag = current(array_splice($args, 1, 1));
47
+
48
+ return apply_filters_ref_array($tag, $args);
49
+ }));
50
+ $twig->addFunction(new Twig_SimpleFunction('function', array(&$this, 'exec_function')));
51
+ $twig->addFunction(new Twig_SimpleFunction('fn', array(&$this, 'exec_function')));
52
+
53
+ /* bloginfo and translate */
54
  $twig->addFunction('bloginfo', new Twig_SimpleFunction('bloginfo', function($show = '', $filter = 'raw'){
55
  return get_bloginfo($show, $filter);
56
  }));
functions/functions-wp-helper.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  class WPHelper {
4
 
5
- public static function init_transient($slug, $callback, $transient_time = 1800){
6
  if (false===($data = get_transient($slug))){
7
  $data = $callback();
8
  set_transient($slug, $data, $transient_time);
@@ -260,6 +260,12 @@ class WPHelper {
260
  return 0;
261
  }
262
 
 
 
 
 
 
 
263
  /* this $args thing is a fucking mess, fix at some point:
264
 
265
  http://codex.wordpress.org/Function_Reference/comment_form */
2
 
3
  class WPHelper {
4
 
5
+ public static function transient($slug, $callback, $transient_time = 1800){
6
  if (false===($data = get_transient($slug))){
7
  $data = $callback();
8
  set_transient($slug, $data, $transient_time);
260
  return 0;
261
  }
262
 
263
+ public static function get_term_id_by_term_taxonomy_id($ttid){
264
+ global $wpdb;
265
+ $query = "SELECT term_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = '$ttid'";
266
+ return $wpdb->get_var($query);
267
+ }
268
+
269
  /* this $args thing is a fucking mess, fix at some point:
270
 
271
  http://codex.wordpress.org/Function_Reference/comment_form */
functions/functions-wp-image-helper.php CHANGED
@@ -63,6 +63,9 @@
63
  }
64
 
65
  public static function resize($src, $w, $h = 0){
 
 
 
66
  if (strstr($src, 'http') && !strstr($src, site_url())) {
67
  $src = self::sideload_image($src);
68
  }
@@ -83,7 +86,6 @@
83
  $old_root_path = str_replace('//', '/', $old_root_path);
84
  $new_root_path = str_replace('//', '/', $new_root_path);
85
  if (file_exists($new_root_path)) {
86
- error_log('return '.$new_path);
87
  if ($abs){
88
  return untrailingslashit(site_url()).$new_path;
89
  } else {
@@ -118,8 +120,10 @@
118
  return untrailingslashit(site_url()).$new_path;
119
  }
120
  return $new_path;
 
 
121
  } else {
122
- error_log('there was an error');
123
  }
124
  return $src;
125
  }
63
  }
64
 
65
  public static function resize($src, $w, $h = 0){
66
+ if (empty($src)){
67
+ return '';
68
+ }
69
  if (strstr($src, 'http') && !strstr($src, site_url())) {
70
  $src = self::sideload_image($src);
71
  }
86
  $old_root_path = str_replace('//', '/', $old_root_path);
87
  $new_root_path = str_replace('//', '/', $new_root_path);
88
  if (file_exists($new_root_path)) {
 
89
  if ($abs){
90
  return untrailingslashit(site_url()).$new_path;
91
  } else {
120
  return untrailingslashit(site_url()).$new_path;
121
  }
122
  return $new_path;
123
+ } else if (isset($image->error_data['error_loading_image'])) {
124
+ error_log('Error loading '.$image->error_data['error_loading_image']);
125
  } else {
126
+ WPHelper::error_log($image);
127
  }
128
  return $src;
129
  }
{router → functions/router}/.gitignore RENAMED
File without changes
{router → functions/router}/.htaccess RENAMED
File without changes
{router → functions/router}/LICENSE RENAMED
File without changes
{router → functions/router}/README.md RENAMED
File without changes
{router → functions/router}/Route.php RENAMED
File without changes
{router → functions/router}/Router.php RENAMED
File without changes
{router → functions/router}/example.php RENAMED
File without changes
functions/timber-post.php CHANGED
@@ -176,6 +176,9 @@ class TimberPost extends TimberCore {
176
  */
177
  function import_custom($pid) {
178
  $customs = get_post_custom($pid);
 
 
 
179
  foreach ($customs as $key => $value) {
180
  $v = $value[0];
181
  $this->$key = $v;
176
  */
177
  function import_custom($pid) {
178
  $customs = get_post_custom($pid);
179
+ if (!is_array($customs)){
180
+ return;
181
+ }
182
  foreach ($customs as $key => $value) {
183
  $v = $value[0];
184
  $this->$key = $v;
functions/timber-term.php CHANGED
@@ -97,8 +97,7 @@ class TimberTerm extends TimberCore {
97
  }
98
 
99
  function get_path() {
100
- $p = WPHelper::get_path_base();
101
- return $p . $this->get_url();
102
  }
103
 
104
  function get_link() {
97
  }
98
 
99
  function get_path() {
100
+ return get_term_link($this);
 
101
  }
102
 
103
  function get_link() {
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.13.0
6
  Tested up to: 3.6.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -37,6 +37,13 @@ Timber is great for any WordPress developer who cares about writing good, mainta
37
 
38
  == Changelog ==
39
 
 
 
 
 
 
 
 
40
  = 0.13.0 =
41
  * TimberMenuItems now get the WP classes you've come to know and love (.current-menu-item, etc.)
42
  * More test coverage for images
@@ -55,7 +62,7 @@ Timber is great for any WordPress developer who cares about writing good, mainta
55
  * A few fixes that catch issues with absolute vs. relative URLs in resize
56
 
57
  = 0.12.0 =
58
- * Pagination is refactored to be more intutitve, and well, better.
59
  * Resize is also refactored to respect absolute vs. relative URLs
60
  * Got rid of lots of old, bogus code.
61
 
@@ -83,13 +90,13 @@ Timber is great for any WordPress developer who cares about writing good, mainta
83
  * Lots of code cleanup thanks to [Jakub](http://github.com/hsz)
84
  * Added new function for bloginfo
85
  * You can now hook into timber_context to filter the $context object
86
- * Added Timber::get_terms to retrive lists of your blog's terms
87
  * Added better support for translation
88
  * Added filter for executing a function, ie {{'my_theme_function'|filter}}
89
 
90
  = 0.10.3 =
91
  * Corrected error with sidebar retrieval
92
- * language_attributes are now avaiable as part of Timber::get_context(); payload.
93
  * Upgraded to Twig 1.13.1
94
 
95
  = 0.10.2 =
@@ -104,8 +111,9 @@ Timber is great for any WordPress developer who cares about writing good, mainta
104
  * added lots of aliases so that things like .author will work the same as .get_author
105
 
106
  == Screenshots ==
107
- <img src="/assets/sample-twig.png" />
108
- Here's what writ
 
109
 
110
  == Installation ==
111
 
@@ -128,12 +136,19 @@ Then create a subdirectory called `views` in your theme folder. The make this fi
128
 
129
  That's Timber!
130
 
131
-
132
  == Frequently Asked Questions ==
133
 
134
  = Can it be used in an existing theme? =
135
-
136
  You bet! Watch these **[video tutorials](https://github.com/jarednova/timber/wiki/Video-Tutorials)** to see how.
137
 
 
 
 
 
 
 
 
 
 
138
  = Support? =
139
  Leave a [GitHub issue](https://github.com/jarednova/timber/issues?state=open) and I'll holler back.
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.5
5
+ Stable tag: 0.13.5
6
  Tested up to: 3.6.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
37
 
38
  == Changelog ==
39
 
40
+ = 0.13.5 =
41
+ * Added comprehensive support for actions and filters (thanks @mgmartel)
42
+ * Rewrote routing to template to be 100% harmonious with WordPress (thanks again @mgmartel)
43
+ * Fix to some pagination errors when using a custom rewrite on a taxonomy (thanks to @kylehotchkiss)
44
+ * Fixed issue with stripping the ellipses on a preview (thanks to @bryanscode)
45
+ * Functions now work more logically, example: {{function('my_special_function', 'arg1')}}
46
+
47
  = 0.13.0 =
48
  * TimberMenuItems now get the WP classes you've come to know and love (.current-menu-item, etc.)
49
  * More test coverage for images
62
  * A few fixes that catch issues with absolute vs. relative URLs in resize
63
 
64
  = 0.12.0 =
65
+ * Pagination is refactored to be more intuitive, and well, better.
66
  * Resize is also refactored to respect absolute vs. relative URLs
67
  * Got rid of lots of old, bogus code.
68
 
90
  * Lots of code cleanup thanks to [Jakub](http://github.com/hsz)
91
  * Added new function for bloginfo
92
  * You can now hook into timber_context to filter the $context object
93
+ * Added Timber::get_terms to retrieve lists of your blog's terms
94
  * Added better support for translation
95
  * Added filter for executing a function, ie {{'my_theme_function'|filter}}
96
 
97
  = 0.10.3 =
98
  * Corrected error with sidebar retrieval
99
+ * language_attributes are now available as part of Timber::get_context(); payload.
100
  * Upgraded to Twig 1.13.1
101
 
102
  = 0.10.2 =
111
  * added lots of aliases so that things like .author will work the same as .get_author
112
 
113
  == Screenshots ==
114
+
115
+ 1. This what a normal WordPres PHP file looks like
116
+ 2. With Timber, you write Twig files that are super-clear and HTML-centric.
117
 
118
  == Installation ==
119
 
136
 
137
  That's Timber!
138
 
 
139
  == Frequently Asked Questions ==
140
 
141
  = Can it be used in an existing theme? =
 
142
  You bet! Watch these **[video tutorials](https://github.com/jarednova/timber/wiki/Video-Tutorials)** to see how.
143
 
144
+ = Is it used in production? =
145
+ At Upstatement we've now used it on more than a dozen client sites. You can check them out in the showcase here: http://jarednova.github.io/timber/
146
+
147
+ = Doesn't this all make WordPress harder since there's more to learn? =
148
+ Does jQuery make JavaScript harder? Yes, it's an extra piece to learn -- but it super-charges your ability to write unencumbered JavaScript (and prevents you from having to learn lots of the messy internals). If your answer is "jQuery sucks and everyone should learn how to write vanilla JS or they're rotten stupid people," this tool isn't for you.
149
+
150
+ = Will you support it? =
151
+ As stated above, we're using it in dozens of sites (and dozens more planned). This isn't going anywhere. Twig is the chosen language for other PHP platforms like Symfony, Drupal8 and Craft. WordPress will eventually adopt Twig too.
152
+
153
  = Support? =
154
  Leave a [GitHub issue](https://github.com/jarednova/timber/issues?state=open) and I'll holler back.
timber.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Timber
4
  Description: The WordPress Timber Library allows you to write themes using the power Twig templates
5
  Author: Jared Novack + Upstatement
6
- Version: 0.13.0
7
  Author URI: http://timber.upstatement.com/
8
  */
9
 
@@ -261,7 +261,7 @@ class Timber {
261
  public static function handle_term_query($taxonomies, $args, $TermClass){
262
  $terms = get_terms($taxonomies, $args);
263
  foreach($terms as &$term){
264
- $term = new TimberTerm($term->term_id);
265
  }
266
  return $terms;
267
  }
@@ -363,8 +363,8 @@ class Timber {
363
  public static function add_route($route, $callback) {
364
  global $timber;
365
  if (!isset($timber->router)) {
366
- require_once('router/Router.php');
367
- require_once('router/Route.php');
368
  $timber->router = new Router();
369
  $timber->router->setBasePath('/');
370
  }
@@ -372,21 +372,23 @@ class Timber {
372
  }
373
 
374
  public function load_template($template, $query = false) {
 
 
375
  if ($query) {
376
- global $wp_query;
377
- $wp_query = new WP_Query($query);
 
 
 
378
  }
379
- $template = locate_template($template);
380
- $GLOBALS['timber_template'] = $template;
381
- add_action('send_headers', function () {
382
- header('HTTP/1.1 200 OK');
383
- });
384
- add_action('wp_loaded', function ($template) {
385
- if (isset($GLOBALS['timber_template'])) {
386
- load_template($GLOBALS['timber_template']);
387
  die;
388
- }
389
- }, 10, 1);
390
  }
391
 
392
  /* Pagination
@@ -403,7 +405,7 @@ class Timber {
403
 
404
  $args['current'] = max( 1, get_query_var('paged') );
405
  $args['mid_size'] = max(9 - $args['current'], 3);
406
- $args['base'] = get_pagenum_link(0).'%_%';
407
  $args['prev_next'] = false;
408
  $args = array_merge($args, $prefs);
409
  $data['pages'] = WPHelper::paginate_links($args);
3
  Plugin Name: Timber
4
  Description: The WordPress Timber Library allows you to write themes using the power Twig templates
5
  Author: Jared Novack + Upstatement
6
+ Version: 0.13.5
7
  Author URI: http://timber.upstatement.com/
8
  */
9
 
261
  public static function handle_term_query($taxonomies, $args, $TermClass){
262
  $terms = get_terms($taxonomies, $args);
263
  foreach($terms as &$term){
264
+ $term = new $TermClass($term->term_id);
265
  }
266
  return $terms;
267
  }
363
  public static function add_route($route, $callback) {
364
  global $timber;
365
  if (!isset($timber->router)) {
366
+ require_once('functions/router/Router.php');
367
+ require_once('functions/router/Route.php');
368
  $timber->router = new Router();
369
  $timber->router->setBasePath('/');
370
  }
372
  }
373
 
374
  public function load_template($template, $query = false) {
375
+ $template = locate_template($template);
376
+
377
  if ($query) {
378
+ add_action('do_parse_request',function() use ($query) {
379
+ global $wp;
380
+ $wp->query_vars = $query;
381
+ return false;
382
+ });
383
  }
384
+ if ($template) {
385
+ add_action('wp_loaded', function() use ($template) {
386
+ wp();
387
+ do_action('template_redirect');
388
+ load_template($template);
 
 
 
389
  die;
390
+ });
391
+ }
392
  }
393
 
394
  /* Pagination
405
 
406
  $args['current'] = max( 1, get_query_var('paged') );
407
  $args['mid_size'] = max(9 - $args['current'], 3);
408
+ $args['base'] = trailingslashit(get_pagenum_link(0)).'%_%';
409
  $args['prev_next'] = false;
410
  $args = array_merge($args, $prefs);
411
  $data['pages'] = WPHelper::paginate_links($args);