SimplePie_Misc::display_cached_file PHP Method

display_cached_file() public method

This is most useful for caching images (get_favicon(), etc.), however it works for all cached files. This WILL NOT display ANY file/image/page/whatever, but rather only display what has already been cached by SimplePie.
See also: SimplePie::get_favicon()
public display_cached_file ( str $identifier_url, str $cache_location = './cache', str $cache_extension = 'spc', str $cache_class = 'SimplePie_Cache', str $cache_name_function = 'md5' )
$identifier_url str URL that is used to identify the content. This may or may not be the actual URL of the live content.
$cache_location str Location of SimplePie's cache. Defaults to './cache'.
$cache_extension str The file extension that the file was cached with. Defaults to 'spc'.
$cache_class str Name of the cache-handling class being used in SimplePie. Defaults to 'SimplePie_Cache', and should be left as-is unless you've overloaded the class.
$cache_name_function str Obsolete. Exists for backwards compatibility reasons only.
    function display_cached_file($identifier_url, $cache_location = './cache', $cache_extension = 'spc', $cache_class = 'SimplePie_Cache', $cache_name_function = 'md5')
    {
        $cache = call_user_func(array($cache_class, 'create'), $cache_location, $identifier_url, $cache_extension);
        if ($file = $cache->load()) {
            if (isset($file['headers']['content-type'])) {
                header('Content-type:' . $file['headers']['content-type']);
            } else {
                header('Content-type: application/octet-stream');
            }
            header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT');
            // 7 days
            echo $file['body'];
            exit;
        }
        die('Cached file for ' . $identifier_url . ' cannot be found.');
    }

Usage Example

Example #1
0
 * @package Lilina
 * @version 1.0
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */
/** */
define('LILINA_PATH', dirname(__FILE__));
define('LILINA_INCPATH', LILINA_PATH . '/inc');
define('LILINA_PAGE', 'favicon');
// Hide errors
ini_set('display_errors', false);
require_once LILINA_INCPATH . '/contrib/simplepie.class.php';
if (!isset($_GET['i'])) {
    die;
}
require_once LILINA_INCPATH . '/core/conf.php';
require_once LILINA_INCPATH . '/core/plugin-functions.php';
function faux_hash($input)
{
    return $input;
}
if ($_GET['i'] != 'default' && file_exists(LILINA_CACHE_DIR . $_GET['i'] . '.spi')) {
    SimplePie_Misc::display_cached_file($_GET['i'], LILINA_CONTENT_DIR . '/system/cache', 'spi', 'SimplePie_Cache', 'faux_hash');
} else {
    require_once LILINA_INCPATH . '/core/class-templates.php';
    Locale::load_default_textdomain();
    header('Content-Type: image/png');
    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT');
    // 7 days
    echo file_get_contents(Templates::get_file('feed.png'));
    die;
}
All Usage Examples Of SimplePie_Misc::display_cached_file