]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/simplepie/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-2009, 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-2010 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
43 * @todo phpDoc comments
47 class SimplePie_Enclosure
77 // Constructor, used to input the data
78 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 )
80 $this- > bitrate
= $bitrate ;
81 $this- > captions
= $captions ;
82 $this- > categories
= $categories ;
83 $this- > channels
= $channels ;
84 $this- > copyright
= $copyright ;
85 $this- > credits
= $credits ;
86 $this- > description
= $description ;
87 $this- > duration
= $duration ;
88 $this- > expression
= $expression ;
89 $this- > framerate
= $framerate ;
90 $this- > hashes
= $hashes ;
91 $this- > height
= $height ;
92 $this- > keywords
= $keywords ;
94 $this- > length
= $length ;
96 $this- > medium
= $medium ;
97 $this- > player
= $player ;
98 $this- > ratings
= $ratings ;
99 $this- > restrictions
= $restrictions ;
100 $this- > samplingrate
= $samplingrate ;
101 $this- > thumbnails
= $thumbnails ;
102 $this- > title
= $title ;
104 $this- > width
= $width ;
106 if ( class_exists ( 'idna_convert' ))
108 $idn = new idna_convert ();
109 $parsed = SimplePie_Misc
:: parse_url ( $link );
110 $this- > link
= SimplePie_Misc
:: compress_parse_url ( $parsed [ 'scheme' ], $idn- > encode ( $parsed [ 'authority' ]), $parsed [ 'path' ], $parsed [ 'query' ], $parsed [ 'fragment' ]);
112 $this- > handler
= $this- > get_handler (); // Needs to load last
115 public function __toString ()
117 // There is no $this->data here
118 return md5 ( serialize ( $this ));
121 public function get_bitrate ()
123 if ( $this- > bitrate
!== null )
125 return $this- > bitrate
;
133 public function get_caption ( $key = 0 )
135 $captions = $this- > get_captions ();
136 if ( isset ( $captions [ $key ]))
138 return $captions [ $key ];
146 public function get_captions ()
148 if ( $this- > captions
!== null )
150 return $this- > captions
;
158 public function get_category ( $key = 0 )
160 $categories = $this- > get_categories ();
161 if ( isset ( $categories [ $key ]))
163 return $categories [ $key ];
171 public function get_categories ()
173 if ( $this- > categories
!== null )
175 return $this- > categories
;
183 public function get_channels ()
185 if ( $this- > channels
!== null )
187 return $this- > channels
;
195 public function get_copyright ()
197 if ( $this- > copyright
!== null )
199 return $this- > copyright
;
207 public function get_credit ( $key = 0 )
209 $credits = $this- > get_credits ();
210 if ( isset ( $credits [ $key ]))
212 return $credits [ $key ];
220 public function get_credits ()
222 if ( $this- > credits
!== null )
224 return $this- > credits
;
232 public function get_description ()
234 if ( $this- > description
!== null )
236 return $this- > description
;
244 public function get_duration ( $convert = false )
246 if ( $this- > duration
!== null )
250 $time = SimplePie_Misc
:: time_hms ( $this- > duration
);
255 return $this- > duration
;
264 public function get_expression ()
266 if ( $this- > expression
!== null )
268 return $this- > expression
;
276 public function get_extension ()
278 if ( $this- > link
!== null )
280 $url = SimplePie_Misc
:: parse_url ( $this- > link
);
281 if ( $url [ 'path' ] !== '' )
283 return pathinfo ( $url [ 'path' ], PATHINFO_EXTENSION
);
289 public function get_framerate ()
291 if ( $this- > framerate
!== null )
293 return $this- > framerate
;
301 public function get_handler ()
303 return $this- > get_real_type ( true );
306 public function get_hash ( $key = 0 )
308 $hashes = $this- > get_hashes ();
309 if ( isset ( $hashes [ $key ]))
311 return $hashes [ $key ];
319 public function get_hashes ()
321 if ( $this- > hashes
!== null )
323 return $this- > hashes
;
331 public function get_height ()
333 if ( $this- > height
!== null )
335 return $this- > height
;
343 public function get_language ()
345 if ( $this- > lang
!== null )
355 public function get_keyword ( $key = 0 )
357 $keywords = $this- > get_keywords ();
358 if ( isset ( $keywords [ $key ]))
360 return $keywords [ $key ];
368 public function get_keywords ()
370 if ( $this- > keywords
!== null )
372 return $this- > keywords
;
380 public function get_length ()
382 if ( $this- > length
!== null )
384 return $this- > length
;
392 public function get_link ()
394 if ( $this- > link
!== null )
396 return urldecode ( $this- > link
);
404 public function get_medium ()
406 if ( $this- > medium
!== null )
408 return $this- > medium
;
416 public function get_player ()
418 if ( $this- > player
!== null )
420 return $this- > player
;
428 public function get_rating ( $key = 0 )
430 $ratings = $this- > get_ratings ();
431 if ( isset ( $ratings [ $key ]))
433 return $ratings [ $key ];
441 public function get_ratings ()
443 if ( $this- > ratings
!== null )
445 return $this- > ratings
;
453 public function get_restriction ( $key = 0 )
455 $restrictions = $this- > get_restrictions ();
456 if ( isset ( $restrictions [ $key ]))
458 return $restrictions [ $key ];
466 public function get_restrictions ()
468 if ( $this- > restrictions
!== null )
470 return $this- > restrictions
;
478 public function get_sampling_rate ()
480 if ( $this- > samplingrate
!== null )
482 return $this- > samplingrate
;
490 public function get_size ()
492 $length = $this- > get_length ();
493 if ( $length !== null )
495 return round ( $length / 1048576 , 2 );
503 public function get_thumbnail ( $key = 0 )
505 $thumbnails = $this- > get_thumbnails ();
506 if ( isset ( $thumbnails [ $key ]))
508 return $thumbnails [ $key ];
516 public function get_thumbnails ()
518 if ( $this- > thumbnails
!== null )
520 return $this- > thumbnails
;
528 public function get_title ()
530 if ( $this- > title
!== null )
540 public function get_type ()
542 if ( $this- > type
!== null )
552 public function get_width ()
554 if ( $this- > width
!== null )
564 public function native_embed ( $options = '' )
566 return $this- > embed ( $options , true );
570 * @todo If the dimensions for media:content are defined, use them when width/height are set to 'auto'.
572 public function embed ( $options = '' , $native = false )
582 $bgcolor = '#ffffff' ;
585 $handler = $this- > get_handler ();
586 $type = $this- > get_real_type ();
588 // Process options and reassign values as necessary
589 if ( is_array ( $options ))
595 $options = explode ( ',' , $options );
596 foreach ( $options as $option )
598 $opt = explode ( ':' , $option , 2 );
599 if ( isset ( $opt [ 0 ], $opt [ 1 ]))
601 $opt [ 0 ] = trim ( $opt [ 0 ]);
602 $opt [ 1 ] = trim ( $opt [ 1 ]);
638 $mediaplayer = $opt [ 1 ];
642 $widescreen = $opt [ 1 ];
649 $mime = explode ( '/' , $type , 2 );
652 // Process values for 'auto'
653 if ( $width === 'auto' )
655 if ( $mime === 'video' )
657 if ( $height === 'auto' )
663 $width = round (( intval ( $height )/ 9 )* 16 );
667 $width = round (( intval ( $height )/ 3 )* 4 );
676 if ( $height === 'auto' )
678 if ( $mime === 'audio' )
682 elseif ( $mime === 'video' )
684 if ( $width === 'auto' )
697 $height = round (( intval ( $width )/ 16 )* 9 );
701 $height = round (( intval ( $width )/ 4 )* 3 );
709 elseif ( $mime === 'audio' )
714 // Set proper placeholder value
715 if ( $mime === 'audio' )
717 $placeholder = $audio ;
719 elseif ( $mime === 'video' )
721 $placeholder = $video ;
727 if ( $handler === 'odeo' )
731 $embed .= '<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://adobe.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url=' . $this- > get_link () . '"></embed>' ;
735 $embed .= '<script type="text/javascript">embed_odeo("' . $this- > get_link () . '");</script>' ;
740 elseif ( $handler === 'flash' )
744 $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>" ;
748 $embed .= "<script type='text/javascript'>embed_flash(' $bgcolor' , ' $width' , ' $height' , '" . $this- > get_link () . "', ' $loop' , ' $type' );</script>" ;
752 // Flash Media Player file types.
753 // Preferred handler for MP3 file types.
754 elseif ( $handler === 'fmedia' || ( $handler === 'mp3' && $mediaplayer !== '' ))
759 $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>" ;
763 $embed .= "<script type='text/javascript'>embed_flv(' $width' , ' $height' , '" . rawurlencode ( $this- > get_link (). '?file_extension=.' . $this- > get_extension ()) . "', ' $placeholder' , ' $loop' , ' $mediaplayer' );</script>" ;
767 // QuickTime 7 file types. Need to test with QuickTime 6.
768 // Only handle MP3's if the Flash Media Player is not present.
769 elseif ( $handler === 'quicktime' || ( $handler === 'mp3' && $mediaplayer === '' ))
774 if ( $placeholder !== '' )
776 $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>" ;
780 $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>" ;
785 $embed .= "<script type='text/javascript'>embed_quicktime(' $type' , ' $bgcolor' , ' $width' , ' $height' , '" . $this- > get_link () . "', ' $placeholder' , ' $loop' );</script>" ;
790 elseif ( $handler === 'wmedia' )
795 $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>" ;
799 $embed .= "<script type='text/javascript'>embed_wmedia(' $width' , ' $height' , '" . $this- > get_link () . "');</script>" ;
804 else $embed .= '<a href="' . $this- > get_link () . '" class="' . $altclass . '">' . $alt . '</a>' ;
809 public function get_real_type ( $find_handler = false )
811 // If it's Odeo, let's get it out of the way.
812 if ( substr ( strtolower ( $this- > get_link ()), 0 , 15 ) === 'http://odeo.com' )
817 // Mime-types by handler.
818 $types_flash = array ( 'application/x-shockwave-flash' , 'application/futuresplash' ); // Flash
819 $types_fmedia = array ( 'video/flv' , 'video/x-flv' , 'flv-application/octet-stream' ); // Flash Media Player
820 $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
821 $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
822 $types_mp3 = array ( 'audio/mp3' , 'audio/x-mp3' , 'audio/mpeg' , 'audio/x-mpeg' ); // MP3
824 if ( $this- > get_type () !== null )
826 $type = strtolower ( $this- > type
);
833 // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
834 if (! in_array ( $type , array_merge ( $types_flash , $types_fmedia , $types_quicktime , $types_wmedia , $types_mp3 )))
836 switch ( strtolower ( $this- > get_extension ()))
848 $type = 'audio/aiff' ;
859 $type = 'audio/midi' ;
863 $type = 'audio/x-m4a' ;
876 $type = 'audio/x-ms-wax' ;
880 $type = 'audio/x-ms-wma' ;
886 $type = 'video/3gpp' ;
891 $type = 'video/3gpp2' ;
895 $type = 'video/x-ms-asf' ;
899 $type = 'video/x-flv' ;
913 $type = 'video/mpeg' ;
917 $type = 'video/x-m4v' ;
922 $type = 'video/quicktime' ;
931 $type = 'video/sd-video' ;
935 $type = 'video/x-ms-wm' ;
939 $type = 'video/x-ms-wmv' ;
943 $type = 'video/x-ms-wvx' ;
948 $type = 'application/futuresplash' ;
952 $type = 'application/x-shockwave-flash' ;
959 if ( in_array ( $type , $types_flash ))
963 elseif ( in_array ( $type , $types_fmedia ))
967 elseif ( in_array ( $type , $types_quicktime ))
971 elseif ( in_array ( $type , $types_wmedia ))
975 elseif ( in_array ( $type , $types_mp3 ))