Version Description
Download this release
Release Info
Developer | jarednova |
Plugin | Timber |
Version | 1.0.2 |
Comparing to | |
See all releases |
Code changes from version 1.0.1 to 1.0.2
- lib/Helper.php +12 -0
- lib/Image.php +16 -3
- lib/Post.php +10 -2
- lib/Term.php +1 -2
- lib/Timber.php +23 -18
- lib/User.php +4 -2
- readme.txt +1 -1
- timber-starter-theme/single.php +0 -1
- timber-starter-theme/templates/base.twig +1 -1
- timber-starter-theme/templates/single.twig +3 -1
- timber.php +1 -1
- vendor/autoload.php +1 -1
- vendor/composer/autoload_real.php +5 -5
lib/Helper.php
CHANGED
@@ -442,6 +442,18 @@ class Helper {
|
|
442 |
/* Links, Forms, Etc. Utilities
|
443 |
======================== */
|
444 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
445 |
/**
|
446 |
*
|
447 |
*
|
442 |
/* Links, Forms, Etc. Utilities
|
443 |
======================== */
|
444 |
|
445 |
+
/**
|
446 |
+
*
|
447 |
+
* Gets the comment form for use on a single article page
|
448 |
+
* @deprecated 0.21.8 use `{{ function('comment_form') }}` instead
|
449 |
+
* @param int $post_id which post_id should the form be tied to?
|
450 |
+
* @param array $args this $args thing is a fucking mess, [fix at some point](http://codex.wordpress.org/Function_Reference/comment_form)
|
451 |
+
* @return string
|
452 |
+
*/
|
453 |
+
public static function get_comment_form( $post_id = null, $args = array() ) {
|
454 |
+
return self::ob_function( 'comment_form', array( $args, $post_id ) );
|
455 |
+
}
|
456 |
+
|
457 |
/**
|
458 |
*
|
459 |
*
|
lib/Image.php
CHANGED
@@ -154,6 +154,17 @@ class Image extends Post implements CoreInterface {
|
|
154 |
return null;
|
155 |
}
|
156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
/**
|
158 |
* @internal
|
159 |
* @param int $iid the id number of the image in the WP database
|
@@ -165,7 +176,7 @@ class Image extends Post implements CoreInterface {
|
|
165 |
if ( !is_array($image_info) ) {
|
166 |
$image_info = array();
|
167 |
}
|
168 |
-
$image_custom = get_post_custom($iid);
|
169 |
$basic = get_post($iid);
|
170 |
if ( $basic ) {
|
171 |
if ( isset($basic->post_excerpt) ) {
|
@@ -212,7 +223,9 @@ class Image extends Post implements CoreInterface {
|
|
212 |
*/
|
213 |
function init( $iid = false ) {
|
214 |
if ( !$iid ) { Helper::error_log('Initalized TimberImage without providing first parameter.'); return; }
|
215 |
-
|
|
|
|
|
216 |
if ( !is_numeric($iid) && is_string($iid) ) {
|
217 |
if ( strstr($iid, '://') ) {
|
218 |
$this->init_with_url($iid);
|
@@ -263,7 +276,7 @@ class Image extends Post implements CoreInterface {
|
|
263 |
$this->ID = $iid;
|
264 |
}
|
265 |
if ( isset($this->ID) ) {
|
266 |
-
$custom = get_post_custom($this->ID);
|
267 |
foreach ( $custom as $key => $value ) {
|
268 |
$this->$key = $value[0];
|
269 |
}
|
154 |
return null;
|
155 |
}
|
156 |
|
157 |
+
/**
|
158 |
+
* @return array
|
159 |
+
*/
|
160 |
+
protected function get_post_custom($iid) {
|
161 |
+
$pc = get_post_custom($iid);
|
162 |
+
if ( is_bool($pc) ) {
|
163 |
+
return array();
|
164 |
+
}
|
165 |
+
return $pc;
|
166 |
+
}
|
167 |
+
|
168 |
/**
|
169 |
* @internal
|
170 |
* @param int $iid the id number of the image in the WP database
|
176 |
if ( !is_array($image_info) ) {
|
177 |
$image_info = array();
|
178 |
}
|
179 |
+
$image_custom = self::get_post_custom($iid);
|
180 |
$basic = get_post($iid);
|
181 |
if ( $basic ) {
|
182 |
if ( isset($basic->post_excerpt) ) {
|
223 |
*/
|
224 |
function init( $iid = false ) {
|
225 |
if ( !$iid ) { Helper::error_log('Initalized TimberImage without providing first parameter.'); return; }
|
226 |
+
if ( $iid instanceof self ) {
|
227 |
+
$iid = (int) $iid->ID;
|
228 |
+
}
|
229 |
if ( !is_numeric($iid) && is_string($iid) ) {
|
230 |
if ( strstr($iid, '://') ) {
|
231 |
$this->init_with_url($iid);
|
276 |
$this->ID = $iid;
|
277 |
}
|
278 |
if ( isset($this->ID) ) {
|
279 |
+
$custom = self::get_post_custom($this->ID);
|
280 |
foreach ( $custom as $key => $value ) {
|
281 |
$this->$key = $value[0];
|
282 |
}
|
lib/Post.php
CHANGED
@@ -167,8 +167,6 @@ class Post extends Core implements CoreInterface {
|
|
167 |
* @param mixed $pid
|
168 |
*/
|
169 |
public function __construct( $pid = null ) {
|
170 |
-
$this->namespacing();
|
171 |
-
|
172 |
$pid = $this->determine_id($pid);
|
173 |
$this->init($pid);
|
174 |
}
|
@@ -506,6 +504,16 @@ class Post extends Core implements CoreInterface {
|
|
506 |
return $post;
|
507 |
}
|
508 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
509 |
|
510 |
/**
|
511 |
* Get the terms associated with the post
|
167 |
* @param mixed $pid
|
168 |
*/
|
169 |
public function __construct( $pid = null ) {
|
|
|
|
|
170 |
$pid = $this->determine_id($pid);
|
171 |
$this->init($pid);
|
172 |
}
|
504 |
return $post;
|
505 |
}
|
506 |
|
507 |
+
/**
|
508 |
+
*
|
509 |
+
* Gets the comment form for use on a single article page
|
510 |
+
* @param array $args this $args thing is a fucking mess, [fix at some point](http://codex.wordpress.org/Function_Reference/comment_form)
|
511 |
+
* @return string of HTML for the form
|
512 |
+
*/
|
513 |
+
public function comment_form( $args = array() ) {
|
514 |
+
return Helper::get_comment_form( $this->ID, $args );
|
515 |
+
}
|
516 |
+
|
517 |
|
518 |
/**
|
519 |
* Get the terms associated with the post
|
lib/Term.php
CHANGED
@@ -6,7 +6,6 @@ use Timber\Core;
|
|
6 |
use Timber\CoreInterface;
|
7 |
|
8 |
use Timber\Post;
|
9 |
-
use TImber\Term;
|
10 |
use Timber\Helper;
|
11 |
use Timber\URLHelper;
|
12 |
|
@@ -413,4 +412,4 @@ class Term extends Core implements CoreInterface {
|
|
413 |
public function title() {
|
414 |
return $this->name;
|
415 |
}
|
416 |
-
}
|
6 |
use Timber\CoreInterface;
|
7 |
|
8 |
use Timber\Post;
|
|
|
9 |
use Timber\Helper;
|
10 |
use Timber\URLHelper;
|
11 |
|
412 |
public function title() {
|
413 |
return $this->name;
|
414 |
}
|
415 |
+
}
|
lib/Timber.php
CHANGED
@@ -39,6 +39,8 @@ class Timber {
|
|
39 |
public static $auto_meta = true;
|
40 |
public static $autoescape = false;
|
41 |
|
|
|
|
|
42 |
/**
|
43 |
* @codeCoverageIgnore
|
44 |
*/
|
@@ -194,24 +196,27 @@ class Timber {
|
|
194 |
* @return array
|
195 |
*/
|
196 |
public static function get_context() {
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
|
|
|
|
|
|
215 |
}
|
216 |
|
217 |
/**
|
39 |
public static $auto_meta = true;
|
40 |
public static $autoescape = false;
|
41 |
|
42 |
+
public static $context_cache = [];
|
43 |
+
|
44 |
/**
|
45 |
* @codeCoverageIgnore
|
46 |
*/
|
196 |
* @return array
|
197 |
*/
|
198 |
public static function get_context() {
|
199 |
+
if( empty(self::$context_cache) ) {
|
200 |
+
self::$context_cache['http_host'] = 'http://'.URLHelper::get_host();
|
201 |
+
self::$context_cache['wp_title'] = Helper::get_wp_title();
|
202 |
+
self::$context_cache['wp_head'] = Helper::function_wrapper('wp_head');
|
203 |
+
self::$context_cache['wp_footer'] = Helper::function_wrapper('wp_footer');
|
204 |
+
self::$context_cache['body_class'] = implode(' ', get_body_class());
|
205 |
+
|
206 |
+
self::$context_cache['site'] = new Site();
|
207 |
+
self::$context_cache['request'] = new Request();
|
208 |
+
$user = new User();
|
209 |
+
self::$context_cache['user'] = ($user->ID) ? $user : false;
|
210 |
+
self::$context_cache['theme'] = self::$context_cache['site']->theme;
|
211 |
+
|
212 |
+
self::$context_cache['posts'] = Timber::query_posts();
|
213 |
+
|
214 |
+
self::$context_cache = apply_filters('timber_context', self::$context_cache);
|
215 |
+
self::$context_cache = apply_filters('timber/context', self::$context_cache);
|
216 |
+
}
|
217 |
+
|
218 |
+
|
219 |
+
return self::$context_cache;
|
220 |
}
|
221 |
|
222 |
/**
|
lib/User.php
CHANGED
@@ -7,6 +7,8 @@ use Timber\CoreInterface;
|
|
7 |
|
8 |
use Timber\URLHelper;
|
9 |
|
|
|
|
|
10 |
/**
|
11 |
* This is used in Timber to represent users retrived from WordPress. You can call `$my_user = new TimberUser(123);` directly, or access it through the `{{ post.author }}` method.
|
12 |
* @example
|
@@ -40,7 +42,7 @@ class User extends Core implements CoreInterface {
|
|
40 |
|
41 |
/**
|
42 |
* @api
|
43 |
-
* @var string The URL of the author's avatar
|
44 |
*/
|
45 |
public $avatar;
|
46 |
|
@@ -142,7 +144,7 @@ class User extends Core implements CoreInterface {
|
|
142 |
}
|
143 |
$this->id = $this->ID;
|
144 |
$this->name = $this->name();
|
145 |
-
$this->avatar = get_avatar_url($this->id);
|
146 |
$custom = $this->get_custom();
|
147 |
$this->import($custom);
|
148 |
}
|
7 |
|
8 |
use Timber\URLHelper;
|
9 |
|
10 |
+
use Timber\Image;
|
11 |
+
|
12 |
/**
|
13 |
* This is used in Timber to represent users retrived from WordPress. You can call `$my_user = new TimberUser(123);` directly, or access it through the `{{ post.author }}` method.
|
14 |
* @example
|
42 |
|
43 |
/**
|
44 |
* @api
|
45 |
+
* @var string|Image The URL of the author's avatar
|
46 |
*/
|
47 |
public $avatar;
|
48 |
|
144 |
}
|
145 |
$this->id = $this->ID;
|
146 |
$this->name = $this->name();
|
147 |
+
$this->avatar = new Image(get_avatar_url($this->id));
|
148 |
$custom = $this->get_custom();
|
149 |
$this->import($custom);
|
150 |
}
|
readme.txt
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
Contributors: jarednova, connorjburton, lggorman
|
3 |
Tags: template engine, templates, twig
|
4 |
Requires at least: 3.7
|
5 |
-
Stable tag: 1.0.
|
6 |
Tested up to: 4.5.1
|
7 |
PHP version: 5.3.0 or greater
|
8 |
License: GPLv2 or later
|
2 |
Contributors: jarednova, connorjburton, lggorman
|
3 |
Tags: template engine, templates, twig
|
4 |
Requires at least: 3.7
|
5 |
+
Stable tag: 1.0.2
|
6 |
Tested up to: 4.5.1
|
7 |
PHP version: 5.3.0 or greater
|
8 |
License: GPLv2 or later
|
timber-starter-theme/single.php
CHANGED
@@ -12,7 +12,6 @@
|
|
12 |
$context = Timber::get_context();
|
13 |
$post = Timber::query_post();
|
14 |
$context['post'] = $post;
|
15 |
-
$context['comment_form'] = comment_form();
|
16 |
|
17 |
if ( post_password_required( $post->ID ) ) {
|
18 |
Timber::render( 'single-password.twig', $context );
|
12 |
$context = Timber::get_context();
|
13 |
$post = Timber::query_post();
|
14 |
$context['post'] = $post;
|
|
|
15 |
|
16 |
if ( post_password_required( $post->ID ) ) {
|
17 |
Timber::render( 'single-password.twig', $context );
|
timber-starter-theme/templates/base.twig
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
{% block header %}
|
12 |
<div class="wrapper">
|
13 |
<h1 class="hdr-logo" role="banner">
|
14 |
-
<a class="hdr-logo-link" href="
|
15 |
</h1>
|
16 |
<nav id="nav-main" class="nav-main" role="navigation">
|
17 |
{% include "menu.twig" with {'menu': menu.get_items} %}
|
11 |
{% block header %}
|
12 |
<div class="wrapper">
|
13 |
<h1 class="hdr-logo" role="banner">
|
14 |
+
<a class="hdr-logo-link" href="{{site.siteurl}}" rel="home">{{site.name}}</a>
|
15 |
</h1>
|
16 |
<nav id="nav-main" class="nav-main" role="navigation">
|
17 |
{% include "menu.twig" with {'menu': menu.get_items} %}
|
timber-starter-theme/templates/single.twig
CHANGED
@@ -12,10 +12,11 @@
|
|
12 |
{{post.content}}
|
13 |
</div>
|
14 |
</section>
|
|
|
15 |
<section class="comments">
|
16 |
<div class="respond">
|
17 |
<h3 class="h2">Comments</h3>
|
18 |
-
{{ comment_form }}
|
19 |
</div>
|
20 |
<div class="responses">
|
21 |
{% for cmt in post.get_comments() %}
|
@@ -23,6 +24,7 @@
|
|
23 |
{% endfor %}
|
24 |
</div>
|
25 |
</section>
|
|
|
26 |
</article>
|
27 |
</div><!-- /content-wrapper -->
|
28 |
{% endblock %}
|
12 |
{{post.content}}
|
13 |
</div>
|
14 |
</section>
|
15 |
+
{% if post.comment_status != 'closed' %}
|
16 |
<section class="comments">
|
17 |
<div class="respond">
|
18 |
<h3 class="h2">Comments</h3>
|
19 |
+
{{ fn('comment_form') }}
|
20 |
</div>
|
21 |
<div class="responses">
|
22 |
{% for cmt in post.get_comments() %}
|
24 |
{% endfor %}
|
25 |
</div>
|
26 |
</section>
|
27 |
+
{% endif %}
|
28 |
</article>
|
29 |
</div><!-- /content-wrapper -->
|
30 |
{% endblock %}
|
timber.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Timber
|
|
4 |
Description: The WordPress Timber Library allows you to write themes using the power Twig templates.
|
5 |
Plugin URI: http://timber.upstatement.com
|
6 |
Author: Jared Novack + Upstatement
|
7 |
-
Version: 1.0.
|
8 |
Author URI: http://upstatement.com/
|
9 |
*/
|
10 |
// we look for Composer files first in the plugins dir.
|
4 |
Description: The WordPress Timber Library allows you to write themes using the power Twig templates.
|
5 |
Plugin URI: http://timber.upstatement.com
|
6 |
Author: Jared Novack + Upstatement
|
7 |
+
Version: 1.0.2
|
8 |
Author URI: http://upstatement.com/
|
9 |
*/
|
10 |
// we look for Composer files first in the plugins dir.
|
vendor/autoload.php
CHANGED
@@ -4,4 +4,4 @@
|
|
4 |
|
5 |
require_once __DIR__ . '/composer' . '/autoload_real.php';
|
6 |
|
7 |
-
return
|
4 |
|
5 |
require_once __DIR__ . '/composer' . '/autoload_real.php';
|
6 |
|
7 |
+
return ComposerAutoloaderInit0f0eeb7542dd42954cb9afcc97bcfdce::getLoader();
|
vendor/composer/autoload_real.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
// autoload_real.php @generated by Composer
|
4 |
|
5 |
-
class
|
6 |
{
|
7 |
private static $loader;
|
8 |
|
@@ -19,9 +19,9 @@ class ComposerAutoloaderInit327165da8fdb503dc7c8e78bb047573c
|
|
19 |
return self::$loader;
|
20 |
}
|
21 |
|
22 |
-
spl_autoload_register(array('
|
23 |
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
24 |
-
spl_autoload_unregister(array('
|
25 |
|
26 |
$map = require __DIR__ . '/autoload_namespaces.php';
|
27 |
foreach ($map as $namespace => $path) {
|
@@ -42,14 +42,14 @@ class ComposerAutoloaderInit327165da8fdb503dc7c8e78bb047573c
|
|
42 |
|
43 |
$includeFiles = require __DIR__ . '/autoload_files.php';
|
44 |
foreach ($includeFiles as $fileIdentifier => $file) {
|
45 |
-
|
46 |
}
|
47 |
|
48 |
return $loader;
|
49 |
}
|
50 |
}
|
51 |
|
52 |
-
function
|
53 |
{
|
54 |
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
55 |
require $file;
|
2 |
|
3 |
// autoload_real.php @generated by Composer
|
4 |
|
5 |
+
class ComposerAutoloaderInit0f0eeb7542dd42954cb9afcc97bcfdce
|
6 |
{
|
7 |
private static $loader;
|
8 |
|
19 |
return self::$loader;
|
20 |
}
|
21 |
|
22 |
+
spl_autoload_register(array('ComposerAutoloaderInit0f0eeb7542dd42954cb9afcc97bcfdce', 'loadClassLoader'), true, true);
|
23 |
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
24 |
+
spl_autoload_unregister(array('ComposerAutoloaderInit0f0eeb7542dd42954cb9afcc97bcfdce', 'loadClassLoader'));
|
25 |
|
26 |
$map = require __DIR__ . '/autoload_namespaces.php';
|
27 |
foreach ($map as $namespace => $path) {
|
42 |
|
43 |
$includeFiles = require __DIR__ . '/autoload_files.php';
|
44 |
foreach ($includeFiles as $fileIdentifier => $file) {
|
45 |
+
composerRequire0f0eeb7542dd42954cb9afcc97bcfdce($fileIdentifier, $file);
|
46 |
}
|
47 |
|
48 |
return $loader;
|
49 |
}
|
50 |
}
|
51 |
|
52 |
+
function composerRequire0f0eeb7542dd42954cb9afcc97bcfdce($fileIdentifier, $file)
|
53 |
{
|
54 |
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
55 |
require $file;
|