Timber - Version 0.16.5

Version Description

  • print_a lives! added methods for TimberPost
  • quick fix on TimberPost::content which was generating warning
Download this release

Release Info

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

Code changes from version 0.16.4 to 0.16.5

functions/functions-twig.php CHANGED
@@ -272,76 +272,27 @@ function twig_make_excerpt($text, $length = 55){
272
  return wp_trim_words($text, $length);
273
  }
274
 
275
- function twig_invoke($method, $obj) {
276
- $product = '';
277
- $totalParams = $method->getNumberOfParameters();
278
- $reqParams = $method->getNumberOfRequiredParameters();
279
- if (!$method->getNumberOfParameters()) {
280
- //zero parameters, easy street
281
- $product = $method->invoke($obj);
282
- //$product = $method->getName();
283
- } else if ($method->getNumberOfRequiredParameters()) {
284
- //there are required parametres
285
- //$product = $method->getName();
286
- } else if ($totalParams && !$reqParams) {
287
- //all params are optional
288
- $pass = array();
289
- $product = $pass;
290
- if ($method->getName() == 'get_preview') {
291
- $function = $method->getName();
292
- // try {
293
- // $product = $obj->$function();
294
- // } catch($e){
295
- // $product = 'error with '.$method->getName();
296
- // }
297
- }
298
-
299
- //$product = $method->invokeArgs($obj, $pass);
300
- //$product = $args;
301
- } else {
302
- $product = '?????';
303
- }
304
- return $product;
305
- }
306
-
307
  function twig_print_r($arr) {
 
308
  return print_r($arr, true);
 
309
  }
310
 
311
  function twig_print_a($arr) {
312
  return '<pre>' . twig_object_docs($arr, true) . '</pre>';
313
  }
314
 
315
- function twig_object_docs($obj) {
316
- if (!class_exists(get_class($obj))){
317
- return false;
318
- }
319
- $reflector = new ReflectionClass($obj);
320
- $methods = $reflector->getMethods();
321
- $rets = array();
322
- $rep = $reflector->getProperty('representation')->getValue();
323
- foreach ($methods as $method) {
324
- if ($method->isPublic()) {
325
- $comments = $method->getDocComment();
326
- $comments = str_replace('/**', '', $comments);
327
- //$comments = preg_replace('(\/)(\*)(\*)\r', '', $comments);
328
- $info = new stdClass();
329
- $info->comments = $comments;
330
- $info->returns = twig_invoke($method, $obj);
331
- $info->params = $method->getParameters();
332
- //if (strlen($comments) && !strstr($comments, '@nodoc')){
333
- //$rets[$rep.'.'.$method->name] = $comments;
334
- //$rets[$rep.'.'.$method->name] = $info->returns;
335
- $rets[$method->name] = $info->returns;
336
- //}
337
- }
338
- }
339
- foreach ($obj as $key => $value) {
340
- $rets[$key] = $value;
341
  }
 
342
  ksort($rets);
343
-
344
- return '<pre>' . (print_r($rets, true)) . '</pre>';
 
345
  }
346
 
347
  new TimberTwig();
272
  return wp_trim_words($text, $length);
273
  }
274
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  function twig_print_r($arr) {
276
+ //$rets = twig_object_docs($obj, false);
277
  return print_r($arr, true);
278
+ return $rets;
279
  }
280
 
281
  function twig_print_a($arr) {
282
  return '<pre>' . twig_object_docs($arr, true) . '</pre>';
283
  }
284
 
285
+ function twig_object_docs($obj, $methods = true) {
286
+ $class = get_class($obj);
287
+ $properties = (array) $obj;
288
+ if ($methods){
289
+ $methods = $obj->get_method_values();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  }
291
+ $rets = array_merge($properties, $methods);
292
  ksort($rets);
293
+ $str = print_r($rets, true);
294
+ $str = str_replace('Array', $class . ' Object', $str);
295
+ return $str;
296
  }
297
 
298
  new TimberTwig();
functions/timber-core.php CHANGED
@@ -33,6 +33,12 @@ class TimberCore {
33
  return $this->_can_edit;
34
  }
35
 
 
 
 
 
 
 
36
  //deprecated
37
  function url_to_path($url = '') {
38
  if (!strlen($url) && $this->url) {
33
  return $this->_can_edit;
34
  }
35
 
36
+ function get_method_values(){
37
+ $ret = array();
38
+ $ret['can_edit'] = $this->can_edit();
39
+ return $ret;
40
+ }
41
+
42
  //deprecated
43
  function url_to_path($url = '') {
44
  if (!strlen($url) && $this->url) {
functions/timber-post.php CHANGED
@@ -543,7 +543,33 @@ class TimberPost extends TimberCore {
543
  return get_post_format($this->ID);
544
  }
545
 
546
- //Aliases
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
547
  public function author() {
548
  return $this->get_author();
549
  }
@@ -564,7 +590,7 @@ class TimberPost extends TimberCore {
564
  return $this->get_comments();
565
  }
566
 
567
- public function content($page) {
568
  return $this->get_content(0, $page);
569
  }
570
 
543
  return get_post_format($this->ID);
544
  }
545
 
546
+ // Docs
547
+
548
+ public function get_method_values(){
549
+ $ret = parent::get_method_values();
550
+ $ret['author'] = $this->author();
551
+ $ret['categories'] = $this->categories();
552
+ $ret['category'] = $this->category();
553
+ $ret['children'] = $this->children();
554
+ $ret['comments'] = $this->comments();
555
+ $ret['content'] = $this->content();
556
+ $ret['display_date'] = $this->display_date();
557
+ $ret['edit_link'] = $this->edit_link();
558
+ $ret['format'] = $this->format();
559
+ $ret['link'] = $this->link();
560
+ $ret['next'] = $this->next();
561
+ $ret['pagination'] = $this->pagination();
562
+ $ret['parent'] = $this->parent();
563
+ $ret['path'] = $this->path();
564
+ $ret['prev'] = $this->prev();
565
+ $ret['terms'] = $this->terms();
566
+ $ret['tags'] = $this->tags();
567
+ $ret['thumbnail'] = $this->thumbnail();
568
+ $ret['title'] = $this->title();
569
+ return $ret;
570
+ }
571
+
572
+ // Aliases
573
  public function author() {
574
  return $this->get_author();
575
  }
590
  return $this->get_comments();
591
  }
592
 
593
+ public function content($page = 0) {
594
  return $this->get_content(0, $page);
595
  }
596
 
readme.txt CHANGED
@@ -41,6 +41,10 @@ Timber is great for any WordPress developer who cares about writing good, mainta
41
 
42
  == Changelog ==
43
 
 
 
 
 
44
  = 0.16.4 =
45
  * Fixed a few things on image handling
46
  * Updated to Twig 1.15 (thanks @fabpot)
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
47
+
48
  = 0.16.4 =
49
  * Fixed a few things on image handling
50
  * Updated to Twig 1.15 (thanks @fabpot)
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.4
8
  Author URI: http://upstatement.com/
9
  */
10
 
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