wip
This commit is contained in:
@@ -1,46 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Sam Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
// SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SimplePie;
|
||||
|
||||
@@ -50,86 +13,83 @@ namespace SimplePie;
|
||||
* Used by {@see \SimplePie\Item::get_enclosure()} and {@see \SimplePie\Item::get_enclosures()}
|
||||
*
|
||||
* This class can be overloaded with {@see \SimplePie\SimplePie::set_enclosure_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class Enclosure
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_bitrate()
|
||||
*/
|
||||
public $bitrate;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @var Caption[]|null
|
||||
* @see get_captions()
|
||||
*/
|
||||
public $captions;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @var Category[]|null
|
||||
* @see get_categories()
|
||||
*/
|
||||
public $categories;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @var ?int
|
||||
* @see get_channels()
|
||||
*/
|
||||
public $channels;
|
||||
|
||||
/**
|
||||
* @var \SimplePie\Copyright
|
||||
* @var ?Copyright
|
||||
* @see get_copyright()
|
||||
*/
|
||||
public $copyright;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @var Credit[]|null
|
||||
* @see get_credits()
|
||||
*/
|
||||
public $credits;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_description()
|
||||
*/
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @var ?int
|
||||
* @see get_duration()
|
||||
*/
|
||||
public $duration;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_expression()
|
||||
*/
|
||||
public $expression;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_framerate()
|
||||
*/
|
||||
public $framerate;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_handler()
|
||||
*/
|
||||
public $handler;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @var string[]|null
|
||||
* @see get_hashes()
|
||||
*/
|
||||
public $hashes;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_height()
|
||||
*/
|
||||
public $height;
|
||||
@@ -141,79 +101,79 @@ class Enclosure
|
||||
public $javascript;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @var string[]|null
|
||||
* @see get_keywords()
|
||||
*/
|
||||
public $keywords;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_language()
|
||||
*/
|
||||
public $lang;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?int
|
||||
* @see get_length()
|
||||
*/
|
||||
public $length;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_link()
|
||||
*/
|
||||
public $link;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_medium()
|
||||
*/
|
||||
public $medium;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_player()
|
||||
*/
|
||||
public $player;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @var Rating[]|null
|
||||
* @see get_ratings()
|
||||
*/
|
||||
public $ratings;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @var ?Restriction[]
|
||||
* @see get_restrictions()
|
||||
*/
|
||||
public $restrictions;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_sampling_rate()
|
||||
*/
|
||||
public $samplingrate;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @var string[]|null
|
||||
* @see get_thumbnails()
|
||||
*/
|
||||
public $thumbnails;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_title()
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_type()
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var ?string
|
||||
* @see get_width()
|
||||
*/
|
||||
public $width;
|
||||
@@ -224,10 +184,46 @@ class Enclosure
|
||||
* For documentation on all the parameters, see the corresponding
|
||||
* properties and their accessors
|
||||
*
|
||||
* @uses idna_convert If available, this will convert an IDN
|
||||
* @uses idn_to_ascii If available, this will convert an IDN
|
||||
*
|
||||
* @param null $javascript
|
||||
* @param Caption[]|null $captions
|
||||
* @param Category[]|null $categories
|
||||
* @param Credit[]|null $credits
|
||||
* @param string[]|null $hashes
|
||||
* @param string[]|null $keywords
|
||||
* @param Rating[]|null $ratings
|
||||
* @param Restriction[]|null $restrictions
|
||||
* @param string[]|null $thumbnails
|
||||
*/
|
||||
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)
|
||||
{
|
||||
public function __construct(
|
||||
?string $link = null,
|
||||
?string $type = null,
|
||||
?int $length = null,
|
||||
$javascript = null,
|
||||
?string $bitrate = null,
|
||||
?array $captions = null,
|
||||
?array $categories = null,
|
||||
?int $channels = null,
|
||||
?Copyright $copyright = null,
|
||||
?array $credits = null,
|
||||
?string $description = null,
|
||||
?int $duration = null,
|
||||
?string $expression = null,
|
||||
?string $framerate = null,
|
||||
?array $hashes = null,
|
||||
?string $height = null,
|
||||
?array $keywords = null,
|
||||
?string $lang = null,
|
||||
?string $medium = null,
|
||||
?string $player = null,
|
||||
?array $ratings = null,
|
||||
?array $restrictions = null,
|
||||
?string $samplingrate = null,
|
||||
?array $thumbnails = null,
|
||||
?string $title = null,
|
||||
?string $width = null
|
||||
) {
|
||||
$this->bitrate = $bitrate;
|
||||
$this->captions = $captions;
|
||||
$this->categories = $categories;
|
||||
@@ -254,10 +250,12 @@ class Enclosure
|
||||
$this->type = $type;
|
||||
$this->width = $width;
|
||||
|
||||
if (class_exists('idna_convert')) {
|
||||
$idn = new \idna_convert();
|
||||
$parsed = \SimplePie\Misc::parse_url($link);
|
||||
$this->link = \SimplePie\Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
|
||||
if (function_exists('idn_to_ascii')) {
|
||||
$parsed = \SimplePie\Misc::parse_url($link ?? '');
|
||||
if ($parsed['authority'] !== '' && !ctype_print($parsed['authority'])) {
|
||||
$authority = (string) \idn_to_ascii($parsed['authority'], \IDNA_NONTRANSITIONAL_TO_ASCII, \INTL_IDNA_VARIANT_UTS46);
|
||||
$this->link = \SimplePie\Misc::compress_parse_url($parsed['scheme'], $authority, $parsed['path'], $parsed['query'], $parsed['fragment']);
|
||||
}
|
||||
}
|
||||
$this->handler = $this->get_handler(); // Needs to load last
|
||||
}
|
||||
@@ -293,7 +291,7 @@ class Enclosure
|
||||
* @param int $key
|
||||
* @return \SimplePie\Caption|null
|
||||
*/
|
||||
public function get_caption($key = 0)
|
||||
public function get_caption(int $key = 0)
|
||||
{
|
||||
$captions = $this->get_captions();
|
||||
if (isset($captions[$key])) {
|
||||
@@ -306,7 +304,7 @@ class Enclosure
|
||||
/**
|
||||
* Get all captions
|
||||
*
|
||||
* @return array|null Array of {@see \SimplePie\Caption} objects
|
||||
* @return Caption[]|null
|
||||
*/
|
||||
public function get_captions()
|
||||
{
|
||||
@@ -323,7 +321,7 @@ class Enclosure
|
||||
* @param int $key
|
||||
* @return \SimplePie\Category|null
|
||||
*/
|
||||
public function get_category($key = 0)
|
||||
public function get_category(int $key = 0)
|
||||
{
|
||||
$categories = $this->get_categories();
|
||||
if (isset($categories[$key])) {
|
||||
@@ -336,7 +334,7 @@ class Enclosure
|
||||
/**
|
||||
* Get all categories
|
||||
*
|
||||
* @return array|null Array of {@see \SimplePie\Category} objects
|
||||
* @return \SimplePie\Category[]|null
|
||||
*/
|
||||
public function get_categories()
|
||||
{
|
||||
@@ -381,7 +379,7 @@ class Enclosure
|
||||
* @param int $key
|
||||
* @return \SimplePie\Credit|null
|
||||
*/
|
||||
public function get_credit($key = 0)
|
||||
public function get_credit(int $key = 0)
|
||||
{
|
||||
$credits = $this->get_credits();
|
||||
if (isset($credits[$key])) {
|
||||
@@ -394,7 +392,7 @@ class Enclosure
|
||||
/**
|
||||
* Get all credits
|
||||
*
|
||||
* @return array|null Array of {@see \SimplePie\Credit} objects
|
||||
* @return Credit[]|null
|
||||
*/
|
||||
public function get_credits()
|
||||
{
|
||||
@@ -425,7 +423,7 @@ class Enclosure
|
||||
* @param bool $convert Convert seconds into hh:mm:ss
|
||||
* @return string|int|null 'hh:mm:ss' string if `$convert` was specified, otherwise integer (or null if none found)
|
||||
*/
|
||||
public function get_duration($convert = false)
|
||||
public function get_duration(bool $convert = false)
|
||||
{
|
||||
if ($this->duration !== null) {
|
||||
if ($convert) {
|
||||
@@ -500,7 +498,7 @@ class Enclosure
|
||||
* @param int $key
|
||||
* @return string|null Hash as per `media:hash`, prefixed with "$algo:"
|
||||
*/
|
||||
public function get_hash($key = 0)
|
||||
public function get_hash(int $key = 0)
|
||||
{
|
||||
$hashes = $this->get_hashes();
|
||||
if (isset($hashes[$key])) {
|
||||
@@ -513,7 +511,7 @@ class Enclosure
|
||||
/**
|
||||
* Get all credits
|
||||
*
|
||||
* @return array|null Array of strings, see {@see get_hash()}
|
||||
* @return string[]|null Array of strings, see {@see get_hash()}
|
||||
*/
|
||||
public function get_hashes()
|
||||
{
|
||||
@@ -559,7 +557,7 @@ class Enclosure
|
||||
* @param int $key
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_keyword($key = 0)
|
||||
public function get_keyword(int $key = 0)
|
||||
{
|
||||
$keywords = $this->get_keywords();
|
||||
if (isset($keywords[$key])) {
|
||||
@@ -572,7 +570,7 @@ class Enclosure
|
||||
/**
|
||||
* Get all keywords
|
||||
*
|
||||
* @return array|null Array of strings
|
||||
* @return string[]|null
|
||||
*/
|
||||
public function get_keywords()
|
||||
{
|
||||
@@ -586,7 +584,7 @@ class Enclosure
|
||||
/**
|
||||
* Get length
|
||||
*
|
||||
* @return float Length in bytes
|
||||
* @return ?int Length in bytes
|
||||
*/
|
||||
public function get_length()
|
||||
{
|
||||
@@ -647,7 +645,7 @@ class Enclosure
|
||||
* @param int $key
|
||||
* @return \SimplePie\Rating|null
|
||||
*/
|
||||
public function get_rating($key = 0)
|
||||
public function get_rating(int $key = 0)
|
||||
{
|
||||
$ratings = $this->get_ratings();
|
||||
if (isset($ratings[$key])) {
|
||||
@@ -660,7 +658,7 @@ class Enclosure
|
||||
/**
|
||||
* Get all ratings
|
||||
*
|
||||
* @return array|null Array of {@see \SimplePie\Rating} objects
|
||||
* @return Rating[]|null
|
||||
*/
|
||||
public function get_ratings()
|
||||
{
|
||||
@@ -677,7 +675,7 @@ class Enclosure
|
||||
* @param int $key
|
||||
* @return \SimplePie\Restriction|null
|
||||
*/
|
||||
public function get_restriction($key = 0)
|
||||
public function get_restriction(int $key = 0)
|
||||
{
|
||||
$restrictions = $this->get_restrictions();
|
||||
if (isset($restrictions[$key])) {
|
||||
@@ -690,7 +688,7 @@ class Enclosure
|
||||
/**
|
||||
* Get all restrictions
|
||||
*
|
||||
* @return array|null Array of {@see \SimplePie\Restriction} objects
|
||||
* @return Restriction[]|null
|
||||
*/
|
||||
public function get_restrictions()
|
||||
{
|
||||
@@ -736,7 +734,7 @@ class Enclosure
|
||||
* @param int $key
|
||||
* @return string|null Thumbnail URL
|
||||
*/
|
||||
public function get_thumbnail($key = 0)
|
||||
public function get_thumbnail(int $key = 0)
|
||||
{
|
||||
$thumbnails = $this->get_thumbnails();
|
||||
if (isset($thumbnails[$key])) {
|
||||
@@ -749,7 +747,7 @@ class Enclosure
|
||||
/**
|
||||
* Get all thumbnails
|
||||
*
|
||||
* @return array|null Array of thumbnail URLs
|
||||
* @return string[]|null Array of thumbnail URLs
|
||||
*/
|
||||
public function get_thumbnails()
|
||||
{
|
||||
@@ -808,7 +806,7 @@ class Enclosure
|
||||
*
|
||||
* @deprecated Use the second parameter to {@see embed} instead
|
||||
*
|
||||
* @param array|string $options See first parameter to {@see embed}
|
||||
* @param array<string, mixed>|string $options See first parameter to {@see embed}
|
||||
* @return string HTML string to output
|
||||
*/
|
||||
public function native_embed($options = '')
|
||||
@@ -857,11 +855,11 @@ class Enclosure
|
||||
* `width` and `height` set to `auto` will default to 480x270 video resolution.
|
||||
*
|
||||
* @todo If the dimensions for media:content are defined, use them when width/height are set to 'auto'.
|
||||
* @param array|string $options Comma-separated key:value list, or array
|
||||
* @param array<string, mixed>|string $options Comma-separated key:value list, or array
|
||||
* @param bool $native Use `<embed>`
|
||||
* @return string HTML string to output
|
||||
*/
|
||||
public function embed($options = '', $native = false)
|
||||
public function embed($options = '', bool $native = false)
|
||||
{
|
||||
// Set up defaults
|
||||
$audio = '';
|
||||
@@ -933,7 +931,7 @@ class Enclosure
|
||||
}
|
||||
}
|
||||
|
||||
$mime = explode('/', $type, 2);
|
||||
$mime = explode('/', (string) $type, 2);
|
||||
$mime = $mime[0];
|
||||
|
||||
// Process values for 'auto'
|
||||
@@ -994,7 +992,10 @@ class Enclosure
|
||||
// Flash Media Player file types.
|
||||
// Preferred handler for MP3 file types.
|
||||
elseif ($handler === 'fmedia' || ($handler === 'mp3' && $mediaplayer !== '')) {
|
||||
$height += 20;
|
||||
if (is_numeric($height)) {
|
||||
$height += 20;
|
||||
}
|
||||
|
||||
if ($native) {
|
||||
$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>";
|
||||
} else {
|
||||
@@ -1005,7 +1006,10 @@ class Enclosure
|
||||
// QuickTime 7 file types. Need to test with QuickTime 6.
|
||||
// Only handle MP3's if the Flash Media Player is not present.
|
||||
elseif ($handler === 'quicktime' || ($handler === 'mp3' && $mediaplayer === '')) {
|
||||
$height += 16;
|
||||
if (is_numeric($height)) {
|
||||
$height += 16;
|
||||
}
|
||||
|
||||
if ($native) {
|
||||
if ($placeholder !== '') {
|
||||
$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>";
|
||||
@@ -1019,7 +1023,10 @@ class Enclosure
|
||||
|
||||
// Windows Media
|
||||
elseif ($handler === 'wmedia') {
|
||||
$height += 45;
|
||||
if (is_numeric($height)) {
|
||||
$height += 45;
|
||||
}
|
||||
|
||||
if ($native) {
|
||||
$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>";
|
||||
} else {
|
||||
@@ -1044,9 +1051,9 @@ class Enclosure
|
||||
*
|
||||
* @see get_type()
|
||||
* @param bool $find_handler Internal use only, use {@see get_handler()} instead
|
||||
* @return string MIME type
|
||||
* @return string|null MIME type
|
||||
*/
|
||||
public function get_real_type($find_handler = false)
|
||||
public function get_real_type(bool $find_handler = false)
|
||||
{
|
||||
// Mime-types by handler.
|
||||
$types_flash = ['application/x-shockwave-flash', 'application/futuresplash']; // Flash
|
||||
@@ -1055,10 +1062,9 @@ class Enclosure
|
||||
$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
|
||||
$types_mp3 = ['audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg']; // MP3
|
||||
|
||||
if ($this->get_type() !== null) {
|
||||
$type = strtolower($this->type);
|
||||
} else {
|
||||
$type = null;
|
||||
$type = $this->get_type();
|
||||
if ($type !== null) {
|
||||
$type = strtolower($type);
|
||||
}
|
||||
|
||||
// If we encounter an unsupported mime-type, check the file extension and guess intelligently.
|
||||
@@ -1114,9 +1120,9 @@ class Enclosure
|
||||
$type = 'audio/x-ms-wma';
|
||||
break;
|
||||
|
||||
// Video mime-types
|
||||
case '3gp':
|
||||
case '3gpp':
|
||||
// Video mime-types
|
||||
$type = 'video/3gpp';
|
||||
break;
|
||||
|
||||
@@ -1177,8 +1183,8 @@ class Enclosure
|
||||
$type = 'video/x-ms-wvx';
|
||||
break;
|
||||
|
||||
// Flash mime-types
|
||||
case 'spl':
|
||||
// Flash mime-types
|
||||
$type = 'application/futuresplash';
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user