Timber - Version 0.12.2

Version Description

  • TimberMenus now contain metadata 'bout the menu (thanks @bryanaka)
  • Fixed issue with Windows servers (thanks @kzykhys)
  • Resizing external images now incl. the full URL to avoid conflicts
  • Fixed pagination oddity
  • Some code cleanup stuff.
Download this release

Release Info

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

Code changes from version 0.12.1 to 0.12.2

functions/functions-twig.php CHANGED
@@ -11,28 +11,32 @@ class TimberTwig {
11
  * @return Twig_Environment
12
  */
13
  function add_twig_filters($twig) {
 
14
  $twig->addFilter('resize', new Twig_Filter_Function(array('WPImageHelper', 'resize')));
15
  $twig->addFilter('letterbox', new Twig_Filter_Function('wp_resize_letterbox'));
16
- $twig->addFilter('excerpt', new Twig_Filter_Function('twig_make_excerpt'));
 
 
 
 
 
 
17
  $twig->addFilter('print_r', new Twig_Filter_Function('twig_print_r'));
18
  $twig->addFilter('print_a', new Twig_Filter_Function('twig_print_a'));
19
- $twig->addFilter('docs', new Twig_Filter_function('twig_object_docs'));
20
 
21
- $twig->addFilter('get_src_from_attachment_id', new Twig_Filter_Function('twig_get_src_from_attachment_id'));
 
 
22
  $twig->addFilter('path', new Twig_Filter_Function('twig_get_path'));
23
- $twig->addFilter('tojpg', new Twig_Filter_Function(array('WPImageHelper', 'img_to_jpg')));
24
- $twig->addFilter('wpautop', new Twig_Filter_Function('wpautop'));
 
 
25
  $twig->addFilter('twitterify', new Twig_Filter_Function(array('WPHelper', 'twitterify')));
26
  $twig->addFilter('twitterfy', new Twig_Filter_Function(array('WPHelper', 'twitterify')));
27
- $twig->addFilter('get_class', new Twig_Filter_Function('twig_get_class'));
28
- $twig->addFilter('function', new Twig_Filter_Function(array(&$this, 'exec_function')));
29
-
30
- $twig->addFilter('get_type', new Twig_Filter_Function('twig_get_type'));
31
- $twig->addFilter('shortcodes', new Twig_Filter_Function('twig_shortcodes'));
32
- $twig->addFilter('sanitize', new Twig_Filter_Function('sanitize_title'));
33
- $twig->addFilter('pretags', new Twig_Filter_Function(array(&$this, 'twig_pretags')));
34
  $twig->addFilter('wp_body_class', new Twig_Filter_Function('twig_body_class'));
35
- $twig->addFilter('time_ago', new Twig_Filter_Function('twig_time_ago'));
 
36
 
37
  $twig->addFunction('bloginfo', new Twig_SimpleFunction('bloginfo', function($show = '', $filter = 'raw'){
38
  return get_bloginfo($show, $filter);
11
  * @return Twig_Environment
12
  */
13
  function add_twig_filters($twig) {
14
+ /* image filters */
15
  $twig->addFilter('resize', new Twig_Filter_Function(array('WPImageHelper', 'resize')));
16
  $twig->addFilter('letterbox', new Twig_Filter_Function('wp_resize_letterbox'));
17
+ $twig->addFilter('tojpg', new Twig_Filter_Function(array('WPImageHelper', 'img_to_jpg')));
18
+ $twig->addFilter('get_src_from_attachment_id', new Twig_Filter_Function('twig_get_src_from_attachment_id'));
19
+
20
+ /* debugging filters */
21
+ $twig->addFilter('docs', new Twig_Filter_function('twig_object_docs'));
22
+ $twig->addFilter('get_class', new Twig_Filter_Function('twig_get_class'));
23
+ $twig->addFilter('get_type', new Twig_Filter_Function('twig_get_type'));
24
  $twig->addFilter('print_r', new Twig_Filter_Function('twig_print_r'));
25
  $twig->addFilter('print_a', new Twig_Filter_Function('twig_print_a'));
 
26
 
27
+ /* other filters */
28
+ $twig->addFilter('excerpt', new Twig_Filter_Function('twig_make_excerpt'));
29
+ $twig->addFilter('function', new Twig_Filter_Function(array(&$this, 'exec_function')));
30
  $twig->addFilter('path', new Twig_Filter_Function('twig_get_path'));
31
+ $twig->addFilter('pretags', new Twig_Filter_Function(array(&$this, 'twig_pretags')));
32
+ $twig->addFilter('sanitize', new Twig_Filter_Function('sanitize_title'));
33
+ $twig->addFilter('shortcodes', new Twig_Filter_Function('twig_shortcodes'));
34
+ $twig->addFilter('time_ago', new Twig_Filter_Function('twig_time_ago'));
35
  $twig->addFilter('twitterify', new Twig_Filter_Function(array('WPHelper', 'twitterify')));
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);
functions/functions-wp-helper.php CHANGED
@@ -25,9 +25,12 @@ class WPHelper {
25
  }
26
 
27
  public static function is_url($url) {
 
 
 
28
  $url = strtolower($url);
29
  if (strstr('://', $url)) {
30
- return true;
31
  }
32
  return false;
33
  }
@@ -386,7 +389,7 @@ class WPHelper {
386
  $n_display = number_format_i18n($n);
387
  if ( $n == $current ) :
388
  //$page_links[] = "<span class='page-numbers current'>$n_display</span>";
389
- $page_links[] = array('class' => 'page-number current', 'text' => $n_display);
390
  $dots = true;
391
  else :
392
  if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
25
  }
26
 
27
  public static function is_url($url) {
28
+ if (!is_string($url)){
29
+ return false;
30
+ }
31
  $url = strtolower($url);
32
  if (strstr('://', $url)) {
33
+ return true;
34
  }
35
  return false;
36
  }
389
  $n_display = number_format_i18n($n);
390
  if ( $n == $current ) :
391
  //$page_links[] = "<span class='page-numbers current'>$n_display</span>";
392
+ $page_links[] = array('class' => 'page-number current', 'title' => $n_display, 'text' => $n_display);
393
  $dots = true;
394
  else :
395
  if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
functions/functions-wp-image-helper.php CHANGED
@@ -27,24 +27,24 @@
27
  return $filename;
28
  }
29
 
30
- public static function sideloaded_file_loc($file){
31
  $upload = wp_upload_dir();
32
  $dir = $upload['path'];
 
33
  $file = parse_url($file);
34
  $path_parts = pathinfo($file['path']);
35
- $basename = $path_parts['filename'];
36
  $ext = $path_parts['extension'];
37
- $old_root_path = $dir . '/' . $basename. '.' . $ext;
38
- if (file_exists($old_root_path)){
39
- return str_replace($_SERVER['DOCUMENT_ROOT'], '', $old_root_path);
40
- }
41
- return false;
42
  }
43
 
44
  public static function sideload_image($file) {
45
- if ($loc = self::sideloaded_file_loc($file)){
46
- return $loc;
 
 
47
  }
 
48
  require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-admin/includes/file.php');
49
  require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-admin/includes/media.php');
50
  // Download file to temp location
@@ -59,9 +59,9 @@
59
  $file_array['tmp_name'] = '';
60
  }
61
  // do the validation and storage stuff
62
- $file = wp_upload_bits($file_array['name'], null, file_get_contents($file_array['tmp_name']));
63
- $file['path'] = str_replace($_SERVER['DOCUMENT_ROOT'], '', $file['file']);
64
- return $file['path'];
65
  }
66
 
67
  public static function resize($src, $w, $h = 0){
27
  return $filename;
28
  }
29
 
30
+ public static function get_sideloaded_file_loc($file){
31
  $upload = wp_upload_dir();
32
  $dir = $upload['path'];
33
+ $filename = $file;
34
  $file = parse_url($file);
35
  $path_parts = pathinfo($file['path']);
36
+ $basename = base64_encode($filename);
37
  $ext = $path_parts['extension'];
38
+ return $dir . '/' . $basename. '.' . $ext;
 
 
 
 
39
  }
40
 
41
  public static function sideload_image($file) {
42
+ $loc = self::get_sideloaded_file_loc($file);
43
+ if (file_exists($loc)){
44
+ error_log('already exists');
45
+ return str_replace($_SERVER['DOCUMENT_ROOT'], '', $loc);
46
  }
47
+ error_log('make a new one');
48
  require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-admin/includes/file.php');
49
  require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-admin/includes/media.php');
50
  // Download file to temp location
59
  $file_array['tmp_name'] = '';
60
  }
61
  // do the validation and storage stuff
62
+ $locinfo = pathinfo($loc);
63
+ $file = wp_upload_bits($locinfo['basename'], null, file_get_contents($file_array['tmp_name']));
64
+ return $file['url'];
65
  }
66
 
67
  public static function resize($src, $w, $h = 0){
functions/timber-menu.php CHANGED
@@ -3,17 +3,22 @@
3
  class TimberMenu extends TimberCore {
4
 
5
  var $items = null;
 
 
6
 
7
  function __construct($slug) {
8
- $menu_id = $slug;
9
- if (!is_numeric($slug)){
10
- $locations = get_nav_menu_locations();
11
- $menu_id = wp_get_nav_menu_object($locations[$slug]);
12
  }
13
- if (isset($locations[$slug]) || is_numeric($menu_id)) {
 
14
  $menu = wp_get_nav_menu_items($menu_id);
15
  $menu = self::order_children($menu);
16
  $this->items = $menu;
 
 
 
17
  } else {
18
  WPHelper::error_log("Sorry, the menu you were looking for wasn't found ('".$slug."'). Here's what Timber did find:");
19
  WPHelper::error_log($locations);
3
  class TimberMenu extends TimberCore {
4
 
5
  var $items = null;
6
+ var $name = null;
7
+ var $ID = null;
8
 
9
  function __construct($slug) {
10
+ $locations = get_nav_menu_locations();
11
+ if (is_numeric($slug)){
12
+ $slug = array_search($slug, $locations);
 
13
  }
14
+ if (isset($locations[$slug])) {
15
+ $menu_id = $locations[$slug];
16
  $menu = wp_get_nav_menu_items($menu_id);
17
  $menu = self::order_children($menu);
18
  $this->items = $menu;
19
+ $menu_info = wp_get_nav_menu_object($menu_id);
20
+ $this->import($menu_info);
21
+ $this->ID = $this->term_id;
22
  } else {
23
  WPHelper::error_log("Sorry, the menu you were looking for wasn't found ('".$slug."'). Here's what Timber did find:");
24
  WPHelper::error_log($locations);
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.12.0
6
  Tested up to: 3.6
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.12.1 =
41
  * A few fixes that catch issues with absolute vs. relative URLs in resize
42
 
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.5
5
+ Stable tag: 0.12.2
6
  Tested up to: 3.6
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
37
 
38
  == Changelog ==
39
 
40
+ = 0.12.2 =
41
+ * TimberMenus now contain metadata 'bout the menu (thanks @bryanaka)
42
+ * Fixed issue with Windows servers (thanks @kzykhys)
43
+ * Resizing external images now incl. the full URL to avoid conflicts
44
+ * Fixed pagination oddity
45
+ * Some code cleanup stuff.
46
+
47
  = 0.12.1 =
48
  * A few fixes that catch issues with absolute vs. relative URLs in resize
49
 
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.12.1
7
  Author URI: http://timber.upstatement.com/
8
  */
9
 
@@ -61,6 +61,7 @@ class Timber {
61
  $plugin_url_path = str_replace('https://', '', $plugin_url_path);
62
  $plugin_url_path = str_replace('http://', '', $plugin_url_path);
63
  $timber_dirs = dirname(__FILE__);
 
64
  $timber_dirs = explode('/', $timber_dirs);
65
  $timber_dirname = array_pop($timber_dirs);
66
  define("TIMBER", $timber_loc);
@@ -406,8 +407,14 @@ class Timber {
406
  $args['prev_next'] = false;
407
  $args = array_merge($args, $prefs);
408
  $data['pages'] = WPHelper::paginate_links($args);
409
- $data['next'] = array('link' => next_posts($args['total'], false));
410
- $data['prev'] = array('link' => previous_posts(false));
 
 
 
 
 
 
411
  if ($paged < 2){
412
  $data['prev'] = '';
413
  }
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.12.2
7
  Author URI: http://timber.upstatement.com/
8
  */
9
 
61
  $plugin_url_path = str_replace('https://', '', $plugin_url_path);
62
  $plugin_url_path = str_replace('http://', '', $plugin_url_path);
63
  $timber_dirs = dirname(__FILE__);
64
+ $timber_dirs = str_replace('\\', '/', $timber_dirs);
65
  $timber_dirs = explode('/', $timber_dirs);
66
  $timber_dirname = array_pop($timber_dirs);
67
  define("TIMBER", $timber_loc);
407
  $args['prev_next'] = false;
408
  $args = array_merge($args, $prefs);
409
  $data['pages'] = WPHelper::paginate_links($args);
410
+ $next = next_posts($args['total'], false);
411
+ if ($next){
412
+ $data['next'] = array('link' => $next);
413
+ }
414
+ $prev = previous_posts(false);
415
+ if ($prev){
416
+ $data['prev'] = array('link' => $prev);
417
+ }
418
  if ($paged < 2){
419
  $data['prev'] = '';
420
  }