/** * Print cached page */ public function printCache() { global $cache_path; if (file_exists($this->cache_file)) { // get data from file and prepare for parsing $data = file_get_contents($this->cache_file); $template = new TemplateHandler(); $pattern = '/' . self::TAG_OPEN . '(.*?)' . self::TAG_CLOSE . '/u'; // get all dirty areas preg_match_all($pattern, $data, $matches); if (count($matches) >= 2 && count($matches[1]) > 0) { foreach ($matches[1] as $match) { // give template to handler $template->setXML('<document>' . $match . '</document>'); // start output buffer and get data ob_start(); $template->parse(); $result = ob_get_contents(); ob_end_clean(); // replace output buffer with new data $data = preg_replace($pattern, $result, $data, 1); } } // make sure we have specified cache type if (!_AJAX_REQUEST) { header('Content-Type: text/html; charset=UTF-8'); } print $data; // validate or expire cache entry $this->validateCache(); } }