<?php
class OpenDirectoryXMLCacheObject {
var $cacheDir = CACHE_DIR;
function setCacheDir($path)
{
$this->cacheDir = $path;
}
function setName($cat) {
$this->cat = $cat;
}
function getPath()
{
return './' . $this->cacheDir . '/' . md5(strtolower(catPath($this->cat))) . '.txt';
}
function read() {
if ($this->getPath())
{
if ($fp = fopen($this->getPath(), 'r'))
{
if (($size = filesize($this->getPath())) !== 0)
{
$contents = fread($fp, filesize($this->getPath()));
fclose($fp);
return $contents;
}
else
{
return;
}
}
else
{
return;
}
}
else
{
trigger_error('Missed setCachePath($cat)');
return;
}
return false;
}
function exists() {
if ($this->getPath())
{
return file_exists($this->getPath());
}
else
{
trigger_error('Missed setCachePath($cat)');
return;
}
}
function write($data)
{
if ($this->getPath())
{
if ($data != '')
{
if ($fp = @fopen($this->getPath(), 'w'))
{
fwrite($fp, $data);
fclose($fp);
return true;
}
else
{
if (file_exists($this->cacheDir))
{
trigger_error('PHP doesn\'t have write permissions. Chmod the cache directory to 777 or otherwise disable caching.');
return false;
}
else
{
if (mkdir($this->cacheDir, 0777))
{
return $this->write($data);
}
else
{
trigger_error('Your cache directory is missing. We tried to make one. But it returns an error.');
return false;
}
}
}
}
else
{
return false;
}
}
else
{
trigger_error('Missed setCachePath($cat)');
return false;
}
}
}
?>