Timber - Version 0.21.10

Version Description

  • Removed deprecated twitterify function
  • Much more docs (and deprecation docs)
  • Fixed issues with using constants (thanks @xavivars)
Download this release

Release Info

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

Code changes from version 0.21.9 to 0.21.10

Files changed (39) hide show
  1. README.md +1 -1
  2. lib/timber-archives.php +46 -1
  3. lib/timber-comment.php +299 -233
  4. lib/timber-core.php +24 -9
  5. lib/timber-helper.php +50 -39
  6. lib/timber-image-helper.php +11 -8
  7. lib/timber-image.php +260 -150
  8. lib/timber-page.php +5 -2
  9. lib/timber-post.php +11 -2
  10. lib/timber-site.php +70 -10
  11. lib/timber-term.php +55 -5
  12. lib/timber-theme.php +24 -18
  13. lib/timber-url-helper.php +17 -6
  14. lib/timber-user.php +88 -47
  15. readme.txt +6 -1
  16. timber-starter-theme/.gitignore +0 -2
  17. timber-starter-theme/README.md +3 -0
  18. timber-starter-theme/composer.json +0 -33
  19. timber-starter-theme/composer.lock +0 -288
  20. timber-starter-theme/functions.php +2 -0
  21. timber-starter-theme/phpunit.xml +0 -20
  22. timber-starter-theme/search.php +0 -1
  23. timber-starter-theme/{views → templates}/404.twig +0 -0
  24. timber-starter-theme/{views → templates}/author.twig +0 -0
  25. timber-starter-theme/{views → templates}/base.twig +0 -0
  26. timber-starter-theme/{views → templates}/comment.twig +0 -0
  27. timber-starter-theme/{views → templates}/footer.twig +0 -0
  28. timber-starter-theme/{views → templates}/html-header.twig +0 -0
  29. timber-starter-theme/{views → templates}/index.twig +0 -0
  30. timber-starter-theme/{views → templates}/page-plugin.twig +0 -0
  31. timber-starter-theme/{views → templates}/page.twig +0 -0
  32. timber-starter-theme/{views → templates}/sidebar.twig +0 -0
  33. timber-starter-theme/{views → templates}/single-password.twig +0 -0
  34. timber-starter-theme/{views → templates}/single.twig +0 -0
  35. timber-starter-theme/{views → templates}/tease-post.twig +0 -0
  36. timber-starter-theme/{views → templates}/tease.twig +0 -0
  37. timber-starter-theme/tests/bootstrap.php +0 -18
  38. timber-starter-theme/tests/test-timber-starter-theme.php +0 -42
  39. timber.php +4 -2
README.md CHANGED
@@ -66,7 +66,7 @@ Timber is great for any WordPress developer who cares about writing good, mainta
66
 
67
  #### Related Projects
68
  * [**Timber Starter Theme**](https://github.com/upstatement/timber-starter-theme) The "_s" of Timber to give you an easy start to the most basic theme you can build upon and customize.
69
- * [**Timber Debug Bar**](https://github.com/upstatement/debug-bar-timber) Adds a debug bar panel that will show you want template is in-use and the data sent to your twig file.
70
  * [**TimberPhoton**](https://github.com/slimndap/TimberPhoton) Plug-in to use JetPack's free Photon image manipulation and CDN with Timber.
71
  * [**Timber Sugar**](https://github.com/Upstatement/timber-sugar) A catch-all for goodies to use w Timber.
72
  * [**Twig**](https://github.com/fabpot/Twig) The template language used by Timber.
66
 
67
  #### Related Projects
68
  * [**Timber Starter Theme**](https://github.com/upstatement/timber-starter-theme) The "_s" of Timber to give you an easy start to the most basic theme you can build upon and customize.
69
+ * [**Timber Debug Bar**](https://github.com/upstatement/debug-bar-timber) Adds a debug bar panel that will show you which template is in-use and the data sent to your twig file.
70
  * [**TimberPhoton**](https://github.com/slimndap/TimberPhoton) Plug-in to use JetPack's free Photon image manipulation and CDN with Timber.
71
  * [**Timber Sugar**](https://github.com/Upstatement/timber-sugar) A catch-all for goodies to use w Timber.
72
  * [**Twig**](https://github.com/fabpot/Twig) The template language used by Timber.
lib/timber-archives.php CHANGED
@@ -1,5 +1,35 @@
1
  <?php
2
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  class TimberArchives extends TimberCore {
4
 
5
  public $base = '';
@@ -9,6 +39,21 @@ class TimberArchives extends TimberCore {
9
  */
10
  public $items;
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  function __construct( $args = null, $base = '' ) {
13
  $this->init($args, $base);
14
  }
1
  <?php
2
+ /**
3
+ * The TimberArchives class is used to generate a menu based on the date archives of your posts. The [Nieman Foundation News site](http://nieman.harvard.edu/news/) has an example of how the output can be used in a real site ([screenshot](https://cloud.githubusercontent.com/assets/1298086/9610076/3cdca596-50a5-11e5-82fd-acb74c09c482.png)).
4
+ * @example
5
+ * ```php
6
+ * $context['archives'] = new TimberArchives( $args );
7
+ * ```
8
+ * ```twig
9
+ * <ul>
10
+ * {% for item in archives.items %}
11
+ * <li><a href="{{item.link}}">{{item.name}}</a></li>
12
+ * {% for child item.children %}
13
+ * <li class="child"><a href="{{child.link}}">{{child.name}}</a></li>
14
+ * {% endfor %}
15
+ * {% endfor %}
16
+ * </ul>
17
+ * ```
18
+ * ```html
19
+ * <ul>
20
+ * <li>2015</li>
21
+ * <li class="child">May</li>
22
+ * <li class="child">April</li>
23
+ * <li class="child">March</li>
24
+ * <li class="child">February</li>
25
+ * <li class="child">January</li>
26
+ * <li>2014</li>
27
+ * <li class="child">December</li>
28
+ * <li class="child">November</li>
29
+ * <li class="child">October</li>
30
+ * </ul>
31
+ * ```
32
+ */
33
  class TimberArchives extends TimberCore {
34
 
35
  public $base = '';
39
  */
40
  public $items;
41
 
42
+ /**
43
+ * @api
44
+ * @param $args array of arguments {
45
+ * @type bool show_year => false
46
+ * @type string
47
+ * @type string type => 'monthly-nested'
48
+ * @type int limit => -1
49
+ * @type bool show_post_count => false
50
+ * @type string order => 'DESC'
51
+ * @type string post_type => 'post'
52
+ * @type bool show_year => false
53
+ * @type bool nested => false
54
+ * }
55
+ * @param string $base any additional paths that need to be prepended to the URLs that are generated, for example: "tags"
56
+ */
57
  function __construct( $args = null, $base = '' ) {
58
  $this->init($args, $base);
59
  }
lib/timber-comment.php CHANGED
@@ -1,263 +1,329 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  class TimberComment extends TimberCore implements TimberCoreInterface {
4
 
5
- public $PostClass = 'TimberPost';
6
- public $object_type = 'comment';
7
 
8
- public static $representation = 'comment';
9
 
10
- public $ID;
11
- public $id;
12
- public $comment_author_email;
13
- public $comment_content;
14
- public $comment_date;
15
- public $comment_ID;
16
- public $user_id;
17
- public $comment_author;
18
 
19
- public $children = array();
20
 
21
- /**
22
- * @param int $cid
23
- */
24
- function __construct($cid) {
25
- $this->init($cid);
26
- }
27
 
28
- function __toString(){
29
- return $this->content();
30
- }
31
 
32
- /**
33
- * @internal
34
- * @param integer $cid
35
- */
36
- function init($cid) {
37
- $comment_data = $cid;
38
- if (is_integer($cid)) {
39
- $comment_data = get_comment($cid);
40
- }
41
- $this->import($comment_data);
42
- $this->ID = $this->comment_ID;
43
- $this->id = $this->comment_ID;
44
- $comment_meta_data = $this->get_meta_fields($this->ID);
45
- $this->import($comment_meta_data);
46
- }
47
 
48
- /**
49
- * @api
50
- * @return TimberUser
51
- */
52
- public function author() {
53
- if ($this->user_id) {
54
- return new TimberUser($this->user_id);
55
- } else {
56
- $author = new TimberUser(0);
57
- if (isset($this->comment_author) && $this->comment_author) {
58
- $author->name = $this->comment_author;
59
- } else {
60
- $author->name = 'Anonymous';
61
- }
62
- }
63
- return $author;
64
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- /**
67
- * Fetches the Gravatar
68
- * ```twig
69
- * {{comment.avatar(36,template_uri~"/img/dude.jpg")}}
70
- * ```
71
- * @param int $size
72
- * @param string $default
73
- * @return bool|mixed|string
74
- */
75
- public function avatar($size = 92, $default = '') {
76
- if (!get_option('show_avatars')) {
77
- return false;
78
- }
79
- if (!is_numeric($size)) {
80
- $size = '92';
81
- }
 
 
 
 
 
82
 
83
- $email = $this->avatar_email();
84
- $email_hash = '';
85
- if (!empty($email)) {
86
- $email_hash = md5(strtolower(trim($email)));
87
- }
88
- $host = $this->avatar_host($email_hash);
89
- $default = $this->avatar_default($default, $email, $size, $host);
90
- if (!empty($email)) {
91
- $avatar = $this->avatar_out($default, $host, $email_hash, $size);
92
- } else {
93
- $avatar = $default;
94
- }
95
- return $avatar;
96
- }
97
 
98
- /**
99
- * @api
100
- * @return string
101
- */
102
- public function content() {
103
- return apply_filters('get_comment_text ', $this->comment_content);
104
- }
105
 
106
- /**
107
- * @api
108
- * @return boolean
109
- */
110
- public function approved() {
111
- return $this->comment_approved;
112
- }
 
 
 
 
 
 
 
 
113
 
114
- /**
115
- * @api
116
- * @return string
117
- */
118
- public function date( $date_format = '' ) {
119
- $df = $date_format ? $date_format : get_option('date_format');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  $the_date = (string)mysql2date($df, $this->comment_date);
121
  return apply_filters('get_comment_date ', $the_date, $df);
122
- }
123
 
124
- /**
125
- * @param string $field_name
126
- * @return mixed
127
- */
128
- public function meta($field_name) {
129
- return $this->get_meta_field($field_name);
130
- }
131
 
132
- /**
133
- * @api
134
- * @return bool
135
- */
136
- public function is_child() {
137
- return $this->comment_parent > 0;
138
- }
139
 
140
- /**
141
- * @param int $comment_id
142
- * @return mixed
143
- */
144
- protected function get_meta_fields($comment_id = null) {
145
- if ($comment_id === null) {
146
- $comment_id = $this->ID;
147
- }
148
- //Could not find a WP function to fetch all comment meta data, so I made one.
149
- apply_filters('timber_comment_get_meta_pre', array(), $comment_id);
150
- $comment_metas = get_comment_meta($comment_id);
151
- foreach ($comment_metas as &$cm) {
152
- if (is_array($cm) && count($cm) == 1) {
153
- $cm = $cm[0];
154
- }
155
- }
156
- $comment_metas = apply_filters('timber_comment_get_meta', $comment_metas, $comment_id);
157
- return $comment_metas;
158
- }
 
159
 
160
- /**
161
- * @param string $field_name
162
- * @return mixed
163
- */
164
- protected function get_meta_field($field_name) {
165
- $value = apply_filters('timber_comment_get_meta_field_pre', null, $this->ID, $field_name, $this);
166
- if ($value === null) {
167
- $value = get_comment_meta($this->ID, $field_name, true);
168
- }
169
- $value = apply_filters('timber_comment_get_meta_field', $value, $this->ID, $field_name, $this);
170
- return $value;
171
- }
 
172
 
173
- /* AVATAR Stuff
174
- ======================= */
175
 
176
- /**
177
- * @internal
178
- * @return string
179
- */
180
- protected function avatar_email() {
181
- $id = (int)$this->user_id;
182
- $user = get_userdata($id);
183
- if ($user) {
184
- $email = $user->user_email;
185
- } else {
186
- $email = $this->comment_author_email;
187
- }
188
- return $email;
189
- }
190
 
191
- /**
192
- * @internal
193
- * @param string $email_hash
194
- * @return string
195
- */
196
- protected function avatar_host($email_hash) {
197
- if (is_ssl()) {
198
- $host = 'https://secure.gravatar.com';
199
- } else {
200
- if (!empty($email_hash)) {
201
- $host = sprintf("http://%d.gravatar.com", (hexdec($email_hash[0]) % 2));
202
- } else {
203
- $host = 'http://0.gravatar.com';
204
- }
205
- }
206
- return $host;
207
- }
208
 
209
- /**
210
- * @internal
211
- * @todo what if it's relative?
212
- * @param string $default
213
- * @param string $email
214
- * @param string $size
215
- * @param string $host
216
- * @return string
217
- */
218
- protected function avatar_default($default, $email, $size, $host) {
219
- if (substr($default, 0, 1) == '/') {
220
- $default = home_url() . $default;
221
- }
222
 
223
- if (empty($default)) {
224
- $avatar_default = get_option('avatar_default');
225
- if (empty($avatar_default)) {
226
- $default = 'mystery';
227
- } else {
228
- $default = $avatar_default;
229
- }
230
- }
231
- if ('mystery' == $default) {
232
- $default = $host . '/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size;
233
- // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com')
234
- } else if ('blank' == $default) {
235
- $default = $email ? 'blank' : includes_url('images/blank.gif');
236
- } else if (!empty($email) && 'gravatar_default' == $default) {
237
- $default = '';
238
- } else if ('gravatar_default' == $default) {
239
- $default = $host . '/avatar/?s=' . $size;
240
- } else if (empty($email) && !strstr($default, 'http://')) {
241
- $default = $host . '/avatar/?d=' . $default . '&amp;s=' . $size;
242
- }
243
- return $default;
244
- }
245
 
246
- /**
247
- * @internal
248
- * @param string $default
249
- * @param string $host
250
- * @param string $email_hash
251
- * @param string $size
252
- * @return mixed
253
- */
254
- protected function avatar_out($default, $host, $email_hash, $size) {
255
- $out = $host . '/avatar/' . $email_hash . '?s=' . $size . '&amp;d=' . urlencode($default);
256
- $rating = get_option('avatar_rating');
257
- if (!empty($rating)) {
258
- $out .= '&amp;r=' . $rating;
259
- }
260
- return str_replace('&#038;', '&amp;', esc_url($out));
261
- }
262
 
263
  }
1
  <?php
2
 
3
+ /**
4
+ * The TimberComment class is used to view the output of comments. 99% of the time this will be in the context of the comments on a post. However you can also fetch a comment directly using its comment ID.
5
+ * @example
6
+ * ```php
7
+ * $comment = new TimberComment($comment_id);
8
+ * $context['comment_of_the_day'] = $comment;
9
+ * Timber::render('index.twig', $context);
10
+ * ```
11
+ *
12
+ * ```twig
13
+ * <p class="comment">{{comment_of_the_day.content}}</p>
14
+ * <p class="comment-attribution">- {{comment.author.name}}</p>
15
+ * ```
16
+ *
17
+ * ```html
18
+ * <p class="comment">But, O Sarah! If the dead can come back to this earth and flit unseen around those they loved, I shall always be near you; in the garish day and in the darkest night -- amidst your happiest scenes and gloomiest hours - always, always; and if there be a soft breeze upon your cheek, it shall be my breath; or the cool air fans your throbbing temple, it shall be my spirit passing by.</p>
19
+ * <p class="comment-attribution">- Sullivan Ballou</p>
20
+ * ```
21
+ */
22
  class TimberComment extends TimberCore implements TimberCoreInterface {
23
 
24
+ public $PostClass = 'TimberPost';
25
+ public $object_type = 'comment';
26
 
27
+ public static $representation = 'comment';
28
 
29
+ public $ID;
30
+ public $id;
31
+ public $comment_author_email;
32
+ public $comment_content;
33
+ public $comment_date;
34
+ public $comment_ID;
35
+ public $user_id;
36
+ public $comment_author;
37
 
38
+ public $children = array();
39
 
40
+ /**
41
+ * @param int $cid
42
+ */
43
+ function __construct($cid) {
44
+ $this->init($cid);
45
+ }
46
 
47
+ function __toString(){
48
+ return $this->content();
49
+ }
50
 
51
+ /**
52
+ * @internal
53
+ * @param integer $cid
54
+ */
55
+ function init($cid) {
56
+ $comment_data = $cid;
57
+ if (is_integer($cid)) {
58
+ $comment_data = get_comment($cid);
59
+ }
60
+ $this->import($comment_data);
61
+ $this->ID = $this->comment_ID;
62
+ $this->id = $this->comment_ID;
63
+ $comment_meta_data = $this->get_meta_fields($this->ID);
64
+ $this->import($comment_meta_data);
65
+ }
66
 
67
+ /**
68
+ * @api
69
+ * @example
70
+ * ```twig
71
+ * <h3>Comments by...</h3>
72
+ * <ol>
73
+ * {% for comment in post.comments %}
74
+ * <li>{{comment.author.name}}, who is a {{comment.author.role}}</li>
75
+ * {% endfor %}
76
+ * </ol>
77
+ * ```
78
+ * ```html
79
+ * <h3>Comments by...</h3>
80
+ * <ol>
81
+ * <li>Jared Novack, who is a contributor</li>
82
+ * <li>Katie Ricci, who is a subscriber</li>
83
+ * <li>Rebecca Pearl, who is a author</li>
84
+ * </ol>
85
+ * ```
86
+ * @return TimberUser
87
+ */
88
+ public function author() {
89
+ if ($this->user_id) {
90
+ return new TimberUser($this->user_id);
91
+ } else {
92
+ $author = new TimberUser(0);
93
+ if (isset($this->comment_author) && $this->comment_author) {
94
+ $author->name = $this->comment_author;
95
+ } else {
96
+ $author->name = 'Anonymous';
97
+ }
98
+ }
99
+ return $author;
100
+ }
101
 
102
+ /**
103
+ * Fetches the Gravatar
104
+ * @api
105
+ * @example
106
+ * ```twig
107
+ * <img src="{{comment.avatar(36,template_uri~"/img/dude.jpg")}}" alt="Image of {{comment.author.name}}" />
108
+ * ```
109
+ * ```html
110
+ * <img src="http://gravatar.com/i/sfsfsdfasdfsfa.jpg" alt="Image of Katherine Rich" />
111
+ * ```
112
+ * @param int $size
113
+ * @param string $default
114
+ * @return bool|mixed|string
115
+ */
116
+ public function avatar($size = 92, $default = '') {
117
+ if (!get_option('show_avatars')) {
118
+ return false;
119
+ }
120
+ if (!is_numeric($size)) {
121
+ $size = '92';
122
+ }
123
 
124
+ $email = $this->avatar_email();
125
+ $email_hash = '';
126
+ if (!empty($email)) {
127
+ $email_hash = md5(strtolower(trim($email)));
128
+ }
129
+ $host = $this->avatar_host($email_hash);
130
+ $default = $this->avatar_default($default, $email, $size, $host);
131
+ if (!empty($email)) {
132
+ $avatar = $this->avatar_out($default, $host, $email_hash, $size);
133
+ } else {
134
+ $avatar = $default;
135
+ }
136
+ return $avatar;
137
+ }
138
 
139
+ /**
140
+ * @api
141
+ * @return string
142
+ */
143
+ public function content() {
144
+ return apply_filters('get_comment_text ', $this->comment_content);
145
+ }
146
 
147
+ /**
148
+ * @api
149
+ * @example
150
+ * ```twig
151
+ * {% if comment.approved %}
152
+ * Your comment is good
153
+ * {% else %}
154
+ * Do you kiss your mother with that mouth?
155
+ * {% endif %}
156
+ * ```
157
+ * @return boolean
158
+ */
159
+ public function approved() {
160
+ return $this->comment_approved;
161
+ }
162
 
163
+ /**
164
+ * @api
165
+ * @example
166
+ * ```twig
167
+ * {% for comment in post.comments %}
168
+ * <article class="comment">
169
+ * <p class="date">Posted on {{ comment.date }}:</p>
170
+ * <p class="comment">{{ comment.content }}</p>
171
+ * </article>
172
+ * {% endfor %}
173
+ * ```
174
+ * ```html
175
+ * <article class="comment">
176
+ * <p class="date">Posted on September 28, 2015:</p>
177
+ * <p class="comment">Happy Birthday!</p>
178
+ * </article>
179
+ * ```
180
+ * @return string
181
+ */
182
+ public function date( $date_format = '' ) {
183
+ $df = $date_format ? $date_format : get_option('date_format');
184
  $the_date = (string)mysql2date($df, $this->comment_date);
185
  return apply_filters('get_comment_date ', $the_date, $df);
186
+ }
187
 
188
+ /**
189
+ * @param string $field_name
190
+ * @return mixed
191
+ */
192
+ public function meta($field_name) {
193
+ return $this->get_meta_field($field_name);
194
+ }
195
 
196
+ /**
197
+ * @api
198
+ * @return bool
199
+ */
200
+ public function is_child() {
201
+ return $this->comment_parent > 0;
202
+ }
203
 
204
+ /**
205
+ * @internal
206
+ * @param int $comment_id
207
+ * @return mixed
208
+ */
209
+ protected function get_meta_fields($comment_id = null) {
210
+ if ($comment_id === null) {
211
+ $comment_id = $this->ID;
212
+ }
213
+ //Could not find a WP function to fetch all comment meta data, so I made one.
214
+ apply_filters('timber_comment_get_meta_pre', array(), $comment_id);
215
+ $comment_metas = get_comment_meta($comment_id);
216
+ foreach ($comment_metas as &$cm) {
217
+ if (is_array($cm) && count($cm) == 1) {
218
+ $cm = $cm[0];
219
+ }
220
+ }
221
+ $comment_metas = apply_filters('timber_comment_get_meta', $comment_metas, $comment_id);
222
+ return $comment_metas;
223
+ }
224
 
225
+ /**
226
+ * @internal
227
+ * @param string $field_name
228
+ * @return mixed
229
+ */
230
+ protected function get_meta_field($field_name) {
231
+ $value = apply_filters('timber_comment_get_meta_field_pre', null, $this->ID, $field_name, $this);
232
+ if ($value === null) {
233
+ $value = get_comment_meta($this->ID, $field_name, true);
234
+ }
235
+ $value = apply_filters('timber_comment_get_meta_field', $value, $this->ID, $field_name, $this);
236
+ return $value;
237
+ }
238
 
239
+ /* AVATAR Stuff
240
+ ======================= */
241
 
242
+ /**
243
+ * @internal
244
+ * @return string
245
+ */
246
+ protected function avatar_email() {
247
+ $id = (int)$this->user_id;
248
+ $user = get_userdata($id);
249
+ if ($user) {
250
+ $email = $user->user_email;
251
+ } else {
252
+ $email = $this->comment_author_email;
253
+ }
254
+ return $email;
255
+ }
256
 
257
+ /**
258
+ * @internal
259
+ * @param string $email_hash
260
+ * @return string
261
+ */
262
+ protected function avatar_host($email_hash) {
263
+ if (is_ssl()) {
264
+ $host = 'https://secure.gravatar.com';
265
+ } else {
266
+ if (!empty($email_hash)) {
267
+ $host = sprintf("http://%d.gravatar.com", (hexdec($email_hash[0]) % 2));
268
+ } else {
269
+ $host = 'http://0.gravatar.com';
270
+ }
271
+ }
272
+ return $host;
273
+ }
274
 
275
+ /**
276
+ * @internal
277
+ * @todo what if it's relative?
278
+ * @param string $default
279
+ * @param string $email
280
+ * @param string $size
281
+ * @param string $host
282
+ * @return string
283
+ */
284
+ protected function avatar_default($default, $email, $size, $host) {
285
+ if (substr($default, 0, 1) == '/') {
286
+ $default = home_url() . $default;
287
+ }
288
 
289
+ if (empty($default)) {
290
+ $avatar_default = get_option('avatar_default');
291
+ if (empty($avatar_default)) {
292
+ $default = 'mystery';
293
+ } else {
294
+ $default = $avatar_default;
295
+ }
296
+ }
297
+ if ('mystery' == $default) {
298
+ $default = $host . '/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size;
299
+ // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com')
300
+ } else if ('blank' == $default) {
301
+ $default = $email ? 'blank' : includes_url('images/blank.gif');
302
+ } else if (!empty($email) && 'gravatar_default' == $default) {
303
+ $default = '';
304
+ } else if ('gravatar_default' == $default) {
305
+ $default = $host . '/avatar/?s=' . $size;
306
+ } else if (empty($email) && !strstr($default, 'http://')) {
307
+ $default = $host . '/avatar/?d=' . $default . '&amp;s=' . $size;
308
+ }
309
+ return $default;
310
+ }
311
 
312
+ /**
313
+ * @internal
314
+ * @param string $default
315
+ * @param string $host
316
+ * @param string $email_hash
317
+ * @param string $size
318
+ * @return mixed
319
+ */
320
+ protected function avatar_out($default, $host, $email_hash, $size) {
321
+ $out = $host . '/avatar/' . $email_hash . '?s=' . $size . '&amp;d=' . urlencode($default);
322
+ $rating = get_option('avatar_rating');
323
+ if (!empty($rating)) {
324
+ $out .= '&amp;r=' . $rating;
325
+ }
326
+ return str_replace('&#038;', '&amp;', esc_url($out));
327
+ }
328
 
329
  }
lib/timber-core.php CHANGED
@@ -32,21 +32,27 @@ abstract class TimberCore {
32
  * @return mixed
33
  */
34
  function __get( $field ) {
35
- if ( isset( $this->$field ) ) {
36
- return $this->$field;
37
- }
38
- if ( $meta_value = $this->meta( $field ) ) {
39
  return $this->$field = $meta_value;
40
  }
41
- if (method_exists($this, $field)) {
42
  return $this->$field = $this->$field();
43
  }
44
  return $this->$field = false;
45
  }
46
 
47
  /**
48
- *
49
- *
 
 
 
 
 
 
50
  * @param array|object $info an object or array you want to grab data from to attach to the Timber object
51
  */
52
  function import( $info, $force = false ) {
@@ -66,8 +72,7 @@ abstract class TimberCore {
66
 
67
 
68
  /**
69
- *
70
- *
71
  * @param string $key
72
  * @param mixed $value
73
  */
@@ -76,6 +81,16 @@ abstract class TimberCore {
76
  }
77
 
78
  /**
 
 
 
 
 
 
 
 
 
 
79
  * @return bool
80
  */
81
  function can_edit() {
32
  * @return mixed
33
  */
34
  function __get( $field ) {
35
+ if ( property_exists($this, $field) ) {
36
+ return $this->$field;
37
+ }
38
+ if ( method_exists($this, 'meta') && $meta_value = $this->meta( $field ) ) {
39
  return $this->$field = $meta_value;
40
  }
41
+ if ( method_exists($this, $field) ) {
42
  return $this->$field = $this->$field();
43
  }
44
  return $this->$field = false;
45
  }
46
 
47
  /**
48
+ * Takes an array or object and adds the properties to the parent object
49
+ * @example
50
+ * ```php
51
+ * $data = array('airplane' => '757-200', 'flight' => '5316');
52
+ * $post = new TimberPost()
53
+ * $post->import(data);
54
+ * echo $post->airplane; //757-200
55
+ * ```
56
  * @param array|object $info an object or array you want to grab data from to attach to the Timber object
57
  */
58
  function import( $info, $force = false ) {
72
 
73
 
74
  /**
75
+ * @ignore
 
76
  * @param string $key
77
  * @param mixed $value
78
  */
81
  }
82
 
83
  /**
84
+ * Can you edit this post/term/user? Well good for you. You're no better than me.
85
+ * @example
86
+ * ```twig
87
+ * {% if post.can_edit %}
88
+ * <a href="{{ post.edit_link }}">Edit</a>
89
+ * {% endif %}
90
+ * ```
91
+ * ```html
92
+ * <a href="http://example.org/wp-admin/edit.php?p=242">Edit</a>
93
+ * ```
94
  * @return bool
95
  */
96
  function can_edit() {
lib/timber-helper.php CHANGED
@@ -1,5 +1,8 @@
1
  <?php
2
 
 
 
 
3
  class TimberHelper {
4
 
5
  /**
@@ -89,8 +92,8 @@ class TimberHelper {
89
  /* These are for measuring page render time */
90
 
91
  /**
92
- *
93
- *
94
  * @return float
95
  */
96
  public static function start_timer() {
@@ -101,8 +104,13 @@ class TimberHelper {
101
  }
102
 
103
  /**
104
- *
105
- *
 
 
 
 
 
106
  * @param int $start
107
  * @return string
108
  */
@@ -119,8 +127,27 @@ class TimberHelper {
119
  ======================== */
120
 
121
  /**
122
- *
123
- *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  * @param callback $function
125
  * @param array $args
126
  * @return string
@@ -249,22 +276,6 @@ class TimberHelper {
249
  return $html;
250
  }
251
 
252
- /**
253
- * @param string $ret
254
- * @return string
255
- * @deprecated since 0.20.0
256
- */
257
- public static function twitterify( $ret ) {
258
- $ret = preg_replace( "#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret );
259
- $ret = preg_replace( "#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret );
260
- $pattern = '#([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.';
261
- $pattern .= '[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?)#i';
262
- $ret = preg_replace( $pattern, '<a href="mailto:\\1">\\1</a>', $ret );
263
- $ret = preg_replace( "/\B@(\w+)/", " <a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $ret );
264
- $ret = preg_replace( "/\B#(\w+)/", " <a href=\"http://twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $ret );
265
- return trim($ret);
266
- }
267
-
268
  /* WordPress Query Utilities
269
  ======================== */
270
 
@@ -272,7 +283,7 @@ class TimberHelper {
272
  * @param string $key
273
  * @param string $value
274
  * @return array|int
275
- * @deprecated since 0.20.0
276
  */
277
  public static function get_posts_by_meta( $key, $value ) {
278
  global $wpdb;
@@ -296,7 +307,7 @@ class TimberHelper {
296
  * @param string $key
297
  * @param string $value
298
  * @return int
299
- * @deprecated since 0.20.0
300
  */
301
  public static function get_post_by_meta( $key, $value ) {
302
  global $wpdb;
@@ -312,7 +323,7 @@ class TimberHelper {
312
 
313
  /**
314
  *
315
- * @deprecated since 0.21.8
316
  * @param int $ttid
317
  * @return mixed
318
  */
@@ -478,7 +489,7 @@ class TimberHelper {
478
  /**
479
  *
480
  * Gets the comment form for use on a single article page
481
- * @deprecated since 0.21.8
482
  * @param int $post_id which post_id should the form be tied to?
483
  * @param array $args this $args thing is a fucking mess, [fix at some point](http://codex.wordpress.org/Function_Reference/comment_form)
484
  * @return string
@@ -590,91 +601,91 @@ class TimberHelper {
590
  }
591
 
592
  /**
593
- * @deprecated since 0.18.0
594
  */
595
  static function get_current_url() {
596
  return TimberURLHelper::get_current_url();
597
  }
598
 
599
  /**
600
- * @deprecated since 0.18.0
601
  */
602
  static function is_url( $url ) {
603
  return TimberURLHelper::is_url( $url );
604
  }
605
 
606
  /**
607
- * @deprecated since 0.18.0
608
  */
609
  static function get_path_base() {
610
  return TimberURLHelper::get_path_base();
611
  }
612
 
613
  /**
614
- * @deprecated since 0.18.0
615
  */
616
  static function get_rel_url( $url, $force = false ) {
617
  return TimberURLHelper::get_rel_url( $url, $force );
618
  }
619
 
620
  /**
621
- * @deprecated since 0.18.0
622
  */
623
  static function is_local( $url ) {
624
  return TimberURLHelper::is_local( $url );
625
  }
626
 
627
  /**
628
- * @deprecated since 0.18.0
629
  */
630
  static function get_full_path( $src ) {
631
  return TimberURLHelper::get_full_path( $src );
632
  }
633
 
634
  /**
635
- * @deprecated since 0.18.0
636
  */
637
  static function get_rel_path( $src ) {
638
  return TimberURLHelper::get_rel_path( $src );
639
  }
640
 
641
  /**
642
- * @deprecated since 0.18.0
643
  */
644
  static function remove_double_slashes( $url ) {
645
  return TimberURLHelper::remove_double_slashes( $url );
646
  }
647
 
648
  /**
649
- * @deprecated since 0.18.0
650
  */
651
  static function prepend_to_url( $url, $path ) {
652
  return TimberURLHelper::prepend_to_url( $url, $path );
653
  }
654
 
655
  /**
656
- * @deprecated since 0.18.0
657
  */
658
  static function preslashit( $path ) {
659
  return TimberURLHelper::preslashit( $path );
660
  }
661
 
662
  /**
663
- * @deprecated since 0.18.0
664
  */
665
  static function is_external( $url ) {
666
  return TimberURLHelper::is_external( $url );
667
  }
668
 
669
  /**
670
- * @deprecated since 0.18.0
671
  */
672
  static function download_url( $url, $timeout = 300 ) {
673
  return TimberURLHelper::download_url( $url, $timeout );
674
  }
675
 
676
  /**
677
- * @deprecated since 0.18.0
678
  */
679
  static function get_params( $i = -1 ) {
680
  return TimberURLHelper::get_params( $i );
1
  <?php
2
 
3
+ /**
4
+ * As the name suggests these are helpers for Timber (and you!) when developing. You can find additional (mainly internally-focused helpers) in TimberURLHelper
5
+ */
6
  class TimberHelper {
7
 
8
  /**
92
  /* These are for measuring page render time */
93
 
94
  /**
95
+ * For measuring time, this will start a timer
96
+ * @api
97
  * @return float
98
  */
99
  public static function start_timer() {
104
  }
105
 
106
  /**
107
+ * For stopping time and getting the data
108
+ * @example
109
+ * ```php
110
+ * $start = TimberHelper::start_timer();
111
+ * // do some stuff that takes awhile
112
+ * echo TimberHelper::stop_timer( $start );
113
+ * ```
114
  * @param int $start
115
  * @return string
116
  */
127
  ======================== */
128
 
129
  /**
130
+ * Calls a function with an output buffer. This is useful if you have a function that outputs text that you want to capture and use within a twig template.
131
+ * @example
132
+ * ```php
133
+ * function the_form() {
134
+ * echo '<form action="form.php"><input type="text" /><input type="submit /></form>';
135
+ * }
136
+ *
137
+ * $context = Timber::get_context();
138
+ * $context['post'] = new TimberPost();
139
+ * $context['my_form'] = TimberHelper::ob_function('the_form');
140
+ * Timber::render('single-form.twig', $context);
141
+ * ```
142
+ * ```twig
143
+ * <h1>{{ post.title }}</h1>
144
+ * {{ my_form }}
145
+ * ```
146
+ * ```html
147
+ * <h1>Apply to my contest!</h1>
148
+ * <form action="form.php"><input type="text" /><input type="submit /></form>
149
+ * ```
150
+ * @api
151
  * @param callback $function
152
  * @param array $args
153
  * @return string
276
  return $html;
277
  }
278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  /* WordPress Query Utilities
280
  ======================== */
281
 
283
  * @param string $key
284
  * @param string $value
285
  * @return array|int
286
+ * @deprecated 0.20.0
287
  */
288
  public static function get_posts_by_meta( $key, $value ) {
289
  global $wpdb;
307
  * @param string $key
308
  * @param string $value
309
  * @return int
310
+ * @deprecated 0.20.0
311
  */
312
  public static function get_post_by_meta( $key, $value ) {
313
  global $wpdb;
323
 
324
  /**
325
  *
326
+ * @deprecated 0.21.8
327
  * @param int $ttid
328
  * @return mixed
329
  */
489
  /**
490
  *
491
  * Gets the comment form for use on a single article page
492
+ * @deprecated 0.21.8 use `{{ function('comment_form') }}` instead
493
  * @param int $post_id which post_id should the form be tied to?
494
  * @param array $args this $args thing is a fucking mess, [fix at some point](http://codex.wordpress.org/Function_Reference/comment_form)
495
  * @return string
601
  }
602
 
603
  /**
604
+ * @deprecated 0.18.0
605
  */
606
  static function get_current_url() {
607
  return TimberURLHelper::get_current_url();
608
  }
609
 
610
  /**
611
+ * @deprecated 0.18.0
612
  */
613
  static function is_url( $url ) {
614
  return TimberURLHelper::is_url( $url );
615
  }
616
 
617
  /**
618
+ * @deprecated 0.18.0
619
  */
620
  static function get_path_base() {
621
  return TimberURLHelper::get_path_base();
622
  }
623
 
624
  /**
625
+ * @deprecated 0.18.0
626
  */
627
  static function get_rel_url( $url, $force = false ) {
628
  return TimberURLHelper::get_rel_url( $url, $force );
629
  }
630
 
631
  /**
632
+ * @deprecated 0.18.0
633
  */
634
  static function is_local( $url ) {
635
  return TimberURLHelper::is_local( $url );
636
  }
637
 
638
  /**
639
+ * @deprecated 0.18.0
640
  */
641
  static function get_full_path( $src ) {
642
  return TimberURLHelper::get_full_path( $src );
643
  }
644
 
645
  /**
646
+ * @deprecated 0.18.0
647
  */
648
  static function get_rel_path( $src ) {
649
  return TimberURLHelper::get_rel_path( $src );
650
  }
651
 
652
  /**
653
+ * @deprecated 0.18.0
654
  */
655
  static function remove_double_slashes( $url ) {
656
  return TimberURLHelper::remove_double_slashes( $url );
657
  }
658
 
659
  /**
660
+ * @deprecated 0.18.0
661
  */
662
  static function prepend_to_url( $url, $path ) {
663
  return TimberURLHelper::prepend_to_url( $url, $path );
664
  }
665
 
666
  /**
667
+ * @deprecated 0.18.0
668
  */
669
  static function preslashit( $path ) {
670
  return TimberURLHelper::preslashit( $path );
671
  }
672
 
673
  /**
674
+ * @deprecated 0.18.0
675
  */
676
  static function is_external( $url ) {
677
  return TimberURLHelper::is_external( $url );
678
  }
679
 
680
  /**
681
+ * @deprecated 0.18.0
682
  */
683
  static function download_url( $url, $timeout = 300 ) {
684
  return TimberURLHelper::download_url( $url, $timeout );
685
  }
686
 
687
  /**
688
+ * @deprecated 0.18.0
689
  */
690
  static function get_params( $i = -1 ) {
691
  return TimberURLHelper::get_params( $i );
lib/timber-image-helper.php CHANGED
@@ -28,11 +28,19 @@ class TimberImageHelper {
28
  * Generates a new image with the specified dimensions.
29
  * New dimensions are achieved by cropping to maintain ratio.
30
  *
 
31
  * @param string $src an URL (absolute or relative) to the original image
32
  * @param int|string $w target width(int) or WordPress image size (WP-set or user-defined)
33
  * @param int $h target height (ignored if $w is WP image size)
34
- * @param string $crop
35
  * @param bool $force
 
 
 
 
 
 
 
36
  * @return string (ex: )
37
  */
38
  public static function resize( $src, $w, $h = 0, $crop = 'default', $force = false ) {
@@ -59,11 +67,6 @@ class TimberImageHelper {
59
  * }
60
  */
61
  private static function find_wp_dimensions( $size ) {
62
-
63
- // if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ) ) ) {
64
-
65
- // $sizes[ $_size ]['width'] = get_option( $_size . '_size_w' );
66
- // $sizes[ $_size ]['height'] = get_option( $_size . '_size_h' );
67
  global $_wp_additional_image_sizes;
68
  if (isset($_wp_additional_image_sizes[$size])) {
69
  $w = $_wp_additional_image_sizes[$size]['width'];
@@ -181,8 +184,8 @@ class TimberImageHelper {
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/
28
  * Generates a new image with the specified dimensions.
29
  * New dimensions are achieved by cropping to maintain ratio.
30
  *
31
+ * @api
32
  * @param string $src an URL (absolute or relative) to the original image
33
  * @param int|string $w target width(int) or WordPress image size (WP-set or user-defined)
34
  * @param int $h target height (ignored if $w is WP image size)
35
+ * @param string $crop your choices are 'default', 'center', 'top', 'bottom', 'left', 'right'
36
  * @param bool $force
37
+ * @example
38
+ * ```twig
39
+ * <img src="{{ image.src | resize(300, 200, 'top') }}" />
40
+ * ```
41
+ * ```html
42
+ * <img src="http://example.org/wp-content/uploads/pic-300x200-c-top.jpg" />
43
+ * ```
44
  * @return string (ex: )
45
  */
46
  public static function resize( $src, $w, $h = 0, $crop = 'default', $force = false ) {
67
  * }
68
  */
69
  private static function find_wp_dimensions( $size ) {
 
 
 
 
 
70
  global $_wp_additional_image_sizes;
71
  if (isset($_wp_additional_image_sizes[$size])) {
72
  $w = $_wp_additional_image_sizes[$size]['width'];
184
  *
185
  * keeping these here so I know what the hell we're matching
186
  * $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);
187
+ * $match = preg_match("/\/srv\/www\/wordpress-develop\/src\/wp-content\/uploads\/2014\/05\/arch-[0-9]*x[0-9]*-c-[a-z]*.jpg/", $filename);
188
+ *
189
  * @param string $filename ex: my-pic
190
  * @param string $ext ex: jpg
191
  * @param string $dir var/www/wp-content/uploads/2015/
lib/timber-image.php CHANGED
@@ -1,5 +1,42 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  class TimberImage extends TimberPost implements TimberCoreInterface {
4
 
5
  protected $_can_edit;
@@ -21,6 +58,7 @@ class TimberImage extends TimberPost implements TimberCoreInterface {
21
  public $file;
22
  public $sizes = array();
23
  /**
 
24
  * @var string $caption the string stored in the WordPress database
25
  */
26
  public $caption;
@@ -30,14 +68,23 @@ class TimberImage extends TimberPost implements TimberCoreInterface {
30
  protected $_wp_attached_file;
31
 
32
  /**
33
- * @param int $iid
 
 
 
 
 
 
 
 
 
34
  */
35
  public function __construct($iid) {
36
  $this->init($iid);
37
  }
38
 
39
  /**
40
- * @return string
41
  */
42
  public function __toString() {
43
  if ($this->get_src()) {
@@ -47,26 +94,29 @@ class TimberImage extends TimberPost implements TimberCoreInterface {
47
  }
48
 
49
  /**
50
- * @internal
51
- * @return mixed
52
  */
53
  function get_pathinfo() {
54
  return pathinfo($this->file);
55
  }
56
 
57
  /**
 
58
  * @param string $dim
59
  * @return array|int
60
  */
61
- function get_dimensions($dim = null) {
62
  if (isset($this->_dimensions)) {
63
  return $this->get_dimensions_loaded($dim);
64
  }
65
- list($width, $height) = getimagesize($this->file_loc);
66
- $this->_dimensions = array();
67
- $this->_dimensions[0] = $width;
68
- $this->_dimensions[1] = $height;
69
- return $this->get_dimensions_loaded($dim);
 
 
70
  }
71
 
72
  /**
@@ -89,49 +139,32 @@ class TimberImage extends TimberPost implements TimberCoreInterface {
89
 
90
  /**
91
  * @internal
92
- * @return int
93
- */
94
- function get_width() {
95
- return $this->get_dimensions('width');
96
- }
97
-
98
- /**
99
- * @internal
100
- * @return int
101
- */
102
- function get_height() {
103
- return $this->get_dimensions('height');
104
- }
105
-
106
- /**
107
- * @internal
108
- * @param string $size
109
- * @return bool|string
110
  */
111
- function get_src( $size = '' ) {
112
- if ( isset($this->abs_url) ) {
113
- return $this->_maybe_secure_url($this->abs_url);
114
- }
115
-
116
- if ( $size && is_string($size) && isset($this->sizes[$size]) ) {
117
- $image = image_downsize($this->ID, $size);
118
- return $this->_maybe_secure_url(reset($image));
 
 
 
 
 
 
 
 
119
  }
120
-
121
- if ( !isset($this->file) && isset($this->_wp_attached_file) ) {
122
- $this->file = $this->_wp_attached_file;
123
  }
124
-
125
- if ( !isset($this->file) ) {
126
- return false;
127
  }
128
-
129
- $dir = self::wp_upload_dir();
130
- $base = $dir['baseurl'];
131
-
132
- $src = trailingslashit($this->_maybe_secure_url($base)) . $this->file;
133
- $src = apply_filters('timber/image/src', $src, $this->ID);
134
- return apply_filters('timber_image_src', $src, $this->ID);
135
  }
136
 
137
  /**
@@ -156,56 +189,6 @@ class TimberImage extends TimberPost implements TimberCoreInterface {
156
  return $wp_upload_dir;
157
  }
158
 
159
- /**
160
- * @internal
161
- * @return string
162
- */
163
- function get_path() {
164
- if (strlen($this->abs_url)) {
165
- return $this->abs_url;
166
- }
167
- return get_permalink($this->ID);
168
- }
169
-
170
- /**
171
- * @api
172
- * @return string the /relative/path/to/the/file
173
- */
174
- public function path() {
175
- return TimberURLHelper::get_rel_path($this->src());
176
- }
177
-
178
- /**
179
- * @api
180
- * @return bool|TimberPost
181
- */
182
- function parent() {
183
- if (!$this->post_parent) {
184
- return false;
185
- }
186
- return new $this->PostClass($this->post_parent);
187
- }
188
-
189
- /**
190
- * @internal
191
- * @deprecated 0.21.8
192
- * @return bool|TimberPost
193
- */
194
- function get_parent() {
195
- return $this->parent();
196
- }
197
-
198
- /**
199
- * @internal
200
- * @see TimberImage::alt
201
- * @return string
202
- */
203
- function get_alt() {
204
- $alt = trim(strip_tags(get_post_meta($this->ID, '_wp_attachment_image_alt', true)));
205
- return $alt;
206
- }
207
-
208
-
209
  /**
210
  * @internal
211
  * @param int $iid
@@ -257,36 +240,6 @@ class TimberImage extends TimberPost implements TimberCoreInterface {
257
  }
258
  }
259
 
260
- /**
261
- * @internal
262
- * @param int $iid the id number of the image in the WP database
263
- */
264
- protected function get_image_info( $iid ) {
265
- $image_info = $iid;
266
- if (is_numeric($iid)) {
267
- $image_info = wp_get_attachment_metadata($iid);
268
- if (!is_array($image_info)) {
269
- $image_info = array();
270
- }
271
- $image_custom = get_post_custom($iid);
272
- $basic = get_post($iid);
273
- if ($basic) {
274
- if (isset($basic->post_excerpt)) {
275
- $this->caption = $basic->post_excerpt;
276
- }
277
- $image_custom = array_merge($image_custom, get_object_vars($basic));
278
- }
279
- return array_merge($image_info, $image_custom);
280
- }
281
- if (is_array($image_info) && isset($image_info['image'])) {
282
- return $image_info['image'];
283
- }
284
- if (is_object($image_info)) {
285
- return get_object_vars($image_info);
286
- }
287
- return $iid;
288
- }
289
-
290
  /**
291
  * @internal
292
  * @param string $relative_path
@@ -322,19 +275,19 @@ class TimberImage extends TimberPost implements TimberCoreInterface {
322
  }
323
 
324
  /**
325
- * @deprecated use src() instead
326
- * @return string
327
- */
328
- function get_url() {
329
- return $this->get_src();
330
- }
331
-
332
- /**
333
- * @deprecated use src() instead
334
- * @return string
335
  */
336
- function url() {
337
- return $this->get_src();
 
338
  }
339
 
340
  /**
@@ -343,7 +296,11 @@ class TimberImage extends TimberPost implements TimberCoreInterface {
343
  * ```twig
344
  * {% if post.thumbnail.aspect < 1 %}
345
  * {# handle vertical image #}
346
- * <img
 
 
 
 
347
  * @return float
348
  */
349
  public function aspect() {
@@ -354,35 +311,188 @@ class TimberImage extends TimberPost implements TimberCoreInterface {
354
 
355
  /**
356
  * @api
 
 
 
 
 
 
 
357
  * @return int
358
  */
359
  public function height() {
360
- return $this->get_height();
361
  }
362
 
363
  /**
 
364
  * @api
365
- * @param string $size
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  * @return bool|string
367
  */
368
  public function src($size = '') {
369
- return $this->get_src($size);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
  }
371
 
372
  /**
373
  * @api
 
 
 
 
 
 
 
374
  * @return int
375
  */
376
  public function width() {
377
- return $this->get_width();
378
  }
379
 
 
380
  /**
381
- * @api
382
- * @return string alt text stored in WordPress
 
383
  */
384
- public function alt() {
385
- return $this->get_alt();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
  }
387
 
388
  }
1
  <?php
2
 
3
+ /**
4
+ * If TimberPost is the class you're going to spend the most time, TimberImage is the class you're going to have the most fun with.
5
+ * @example
6
+ * ```php
7
+ * $context = Timber::get_context();
8
+ * $post = new TimberPost();
9
+ * $context['post'] = $post;
10
+ *
11
+ * // lets say you have an alternate large 'cover image' for your post stored in a custom field which returns an image ID
12
+ * $cover_image_id = $post->cover_image;
13
+ * $context['cover_image'] = new TimberImage($cover_image_id);
14
+ * Timber::render('single.twig', $context);
15
+ * ```
16
+ *
17
+ * ```twig
18
+ * <article>
19
+ * <img src="{{cover_image.src}}" class="cover-image" />
20
+ * <h1 class="headline">{{post.title}}</h1>
21
+ * <div class="body">
22
+ * {{post.content}}
23
+ * </div>
24
+ *
25
+ * <img src="{{ Image(post.custom_field_with_image_id).src }}" alt="Another way to initialize images as TimberImages, but within Twig" />
26
+ * </article>
27
+ * ```
28
+ *
29
+ * ```html
30
+ * <article>
31
+ * <img src="http://example.org/wp-content/uploads/2015/06/nevermind.jpg" class="cover-image" />
32
+ * <h1 class="headline">Now you've done it!</h1>
33
+ * <div class="body">
34
+ * Whatever whatever
35
+ * </div>
36
+ * <img src="http://example.org/wp-content/uploads/2015/06/kurt.jpg" alt="Another way to initialize images as TimberImages, but within Twig" />
37
+ * </article>
38
+ * ```
39
+ */
40
  class TimberImage extends TimberPost implements TimberCoreInterface {
41
 
42
  protected $_can_edit;
58
  public $file;
59
  public $sizes = array();
60
  /**
61
+ * @api
62
  * @var string $caption the string stored in the WordPress database
63
  */
64
  public $caption;
68
  protected $_wp_attached_file;
69
 
70
  /**
71
+ * Creates a new TimberImage object
72
+ * @example
73
+ * ```php
74
+ * // You can pass it an ID number
75
+ * $myImage = new TimberImage(552);
76
+ *
77
+ * //Or send it a URL to an image
78
+ * $myImage = new TimberImage('http://google.com/logo.jpg');
79
+ * ```
80
+ * @param int|string $iid
81
  */
82
  public function __construct($iid) {
83
  $this->init($iid);
84
  }
85
 
86
  /**
87
+ * @return string the src of the file
88
  */
89
  public function __toString() {
90
  if ($this->get_src()) {
94
  }
95
 
96
  /**
97
+ * Get a PHP array with pathinfo() info from the file
98
+ * @return array
99
  */
100
  function get_pathinfo() {
101
  return pathinfo($this->file);
102
  }
103
 
104
  /**
105
+ * @internal
106
  * @param string $dim
107
  * @return array|int
108
  */
109
+ protected function get_dimensions($dim = null) {
110
  if (isset($this->_dimensions)) {
111
  return $this->get_dimensions_loaded($dim);
112
  }
113
+ if ( file_exists($this->file_loc) && filesize($this->file_loc) ) {
114
+ list($width, $height) = getimagesize($this->file_loc);
115
+ $this->_dimensions = array();
116
+ $this->_dimensions[0] = $width;
117
+ $this->_dimensions[1] = $height;
118
+ return $this->get_dimensions_loaded($dim);
119
+ }
120
  }
121
 
122
  /**
139
 
140
  /**
141
  * @internal
142
+ * @param int $iid the id number of the image in the WP database
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  */
144
+ protected function get_image_info( $iid ) {
145
+ $image_info = $iid;
146
+ if (is_numeric($iid)) {
147
+ $image_info = wp_get_attachment_metadata($iid);
148
+ if (!is_array($image_info)) {
149
+ $image_info = array();
150
+ }
151
+ $image_custom = get_post_custom($iid);
152
+ $basic = get_post($iid);
153
+ if ($basic) {
154
+ if (isset($basic->post_excerpt)) {
155
+ $this->caption = $basic->post_excerpt;
156
+ }
157
+ $image_custom = array_merge($image_custom, get_object_vars($basic));
158
+ }
159
+ return array_merge($image_info, $image_custom);
160
  }
161
+ if (is_array($image_info) && isset($image_info['image'])) {
162
+ return $image_info['image'];
 
163
  }
164
+ if (is_object($image_info)) {
165
+ return get_object_vars($image_info);
 
166
  }
167
+ return $iid;
 
 
 
 
 
 
168
  }
169
 
170
  /**
189
  return $wp_upload_dir;
190
  }
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  /**
193
  * @internal
194
  * @param int $iid
240
  }
241
  }
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  /**
244
  * @internal
245
  * @param string $relative_path
275
  }
276
 
277
  /**
278
+ * @api
279
+ * @example
280
+ * ```twig
281
+ * <img src="{{ image.src }}" alt="{{ image.alt }}" />
282
+ * ```
283
+ * ```html
284
+ * <img src="http://example.org/wp-content/uploads/2015/08/pic.jpg" alt="W3 Checker told me to add alt text, so I am" />
285
+ * ```
286
+ * @return string alt text stored in WordPress
 
287
  */
288
+ public function alt() {
289
+ $alt = trim(strip_tags(get_post_meta($this->ID, '_wp_attachment_image_alt', true)));
290
+ return $alt;
291
  }
292
 
293
  /**
296
  * ```twig
297
  * {% if post.thumbnail.aspect < 1 %}
298
  * {# handle vertical image #}
299
+ * <img src="{{ post.thumbnail.src|resize(300, 500) }}" alt="A basketball player" />
300
+ * {% else %}
301
+ * <img src="{{ post.thumbnail.src|resize(500) }}" alt="A sumo wrestler" />
302
+ * {% endif %}
303
+ * ```
304
  * @return float
305
  */
306
  public function aspect() {
311
 
312
  /**
313
  * @api
314
+ * @example
315
+ * ```twig
316
+ * <img src="{{ image.src }}" height="{{ image.height }}" />
317
+ * ```
318
+ * ```html
319
+ * <img src="http://example.org/wp-content/uploads/2015/08/pic.jpg" height="900" />
320
+ * ```
321
  * @return int
322
  */
323
  public function height() {
324
+ return $this->get_dimensions('height');
325
  }
326
 
327
  /**
328
+ * Returns the link to an image attachment's Permalink page (NOT the link for the image itself!!)
329
  * @api
330
+ * @example
331
+ * ```twig
332
+ * <a href="{{ image.link }}"><img src="{{ image.src }} "/></a>
333
+ * ```
334
+ * ```html
335
+ * <a href="http://example.org/my-cool-picture"><img src="http://example.org/wp-content/uploads/2015/whatever.jpg"/></a>
336
+ * ```
337
+ */
338
+ public function link() {
339
+ if (strlen($this->abs_url)) {
340
+ return $this->abs_url;
341
+ }
342
+ return get_permalink($this->ID);
343
+ }
344
+
345
+ /**
346
+ * @api
347
+ * @return bool|TimberPost
348
+ */
349
+ public function parent() {
350
+ if (!$this->post_parent) {
351
+ return false;
352
+ }
353
+ return new $this->PostClass($this->post_parent);
354
+ }
355
+
356
+ /**
357
+ * @api
358
+ * @example
359
+ * ```twig
360
+ * <img src="{{ image.path }}" />
361
+ * ```
362
+ * ```html
363
+ * <img src="/wp-content/uploads/2015/08/pic.jpg" />
364
+ * ```
365
+ * @return string the /relative/path/to/the/file
366
+ */
367
+ public function path() {
368
+ return TimberURLHelper::get_rel_path($this->src());
369
+ }
370
+
371
+ /**
372
+ * @param string $size a size known to WordPress (like "medium")
373
+ * @api
374
+ * @example
375
+ * ```twig
376
+ * <h1>{{post.title}}</h1>
377
+ * <img src="{{post.thumbnail.src}}" />
378
+ * ```
379
+ * ```html
380
+ * <img src="http://example.org/wp-content/uploads/2015/08/pic.jpg" />
381
+ * ```
382
  * @return bool|string
383
  */
384
  public function src($size = '') {
385
+ if ( isset($this->abs_url) ) {
386
+ return $this->_maybe_secure_url($this->abs_url);
387
+ }
388
+
389
+ if ( $size && is_string($size) && isset($this->sizes[$size]) ) {
390
+ $image = image_downsize($this->ID, $size);
391
+ return $this->_maybe_secure_url(reset($image));
392
+ }
393
+
394
+ if ( !isset($this->file) && isset($this->_wp_attached_file) ) {
395
+ $this->file = $this->_wp_attached_file;
396
+ }
397
+
398
+ if ( !isset($this->file) ) {
399
+ return false;
400
+ }
401
+
402
+ $dir = self::wp_upload_dir();
403
+ $base = $dir['baseurl'];
404
+
405
+ $src = trailingslashit($this->_maybe_secure_url($base)) . $this->file;
406
+ $src = apply_filters('timber/image/src', $src, $this->ID);
407
+ return apply_filters('timber_image_src', $src, $this->ID);
408
+ }
409
+
410
+ /**
411
+ * @deprecated use src() instead
412
+ * @return string
413
+ */
414
+ function url() {
415
+ return $this->get_src();
416
  }
417
 
418
  /**
419
  * @api
420
+ * @example
421
+ * ```twig
422
+ * <img src="{{ image.src }}" width="{{ image.width }}" />
423
+ * ```
424
+ * ```html
425
+ * <img src="http://example.org/wp-content/uploads/2015/08/pic.jpg" width="1600" />
426
+ * ```
427
  * @return int
428
  */
429
  public function width() {
430
+ return $this->get_dimensions('width');
431
  }
432
 
433
+
434
  /**
435
+ * @deprecated 0.21.9 use TimberImage::width() instead
436
+ * @internal
437
+ * @return int
438
  */
439
+ function get_width() {
440
+ return $this->width();
441
+ }
442
+
443
+ /**
444
+ * @deprecated 0.21.9 use TimberImage::height() instead
445
+ * @internal
446
+ * @return int
447
+ */
448
+ function get_height() {
449
+ return $this->height();
450
+ }
451
+
452
+ /**
453
+ * @deprecated 0.21.9 use TimberImage::src
454
+ * @internal
455
+ * @param string $size
456
+ * @return bool|string
457
+ */
458
+ function get_src( $size = '' ) {
459
+ return $this->src( $size );
460
+ }
461
+
462
+ /**
463
+ * @deprecated 0.21.9 use TimberImage::path()
464
+ * @internal
465
+ * @return string
466
+ */
467
+ function get_path() {
468
+ return $this->link();
469
+ }
470
+
471
+ /**
472
+ * @deprecated use src() instead
473
+ * @return string
474
+ */
475
+ function get_url() {
476
+ return $this->get_src();
477
+ }
478
+
479
+ /**
480
+ * @internal
481
+ * @deprecated 0.21.8
482
+ * @return bool|TimberPost
483
+ */
484
+ function get_parent() {
485
+ return $this->parent();
486
+ }
487
+
488
+ /**
489
+ * @internal
490
+ * @deprecated 0.21.9
491
+ * @see TimberImage::alt
492
+ * @return string
493
+ */
494
+ function get_alt() {
495
+ return $this->alt();
496
  }
497
 
498
  }
lib/timber-page.php CHANGED
@@ -1,6 +1,9 @@
1
  <?php
2
 
3
- class TimberPage extends TimberPost
4
- {
 
 
 
5
 
6
  }
1
  <?php
2
 
3
+ /**
4
+ * @ignore
5
+ * @deprecated 0.21.9
6
+ */
7
+ class TimberPage extends TimberPost {
8
 
9
  }
lib/timber-post.php CHANGED
@@ -14,13 +14,22 @@
14
  * ```twig
15
  * {# single.twig #}
16
  * <article>
17
- * <h1 class="headline">{{post.post_title}}</h1>
18
  * <div class="body">
19
  * {{post.content}}
20
  * </div>
21
  * </article>
22
  * ```
23
  *
 
 
 
 
 
 
 
 
 
24
  * @package Timber
25
  */
26
  class TimberPost extends TimberCore implements TimberCoreInterface {
@@ -1290,7 +1299,7 @@ class TimberPost extends TimberCore implements TimberCoreInterface {
1290
  }
1291
 
1292
  /**
1293
- * @deprecated use link() instead
1294
  * @return string
1295
  */
1296
  public function permalink() {
14
  * ```twig
15
  * {# single.twig #}
16
  * <article>
17
+ * <h1 class="headline">{{post.title}}</h1>
18
  * <div class="body">
19
  * {{post.content}}
20
  * </div>
21
  * </article>
22
  * ```
23
  *
24
+ * ```html
25
+ * <article>
26
+ * <h1 class="headline">The Empire Strikes Back</h1>
27
+ * <div class="body">
28
+ * It is a dark time for the Rebellion. Although the Death Star has been destroyed, Imperial troops have driven the Rebel forces from their hidden base and pursued them across the galaxy.
29
+ * </div>
30
+ * </article>
31
+ * ```
32
+ *
33
  * @package Timber
34
  */
35
  class TimberPost extends TimberCore implements TimberCoreInterface {
1299
  }
1300
 
1301
  /**
1302
+ * @deprecated 0.20.0 use link() instead
1303
  * @return string
1304
  */
1305
  public function permalink() {
lib/timber-site.php CHANGED
@@ -1,7 +1,27 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  class TimberSite extends TimberCore implements TimberCoreInterface {
4
 
 
 
 
 
5
  public $admin_email;
6
  public $blogname;
7
  /**
@@ -11,18 +31,40 @@ class TimberSite extends TimberCore implements TimberCoreInterface {
11
  public $charset;
12
 
13
  /**
 
14
  * @var string
15
  */
16
  public $description;
 
 
 
 
17
  public $id;
 
 
 
 
18
  public $language;
 
 
 
 
19
  public $language_attributes;
20
  /**
21
  * @api
22
- * @var bool
23
  */
24
  public $multisite;
 
 
 
 
 
25
  public $name;
 
 
 
 
26
  public $pingback_url;
27
  public $siteurl;
28
  /**
@@ -38,8 +80,15 @@ class TimberSite extends TimberCore implements TimberCoreInterface {
38
  public $url;
39
 
40
  /**
41
- *
42
- *
 
 
 
 
 
 
 
43
  * @param string|int $site_name_or_id
44
  */
45
  function __construct( $site_name_or_id = null ) {
@@ -115,16 +164,16 @@ class TimberSite extends TimberCore implements TimberCoreInterface {
115
  }
116
 
117
  /**
118
- *
119
  * @internal
120
  * @return string
121
  */
122
  function get_link() {
123
- return $this->url;
124
  }
125
 
126
  /**
127
- *
128
  * @internal
129
  * @return string
130
  */
@@ -133,16 +182,27 @@ class TimberSite extends TimberCore implements TimberCoreInterface {
133
  }
134
 
135
  /**
136
- *
 
 
 
 
 
 
 
 
 
 
 
137
  * @api
138
  * @return string
139
  */
140
  public function link() {
141
- return $this->get_link();
142
  }
143
 
144
  /**
145
- *
146
  */
147
  public function meta( $field ) {
148
  return $this->__get( $field );
@@ -150,7 +210,7 @@ class TimberSite extends TimberCore implements TimberCoreInterface {
150
 
151
  /**
152
  *
153
- *
154
  * @param string $key
155
  * @param mixed $value
156
  */
1
  <?php
2
 
3
+ /**
4
+ * TimberSite gives you access to information you need about your site. In Multisite setups, you can get info on other sites in your network.
5
+ * @example
6
+ * ```php
7
+ * $context = Timber::get_context();
8
+ * $other_site_id = 2;
9
+ * $context['other_site'] = new TimberSite($other_site_id);
10
+ * Timber::render('index.twig', $context);
11
+ * ```
12
+ * ```twig
13
+ * My site is called {{site.name}}, another site on my network is {{other_site.name}}
14
+ * ```
15
+ * ```html
16
+ * My site is called Jared's blog, another site on my network is Upstatement.com
17
+ * ```
18
+ */
19
  class TimberSite extends TimberCore implements TimberCoreInterface {
20
 
21
+ /**
22
+ * @api
23
+ * @var string the admin email address set in the WP admin panel
24
+ */
25
  public $admin_email;
26
  public $blogname;
27
  /**
31
  public $charset;
32
 
33
  /**
34
+ * @api
35
  * @var string
36
  */
37
  public $description;
38
+ /**
39
+ * @api
40
+ * @var int the ID of a site in multisite
41
+ */
42
  public $id;
43
+ /**
44
+ * @api
45
+ * @var string the language setting ex: en-US
46
+ */
47
  public $language;
48
+ /**
49
+ * @api
50
+ * @var string of language attributes for usage in the <html> tag
51
+ */
52
  public $language_attributes;
53
  /**
54
  * @api
55
+ * @var bool true if multisite, false if plain ole' WordPress
56
  */
57
  public $multisite;
58
+
59
+ /**
60
+ * @api
61
+ * @var string
62
+ */
63
  public $name;
64
+
65
+ /** @api
66
+ * @var string for people who like trackback spam
67
+ */
68
  public $pingback_url;
69
  public $siteurl;
70
  /**
80
  public $url;
81
 
82
  /**
83
+ * Constructs a TimberSite object
84
+ * @example
85
+ * ```php
86
+ * //multisite setup
87
+ * $site = new TimberSite(1);
88
+ * $site_two = new TimberSite("My Cool Site");
89
+ * //non-multisite
90
+ * $site = new TimberSite();
91
+ * ```
92
  * @param string|int $site_name_or_id
93
  */
94
  function __construct( $site_name_or_id = null ) {
164
  }
165
 
166
  /**
167
+ * @deprecated 0.21.9
168
  * @internal
169
  * @return string
170
  */
171
  function get_link() {
172
+ return $this->link();
173
  }
174
 
175
  /**
176
+ * @deprecated 0.21.9
177
  * @internal
178
  * @return string
179
  */
182
  }
183
 
184
  /**
185
+ * Returns the link to the site's home.
186
+ * @example
187
+ * ```twig
188
+ * <a href="{{ site.link }}" title="Home">
189
+ * <img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
190
+ * </a>
191
+ * ```
192
+ * ```html
193
+ * <a href="http://example.org" title="Home">
194
+ * <img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
195
+ * </a>
196
+ * ```
197
  * @api
198
  * @return string
199
  */
200
  public function link() {
201
+ return $this->url;
202
  }
203
 
204
  /**
205
+ * @ignore
206
  */
207
  public function meta( $field ) {
208
  return $this->__get( $field );
210
 
211
  /**
212
  *
213
+ * @ignore
214
  * @param string $key
215
  * @param mixed $value
216
  */
lib/timber-term.php CHANGED
@@ -1,5 +1,35 @@
1
  <?php
2
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  class TimberTerm extends TimberCore implements TimberCoreInterface {
4
 
5
  public $PostClass = 'TimberPost';
@@ -54,7 +84,9 @@ class TimberTerm extends TimberCore implements TimberCoreInterface {
54
  global $wp_query;
55
  if ( isset($wp_query->queried_object) ) {
56
  $qo = $wp_query->queried_object;
57
- return $qo->term_id;
 
 
58
  }
59
  if ( isset($wp_query->tax_query->queries[0]['terms'][0]) ) {
60
  return $wp_query->tax_query->queries[0]['terms'][0];
@@ -114,6 +146,7 @@ class TimberTerm extends TimberCore implements TimberCoreInterface {
114
  $query = $wpdb->prepare("SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $tid);
115
  $tax = $wpdb->get_var($query);
116
  if (isset($tax) && strlen($tax)) {
 
117
  return get_term($tid, $tax);
118
  }
119
  }
@@ -195,6 +228,8 @@ class TimberTerm extends TimberCore implements TimberCoreInterface {
195
  }
196
 
197
  /**
 
 
198
  * @param int $numberposts
199
  * @param string $post_type
200
  * @param string $PostClass
@@ -280,6 +315,21 @@ class TimberTerm extends TimberCore implements TimberCoreInterface {
280
  return $this->get_children();
281
  }
282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  /**
284
  * @api
285
  * @return string
@@ -327,7 +377,7 @@ class TimberTerm extends TimberCore implements TimberCoreInterface {
327
  * @param int $numberposts_or_args
328
  * @param string $post_type_or_class
329
  * @param string $post_class
330
- * @example
331
  * ```twig
332
  * <h4>Recent posts in {{term.name}}</h4>
333
  * <ul>
@@ -351,7 +401,7 @@ class TimberTerm extends TimberCore implements TimberCoreInterface {
351
  }
352
 
353
  /**
354
- * @deprecated since 0.21.9
355
  * @return string
356
  */
357
  public function url() {
@@ -359,7 +409,7 @@ class TimberTerm extends TimberCore implements TimberCoreInterface {
359
  }
360
 
361
  /**
362
- * @deprecated
363
  * @param int $i
364
  * @return string
365
  */
1
  <?php
2
+ /**
3
+ * Terms: WordPress has got 'em, you want 'em. Categories. Tags. Custom Taxonomies. You don't care, you're a fiend. Well let's get this under control
4
+ * @example
5
+ * ```php
6
+ * //Get a term by its ID
7
+ * $context['term'] = new TimberTerm(6);
8
+ * //Get a term when on a term archive page
9
+ * $context['term_page'] = new TimberTerm();
10
+ * //Get a term with a slug
11
+ * $context['team'] = new TimberTerm('patriots');
12
+ * //Get a team with a slug from a specific taxonomy
13
+ * $context['st_louis'] = new TimberTerm('cardinals', 'baseball');
14
+ * Timber::render('index.twig', $context);
15
+ * ```
16
+ * ```twig
17
+ * <h2>{{term_page.name}} Archives</h2>
18
+ * <h3>Teams</h3>
19
+ * <ul>
20
+ * <li>{{st_louis.name}} - {{st_louis.description}}</li>
21
+ * <li>{{team.name}} - {{team.description}}</li>
22
+ * </ul>
23
+ * ```
24
+ * ```html
25
+ * <h2>Team Archives</h2>
26
+ * <h3>Teams</h3>
27
+ * <ul>
28
+ * <li>St. Louis Cardinals - Winner of 11 World Series</li>
29
+ * <li>New England Patriots - Winner of 4 Super Bowls</li>
30
+ * </ul>
31
+ * ```
32
+ */
33
  class TimberTerm extends TimberCore implements TimberCoreInterface {
34
 
35
  public $PostClass = 'TimberPost';
84
  global $wp_query;
85
  if ( isset($wp_query->queried_object) ) {
86
  $qo = $wp_query->queried_object;
87
+ if (isset($qo->term_id)) {
88
+ return $qo->term_id;
89
+ }
90
  }
91
  if ( isset($wp_query->tax_query->queries[0]['terms'][0]) ) {
92
  return $wp_query->tax_query->queries[0]['terms'][0];
146
  $query = $wpdb->prepare("SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $tid);
147
  $tax = $wpdb->get_var($query);
148
  if (isset($tax) && strlen($tax)) {
149
+ $this->taxonomy = $tax;
150
  return get_term($tid, $tax);
151
  }
152
  }
228
  }
229
 
230
  /**
231
+ * Get Posts that have been "tagged" with the particular term
232
+ * @internal
233
  * @param int $numberposts
234
  * @param string $post_type
235
  * @param string $PostClass
315
  return $this->get_children();
316
  }
317
 
318
+ /**
319
+ * @api
320
+ * @return string
321
+ */
322
+ public function description() {
323
+ $prefix = '<p>';
324
+ $suffix = '</p>';
325
+ $desc = term_description( $this->ID, $this->taxonomy );
326
+ if (substr($desc, 0, strlen($prefix)) == $prefix) {
327
+ $desc = substr($desc, strlen($prefix));
328
+ }
329
+ $desc = preg_replace('/'. preg_quote('</p>', '/') . '$/', '', $desc);
330
+ return trim($desc);
331
+ }
332
+
333
  /**
334
  * @api
335
  * @return string
377
  * @param int $numberposts_or_args
378
  * @param string $post_type_or_class
379
  * @param string $post_class
380
+ * @example
381
  * ```twig
382
  * <h4>Recent posts in {{term.name}}</h4>
383
  * <ul>
401
  }
402
 
403
  /**
404
+ * @deprecated 0.21.9 use TimberTerm::link() instead
405
  * @return string
406
  */
407
  public function url() {
409
  }
410
 
411
  /**
412
+ * @deprecated 0.20.0 this was a dumb idea
413
  * @param int $i
414
  * @return string
415
  */
lib/timber-theme.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  /**
4
  * Need to display info about your theme? Well you've come to the right place. By default info on the current theme comes for free with what's fetched by `Timber::get_context()` in which case you can access it your theme like so:
5
- * @example
6
  * ```php
7
  * <?php
8
  * $context = Timber::get_context();
@@ -19,24 +19,12 @@
19
  */
20
  class TimberTheme extends TimberCore {
21
 
22
- /**
23
- * @api
24
- * @var string the absolute path to the theme (ex: `http://example.org/wp-content/themes/my-timber-theme`)
25
- */
26
- public $link;
27
-
28
  /**
29
  * @api
30
  * @var string the human-friendly name of the theme (ex: `My Timber Starter Theme`)
31
  */
32
  public $name;
33
 
34
- /**
35
- * @api
36
- * @var string the relative path to the theme (ex: `/wp-content/themes/my-timber-theme`)
37
- */
38
- public $path;
39
-
40
  /**
41
  * @api
42
  * @var TimberTheme|bool the TimberTheme object for the parent theme (if it exists), false otherwise
@@ -87,19 +75,37 @@ class TimberTheme extends TimberCore {
87
  $this->name = $data->get('Name');
88
  $ss = $data->get_stylesheet();
89
  $this->slug = $ss;
90
- $this->path = WP_CONTENT_SUBDIR . str_replace(WP_CONTENT_DIR, '', get_stylesheet_directory());
 
 
 
 
91
  $this->uri = get_stylesheet_directory_uri();
92
- $this->link = $this->uri;
93
  $this->parent_slug = $data->get('Template');
94
- if (!$this->parent_slug) {
95
- $this->path = WP_CONTENT_SUBDIR . str_replace(WP_CONTENT_DIR, '', get_template_directory());
96
  $this->uri = get_template_directory_uri();
97
  }
98
- if ($this->parent_slug && $this->parent_slug != $this->slug) {
99
  $this->parent = new TimberTheme($this->parent_slug);
100
  }
101
  }
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  /**
104
  * @param string $name
105
  * @param bool $default
2
 
3
  /**
4
  * Need to display info about your theme? Well you've come to the right place. By default info on the current theme comes for free with what's fetched by `Timber::get_context()` in which case you can access it your theme like so:
5
+ * @example
6
  * ```php
7
  * <?php
8
  * $context = Timber::get_context();
19
  */
20
  class TimberTheme extends TimberCore {
21
 
 
 
 
 
 
 
22
  /**
23
  * @api
24
  * @var string the human-friendly name of the theme (ex: `My Timber Starter Theme`)
25
  */
26
  public $name;
27
 
 
 
 
 
 
 
28
  /**
29
  * @api
30
  * @var TimberTheme|bool the TimberTheme object for the parent theme (if it exists), false otherwise
75
  $this->name = $data->get('Name');
76
  $ss = $data->get_stylesheet();
77
  $this->slug = $ss;
78
+
79
+ if ( ! function_exists( 'get_home_path' ) ) {
80
+ require_once(ABSPATH . 'wp-admin/includes/file.php');
81
+ }
82
+
83
  $this->uri = get_stylesheet_directory_uri();
 
84
  $this->parent_slug = $data->get('Template');
85
+ if ( !$this->parent_slug ) {
 
86
  $this->uri = get_template_directory_uri();
87
  }
88
+ if ( $this->parent_slug && $this->parent_slug != $this->slug ) {
89
  $this->parent = new TimberTheme($this->parent_slug);
90
  }
91
  }
92
 
93
+ /**
94
+ * @api
95
+ * @return string the absolute path to the theme (ex: `http://example.org/wp-content/themes/my-timber-theme`)
96
+ */
97
+ public function link() {
98
+ return $this->uri;
99
+ }
100
+
101
+ /**
102
+ * @api
103
+ * @return string the relative path to the theme (ex: `/wp-content/themes/my-timber-theme`)
104
+ */
105
+ public function path() {
106
+ return TimberURLHelper::get_rel_url( $this->link() );
107
+ }
108
+
109
  /**
110
  * @param string $name
111
  * @param bool $default
lib/timber-url-helper.php CHANGED
@@ -12,7 +12,7 @@ class TimberURLHelper {
12
  if ( isset( $_SERVER['HTTPS'] ) && $_SERVER["HTTPS"] == "on" ) {
13
  $pageURL = "https://";;
14
  }
15
- if ( $_SERVER["SERVER_PORT"] != "80" ) {
16
  $pageURL .= self::get_host() . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
17
  } else {
18
  $pageURL .= self::get_host() . $_SERVER["REQUEST_URI"];
@@ -88,7 +88,7 @@ class TimberURLHelper {
88
  public static function get_host() {
89
  if (isset($_SERVER['HTTP_HOST'])) {
90
  return $_SERVER['HTTP_HOST'];
91
- }
92
  if (isset($_SERVER['SERVER_NAME'])) {
93
  return $_SERVER['SERVER_NAME'];
94
  }
@@ -225,14 +225,25 @@ class TimberURLHelper {
225
  * @return boolean if $url points to an external location returns true
226
  */
227
  public static function is_external_content( $url ) {
 
 
 
 
 
 
228
  // using content_url() instead of site_url or home_url is IMPORTANT
229
  // otherwise you run into errors with sites that:
230
  // 1. use WPML plugin
231
- // 2. or redefine upload directory
232
- $is_external = TimberURLHelper::is_absolute( $url ) && !strstr( $url, content_url() );
233
- return $is_external;
234
- }
235
 
 
 
 
 
 
 
 
236
  /**
237
  *
238
  *
12
  if ( isset( $_SERVER['HTTPS'] ) && $_SERVER["HTTPS"] == "on" ) {
13
  $pageURL = "https://";;
14
  }
15
+ if ( isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"] && $_SERVER["SERVER_PORT"] != "80" ) {
16
  $pageURL .= self::get_host() . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
17
  } else {
18
  $pageURL .= self::get_host() . $_SERVER["REQUEST_URI"];
88
  public static function get_host() {
89
  if (isset($_SERVER['HTTP_HOST'])) {
90
  return $_SERVER['HTTP_HOST'];
91
+ }
92
  if (isset($_SERVER['SERVER_NAME'])) {
93
  return $_SERVER['SERVER_NAME'];
94
  }
225
  * @return boolean if $url points to an external location returns true
226
  */
227
  public static function is_external_content( $url ) {
228
+ $is_external = TimberURLHelper::is_absolute( $url ) && ! TimberURLHelper::is_internal_content( $url );
229
+
230
+ return $is_external;
231
+ }
232
+
233
+ private static function is_internal_content($url) {
234
  // using content_url() instead of site_url or home_url is IMPORTANT
235
  // otherwise you run into errors with sites that:
236
  // 1. use WPML plugin
237
+ // 2. or redefine content directory
238
+ $is_content_url = strstr( $url, content_url() );
 
 
239
 
240
+ // this case covers when the upload directory has been redefined
241
+ $upload_dir = wp_upload_dir();
242
+ $is_upload_url = strstr( $url, $upload_dir['baseurl'] );
243
+
244
+ return $is_content_url || $is_upload_url;
245
+ }
246
+
247
  /**
248
  *
249
  *
lib/timber-user.php CHANGED
@@ -1,5 +1,22 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  class TimberUser extends TimberCore implements TimberCoreInterface {
4
 
5
  public $object_type = 'user';
@@ -7,10 +24,30 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
7
 
8
  public $_link;
9
 
 
 
 
 
10
  public $description;
11
  public $display_name;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  public $id;
13
- public $name;
14
  public $user_nicename;
15
 
16
  /**
@@ -21,7 +58,15 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
21
  }
22
 
23
  /**
24
- * @return string
 
 
 
 
 
 
 
 
25
  */
26
  function __toString() {
27
  $name = $this->name();
@@ -45,8 +90,8 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
45
 
46
  /**
47
  * @internal
48
- * @param string $field
49
- * @param mixed $value
50
  */
51
  function __set($field, $value) {
52
  if ( $field == 'name' ) {
@@ -57,18 +102,7 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
57
 
58
  /**
59
  * @internal
60
- * @return string
61
- */
62
- public function get_link() {
63
- if ( !$this->_link ) {
64
- $this->_link = untrailingslashit(get_author_posts_url($this->ID));
65
- }
66
- return $this->_link;
67
- }
68
-
69
- /**
70
- * @internal
71
- * @param int|bool $uid
72
  */
73
  protected function init($uid = false) {
74
  if ( $uid === false ) {
@@ -83,7 +117,7 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
83
  }
84
  if ( is_numeric($uid) ) {
85
  $data = get_userdata($uid);
86
- } else if ( is_string($uid) ) {
87
  $data = get_user_by('login', $uid);
88
  }
89
  if ( isset($data) && is_object($data) ) {
@@ -95,7 +129,8 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
95
  }
96
  $this->id = $this->ID;
97
  $this->name = $this->name();
98
- $this->import_custom();
 
99
  }
100
 
101
  /**
@@ -135,9 +170,15 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
135
  return null;
136
  }
137
 
138
- function import_custom() {
139
- $custom = $this->get_custom();
140
- $this->import($custom);
 
 
 
 
 
 
141
  }
142
 
143
  /**
@@ -149,59 +190,59 @@ class TimberUser extends TimberCore implements TimberCoreInterface {
149
  }
150
 
151
  /**
152
- * @deprecated 0.21.8
153
- * @return string
154
  */
155
- function get_permalink() {
156
- return $this->get_link();
157
  }
158
 
159
  /**
160
- * @deprecated 0.21.8
161
- * @return string
162
  */
163
- function permalink() {
164
- return $this->get_permalink();
165
  }
166
 
167
  /**
168
- * @internal
169
- * @return string ex: /author/lincoln
170
  */
171
- function get_path() {
172
- return TimberURLHelper::get_rel_url($this->get_link());
173
  }
174
 
175
  /**
176
- * @param string $field_name
177
- * @return mixed
178
  */
179
- function meta($field_name) {
180
- return $this->get_meta_field($field_name);
181
  }
182
 
183
  /**
184
- * @api
185
- * @return string
186
  */
187
- function path() {
188
- return $this->get_path();
189
  }
190
 
191
  /**
192
- * @api
193
  * @return string
194
  */
195
- function slug() {
196
- return $this->user_nicename;
197
  }
198
 
199
  /**
200
- * @api
201
  * @return string
202
  */
203
- function link() {
204
- return $this->get_link();
205
  }
206
 
207
  }
1
  <?php
2
 
3
+ /**
4
+ * 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.
5
+ * @example
6
+ * ```php
7
+ * $context['current_user'] = new TimberUser();
8
+ * $context['post'] = new TimberPost();
9
+ * Timber::render('single.twig', $context);
10
+ * ```
11
+ * ```twig
12
+ * <p class="current-user-info">Your name is {{ current_user.name }}</p>
13
+ * <p class="article-info">This article is called "{{ post.title }}" and it's by {{ post.author.name }}
14
+ * ```
15
+ * ```html
16
+ * <p class="current-user-info">Your name is Jesse Eisenberg</p>
17
+ * <p class="article-info">This article is called "Consider the Lobster" and it's by David Foster Wallace
18
+ * ```
19
+ */
20
  class TimberUser extends TimberCore implements TimberCoreInterface {
21
 
22
  public $object_type = 'user';
24
 
25
  public $_link;
26
 
27
+ /**
28
+ * @api
29
+ * @var string The description from WordPress
30
+ */
31
  public $description;
32
  public $display_name;
33
+
34
+ /**
35
+ * @api
36
+ * @var string The first name of the user
37
+ */
38
+ public $first_name;
39
+
40
+ /**
41
+ * @api
42
+ * @var string The last name of the user
43
+ */
44
+ public $last_name;
45
+
46
+ /**
47
+ * @api
48
+ * @var int The ID from WordPress
49
+ */
50
  public $id;
 
51
  public $user_nicename;
52
 
53
  /**
58
  }
59
 
60
  /**
61
+ * @example
62
+ * ```twig
63
+ * This post is by {{ post.author }}
64
+ * ```
65
+ * ```html
66
+ * This post is by Jared Novack
67
+ * ```
68
+ *
69
+ * @return string a fallback for TimberUser::name()
70
  */
71
  function __toString() {
72
  $name = $this->name();
90
 
91
  /**
92
  * @internal
93
+ * @param string $field
94
+ * @param mixed $value
95
  */
96
  function __set($field, $value) {
97
  if ( $field == 'name' ) {
102
 
103
  /**
104
  * @internal
105
+ * @param int|bool $uid The user ID to use
 
 
 
 
 
 
 
 
 
 
 
106
  */
107
  protected function init($uid = false) {
108
  if ( $uid === false ) {
117
  }
118
  if ( is_numeric($uid) ) {
119
  $data = get_userdata($uid);
120
+ } else if ( is_string($uid) ) {
121
  $data = get_user_by('login', $uid);
122
  }
123
  if ( isset($data) && is_object($data) ) {
129
  }
130
  $this->id = $this->ID;
131
  $this->name = $this->name();
132
+ $custom = $this->get_custom();
133
+ $this->import($custom);
134
  }
135
 
136
  /**
170
  return null;
171
  }
172
 
173
+ /**
174
+ * @api
175
+ * @return string http://example.org/author/lincoln
176
+ */
177
+ public function link() {
178
+ if ( !$this->_link ) {
179
+ $this->_link = untrailingslashit(get_author_posts_url($this->ID));
180
+ }
181
+ return $this->_link;
182
  }
183
 
184
  /**
190
  }
191
 
192
  /**
193
+ * @param string $field_name
194
+ * @return mixed
195
  */
196
+ function meta($field_name) {
197
+ return $this->get_meta_field($field_name);
198
  }
199
 
200
  /**
201
+ * @api
202
+ * @return string ex: /author/lincoln
203
  */
204
+ public function path() {
205
+ return TimberURLHelper::get_rel_url($this->get_link());
206
  }
207
 
208
  /**
209
+ * @api
210
+ * @return string ex baberaham-lincoln
211
  */
212
+ public function slug() {
213
+ return $this->user_nicename;
214
  }
215
 
216
  /**
217
+ * @deprecated 0.21.9
218
+ * @return string The link to a user's profile page
219
  */
220
+ function get_link() {
221
+ return $this->link();
222
  }
223
 
224
  /**
225
+ * @deprecated 0.21.8
226
+ * @return string ex: /author/lincoln
227
  */
228
+ function get_path() {
229
+ return $this->path();
230
  }
231
 
232
  /**
233
+ * @deprecated 0.21.8
234
  * @return string
235
  */
236
+ function get_permalink() {
237
+ return $this->get_link();
238
  }
239
 
240
  /**
241
+ * @deprecated 0.21.8
242
  * @return string
243
  */
244
+ function permalink() {
245
+ return $this->get_permalink();
246
  }
247
 
248
  }
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.9
6
  Tested up to: 4.2.3
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
@@ -41,6 +41,11 @@ Timber is great for any WordPress developer who cares about writing good, mainta
41
 
42
  == Changelog ==
43
 
 
 
 
 
 
44
  = 0.21.9 =
45
  * Much much much more inline docs
46
  * Fix to TimberComment::approved()
2
  Contributors: jarednova
3
  Tags: template engine, templates, twig
4
  Requires at least: 3.7
5
+ Stable tag: 0.21.10
6
  Tested up to: 4.2.3
7
  PHP version: 5.3.0 or greater
8
  License: GPLv2 or later
41
 
42
  == Changelog ==
43
 
44
+ = 0.21.10 =
45
+ * Removed deprecated twitterify function
46
+ * Much more docs (and deprecation docs)
47
+ * Fixed issues with using constants (thanks @xavivars)
48
+
49
  = 0.21.9 =
50
  * Much much much more inline docs
51
  * Fix to TimberComment::approved()
timber-starter-theme/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- vendor
2
- wp-content
 
 
timber-starter-theme/README.md CHANGED
@@ -1,2 +1,5 @@
1
  # timber-starter-theme
 
 
 
2
  The "_s" for Timber: a dead-simple theme that you can build from
1
  # timber-starter-theme
2
+
3
+ [![Build Status](https://travis-ci.org/Upstatement/timber-starter-theme.svg)](https://travis-ci.org/Upstatement/timber-starter-theme)
4
+
5
  The "_s" for Timber: a dead-simple theme that you can build from
timber-starter-theme/composer.json DELETED
@@ -1,33 +0,0 @@
1
- {
2
- "name": "upstatement/timber-starter-theme",
3
- "description": "Starter theme to build a Timber theme",
4
- "type":"wordpress-theme",
5
- "minimum-stability" : "dev",
6
- "authors": [
7
- {
8
- "name": "jarednova",
9
- "email": "jared@upstatement.com"
10
- }
11
- ],
12
- "require-dev": {
13
- "jarednova/timber": "dev-master"
14
- },
15
- "repositories": [
16
- {
17
- "type" : "package",
18
- "package" : {
19
- "name" : "jarednova/php-router",
20
- "version" : "1.0.1",
21
- "dist" : {
22
- "url" : "https://github.com/jarednova/PHP-Router/archive/fix_psr_0.zip",
23
- "type" : "zip"
24
- },
25
- "autoload": {
26
- "psr-0": {
27
- "PHPRouter": "src/"
28
- }
29
- }
30
- }
31
- }
32
- ]
33
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
timber-starter-theme/composer.lock DELETED
@@ -1,288 +0,0 @@
1
- {
2
- "_readme": [
3
- "This file locks the dependencies of your project to a known state",
4
- "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5
- "This file is @generated automatically"
6
- ],
7
- "hash": "1af701633a1ce830ac7dcdad25ae49d6",
8
- "packages": [],
9
- "packages-dev": [
10
- {
11
- "name": "asm89/twig-cache-extension",
12
- "version": "dev-master",
13
- "source": {
14
- "type": "git",
15
- "url": "https://github.com/asm89/twig-cache-extension.git",
16
- "reference": "1a13fe102241a1b22d2e72a19f31212f328b57a7"
17
- },
18
- "dist": {
19
- "type": "zip",
20
- "url": "https://api.github.com/repos/asm89/twig-cache-extension/zipball/1a13fe102241a1b22d2e72a19f31212f328b57a7",
21
- "reference": "1a13fe102241a1b22d2e72a19f31212f328b57a7",
22
- "shasum": ""
23
- },
24
- "require": {
25
- "php": ">=5.3.2",
26
- "twig/twig": "~1.0"
27
- },
28
- "require-dev": {
29
- "doctrine/cache": "~1.0"
30
- },
31
- "type": "library",
32
- "extra": {
33
- "branch-alias": {
34
- "dev-master": "1.0-dev"
35
- }
36
- },
37
- "autoload": {
38
- "psr-4": {
39
- "": "lib/"
40
- }
41
- },
42
- "notification-url": "https://packagist.org/downloads/",
43
- "license": [
44
- "MIT"
45
- ],
46
- "authors": [
47
- {
48
- "name": "Alexander",
49
- "email": "iam.asm89@gmail.com"
50
- }
51
- ],
52
- "description": "Cache fragments of templates directly within Twig.",
53
- "homepage": "https://github.com/asm89/twig-cache-extension",
54
- "keywords": [
55
- "cache",
56
- "extension",
57
- "twig"
58
- ],
59
- "time": "2014-07-28 07:30:56"
60
- },
61
- {
62
- "name": "composer/installers",
63
- "version": "dev-master",
64
- "source": {
65
- "type": "git",
66
- "url": "https://github.com/composer/installers.git",
67
- "reference": "d64e23fce42a4063d63262b19b8e7c0f3b5e4c45"
68
- },
69
- "dist": {
70
- "type": "zip",
71
- "url": "https://api.github.com/repos/composer/installers/zipball/d64e23fce42a4063d63262b19b8e7c0f3b5e4c45",
72
- "reference": "d64e23fce42a4063d63262b19b8e7c0f3b5e4c45",
73
- "shasum": ""
74
- },
75
- "replace": {
76
- "roundcube/plugin-installer": "*",
77
- "shama/baton": "*"
78
- },
79
- "require-dev": {
80
- "composer/composer": "1.0.*@dev",
81
- "phpunit/phpunit": "4.1.*"
82
- },
83
- "type": "composer-installer",
84
- "extra": {
85
- "class": "Composer\\Installers\\Installer",
86
- "branch-alias": {
87
- "dev-master": "1.0-dev"
88
- }
89
- },
90
- "autoload": {
91
- "psr-0": {
92
- "Composer\\Installers\\": "src/"
93
- }
94
- },
95
- "notification-url": "https://packagist.org/downloads/",
96
- "license": [
97
- "MIT"
98
- ],
99
- "authors": [
100
- {
101
- "name": "Kyle Robinson Young",
102
- "email": "kyle@dontkry.com",
103
- "homepage": "https://github.com/shama"
104
- }
105
- ],
106
- "description": "A multi-framework Composer library installer",
107
- "homepage": "http://composer.github.com/installers/",
108
- "keywords": [
109
- "Craft",
110
- "Dolibarr",
111
- "Hurad",
112
- "MODX Evo",
113
- "OXID",
114
- "SMF",
115
- "Thelia",
116
- "WolfCMS",
117
- "agl",
118
- "aimeos",
119
- "annotatecms",
120
- "bitrix",
121
- "cakephp",
122
- "chef",
123
- "codeigniter",
124
- "concrete5",
125
- "croogo",
126
- "dokuwiki",
127
- "drupal",
128
- "elgg",
129
- "fuelphp",
130
- "grav",
131
- "installer",
132
- "joomla",
133
- "kohana",
134
- "laravel",
135
- "lithium",
136
- "magento",
137
- "mako",
138
- "mediawiki",
139
- "modulework",
140
- "moodle",
141
- "phpbb",
142
- "piwik",
143
- "ppi",
144
- "puppet",
145
- "roundcube",
146
- "shopware",
147
- "silverstripe",
148
- "symfony",
149
- "typo3",
150
- "wordpress",
151
- "zend",
152
- "zikula"
153
- ],
154
- "time": "2015-02-18 17:17:01"
155
- },
156
- {
157
- "name": "jarednova/php-router",
158
- "version": "1.0.1",
159
- "dist": {
160
- "type": "zip",
161
- "url": "https://github.com/jarednova/PHP-Router/archive/fix_psr_0.zip",
162
- "reference": null,
163
- "shasum": null
164
- },
165
- "type": "library",
166
- "autoload": {
167
- "psr-0": {
168
- "PHPRouter": "src/"
169
- }
170
- }
171
- },
172
- {
173
- "name": "jarednova/timber",
174
- "version": "dev-master",
175
- "source": {
176
- "type": "git",
177
- "url": "https://github.com/jarednova/timber.git",
178
- "reference": "c34e79f073b6b905f6fcaa9479977fc60ba5f17c"
179
- },
180
- "dist": {
181
- "type": "zip",
182
- "url": "https://api.github.com/repos/jarednova/timber/zipball/c34e79f073b6b905f6fcaa9479977fc60ba5f17c",
183
- "reference": "c34e79f073b6b905f6fcaa9479977fc60ba5f17c",
184
- "shasum": ""
185
- },
186
- "require": {
187
- "asm89/twig-cache-extension": "~1.0",
188
- "composer/installers": "~1.0",
189
- "jarednova/php-router": "1.0.1",
190
- "php": ">=5.3.0",
191
- "twig/twig": "~1.15"
192
- },
193
- "require-dev": {
194
- "advancedcustomfields/acf5-beta": "5.0",
195
- "phpunit/phpunit": "~4.0",
196
- "satooshi/php-coveralls": "dev-master",
197
- "wp-cli/wp-cli": "*"
198
- },
199
- "type": "wordpress-plugin",
200
- "notification-url": "https://packagist.org/downloads/",
201
- "license": [
202
- "MIT"
203
- ],
204
- "authors": [
205
- {
206
- "name": "Jared Novack",
207
- "email": "jared@upstatement.com",
208
- "homepage": "http://upstatement.com"
209
- }
210
- ],
211
- "description": "Plugin to write WordPress themes w Object-Oriented Code and the Twig Template Engine",
212
- "homepage": "http://timber.upstatement.com",
213
- "keywords": [
214
- "templating",
215
- "themes",
216
- "timber",
217
- "twig"
218
- ],
219
- "time": "2015-02-21 21:36:29"
220
- },
221
- {
222
- "name": "twig/twig",
223
- "version": "dev-master",
224
- "source": {
225
- "type": "git",
226
- "url": "https://github.com/twigphp/Twig.git",
227
- "reference": "19f8d073aaf7cadf6218d88c9f651657cfda9211"
228
- },
229
- "dist": {
230
- "type": "zip",
231
- "url": "https://api.github.com/repos/twigphp/Twig/zipball/19f8d073aaf7cadf6218d88c9f651657cfda9211",
232
- "reference": "19f8d073aaf7cadf6218d88c9f651657cfda9211",
233
- "shasum": ""
234
- },
235
- "require": {
236
- "php": ">=5.2.7"
237
- },
238
- "type": "library",
239
- "extra": {
240
- "branch-alias": {
241
- "dev-master": "1.18-dev"
242
- }
243
- },
244
- "autoload": {
245
- "psr-0": {
246
- "Twig_": "lib/"
247
- }
248
- },
249
- "notification-url": "https://packagist.org/downloads/",
250
- "license": [
251
- "BSD-3-Clause"
252
- ],
253
- "authors": [
254
- {
255
- "name": "Fabien Potencier",
256
- "email": "fabien@symfony.com",
257
- "homepage": "http://fabien.potencier.org",
258
- "role": "Lead Developer"
259
- },
260
- {
261
- "name": "Armin Ronacher",
262
- "email": "armin.ronacher@active-4.com",
263
- "role": "Project Founder"
264
- },
265
- {
266
- "name": "Twig Team",
267
- "homepage": "http://twig.sensiolabs.org/contributors",
268
- "role": "Contributors"
269
- }
270
- ],
271
- "description": "Twig, the flexible, fast, and secure template language for PHP",
272
- "homepage": "http://twig.sensiolabs.org",
273
- "keywords": [
274
- "templating"
275
- ],
276
- "time": "2015-02-27 16:10:10"
277
- }
278
- ],
279
- "aliases": [],
280
- "minimum-stability": "dev",
281
- "stability-flags": {
282
- "jarednova/timber": 20
283
- },
284
- "prefer-stable": false,
285
- "prefer-lowest": false,
286
- "platform": [],
287
- "platform-dev": []
288
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
timber-starter-theme/functions.php CHANGED
@@ -7,6 +7,8 @@ if ( ! class_exists( 'Timber' ) ) {
7
  return;
8
  }
9
 
 
 
10
  class StarterSite extends TimberSite {
11
 
12
  function __construct() {
7
  return;
8
  }
9
 
10
+ Timber::$dirname = array('templates', 'views');
11
+
12
  class StarterSite extends TimberSite {
13
 
14
  function __construct() {
timber-starter-theme/phpunit.xml DELETED
@@ -1,20 +0,0 @@
1
- <phpunit
2
- bootstrap="tests/bootstrap.php"
3
- backupGlobals="false"
4
- colors="true"
5
- convertErrorsToExceptions="true"
6
- convertNoticesToExceptions="true"
7
- convertWarningsToExceptions="true"
8
- >
9
- <testsuites>
10
- <testsuite>
11
- <directory prefix="test-" suffix=".php">./tests/</directory>
12
- </testsuite>
13
- <!-- The suite below HAS to be last to run,
14
- as it includes a test that sets some const and would contaminate
15
- the other tests as well. -->
16
- <testsuite>
17
- <directory prefix="testX-" suffix=".php">./tests/</directory>
18
- </testsuite>
19
- </testsuites>
20
- </phpunit>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
timber-starter-theme/search.php CHANGED
@@ -15,5 +15,4 @@ $context = Timber::get_context();
15
  $context['title'] = 'Search results for '. get_search_query();
16
  $context['posts'] = Timber::get_posts();
17
 
18
-
19
  Timber::render( $templates, $context );
15
  $context['title'] = 'Search results for '. get_search_query();
16
  $context['posts'] = Timber::get_posts();
17
 
 
18
  Timber::render( $templates, $context );
timber-starter-theme/{views → templates}/404.twig RENAMED
File without changes
timber-starter-theme/{views → templates}/author.twig RENAMED
File without changes
timber-starter-theme/{views → templates}/base.twig RENAMED
File without changes
timber-starter-theme/{views → templates}/comment.twig RENAMED
File without changes
timber-starter-theme/{views → templates}/footer.twig RENAMED
File without changes
timber-starter-theme/{views → templates}/html-header.twig RENAMED
File without changes
timber-starter-theme/{views → templates}/index.twig RENAMED
File without changes
timber-starter-theme/{views → templates}/page-plugin.twig RENAMED
File without changes
timber-starter-theme/{views → templates}/page.twig RENAMED
File without changes
timber-starter-theme/{views → templates}/sidebar.twig RENAMED
File without changes
timber-starter-theme/{views → templates}/single-password.twig RENAMED
File without changes
timber-starter-theme/{views → templates}/single.twig RENAMED
File without changes
timber-starter-theme/{views → templates}/tease-post.twig RENAMED
File without changes
timber-starter-theme/{views → templates}/tease.twig RENAMED
File without changes
timber-starter-theme/tests/bootstrap.php DELETED
@@ -1,18 +0,0 @@
1
- <?php
2
-
3
- if ( file_exists($composer_autoload = __DIR__ . '/../vendor/autoload.php') ) {
4
- require_once($composer_autoload);
5
- }
6
-
7
-
8
- $_tests_dir = getenv('WP_TESTS_DIR');
9
- if ( !$_tests_dir ) $_tests_dir = '/tmp/wordpress-tests-lib';
10
-
11
- require_once $_tests_dir . '/includes/functions.php';
12
-
13
- function _manually_load_plugin() {
14
- require dirname( __FILE__ ) . '/../wp-content/plugins/timber/timber.php';
15
- }
16
-
17
- tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
18
- require $_tests_dir . '/includes/bootstrap.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
timber-starter-theme/tests/test-timber-starter-theme.php DELETED
@@ -1,42 +0,0 @@
1
- <?php
2
-
3
- class TestTimberStarterTheme extends WP_UnitTestCase {
4
-
5
- function testFunctionsPHP() {
6
- self::_setupStarterTheme();
7
- require_once(get_template_directory().'/functions.php');
8
- $context = Timber::get_context();
9
- $this->assertEquals('StarterSite', get_class($context['site']));
10
- $this->assertTrue(current_theme_supports('post-thumbnails'));
11
- $this->assertEquals('bar', $context['foo']);
12
- switch_theme('twentythirteen');
13
- }
14
-
15
- static function _setupStarterTheme(){
16
- $dest = WP_CONTENT_DIR.'/themes/timber-starter-theme/';
17
- $src = __DIR__.'/../../timber-starter-theme/';
18
- if (is_dir($src)) {
19
- self::_copyDirectory($src, $dest);
20
- switch_theme('timber-starter-theme');
21
- } else {
22
- echo 'no its not';
23
- }
24
- }
25
-
26
- static function _copyDirectory($src, $dst){
27
- $dir = opendir($src);
28
- @mkdir($dst);
29
- while(false !== ( $file = readdir($dir)) ) {
30
- if (( $file != '.' ) && ( $file != '..' )) {
31
- if ( is_dir($src . '/' . $file) ) {
32
- self::_copyDirectory($src . '/' . $file,$dst . '/' . $file);
33
- }
34
- else {
35
- copy($src . '/' . $file,$dst . '/' . $file);
36
- }
37
- }
38
- }
39
- closedir($dir);
40
- }
41
-
42
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.9
8
  Author URI: http://upstatement.com/
9
  */
10
 
@@ -48,6 +48,9 @@ class Timber {
48
  public static $autoescape = false;
49
 
50
  public function __construct() {
 
 
 
51
  $this->test_compatibility();
52
  $this->init_constants();
53
  $this->init();
@@ -72,7 +75,6 @@ class Timber {
72
  protected function init() {
73
  TimberTwig::init();
74
  TimberRoutes::init( $this );
75
-
76
  TimberImageHelper::init();
77
  TimberAdmin::init();
78
  TimberIntegrations::init();
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.10
8
  Author URI: http://upstatement.com/
9
  */
10
 
48
  public static $autoescape = false;
49
 
50
  public function __construct() {
51
+ if ( !defined('ABSPATH') ) {
52
+ return;
53
+ }
54
  $this->test_compatibility();
55
  $this->init_constants();
56
  $this->init();
75
  protected function init() {
76
  TimberTwig::init();
77
  TimberRoutes::init( $this );
 
78
  TimberImageHelper::init();
79
  TimberAdmin::init();
80
  TimberIntegrations::init();