<?php
class rssad {
var $id; var $uri; var $pocet = 5; var $cache = true; var $cache_cesta; var $cache_cas = '30'; var $server = 'http://rssad.mazlo.org/get.php'; var $kodovani = 'UTF-8'; var $curl = false;
function _cache($soubor) {
if(!$this->cache)
return false;
$hash = md5($soubor).'.html';
$cas = time()-60*$this->cache_cas;
$obsah = is_file($this->cache_cesta.$hash) ? $this->_get($this->cache_cesta.$hash) : null;
if(!$obsah)
return false;
$obsah = unserialize($obsah);
if($obsah['cas'] > $cas)
return $obsah['data'];
else
return false;
}
function _get($soubor, $vzdaleny=false) {
if($this->curl && $vzdaleny) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $soubor);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$obsah = curl_exec($curl);
curl_close($curl);
}
else
$obsah = @file_get_contents($soubor);
if(!$obsah)
return false;
return $obsah;
}
function _put($filename, $s) {
if (function_exists('file_put_contents'))
file_put_contents($filename, $s);
else {
$f = fopen($filename, 'w');
flock($f, 1);
fwrite($f, $s);
flock($f, 3);
fclose($f);
}
}
function zobraz() {
$soubor = $this->server.'?id='.$this->id.'&limit='.$this->pocet.'&uri='.$this->uri;
$obsah = $this->_cache($soubor);
if($obsah)
echo $obsah;
else {
$obsah = $this->_get($soubor, true);
if($this->kodovani != 'UTF-8')
$obsah = iconv('UTF-8', $this->kodovani, $obsah);
echo $obsah;
$tofile = serialize(array('cas' => time(), 'data' => $obsah));
$this->_put($this->cache_cesta.md5($soubor).'.html', $tofile);
}
}
}
?>