Changeset 59141 for trunk/src/wp-includes/SimplePie/src/Cache/File.php
- Timestamp:
- 09/30/2024 10:48:16 PM (5 months ago)
- Location:
- trunk/src/wp-includes/SimplePie/src
- Files:
-
- 1 added
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
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');
Note: See TracChangeset
for help on using the changeset viewer.