Timber - Version 0.12.0

Version Description

  • Pagination is refactored to be more intutitve, and well, better.
  • Resize is also refactored to respect absolute vs. relative URLs
  • Got rid of lots of old, bogus code.
Download this release

Release Info

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

Code changes from version 0.11.0 to 0.12.0

functions/functions-twig.php CHANGED
@@ -11,7 +11,7 @@ class TimberTwig {
11
  * @return Twig_Environment
12
  */
13
  function add_twig_filters($twig) {
14
- $twig->addFilter('resize', new Twig_Filter_Function('wp_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'));
@@ -32,14 +32,13 @@ class TimberTwig {
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('wp_title', new Twig_Filter_Function('twig_wp_title'));
36
  $twig->addFilter('time_ago', new Twig_Filter_Function('twig_time_ago'));
37
 
38
  $twig->addFunction('bloginfo', new Twig_SimpleFunction('bloginfo', function($show = '', $filter = 'raw'){
39
- return get_bloginfo($show, $filter);
40
  }));
41
  $twig->addFunction('__', new Twig_SimpleFunction('__', function($text, $domain = 'default'){
42
- return __($text, $domain);
43
  }));
44
 
45
  $twig = apply_filters('get_twig', $twig);
@@ -82,23 +81,6 @@ class TimberTwig {
82
  return false;
83
  }
84
 
85
- function twig_choose_template($filenames, $dirs) {
86
- if (is_array($filenames)) {
87
- /* its an array so we have to figure out which one the dev wants */
88
- foreach ($filenames as $filename) {
89
- if (self::template_exists($filename, $dirs)) {
90
- return $filename;
91
- }
92
- }
93
- return false;
94
- } else {
95
- /* its a single, but we still need to figure out if it exists, default to index.html */
96
- // if (!twig_template_exists($filenames, $dirs)){
97
- // $filenames = 'index.html';
98
- // }
99
- }
100
- return $filenames;
101
- }
102
  }
103
 
104
  function twig_shortcodes($text) {
@@ -114,30 +96,6 @@ function twig_get_type($this) {
114
  return gettype($this);
115
  }
116
 
117
- function wp_resize_external($src, $w, $h) {
118
- $upload = wp_upload_dir();
119
- $dir = $upload['path'];
120
- $file = parse_url($src);
121
- $path_parts = pathinfo($file['path']);
122
- $basename = $path_parts['filename'];
123
- $newbase = $basename . '-r-' . $w . 'x' . $h;
124
- $ext = $path_parts['extension'];
125
-
126
- $new_root_path = $dir . '/' . $newbase . '.' . $ext;
127
-
128
- $new_path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $new_root_path);
129
- if (strpos($new_path, '/') != 0) {
130
- $new_path = '/' . $new_path;
131
- }
132
- $ret = array('new_root_path' => $new_root_path, 'old_root_path' => $dir . '/' . $basename . '.' . $ext, 'new_path' => $new_path);
133
-
134
- if (file_exists($new_root_path)) {
135
- return $ret;
136
- }
137
- $image = WPHelper::sideload_image($src);
138
- return $ret;
139
- }
140
-
141
  function hexrgb($hexstr) {
142
  $int = hexdec($hexstr);
143
  return array("red" => 0xFF & ($int >> 0x10), "green" => 0xFF & ($int >> 0x8), "blue" => 0xFF & $int);
@@ -160,99 +118,43 @@ function wp_resize_letterbox($src, $w, $h, $color = '#000000') {
160
  imagefill($bg, 0, 0, $white);
161
 
162
  $image = wp_get_image_editor($old_file);
163
- if (!is_wp_error($image)) {
164
- $current_size = $image->get_size();
165
- $ow = $current_size['width'];
166
- $oh = $current_size['height'];
167
- $new_aspect = $w / $h;
168
- $old_aspect = $ow / $oh;
169
- if ($new_aspect > $old_aspect) {
170
- //taller than goal
171
- $h_scale = $h / $oh;
172
- $owt = $ow * $h_scale;
173
- $y = 0;
174
- $x = $w / 2 - $owt / 2;
175
- $oht = $h;
176
- $image->crop(0, 0, $ow, $oh, $owt, $oht);
177
- } else {
178
- $w_scale = $w / $ow;
179
- $oht = $oh * $w_scale;
180
- $x = 0;
181
- $y = $h / 2 - $oht / 2;
182
- $owt = $w;
183
- $image->crop(0, 0, $ow, $oh, $owt, $oht);
184
- }
185
- $image->save($new_file);
186
- $func = 'imagecreatefromjpeg';
187
- $ext = pathinfo($new_file, PATHINFO_EXTENSION);
188
- if ($ext == 'gif') {
189
- $func = 'imagecreatefromgif';
190
- } else if ($ext == 'png') {
191
- $func = 'imagecreatefrompng';
192
- }
193
- $image = $func($new_file);
194
- imagecopy($bg, $image, $x, $y, 0, 0, $owt, $oht);
195
- $new_file = str_replace('-lb-', '-lbox-', $new_file);
196
- imagejpeg($bg, $new_file);
197
- return WPHelper::get_rel_path($new_file);
198
- }
199
- return null;
200
- }
201
-
202
- function wp_resize($src, $w, $h = 0) {
203
- $root = $_SERVER['DOCUMENT_ROOT'];
204
- if (strstr($src, 'http')) {
205
- //Its a URL so we need to fetch it
206
- $external = wp_resize_external($src, $w, $h);
207
- $old_root_path = $external['old_root_path'];
208
- $new_root_path = $external['new_root_path'];
209
- $new_path = $external['new_path'];
210
- } else {
211
- //oh good, its in the uploads folder!
212
- $path_parts = pathinfo($src);
213
- $basename = $path_parts['filename'];
214
- $ext = $path_parts['extension'];
215
- $dir = $path_parts['dirname'];
216
- $newbase = $basename . '-r-' . $w . 'x' . $h;
217
- $new_path = $dir . '/' . $newbase . '.' . $ext;
218
- $new_root_path = $root . $new_path;
219
- $old_root_path = $root . $src;
220
-
221
- $old_root_path = str_replace('//', '/', $old_root_path);
222
- $new_root_path = str_replace('//', '/', $new_root_path);
223
-
224
- if (file_exists($new_root_path)) {
225
- return $new_path;
226
- }
227
- }
228
- $image = wp_get_image_editor($old_root_path);
229
- if (!is_wp_error($image)) {
230
- $current_size = $image->get_size();
231
- $ow = $current_size['width'];
232
- $oh = $current_size['height'];
233
- if ($h) {
234
- $new_aspect = $w / $h;
235
- $old_aspect = $ow / $oh;
236
-
237
- if ($new_aspect > $old_aspect) {
238
- //cropping a vertical photo horitzonally
239
- $oht = $ow / $new_aspect;
240
- $oy = ($oh - $oht) / 6;
241
- $image->crop(0, $oy, $ow, $oht, $w, $h);
242
- } else {
243
- $owt = $oh * $new_aspect;
244
- $ox = $ow / 2 - $owt / 2;
245
- $image->crop($ox, 0, $owt, $oh, $w, $h);
246
- }
247
- } else {
248
- $image->resize($w, $w);
249
  }
250
- // $image->
251
- $image->save($new_root_path);
252
- return $new_path;
253
- } else {
254
- return $src;
255
- }
256
  }
257
 
258
  function twig_time_ago($from, $to = null) {
@@ -286,10 +188,6 @@ function twig_time_ago($from, $to = null) {
286
  return $output;
287
  }
288
 
289
- function twig_wp_title() {
290
- return wp_title('|', false, 'right');
291
- }
292
-
293
  function twig_body_class($body_classes) {
294
  ob_start();
295
  if (is_array($body_classes)) {
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'));
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);
39
  }));
40
  $twig->addFunction('__', new Twig_SimpleFunction('__', function($text, $domain = 'default'){
41
+ return __($text, $domain);
42
  }));
43
 
44
  $twig = apply_filters('get_twig', $twig);
81
  return false;
82
  }
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
85
 
86
  function twig_shortcodes($text) {
96
  return gettype($this);
97
  }
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  function hexrgb($hexstr) {
100
  $int = hexdec($hexstr);
101
  return array("red" => 0xFF & ($int >> 0x10), "green" => 0xFF & ($int >> 0x8), "blue" => 0xFF & $int);
118
  imagefill($bg, 0, 0, $white);
119
 
120
  $image = wp_get_image_editor($old_file);
121
+ if (!is_wp_error($image)) {
122
+ $current_size = $image->get_size();
123
+ $ow = $current_size['width'];
124
+ $oh = $current_size['height'];
125
+ $new_aspect = $w / $h;
126
+ $old_aspect = $ow / $oh;
127
+ if ($new_aspect > $old_aspect) {
128
+ //taller than goal
129
+ $h_scale = $h / $oh;
130
+ $owt = $ow * $h_scale;
131
+ $y = 0;
132
+ $x = $w / 2 - $owt / 2;
133
+ $oht = $h;
134
+ $image->crop(0, 0, $ow, $oh, $owt, $oht);
135
+ } else {
136
+ $w_scale = $w / $ow;
137
+ $oht = $oh * $w_scale;
138
+ $x = 0;
139
+ $y = $h / 2 - $oht / 2;
140
+ $owt = $w;
141
+ $image->crop(0, 0, $ow, $oh, $owt, $oht);
142
+ }
143
+ $image->save($new_file);
144
+ $func = 'imagecreatefromjpeg';
145
+ $ext = pathinfo($new_file, PATHINFO_EXTENSION);
146
+ if ($ext == 'gif') {
147
+ $func = 'imagecreatefromgif';
148
+ } else if ($ext == 'png') {
149
+ $func = 'imagecreatefrompng';
150
+ }
151
+ $image = $func($new_file);
152
+ imagecopy($bg, $image, $x, $y, 0, 0, $owt, $oht);
153
+ $new_file = str_replace('-lb-', '-lbox-', $new_file);
154
+ imagejpeg($bg, $new_file);
155
+ return WPHelper::get_rel_path($new_file);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  }
157
+ return null;
 
 
 
 
 
158
  }
159
 
160
  function twig_time_ago($from, $to = null) {
188
  return $output;
189
  }
190
 
 
 
 
 
191
  function twig_body_class($body_classes) {
192
  ob_start();
193
  if (is_array($body_classes)) {
functions/functions-wp-helper.php CHANGED
@@ -9,6 +9,13 @@ class WPHelper {
9
  return (bool)count(array_filter(array_keys($arr), 'is_string'));
10
  }
11
 
 
 
 
 
 
 
 
12
  public static function ob_function($function, $args = array(null)) {
13
  ob_start();
14
  call_user_func_array($function, $args);
@@ -97,31 +104,6 @@ class WPHelper {
97
  return $tmpfname;
98
  }
99
 
100
- public static function sideload_image($file) {
101
- require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-admin/includes/file.php');
102
- require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-admin/includes/media.php');
103
- if (empty($file)) {
104
- error_log('returnning');
105
- return null;
106
- }
107
- // Download file to temp location
108
- $tmp = download_url($file);
109
- preg_match('/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches);
110
- $file_array['name'] = basename($matches[0]);
111
- $file_array['tmp_name'] = $tmp;
112
- // If error storing temporarily, unlink
113
- if (is_wp_error($tmp)) {
114
- error_log('theres an error');
115
- @unlink($file_array['tmp_name']);
116
- $file_array['tmp_name'] = '';
117
- }
118
- error_log('continuing on');
119
- // do the validation and storage stuff
120
- $file = wp_upload_bits($file_array['name'], null, file_get_contents($file_array['tmp_name']));
121
-
122
- return $file;
123
- }
124
-
125
  public static function osort(&$array, $prop) {
126
  usort($array, function ($a, $b) use ($prop) {
127
  return $a->$prop > $b->$prop ? 1 : -1;
@@ -359,4 +341,93 @@ class WPHelper {
359
  return $ret;
360
  }
361
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  }
9
  return (bool)count(array_filter(array_keys($arr), 'is_string'));
10
  }
11
 
12
+ public static function preslashit($path){
13
+ if (strpos($path, '/') != 0) {
14
+ $path = '/' . $path;
15
+ }
16
+ return $path;
17
+ }
18
+
19
  public static function ob_function($function, $args = array(null)) {
20
  ob_start();
21
  call_user_func_array($function, $args);
104
  return $tmpfname;
105
  }
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  public static function osort(&$array, $prop) {
108
  usort($array, function ($a, $b) use ($prop) {
109
  return $a->$prop > $b->$prop ? 1 : -1;
341
  return $ret;
342
  }
343
 
344
+ function paginate_links( $args = '' ) {
345
+ $defaults = array(
346
+ 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
347
+ 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
348
+ 'total' => 1,
349
+ 'current' => 0,
350
+ 'show_all' => false,
351
+ 'prev_next' => true,
352
+ 'prev_text' => __('« Previous'),
353
+ 'next_text' => __('Next »'),
354
+ 'end_size' => 1,
355
+ 'mid_size' => 2,
356
+ 'type' => 'plain',
357
+ 'add_args' => false, // array of query args to add
358
+ 'add_fragment' => ''
359
+ );
360
+
361
+ $args = wp_parse_args( $args, $defaults );
362
+ extract($args, EXTR_SKIP);
363
+
364
+ // Who knows what else people pass in $args
365
+ $total = (int) $total;
366
+ if ( $total < 2 )
367
+ return;
368
+ $current = (int) $current;
369
+ $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
370
+ $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
371
+ $add_args = is_array($add_args) ? $add_args : false;
372
+ $r = '';
373
+ $page_links = array();
374
+ $n = 0;
375
+ $dots = false;
376
+
377
+ if ( $prev_next && $current && 1 < $current ) :
378
+ $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
379
+ $link = str_replace('%#%', $current - 1, $link);
380
+ if ( $add_args )
381
+ $link = add_query_arg( $add_args, $link );
382
+ $link .= $add_fragment;
383
+ $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $prev_text . '</a>';
384
+ endif;
385
+ for ( $n = 1; $n <= $total; $n++ ) :
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 ) ) :
393
+ $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
394
+ $link = str_replace('%#%', $n, $link);
395
+ if ( $add_args )
396
+ $link = add_query_arg( $add_args, $link );
397
+ $link = trailingslashit($link).ltrim($add_fragment, '/');
398
+ //$page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$n_display</a>";
399
+ $page_links[] = array('class' => 'page-number', 'link' => esc_url( apply_filters( 'paginate_links', $link ) ), 'title' => $n_display);
400
+ $dots = true;
401
+ elseif ( $dots && !$show_all ) :
402
+ $page_links[] = array('class' => 'dots', 'title' => __( '&hellip;' ));
403
+ //$page_links[] = '<span class="page-numbers dots">' . __( '&hellip;' ) . '</span>';
404
+ $dots = false;
405
+ endif;
406
+ endif;
407
+ endfor;
408
+ if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
409
+ $link = str_replace('%_%', $format, $base);
410
+ $link = str_replace('%#%', $current + 1, $link);
411
+ if ( $add_args )
412
+ $link = add_query_arg( $add_args, $link );
413
+ $link = trailingslashit($link).$add_fragment;
414
+
415
+ $page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $next_text . '</a>';
416
+ endif;
417
+ switch ( $type ) :
418
+ case 'array' :
419
+ return $page_links;
420
+ break;
421
+ case 'list' :
422
+ $r .= "<ul class='page-numbers'>\n\t<li>";
423
+ $r .= join("</li>\n\t<li>", $page_links);
424
+ $r .= "</li>\n</ul>\n";
425
+ break;
426
+ default :
427
+ $r = join("\n", $page_links);
428
+ break;
429
+ endswitch;
430
+ return $r;
431
+ }
432
+
433
  }
functions/functions-wp-image-helper.php CHANGED
@@ -8,7 +8,6 @@
8
  }
9
 
10
  function img_to_jpg($src, $bghex = '#FFFFFF'){
11
- //WPHelper::error_log('$src = '.$src);
12
  $output = str_replace('.png', '.jpg', $src);
13
  $input_file = $_SERVER['DOCUMENT_ROOT'] . $src;
14
  $output_file = $_SERVER['DOCUMENT_ROOT'] . $output;
@@ -27,4 +26,98 @@
27
  return $filename;
28
  }
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
8
  }
9
 
10
  function img_to_jpg($src, $bghex = '#FFFFFF'){
 
11
  $output = str_replace('.png', '.jpg', $src);
12
  $input_file = $_SERVER['DOCUMENT_ROOT'] . $src;
13
  $output_file = $_SERVER['DOCUMENT_ROOT'] . $output;
26
  return $filename;
27
  }
28
 
29
+ public static function sideloaded_file_loc($file){
30
+ $upload = wp_upload_dir();
31
+ $dir = $upload['path'];
32
+ $file = parse_url($file);
33
+ $path_parts = pathinfo($file['path']);
34
+ $basename = $path_parts['filename'];
35
+ $ext = $path_parts['extension'];
36
+ $old_root_path = $dir . '/' . $basename. '.' . $ext;
37
+ if (file_exists($old_root_path)){
38
+ return str_replace($_SERVER['DOCUMENT_ROOT'], '', $old_root_path);
39
+ }
40
+ return false;
41
+ }
42
+
43
+ public static function sideload_image($file) {
44
+ if ($loc = self::sideloaded_file_loc($file)){
45
+ return $loc;
46
+ }
47
+ require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-admin/includes/file.php');
48
+ require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-admin/includes/media.php');
49
+ // Download file to temp location
50
+ $tmp = download_url($file);
51
+ preg_match('/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches);
52
+ $file_array['name'] = basename($matches[0]);
53
+ $file_array['tmp_name'] = $tmp;
54
+ // If error storing temporarily, unlink
55
+ if (is_wp_error($tmp)) {
56
+ error_log('theres an error');
57
+ @unlink($file_array['tmp_name']);
58
+ $file_array['tmp_name'] = '';
59
+ }
60
+ // do the validation and storage stuff
61
+ $file = wp_upload_bits($file_array['name'], null, file_get_contents($file_array['tmp_name']));
62
+ $file['path'] = str_replace($_SERVER['DOCUMENT_ROOT'], '', $file['file']);
63
+ return $file['path'];
64
+ }
65
+
66
+ public static function resize($src, $w, $h = 0){
67
+ if (strstr($src, 'http') && !strstr($src, site_url())) {
68
+ $src = self::sideload_image($src);
69
+ }
70
+ $abs = false;
71
+ if (strstr($src, 'http')){
72
+ $abs = true;
73
+ }
74
+ //oh good, it's a relative image in the uploads folder!
75
+ $path_parts = pathinfo($src);
76
+ $basename = $path_parts['filename'];
77
+ $ext = $path_parts['extension'];
78
+ $dir = $path_parts['dirname'];
79
+ $newbase = $basename . '-r-' . $w . 'x' . $h;
80
+ $new_path = $dir . '/' . $newbase . '.' . $ext;
81
+ $new_path = str_replace(site_url(), '', $new_path);
82
+ $new_root_path = $_SERVER['DOCUMENT_ROOT'] . $new_path;
83
+ $old_root_path = $_SERVER['DOCUMENT_ROOT'] . $src;
84
+
85
+ $old_root_path = str_replace('//', '/', $old_root_path);
86
+ $new_root_path = str_replace('//', '/', $new_root_path);
87
+ if (file_exists($new_root_path)) {
88
+ if ($abs){
89
+ return untrailingslashit(site_url()).$new_path;
90
+ }
91
+ return $new_path;
92
+ }
93
+ $image = wp_get_image_editor($old_root_path);
94
+ if (!is_wp_error($image)) {
95
+ $current_size = $image->get_size();
96
+ $ow = $current_size['width'];
97
+ $oh = $current_size['height'];
98
+ if ($h) {
99
+ $new_aspect = $w / $h;
100
+ $old_aspect = $ow / $oh;
101
+
102
+ if ($new_aspect > $old_aspect) {
103
+ //cropping a vertical photo horitzonally
104
+ $oht = $ow / $new_aspect;
105
+ $oy = ($oh - $oht) / 6;
106
+ $image->crop(0, $oy, $ow, $oht, $w, $h);
107
+ } else {
108
+ $owt = $oh * $new_aspect;
109
+ $ox = $ow / 2 - $owt / 2;
110
+ $image->crop($ox, 0, $owt, $oh, $w, $h);
111
+ }
112
+ } else {
113
+ $image->resize($w, $w);
114
+ }
115
+ $image->save($new_root_path);
116
+ if ($abs){
117
+ return untrailingslashit(site_url()).$new_path;
118
+ }
119
+ return $new_path;
120
+ }
121
+ return $src;
122
+ }
123
  }
functions/timber-image.php CHANGED
@@ -25,8 +25,9 @@ class TimberImage extends TimberCore {
25
  $this->file = $this->_wp_attached_file;
26
  }
27
  if (isset($this->file)) {
 
28
  $dir = wp_upload_dir();
29
- $base = $this->url_to_path($dir["baseurl"]);
30
  return trailingslashit($base) . $this->file;
31
  }
32
  return false;
@@ -47,7 +48,6 @@ class TimberImage extends TimberCore {
47
  }
48
 
49
  function init($iid) {
50
-
51
  if (!is_numeric($iid) && is_string($iid)) {
52
  if (strstr($iid, '://')) {
53
  $this->init_with_url($iid);
25
  $this->file = $this->_wp_attached_file;
26
  }
27
  if (isset($this->file)) {
28
+ //return $this->file;
29
  $dir = wp_upload_dir();
30
+ $base = ($dir["baseurl"]);
31
  return trailingslashit($base) . $this->file;
32
  }
33
  return false;
48
  }
49
 
50
  function init($iid) {
 
51
  if (!is_numeric($iid) && is_string($iid)) {
52
  if (strstr($iid, '://')) {
53
  $this->init_with_url($iid);
functions/timber-post.php CHANGED
@@ -429,7 +429,7 @@ class TimberPost extends TimberCore {
429
  }
430
 
431
  function link() {
432
- return $this->get_link();
433
  }
434
 
435
  function permalink() {
429
  }
430
 
431
  function link() {
432
+ return $this->get_permalink();
433
  }
434
 
435
  function permalink() {
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.11.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,11 @@ Timber is great for any WordPress developer who cares about writing good, mainta
37
 
38
  == Changelog ==
39
 
 
 
 
 
 
40
  = 0.11.0 =
41
  * fixed load order of views so files inside of the child theme have priority over the parent theme.
42
  * comment ordering respects the default set in WordPress
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
 
38
  == Changelog ==
39
 
40
+ = 0.12.0 =
41
+ * Pagination is refactored to be more intutitve, and well, better.
42
+ * Resize is also refactored to respect absolute vs. relative URLs
43
+ * Got rid of lots of old, bogus code.
44
+
45
  = 0.11.0 =
46
  * fixed load order of views so files inside of the child theme have priority over the parent theme.
47
  * comment ordering respects the default set in WordPress
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.11.0
7
  Author URI: http://timber.upstatement.com/
8
  */
9
 
@@ -391,22 +391,25 @@ class Timber {
391
  /* Pagination
392
  ================================ */
393
 
394
- public function get_pagination(){
395
  global $wp_query;
396
  global $paged;
397
- $data = array();
398
- $data['pages'] = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']);
399
- $paged = 1;
400
- if (isset($wp_query->query_vars['paged'])) {
401
- $paged = $wp_query->query_vars['paged'];
402
- }
403
- $data['base'] = get_pagenum_link(0);
404
- $data['paged'] = $paged;
405
- if ($paged < $data['pages']) {
406
- $data['next'] = array('link' => next_posts(0, false), 'path' => next_posts(0, false));
407
  }
408
- if ($paged > 1) {
409
- $data['prev'] = array('link' => previous_posts(false), 'path' => previous_posts(false));
 
 
 
 
 
 
 
 
 
 
410
  }
411
  return $data;
412
  }
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.0
7
  Author URI: http://timber.upstatement.com/
8
  */
9
 
391
  /* Pagination
392
  ================================ */
393
 
394
+ public static function get_pagination($prefs = array()){
395
  global $wp_query;
396
  global $paged;
397
+ $args['total'] = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']);
398
+ if (strlen(trim(get_option('permalink_structure')))){
399
+ $args['format'] = 'page/%#%';
 
 
 
 
 
 
 
400
  }
401
+ $args['type'] = 'array';
402
+
403
+ $args['current'] = max( 1, get_query_var('paged') );
404
+ $args['mid_size'] = max(9 - $args['current'], 3);
405
+ $args['base'] = get_pagenum_link(0).'%_%';
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
  }
414
  return $data;
415
  }