filemtime($file)) // and newer than the source && ($cachetime > @filemtime($purge)) // and newer than the purgefile && ($cachetime > filemtime('conf/dokuwiki.php')) // and newer than the config file && ($cachetime > @filemtime('conf/local.php')) // and newer than the local config file && ($cachetime > filemtime('inc/parser.php')) // and newer than the parser && ($cachetime > filemtime('inc/format.php'))) // and newer than the formating functions { $parsed = io_readFile($cache); //give back cache $parsed .= "\n\n"; }elseif(file_exists($file)){ $parsed = parse(io_readFile($file)); io_saveFile($cache,$parsed); $parsed .= "\n\n"; } return $parsed; } /** * Returns content of $file as cleaned string. Uses gzip if extension * is .gz */ function io_readFile($file){ $ret = ''; if(file_exists($file)){ if(substr($file,-3) == '.gz'){ $ret = join('',gzfile($file)); }else{ $ret = join('',file($file)); } } return cleanText($ret); } /** * Saves $content to $file. Uses gzip if extension * is .gz */ function io_saveFile($file,$content){ io_makeFileDir($file); if(substr($file,-3) == '.gz'){ $fh = gzopen($file,'wb9'); if(!$fh) die("Writing $file failed"); gzwrite($fh, $content); gzclose($fh); }else{ $fh = fopen($file,'wb'); if(!$fh) die("Writing $file failed"); fwrite($fh, $content); fclose($fh); } } /** * Create the directory needed for the given file */ function io_makeFileDir($file){ global $conf; $dir = dirname($file); umask($conf['dmask']); if(!is_dir($dir)){ io_mkdir_p($dir) || die("Creating directory $dir failed"); } umask($conf['umask']); } /** * Creates a directory hierachy. * * @see http://www.php.net/manual/en/function.mkdir.php * @author */ function io_mkdir_p($target){ if (is_dir($target)||empty($target)) return 1; // best case check first if (file_exists($target) && !is_dir($target)) return 0; if (io_mkdir_p(substr($target,0,strrpos($target,'/')))) return mkdir($target,0777); // crawl back up & create dir tree return 0; } /** * Runs an external command and returns it's output as string * inspired by a patch by Harry Brueckner */ function io_runcmd($cmd){ $fh = popen($cmd, "r"); if(!$fh) return false; $ret = ''; while (!feof($fh)) { $ret .= fread($fh, 8192); } pclose($fh); return $ret; } ?>