]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/simplepie/library/SimplePie/Enclosure.php
5 * A PHP-Based RSS and Atom Feed Framework.
6 * Takes the hard work out of managing a complete RSS/Atom solution.
8 * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
11 * Redistribution and use in source and binary forms, with or without modification, are
12 * permitted provided that the following conditions are met:
14 * * Redistributions of source code must retain the above copyright notice, this list of
15 * conditions and the following disclaimer.
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.
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
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.
37 * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
39 * @author Geoffrey Sneddon
41 * @link http://simplepie.org/ SimplePie
42 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 * Handles everything related to enclosures (including Media RSS and iTunes RSS)
48 * Used by {@see SimplePie_Item::get_enclosure()} and {@see SimplePie_Item::get_enclosures()}
50 * This class can be overloaded with {@see SimplePie::set_enclosure_class()}
55 class SimplePie_Enclosure
71 * @see get_categories()
82 * @var SimplePie_Copyright
83 * @see get_copyright()
95 * @see get_description()
101 * @see get_duration()
107 * @see get_expression()
113 * @see get_framerate()
143 * @see get_keywords()
149 * @see get_language()
185 * @see get_restrictions()
191 * @see get_sampling_rate()
197 * @see get_thumbnails()
220 * Constructor, used to input the data
222 * For documentation on all the parameters, see the corresponding
223 * properties and their accessors
225 * @uses idna_convert If available, this will convert an IDN
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 )
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 ;
243 $this- > length
= $length ;
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 ;
253 $this- > width
= $width ;
255 if ( class_exists ( 'idna_convert' ))
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' ]);
261 $this- > handler
= $this- > get_handler (); // Needs to load last
265 * String-ified version
269 public function __toString ()
271 // There is no $this->data here
272 return md5 ( serialize ( $this ));
278 * @return string|null
280 public function get_bitrate ()
282 if ( $this- > bitrate
!== null )
284 return $this- > bitrate
;
293 * Get a single caption
296 * @return SimplePie_Caption|null
298 public function get_caption ( $key = 0 )
300 $captions = $this- > get_captions ();
301 if ( isset ( $captions [ $key ]))
303 return $captions [ $key ];
314 * @return array|null Array of {@see SimplePie_Caption} objects
316 public function get_captions ()
318 if ( $this- > captions
!== null )
320 return $this- > captions
;
329 * Get a single category
332 * @return SimplePie_Category|null
334 public function get_category ( $key = 0 )
336 $categories = $this- > get_categories ();
337 if ( isset ( $categories [ $key ]))
339 return $categories [ $key ];
350 * @return array|null Array of {@see SimplePie_Category} objects
352 public function get_categories ()
354 if ( $this- > categories
!== null )
356 return $this- > categories
;
365 * Get the number of audio channels
369 public function get_channels ()
371 if ( $this- > channels
!== null )
373 return $this- > channels
;
382 * Get the copyright information
384 * @return SimplePie_Copyright|null
386 public function get_copyright ()
388 if ( $this- > copyright
!== null )
390 return $this- > copyright
;
399 * Get a single credit
402 * @return SimplePie_Credit|null
404 public function get_credit ( $key = 0 )
406 $credits = $this- > get_credits ();
407 if ( isset ( $credits [ $key ]))
409 return $credits [ $key ];
420 * @return array|null Array of {@see SimplePie_Credit} objects
422 public function get_credits ()
424 if ( $this- > credits
!== null )
426 return $this- > credits
;
435 * Get the description of the enclosure
437 * @return string|null
439 public function get_description ()
441 if ( $this- > description
!== null )
443 return $this- > description
;
452 * Get the duration of the enclosure
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)
457 public function get_duration ( $convert = false )
459 if ( $this- > duration
!== null )
463 $time = SimplePie_Misc
:: time_hms ( $this- > duration
);
468 return $this- > duration
;
480 * @return string Probably one of 'sample', 'full', 'nonstop', 'clip'. Defaults to 'full'
482 public function get_expression ()
484 if ( $this- > expression
!== null )
486 return $this- > expression
;
495 * Get the file extension
497 * @return string|null
499 public function get_extension ()
501 if ( $this- > link
!== null )
503 $url = SimplePie_Misc
:: parse_url ( $this- > link
);
504 if ( $url [ 'path' ] !== '' )
506 return pathinfo ( $url [ 'path' ], PATHINFO_EXTENSION
);
513 * Get the framerate (in frames-per-second)
515 * @return string|null
517 public function get_framerate ()
519 if ( $this- > framerate
!== null )
521 return $this- > framerate
;
530 * Get the preferred handler
532 * @return string|null One of 'flash', 'fmedia', 'quicktime', 'wmedia', 'mp3'
534 public function get_handler ()
536 return $this- > get_real_type ( true );
542 * @link http://www.rssboard.org/media-rss#media-hash
544 * @return string|null Hash as per `media:hash`, prefixed with "$algo:"
546 public function get_hash ( $key = 0 )
548 $hashes = $this- > get_hashes ();
549 if ( isset ( $hashes [ $key ]))
551 return $hashes [ $key ];
562 * @return array|null Array of strings, see {@see get_hash()}
564 public function get_hashes ()
566 if ( $this- > hashes
!== null )
568 return $this- > hashes
;
579 * @return string|null
581 public function get_height ()
583 if ( $this- > height
!== null )
585 return $this- > height
;
596 * @link http://tools.ietf.org/html/rfc3066
597 * @return string|null Language code as per RFC 3066
599 public function get_language ()
601 if ( $this- > lang
!== null )
612 * Get a single keyword
615 * @return string|null
617 public function get_keyword ( $key = 0 )
619 $keywords = $this- > get_keywords ();
620 if ( isset ( $keywords [ $key ]))
622 return $keywords [ $key ];
633 * @return array|null Array of strings
635 public function get_keywords ()
637 if ( $this- > keywords
!== null )
639 return $this- > keywords
;
650 * @return float Length in bytes
652 public function get_length ()
654 if ( $this- > length
!== null )
656 return $this- > length
;
667 * @return string|null
669 public function get_link ()
671 if ( $this- > link
!== null )
673 return urldecode ( $this- > link
);
684 * @link http://www.rssboard.org/media-rss#media-content
685 * @return string|null Should be one of 'image', 'audio', 'video', 'document', 'executable'
687 public function get_medium ()
689 if ( $this- > medium
!== null )
691 return $this- > medium
;
702 * Typically the same as {@see get_permalink()}
703 * @return string|null Player URL
705 public function get_player ()
707 if ( $this- > player
!== null )
709 return $this- > player
;
718 * Get a single rating
721 * @return SimplePie_Rating|null
723 public function get_rating ( $key = 0 )
725 $ratings = $this- > get_ratings ();
726 if ( isset ( $ratings [ $key ]))
728 return $ratings [ $key ];
739 * @return array|null Array of {@see SimplePie_Rating} objects
741 public function get_ratings ()
743 if ( $this- > ratings
!== null )
745 return $this- > ratings
;
754 * Get a single restriction
757 * @return SimplePie_Restriction|null
759 public function get_restriction ( $key = 0 )
761 $restrictions = $this- > get_restrictions ();
762 if ( isset ( $restrictions [ $key ]))
764 return $restrictions [ $key ];
773 * Get all restrictions
775 * @return array|null Array of {@see SimplePie_Restriction} objects
777 public function get_restrictions ()
779 if ( $this- > restrictions
!== null )
781 return $this- > restrictions
;
790 * Get the sampling rate (in kHz)
792 * @return string|null
794 public function get_sampling_rate ()
796 if ( $this- > samplingrate
!== null )
798 return $this- > samplingrate
;
807 * Get the file size (in MiB)
809 * @return float|null File size in mebibytes (1048 bytes)
811 public function get_size ()
813 $length = $this- > get_length ();
814 if ( $length !== null )
816 return round ( $length / 1048576 , 2 );
825 * Get a single thumbnail
828 * @return string|null Thumbnail URL
830 public function get_thumbnail ( $key = 0 )
832 $thumbnails = $this- > get_thumbnails ();
833 if ( isset ( $thumbnails [ $key ]))
835 return $thumbnails [ $key ];
846 * @return array|null Array of thumbnail URLs
848 public function get_thumbnails ()
850 if ( $this- > thumbnails
!== null )
852 return $this- > thumbnails
;
863 * @return string|null
865 public function get_title ()
867 if ( $this- > title
!== null )
878 * Get mimetype of the enclosure
880 * @see get_real_type()
881 * @return string|null MIME type
883 public function get_type ()
885 if ( $this- > type
!== null )
898 * @return string|null
900 public function get_width ()
902 if ( $this- > width
!== null )
913 * Embed the enclosure using `<embed>`
915 * @deprecated Use the second parameter to {@see embed} instead
917 * @param array|string $options See first paramter to {@see embed}
918 * @return string HTML string to output
920 public function native_embed ( $options = '' )
922 return $this- > embed ( $options , true );
926 * Embed the enclosure using Javascript
928 * `$options` is an array or comma-separated key:value string, with the
929 * following properties:
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.
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.
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.
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
970 public function embed ( $options = '' , $native = false )
980 $bgcolor = '#ffffff' ;
983 $handler = $this- > get_handler ();
984 $type = $this- > get_real_type ();
986 // Process options and reassign values as necessary
987 if ( is_array ( $options ))
993 $options = explode ( ',' , $options );
994 foreach ( $options as $option )
996 $opt = explode ( ':' , $option , 2 );
997 if ( isset ( $opt [ 0 ], $opt [ 1 ]))
999 $opt [ 0 ] = trim ( $opt [ 0 ]);
1000 $opt [ 1 ] = trim ( $opt [ 1 ]);
1016 $altclass = $opt [ 1 ];
1036 $mediaplayer = $opt [ 1 ];
1040 $widescreen = $opt [ 1 ];
1047 $mime = explode ( '/' , $type , 2 );
1050 // Process values for 'auto'
1051 if ( $width === 'auto' )
1053 if ( $mime === 'video' )
1055 if ( $height === 'auto' )
1059 elseif ( $widescreen )
1061 $width = round (( intval ( $height )/ 9 )* 16 );
1065 $width = round (( intval ( $height )/ 3 )* 4 );
1074 if ( $height === 'auto' )
1076 if ( $mime === 'audio' )
1080 elseif ( $mime === 'video' )
1082 if ( $width === 'auto' )
1093 elseif ( $widescreen )
1095 $height = round (( intval ( $width )/ 16 )* 9 );
1099 $height = round (( intval ( $width )/ 4 )* 3 );
1107 elseif ( $mime === 'audio' )
1112 // Set proper placeholder value
1113 if ( $mime === 'audio' )
1115 $placeholder = $audio ;
1117 elseif ( $mime === 'video' )
1119 $placeholder = $video ;
1125 if ( $handler === 'flash' )
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>" ;
1133 $embed .= "<script type='text/javascript'>embed_flash(' $bgcolor' , ' $width' , ' $height' , '" . $this- > get_link () . "', ' $loop' , ' $type' );</script>" ;
1137 // Flash Media Player file types.
1138 // Preferred handler for MP3 file types.
1139 elseif ( $handler === 'fmedia' || ( $handler === 'mp3' && $mediaplayer !== '' ))
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>" ;
1148 $embed .= "<script type='text/javascript'>embed_flv(' $width' , ' $height' , '" . rawurlencode ( $this- > get_link (). '?file_extension=.' . $this- > get_extension ()) . "', ' $placeholder' , ' $loop' , ' $mediaplayer' );</script>" ;
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 === '' ))
1159 if ( $placeholder !== '' )
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>" ;
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>" ;
1170 $embed .= "<script type='text/javascript'>embed_quicktime(' $type' , ' $bgcolor' , ' $width' , ' $height' , '" . $this- > get_link () . "', ' $placeholder' , ' $loop' );</script>" ;
1175 elseif ( $handler === 'wmedia' )
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>" ;
1184 $embed .= "<script type='text/javascript'>embed_wmedia(' $width' , ' $height' , '" . $this- > get_link () . "');</script>" ;
1189 else $embed .= '<a href="' . $this- > get_link () . '" class="' . $altclass . '">' . $alt . '</a>' ;
1195 * Get the real media type
1197 * Often, feeds lie to us, necessitating a bit of deeper inspection. This
1198 * converts types to their canonical representations based on the file
1202 * @param bool $find_handler Internal use only, use {@see get_handler()} instead
1203 * @return string MIME type
1205 public function get_real_type ( $find_handler = false )
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
1214 if ( $this- > get_type () !== null )
1216 $type = strtolower ( $this- > type
);
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 )))
1226 switch ( strtolower ( $this- > get_extension ()))
1231 $type = 'audio/acc' ;
1238 $type = 'audio/aiff' ;
1242 $type = 'audio/wav' ;
1249 $type = 'audio/midi' ;
1253 $type = 'audio/x-m4a' ;
1258 $type = 'audio/mp3' ;
1262 $type = 'audio/wav' ;
1266 $type = 'audio/x-ms-wax' ;
1270 $type = 'audio/x-ms-wma' ;
1276 $type = 'video/3gpp' ;
1281 $type = 'video/3gpp2' ;
1285 $type = 'video/x-ms-asf' ;
1289 $type = 'video/x-flv' ;
1303 $type = 'video/mpeg' ;
1307 $type = 'video/x-m4v' ;
1312 $type = 'video/quicktime' ;
1317 $type = 'video/mp4' ;
1321 $type = 'video/sd-video' ;
1325 $type = 'video/x-ms-wm' ;
1329 $type = 'video/x-ms-wmv' ;
1333 $type = 'video/x-ms-wvx' ;
1338 $type = 'application/futuresplash' ;
1342 $type = 'application/x-shockwave-flash' ;
1349 if ( in_array ( $type , $types_flash ))
1353 elseif ( in_array ( $type , $types_fmedia ))
1357 elseif ( in_array ( $type , $types_quicktime ))
1361 elseif ( in_array ( $type , $types_wmedia ))
1365 elseif ( in_array ( $type , $types_mp3 ))