Beispiel #1
0
function plugin_showrss_get_rss($target, $cachehour)
{
    $buf = '';
    $time = NULL;
    if ($cachehour) {
        // Remove expired cache
        plugin_showrss_cache_expire($cachehour);
        // Get the cache not expired
        $filename = CACHE_DIR . encode($target) . '.tmp';
        if (is_readable($filename)) {
            $buf = join('', file($filename));
            $time = filemtime($filename) - LOCALZONE;
        }
    }
    if ($time === NULL) {
        // Newly get RSS
        $data = http_request($target);
        if ($data['rc'] !== 200) {
            return array(FALSE, 0);
        }
        $buf = $data['data'];
        $time = UTIME;
        // Save RSS into cache
        if ($cachehour) {
            $fp = fopen($filename, 'w');
            fwrite($fp, $buf);
            fclose($fp);
        }
    }
    // Parse
    $obj = new ShowRSS_XML();
    return array($obj->parse($buf), $time);
}
function plugin_showrss_get_rss($target, $usecache)
{
    $buf = '';
    $time = NULL;
    if ($usecache) {
        // 期限切れのキャッシュをクリア
        plugin_showrss_cache_expire($usecache);
        // キャッシュがあれば取得する
        $filename = MOD_PUKI_CACHE_DIR . PukiWikiFunc::encode($target) . '.tmp';
        if (is_readable($filename)) {
            $buf = join('', file($filename));
            $time = filemtime($filename) - MOD_PUKI_LOCALZONE;
        }
    }
    if ($time === NULL) {
        // rss本体を取得
        $data = PukiWikiFunc::http_request($target);
        if ($data['rc'] !== 200) {
            return array(FALSE, 0);
        }
        $buf = $data['data'];
        $time = MOD_PUKI_UTIME;
        // キャッシュを保存
        if ($usecache) {
            $fp = fopen($filename, 'w');
            fwrite($fp, $buf);
            fclose($fp);
        }
    }
    // parse
    $obj = new ShowRSS_XML();
    return array($obj->parse($buf), $time);
}