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