[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/SimplePie/src/Cache/ -> File.php (source)

   1  <?php
   2  
   3  /**
   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.
  35   *
  36   * @package SimplePie
  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
  42   * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  43   */
  44  
  45  namespace SimplePie\Cache;
  46  
  47  /**
  48   * Caches data to the filesystem
  49   *
  50   * @package SimplePie
  51   * @subpackage Caching
  52   * @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead
  53   */
  54  class File implements Base
  55  {
  56      /**
  57       * Location string
  58       *
  59       * @see SimplePie::$cache_location
  60       * @var string
  61       */
  62      protected $location;
  63  
  64      /**
  65       * Filename
  66       *
  67       * @var string
  68       */
  69      protected $filename;
  70  
  71      /**
  72       * File extension
  73       *
  74       * @var string
  75       */
  76      protected $extension;
  77  
  78      /**
  79       * File path
  80       *
  81       * @var string
  82       */
  83      protected $name;
  84  
  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      }
  99  
 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              }
 112  
 113              $data = serialize($data);
 114              return (bool) file_put_contents($this->name, $data);
 115          }
 116          return false;
 117      }
 118  
 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      }
 131  
 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      }
 141  
 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      }
 151  
 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  }
 165  
 166  class_alias('SimplePie\Cache\File', 'SimplePie_Cache_File');


Generated : Sat Dec 21 08:20:01 2024 Cross-referenced by PHPXref