lastRSS::Get PHP Method

Get() public method

-------------------------------------------------------------------
public Get ( $rss_url )
    function Get($rss_url)
    {
        // If CACHE ENABLED
        if ($this->cache_dir != '') {
            $cache_file = $this->cache_dir . '/rsscache_' . md5($rss_url);
            $timedif = @(time() - filemtime($cache_file));
            if ($timedif < $this->cache_time) {
                // cached file is fresh enough, return cached array
                $result = unserialize(join('', file($cache_file)));
                // set 'cached' to 1 only if cached file is correct
                if ($result) {
                    $result->cached = 1;
                }
            } else {
                // cached file is too old, create new
                $result = $this->Parse($rss_url);
                $serialized = serialize($result);
                if ($f = @fopen($cache_file, 'w')) {
                    fwrite($f, $serialized, strlen($serialized));
                    fclose($f);
                }
                if ($result) {
                    $result->cached = 0;
                }
            }
        } else {
            $result = $this->Parse($rss_url);
            if ($result) {
                $result->cached = 0;
            }
        }
        // return result
        return $result;
    }

Usage Example

示例#1
0
文件: module.php 项目: 4uva4ek/svato
function mod_rss($module_id, $cfg)
{
    cmsCore::includeFile('includes/rss/lastRSS.php');
    $rss = new lastRSS();
    $rss->cache_dir = PATH . '/cache';
    $rss->cache_time = (int) @$cfg['cachetime'] * 3600;
    $rss->cp = 'UTF-8';
    $rss->items_limit = $cfg['itemslimit'];
    $rs = $rss->Get($cfg['rssurl']);
    if (!$rs) {
        return false;
    }
    cmsPage::initTemplate('modules', 'mod_rss')->assign('rs', $rs)->assign('cfg', $cfg)->display('mod_rss.tpl');
    return true;
}
All Usage Examples Of lastRSS::Get