Changeset 59141
- Timestamp:
- 09/30/2024 10:48:16 PM (4 months ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 55 added
- 19 edited
- 1 copied
- 28 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/SimplePie/src/Author.php
r59140 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie; 46 44 47 /** 45 48 * Manages all author-related data 46 49 * 47 * Used by {@see SimplePie_Item::get_author()} and {@see SimplePie::get_authors()}50 * Used by {@see Item::get_author()} and {@see SimplePie::get_authors()} 48 51 * 49 52 * This class can be overloaded with {@see SimplePie::set_author_class()} … … 52 55 * @subpackage API 53 56 */ 54 class SimplePie_Author57 class Author 55 58 { 56 57 58 59 60 61 62 var$name;59 /** 60 * Author's name 61 * 62 * @var string 63 * @see get_name() 64 */ 65 public $name; 63 66 64 65 66 67 68 69 70 var$link;67 /** 68 * Author's link 69 * 70 * @var string 71 * @see get_link() 72 */ 73 public $link; 71 74 72 73 74 75 76 77 78 var$email;75 /** 76 * Author's email address 77 * 78 * @var string 79 * @see get_email() 80 */ 81 public $email; 79 82 80 81 82 83 84 85 86 87 88 89 90 91 92 83 /** 84 * Constructor, used to input the data 85 * 86 * @param string $name 87 * @param string $link 88 * @param string $email 89 */ 90 public function __construct($name = null, $link = null, $email = null) 91 { 92 $this->name = $name; 93 $this->link = $link; 94 $this->email = $email; 95 } 93 96 94 95 96 97 98 99 100 101 102 103 97 /** 98 * String-ified version 99 * 100 * @return string 101 */ 102 public function __toString() 103 { 104 // There is no $this->data here 105 return md5(serialize($this)); 106 } 104 107 105 /** 106 * Author's name 107 * 108 * @return string|null 109 */ 110 public function get_name() 111 { 112 if ($this->name !== null) 113 { 114 return $this->name; 115 } 108 /** 109 * Author's name 110 * 111 * @return string|null 112 */ 113 public function get_name() 114 { 115 if ($this->name !== null) { 116 return $this->name; 117 } 116 118 117 118 119 return null; 120 } 119 121 120 /** 121 * Author's link 122 * 123 * @return string|null 124 */ 125 public function get_link() 126 { 127 if ($this->link !== null) 128 { 129 return $this->link; 130 } 122 /** 123 * Author's link 124 * 125 * @return string|null 126 */ 127 public function get_link() 128 { 129 if ($this->link !== null) { 130 return $this->link; 131 } 131 132 132 133 133 return null; 134 } 134 135 135 /** 136 * Author's email address 137 * 138 * @return string|null 139 */ 140 public function get_email() 141 { 142 if ($this->email !== null) 143 { 144 return $this->email; 145 } 136 /** 137 * Author's email address 138 * 139 * @return string|null 140 */ 141 public function get_email() 142 { 143 if ($this->email !== null) { 144 return $this->email; 145 } 146 146 147 148 147 return null; 148 } 149 149 } 150 151 class_alias('SimplePie\Author', 'SimplePie_Author'); -
trunk/src/wp-includes/SimplePie/src/Cache.php
r59140 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie; 46 47 use SimplePie\Cache\Base; 48 44 49 /** 45 50 * Used to create cache objects … … 51 56 * @package SimplePie 52 57 * @subpackage Caching 58 * @deprecated since SimplePie 1.8.0, use "SimplePie\SimplePie::set_cache()" instead 53 59 */ 54 class SimplePie_Cache60 class Cache 55 61 { 56 57 58 59 60 61 62 63 protected static $handlers = array( 64 'mysql' => 'SimplePie_Cache_MySQL',65 'memcache' => 'SimplePie_Cache_Memcache',66 'memcached' => 'SimplePie_Cache_Memcached',67 'redis' => 'SimplePie_Cache_Redis'68 );62 /** 63 * Cache handler classes 64 * 65 * These receive 3 parameters to their constructor, as documented in 66 * {@see register()} 67 * @var array 68 */ 69 protected static $handlers = [ 70 'mysql' => 'SimplePie\Cache\MySQL', 71 'memcache' => 'SimplePie\Cache\Memcache', 72 'memcached' => 'SimplePie\Cache\Memcached', 73 'redis' => 'SimplePie\Cache\Redis' 74 ]; 69 75 70 /** 71 * Don't call the constructor. Please. 72 */ 73 private function __construct() { } 76 /** 77 * Don't call the constructor. Please. 78 */ 79 private function __construct() 80 { 81 } 74 82 75 /** 76 * Create a new SimplePie_Cache object 77 * 78 * @param string $location URL location (scheme is used to determine handler) 79 * @param string $filename Unique identifier for cache object 80 * @param string $extension 'spi' or 'spc' 81 * @return SimplePie_Cache_Base Type of object depends on scheme of `$location` 82 */ 83 public static function get_handler($location, $filename, $extension) 84 { 85 $type = explode(':', $location, 2); 86 $type = $type[0]; 87 if (!empty(self::$handlers[$type])) 88 { 89 $class = self::$handlers[$type]; 90 return new $class($location, $filename, $extension); 91 } 83 /** 84 * Create a new SimplePie\Cache object 85 * 86 * @param string $location URL location (scheme is used to determine handler) 87 * @param string $filename Unique identifier for cache object 88 * @param Base::TYPE_FEED|Base::TYPE_IMAGE $extension 'spi' or 'spc' 89 * @return Base Type of object depends on scheme of `$location` 90 */ 91 public static function get_handler($location, $filename, $extension) 92 { 93 $type = explode(':', $location, 2); 94 $type = $type[0]; 95 if (!empty(self::$handlers[$type])) { 96 $class = self::$handlers[$type]; 97 return new $class($location, $filename, $extension); 98 } 92 99 93 return new SimplePie_Cache_File($location, $filename, $extension);94 100 return new \SimplePie\Cache\File($location, $filename, $extension); 101 } 95 102 96 /** 97 * Create a new SimplePie_Cache object 98 * 99 * @deprecated Use {@see get_handler} instead 100 */ 101 public function create($location, $filename, $extension) 102 { 103 trigger_error('Cache::create() has been replaced with Cache::get_handler(). Switch to the registry system to use this.', E_USER_DEPRECATED); 104 return self::get_handler($location, $filename, $extension); 105 } 103 /** 104 * Create a new SimplePie\Cache object 105 * 106 * @deprecated since SimplePie 1.3.1, use {@see get_handler()} instead 107 */ 108 public function create($location, $filename, $extension) 109 { 110 trigger_error('Cache::create() has been replaced with Cache::get_handler() since SimplePie 1.3.1, use the registry system instead.', \E_USER_DEPRECATED); 106 111 107 /** 108 * Register a handler 109 * 110 * @param string $type DSN type to register for 111 * @param string $class Name of handler class. Must implement SimplePie_Cache_Base 112 */ 113 public static function register($type, $class) 114 { 115 self::$handlers[$type] = $class; 116 } 112 return self::get_handler($location, $filename, $extension); 113 } 117 114 118 /** 119 * Parse a URL into an array 120 * 121 * @param string $url 122 * @return array 123 */ 124 public static function parse_URL($url) 125 { 126 $params = parse_url($url); 127 $params['extras'] = array(); 128 if (isset($params['query'])) 129 { 130 parse_str($params['query'], $params['extras']); 131 } 132 return $params; 133 } 115 /** 116 * Register a handler 117 * 118 * @param string $type DSN type to register for 119 * @param class-string<Base> $class Name of handler class. Must implement Base 120 */ 121 public static function register($type, $class) 122 { 123 self::$handlers[$type] = $class; 124 } 125 126 /** 127 * Parse a URL into an array 128 * 129 * @param string $url 130 * @return array 131 */ 132 public static function parse_URL($url) 133 { 134 $params = parse_url($url); 135 $params['extras'] = []; 136 if (isset($params['query'])) { 137 parse_str($params['query'], $params['extras']); 138 } 139 return $params; 140 } 134 141 } 142 143 class_alias('SimplePie\Cache', 'SimplePie_Cache'); -
trunk/src/wp-includes/SimplePie/src/Cache/Base.php
r47733 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie\Cache; 46 44 47 /** 45 48 * Base for cache objects 46 49 * 47 * Classes to be used with {@see SimplePie_Cache::register()} are expected50 * Classes to be used with {@see \SimplePie\Cache::register()} are expected 48 51 * to implement this interface. 49 52 * 50 53 * @package SimplePie 51 54 * @subpackage Caching 55 * @deprecated since SimplePie 1.8.0, use "Psr\SimpleCache\CacheInterface" instead 52 56 */ 53 interface SimplePie_Cache_Base57 interface Base 54 58 { 55 56 57 58 59 60 59 /** 60 * Feed cache type 61 * 62 * @var string 63 */ 64 public const TYPE_FEED = 'spc'; 61 65 62 63 64 65 66 67 66 /** 67 * Image cache type 68 * 69 * @var string 70 */ 71 public const TYPE_IMAGE = 'spi'; 68 72 69 70 71 72 73 74 * @param string$type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data75 76 73 /** 74 * Create a new cache object 75 * 76 * @param string $location Location string (from SimplePie::$cache_location) 77 * @param string $name Unique ID for the cache 78 * @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data 79 */ 80 public function __construct($location, $name, $type); 77 81 78 79 80 81 * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property82 83 84 82 /** 83 * Save data to the cache 84 * 85 * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 86 * @return bool Successfulness 87 */ 88 public function save($data); 85 89 86 87 88 89 90 91 90 /** 91 * Retrieve the data saved to the cache 92 * 93 * @return array Data for SimplePie::$data 94 */ 95 public function load(); 92 96 93 94 95 96 97 98 97 /** 98 * Retrieve the last modified time for the cache 99 * 100 * @return int Timestamp 101 */ 102 public function mtime(); 99 103 100 101 102 103 104 105 104 /** 105 * Set the last modified time to the current time 106 * 107 * @return bool Success status 108 */ 109 public function touch(); 106 110 107 108 109 110 111 112 111 /** 112 * Remove the cache 113 * 114 * @return bool Success status 115 */ 116 public function unlink(); 113 117 } 118 119 class_alias('SimplePie\Cache\Base', 'SimplePie_Cache_Base'); -
trunk/src/wp-includes/SimplePie/src/Cache/DB.php
r47733 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie\Cache; 46 44 47 /** 45 48 * Base class for database-based caches … … 47 50 * @package SimplePie 48 51 * @subpackage Caching 52 * @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead 49 53 */ 50 abstract class SimplePie_Cache_DB implements SimplePie_Cache_Base54 abstract class DB implements Base 51 55 { 52 53 54 55 56 57 * @paramSimplePie $data58 59 60 61 62 63 $items_by_id = array();56 /** 57 * Helper for database conversion 58 * 59 * Converts a given {@see SimplePie} object into data to be stored 60 * 61 * @param \SimplePie\SimplePie $data 62 * @return array First item is the serialized data for storage, second item is the unique ID for this item 63 */ 64 protected static function prepare_simplepie_object_for_cache($data) 65 { 66 $items = $data->get_items(); 67 $items_by_id = []; 64 68 65 if (!empty($items)) 66 { 67 foreach ($items as $item) 68 { 69 $items_by_id[$item->get_id()] = $item; 70 } 69 if (!empty($items)) { 70 foreach ($items as $item) { 71 $items_by_id[$item->get_id()] = $item; 72 } 71 73 72 if (count($items_by_id) !== count($items)) 73 { 74 $items_by_id = array(); 75 foreach ($items as $item) 76 { 77 $items_by_id[$item->get_id(true)] = $item; 78 } 79 } 74 if (count($items_by_id) !== count($items)) { 75 $items_by_id = []; 76 foreach ($items as $item) { 77 $items_by_id[$item->get_id(true)] = $item; 78 } 79 } 80 80 81 if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0])) 82 { 83 $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]; 84 } 85 elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0])) 86 { 87 $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]; 88 } 89 elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0])) 90 { 91 $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]; 92 } 93 elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0])) 94 { 95 $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]; 96 } 97 else 98 { 99 $channel = null; 100 } 81 if (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0])) { 82 $channel = &$data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0]; 83 } elseif (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0])) { 84 $channel = &$data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0]; 85 } elseif (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0])) { 86 $channel = &$data->data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0]; 87 } elseif (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0]['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['channel'][0])) { 88 $channel = &$data->data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0]['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['channel'][0]; 89 } else { 90 $channel = null; 91 } 101 92 102 if ($channel !== null) 103 { 104 if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'])) 105 { 106 unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']); 107 } 108 if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry'])) 109 { 110 unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']); 111 } 112 if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])) 113 { 114 unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']); 115 } 116 if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])) 117 { 118 unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']); 119 } 120 if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item'])) 121 { 122 unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']); 123 } 124 } 125 if (isset($data->data['items'])) 126 { 127 unset($data->data['items']); 128 } 129 if (isset($data->data['ordered_items'])) 130 { 131 unset($data->data['ordered_items']); 132 } 133 } 134 return array(serialize($data->data), $items_by_id); 135 } 93 if ($channel !== null) { 94 if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['entry'])) { 95 unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['entry']); 96 } 97 if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['entry'])) { 98 unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['entry']); 99 } 100 if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_10]['item'])) { 101 unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_10]['item']); 102 } 103 if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_090]['item'])) { 104 unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_090]['item']); 105 } 106 if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['item'])) { 107 unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['item']); 108 } 109 } 110 if (isset($data->data['items'])) { 111 unset($data->data['items']); 112 } 113 if (isset($data->data['ordered_items'])) { 114 unset($data->data['ordered_items']); 115 } 116 } 117 return [serialize($data->data), $items_by_id]; 118 } 136 119 } 120 121 class_alias('SimplePie\Cache\DB', 'SimplePie_Cache_DB'); -
trunk/src/wp-includes/SimplePie/src/Cache/File.php
r47733 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie\Cache; 46 44 47 /** 45 48 * Caches data to the filesystem … … 47 50 * @package SimplePie 48 51 * @subpackage Caching 52 * @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead 49 53 */ 50 class SimplePie_Cache_File implements SimplePie_Cache_Base54 class File implements Base 51 55 { 52 53 54 55 56 57 58 56 /** 57 * Location string 58 * 59 * @see SimplePie::$cache_location 60 * @var string 61 */ 62 protected $location; 59 63 60 61 62 63 64 65 64 /** 65 * Filename 66 * 67 * @var string 68 */ 69 protected $filename; 66 70 67 68 69 70 71 72 71 /** 72 * File extension 73 * 74 * @var string 75 */ 76 protected $extension; 73 77 74 75 76 77 78 79 78 /** 79 * File path 80 * 81 * @var string 82 */ 83 protected $name; 80 84 81 82 83 84 85 86 * @param string$type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data87 88 89 90 91 92 93 94 85 /** 86 * Create a new cache object 87 * 88 * @param string $location Location string (from SimplePie::$cache_location) 89 * @param string $name Unique ID for the cache 90 * @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data 91 */ 92 public function __construct($location, $name, $type) 93 { 94 $this->location = $location; 95 $this->filename = $name; 96 $this->extension = $type; 97 $this->name = "$this->location/$this->filename.$this->extension"; 98 } 95 99 96 /** 97 * Save data to the cache 98 * 99 * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 100 * @return bool Successfulness 101 */ 102 public function save($data) 103 { 104 if (file_exists($this->name) && is_writable($this->name) || file_exists($this->location) && is_writable($this->location)) 105 { 106 if ($data instanceof SimplePie) 107 { 108 $data = $data->data; 109 } 100 /** 101 * Save data to the cache 102 * 103 * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 104 * @return bool Successfulness 105 */ 106 public function save($data) 107 { 108 if (file_exists($this->name) && is_writable($this->name) || file_exists($this->location) && is_writable($this->location)) { 109 if ($data instanceof \SimplePie\SimplePie) { 110 $data = $data->data; 111 } 110 112 111 112 113 114 115 113 $data = serialize($data); 114 return (bool) file_put_contents($this->name, $data); 115 } 116 return false; 117 } 116 118 117 /** 118 * Retrieve the data saved to the cache 119 * 120 * @return array Data for SimplePie::$data 121 */ 122 public function load() 123 { 124 if (file_exists($this->name) && is_readable($this->name)) 125 { 126 return unserialize(file_get_contents($this->name)); 127 } 128 return false; 129 } 119 /** 120 * Retrieve the data saved to the cache 121 * 122 * @return array Data for SimplePie::$data 123 */ 124 public function load() 125 { 126 if (file_exists($this->name) && is_readable($this->name)) { 127 return unserialize(file_get_contents($this->name)); 128 } 129 return false; 130 } 130 131 131 132 133 134 135 136 137 138 139 132 /** 133 * Retrieve the last modified time for the cache 134 * 135 * @return int Timestamp 136 */ 137 public function mtime() 138 { 139 return @filemtime($this->name); 140 } 140 141 141 142 143 144 145 146 147 148 149 142 /** 143 * Set the last modified time to the current time 144 * 145 * @return bool Success status 146 */ 147 public function touch() 148 { 149 return @touch($this->name); 150 } 150 151 151 /** 152 * Remove the cache 153 * 154 * @return bool Success status 155 */ 156 public function unlink() 157 { 158 if (file_exists($this->name)) 159 { 160 return unlink($this->name); 161 } 162 return false; 163 } 152 /** 153 * Remove the cache 154 * 155 * @return bool Success status 156 */ 157 public function unlink() 158 { 159 if (file_exists($this->name)) { 160 return unlink($this->name); 161 } 162 return false; 163 } 164 164 } 165 166 class_alias('SimplePie\Cache\File', 'SimplePie_Cache_File'); -
trunk/src/wp-includes/SimplePie/src/Cache/Memcache.php
r47733 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie\Cache; 46 47 use Memcache as NativeMemcache; 48 44 49 /** 45 50 * Caches data to memcache … … 54 59 * @subpackage Caching 55 60 * @uses Memcache 61 * @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead 56 62 */ 57 class SimplePie_Cache_Memcache implements SimplePie_Cache_Base63 class Memcache implements Base 58 64 { 59 60 61 62 63 64 65 /** 66 * Memcache instance 67 * 68 * @var Memcache 69 */ 70 protected $cache; 65 71 66 67 68 69 70 71 72 /** 73 * Options 74 * 75 * @var array 76 */ 77 protected $options; 72 78 73 74 75 76 77 78 79 /** 80 * Cache name 81 * 82 * @var string 83 */ 84 protected $name; 79 85 80 81 82 83 84 85 * @param string$type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data86 87 88 89 $this->options = array( 90 91 92 'extras' => array( 93 94 95 ),96 );97 $this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));86 /** 87 * Create a new cache object 88 * 89 * @param string $location Location string (from SimplePie::$cache_location) 90 * @param string $name Unique ID for the cache 91 * @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data 92 */ 93 public function __construct($location, $name, $type) 94 { 95 $this->options = [ 96 'host' => '127.0.0.1', 97 'port' => 11211, 98 'extras' => [ 99 'timeout' => 3600, // one hour 100 'prefix' => 'simplepie_', 101 ], 102 ]; 103 $this->options = array_replace_recursive($this->options, \SimplePie\Cache::parse_URL($location)); 98 104 99 105 $this->name = $this->options['extras']['prefix'] . md5("$name:$type"); 100 106 101 $this->cache = newMemcache();102 103 107 $this->cache = new NativeMemcache(); 108 $this->cache->addServer($this->options['host'], (int) $this->options['port']); 109 } 104 110 105 /** 106 * Save data to the cache 107 * 108 * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 109 * @return bool Successfulness 110 */ 111 public function save($data) 112 { 113 if ($data instanceof SimplePie) 114 { 115 $data = $data->data; 116 } 117 return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']); 118 } 111 /** 112 * Save data to the cache 113 * 114 * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 115 * @return bool Successfulness 116 */ 117 public function save($data) 118 { 119 if ($data instanceof \SimplePie\SimplePie) { 120 $data = $data->data; 121 } 122 return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']); 123 } 119 124 120 121 122 123 124 125 126 127 125 /** 126 * Retrieve the data saved to the cache 127 * 128 * @return array Data for SimplePie::$data 129 */ 130 public function load() 131 { 132 $data = $this->cache->get($this->name); 128 133 129 if ($data !== false) 130 { 131 return unserialize($data); 132 } 133 return false; 134 } 134 if ($data !== false) { 135 return unserialize($data); 136 } 137 return false; 138 } 135 139 136 137 138 139 140 141 142 143 140 /** 141 * Retrieve the last modified time for the cache 142 * 143 * @return int Timestamp 144 */ 145 public function mtime() 146 { 147 $data = $this->cache->get($this->name); 144 148 145 if ($data !== false) 146 { 147 // essentially ignore the mtime because Memcache expires on its own 148 return time(); 149 } 149 if ($data !== false) { 150 // essentially ignore the mtime because Memcache expires on its own 151 return time(); 152 } 150 153 151 152 154 return false; 155 } 153 156 154 155 156 157 158 159 160 161 157 /** 158 * Set the last modified time to the current time 159 * 160 * @return bool Success status 161 */ 162 public function touch() 163 { 164 $data = $this->cache->get($this->name); 162 165 163 if ($data !== false) 164 { 165 return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']); 166 } 166 if ($data !== false) { 167 return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']); 168 } 167 169 168 169 170 return false; 171 } 170 172 171 172 173 174 175 176 177 178 179 173 /** 174 * Remove the cache 175 * 176 * @return bool Success status 177 */ 178 public function unlink() 179 { 180 return $this->cache->delete($this->name, 0); 181 } 180 182 } 183 184 class_alias('SimplePie\Cache\Memcache', 'SimplePie_Cache_Memcache'); -
trunk/src/wp-includes/SimplePie/src/Cache/Memcached.php
r47733 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie\Cache; 46 47 use Memcached as NativeMemcached; 48 44 49 /** 45 50 * Caches data to memcached … … 55 60 * @author Paul L. McNeely 56 61 * @uses Memcached 62 * @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead 57 63 */ 58 class SimplePie_Cache_Memcached implements SimplePie_Cache_Base64 class Memcached implements Base 59 65 { 60 66 /** 61 * Memcached instance62 * @var Memcached67 * NativeMemcached instance 68 * @var NativeMemcached 63 69 */ 64 70 protected $cache; … … 79 85 * Create a new cache object 80 86 * @param string $location Location string (from SimplePie::$cache_location) 81 * @param string $name 82 * @param string $typeEither TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data87 * @param string $name Unique ID for the cache 88 * @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data 83 89 */ 84 public function __construct($location, $name, $type) { 85 $this->options = array( 90 public function __construct($location, $name, $type) 91 { 92 $this->options = [ 86 93 'host' => '127.0.0.1', 87 94 'port' => 11211, 88 'extras' => array(95 'extras' => [ 89 96 'timeout' => 3600, // one hour 90 97 'prefix' => 'simplepie_', 91 ),92 );93 $this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));98 ], 99 ]; 100 $this->options = array_replace_recursive($this->options, \SimplePie\Cache::parse_URL($location)); 94 101 95 102 $this->name = $this->options['extras']['prefix'] . md5("$name:$type"); 96 103 97 $this->cache = new Memcached();104 $this->cache = new NativeMemcached(); 98 105 $this->cache->addServer($this->options['host'], (int)$this->options['port']); 99 106 } … … 101 108 /** 102 109 * Save data to the cache 103 * @param array| SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property110 * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 104 111 * @return bool Successfulness 105 112 */ 106 public function save($data) { 107 if ($data instanceof SimplePie) { 113 public function save($data) 114 { 115 if ($data instanceof \SimplePie\SimplePie) { 108 116 $data = $data->data; 109 117 } … … 116 124 * @return array Data for SimplePie::$data 117 125 */ 118 public function load() { 126 public function load() 127 { 119 128 $data = $this->cache->get($this->name); 120 129 … … 129 138 * @return int Timestamp 130 139 */ 131 public function mtime() { 140 public function mtime() 141 { 132 142 $data = $this->cache->get($this->name . '_mtime'); 133 143 return (int) $data; … … 138 148 * @return bool Success status 139 149 */ 140 public function touch() { 150 public function touch() 151 { 141 152 $data = $this->cache->get($this->name); 142 153 return $this->setData($data); … … 147 158 * @return bool Success status 148 159 */ 149 public function unlink() { 160 public function unlink() 161 { 150 162 return $this->cache->delete($this->name, 0); 151 163 } 152 164 153 165 /** 154 * Set the last modified time and data to Memcached166 * Set the last modified time and data to NativeMemcached 155 167 * @return bool Success status 156 168 */ 157 private function setData($data) {158 169 private function setData($data) 170 { 159 171 if ($data !== false) { 160 172 $this->cache->set($this->name . '_mtime', time(), (int)$this->options['extras']['timeout']); … … 165 177 } 166 178 } 179 180 class_alias('SimplePie\Cache\Memcached', 'SimplePie_Cache_Memcached'); -
trunk/src/wp-includes/SimplePie/src/Cache/MySQL.php
r47733 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie\Cache; 46 44 47 /** 45 48 * Caches data to a MySQL database … … 53 56 * @package SimplePie 54 57 * @subpackage Caching 58 * @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead 55 59 */ 56 class SimplePie_Cache_MySQL extends SimplePie_Cache_DB60 class MySQL extends DB 57 61 { 58 /** 59 * PDO instance 60 * 61 * @var PDO 62 */ 63 protected $mysql; 64 65 /** 66 * Options 67 * 68 * @var array 69 */ 70 protected $options; 71 72 /** 73 * Cache ID 74 * 75 * @var string 76 */ 77 protected $id; 78 79 /** 80 * Create a new cache object 81 * 82 * @param string $location Location string (from SimplePie::$cache_location) 83 * @param string $name Unique ID for the cache 84 * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data 85 */ 86 public function __construct($location, $name, $type) 87 { 88 $this->options = array( 89 'user' => null, 90 'pass' => null, 91 'host' => '127.0.0.1', 92 'port' => '3306', 93 'path' => '', 94 'extras' => array( 95 'prefix' => '', 96 'cache_purge_time' => 2592000 97 ), 98 ); 99 100 $this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location)); 101 102 // Path is prefixed with a "/" 103 $this->options['dbname'] = substr($this->options['path'], 1); 104 105 try 106 { 107 $this->mysql = new PDO("mysql:dbname={$this->options['dbname']};host={$this->options['host']};port={$this->options['port']}", $this->options['user'], $this->options['pass'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); 108 } 109 catch (PDOException $e) 110 { 111 $this->mysql = null; 112 return; 113 } 114 115 $this->id = $name . $type; 116 117 if (!$query = $this->mysql->query('SHOW TABLES')) 118 { 119 $this->mysql = null; 120 return; 121 } 122 123 $db = array(); 124 while ($row = $query->fetchColumn()) 125 { 126 $db[] = $row; 127 } 128 129 if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db)) 130 { 131 $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))'); 132 if ($query === false) 133 { 134 trigger_error("Can't create " . $this->options['extras']['prefix'] . "cache_data table, check permissions", E_USER_WARNING); 135 $this->mysql = null; 136 return; 137 } 138 } 139 140 if (!in_array($this->options['extras']['prefix'] . 'items', $db)) 141 { 142 $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` MEDIUMBLOB NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))'); 143 if ($query === false) 144 { 145 trigger_error("Can't create " . $this->options['extras']['prefix'] . "items table, check permissions", E_USER_WARNING); 146 $this->mysql = null; 147 return; 148 } 149 } 150 } 151 152 /** 153 * Save data to the cache 154 * 155 * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 156 * @return bool Successfulness 157 */ 158 public function save($data) 159 { 160 if ($this->mysql === null) 161 { 162 return false; 163 } 164 165 $query = $this->mysql->prepare('DELETE i, cd FROM `' . $this->options['extras']['prefix'] . 'cache_data` cd, ' . 166 '`' . $this->options['extras']['prefix'] . 'items` i ' . 167 'WHERE cd.id = i.feed_id ' . 168 'AND cd.mtime < (unix_timestamp() - :purge_time)'); 169 $query->bindValue(':purge_time', $this->options['extras']['cache_purge_time']); 170 171 if (!$query->execute()) 172 { 173 return false; 174 } 175 176 if ($data instanceof SimplePie) 177 { 178 $data = clone $data; 179 180 $prepared = self::prepare_simplepie_object_for_cache($data); 181 182 $query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed'); 183 $query->bindValue(':feed', $this->id); 184 if ($query->execute()) 185 { 186 if ($query->fetchColumn() > 0) 187 { 188 $items = count($prepared[1]); 189 if ($items) 190 { 191 $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed'; 192 $query = $this->mysql->prepare($sql); 193 $query->bindValue(':items', $items); 194 } 195 else 196 { 197 $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed'; 198 $query = $this->mysql->prepare($sql); 199 } 200 201 $query->bindValue(':data', $prepared[0]); 202 $query->bindValue(':time', time()); 203 $query->bindValue(':feed', $this->id); 204 if (!$query->execute()) 205 { 206 return false; 207 } 208 } 209 else 210 { 211 $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)'); 212 $query->bindValue(':feed', $this->id); 213 $query->bindValue(':count', count($prepared[1])); 214 $query->bindValue(':data', $prepared[0]); 215 $query->bindValue(':time', time()); 216 if (!$query->execute()) 217 { 218 return false; 219 } 220 } 221 222 $ids = array_keys($prepared[1]); 223 if (!empty($ids)) 224 { 225 foreach ($ids as $id) 226 { 227 $database_ids[] = $this->mysql->quote($id); 228 } 229 230 $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed'); 231 $query->bindValue(':feed', $this->id); 232 233 if ($query->execute()) 234 { 235 $existing_ids = array(); 236 while ($row = $query->fetchColumn()) 237 { 238 $existing_ids[] = $row; 239 } 240 241 $new_ids = array_diff($ids, $existing_ids); 242 243 foreach ($new_ids as $new_id) 244 { 245 if (!($date = $prepared[1][$new_id]->get_date('U'))) 246 { 247 $date = time(); 248 } 249 250 $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)'); 251 $query->bindValue(':feed', $this->id); 252 $query->bindValue(':id', $new_id); 253 $query->bindValue(':data', serialize($prepared[1][$new_id]->data)); 254 $query->bindValue(':date', $date); 255 if (!$query->execute()) 256 { 257 return false; 258 } 259 } 260 return true; 261 } 262 } 263 else 264 { 265 return true; 266 } 267 } 268 } 269 else 270 { 271 $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed'); 272 $query->bindValue(':feed', $this->id); 273 if ($query->execute()) 274 { 275 if ($query->rowCount() > 0) 276 { 277 $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed'); 278 $query->bindValue(':data', serialize($data)); 279 $query->bindValue(':time', time()); 280 $query->bindValue(':feed', $this->id); 281 if ($this->execute()) 282 { 283 return true; 284 } 285 } 286 else 287 { 288 $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)'); 289 $query->bindValue(':id', $this->id); 290 $query->bindValue(':data', serialize($data)); 291 $query->bindValue(':time', time()); 292 if ($query->execute()) 293 { 294 return true; 295 } 296 } 297 } 298 } 299 return false; 300 } 301 302 /** 303 * Retrieve the data saved to the cache 304 * 305 * @return array Data for SimplePie::$data 306 */ 307 public function load() 308 { 309 if ($this->mysql === null) 310 { 311 return false; 312 } 313 314 $query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id'); 315 $query->bindValue(':id', $this->id); 316 if ($query->execute() && ($row = $query->fetch())) 317 { 318 $data = unserialize($row[1]); 319 320 if (isset($this->options['items'][0])) 321 { 322 $items = (int) $this->options['items'][0]; 323 } 324 else 325 { 326 $items = (int) $row[0]; 327 } 328 329 if ($items !== 0) 330 { 331 if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0])) 332 { 333 $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]; 334 } 335 elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0])) 336 { 337 $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]; 338 } 339 elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0])) 340 { 341 $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]; 342 } 343 elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0])) 344 { 345 $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]; 346 } 347 else 348 { 349 $feed = null; 350 } 351 352 if ($feed !== null) 353 { 354 $sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC'; 355 if ($items > 0) 356 { 357 $sql .= ' LIMIT ' . $items; 358 } 359 360 $query = $this->mysql->prepare($sql); 361 $query->bindValue(':feed', $this->id); 362 if ($query->execute()) 363 { 364 while ($row = $query->fetchColumn()) 365 { 366 $feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row); 367 } 368 } 369 else 370 { 371 return false; 372 } 373 } 374 } 375 return $data; 376 } 377 return false; 378 } 379 380 /** 381 * Retrieve the last modified time for the cache 382 * 383 * @return int Timestamp 384 */ 385 public function mtime() 386 { 387 if ($this->mysql === null) 388 { 389 return false; 390 } 391 392 $query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id'); 393 $query->bindValue(':id', $this->id); 394 if ($query->execute() && ($time = $query->fetchColumn())) 395 { 396 return $time; 397 } 398 399 return false; 400 } 401 402 /** 403 * Set the last modified time to the current time 404 * 405 * @return bool Success status 406 */ 407 public function touch() 408 { 409 if ($this->mysql === null) 410 { 411 return false; 412 } 413 414 $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id'); 415 $query->bindValue(':time', time()); 416 $query->bindValue(':id', $this->id); 417 418 return $query->execute() && $query->rowCount() > 0; 419 } 420 421 /** 422 * Remove the cache 423 * 424 * @return bool Success status 425 */ 426 public function unlink() 427 { 428 if ($this->mysql === null) 429 { 430 return false; 431 } 432 433 $query = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id'); 434 $query->bindValue(':id', $this->id); 435 $query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id'); 436 $query2->bindValue(':id', $this->id); 437 438 return $query->execute() && $query2->execute(); 439 } 62 /** 63 * PDO instance 64 * 65 * @var \PDO 66 */ 67 protected $mysql; 68 69 /** 70 * Options 71 * 72 * @var array 73 */ 74 protected $options; 75 76 /** 77 * Cache ID 78 * 79 * @var string 80 */ 81 protected $id; 82 83 /** 84 * Create a new cache object 85 * 86 * @param string $location Location string (from SimplePie::$cache_location) 87 * @param string $name Unique ID for the cache 88 * @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data 89 */ 90 public function __construct($location, $name, $type) 91 { 92 $this->options = [ 93 'user' => null, 94 'pass' => null, 95 'host' => '127.0.0.1', 96 'port' => '3306', 97 'path' => '', 98 'extras' => [ 99 'prefix' => '', 100 'cache_purge_time' => 2592000 101 ], 102 ]; 103 104 $this->options = array_replace_recursive($this->options, \SimplePie\Cache::parse_URL($location)); 105 106 // Path is prefixed with a "/" 107 $this->options['dbname'] = substr($this->options['path'], 1); 108 109 try { 110 $this->mysql = new \PDO("mysql:dbname={$this->options['dbname']};host={$this->options['host']};port={$this->options['port']}", $this->options['user'], $this->options['pass'], [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']); 111 } catch (\PDOException $e) { 112 $this->mysql = null; 113 return; 114 } 115 116 $this->id = $name . $type; 117 118 if (!$query = $this->mysql->query('SHOW TABLES')) { 119 $this->mysql = null; 120 return; 121 } 122 123 $db = []; 124 while ($row = $query->fetchColumn()) { 125 $db[] = $row; 126 } 127 128 if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db)) { 129 $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))'); 130 if ($query === false) { 131 trigger_error("Can't create " . $this->options['extras']['prefix'] . "cache_data table, check permissions", \E_USER_WARNING); 132 $this->mysql = null; 133 return; 134 } 135 } 136 137 if (!in_array($this->options['extras']['prefix'] . 'items', $db)) { 138 $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` MEDIUMBLOB NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))'); 139 if ($query === false) { 140 trigger_error("Can't create " . $this->options['extras']['prefix'] . "items table, check permissions", \E_USER_WARNING); 141 $this->mysql = null; 142 return; 143 } 144 } 145 } 146 147 /** 148 * Save data to the cache 149 * 150 * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 151 * @return bool Successfulness 152 */ 153 public function save($data) 154 { 155 if ($this->mysql === null) { 156 return false; 157 } 158 159 $query = $this->mysql->prepare('DELETE i, cd FROM `' . $this->options['extras']['prefix'] . 'cache_data` cd, ' . 160 '`' . $this->options['extras']['prefix'] . 'items` i ' . 161 'WHERE cd.id = i.feed_id ' . 162 'AND cd.mtime < (unix_timestamp() - :purge_time)'); 163 $query->bindValue(':purge_time', $this->options['extras']['cache_purge_time']); 164 165 if (!$query->execute()) { 166 return false; 167 } 168 169 if ($data instanceof \SimplePie\SimplePie) { 170 $data = clone $data; 171 172 $prepared = self::prepare_simplepie_object_for_cache($data); 173 174 $query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed'); 175 $query->bindValue(':feed', $this->id); 176 if ($query->execute()) { 177 if ($query->fetchColumn() > 0) { 178 $items = count($prepared[1]); 179 if ($items) { 180 $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed'; 181 $query = $this->mysql->prepare($sql); 182 $query->bindValue(':items', $items); 183 } else { 184 $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed'; 185 $query = $this->mysql->prepare($sql); 186 } 187 188 $query->bindValue(':data', $prepared[0]); 189 $query->bindValue(':time', time()); 190 $query->bindValue(':feed', $this->id); 191 if (!$query->execute()) { 192 return false; 193 } 194 } else { 195 $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)'); 196 $query->bindValue(':feed', $this->id); 197 $query->bindValue(':count', count($prepared[1])); 198 $query->bindValue(':data', $prepared[0]); 199 $query->bindValue(':time', time()); 200 if (!$query->execute()) { 201 return false; 202 } 203 } 204 205 $ids = array_keys($prepared[1]); 206 if (!empty($ids)) { 207 foreach ($ids as $id) { 208 $database_ids[] = $this->mysql->quote($id); 209 } 210 211 $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed'); 212 $query->bindValue(':feed', $this->id); 213 214 if ($query->execute()) { 215 $existing_ids = []; 216 while ($row = $query->fetchColumn()) { 217 $existing_ids[] = $row; 218 } 219 220 $new_ids = array_diff($ids, $existing_ids); 221 222 foreach ($new_ids as $new_id) { 223 if (!($date = $prepared[1][$new_id]->get_date('U'))) { 224 $date = time(); 225 } 226 227 $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)'); 228 $query->bindValue(':feed', $this->id); 229 $query->bindValue(':id', $new_id); 230 $query->bindValue(':data', serialize($prepared[1][$new_id]->data)); 231 $query->bindValue(':date', $date); 232 if (!$query->execute()) { 233 return false; 234 } 235 } 236 return true; 237 } 238 } else { 239 return true; 240 } 241 } 242 } else { 243 $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed'); 244 $query->bindValue(':feed', $this->id); 245 if ($query->execute()) { 246 if ($query->rowCount() > 0) { 247 $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed'); 248 $query->bindValue(':data', serialize($data)); 249 $query->bindValue(':time', time()); 250 $query->bindValue(':feed', $this->id); 251 if ($query->execute()) { 252 return true; 253 } 254 } else { 255 $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)'); 256 $query->bindValue(':id', $this->id); 257 $query->bindValue(':data', serialize($data)); 258 $query->bindValue(':time', time()); 259 if ($query->execute()) { 260 return true; 261 } 262 } 263 } 264 } 265 return false; 266 } 267 268 /** 269 * Retrieve the data saved to the cache 270 * 271 * @return array Data for SimplePie::$data 272 */ 273 public function load() 274 { 275 if ($this->mysql === null) { 276 return false; 277 } 278 279 $query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id'); 280 $query->bindValue(':id', $this->id); 281 if ($query->execute() && ($row = $query->fetch())) { 282 $data = unserialize($row[1]); 283 284 if (isset($this->options['items'][0])) { 285 $items = (int) $this->options['items'][0]; 286 } else { 287 $items = (int) $row[0]; 288 } 289 290 if ($items !== 0) { 291 if (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0])) { 292 $feed = &$data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0]; 293 } elseif (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0])) { 294 $feed = &$data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0]; 295 } elseif (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0])) { 296 $feed = &$data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0]; 297 } elseif (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0])) { 298 $feed = &$data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0]; 299 } else { 300 $feed = null; 301 } 302 303 if ($feed !== null) { 304 $sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC'; 305 if ($items > 0) { 306 $sql .= ' LIMIT ' . $items; 307 } 308 309 $query = $this->mysql->prepare($sql); 310 $query->bindValue(':feed', $this->id); 311 if ($query->execute()) { 312 while ($row = $query->fetchColumn()) { 313 $feed['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['entry'][] = unserialize($row); 314 } 315 } else { 316 return false; 317 } 318 } 319 } 320 return $data; 321 } 322 return false; 323 } 324 325 /** 326 * Retrieve the last modified time for the cache 327 * 328 * @return int Timestamp 329 */ 330 public function mtime() 331 { 332 if ($this->mysql === null) { 333 return false; 334 } 335 336 $query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id'); 337 $query->bindValue(':id', $this->id); 338 if ($query->execute() && ($time = $query->fetchColumn())) { 339 return $time; 340 } 341 342 return false; 343 } 344 345 /** 346 * Set the last modified time to the current time 347 * 348 * @return bool Success status 349 */ 350 public function touch() 351 { 352 if ($this->mysql === null) { 353 return false; 354 } 355 356 $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id'); 357 $query->bindValue(':time', time()); 358 $query->bindValue(':id', $this->id); 359 360 return $query->execute() && $query->rowCount() > 0; 361 } 362 363 /** 364 * Remove the cache 365 * 366 * @return bool Success status 367 */ 368 public function unlink() 369 { 370 if ($this->mysql === null) { 371 return false; 372 } 373 374 $query = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id'); 375 $query->bindValue(':id', $this->id); 376 $query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id'); 377 $query2->bindValue(':id', $this->id); 378 379 return $query->execute() && $query2->execute(); 380 } 440 381 } 382 383 class_alias('SimplePie\Cache\MySQL', 'SimplePie_Cache_MySQL'); -
trunk/src/wp-includes/SimplePie/src/Cache/Redis.php
r52393 r59141 2 2 3 3 /** 4 * SimplePie Redis Cache Extension 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. 5 35 * 6 36 * @package SimplePie 7 * @author Jan Kozak <galvani78@gmail.com> 8 * @link http://galvani.cz/ 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 9 42 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 10 * @version 0.2.911 43 */ 12 44 45 namespace SimplePie\Cache; 46 47 use Redis as NativeRedis; 13 48 14 49 /** … … 24 59 * @subpackage Caching 25 60 * @uses Redis 61 * @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead 26 62 */ 27 class SimplePie_Cache_Redis implements SimplePie_Cache_Base { 63 class Redis implements Base 64 { 28 65 /** 29 66 * Redis instance 30 67 * 31 * @var \Redis68 * @var NativeRedis 32 69 */ 33 70 protected $cache; … … 46 83 */ 47 84 protected $name; 48 49 /**50 * Cache Data51 *52 * @var type53 */54 protected $data;55 85 56 86 /** … … 59 89 * @param string $location Location string (from SimplePie::$cache_location) 60 90 * @param string $name Unique ID for the cache 61 * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data 62 */ 63 public function __construct($location, $name, $options = null) { 91 * @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data 92 */ 93 public function __construct($location, $name, $options = null) 94 { 64 95 //$this->cache = \flow\simple\cache\Redis::getRedisClientInstance(); 65 $parsed = SimplePie_Cache::parse_URL($location);66 $redis = new Redis();96 $parsed = \SimplePie\Cache::parse_URL($location); 97 $redis = new NativeRedis(); 67 98 $redis->connect($parsed['host'], $parsed['port']); 68 99 if (isset($parsed['pass'])) { … … 77 108 $this->options = $options; 78 109 } else { 79 $this->options = array (110 $this->options = [ 80 111 'prefix' => 'rss:simple_primary:', 81 112 'expire' => 0, 82 );113 ]; 83 114 } 84 115 … … 87 118 88 119 /** 89 * @param \Redis $cache 90 */ 91 public function setRedisClient(\Redis $cache) { 120 * @param NativeRedis $cache 121 */ 122 public function setRedisClient(NativeRedis $cache) 123 { 92 124 $this->cache = $cache; 93 125 } … … 96 128 * Save data to the cache 97 129 * 98 * @param array| SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property130 * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 99 131 * @return bool Successfulness 100 132 */ 101 public function save($data) { 102 if ($data instanceof SimplePie) { 133 public function save($data) 134 { 135 if ($data instanceof \SimplePie\SimplePie) { 103 136 $data = $data->data; 104 137 } … … 116 149 * @return array Data for SimplePie::$data 117 150 */ 118 public function load() { 151 public function load() 152 { 119 153 $data = $this->cache->get($this->name); 120 154 … … 130 164 * @return int Timestamp 131 165 */ 132 public function mtime() {133 166 public function mtime() 167 { 134 168 $data = $this->cache->get($this->name); 135 169 … … 146 180 * @return bool Success status 147 181 */ 148 public function touch() {149 182 public function touch() 183 { 150 184 $data = $this->cache->get($this->name); 151 185 … … 166 200 * @return bool Success status 167 201 */ 168 public function unlink() { 202 public function unlink() 203 { 169 204 return $this->cache->set($this->name, null); 170 205 } 171 172 206 } 207 208 class_alias('SimplePie\Cache\Redis', 'SimplePie_Cache_Redis'); -
trunk/src/wp-includes/SimplePie/src/Caption.php
r59140 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie; 44 46 45 47 /** 46 48 * Handles `<media:text>` captions as defined in Media RSS. 47 49 * 48 * Used by {@see SimplePie_Enclosure::get_caption()} and {@see SimplePie_Enclosure::get_captions()}50 * Used by {@see \SimplePie\Enclosure::get_caption()} and {@see \SimplePie\Enclosure::get_captions()} 49 51 * 50 * This class can be overloaded with {@see SimplePie::set_caption_class()}52 * This class can be overloaded with {@see \SimplePie\SimplePie::set_caption_class()} 51 53 * 52 54 * @package SimplePie 53 55 * @subpackage API 54 56 */ 55 class SimplePie_Caption57 class Caption 56 58 { 57 58 59 60 61 62 63 var$type;59 /** 60 * Content type 61 * 62 * @var string 63 * @see get_type() 64 */ 65 public $type; 64 66 65 66 67 68 69 70 71 var$lang;67 /** 68 * Language 69 * 70 * @var string 71 * @see get_language() 72 */ 73 public $lang; 72 74 73 74 75 76 77 78 79 var$startTime;75 /** 76 * Start time 77 * 78 * @var string 79 * @see get_starttime() 80 */ 81 public $startTime; 80 82 81 82 83 84 85 86 87 var$endTime;83 /** 84 * End time 85 * 86 * @var string 87 * @see get_endtime() 88 */ 89 public $endTime; 88 90 89 90 91 92 93 94 95 var$text;91 /** 92 * Caption text 93 * 94 * @var string 95 * @see get_text() 96 */ 97 public $text; 96 98 97 98 99 100 101 102 103 104 105 106 107 108 109 110 99 /** 100 * Constructor, used to input the data 101 * 102 * For documentation on all the parameters, see the corresponding 103 * properties and their accessors 104 */ 105 public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null) 106 { 107 $this->type = $type; 108 $this->lang = $lang; 109 $this->startTime = $startTime; 110 $this->endTime = $endTime; 111 $this->text = $text; 112 } 111 113 112 113 114 115 116 117 118 119 120 121 114 /** 115 * String-ified version 116 * 117 * @return string 118 */ 119 public function __toString() 120 { 121 // There is no $this->data here 122 return md5(serialize($this)); 123 } 122 124 123 /** 124 * Get the end time 125 * 126 * @return string|null Time in the format 'hh:mm:ss.SSS' 127 */ 128 public function get_endtime() 129 { 130 if ($this->endTime !== null) 131 { 132 return $this->endTime; 133 } 125 /** 126 * Get the end time 127 * 128 * @return string|null Time in the format 'hh:mm:ss.SSS' 129 */ 130 public function get_endtime() 131 { 132 if ($this->endTime !== null) { 133 return $this->endTime; 134 } 134 135 135 136 136 return null; 137 } 137 138 138 /** 139 * Get the language 140 * 141 * @link http://tools.ietf.org/html/rfc3066 142 * @return string|null Language code as per RFC 3066 143 */ 144 public function get_language() 145 { 146 if ($this->lang !== null) 147 { 148 return $this->lang; 149 } 139 /** 140 * Get the language 141 * 142 * @link http://tools.ietf.org/html/rfc3066 143 * @return string|null Language code as per RFC 3066 144 */ 145 public function get_language() 146 { 147 if ($this->lang !== null) { 148 return $this->lang; 149 } 150 150 151 152 151 return null; 152 } 153 153 154 /** 155 * Get the start time 156 * 157 * @return string|null Time in the format 'hh:mm:ss.SSS' 158 */ 159 public function get_starttime() 160 { 161 if ($this->startTime !== null) 162 { 163 return $this->startTime; 164 } 154 /** 155 * Get the start time 156 * 157 * @return string|null Time in the format 'hh:mm:ss.SSS' 158 */ 159 public function get_starttime() 160 { 161 if ($this->startTime !== null) { 162 return $this->startTime; 163 } 165 164 166 167 165 return null; 166 } 168 167 169 /** 170 * Get the text of the caption 171 * 172 * @return string|null 173 */ 174 public function get_text() 175 { 176 if ($this->text !== null) 177 { 178 return $this->text; 179 } 168 /** 169 * Get the text of the caption 170 * 171 * @return string|null 172 */ 173 public function get_text() 174 { 175 if ($this->text !== null) { 176 return $this->text; 177 } 180 178 181 182 179 return null; 180 } 183 181 184 /** 185 * Get the content type (not MIME type) 186 * 187 * @return string|null Either 'text' or 'html' 188 */ 189 public function get_type() 190 { 191 if ($this->type !== null) 192 { 193 return $this->type; 194 } 182 /** 183 * Get the content type (not MIME type) 184 * 185 * @return string|null Either 'text' or 'html' 186 */ 187 public function get_type() 188 { 189 if ($this->type !== null) { 190 return $this->type; 191 } 195 192 196 197 193 return null; 194 } 198 195 } 196 197 class_alias('SimplePie\Caption', 'SimplePie_Caption'); -
trunk/src/wp-includes/SimplePie/src/Category.php
r59140 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie; 46 44 47 /** 45 48 * Manages all category-related data 46 49 * 47 * Used by {@see SimplePie_Item::get_category()} and {@see SimplePie_Item::get_categories()}50 * Used by {@see \SimplePie\Item::get_category()} and {@see \SimplePie\Item::get_categories()} 48 51 * 49 * This class can be overloaded with {@see SimplePie::set_category_class()}52 * This class can be overloaded with {@see \SimplePie\SimplePie::set_category_class()} 50 53 * 51 54 * @package SimplePie 52 55 * @subpackage API 53 56 */ 54 class SimplePie_Category57 class Category 55 58 { 56 57 58 59 60 61 62 var$term;59 /** 60 * Category identifier 61 * 62 * @var string|null 63 * @see get_term 64 */ 65 public $term; 63 66 64 65 66 67 68 69 70 var$scheme;67 /** 68 * Categorization scheme identifier 69 * 70 * @var string|null 71 * @see get_scheme() 72 */ 73 public $scheme; 71 74 72 73 74 75 76 77 78 var$label;75 /** 76 * Human readable label 77 * 78 * @var string|null 79 * @see get_label() 80 */ 81 public $label; 79 82 80 81 82 * 83 84 85 86 87 88 89 var$type;83 /** 84 * Category type 85 * 86 * category for <category> 87 * subject for <dc:subject> 88 * 89 * @var string|null 90 * @see get_type() 91 */ 92 public $type; 90 93 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 94 /** 95 * Constructor, used to input the data 96 * 97 * @param string|null $term 98 * @param string|null $scheme 99 * @param string|null $label 100 * @param string|null $type 101 */ 102 public function __construct($term = null, $scheme = null, $label = null, $type = null) 103 { 104 $this->term = $term; 105 $this->scheme = $scheme; 106 $this->label = $label; 107 $this->type = $type; 108 } 106 109 107 108 109 110 111 112 113 114 115 116 110 /** 111 * String-ified version 112 * 113 * @return string 114 */ 115 public function __toString() 116 { 117 // There is no $this->data here 118 return md5(serialize($this)); 119 } 117 120 118 119 120 121 122 123 124 125 126 121 /** 122 * Get the category identifier 123 * 124 * @return string|null 125 */ 126 public function get_term() 127 { 128 return $this->term; 129 } 127 130 128 129 130 131 132 133 134 135 136 131 /** 132 * Get the categorization scheme identifier 133 * 134 * @return string|null 135 */ 136 public function get_scheme() 137 { 138 return $this->scheme; 139 } 137 140 138 /** 139 * Get the human readable label 140 * 141 * @param bool $strict 142 * @return string|null 143 */ 144 public function get_label($strict = false) 145 { 146 if ($this->label === null && $strict !== true) 147 { 148 return $this->get_term(); 149 } 150 return $this->label; 151 } 141 /** 142 * Get the human readable label 143 * 144 * @param bool $strict 145 * @return string|null 146 */ 147 public function get_label($strict = false) 148 { 149 if ($this->label === null && $strict !== true) { 150 return $this->get_term(); 151 } 152 return $this->label; 153 } 152 154 153 154 155 156 157 158 159 160 161 155 /** 156 * Get the category type 157 * 158 * @return string|null 159 */ 160 public function get_type() 161 { 162 return $this->type; 163 } 162 164 } 163 165 166 class_alias('SimplePie\Category', 'SimplePie_Category'); -
trunk/src/wp-includes/SimplePie/src/Content/Type/Sniffer.php
r49176 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie\Content\Type; 44 46 45 47 /** … … 52 54 * 53 55 * 54 * This class can be overloaded with {@see SimplePie::set_content_type_sniffer_class()}56 * This class can be overloaded with {@see \SimplePie\SimplePie::set_content_type_sniffer_class()} 55 57 * 56 58 * @package SimplePie 57 59 * @subpackage HTTP 58 60 */ 59 class S implePie_Content_Type_Sniffer61 class Sniffer 60 62 { 61 /** 62 * File object 63 * 64 * @var SimplePie_File 65 */ 66 var $file; 67 68 /** 69 * Create an instance of the class with the input file 70 * 71 * @param SimplePie_Content_Type_Sniffer $file Input file 72 */ 73 public function __construct($file) 74 { 75 $this->file = $file; 76 } 77 78 /** 79 * Get the Content-Type of the specified file 80 * 81 * @return string Actual Content-Type 82 */ 83 public function get_type() 84 { 85 if (isset($this->file->headers['content-type'])) 86 { 87 if (!isset($this->file->headers['content-encoding']) 88 && ($this->file->headers['content-type'] === 'text/plain' 89 || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1' 90 || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1' 91 || $this->file->headers['content-type'] === 'text/plain; charset=UTF-8')) 92 { 93 return $this->text_or_binary(); 94 } 95 96 if (($pos = strpos($this->file->headers['content-type'], ';')) !== false) 97 { 98 $official = substr($this->file->headers['content-type'], 0, $pos); 99 } 100 else 101 { 102 $official = $this->file->headers['content-type']; 103 } 104 $official = trim(strtolower($official)); 105 106 if ($official === 'unknown/unknown' 107 || $official === 'application/unknown') 108 { 109 return $this->unknown(); 110 } 111 elseif (substr($official, -4) === '+xml' 112 || $official === 'text/xml' 113 || $official === 'application/xml') 114 { 115 return $official; 116 } 117 elseif (substr($official, 0, 6) === 'image/') 118 { 119 if ($return = $this->image()) 120 { 121 return $return; 122 } 123 124 return $official; 125 } 126 elseif ($official === 'text/html') 127 { 128 return $this->feed_or_html(); 129 } 130 131 return $official; 132 } 133 134 return $this->unknown(); 135 } 136 137 /** 138 * Sniff text or binary 139 * 140 * @return string Actual Content-Type 141 */ 142 public function text_or_binary() 143 { 144 if (substr($this->file->body, 0, 2) === "\xFE\xFF" 145 || substr($this->file->body, 0, 2) === "\xFF\xFE" 146 || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF" 147 || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF") 148 { 149 return 'text/plain'; 150 } 151 elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body)) 152 { 153 return 'application/octet-stream'; 154 } 155 156 return 'text/plain'; 157 } 158 159 /** 160 * Sniff unknown 161 * 162 * @return string Actual Content-Type 163 */ 164 public function unknown() 165 { 166 $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20"); 167 if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html' 168 || strtolower(substr($this->file->body, $ws, 5)) === '<html' 169 || strtolower(substr($this->file->body, $ws, 7)) === '<script') 170 { 171 return 'text/html'; 172 } 173 elseif (substr($this->file->body, 0, 5) === '%PDF-') 174 { 175 return 'application/pdf'; 176 } 177 elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-') 178 { 179 return 'application/postscript'; 180 } 181 elseif (substr($this->file->body, 0, 6) === 'GIF87a' 182 || substr($this->file->body, 0, 6) === 'GIF89a') 183 { 184 return 'image/gif'; 185 } 186 elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") 187 { 188 return 'image/png'; 189 } 190 elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF") 191 { 192 return 'image/jpeg'; 193 } 194 elseif (substr($this->file->body, 0, 2) === "\x42\x4D") 195 { 196 return 'image/bmp'; 197 } 198 elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00") 199 { 200 return 'image/vnd.microsoft.icon'; 201 } 202 203 return $this->text_or_binary(); 204 } 205 206 /** 207 * Sniff images 208 * 209 * @return string Actual Content-Type 210 */ 211 public function image() 212 { 213 if (substr($this->file->body, 0, 6) === 'GIF87a' 214 || substr($this->file->body, 0, 6) === 'GIF89a') 215 { 216 return 'image/gif'; 217 } 218 elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") 219 { 220 return 'image/png'; 221 } 222 elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF") 223 { 224 return 'image/jpeg'; 225 } 226 elseif (substr($this->file->body, 0, 2) === "\x42\x4D") 227 { 228 return 'image/bmp'; 229 } 230 elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00") 231 { 232 return 'image/vnd.microsoft.icon'; 233 } 234 235 return false; 236 } 237 238 /** 239 * Sniff HTML 240 * 241 * @return string Actual Content-Type 242 */ 243 public function feed_or_html() 244 { 245 $len = strlen($this->file->body); 246 $pos = strspn($this->file->body, "\x09\x0A\x0D\x20\xEF\xBB\xBF"); 247 248 while ($pos < $len) 249 { 250 switch ($this->file->body[$pos]) 251 { 252 case "\x09": 253 case "\x0A": 254 case "\x0D": 255 case "\x20": 256 $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos); 257 continue 2; 258 259 case '<': 260 $pos++; 261 break; 262 263 default: 264 return 'text/html'; 265 } 266 267 if (substr($this->file->body, $pos, 3) === '!--') 268 { 269 $pos += 3; 270 if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false) 271 { 272 $pos += 3; 273 } 274 else 275 { 276 return 'text/html'; 277 } 278 } 279 elseif (substr($this->file->body, $pos, 1) === '!') 280 { 281 if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false) 282 { 283 $pos++; 284 } 285 else 286 { 287 return 'text/html'; 288 } 289 } 290 elseif (substr($this->file->body, $pos, 1) === '?') 291 { 292 if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false) 293 { 294 $pos += 2; 295 } 296 else 297 { 298 return 'text/html'; 299 } 300 } 301 elseif (substr($this->file->body, $pos, 3) === 'rss' 302 || substr($this->file->body, $pos, 7) === 'rdf:RDF') 303 { 304 return 'application/rss+xml'; 305 } 306 elseif (substr($this->file->body, $pos, 4) === 'feed') 307 { 308 return 'application/atom+xml'; 309 } 310 else 311 { 312 return 'text/html'; 313 } 314 } 315 316 return 'text/html'; 317 } 63 /** 64 * File object 65 * 66 * @var \SimplePie\File 67 */ 68 public $file; 69 70 /** 71 * Create an instance of the class with the input file 72 * 73 * @param Sniffer $file Input file 74 */ 75 public function __construct($file) 76 { 77 $this->file = $file; 78 } 79 80 /** 81 * Get the Content-Type of the specified file 82 * 83 * @return string Actual Content-Type 84 */ 85 public function get_type() 86 { 87 if (isset($this->file->headers['content-type'])) { 88 if (!isset($this->file->headers['content-encoding']) 89 && ($this->file->headers['content-type'] === 'text/plain' 90 || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1' 91 || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1' 92 || $this->file->headers['content-type'] === 'text/plain; charset=UTF-8')) { 93 return $this->text_or_binary(); 94 } 95 96 if (($pos = strpos($this->file->headers['content-type'], ';')) !== false) { 97 $official = substr($this->file->headers['content-type'], 0, $pos); 98 } else { 99 $official = $this->file->headers['content-type']; 100 } 101 $official = trim(strtolower($official)); 102 103 if ($official === 'unknown/unknown' 104 || $official === 'application/unknown') { 105 return $this->unknown(); 106 } elseif (substr($official, -4) === '+xml' 107 || $official === 'text/xml' 108 || $official === 'application/xml') { 109 return $official; 110 } elseif (substr($official, 0, 6) === 'image/') { 111 if ($return = $this->image()) { 112 return $return; 113 } 114 115 return $official; 116 } elseif ($official === 'text/html') { 117 return $this->feed_or_html(); 118 } 119 120 return $official; 121 } 122 123 return $this->unknown(); 124 } 125 126 /** 127 * Sniff text or binary 128 * 129 * @return string Actual Content-Type 130 */ 131 public function text_or_binary() 132 { 133 if (substr($this->file->body, 0, 2) === "\xFE\xFF" 134 || substr($this->file->body, 0, 2) === "\xFF\xFE" 135 || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF" 136 || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF") { 137 return 'text/plain'; 138 } elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body)) { 139 return 'application/octet-stream'; 140 } 141 142 return 'text/plain'; 143 } 144 145 /** 146 * Sniff unknown 147 * 148 * @return string Actual Content-Type 149 */ 150 public function unknown() 151 { 152 $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20"); 153 if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html' 154 || strtolower(substr($this->file->body, $ws, 5)) === '<html' 155 || strtolower(substr($this->file->body, $ws, 7)) === '<script') { 156 return 'text/html'; 157 } elseif (substr($this->file->body, 0, 5) === '%PDF-') { 158 return 'application/pdf'; 159 } elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-') { 160 return 'application/postscript'; 161 } elseif (substr($this->file->body, 0, 6) === 'GIF87a' 162 || substr($this->file->body, 0, 6) === 'GIF89a') { 163 return 'image/gif'; 164 } elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") { 165 return 'image/png'; 166 } elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF") { 167 return 'image/jpeg'; 168 } elseif (substr($this->file->body, 0, 2) === "\x42\x4D") { 169 return 'image/bmp'; 170 } elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00") { 171 return 'image/vnd.microsoft.icon'; 172 } 173 174 return $this->text_or_binary(); 175 } 176 177 /** 178 * Sniff images 179 * 180 * @return string Actual Content-Type 181 */ 182 public function image() 183 { 184 if (substr($this->file->body, 0, 6) === 'GIF87a' 185 || substr($this->file->body, 0, 6) === 'GIF89a') { 186 return 'image/gif'; 187 } elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") { 188 return 'image/png'; 189 } elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF") { 190 return 'image/jpeg'; 191 } elseif (substr($this->file->body, 0, 2) === "\x42\x4D") { 192 return 'image/bmp'; 193 } elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00") { 194 return 'image/vnd.microsoft.icon'; 195 } 196 197 return false; 198 } 199 200 /** 201 * Sniff HTML 202 * 203 * @return string Actual Content-Type 204 */ 205 public function feed_or_html() 206 { 207 $len = strlen($this->file->body); 208 $pos = strspn($this->file->body, "\x09\x0A\x0D\x20\xEF\xBB\xBF"); 209 210 while ($pos < $len) { 211 switch ($this->file->body[$pos]) { 212 case "\x09": 213 case "\x0A": 214 case "\x0D": 215 case "\x20": 216 $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos); 217 continue 2; 218 219 case '<': 220 $pos++; 221 break; 222 223 default: 224 return 'text/html'; 225 } 226 227 if (substr($this->file->body, $pos, 3) === '!--') { 228 $pos += 3; 229 if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false) { 230 $pos += 3; 231 } else { 232 return 'text/html'; 233 } 234 } elseif (substr($this->file->body, $pos, 1) === '!') { 235 if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false) { 236 $pos++; 237 } else { 238 return 'text/html'; 239 } 240 } elseif (substr($this->file->body, $pos, 1) === '?') { 241 if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false) { 242 $pos += 2; 243 } else { 244 return 'text/html'; 245 } 246 } elseif (substr($this->file->body, $pos, 3) === 'rss' 247 || substr($this->file->body, $pos, 7) === 'rdf:RDF') { 248 return 'application/rss+xml'; 249 } elseif (substr($this->file->body, $pos, 4) === 'feed') { 250 return 'application/atom+xml'; 251 } else { 252 return 'text/html'; 253 } 254 } 255 256 return 'text/html'; 257 } 318 258 } 259 260 class_alias('SimplePie\Content\Type\Sniffer', 'SimplePie_Content_Type_Sniffer'); -
trunk/src/wp-includes/SimplePie/src/Copyright.php
r59140 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie; 46 44 47 /** 45 48 * Manages `<media:copyright>` copyright tags as defined in Media RSS 46 49 * 47 * Used by {@see SimplePie_Enclosure::get_copyright()}50 * Used by {@see \SimplePie\Enclosure::get_copyright()} 48 51 * 49 * This class can be overloaded with {@see SimplePie::set_copyright_class()}52 * This class can be overloaded with {@see \SimplePie\SimplePie::set_copyright_class()} 50 53 * 51 54 * @package SimplePie 52 55 * @subpackage API 53 56 */ 54 class SimplePie_Copyright57 class Copyright 55 58 { 56 57 58 59 60 61 62 var$url;59 /** 60 * Copyright URL 61 * 62 * @var string 63 * @see get_url() 64 */ 65 public $url; 63 66 64 65 66 67 68 69 70 var$label;67 /** 68 * Attribution 69 * 70 * @var string 71 * @see get_attribution() 72 */ 73 public $label; 71 74 72 73 74 75 76 77 78 79 80 81 82 75 /** 76 * Constructor, used to input the data 77 * 78 * For documentation on all the parameters, see the corresponding 79 * properties and their accessors 80 */ 81 public function __construct($url = null, $label = null) 82 { 83 $this->url = $url; 84 $this->label = $label; 85 } 83 86 84 85 86 87 88 89 90 91 92 93 87 /** 88 * String-ified version 89 * 90 * @return string 91 */ 92 public function __toString() 93 { 94 // There is no $this->data here 95 return md5(serialize($this)); 96 } 94 97 95 /** 96 * Get the copyright URL 97 * 98 * @return string|null URL to copyright information 99 */ 100 public function get_url() 101 { 102 if ($this->url !== null) 103 { 104 return $this->url; 105 } 98 /** 99 * Get the copyright URL 100 * 101 * @return string|null URL to copyright information 102 */ 103 public function get_url() 104 { 105 if ($this->url !== null) { 106 return $this->url; 107 } 106 108 107 108 109 return null; 110 } 109 111 110 /** 111 * Get the attribution text 112 * 113 * @return string|null 114 */ 115 public function get_attribution() 116 { 117 if ($this->label !== null) 118 { 119 return $this->label; 120 } 112 /** 113 * Get the attribution text 114 * 115 * @return string|null 116 */ 117 public function get_attribution() 118 { 119 if ($this->label !== null) { 120 return $this->label; 121 } 121 122 122 123 123 return null; 124 } 124 125 } 126 127 class_alias('SimplePie\Copyright', 'SimplePie_Copyright'); -
trunk/src/wp-includes/SimplePie/src/Credit.php
r59140 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie; 46 44 47 /** 45 48 * Handles `<media:credit>` as defined in Media RSS 46 49 * 47 * Used by {@see SimplePie_Enclosure::get_credit()} and {@see SimplePie_Enclosure::get_credits()}50 * Used by {@see \SimplePie\Enclosure::get_credit()} and {@see \SimplePie\Enclosure::get_credits()} 48 51 * 49 * This class can be overloaded with {@see SimplePie::set_credit_class()}52 * This class can be overloaded with {@see \SimplePie\SimplePie::set_credit_class()} 50 53 * 51 54 * @package SimplePie 52 55 * @subpackage API 53 56 */ 54 class SimplePie_Credit57 class Credit 55 58 { 56 57 58 59 60 61 62 var$role;59 /** 60 * Credited role 61 * 62 * @var string 63 * @see get_role() 64 */ 65 public $role; 63 66 64 65 66 67 68 69 70 var$scheme;67 /** 68 * Organizational scheme 69 * 70 * @var string 71 * @see get_scheme() 72 */ 73 public $scheme; 71 74 72 73 74 75 76 77 78 var$name;75 /** 76 * Credited name 77 * 78 * @var string 79 * @see get_name() 80 */ 81 public $name; 79 82 80 81 82 83 84 85 86 87 88 89 90 91 83 /** 84 * Constructor, used to input the data 85 * 86 * For documentation on all the parameters, see the corresponding 87 * properties and their accessors 88 */ 89 public function __construct($role = null, $scheme = null, $name = null) 90 { 91 $this->role = $role; 92 $this->scheme = $scheme; 93 $this->name = $name; 94 } 92 95 93 94 95 96 97 98 99 100 101 102 96 /** 97 * String-ified version 98 * 99 * @return string 100 */ 101 public function __toString() 102 { 103 // There is no $this->data here 104 return md5(serialize($this)); 105 } 103 106 104 /** 105 * Get the role of the person receiving credit 106 * 107 * @return string|null 108 */ 109 public function get_role() 110 { 111 if ($this->role !== null) 112 { 113 return $this->role; 114 } 107 /** 108 * Get the role of the person receiving credit 109 * 110 * @return string|null 111 */ 112 public function get_role() 113 { 114 if ($this->role !== null) { 115 return $this->role; 116 } 115 117 116 117 118 return null; 119 } 118 120 119 /** 120 * Get the organizational scheme 121 * 122 * @return string|null 123 */ 124 public function get_scheme() 125 { 126 if ($this->scheme !== null) 127 { 128 return $this->scheme; 129 } 121 /** 122 * Get the organizational scheme 123 * 124 * @return string|null 125 */ 126 public function get_scheme() 127 { 128 if ($this->scheme !== null) { 129 return $this->scheme; 130 } 130 131 131 132 132 return null; 133 } 133 134 134 /** 135 * Get the credited person/entity's name 136 * 137 * @return string|null 138 */ 139 public function get_name() 140 { 141 if ($this->name !== null) 142 { 143 return $this->name; 144 } 135 /** 136 * Get the credited person/entity's name 137 * 138 * @return string|null 139 */ 140 public function get_name() 141 { 142 if ($this->name !== null) { 143 return $this->name; 144 } 145 145 146 147 146 return null; 147 } 148 148 } 149 150 class_alias('SimplePie\Credit', 'SimplePie_Credit'); -
trunk/src/wp-includes/SimplePie/src/Enclosure.php
r59140 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie; 46 44 47 /** 45 48 * Handles everything related to enclosures (including Media RSS and iTunes RSS) 46 49 * 47 * Used by {@see SimplePie_Item::get_enclosure()} and {@see SimplePie_Item::get_enclosures()}50 * Used by {@see \SimplePie\Item::get_enclosure()} and {@see \SimplePie\Item::get_enclosures()} 48 51 * 49 * This class can be overloaded with {@see SimplePie::set_enclosure_class()}52 * This class can be overloaded with {@see \SimplePie\SimplePie::set_enclosure_class()} 50 53 * 51 54 * @package SimplePie 52 55 * @subpackage API 53 56 */ 54 class SimplePie_Enclosure57 class Enclosure 55 58 { 56 /** 57 * @var string 58 * @see get_bitrate() 59 */ 60 var $bitrate; 61 62 /** 63 * @var array 64 * @see get_captions() 65 */ 66 var $captions; 67 68 /** 69 * @var array 70 * @see get_categories() 71 */ 72 var $categories; 73 74 /** 75 * @var int 76 * @see get_channels() 77 */ 78 var $channels; 79 80 /** 81 * @var SimplePie_Copyright 82 * @see get_copyright() 83 */ 84 var $copyright; 85 86 /** 87 * @var array 88 * @see get_credits() 89 */ 90 var $credits; 91 92 /** 93 * @var string 94 * @see get_description() 95 */ 96 var $description; 97 98 /** 99 * @var int 100 * @see get_duration() 101 */ 102 var $duration; 103 104 /** 105 * @var string 106 * @see get_expression() 107 */ 108 var $expression; 109 110 /** 111 * @var string 112 * @see get_framerate() 113 */ 114 var $framerate; 115 116 /** 117 * @var string 118 * @see get_handler() 119 */ 120 var $handler; 121 122 /** 123 * @var array 124 * @see get_hashes() 125 */ 126 var $hashes; 127 128 /** 129 * @var string 130 * @see get_height() 131 */ 132 var $height; 133 134 /** 135 * @deprecated 136 * @var null 137 */ 138 var $javascript; 139 140 /** 141 * @var array 142 * @see get_keywords() 143 */ 144 var $keywords; 145 146 /** 147 * @var string 148 * @see get_language() 149 */ 150 var $lang; 151 152 /** 153 * @var string 154 * @see get_length() 155 */ 156 var $length; 157 158 /** 159 * @var string 160 * @see get_link() 161 */ 162 var $link; 163 164 /** 165 * @var string 166 * @see get_medium() 167 */ 168 var $medium; 169 170 /** 171 * @var string 172 * @see get_player() 173 */ 174 var $player; 175 176 /** 177 * @var array 178 * @see get_ratings() 179 */ 180 var $ratings; 181 182 /** 183 * @var array 184 * @see get_restrictions() 185 */ 186 var $restrictions; 187 188 /** 189 * @var string 190 * @see get_sampling_rate() 191 */ 192 var $samplingrate; 193 194 /** 195 * @var array 196 * @see get_thumbnails() 197 */ 198 var $thumbnails; 199 200 /** 201 * @var string 202 * @see get_title() 203 */ 204 var $title; 205 206 /** 207 * @var string 208 * @see get_type() 209 */ 210 var $type; 211 212 /** 213 * @var string 214 * @see get_width() 215 */ 216 var $width; 217 218 /** 219 * Constructor, used to input the data 220 * 221 * For documentation on all the parameters, see the corresponding 222 * properties and their accessors 223 * 224 * @uses idna_convert If available, this will convert an IDN 225 */ 226 public function __construct($link = null, $type = null, $length = null, $javascript = null, $bitrate = null, $captions = null, $categories = null, $channels = null, $copyright = null, $credits = null, $description = null, $duration = null, $expression = null, $framerate = null, $hashes = null, $height = null, $keywords = null, $lang = null, $medium = null, $player = null, $ratings = null, $restrictions = null, $samplingrate = null, $thumbnails = null, $title = null, $width = null) 227 { 228 $this->bitrate = $bitrate; 229 $this->captions = $captions; 230 $this->categories = $categories; 231 $this->channels = $channels; 232 $this->copyright = $copyright; 233 $this->credits = $credits; 234 $this->description = $description; 235 $this->duration = $duration; 236 $this->expression = $expression; 237 $this->framerate = $framerate; 238 $this->hashes = $hashes; 239 $this->height = $height; 240 $this->keywords = $keywords; 241 $this->lang = $lang; 242 $this->length = $length; 243 $this->link = $link; 244 $this->medium = $medium; 245 $this->player = $player; 246 $this->ratings = $ratings; 247 $this->restrictions = $restrictions; 248 $this->samplingrate = $samplingrate; 249 $this->thumbnails = $thumbnails; 250 $this->title = $title; 251 $this->type = $type; 252 $this->width = $width; 253 254 if (class_exists('idna_convert')) 255 { 256 $idn = new idna_convert(); 257 $parsed = SimplePie_Misc::parse_url($link); 258 $this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']); 259 } 260 $this->handler = $this->get_handler(); // Needs to load last 261 } 262 263 /** 264 * String-ified version 265 * 266 * @return string 267 */ 268 public function __toString() 269 { 270 // There is no $this->data here 271 return md5(serialize($this)); 272 } 273 274 /** 275 * Get the bitrate 276 * 277 * @return string|null 278 */ 279 public function get_bitrate() 280 { 281 if ($this->bitrate !== null) 282 { 283 return $this->bitrate; 284 } 285 286 return null; 287 } 288 289 /** 290 * Get a single caption 291 * 292 * @param int $key 293 * @return SimplePie_Caption|null 294 */ 295 public function get_caption($key = 0) 296 { 297 $captions = $this->get_captions(); 298 if (isset($captions[$key])) 299 { 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 { 315 return $this->captions; 316 } 317 318 return null; 319 } 320 321 /** 322 * Get a single category 323 * 324 * @param int $key 325 * @return SimplePie_Category|null 326 */ 327 public function get_category($key = 0) 328 { 329 $categories = $this->get_categories(); 330 if (isset($categories[$key])) 331 { 332 return $categories[$key]; 333 } 334 335 return null; 336 } 337 338 /** 339 * Get all categories 340 * 341 * @return array|null Array of {@see SimplePie_Category} objects 342 */ 343 public function get_categories() 344 { 345 if ($this->categories !== null) 346 { 347 return $this->categories; 348 } 349 350 return null; 351 } 352 353 /** 354 * Get the number of audio channels 355 * 356 * @return int|null 357 */ 358 public function get_channels() 359 { 360 if ($this->channels !== null) 361 { 362 return $this->channels; 363 } 364 365 return null; 366 } 367 368 /** 369 * Get the copyright information 370 * 371 * @return SimplePie_Copyright|null 372 */ 373 public function get_copyright() 374 { 375 if ($this->copyright !== null) 376 { 377 return $this->copyright; 378 } 379 380 return null; 381 } 382 383 /** 384 * Get a single credit 385 * 386 * @param int $key 387 * @return SimplePie_Credit|null 388 */ 389 public function get_credit($key = 0) 390 { 391 $credits = $this->get_credits(); 392 if (isset($credits[$key])) 393 { 394 return $credits[$key]; 395 } 396 397 return null; 398 } 399 400 /** 401 * Get all credits 402 * 403 * @return array|null Array of {@see SimplePie_Credit} objects 404 */ 405 public function get_credits() 406 { 407 if ($this->credits !== null) 408 { 409 return $this->credits; 410 } 411 412 return null; 413 } 414 415 /** 416 * Get the description of the enclosure 417 * 418 * @return string|null 419 */ 420 public function get_description() 421 { 422 if ($this->description !== null) 423 { 424 return $this->description; 425 } 426 427 return null; 428 } 429 430 /** 431 * Get the duration of the enclosure 432 * 433 * @param bool $convert Convert seconds into hh:mm:ss 434 * @return string|int|null 'hh:mm:ss' string if `$convert` was specified, otherwise integer (or null if none found) 435 */ 436 public function get_duration($convert = false) 437 { 438 if ($this->duration !== null) 439 { 440 if ($convert) 441 { 442 $time = SimplePie_Misc::time_hms($this->duration); 443 return $time; 444 } 445 446 return $this->duration; 447 } 448 449 return null; 450 } 451 452 /** 453 * Get the expression 454 * 455 * @return string Probably one of 'sample', 'full', 'nonstop', 'clip'. Defaults to 'full' 456 */ 457 public function get_expression() 458 { 459 if ($this->expression !== null) 460 { 461 return $this->expression; 462 } 463 464 return 'full'; 465 } 466 467 /** 468 * Get the file extension 469 * 470 * @return string|null 471 */ 472 public function get_extension() 473 { 474 if ($this->link !== null) 475 { 476 $url = SimplePie_Misc::parse_url($this->link); 477 if ($url['path'] !== '') 478 { 479 return pathinfo($url['path'], PATHINFO_EXTENSION); 480 } 481 } 482 return null; 483 } 484 485 /** 486 * Get the framerate (in frames-per-second) 487 * 488 * @return string|null 489 */ 490 public function get_framerate() 491 { 492 if ($this->framerate !== null) 493 { 494 return $this->framerate; 495 } 496 497 return null; 498 } 499 500 /** 501 * Get the preferred handler 502 * 503 * @return string|null One of 'flash', 'fmedia', 'quicktime', 'wmedia', 'mp3' 504 */ 505 public function get_handler() 506 { 507 return $this->get_real_type(true); 508 } 509 510 /** 511 * Get a single hash 512 * 513 * @link http://www.rssboard.org/media-rss#media-hash 514 * @param int $key 515 * @return string|null Hash as per `media:hash`, prefixed with "$algo:" 516 */ 517 public function get_hash($key = 0) 518 { 519 $hashes = $this->get_hashes(); 520 if (isset($hashes[$key])) 521 { 522 return $hashes[$key]; 523 } 524 525 return null; 526 } 527 528 /** 529 * Get all credits 530 * 531 * @return array|null Array of strings, see {@see get_hash()} 532 */ 533 public function get_hashes() 534 { 535 if ($this->hashes !== null) 536 { 537 return $this->hashes; 538 } 539 540 return null; 541 } 542 543 /** 544 * Get the height 545 * 546 * @return string|null 547 */ 548 public function get_height() 549 { 550 if ($this->height !== null) 551 { 552 return $this->height; 553 } 554 555 return null; 556 } 557 558 /** 559 * Get the language 560 * 561 * @link http://tools.ietf.org/html/rfc3066 562 * @return string|null Language code as per RFC 3066 563 */ 564 public function get_language() 565 { 566 if ($this->lang !== null) 567 { 568 return $this->lang; 569 } 570 571 return null; 572 } 573 574 /** 575 * Get a single keyword 576 * 577 * @param int $key 578 * @return string|null 579 */ 580 public function get_keyword($key = 0) 581 { 582 $keywords = $this->get_keywords(); 583 if (isset($keywords[$key])) 584 { 585 return $keywords[$key]; 586 } 587 588 return null; 589 } 590 591 /** 592 * Get all keywords 593 * 594 * @return array|null Array of strings 595 */ 596 public function get_keywords() 597 { 598 if ($this->keywords !== null) 599 { 600 return $this->keywords; 601 } 602 603 return null; 604 } 605 606 /** 607 * Get length 608 * 609 * @return float Length in bytes 610 */ 611 public function get_length() 612 { 613 if ($this->length !== null) 614 { 615 return $this->length; 616 } 617 618 return null; 619 } 620 621 /** 622 * Get the URL 623 * 624 * @return string|null 625 */ 626 public function get_link() 627 { 628 if ($this->link !== null) 629 { 630 return urldecode($this->link); 631 } 632 633 return null; 634 } 635 636 /** 637 * Get the medium 638 * 639 * @link http://www.rssboard.org/media-rss#media-content 640 * @return string|null Should be one of 'image', 'audio', 'video', 'document', 'executable' 641 */ 642 public function get_medium() 643 { 644 if ($this->medium !== null) 645 { 646 return $this->medium; 647 } 648 649 return null; 650 } 651 652 /** 653 * Get the player URL 654 * 655 * Typically the same as {@see get_permalink()} 656 * @return string|null Player URL 657 */ 658 public function get_player() 659 { 660 if ($this->player !== null) 661 { 662 return $this->player; 663 } 664 665 return null; 666 } 667 668 /** 669 * Get a single rating 670 * 671 * @param int $key 672 * @return SimplePie_Rating|null 673 */ 674 public function get_rating($key = 0) 675 { 676 $ratings = $this->get_ratings(); 677 if (isset($ratings[$key])) 678 { 679 return $ratings[$key]; 680 } 681 682 return null; 683 } 684 685 /** 686 * Get all ratings 687 * 688 * @return array|null Array of {@see SimplePie_Rating} objects 689 */ 690 public function get_ratings() 691 { 692 if ($this->ratings !== null) 693 { 694 return $this->ratings; 695 } 696 697 return null; 698 } 699 700 /** 701 * Get a single restriction 702 * 703 * @param int $key 704 * @return SimplePie_Restriction|null 705 */ 706 public function get_restriction($key = 0) 707 { 708 $restrictions = $this->get_restrictions(); 709 if (isset($restrictions[$key])) 710 { 711 return $restrictions[$key]; 712 } 713 714 return null; 715 } 716 717 /** 718 * Get all restrictions 719 * 720 * @return array|null Array of {@see SimplePie_Restriction} objects 721 */ 722 public function get_restrictions() 723 { 724 if ($this->restrictions !== null) 725 { 726 return $this->restrictions; 727 } 728 729 return null; 730 } 731 732 /** 733 * Get the sampling rate (in kHz) 734 * 735 * @return string|null 736 */ 737 public function get_sampling_rate() 738 { 739 if ($this->samplingrate !== null) 740 { 741 return $this->samplingrate; 742 } 743 744 return null; 745 } 746 747 /** 748 * Get the file size (in MiB) 749 * 750 * @return float|null File size in mebibytes (1048 bytes) 751 */ 752 public function get_size() 753 { 754 $length = $this->get_length(); 755 if ($length !== null) 756 { 757 return round($length/1048576, 2); 758 } 759 760 return null; 761 } 762 763 /** 764 * Get a single thumbnail 765 * 766 * @param int $key 767 * @return string|null Thumbnail URL 768 */ 769 public function get_thumbnail($key = 0) 770 { 771 $thumbnails = $this->get_thumbnails(); 772 if (isset($thumbnails[$key])) 773 { 774 return $thumbnails[$key]; 775 } 776 777 return null; 778 } 779 780 /** 781 * Get all thumbnails 782 * 783 * @return array|null Array of thumbnail URLs 784 */ 785 public function get_thumbnails() 786 { 787 if ($this->thumbnails !== null) 788 { 789 return $this->thumbnails; 790 } 791 792 return null; 793 } 794 795 /** 796 * Get the title 797 * 798 * @return string|null 799 */ 800 public function get_title() 801 { 802 if ($this->title !== null) 803 { 804 return $this->title; 805 } 806 807 return null; 808 } 809 810 /** 811 * Get mimetype of the enclosure 812 * 813 * @see get_real_type() 814 * @return string|null MIME type 815 */ 816 public function get_type() 817 { 818 if ($this->type !== null) 819 { 820 return $this->type; 821 } 822 823 return null; 824 } 825 826 /** 827 * Get the width 828 * 829 * @return string|null 830 */ 831 public function get_width() 832 { 833 if ($this->width !== null) 834 { 835 return $this->width; 836 } 837 838 return null; 839 } 840 841 /** 842 * Embed the enclosure using `<embed>` 843 * 844 * @deprecated Use the second parameter to {@see embed} instead 845 * 846 * @param array|string $options See first paramter to {@see embed} 847 * @return string HTML string to output 848 */ 849 public function native_embed($options='') 850 { 851 return $this->embed($options, true); 852 } 853 854 /** 855 * Embed the enclosure using Javascript 856 * 857 * `$options` is an array or comma-separated key:value string, with the 858 * following properties: 859 * 860 * - `alt` (string): Alternate content for when an end-user does not have 861 * the appropriate handler installed or when a file type is 862 * unsupported. Can be any text or HTML. Defaults to blank. 863 * - `altclass` (string): If a file type is unsupported, the end-user will 864 * see the alt text (above) linked directly to the content. That link 865 * will have this value as its class name. Defaults to blank. 866 * - `audio` (string): This is an image that should be used as a 867 * placeholder for audio files before they're loaded (QuickTime-only). 868 * Can be any relative or absolute URL. Defaults to blank. 869 * - `bgcolor` (string): The background color for the media, if not 870 * already transparent. Defaults to `#ffffff`. 871 * - `height` (integer): The height of the embedded media. Accepts any 872 * numeric pixel value (such as `360`) or `auto`. Defaults to `auto`, 873 * and it is recommended that you use this default. 874 * - `loop` (boolean): Do you want the media to loop when it's done? 875 * Defaults to `false`. 876 * - `mediaplayer` (string): The location of the included 877 * `mediaplayer.swf` file. This allows for the playback of Flash Video 878 * (`.flv`) files, and is the default handler for non-Odeo MP3's. 879 * Defaults to blank. 880 * - `video` (string): This is an image that should be used as a 881 * placeholder for video files before they're loaded (QuickTime-only). 882 * Can be any relative or absolute URL. Defaults to blank. 883 * - `width` (integer): The width of the embedded media. Accepts any 884 * numeric pixel value (such as `480`) or `auto`. Defaults to `auto`, 885 * and it is recommended that you use this default. 886 * - `widescreen` (boolean): Is the enclosure widescreen or standard? 887 * This applies only to video enclosures, and will automatically resize 888 * the content appropriately. Defaults to `false`, implying 4:3 mode. 889 * 890 * Note: Non-widescreen (4:3) mode with `width` and `height` set to `auto` 891 * will default to 480x360 video resolution. Widescreen (16:9) mode with 892 * `width` and `height` set to `auto` will default to 480x270 video resolution. 893 * 894 * @todo If the dimensions for media:content are defined, use them when width/height are set to 'auto'. 895 * @param array|string $options Comma-separated key:value list, or array 896 * @param bool $native Use `<embed>` 897 * @return string HTML string to output 898 */ 899 public function embed($options = '', $native = false) 900 { 901 // Set up defaults 902 $audio = ''; 903 $video = ''; 904 $alt = ''; 905 $altclass = ''; 906 $loop = 'false'; 907 $width = 'auto'; 908 $height = 'auto'; 909 $bgcolor = '#ffffff'; 910 $mediaplayer = ''; 911 $widescreen = false; 912 $handler = $this->get_handler(); 913 $type = $this->get_real_type(); 914 915 // Process options and reassign values as necessary 916 if (is_array($options)) 917 { 918 extract($options); 919 } 920 else 921 { 922 $options = explode(',', $options); 923 foreach($options as $option) 924 { 925 $opt = explode(':', $option, 2); 926 if (isset($opt[0], $opt[1])) 927 { 928 $opt[0] = trim($opt[0]); 929 $opt[1] = trim($opt[1]); 930 switch ($opt[0]) 931 { 932 case 'audio': 933 $audio = $opt[1]; 934 break; 935 936 case 'video': 937 $video = $opt[1]; 938 break; 939 940 case 'alt': 941 $alt = $opt[1]; 942 break; 943 944 case 'altclass': 945 $altclass = $opt[1]; 946 break; 947 948 case 'loop': 949 $loop = $opt[1]; 950 break; 951 952 case 'width': 953 $width = $opt[1]; 954 break; 955 956 case 'height': 957 $height = $opt[1]; 958 break; 959 960 case 'bgcolor': 961 $bgcolor = $opt[1]; 962 break; 963 964 case 'mediaplayer': 965 $mediaplayer = $opt[1]; 966 break; 967 968 case 'widescreen': 969 $widescreen = $opt[1]; 970 break; 971 } 972 } 973 } 974 } 975 976 $mime = explode('/', $type, 2); 977 $mime = $mime[0]; 978 979 // Process values for 'auto' 980 if ($width === 'auto') 981 { 982 if ($mime === 'video') 983 { 984 if ($height === 'auto') 985 { 986 $width = 480; 987 } 988 elseif ($widescreen) 989 { 990 $width = round((intval($height)/9)*16); 991 } 992 else 993 { 994 $width = round((intval($height)/3)*4); 995 } 996 } 997 else 998 { 999 $width = '100%'; 1000 } 1001 } 1002 1003 if ($height === 'auto') 1004 { 1005 if ($mime === 'audio') 1006 { 1007 $height = 0; 1008 } 1009 elseif ($mime === 'video') 1010 { 1011 if ($width === 'auto') 1012 { 1013 if ($widescreen) 1014 { 1015 $height = 270; 1016 } 1017 else 1018 { 1019 $height = 360; 1020 } 1021 } 1022 elseif ($widescreen) 1023 { 1024 $height = round((intval($width)/16)*9); 1025 } 1026 else 1027 { 1028 $height = round((intval($width)/4)*3); 1029 } 1030 } 1031 else 1032 { 1033 $height = 376; 1034 } 1035 } 1036 elseif ($mime === 'audio') 1037 { 1038 $height = 0; 1039 } 1040 1041 // Set proper placeholder value 1042 if ($mime === 'audio') 1043 { 1044 $placeholder = $audio; 1045 } 1046 elseif ($mime === 'video') 1047 { 1048 $placeholder = $video; 1049 } 1050 1051 $embed = ''; 1052 1053 // Flash 1054 if ($handler === 'flash') 1055 { 1056 if ($native) 1057 { 1058 $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>"; 1059 } 1060 else 1061 { 1062 $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>"; 1063 } 1064 } 1065 1066 // Flash Media Player file types. 1067 // Preferred handler for MP3 file types. 1068 elseif ($handler === 'fmedia' || ($handler === 'mp3' && $mediaplayer !== '')) 1069 { 1070 $height += 20; 1071 if ($native) 1072 { 1073 $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>"; 1074 } 1075 else 1076 { 1077 $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>"; 1078 } 1079 } 1080 1081 // QuickTime 7 file types. Need to test with QuickTime 6. 1082 // Only handle MP3's if the Flash Media Player is not present. 1083 elseif ($handler === 'quicktime' || ($handler === 'mp3' && $mediaplayer === '')) 1084 { 1085 $height += 16; 1086 if ($native) 1087 { 1088 if ($placeholder !== '') 1089 { 1090 $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>"; 1091 } 1092 else 1093 { 1094 $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>"; 1095 } 1096 } 1097 else 1098 { 1099 $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>"; 1100 } 1101 } 1102 1103 // Windows Media 1104 elseif ($handler === 'wmedia') 1105 { 1106 $height += 45; 1107 if ($native) 1108 { 1109 $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>"; 1110 } 1111 else 1112 { 1113 $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>"; 1114 } 1115 } 1116 1117 // Everything else 1118 else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>'; 1119 1120 return $embed; 1121 } 1122 1123 /** 1124 * Get the real media type 1125 * 1126 * Often, feeds lie to us, necessitating a bit of deeper inspection. This 1127 * converts types to their canonical representations based on the file 1128 * extension 1129 * 1130 * @see get_type() 1131 * @param bool $find_handler Internal use only, use {@see get_handler()} instead 1132 * @return string MIME type 1133 */ 1134 public function get_real_type($find_handler = false) 1135 { 1136 // Mime-types by handler. 1137 $types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash 1138 $types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player 1139 $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 1140 $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 1141 $types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3 1142 1143 if ($this->get_type() !== null) 1144 { 1145 $type = strtolower($this->type); 1146 } 1147 else 1148 { 1149 $type = null; 1150 } 1151 1152 // If we encounter an unsupported mime-type, check the file extension and guess intelligently. 1153 if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3))) 1154 { 1155 $extension = $this->get_extension(); 1156 if ($extension === null) { 1157 return null; 1158 } 1159 1160 switch (strtolower($extension)) 1161 { 1162 // Audio mime-types 1163 case 'aac': 1164 case 'adts': 1165 $type = 'audio/acc'; 1166 break; 1167 1168 case 'aif': 1169 case 'aifc': 1170 case 'aiff': 1171 case 'cdda': 1172 $type = 'audio/aiff'; 1173 break; 1174 1175 case 'bwf': 1176 $type = 'audio/wav'; 1177 break; 1178 1179 case 'kar': 1180 case 'mid': 1181 case 'midi': 1182 case 'smf': 1183 $type = 'audio/midi'; 1184 break; 1185 1186 case 'm4a': 1187 $type = 'audio/x-m4a'; 1188 break; 1189 1190 case 'mp3': 1191 case 'swa': 1192 $type = 'audio/mp3'; 1193 break; 1194 1195 case 'wav': 1196 $type = 'audio/wav'; 1197 break; 1198 1199 case 'wax': 1200 $type = 'audio/x-ms-wax'; 1201 break; 1202 1203 case 'wma': 1204 $type = 'audio/x-ms-wma'; 1205 break; 1206 1207 // Video mime-types 1208 case '3gp': 1209 case '3gpp': 1210 $type = 'video/3gpp'; 1211 break; 1212 1213 case '3g2': 1214 case '3gp2': 1215 $type = 'video/3gpp2'; 1216 break; 1217 1218 case 'asf': 1219 $type = 'video/x-ms-asf'; 1220 break; 1221 1222 case 'flv': 1223 $type = 'video/x-flv'; 1224 break; 1225 1226 case 'm1a': 1227 case 'm1s': 1228 case 'm1v': 1229 case 'm15': 1230 case 'm75': 1231 case 'mp2': 1232 case 'mpa': 1233 case 'mpeg': 1234 case 'mpg': 1235 case 'mpm': 1236 case 'mpv': 1237 $type = 'video/mpeg'; 1238 break; 1239 1240 case 'm4v': 1241 $type = 'video/x-m4v'; 1242 break; 1243 1244 case 'mov': 1245 case 'qt': 1246 $type = 'video/quicktime'; 1247 break; 1248 1249 case 'mp4': 1250 case 'mpg4': 1251 $type = 'video/mp4'; 1252 break; 1253 1254 case 'sdv': 1255 $type = 'video/sd-video'; 1256 break; 1257 1258 case 'wm': 1259 $type = 'video/x-ms-wm'; 1260 break; 1261 1262 case 'wmv': 1263 $type = 'video/x-ms-wmv'; 1264 break; 1265 1266 case 'wvx': 1267 $type = 'video/x-ms-wvx'; 1268 break; 1269 1270 // Flash mime-types 1271 case 'spl': 1272 $type = 'application/futuresplash'; 1273 break; 1274 1275 case 'swf': 1276 $type = 'application/x-shockwave-flash'; 1277 break; 1278 } 1279 } 1280 1281 if ($find_handler) 1282 { 1283 if (in_array($type, $types_flash)) 1284 { 1285 return 'flash'; 1286 } 1287 elseif (in_array($type, $types_fmedia)) 1288 { 1289 return 'fmedia'; 1290 } 1291 elseif (in_array($type, $types_quicktime)) 1292 { 1293 return 'quicktime'; 1294 } 1295 elseif (in_array($type, $types_wmedia)) 1296 { 1297 return 'wmedia'; 1298 } 1299 elseif (in_array($type, $types_mp3)) 1300 { 1301 return 'mp3'; 1302 } 1303 1304 return null; 1305 } 1306 1307 return $type; 1308 } 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 &nbs