|
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; |
|
43
|
|
|
protected $_dimensions; |
|
44
|
|
|
public $abs_url; |
|
45
|
|
|
/** |
|
46
|
|
|
* @var string $object_type what does this class represent in WordPress terms? |
|
47
|
|
|
*/ |
|
48
|
|
|
public $object_type = 'image'; |
|
49
|
|
|
/** |
|
50
|
|
|
* @var string $representation what does this class represent in WordPress terms? |
|
51
|
|
|
*/ |
|
52
|
|
|
public static $representation = 'image'; |
|
53
|
|
|
/** |
|
54
|
|
|
* @var array of supported relative file types |
|
55
|
|
|
*/ |
|
56
|
|
|
private $file_types = array('jpg', 'jpeg', 'png', 'svg', 'bmp', 'ico', 'gif', 'tiff', 'pdf'); |
|
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @api |
|
59
|
|
|
* @var string $file_loc the location of the image file in the filesystem (ex: `/var/www/htdocs/wp-content/uploads/2015/08/my-pic.jpg`) |
|
60
|
|
|
*/ |
|
61
|
|
|
public $file_loc; |
|
62
|
|
|
public $file; |
|
63
|
|
|
public $sizes = array(); |
|
64
|
|
|
/** |
|
65
|
|
|
* @api |
|
66
|
|
|
* @var string $caption the string stored in the WordPress database |
|
67
|
|
|
*/ |
|
68
|
|
|
public $caption; |
|
69
|
|
|
/** |
|
70
|
|
|
* @var $_wp_attached_file the file as stored in the WordPress database |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $_wp_attached_file; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Creates a new TimberImage object |
|
76
|
|
|
* @example |
|
77
|
|
|
* ```php |
|
78
|
|
|
* // You can pass it an ID number |
|
79
|
|
|
* $myImage = new TimberImage(552); |
|
80
|
|
|
* |
|
81
|
|
|
* //Or send it a URL to an image |
|
82
|
|
|
* $myImage = new TimberImage('http://google.com/logo.jpg'); |
|
83
|
|
|
* ``` |
|
84
|
|
|
* @param int|string $iid |
|
85
|
|
|
*/ |
|
86
|
|
|
public function __construct($iid) { |
|
87
|
|
|
$this->init($iid); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return string the src of the file |
|
|
|
|
|
|
92
|
|
|
*/ |
|
93
|
|
|
public function __toString() { |
|
94
|
|
|
if ( $this->get_src() ) { |
|
|
|
|
|
|
95
|
|
|
return $this->get_src(); |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
return ''; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get a PHP array with pathinfo() info from the file |
|
102
|
|
|
* @return array |
|
103
|
|
|
*/ |
|
104
|
|
|
function get_pathinfo() { |
|
|
|
|
|
|
105
|
|
|
return pathinfo($this->file); |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @internal |
|
110
|
|
|
* @param string $dim |
|
|
|
|
|
|
111
|
|
|
* @return array|int |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function get_dimensions($dim = null) { |
|
114
|
|
|
if ( isset($this->_dimensions) ) { |
|
115
|
|
|
return $this->get_dimensions_loaded($dim); |
|
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
if ( file_exists($this->file_loc) && filesize($this->file_loc) ) { |
|
|
|
|
|
|
118
|
|
|
list($width, $height) = getimagesize($this->file_loc); |
|
|
|
|
|
|
119
|
|
|
$this->_dimensions = array(); |
|
120
|
|
|
$this->_dimensions[0] = $width; |
|
121
|
|
|
$this->_dimensions[1] = $height; |
|
122
|
|
|
return $this->get_dimensions_loaded($dim); |
|
|
|
|
|
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @internal |
|
128
|
|
|
* @param string|null $dim |
|
129
|
|
|
* @return array|int |
|
130
|
|
|
*/ |
|
131
|
|
|
protected function get_dimensions_loaded($dim) { |
|
132
|
|
|
if ( $dim === null ) { |
|
133
|
|
|
return $this->_dimensions; |
|
134
|
|
|
} |
|
135
|
|
|
if ( $dim == 'w' || $dim == 'width' ) { |
|
|
|
|
|
|
136
|
|
|
return $this->_dimensions[0]; |
|
137
|
|
|
} |
|
138
|
|
|
if ( $dim == 'h' || $dim == 'height' ) { |
|
|
|
|
|
|
139
|
|
|
return $this->_dimensions[1]; |
|
140
|
|
|
} |
|
141
|
|
|
return null; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @internal |
|
146
|
|
|
* @param int $iid the id number of the image in the WP database |
|
147
|
|
|
*/ |
|
148
|
|
|
protected function get_image_info( $iid ) { |
|
149
|
|
|
$image_info = $iid; |
|
150
|
|
|
if (is_numeric($iid)) { |
|
|
|
|
|
|
151
|
|
|
$image_info = wp_get_attachment_metadata($iid); |
|
|
|
|
|
|
152
|
|
|
if (!is_array($image_info)) { |
|
|
|
|
|
|
153
|
|
|
$image_info = array(); |
|
154
|
|
|
} |
|
155
|
|
|
$image_custom = get_post_custom($iid); |
|
|
|
|
|
|
156
|
|
|
$basic = get_post($iid); |
|
|
|
|
|
|
157
|
|
|
if ($basic) { |
|
|
|
|
|
|
158
|
|
|
if (isset($basic->post_excerpt)) { |
|
|
|
|
|
|
159
|
|
|
$this->caption = $basic->post_excerpt; |
|
160
|
|
|
} |
|
161
|
|
|
$image_custom = array_merge($image_custom, get_object_vars($basic)); |
|
|
|
|
|
|
162
|
|
|
} |
|
163
|
|
|
return array_merge($image_info, $image_custom); |
|
|
|
|
|
|
164
|
|
|
} |
|
165
|
|
|
if (is_array($image_info) && isset($image_info['image'])) { |
|
|
|
|
|
|
166
|
|
|
return $image_info['image']; |
|
167
|
|
|
} |
|
168
|
|
|
if (is_object($image_info)) { |
|
|
|
|
|
|
169
|
|
|
return get_object_vars($image_info); |
|
|
|
|
|
|
170
|
|
|
} |
|
171
|
|
|
return $iid; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @internal |
|
176
|
|
|
* @param string $url for evaluation |
|
177
|
|
|
* @return string with http/https corrected depending on what's appropriate for server |
|
178
|
|
|
*/ |
|
179
|
|
|
protected static function _maybe_secure_url($url) { |
|
180
|
|
|
if ( is_ssl() && strpos($url, 'https') !== 0 && strpos($url, 'http') === 0 ) { |
|
|
|
|
|
|
181
|
|
|
$url = 'https' . substr($url, strlen('http')); |
|
|
|
|
|
|
182
|
|
|
} |
|
183
|
|
|
return $url; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
public static function wp_upload_dir() { |
|
187
|
|
|
static $wp_upload_dir = false; |
|
188
|
|
|
|
|
189
|
|
|
if ( !$wp_upload_dir ) { |
|
|
|
|
|
|
190
|
|
|
$wp_upload_dir = wp_upload_dir(); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
return $wp_upload_dir; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @internal |
|
198
|
|
|
* @param int $iid |
|
|
|
|
|
|
199
|
|
|
*/ |
|
200
|
|
|
function init( $iid = false ) { |
|
|
|
|
|
|
201
|
|
|
if ( !is_numeric( $iid ) && is_string( $iid ) ) { |
|
|
|
|
|
|
202
|
|
|
if (strstr($iid, '://')) { |
|
|
|
|
|
|
203
|
|
|
$this->init_with_url($iid); |
|
|
|
|
|
|
204
|
|
|
return; |
|
205
|
|
|
} |
|
206
|
|
|
if ( strstr($iid, ABSPATH) ) { |
|
|
|
|
|
|
207
|
|
|
$this->init_with_file_path($iid); |
|
|
|
|
|
|
208
|
|
|
return; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
$relative = false; |
|
212
|
|
|
$iid_lower = strtolower($iid); |
|
|
|
|
|
|
213
|
|
|
foreach( $this->file_types as $type ) { if( strstr( $iid_lower, $type ) ) { $relative = true; break; } }; |
|
|
|
|
|
|
214
|
|
|
if ( $relative ) { |
|
215
|
|
|
$this->init_with_relative_path( $iid ); |
|
216
|
|
|
return; |
|
217
|
|
|
} |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
$image_info = $this->get_image_info($iid); |
|
|
|
|
|
|
221
|
|
|
|
|
222
|
|
|
$this->import($image_info); |
|
|
|
|
|
|
223
|
|
|
$basedir = self::wp_upload_dir(); |
|
224
|
|
|
$basedir = $basedir['basedir']; |
|
225
|
|
|
if ( isset($this->file) ) { |
|
226
|
|
|
$this->file_loc = $basedir . DIRECTORY_SEPARATOR . $this->file; |
|
227
|
|
|
} else if ( isset($this->_wp_attached_file) ) { |
|
228
|
|
|
$this->file = reset($this->_wp_attached_file); |
|
|
|
|
|
|
229
|
|
|
$this->file_loc = $basedir . DIRECTORY_SEPARATOR . $this->file; |
|
230
|
|
|
} |
|
231
|
|
|
if ( isset($image_info['id']) ) { |
|
232
|
|
|
$this->ID = $image_info['id']; |
|
233
|
|
|
} else if ( is_numeric($iid) ) { |
|
|
|
|
|
|
234
|
|
|
$this->ID = $iid; |
|
|
|
|
|
|
235
|
|
|
} |
|
236
|
|
|
if ( isset($this->ID) ) { |
|
237
|
|
|
$custom = get_post_custom($this->ID); |
|
|
|
|
|
|
238
|
|
|
foreach ($custom as $key => $value) { |
|
|
|
|
|
|
239
|
|
|
$this->$key = $value[0]; |
|
240
|
|
|
} |
|
241
|
|
|
} else { |
|
242
|
|
|
if ( is_array($iid) || is_object($iid) ) { |
|
|
|
|
|
|
243
|
|
|
TimberHelper::error_log('Not able to init in TimberImage with iid='); |
|
|
|
|
|
|
244
|
|
|
TimberHelper::error_log($iid); |
|
|
|
|
|
|
245
|
|
|
} else { |
|
246
|
|
|
TimberHelper::error_log('Not able to init in TimberImage with iid=' . $iid); |
|
|
|
|
|
|
247
|
|
|
} |
|
248
|
|
|
} |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* @internal |
|
253
|
|
|
* @param string $relative_path |
|
254
|
|
|
*/ |
|
255
|
|
|
protected function init_with_relative_path( $relative_path ) { |
|
256
|
|
|
$this->abs_url = home_url( $relative_path ); |
|
257
|
|
|
$file_path = TimberURLHelper::get_full_path( $relative_path ); |
|
258
|
|
|
$this->file_loc = $file_path; |
|
259
|
|
|
$this->file = $file_path; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* @internal |
|
264
|
|
|
* @param string $file_path |
|
265
|
|
|
*/ |
|
266
|
|
|
protected function init_with_file_path( $file_path ) { |
|
267
|
|
|
$url = TimberURLHelper::file_system_to_url( $file_path ); |
|
268
|
|
|
$this->abs_url = $url; |
|
269
|
|
|
$this->file_loc = $file_path; |
|
270
|
|
|
$this->file = $file_path; |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
/** |
|
274
|
|
|
* @internal |
|
275
|
|
|
* @param string $url |
|
276
|
|
|
*/ |
|
277
|
|
|
protected function init_with_url($url) { |
|
278
|
|
|
$this->abs_url = $url; |
|
279
|
|
|
if ( TimberURLHelper::is_local($url) ) { |
|
|
|
|
|
|
280
|
|
|
$this->file = ABSPATH . TimberURLHelper::get_rel_url($url); |
|
|
|
|
|
|
281
|
|
|
$this->file_loc = ABSPATH . TimberURLHelper::get_rel_url($url); |
|
|
|
|
|
|
282
|
|
|
} |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* @api |
|
287
|
|
|
* @example |
|
288
|
|
|
* ```twig |
|
289
|
|
|
* <img src="{{ image.src }}" alt="{{ image.alt }}" /> |
|
290
|
|
|
* ``` |
|
291
|
|
|
* ```html |
|
292
|
|
|
* <img src="http://example.org/wp-content/uploads/2015/08/pic.jpg" alt="W3 Checker told me to add alt text, so I am" /> |
|
293
|
|
|
* ``` |
|
294
|
|
|
* @return string alt text stored in WordPress |
|
295
|
|
|
*/ |
|
296
|
|
|
public function alt() { |
|
297
|
|
|
$alt = trim(strip_tags(get_post_meta($this->ID, '_wp_attachment_image_alt', true))); |
|
|
|
|
|
|
298
|
|
|
return $alt; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* @api |
|
303
|
|
|
* @example |
|
304
|
|
|
* ```twig |
|
305
|
|
|
* {% if post.thumbnail.aspect < 1 %} |
|
306
|
|
|
* {# handle vertical image #} |
|
307
|
|
|
* <img src="{{ post.thumbnail.src|resize(300, 500) }}" alt="A basketball player" /> |
|
308
|
|
|
* {% else %} |
|
309
|
|
|
* <img src="{{ post.thumbnail.src|resize(500) }}" alt="A sumo wrestler" /> |
|
310
|
|
|
* {% endif %} |
|
311
|
|
|
* ``` |
|
312
|
|
|
* @return float |
|
|
|
|
|
|
313
|
|
|
*/ |
|
314
|
|
|
public function aspect() { |
|
315
|
|
|
$w = intval($this->width()); |
|
|
|
|
|
|
316
|
|
|
$h = intval($this->height()); |
|
|
|
|
|
|
317
|
|
|
return $w / $h; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* @api |
|
322
|
|
|
* @example |
|
323
|
|
|
* ```twig |
|
324
|
|
|
* <img src="{{ image.src }}" height="{{ image.height }}" /> |
|
325
|
|
|
* ``` |
|
326
|
|
|
* ```html |
|
327
|
|
|
* <img src="http://example.org/wp-content/uploads/2015/08/pic.jpg" height="900" /> |
|
328
|
|
|
* ``` |
|
329
|
|
|
* @return int |
|
|
|
|
|
|
330
|
|
|
*/ |
|
331
|
|
|
public function height() { |
|
332
|
|
|
return $this->get_dimensions('height'); |
|
|
|
|
|
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
/** |
|
336
|
|
|
* Returns the link to an image attachment's Permalink page (NOT the link for the image itself!!) |
|
337
|
|
|
* @api |
|
338
|
|
|
* @example |
|
339
|
|
|
* ```twig |
|
340
|
|
|
* <a href="{{ image.link }}"><img src="{{ image.src }} "/></a> |
|
341
|
|
|
* ``` |
|
342
|
|
|
* ```html |
|
343
|
|
|
* <a href="http://example.org/my-cool-picture"><img src="http://example.org/wp-content/uploads/2015/whatever.jpg"/></a> |
|
344
|
|
|
* ``` |
|
345
|
|
|
*/ |
|
346
|
|
|
public function link() { |
|
347
|
|
|
if ( strlen($this->abs_url) ) { |
|
|
|
|
|
|
348
|
|
|
return $this->abs_url; |
|
349
|
|
|
} |
|
350
|
|
|
return get_permalink($this->ID); |
|
|
|
|
|
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
/** |
|
354
|
|
|
* @api |
|
355
|
|
|
* @return bool|TimberPost |
|
|
|
|
|
|
356
|
|
|
*/ |
|
357
|
|
|
public function parent() { |
|
358
|
|
|
if ( !$this->post_parent ) { |
|
|
|
|
|
|
359
|
|
|
return false; |
|
360
|
|
|
} |
|
361
|
|
|
return new $this->PostClass($this->post_parent); |
|
|
|
|
|
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
/** |
|
365
|
|
|
* @api |
|
366
|
|
|
* @example |
|
367
|
|
|
* ```twig |
|
368
|
|
|
* <img src="{{ image.path }}" /> |
|
369
|
|
|
* ``` |
|
370
|
|
|
* ```html |
|
371
|
|
|
* <img src="/wp-content/uploads/2015/08/pic.jpg" /> |
|
372
|
|
|
* ``` |
|
373
|
|
|
* @return string the /relative/path/to/the/file |
|
374
|
|
|
*/ |
|
375
|
|
|
public function path() { |
|
376
|
|
|
return TimberURLHelper::get_rel_path($this->src()); |
|
|
|
|
|
|
377
|
|
|
} |
|
378
|
|
|
|
|
379
|
|
|
/** |
|
380
|
|
|
* @param string $size a size known to WordPress (like "medium") |
|
381
|
|
|
* @api |
|
382
|
|
|
* @example |
|
383
|
|
|
* ```twig |
|
384
|
|
|
* <h1>{{post.title}}</h1> |
|
385
|
|
|
* <img src="{{post.thumbnail.src}}" /> |
|
386
|
|
|
* ``` |
|
387
|
|
|
* ```html |
|
388
|
|
|
* <img src="http://example.org/wp-content/uploads/2015/08/pic.jpg" /> |
|
389
|
|
|
* ``` |
|
390
|
|
|
* @return bool|string |
|
391
|
|
|
*/ |
|
392
|
|
|
public function src($size = '') { |
|
393
|
|
|
if ( isset($this->abs_url) ) { |
|
394
|
|
|
return $this->_maybe_secure_url($this->abs_url); |
|
|
|
|
|
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
if ( $size && is_string($size) && isset($this->sizes[$size]) ) { |
|
|
|
|
|
|
398
|
|
|
$image = image_downsize($this->ID, $size); |
|
|
|
|
|
|
399
|
|
|
return $this->_maybe_secure_url(reset($image)); |
|
|
|
|
|
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
if ( !isset($this->file) && isset($this->_wp_attached_file) ) { |
|
|
|
|
|
|
403
|
|
|
$this->file = $this->_wp_attached_file; |
|
404
|
|
|
} |
|
405
|
|
|
|
|
406
|
|
|
if ( !isset($this->file) ) { |
|
|
|
|
|
|
407
|
|
|
return false; |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
$dir = self::wp_upload_dir(); |
|
411
|
|
|
$base = $dir['baseurl']; |
|
412
|
|
|
|
|
413
|
|
|
$src = trailingslashit($this->_maybe_secure_url($base)) . $this->file; |
|
|
|
|
|
|
414
|
|
|
$src = apply_filters('timber/image/src', $src, $this->ID); |
|
|
|
|
|
|
415
|
|
|
return apply_filters('timber_image_src', $src, $this->ID); |
|
|
|
|
|
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
/** |
|
419
|
|
|
* @deprecated use src() instead |
|
420
|
|
|
* @return string |
|
|
|
|
|
|
421
|
|
|
*/ |
|
422
|
|
|
function url() { |
|
|
|
|
|
|
423
|
|
|
return $this->get_src(); |
|
|
|
|
|
|
424
|
|
|
} |
|
425
|
|
|
|
|
426
|
|
|
/** |
|
427
|
|
|
* @api |
|
428
|
|
|
* @example |
|
429
|
|
|
* ```twig |
|
430
|
|
|
* <img src="{{ image.src }}" width="{{ image.width }}" /> |
|
431
|
|
|
* ``` |
|
432
|
|
|
* ```html |
|
433
|
|
|
* <img src="http://example.org/wp-content/uploads/2015/08/pic.jpg" width="1600" /> |
|
434
|
|
|
* ``` |
|
435
|
|
|
* @return int |
|
|
|
|
|
|
436
|
|
|
*/ |
|
437
|
|
|
public function width() { |
|
438
|
|
|
return $this->get_dimensions('width'); |
|
|
|
|
|
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
|
|
442
|
|
|
/** |
|
443
|
|
|
* @deprecated 0.21.9 use TimberImage::width() instead |
|
444
|
|
|
* @internal |
|
445
|
|
|
* @return int |
|
|
|
|
|
|
446
|
|
|
*/ |
|
447
|
|
|
function get_width() { |
|
|
|
|
|
|
448
|
|
|
return $this->width(); |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
/** |
|
452
|
|
|
* @deprecated 0.21.9 use TimberImage::height() instead |
|
453
|
|
|
* @internal |
|
454
|
|
|
* @return int |
|
|
|
|
|
|
455
|
|
|
*/ |
|
456
|
|
|
function get_height() { |
|
|
|
|
|
|
457
|
|
|
return $this->height(); |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
|
|
/** |
|
461
|
|
|
* @deprecated 0.21.9 use TimberImage::src |
|
462
|
|
|
* @internal |
|
463
|
|
|
* @param string $size |
|
464
|
|
|
* @return bool|string |
|
465
|
|
|
*/ |
|
466
|
|
|
function get_src( $size = '' ) { |
|
|
|
|
|
|
467
|
|
|
return $this->src( $size ); |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
/** |
|
471
|
|
|
* @deprecated 0.21.9 use TimberImage::path() |
|
472
|
|
|
* @internal |
|
473
|
|
|
* @return string |
|
474
|
|
|
*/ |
|
475
|
|
|
function get_path() { |
|
|
|
|
|
|
476
|
|
|
return $this->link(); |
|
477
|
|
|
} |
|
478
|
|
|
|
|
479
|
|
|
/** |
|
480
|
|
|
* @deprecated use src() instead |
|
481
|
|
|
* @return string |
|
|
|
|
|
|
482
|
|
|
*/ |
|
483
|
|
|
function get_url() { |
|
|
|
|
|
|
484
|
|
|
return $this->get_src(); |
|
|
|
|
|
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
/** |
|
488
|
|
|
* @internal |
|
489
|
|
|
* @deprecated 0.21.8 |
|
490
|
|
|
* @return bool|TimberPost |
|
|
|
|
|
|
491
|
|
|
*/ |
|
492
|
|
|
function get_parent() { |
|
|
|
|
|
|
493
|
|
|
return $this->parent(); |
|
494
|
|
|
} |
|
495
|
|
|
|
|
496
|
|
|
/** |
|
497
|
|
|
* @internal |
|
498
|
|
|
* @deprecated 0.21.9 |
|
499
|
|
|
* @see TimberImage::alt |
|
500
|
|
|
* @return string |
|
501
|
|
|
*/ |
|
502
|
|
|
function get_alt() { |
|
|
|
|
|
|
503
|
|
|
return $this->alt(); |
|
504
|
|
|
} |
|
505
|
|
|
|
|
506
|
|
|
} |
|
507
|
|
|
|