Esempio n. 1
0
function jpcache_write($gzdata, $datasize, $datacrc)
{
    // Construct filename
    $filename = $GLOBALS["JPCACHE_DIR"] . "/" . $GLOBALS["JPCACHE_FILEPREFIX"] . $GLOBALS["jpcache_key"];
    // Create and fill cachedata-array
    $cachedata = array();
    $cachedata["jpcache_version"] = $GLOBALS["JPCACHE_VERSION"];
    $cachedata["jpcache_expire"] = $GLOBALS["JPCACHE_TIME"] > 0 ? time() + $GLOBALS["JPCACHE_TIME"] : 0;
    $cachedata["jpcachedata_gzdata"] = $gzdata;
    $cachedata["jpcachedata_datasize"] = $datasize;
    $cachedata["jpcachedata_datacrc"] = $datacrc;
    // And write the data
    if (jpcache_filewrite($filename, serialize($cachedata))) {
        jpcache_debug("Successfully wrote cachefile {$filename}");
    } else {
        jpcache_debug("Unable to write cachefile {$filename}");
    }
}
Esempio n. 2
0
function jpcache_write($gzdata, $datasize, $datacrc, $contents_snippet)
{
    // Construct filename
    $filename = $GLOBALS["JPCACHE_DIR"] . "/" . $GLOBALS["JPCACHE_FILEPREFIX"] . $GLOBALS["jpcache_key"];
    // Create and fill cachedata-array
    $cachedata = array();
    $cachedata["jpcache_version"] = $GLOBALS["JPCACHE_VERSION"];
    $cachedata["jpcache_expire"] = $GLOBALS["JPCACHE_TIME"] > 0 ? time() + $GLOBALS["JPCACHE_TIME"] : 0;
    $cachedata["jpcachedata_gzdata"] = $gzdata;
    $cachedata["jpcachedata_datasize"] = $datasize;
    $cachedata["jpcachedata_datacrc"] = $datacrc;
    if (function_exists('headers_list')) {
        $headers = headers_list();
        foreach ($headers as $item) {
            if (stristr($item, 'Content-Type') !== false) {
                $cachedata["jpcachedata_type"] = substr($item, strpos($item, ': ') + 2);
            }
        }
    }
    // Buggy PHP versions just return blank arrays on headers_list()
    if (!function_exists('headers_list') || !isset($cachedata["jpcachedata_type"])) {
        //Content-Sniffing to set correct Content-Type, because headers were not available
        if (strpos($contents_snippet, '<rss version="0.92">') === 0) {
            $cachedata["jpcachedata_type"] = 'application/rss+xml; charset=utf-8';
        } elseif (strpos($contents_snippet, chr(60) . '?xml version="1.0" encoding="UTF-8"?' . chr(62) . "\n<feed") === 0) {
            $cachedata["jpcachedata_type"] = 'application/atom+xml; charset=utf-8';
        } else {
            $cachedata["jpcachedata_type"] = $GLOBALS['JPCACHE_DEFAULT_MIMETYPE'];
        }
    }
    // And write the data
    if (jpcache_filewrite($filename, serialize($cachedata))) {
        jpcache_debug("Successfully wrote cachefile {$filename}");
    } else {
        jpcache_debug("Unable to write cachefile {$filename}");
    }
}