root / drupal7 / sites / all / libraries / simplepie / library / SimplePie / Enclosure.php @ 41cc1b08
1 | 41cc1b08 | Assos Assos | <?php
|
---|---|---|---|
2 | /**
|
||
3 | * SimplePie
|
||
4 | *
|
||
5 | * A PHP-Based RSS and Atom Feed Framework.
|
||
6 | * Takes the hard work out of managing a complete RSS/Atom solution.
|
||
7 | *
|
||
8 | * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||
9 | * All rights reserved.
|
||
10 | *
|
||
11 | * Redistribution and use in source and binary forms, with or without modification, are
|
||
12 | * permitted provided that the following conditions are met:
|
||
13 | *
|
||
14 | * * Redistributions of source code must retain the above copyright notice, this list of
|
||
15 | * conditions and the following disclaimer.
|
||
16 | *
|
||
17 | * * Redistributions in binary form must reproduce the above copyright notice, this list
|
||
18 | * of conditions and the following disclaimer in the documentation and/or other materials
|
||
19 | * provided with the distribution.
|
||
20 | *
|
||
21 | * * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||
22 | * to endorse or promote products derived from this software without specific prior
|
||
23 | * written permission.
|
||
24 | *
|
||
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||
26 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||
27 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||
28 | * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||
29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||
30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||
31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||
32 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||
33 | * POSSIBILITY OF SUCH DAMAGE.
|
||
34 | *
|
||
35 | * @package SimplePie
|
||
36 | * @version 1.3.1
|
||
37 | * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||
38 | * @author Ryan Parman
|
||
39 | * @author Geoffrey Sneddon
|
||
40 | * @author Ryan McCue
|
||
41 | * @link http://simplepie.org/ SimplePie
|
||
42 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||
43 | */
|
||
44 | |||
45 | /**
|
||
46 | * Handles everything related to enclosures (including Media RSS and iTunes RSS)
|
||
47 | *
|
||
48 | * Used by {@see SimplePie_Item::get_enclosure()} and {@see SimplePie_Item::get_enclosures()}
|
||
49 | *
|
||
50 | * This class can be overloaded with {@see SimplePie::set_enclosure_class()}
|
||
51 | *
|
||
52 | * @package SimplePie
|
||
53 | * @subpackage API
|
||
54 | */
|
||
55 | class SimplePie_Enclosure |
||
56 | { |
||
57 | /**
|
||
58 | * @var string
|
||
59 | * @see get_bitrate()
|
||
60 | */
|
||
61 | var $bitrate; |
||
62 | |||
63 | /**
|
||
64 | * @var array
|
||
65 | * @see get_captions()
|
||
66 | */
|
||
67 | var $captions; |
||
68 | |||
69 | /**
|
||
70 | * @var array
|
||
71 | * @see get_categories()
|
||
72 | */
|
||
73 | var $categories; |
||
74 | |||
75 | /**
|
||
76 | * @var int
|
||
77 | * @see get_channels()
|
||
78 | */
|
||
79 | var $channels; |
||
80 | |||
81 | /**
|
||
82 | * @var SimplePie_Copyright
|
||
83 | * @see get_copyright()
|
||
84 | */
|
||
85 | var $copyright; |
||
86 | |||
87 | /**
|
||
88 | * @var array
|
||
89 | * @see get_credits()
|
||
90 | */
|
||
91 | var $credits; |
||
92 | |||
93 | /**
|
||
94 | * @var string
|
||
95 | * @see get_description()
|
||
96 | */
|
||
97 | var $description; |
||
98 | |||
99 | /**
|
||
100 | * @var int
|
||
101 | * @see get_duration()
|
||
102 | */
|
||
103 | var $duration; |
||
104 | |||
105 | /**
|
||
106 | * @var string
|
||
107 | * @see get_expression()
|
||
108 | */
|
||
109 | var $expression; |
||
110 | |||
111 | /**
|
||
112 | * @var string
|
||
113 | * @see get_framerate()
|
||
114 | */
|
||
115 | var $framerate; |
||
116 | |||
117 | /**
|
||
118 | * @var string
|
||
119 | * @see get_handler()
|
||
120 | */
|
||
121 | var $handler; |
||
122 | |||
123 | /**
|
||
124 | * @var array
|
||
125 | * @see get_hashes()
|
||
126 | */
|
||
127 | var $hashes; |
||
128 | |||
129 | /**
|
||
130 | * @var string
|
||
131 | * @see get_height()
|
||
132 | */
|
||
133 | var $height; |
||
134 | |||
135 | /**
|
||
136 | * @deprecated
|
||
137 | * @var null
|
||
138 | */
|
||
139 | var $javascript; |
||
140 | |||
141 | /**
|
||
142 | * @var array
|
||
143 | * @see get_keywords()
|
||
144 | */
|
||
145 | var $keywords; |
||
146 | |||
147 | /**
|
||
148 | * @var string
|
||
149 | * @see get_language()
|
||
150 | */
|
||
151 | var $lang; |
||
152 | |||
153 | /**
|
||
154 | * @var string
|
||
155 | * @see get_length()
|
||
156 | */
|
||
157 | var $length; |
||
158 | |||
159 | /**
|
||
160 | * @var string
|
||
161 | * @see get_link()
|
||
162 | */
|
||
163 | var $link; |
||
164 | |||
165 | /**
|
||
166 | * @var string
|
||
167 | * @see get_medium()
|
||
168 | */
|
||
169 | var $medium; |
||
170 | |||
171 | /**
|
||
172 | * @var string
|
||
173 | * @see get_player()
|
||
174 | */
|
||
175 | var $player; |
||
176 | |||
177 | /**
|
||
178 | * @var array
|
||
179 | * @see get_ratings()
|
||
180 | */
|
||
181 | var $ratings; |
||
182 | |||
183 | /**
|
||
184 | * @var array
|
||
185 | * @see get_restrictions()
|
||
186 | */
|
||
187 | var $restrictions; |
||
188 | |||
189 | /**
|
||
190 | * @var string
|
||
191 | * @see get_sampling_rate()
|
||
192 | */
|
||
193 | var $samplingrate; |
||
194 | |||
195 | /**
|
||
196 | * @var array
|
||
197 | * @see get_thumbnails()
|
||
198 | */
|
||
199 | var $thumbnails; |
||
200 | |||
201 | /**
|
||
202 | * @var string
|
||
203 | * @see get_title()
|
||
204 | */
|
||
205 | var $title; |
||
206 | |||
207 | /**
|
||
208 | * @var string
|
||
209 | * @see get_type()
|
||
210 | */
|
||
211 | var $type; |
||
212 | |||
213 | /**
|
||
214 | * @var string
|
||
215 | * @see get_width()
|
||
216 | */
|
||
217 | var $width; |
||
218 | |||
219 | /**
|
||
220 | * Constructor, used to input the data
|
||
221 | *
|
||
222 | * For documentation on all the parameters, see the corresponding
|
||
223 | * properties and their accessors
|
||
224 | *
|
||
225 | * @uses idna_convert If available, this will convert an IDN
|
||
226 | */
|
||
227 | public function __construct($link = null, $type = null, $length = null, $javascript = null, $bitrate = null, $captions = null, $categories = null, $channels = null, $copyright = null, $credits = null, $description = null, $duration = null, $expression = null, $framerate = null, $hashes = null, $height = null, $keywords = null, $lang = null, $medium = null, $player = null, $ratings = null, $restrictions = null, $samplingrate = null, $thumbnails = null, $title = null, $width = null) |
||
228 | { |
||
229 | $this->bitrate = $bitrate; |
||
230 | $this->captions = $captions; |
||
231 | $this->categories = $categories; |
||
232 | $this->channels = $channels; |
||
233 | $this->copyright = $copyright; |
||
234 | $this->credits = $credits; |
||
235 | $this->description = $description; |
||
236 | $this->duration = $duration; |
||
237 | $this->expression = $expression; |
||
238 | $this->framerate = $framerate; |
||
239 | $this->hashes = $hashes; |
||
240 | $this->height = $height; |
||
241 | $this->keywords = $keywords; |
||
242 | $this->lang = $lang; |
||
243 | $this->length = $length; |
||
244 | $this->link = $link; |
||
245 | $this->medium = $medium; |
||
246 | $this->player = $player; |
||
247 | $this->ratings = $ratings; |
||
248 | $this->restrictions = $restrictions; |
||
249 | $this->samplingrate = $samplingrate; |
||
250 | $this->thumbnails = $thumbnails; |
||
251 | $this->title = $title; |
||
252 | $this->type = $type; |
||
253 | $this->width = $width; |
||
254 | |||
255 | if (class_exists('idna_convert')) |
||
256 | { |
||
257 | $idn = new idna_convert(); |
||
258 | $parsed = SimplePie_Misc::parse_url($link); |
||
259 | $this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']); |
||
260 | } |
||
261 | $this->handler = $this->get_handler(); // Needs to load last |
||
262 | } |
||
263 | |||
264 | /**
|
||
265 | * String-ified version
|
||
266 | *
|
||
267 | * @return string
|
||
268 | */
|
||
269 | public function __toString() |
||
270 | { |
||
271 | // There is no $this->data here
|
||
272 | return md5(serialize($this)); |
||
273 | } |
||
274 | |||
275 | /**
|
||
276 | * Get the bitrate
|
||
277 | *
|
||
278 | * @return string|null
|
||
279 | */
|
||
280 | public function get_bitrate() |
||
281 | { |
||
282 | if ($this->bitrate !== null) |
||
283 | { |
||
284 | return $this->bitrate; |
||
285 | } |
||
286 | else
|
||
287 | { |
||
288 | return null; |
||
289 | } |
||
290 | } |
||
291 | |||
292 | /**
|
||
293 | * Get a single caption
|
||
294 | *
|
||
295 | * @param int $key
|
||
296 | * @return SimplePie_Caption|null
|
||
297 | */
|
||
298 | public function get_caption($key = 0) |
||
299 | { |
||
300 | $captions = $this->get_captions(); |
||
301 | if (isset($captions[$key])) |
||
302 | { |
||
303 | return $captions[$key]; |
||
304 | } |
||
305 | else
|
||
306 | { |
||
307 | return null; |
||
308 | } |
||
309 | } |
||
310 | |||
311 | /**
|
||
312 | * Get all captions
|
||
313 | *
|
||
314 | * @return array|null Array of {@see SimplePie_Caption} objects
|
||
315 | */
|
||
316 | public function get_captions() |
||
317 | { |
||
318 | if ($this->captions !== null) |
||
319 | { |
||
320 | return $this->captions; |
||
321 | } |
||
322 | else
|
||
323 | { |
||
324 | return null; |
||
325 | } |
||
326 | } |
||
327 | |||
328 | /**
|
||
329 | * Get a single category
|
||
330 | *
|
||
331 | * @param int $key
|
||
332 | * @return SimplePie_Category|null
|
||
333 | */
|
||
334 | public function get_category($key = 0) |
||
335 | { |
||
336 | $categories = $this->get_categories(); |
||
337 | if (isset($categories[$key])) |
||
338 | { |
||
339 | return $categories[$key]; |
||
340 | } |
||
341 | else
|
||
342 | { |
||
343 | return null; |
||
344 | } |
||
345 | } |
||
346 | |||
347 | /**
|
||
348 | * Get all categories
|
||
349 | *
|
||
350 | * @return array|null Array of {@see SimplePie_Category} objects
|
||
351 | */
|
||
352 | public function get_categories() |
||
353 | { |
||
354 | if ($this->categories !== null) |
||
355 | { |
||
356 | return $this->categories; |
||
357 | } |
||
358 | else
|
||
359 | { |
||
360 | return null; |
||
361 | } |
||
362 | } |
||
363 | |||
364 | /**
|
||
365 | * Get the number of audio channels
|
||
366 | *
|
||
367 | * @return int|null
|
||
368 | */
|
||
369 | public function get_channels() |
||
370 | { |
||
371 | if ($this->channels !== null) |
||
372 | { |
||
373 | return $this->channels; |
||
374 | } |
||
375 | else
|
||
376 | { |
||
377 | return null; |
||
378 | } |
||
379 | } |
||
380 | |||
381 | /**
|
||
382 | * Get the copyright information
|
||
383 | *
|
||
384 | * @return SimplePie_Copyright|null
|
||
385 | */
|
||
386 | public function get_copyright() |
||
387 | { |
||
388 | if ($this->copyright !== null) |
||
389 | { |
||
390 | return $this->copyright; |
||
391 | } |
||
392 | else
|
||
393 | { |
||
394 | return null; |
||
395 | } |
||
396 | } |
||
397 | |||
398 | /**
|
||
399 | * Get a single credit
|
||
400 | *
|
||
401 | * @param int $key
|
||
402 | * @return SimplePie_Credit|null
|
||
403 | */
|
||
404 | public function get_credit($key = 0) |
||
405 | { |
||
406 | $credits = $this->get_credits(); |
||
407 | if (isset($credits[$key])) |
||
408 | { |
||
409 | return $credits[$key]; |
||
410 | } |
||
411 | else
|
||
412 | { |
||
413 | return null; |
||
414 | } |
||
415 | } |
||
416 | |||
417 | /**
|
||
418 | * Get all credits
|
||
419 | *
|
||
420 | * @return array|null Array of {@see SimplePie_Credit} objects
|
||
421 | */
|
||
422 | public function get_credits() |
||
423 | { |
||
424 | if ($this->credits !== null) |
||
425 | { |
||
426 | return $this->credits; |
||
427 | } |
||
428 | else
|
||
429 | { |
||
430 | return null; |
||
431 | } |
||
432 | } |
||
433 | |||
434 | /**
|
||
435 | * Get the description of the enclosure
|
||
436 | *
|
||
437 | * @return string|null
|
||
438 | */
|
||
439 | public function get_description() |
||
440 | { |
||
441 | if ($this->description !== null) |
||
442 | { |
||
443 | return $this->description; |
||
444 | } |
||
445 | else
|
||
446 | { |
||
447 | return null; |
||
448 | } |
||
449 | } |
||
450 | |||
451 | /**
|
||
452 | * Get the duration of the enclosure
|
||
453 | *
|
||
454 | * @param string $convert Convert seconds into hh:mm:ss
|
||
455 | * @return string|int|null 'hh:mm:ss' string if `$convert` was specified, otherwise integer (or null if none found)
|
||
456 | */
|
||
457 | public function get_duration($convert = false) |
||
458 | { |
||
459 | if ($this->duration !== null) |
||
460 | { |
||
461 | if ($convert) |
||
462 | { |
||
463 | $time = SimplePie_Misc::time_hms($this->duration); |
||
464 | return $time; |
||
465 | } |
||
466 | else
|
||
467 | { |
||
468 | return $this->duration; |
||
469 | } |
||
470 | } |
||
471 | else
|
||
472 | { |
||
473 | return null; |
||
474 | } |
||
475 | } |
||
476 | |||
477 | /**
|
||
478 | * Get the expression
|
||
479 | *
|
||
480 | * @return string Probably one of 'sample', 'full', 'nonstop', 'clip'. Defaults to 'full'
|
||
481 | */
|
||
482 | public function get_expression() |
||
483 | { |
||
484 | if ($this->expression !== null) |
||
485 | { |
||
486 | return $this->expression; |
||
487 | } |
||
488 | else
|
||
489 | { |
||
490 | return 'full'; |
||
491 | } |
||
492 | } |
||
493 | |||
494 | /**
|
||
495 | * Get the file extension
|
||
496 | *
|
||
497 | * @return string|null
|
||
498 | */
|
||
499 | public function get_extension() |
||
500 | { |
||
501 | if ($this->link !== null) |
||
502 | { |
||
503 | $url = SimplePie_Misc::parse_url($this->link); |
||
504 | if ($url['path'] !== '') |
||
505 | { |
||
506 | return pathinfo($url['path'], PATHINFO_EXTENSION); |
||
507 | } |
||
508 | } |
||
509 | return null; |
||
510 | } |
||
511 | |||
512 | /**
|
||
513 | * Get the framerate (in frames-per-second)
|
||
514 | *
|
||
515 | * @return string|null
|
||
516 | */
|
||
517 | public function get_framerate() |
||
518 | { |
||
519 | if ($this->framerate !== null) |
||
520 | { |
||
521 | return $this->framerate; |
||
522 | } |
||
523 | else
|
||
524 | { |
||
525 | return null; |
||
526 | } |
||
527 | } |
||
528 | |||
529 | /**
|
||
530 | * Get the preferred handler
|
||
531 | *
|
||
532 | * @return string|null One of 'flash', 'fmedia', 'quicktime', 'wmedia', 'mp3'
|
||
533 | */
|
||
534 | public function get_handler() |
||
535 | { |
||
536 | return $this->get_real_type(true); |
||
537 | } |
||
538 | |||
539 | /**
|
||
540 | * Get a single hash
|
||
541 | *
|
||
542 | * @link http://www.rssboard.org/media-rss#media-hash
|
||
543 | * @param int $key
|
||
544 | * @return string|null Hash as per `media:hash`, prefixed with "$algo:"
|
||
545 | */
|
||
546 | public function get_hash($key = 0) |
||
547 | { |
||
548 | $hashes = $this->get_hashes(); |
||
549 | if (isset($hashes[$key])) |
||
550 | { |
||
551 | return $hashes[$key]; |
||
552 | } |
||
553 | else
|
||
554 | { |
||
555 | return null; |
||
556 | } |
||
557 | } |
||
558 | |||
559 | /**
|
||
560 | * Get all credits
|
||
561 | *
|
||
562 | * @return array|null Array of strings, see {@see get_hash()}
|
||
563 | */
|
||
564 | public function get_hashes() |
||
565 | { |
||
566 | if ($this->hashes !== null) |
||
567 | { |
||
568 | return $this->hashes; |
||
569 | } |
||
570 | else
|
||
571 | { |
||
572 | return null; |
||
573 | } |
||
574 | } |
||
575 | |||
576 | /**
|
||
577 | * Get the height
|
||
578 | *
|
||
579 | * @return string|null
|
||
580 | */
|
||
581 | public function get_height() |
||
582 | { |
||
583 | if ($this->height !== null) |
||
584 | { |
||
585 | return $this->height; |
||
586 | } |
||
587 | else
|
||
588 | { |
||
589 | return null; |
||
590 | } |
||
591 | } |
||
592 | |||
593 | /**
|
||
594 | * Get the language
|
||
595 | *
|
||
596 | * @link http://tools.ietf.org/html/rfc3066
|
||
597 | * @return string|null Language code as per RFC 3066
|
||
598 | */
|
||
599 | public function get_language() |
||
600 | { |
||
601 | if ($this->lang !== null) |
||
602 | { |
||
603 | return $this->lang; |
||
604 | } |
||
605 | else
|
||
606 | { |
||
607 | return null; |
||
608 | } |
||
609 | } |
||
610 | |||
611 | /**
|
||
612 | * Get a single keyword
|
||
613 | *
|
||
614 | * @param int $key
|
||
615 | * @return string|null
|
||
616 | */
|
||
617 | public function get_keyword($key = 0) |
||
618 | { |
||
619 | $keywords = $this->get_keywords(); |
||
620 | if (isset($keywords[$key])) |
||
621 | { |
||
622 | return $keywords[$key]; |
||
623 | } |
||
624 | else
|
||
625 | { |
||
626 | return null; |
||
627 | } |
||
628 | } |
||
629 | |||
630 | /**
|
||
631 | * Get all keywords
|
||
632 | *
|
||
633 | * @return array|null Array of strings
|
||
634 | */
|
||
635 | public function get_keywords() |
||
636 | { |
||
637 | if ($this->keywords !== null) |
||
638 | { |
||
639 | return $this->keywords; |
||
640 | } |
||
641 | else
|
||
642 | { |
||
643 | return null; |
||
644 | } |
||
645 | } |
||
646 | |||
647 | /**
|
||
648 | * Get length
|
||
649 | *
|
||
650 | * @return float Length in bytes
|
||
651 | */
|
||
652 | public function get_length() |
||
653 | { |
||
654 | if ($this->length !== null) |
||
655 | { |
||
656 | return $this->length; |
||
657 | } |
||
658 | else
|
||
659 | { |
||
660 | return null; |
||
661 | } |
||
662 | } |
||
663 | |||
664 | /**
|
||
665 | * Get the URL
|
||
666 | *
|
||
667 | * @return string|null
|
||
668 | */
|
||
669 | public function get_link() |
||
670 | { |
||
671 | if ($this->link !== null) |
||
672 | { |
||
673 | return urldecode($this->link); |
||
674 | } |
||
675 | else
|
||
676 | { |
||
677 | return null; |
||
678 | } |
||
679 | } |
||
680 | |||
681 | /**
|
||
682 | * Get the medium
|
||
683 | *
|
||
684 | * @link http://www.rssboard.org/media-rss#media-content
|
||
685 | * @return string|null Should be one of 'image', 'audio', 'video', 'document', 'executable'
|
||
686 | */
|
||
687 | public function get_medium() |
||
688 | { |
||
689 | if ($this->medium !== null) |
||
690 | { |
||
691 | return $this->medium; |
||
692 | } |
||
693 | else
|
||
694 | { |
||
695 | return null; |
||
696 | } |
||
697 | } |
||
698 | |||
699 | /**
|
||
700 | * Get the player URL
|
||
701 | *
|
||
702 | * Typically the same as {@see get_permalink()}
|
||
703 | * @return string|null Player URL
|
||
704 | */
|
||
705 | public function get_player() |
||
706 | { |
||
707 | if ($this->player !== null) |
||
708 | { |
||
709 | return $this->player; |
||
710 | } |
||
711 | else
|
||
712 | { |
||
713 | return null; |
||
714 | } |
||
715 | } |
||
716 | |||
717 | /**
|
||
718 | * Get a single rating
|
||
719 | *
|
||
720 | * @param int $key
|
||
721 | * @return SimplePie_Rating|null
|
||
722 | */
|
||
723 | public function get_rating($key = 0) |
||
724 | { |
||
725 | $ratings = $this->get_ratings(); |
||
726 | if (isset($ratings[$key])) |
||
727 | { |
||
728 | return $ratings[$key]; |
||
729 | } |
||
730 | else
|
||
731 | { |
||
732 | return null; |
||
733 | } |
||
734 | } |
||
735 | |||
736 | /**
|
||
737 | * Get all ratings
|
||
738 | *
|
||
739 | * @return array|null Array of {@see SimplePie_Rating} objects
|
||
740 | */
|
||
741 | public function get_ratings() |
||
742 | { |
||
743 | if ($this->ratings !== null) |
||
744 | { |
||
745 | return $this->ratings; |
||
746 | } |
||
747 | else
|
||
748 | { |
||
749 | return null; |
||
750 | } |
||
751 | } |
||
752 | |||
753 | /**
|
||
754 | * Get a single restriction
|
||
755 | *
|
||
756 | * @param int $key
|
||
757 | * @return SimplePie_Restriction|null
|
||
758 | */
|
||
759 | public function get_restriction($key = 0) |
||
760 | { |
||
761 | $restrictions = $this->get_restrictions(); |
||
762 | if (isset($restrictions[$key])) |
||
763 | { |
||
764 | return $restrictions[$key]; |
||
765 | } |
||
766 | else
|
||
767 | { |
||
768 | return null; |
||
769 | } |
||
770 | } |
||
771 | |||
772 | /**
|
||
773 | * Get all restrictions
|
||
774 | *
|
||
775 | * @return array|null Array of {@see SimplePie_Restriction} objects
|
||
776 | */
|
||
777 | public function get_restrictions() |
||
778 | { |
||
779 | if ($this->restrictions !== null) |
||
780 | { |
||
781 | return $this->restrictions; |
||
782 | } |
||
783 | else
|
||
784 | { |
||
785 | return null; |
||
786 | } |
||
787 | } |
||
788 | |||
789 | /**
|
||
790 | * Get the sampling rate (in kHz)
|
||
791 | *
|
||
792 | * @return string|null
|
||
793 | */
|
||
794 | public function get_sampling_rate() |
||
795 | { |
||
796 | if ($this->samplingrate !== null) |
||
797 | { |
||
798 | return $this->samplingrate; |
||
799 | } |
||
800 | else
|
||
801 | { |
||
802 | return null; |
||
803 | } |
||
804 | } |
||
805 | |||
806 | /**
|
||
807 | * Get the file size (in MiB)
|
||
808 | *
|
||
809 | * @return float|null File size in mebibytes (1048 bytes)
|
||
810 | */
|
||
811 | public function get_size() |
||
812 | { |
||
813 | $length = $this->get_length(); |
||
814 | if ($length !== null) |
||
815 | { |
||
816 | return round($length/1048576, 2); |
||
817 | } |
||
818 | else
|
||
819 | { |
||
820 | return null; |
||
821 | } |
||
822 | } |
||
823 | |||
824 | /**
|
||
825 | * Get a single thumbnail
|
||
826 | *
|
||
827 | * @param int $key
|
||
828 | * @return string|null Thumbnail URL
|
||
829 | */
|
||
830 | public function get_thumbnail($key = 0) |
||
831 | { |
||
832 | $thumbnails = $this->get_thumbnails(); |
||
833 | if (isset($thumbnails[$key])) |
||
834 | { |
||
835 | return $thumbnails[$key]; |
||
836 | } |
||
837 | else
|
||
838 | { |
||
839 | return null; |
||
840 | } |
||
841 | } |
||
842 | |||
843 | /**
|
||
844 | * Get all thumbnails
|
||
845 | *
|
||
846 | * @return array|null Array of thumbnail URLs
|
||
847 | */
|
||
848 | public function get_thumbnails() |
||
849 | { |
||
850 | if ($this->thumbnails !== null) |
||
851 | { |
||
852 | return $this->thumbnails; |
||
853 | } |
||
854 | else
|
||
855 | { |
||
856 | return null; |
||
857 | } |
||
858 | } |
||
859 | |||
860 | /**
|
||
861 | * Get the title
|
||
862 | *
|
||
863 | * @return string|null
|
||
864 | */
|
||
865 | public function get_title() |
||
866 | { |
||
867 | if ($this->title !== null) |
||
868 | { |
||
869 | return $this->title; |
||
870 | } |
||
871 | else
|
||
872 | { |
||
873 | return null; |
||
874 | } |
||
875 | } |
||
876 | |||
877 | /**
|
||
878 | * Get mimetype of the enclosure
|
||
879 | *
|
||
880 | * @see get_real_type()
|
||
881 | * @return string|null MIME type
|
||
882 | */
|
||
883 | public function get_type() |
||
884 | { |
||
885 | if ($this->type !== null) |
||
886 | { |
||
887 | return $this->type; |
||
888 | } |
||
889 | else
|
||
890 | { |
||
891 | return null; |
||
892 | } |
||
893 | } |
||
894 | |||
895 | /**
|
||
896 | * Get the width
|
||
897 | *
|
||
898 | * @return string|null
|
||
899 | */
|
||
900 | public function get_width() |
||
901 | { |
||
902 | if ($this->width !== null) |
||
903 | { |
||
904 | return $this->width; |
||
905 | } |
||
906 | else
|
||
907 | { |
||
908 | return null; |
||
909 | } |
||
910 | } |
||
911 | |||
912 | /**
|
||
913 | * Embed the enclosure using `<embed>`
|
||
914 | *
|
||
915 | * @deprecated Use the second parameter to {@see embed} instead
|
||
916 | *
|
||
917 | * @param array|string $options See first paramter to {@see embed}
|
||
918 | * @return string HTML string to output
|
||
919 | */
|
||
920 | public function native_embed($options='') |
||
921 | { |
||
922 | return $this->embed($options, true); |
||
923 | } |
||
924 | |||
925 | /**
|
||
926 | * Embed the enclosure using Javascript
|
||
927 | *
|
||
928 | * `$options` is an array or comma-separated key:value string, with the
|
||
929 | * following properties:
|
||
930 | *
|
||
931 | * - `alt` (string): Alternate content for when an end-user does not have
|
||
932 | * the appropriate handler installed or when a file type is
|
||
933 | * unsupported. Can be any text or HTML. Defaults to blank.
|
||
934 | * - `altclass` (string): If a file type is unsupported, the end-user will
|
||
935 | * see the alt text (above) linked directly to the content. That link
|
||
936 | * will have this value as its class name. Defaults to blank.
|
||
937 | * - `audio` (string): This is an image that should be used as a
|
||
938 | * placeholder for audio files before they're loaded (QuickTime-only).
|
||
939 | * Can be any relative or absolute URL. Defaults to blank.
|
||
940 | * - `bgcolor` (string): The background color for the media, if not
|
||
941 | * already transparent. Defaults to `#ffffff`.
|
||
942 | * - `height` (integer): The height of the embedded media. Accepts any
|
||
943 | * numeric pixel value (such as `360`) or `auto`. Defaults to `auto`,
|
||
944 | * and it is recommended that you use this default.
|
||
945 | * - `loop` (boolean): Do you want the media to loop when its done?
|
||
946 | * Defaults to `false`.
|
||
947 | * - `mediaplayer` (string): The location of the included
|
||
948 | * `mediaplayer.swf` file. This allows for the playback of Flash Video
|
||
949 | * (`.flv`) files, and is the default handler for non-Odeo MP3's.
|
||
950 | * Defaults to blank.
|
||
951 | * - `video` (string): This is an image that should be used as a
|
||
952 | * placeholder for video files before they're loaded (QuickTime-only).
|
||
953 | * Can be any relative or absolute URL. Defaults to blank.
|
||
954 | * - `width` (integer): The width of the embedded media. Accepts any
|
||
955 | * numeric pixel value (such as `480`) or `auto`. Defaults to `auto`,
|
||
956 | * and it is recommended that you use this default.
|
||
957 | * - `widescreen` (boolean): Is the enclosure widescreen or standard?
|
||
958 | * This applies only to video enclosures, and will automatically resize
|
||
959 | * the content appropriately. Defaults to `false`, implying 4:3 mode.
|
||
960 | *
|
||
961 | * Note: Non-widescreen (4:3) mode with `width` and `height` set to `auto`
|
||
962 | * will default to 480x360 video resolution. Widescreen (16:9) mode with
|
||
963 | * `width` and `height` set to `auto` will default to 480x270 video resolution.
|
||
964 | *
|
||
965 | * @todo If the dimensions for media:content are defined, use them when width/height are set to 'auto'.
|
||
966 | * @param array|string $options Comma-separated key:value list, or array
|
||
967 | * @param bool $native Use `<embed>`
|
||
968 | * @return string HTML string to output
|
||
969 | */
|
||
970 | public function embed($options = '', $native = false) |
||
971 | { |
||
972 | // Set up defaults
|
||
973 | $audio = ''; |
||
974 | $video = ''; |
||
975 | $alt = ''; |
||
976 | $altclass = ''; |
||
977 | $loop = 'false'; |
||
978 | $width = 'auto'; |
||
979 | $height = 'auto'; |
||
980 | $bgcolor = '#ffffff'; |
||
981 | $mediaplayer = ''; |
||
982 | $widescreen = false; |
||
983 | $handler = $this->get_handler(); |
||
984 | $type = $this->get_real_type(); |
||
985 | |||
986 | // Process options and reassign values as necessary
|
||
987 | if (is_array($options)) |
||
988 | { |
||
989 | extract($options); |
||
990 | } |
||
991 | else
|
||
992 | { |
||
993 | $options = explode(',', $options); |
||
994 | foreach($options as $option) |
||
995 | { |
||
996 | $opt = explode(':', $option, 2); |
||
997 | if (isset($opt[0], $opt[1])) |
||
998 | { |
||
999 | $opt[0] = trim($opt[0]); |
||
1000 | $opt[1] = trim($opt[1]); |
||
1001 | switch ($opt[0]) |
||
1002 | { |
||
1003 | case 'audio': |
||
1004 | $audio = $opt[1]; |
||
1005 | break;
|
||
1006 | |||
1007 | case 'video': |
||
1008 | $video = $opt[1]; |
||
1009 | break;
|
||
1010 | |||
1011 | case 'alt': |
||
1012 | $alt = $opt[1]; |
||
1013 | break;
|
||
1014 | |||
1015 | case 'altclass': |
||
1016 | $altclass = $opt[1]; |
||
1017 | break;
|
||
1018 | |||
1019 | case 'loop': |
||
1020 | $loop = $opt[1]; |
||
1021 | break;
|
||
1022 | |||
1023 | case 'width': |
||
1024 | $width = $opt[1]; |
||
1025 | break;
|
||
1026 | |||
1027 | case 'height': |
||
1028 | $height = $opt[1]; |
||
1029 | break;
|
||
1030 | |||
1031 | case 'bgcolor': |
||
1032 | $bgcolor = $opt[1]; |
||
1033 | break;
|
||
1034 | |||
1035 | case 'mediaplayer': |
||
1036 | $mediaplayer = $opt[1]; |
||
1037 | break;
|
||
1038 | |||
1039 | case 'widescreen': |
||
1040 | $widescreen = $opt[1]; |
||
1041 | break;
|
||
1042 | } |
||
1043 | } |
||
1044 | } |
||
1045 | } |
||
1046 | |||
1047 | $mime = explode('/', $type, 2); |
||
1048 | $mime = $mime[0]; |
||
1049 | |||
1050 | // Process values for 'auto'
|
||
1051 | if ($width === 'auto') |
||
1052 | { |
||
1053 | if ($mime === 'video') |
||
1054 | { |
||
1055 | if ($height === 'auto') |
||
1056 | { |
||
1057 | $width = 480; |
||
1058 | } |
||
1059 | elseif ($widescreen) |
||
1060 | { |
||
1061 | $width = round((intval($height)/9)*16); |
||
1062 | } |
||
1063 | else
|
||
1064 | { |
||
1065 | $width = round((intval($height)/3)*4); |
||
1066 | } |
||
1067 | } |
||
1068 | else
|
||
1069 | { |
||
1070 | $width = '100%'; |
||
1071 | } |
||
1072 | } |
||
1073 | |||
1074 | if ($height === 'auto') |
||
1075 | { |
||
1076 | if ($mime === 'audio') |
||
1077 | { |
||
1078 | $height = 0; |
||
1079 | } |
||
1080 | elseif ($mime === 'video') |
||
1081 | { |
||
1082 | if ($width === 'auto') |
||
1083 | { |
||
1084 | if ($widescreen) |
||
1085 | { |
||
1086 | $height = 270; |
||
1087 | } |
||
1088 | else
|
||
1089 | { |
||
1090 | $height = 360; |
||
1091 | } |
||
1092 | } |
||
1093 | elseif ($widescreen) |
||
1094 | { |
||
1095 | $height = round((intval($width)/16)*9); |
||
1096 | } |
||
1097 | else
|
||
1098 | { |
||
1099 | $height = round((intval($width)/4)*3); |
||
1100 | } |
||
1101 | } |
||
1102 | else
|
||
1103 | { |
||
1104 | $height = 376; |
||
1105 | } |
||
1106 | } |
||
1107 | elseif ($mime === 'audio') |
||
1108 | { |
||
1109 | $height = 0; |
||
1110 | } |
||
1111 | |||
1112 | // Set proper placeholder value
|
||
1113 | if ($mime === 'audio') |
||
1114 | { |
||
1115 | $placeholder = $audio; |
||
1116 | } |
||
1117 | elseif ($mime === 'video') |
||
1118 | { |
||
1119 | $placeholder = $video; |
||
1120 | } |
||
1121 | |||
1122 | $embed = ''; |
||
1123 | |||
1124 | // Flash
|
||
1125 | if ($handler === 'flash') |
||
1126 | { |
||
1127 | if ($native) |
||
1128 | { |
||
1129 | $embed .= "<embed src=\"" . $this->get_link() . "\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"$type\" quality=\"high\" width=\"$width\" height=\"$height\" bgcolor=\"$bgcolor\" loop=\"$loop\"></embed>"; |
||
1130 | } |
||
1131 | else
|
||
1132 | { |
||
1133 | $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>"; |
||
1134 | } |
||
1135 | } |
||
1136 | |||
1137 | // Flash Media Player file types.
|
||
1138 | // Preferred handler for MP3 file types.
|
||
1139 | elseif ($handler === 'fmedia' || ($handler === 'mp3' && $mediaplayer !== '')) |
||
1140 | { |
||
1141 | $height += 20; |
||
1142 | if ($native) |
||
1143 | { |
||
1144 | $embed .= "<embed src=\"$mediaplayer\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" quality=\"high\" width=\"$width\" height=\"$height\" wmode=\"transparent\" flashvars=\"file=" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "&autostart=false&repeat=$loop&showdigits=true&showfsbutton=false\"></embed>"; |
||
1145 | } |
||
1146 | else
|
||
1147 | { |
||
1148 | $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>"; |
||
1149 | } |
||
1150 | } |
||
1151 | |||
1152 | // QuickTime 7 file types. Need to test with QuickTime 6.
|
||
1153 | // Only handle MP3's if the Flash Media Player is not present.
|
||
1154 | elseif ($handler === 'quicktime' || ($handler === 'mp3' && $mediaplayer === '')) |
||
1155 | { |
||
1156 | $height += 16; |
||
1157 | if ($native) |
||
1158 | { |
||
1159 | if ($placeholder !== '') |
||
1160 | { |
||
1161 | $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" href=\"" . $this->get_link() . "\" src=\"$placeholder\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"false\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>"; |
||
1162 | } |
||
1163 | else
|
||
1164 | { |
||
1165 | $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" src=\"" . $this->get_link() . "\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"true\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>"; |
||
1166 | } |
||
1167 | } |
||
1168 | else
|
||
1169 | { |
||
1170 | $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>"; |
||
1171 | } |
||
1172 | } |
||
1173 | |||
1174 | // Windows Media
|
||
1175 | elseif ($handler === 'wmedia') |
||
1176 | { |
||
1177 | $height += 45; |
||
1178 | if ($native) |
||
1179 | { |
||
1180 | $embed .= "<embed type=\"application/x-mplayer2\" src=\"" . $this->get_link() . "\" autosize=\"1\" width=\"$width\" height=\"$height\" showcontrols=\"1\" showstatusbar=\"0\" showdisplay=\"0\" autostart=\"0\"></embed>"; |
||
1181 | } |
||
1182 | else
|
||
1183 | { |
||
1184 | $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>"; |
||
1185 | } |
||
1186 | } |
||
1187 | |||
1188 | // Everything else
|
||
1189 | else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>'; |
||
1190 | |||
1191 | return $embed; |
||
1192 | } |
||
1193 | |||
1194 | /**
|
||
1195 | * Get the real media type
|
||
1196 | *
|
||
1197 | * Often, feeds lie to us, necessitating a bit of deeper inspection. This
|
||
1198 | * converts types to their canonical representations based on the file
|
||
1199 | * extension
|
||
1200 | *
|
||
1201 | * @see get_type()
|
||
1202 | * @param bool $find_handler Internal use only, use {@see get_handler()} instead
|
||
1203 | * @return string MIME type
|
||
1204 | */
|
||
1205 | public function get_real_type($find_handler = false) |
||
1206 | { |
||
1207 | // Mime-types by handler.
|
||
1208 | $types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash |
||
1209 | $types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player |
||
1210 | $types_quicktime = array('audio/3gpp', 'audio/3gpp2', 'audio/aac', 'audio/x-aac', 'audio/aiff', 'audio/x-aiff', 'audio/mid', 'audio/midi', 'audio/x-midi', 'audio/mp4', 'audio/m4a', 'audio/x-m4a', 'audio/wav', 'audio/x-wav', 'video/3gpp', 'video/3gpp2', 'video/m4v', 'video/x-m4v', 'video/mp4', 'video/mpeg', 'video/x-mpeg', 'video/quicktime', 'video/sd-video'); // QuickTime |
||
1211 | $types_wmedia = array('application/asx', 'application/x-mplayer2', 'audio/x-ms-wma', 'audio/x-ms-wax', 'video/x-ms-asf-plugin', 'video/x-ms-asf', 'video/x-ms-wm', 'video/x-ms-wmv', 'video/x-ms-wvx'); // Windows Media |
||
1212 | $types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3 |
||
1213 | |||
1214 | if ($this->get_type() !== null) |
||
1215 | { |
||
1216 | $type = strtolower($this->type); |
||
1217 | } |
||
1218 | else
|
||
1219 | { |
||
1220 | $type = null; |
||
1221 | } |
||
1222 | |||
1223 | // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
|
||
1224 | if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3))) |
||
1225 | { |
||
1226 | switch (strtolower($this->get_extension())) |
||
1227 | { |
||
1228 | // Audio mime-types
|
||
1229 | case 'aac': |
||
1230 | case 'adts': |
||
1231 | $type = 'audio/acc'; |
||
1232 | break;
|
||
1233 | |||
1234 | case 'aif': |
||
1235 | case 'aifc': |
||
1236 | case 'aiff': |
||
1237 | case 'cdda': |
||
1238 | $type = 'audio/aiff'; |
||
1239 | break;
|
||
1240 | |||
1241 | case 'bwf': |
||
1242 | $type = 'audio/wav'; |
||
1243 | break;
|
||
1244 | |||
1245 | case 'kar': |
||
1246 | case 'mid': |
||
1247 | case 'midi': |
||
1248 | case 'smf': |
||
1249 | $type = 'audio/midi'; |
||
1250 | break;
|
||
1251 | |||
1252 | case 'm4a': |
||
1253 | $type = 'audio/x-m4a'; |
||
1254 | break;
|
||
1255 | |||
1256 | case 'mp3': |
||
1257 | case 'swa': |
||
1258 | $type = 'audio/mp3'; |
||
1259 | break;
|
||
1260 | |||
1261 | case 'wav': |
||
1262 | $type = 'audio/wav'; |
||
1263 | break;
|
||
1264 | |||
1265 | case 'wax': |
||
1266 | $type = 'audio/x-ms-wax'; |
||
1267 | break;
|
||
1268 | |||
1269 | case 'wma': |
||
1270 | $type = 'audio/x-ms-wma'; |
||
1271 | break;
|
||
1272 | |||
1273 | // Video mime-types
|
||
1274 | case '3gp': |
||
1275 | case '3gpp': |
||
1276 | $type = 'video/3gpp'; |
||
1277 | break;
|
||
1278 | |||
1279 | case '3g2': |
||
1280 | case '3gp2': |
||
1281 | $type = 'video/3gpp2'; |
||
1282 | break;
|
||
1283 | |||
1284 | case 'asf': |
||
1285 | $type = 'video/x-ms-asf'; |
||
1286 | break;
|
||
1287 | |||
1288 | case 'flv': |
||
1289 | $type = 'video/x-flv'; |
||
1290 | break;
|
||
1291 | |||
1292 | case 'm1a': |
||
1293 | case 'm1s': |
||
1294 | case 'm1v': |
||
1295 | case 'm15': |
||
1296 | case 'm75': |
||
1297 | case 'mp2': |
||
1298 | case 'mpa': |
||
1299 | case 'mpeg': |
||
1300 | case 'mpg': |
||
1301 | case 'mpm': |
||
1302 | case 'mpv': |
||
1303 | $type = 'video/mpeg'; |
||
1304 | break;
|
||
1305 | |||
1306 | case 'm4v': |
||
1307 | $type = 'video/x-m4v'; |
||
1308 | break;
|
||
1309 | |||
1310 | case 'mov': |
||
1311 | case 'qt': |
||
1312 | $type = 'video/quicktime'; |
||
1313 | break;
|
||
1314 | |||
1315 | case 'mp4': |
||
1316 | case 'mpg4': |
||
1317 | $type = 'video/mp4'; |
||
1318 | break;
|
||
1319 | |||
1320 | case 'sdv': |
||
1321 | $type = 'video/sd-video'; |
||
1322 | break;
|
||
1323 | |||
1324 | case 'wm': |
||
1325 | $type = 'video/x-ms-wm'; |
||
1326 | break;
|
||
1327 | |||
1328 | case 'wmv': |
||
1329 | $type = 'video/x-ms-wmv'; |
||
1330 | break;
|
||
1331 | |||
1332 | case 'wvx': |
||
1333 | $type = 'video/x-ms-wvx'; |
||
1334 | break;
|
||
1335 | |||
1336 | // Flash mime-types
|
||
1337 | case 'spl': |
||
1338 | $type = 'application/futuresplash'; |
||
1339 | break;
|
||
1340 | |||
1341 | case 'swf': |
||
1342 | $type = 'application/x-shockwave-flash'; |
||
1343 | break;
|
||
1344 | } |
||
1345 | } |
||
1346 | |||
1347 | if ($find_handler) |
||
1348 | { |
||
1349 | if (in_array($type, $types_flash)) |
||
1350 | { |
||
1351 | return 'flash'; |
||
1352 | } |
||
1353 | elseif (in_array($type, $types_fmedia)) |
||
1354 | { |
||
1355 | return 'fmedia'; |
||
1356 | } |
||
1357 | elseif (in_array($type, $types_quicktime)) |
||
1358 | { |
||
1359 | return 'quicktime'; |
||
1360 | } |
||
1361 | elseif (in_array($type, $types_wmedia)) |
||
1362 | { |
||
1363 | return 'wmedia'; |
||
1364 | } |
||
1365 | elseif (in_array($type, $types_mp3)) |
||
1366 | { |
||
1367 | return 'mp3'; |
||
1368 | } |
||
1369 | else
|
||
1370 | { |
||
1371 | return null; |
||
1372 | } |
||
1373 | } |
||
1374 | else
|
||
1375 | { |
||
1376 | return $type; |
||
1377 | } |
||
1378 | } |
||
1379 | } |