Timber - Version 0.21.7

Version Description

  • Fix for Image src in some situtations
Download this release

Release Info

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

Code changes from version 0.21.6 to 0.21.7

lib/timber-image-helper.php CHANGED
@@ -123,14 +123,13 @@ class TimberImageHelper {
123
  /**
124
  * Deletes all resized versions of an image when the source is deleted
125
  */
126
- static function add_actions() {
127
  add_action( 'delete_post', function ( $post_id ) {
128
  $post = get_post( $post_id );
129
  $image_types = array( 'image/jpeg', 'image/png', 'image/gif', 'image/jpg' );
130
  if ( $post->post_type == 'attachment' && in_array( $post->post_mime_type, $image_types ) ) {
131
  $attachment = new TimberImage( $post_id );
132
- TimberImageHelper::delete_resized_files( $attachment->file_loc );
133
- TimberImageHelper::delete_letterboxed_files( $attachment->file_loc );
134
  }
135
  } );
136
  }
@@ -139,7 +138,7 @@ class TimberImageHelper {
139
  * Adds a constant defining the path to the content directory relative to the site
140
  * for example /wp-content or /content
141
  */
142
- static function add_constants() {
143
  if ( !defined( 'WP_CONTENT_SUBDIR' ) ) {
144
  $wp_content_path = str_replace( home_url(), '', WP_CONTENT_URL );
145
  define( 'WP_CONTENT_SUBDIR', $wp_content_path );
@@ -159,16 +158,12 @@ class TimberImageHelper {
159
  }
160
 
161
  //-- end of public methods --//
162
-
163
-
164
  /**
165
- * Deletes resized versions of the supplied file name.
166
- * So if passed a value like my-pic.jpg, this function will delete my-pic-500x200-c-left.jpg, my-pic-400x400-c-default.jpg, etc.
167
- *
168
  * @param string $local_file ex: /var/www/wp-content/uploads/2015/my-pic.jpg
169
- * ex: http://example.org/wp-content/uploads/2015/foo.png
170
  */
171
- static function delete_resized_files( $local_file ) {
172
  if (TimberURLHelper::is_absolute( $local_file ) ) {
173
  $local_file = TimberURLHelper::url_to_file_system( $local_file );
174
  }
@@ -176,37 +171,29 @@ class TimberImageHelper {
176
  $dir = $info['dirname'];
177
  $ext = $info['extension'];
178
  $filename = $info['filename'];
179
- $searcher = '/' . $filename . '-[0-9999999]*';
180
- foreach ( glob( $dir . $searcher ) as $found_file ) {
181
- $regexdir = str_replace( '/', '\/', $dir );
182
- $pattern = '/' . ( $regexdir ) . '\/' . $filename . '-[0-9]*x[0-9]*-c-[a-z]*.' . $ext . '/';
183
- $match = preg_match( $pattern, $found_file );
184
- //keeping these here so I know what the hell we're matching
185
- //$match = preg_match("/\/srv\/www\/wordpress-develop\/src\/wp-content\/uploads\/2014\/05\/$filename-[0-9]*x[0-9]*-c-[a-z]*.jpg/", $found_file);
186
- //$match = preg_match("/\/srv\/www\/wordpress-develop\/src\/wp-content\/uploads\/2014\/05\/arch-[0-9]*x[0-9]*-c-[a-z]*.jpg/", $filename);
187
- if ( $match ) {
188
- unlink( $found_file );
189
- }
190
- }
191
  }
192
 
193
  /**
194
- * Deletes letterboxed versions of the supplied file name
 
195
  *
196
- * @param string $local_file
 
 
 
 
 
 
 
 
197
  */
198
- static function delete_letterboxed_files( $local_file ) {
199
- if (TimberURLHelper::is_absolute( $local_file ) ) {
200
- $local_file = TimberURLHelper::url_to_file_system( $local_file );
201
- }
202
- $info = pathinfo( $local_file );
203
- $dir = $info['dirname'];
204
- $ext = $info['extension'];
205
- $filename = $info['filename'];
206
- $searcher = '/' . $filename . '-lbox-[0-9999999]*';
207
  foreach ( glob( $dir . $searcher ) as $found_file ) {
208
  $regexdir = str_replace( '/', '\/', $dir );
209
- $pattern = '/' . ( $regexdir ) . '\/' . $filename . '-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.' . $ext . '/';
210
  $match = preg_match( $pattern, $found_file );
211
  if ( $match ) {
212
  unlink( $found_file );
123
  /**
124
  * Deletes all resized versions of an image when the source is deleted
125
  */
126
+ protected static function add_actions() {
127
  add_action( 'delete_post', function ( $post_id ) {
128
  $post = get_post( $post_id );
129
  $image_types = array( 'image/jpeg', 'image/png', 'image/gif', 'image/jpg' );
130
  if ( $post->post_type == 'attachment' && in_array( $post->post_mime_type, $image_types ) ) {
131
  $attachment = new TimberImage( $post_id );
132
+ TimberImageHelper::delete_generated_files( $attachment->file_loc );
 
133
  }
134
  } );
135
  }
138
  * Adds a constant defining the path to the content directory relative to the site
139
  * for example /wp-content or /content
140
  */
141
+ protected static function add_constants() {
142
  if ( !defined( 'WP_CONTENT_SUBDIR' ) ) {
143
  $wp_content_path = str_replace( home_url(), '', WP_CONTENT_URL );
144
  define( 'WP_CONTENT_SUBDIR', $wp_content_path );
158
  }
159
 
160
  //-- end of public methods --//
 
 
161
  /**
162
+ * Deletes the auto-generated files for resize and letterboxing created by Timber
 
 
163
  * @param string $local_file ex: /var/www/wp-content/uploads/2015/my-pic.jpg
164
+ * or: http://example.org/wp-content/uploads/2015/my-pic.jpg
165
  */
166
+ static function delete_generated_files( $local_file ) {
167
  if (TimberURLHelper::is_absolute( $local_file ) ) {
168
  $local_file = TimberURLHelper::url_to_file_system( $local_file );
169
  }
171
  $dir = $info['dirname'];
172
  $ext = $info['extension'];
173
  $filename = $info['filename'];
174
+ self::process_delete_generated_files( $filename, $ext, $dir, '-[0-9999999]*', '-[0-9]*x[0-9]*-c-[a-z]*.' );
175
+ self::process_delete_generated_files( $filename, $ext, $dir, '-lbox-[0-9999999]*', '-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.' );
 
 
 
 
 
 
 
 
 
 
176
  }
177
 
178
  /**
179
+ * Deletes resized versions of the supplied file name.
180
+ * So if passed a value like my-pic.jpg, this function will delete my-pic-500x200-c-left.jpg, my-pic-400x400-c-default.jpg, etc.
181
  *
182
+ * keeping these here so I know what the hell we're matching
183
+ * $match = preg_match("/\/srv\/www\/wordpress-develop\/src\/wp-content\/uploads\/2014\/05\/$filename-[0-9]*x[0-9]*-c-[a-z]*.jpg/", $found_file);
184
+ * $match = preg_match("/\/srv\/www\/wordpress-develop\/src\/wp-content\/uploads\/2014\/05\/arch-[0-9]*x[0-9]*-c-[a-z]*.jpg/", $filename);
185
+ *
186
+ * @param string $filename ex: my-pic
187
+ * @param string $ext ex: jpg
188
+ * @param string $dir var/www/wp-content/uploads/2015/
189
+ * @param string $search_pattern pattern of files to pluck from
190
+ * @param string $match_pattern pattern of files to go forth and delete
191
  */
192
+ protected static function process_delete_generated_files( $filename, $ext, $dir, $search_pattern, $match_pattern ) {
193
+ $searcher = '/' . $filename . $search_pattern;
 
 
 
 
 
 
 
194
  foreach ( glob( $dir . $searcher ) as $found_file ) {
195
  $regexdir = str_replace( '/', '\/', $dir );
196
+ $pattern = '/' . ( $regexdir ) . '\/' . $filename . $match_pattern . $ext . '/';
197
  $match = preg_match( $pattern, $found_file );
198
  if ( $match ) {
199
  unlink( $found_file );
lib/timber-image.php CHANGED
@@ -25,12 +25,13 @@ class TimberImage extends TimberPost implements TimberCoreInterface {
25
  }
26
 
27
  /**
28
- * @return string|null
29
  */
30
  function __toString() {
31
  if ($this->get_src()) {
32
  return $this->get_src();
33
  }
 
34
  }
35
 
36
  /**
@@ -112,6 +113,7 @@ class TimberImage extends TimberPost implements TimberCoreInterface {
112
  $base = ($dir["baseurl"]);
113
 
114
  $src = trailingslashit($this->_maybe_secure_url($base)) . $this->file;
 
115
  return apply_filters('timber_image_src', $src);
116
  }
117
 
25
  }
26
 
27
  /**
28
+ * @return string
29
  */
30
  function __toString() {
31
  if ($this->get_src()) {
32
  return $this->get_src();
33
  }
34
+ return '';
35
  }
36
 
37
  /**
113
  $base = ($dir["baseurl"]);
114
 
115
  $src = trailingslashit($this->_maybe_secure_url($base)) . $this->file;
116
+ $src = apply_filters('timber/image/src', $src);
117
  return apply_filters('timber_image_src', $src);
118
  }
119
 
lib/timber-menu-item.php CHANGED
@@ -6,6 +6,7 @@ class TimberMenuItem extends TimberCore implements TimberCoreInterface {
6
  public $has_child_class = false;
7
  public $classes = array();
8
  public $class = '';
 
9
  public $post_name;
10
  public $type;
11
  public $url;
@@ -123,6 +124,19 @@ class TimberMenuItem extends TimberCore implements TimberCoreInterface {
123
  $this->children = array();
124
  }
125
  $this->children[] = $item;
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  }
127
 
128
  /**
6
  public $has_child_class = false;
7
  public $classes = array();
8
  public $class = '';
9
+ public $level = 0;
10
  public $post_name;
11
  public $type;
12
  public $url;
124
  $this->children = array();
125
  }
126
  $this->children[] = $item;
127
+ $item->level = $this->level + 1;
128
+ if ($item->children) {
129
+ $this->update_child_levels();
130
+ }
131
+ }
132
+
133
+ public function update_child_levels() {
134
+ if (is_array($this->children)) {
135
+ foreach( $this->children as $child ) {
136
+ $child->level = $this->level + 1;
137
+ $child->update_child_levels();
138
+ }
139
+ }
140
  }
141
 
142
  /**
lib/timber-post.php CHANGED
@@ -255,6 +255,7 @@ class TimberPost extends TimberCore implements TimberCoreInterface {
255
  if ($readmore) {
256
  $text .= ' <a href="' . $this->get_permalink() . '" class="read-more">' . $readmore . '</a>';
257
  }
 
258
  if (!$strip) {
259
  $text .= '</p>';
260
  }
255
  if ($readmore) {
256
  $text .= ' <a href="' . $this->get_permalink() . '" class="read-more">' . $readmore . '</a>';
257
  }
258
+
259
  if (!$strip) {
260
  $text .= '</p>';
261
  }
lib/timber-twig.php CHANGED
@@ -132,6 +132,44 @@ class TimberTwig {
132
  return new $UserClass( $pid );
133
  } ) );
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  /* bloginfo and translate */
136
  $twig->addFunction( 'bloginfo', new Twig_SimpleFunction( 'bloginfo', function ( $show = '', $filter = 'raw' ) {
137
  return get_bloginfo( $show, $filter );
132
  return new $UserClass( $pid );
133
  } ) );
134
 
135
+ /* TimberObjects Alias */
136
+ $twig->addFunction( new Twig_SimpleFunction( 'Post', function ( $pid, $PostClass = 'TimberPost' ) {
137
+ if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
138
+ foreach ( $pid as &$p ) {
139
+ $p = new $PostClass( $p );
140
+ }
141
+ return $pid;
142
+ }
143
+ return new $PostClass( $pid );
144
+ } ) );
145
+ $twig->addFunction( new Twig_SimpleFunction( 'Image', function ( $pid, $ImageClass = 'TimberImage' ) {
146
+ if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
147
+ foreach ( $pid as &$p ) {
148
+ $p = new $ImageClass( $p );
149
+ }
150
+ return $pid;
151
+ }
152
+ return new $ImageClass( $pid );
153
+ } ) );
154
+ $twig->addFunction( new Twig_SimpleFunction( 'Term', function ( $pid, $TermClass = 'TimberTerm' ) {
155
+ if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
156
+ foreach ( $pid as &$p ) {
157
+ $p = new $TermClass( $p );
158
+ }
159
+ return $pid;
160
+ }
161
+ return new $TermClass( $pid );
162
+ } ) );
163
+ $twig->addFunction( new Twig_SimpleFunction( 'User', function ( $pid, $UserClass = 'TimberUser' ) {
164
+ if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
165
+ foreach ( $pid as &$p ) {
166
+ $p = new $UserClass( $p );
167
+ }
168
+ return $pid;
169
+ }
170
+ return new $UserClass( $pid );
171
+ } ) );
172
+
173
  /* bloginfo and translate */
174
  $twig->addFunction( 'bloginfo', new Twig_SimpleFunction( 'bloginfo', function ( $show = '', $filter = 'raw' ) {
175
  return get_bloginfo( $show, $filter );
lib/timber-user.php CHANGED
@@ -25,10 +25,10 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
25
  */
26
  function __toString() {
27
  $name = $this->name();
28
- if (strlen($name)) {
29
  return $name;
30
  }
31
- if (strlen($this->name)) {
32
  return $this->name;
33
  }
34
  return '';
@@ -39,7 +39,7 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
39
  * @return null
40
  */
41
  function get_meta($field_name) {
42
- return $this->get_meta_field( $field_name );
43
  }
44
 
45
  /**
@@ -47,7 +47,7 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
47
  * @param mixed $value
48
  */
49
  function __set($field, $value) {
50
- if ($field == 'name') {
51
  $this->display_name = $value;
52
  }
53
  $this->$field = $value;
@@ -57,7 +57,7 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
57
  * @return string
58
  */
59
  public function get_link() {
60
- if (!$this->_link) {
61
  $this->_link = untrailingslashit(get_author_posts_url($this->ID));
62
  }
63
  return $this->_link;
@@ -67,21 +67,23 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
67
  * @param int|bool $uid
68
  */
69
  function init($uid = false) {
70
- if ($uid === false) {
71
  $uid = get_current_user_id();
72
  }
73
- if (is_object($uid) || is_array($uid)){
74
  $data = $uid;
75
- if (is_array($uid)){
76
- $data = (object) $uid;
77
  }
78
  $uid = $data->ID;
79
  }
80
- if (is_numeric($uid)) {
81
  $data = get_userdata($uid);
 
 
82
  }
83
- if (isset($data) && is_object($data)) {
84
- if (isset($data->data)){
85
  $this->import($data->data);
86
  } else {
87
  $this->import($data);
@@ -99,7 +101,7 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
99
  function get_meta_field($field_name) {
100
  $value = null;
101
  $value = apply_filters('timber_user_get_meta_field_pre', $value, $this->ID, $field_name, $this);
102
- if ($value === null) {
103
  $value = get_user_meta($this->ID, $field_name, true);
104
  }
105
  $value = apply_filters('timber_user_get_meta_field', $value, $this->ID, $field_name, $this);
@@ -110,15 +112,15 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
110
  * @return array|null
111
  */
112
  function get_custom() {
113
- if ($this->ID) {
114
  $um = array();
115
  $um = apply_filters('timber_user_get_meta_pre', $um, $this->ID, $this);
116
- if (empty($um)) {
117
  $um = get_user_meta($this->ID);
118
  }
119
  $custom = array();
120
  foreach ($um as $key => $value) {
121
- if (is_array($value) && count($value) == 1) {
122
  $value = $value[0];
123
  }
124
  $custom[$key] = maybe_unserialize($value);
25
  */
26
  function __toString() {
27
  $name = $this->name();
28
+ if ( strlen($name) ) {
29
  return $name;
30
  }
31
+ if ( strlen($this->name) ) {
32
  return $this->name;
33
  }
34
  return '';
39
  * @return null
40
  */
41
  function get_meta($field_name) {
42
+ return $this->get_meta_field($field_name);
43
  }
44
 
45
  /**
47
  * @param mixed $value
48
  */
49
  function __set($field, $value) {
50
+ if ( $field == 'name' ) {
51
  $this->display_name = $value;
52
  }
53
  $this->$field = $value;
57
  * @return string
58
  */
59
  public function get_link() {
60
+ if ( !$this->_link ) {
61
  $this->_link = untrailingslashit(get_author_posts_url($this->ID));
62
  }
63
  return $this->_link;
67
  * @param int|bool $uid
68
  */
69
  function init($uid = false) {
70
+ if ( $uid === false ) {
71
  $uid = get_current_user_id();
72
  }
73
+ if ( is_object($uid) || is_array($uid) ) {
74
  $data = $uid;
75
+ if ( is_array($uid) ) {
76
+ $data = (object) $uid;
77
  }
78
  $uid = $data->ID;
79
  }
80
+ if ( is_numeric($uid) ) {
81
  $data = get_userdata($uid);
82
+ } else if ( is_string($uid) ) {
83
+ $data = get_user_by('login', $uid);
84
  }
85
+ if ( isset($data) && is_object($data) ) {
86
+ if ( isset($data->data) ) {
87
  $this->import($data->data);
88
  } else {
89
  $this->import($data);
101
  function get_meta_field($field_name) {
102
  $value = null;
103
  $value = apply_filters('timber_user_get_meta_field_pre', $value, $this->ID, $field_name, $this);
104
+ if ( $value === null ) {
105
  $value = get_user_meta($this->ID, $field_name, true);
106
  }
107
  $value = apply_filters('timber_user_get_meta_field', $value, $this->ID, $field_name, $this);
112
  * @return array|null
113
  */
114
  function get_custom() {
115
+ if ( $this->ID ) {
116
  $um = array();
117
  $um = apply_filters('timber_user_get_meta_pre', $um, $this->ID, $this);
118
+ if ( empty($um) ) {
119
  $um = get_user_meta($this->ID);
120
  }
121
  $custom = array();
122
  foreach ($um as $key => $value) {
123
+ if ( is_array($value) && count($value) == 1 ) {
124
  $value = $value[0];
125
  }
126
  $custom[$key] = maybe_unserialize($value);
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.7
5
- Stable tag: 0.21.5
6
  Tested up to: 4.2.2
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
@@ -41,6 +41,9 @@ Timber is great for any WordPress developer who cares about writing good, mainta
41
 
42
  == Changelog ==
43
 
 
 
 
44
  = 0.21.6 =
45
  * Fix for TimberMenu visiblility
46
  * Fix for TimberComment visibility
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.7
5
+ Stable tag: 0.21.7
6
  Tested up to: 4.2.2
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
41
 
42
  == Changelog ==
43
 
44
+ = 0.21.7 =
45
+ * Fix for Image src in some situtations
46
+
47
  = 0.21.6 =
48
  * Fix for TimberMenu visiblility
49
  * Fix for TimberComment visibility
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.21.6
8
  Author URI: http://upstatement.com/
9
  */
10
 
@@ -249,6 +249,7 @@ class Timber {
249
  }
250
  }
251
  $data = apply_filters( 'timber_context', $data );
 
252
  return $data;
253
  }
254
 
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.21.7
8
  Author URI: http://upstatement.com/
9
  */
10
 
249
  }
250
  }
251
  $data = apply_filters( 'timber_context', $data );
252
+ $data = apply_filters( 'timber/context', $data );
253
  return $data;
254
  }
255
 
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer' . '/autoload_real.php';
6
 
7
- return ComposerAutoloaderInitda967d47ec325ce56e659cd9fd82bee1::getLoader();
4
 
5
  require_once __DIR__ . '/composer' . '/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInit893f1d80a50bb5946e39eb5610c579ee::getLoader();
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInitda967d47ec325ce56e659cd9fd82bee1
6
  {
7
  private static $loader;
8
 
@@ -19,9 +19,9 @@ class ComposerAutoloaderInitda967d47ec325ce56e659cd9fd82bee1
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInitda967d47ec325ce56e659cd9fd82bee1', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInitda967d47ec325ce56e659cd9fd82bee1', 'loadClassLoader'));
25
 
26
  $map = require __DIR__ . '/autoload_namespaces.php';
27
  foreach ($map as $namespace => $path) {
@@ -44,7 +44,7 @@ class ComposerAutoloaderInitda967d47ec325ce56e659cd9fd82bee1
44
  }
45
  }
46
 
47
- function composerRequireda967d47ec325ce56e659cd9fd82bee1($file)
48
  {
49
  require $file;
50
  }
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInit893f1d80a50bb5946e39eb5610c579ee
6
  {
7
  private static $loader;
8
 
19
  return self::$loader;
20
  }
21
 
22
+ spl_autoload_register(array('ComposerAutoloaderInit893f1d80a50bb5946e39eb5610c579ee', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInit893f1d80a50bb5946e39eb5610c579ee', 'loadClassLoader'));
25
 
26
  $map = require __DIR__ . '/autoload_namespaces.php';
27
  foreach ($map as $namespace => $path) {
44
  }
45
  }
46
 
47
+ function composerRequire893f1d80a50bb5946e39eb5610c579ee($file)
48
  {
49
  require $file;
50
  }