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