setTemplatePath($this->module_path.'tpl'); // Get information of the external page module $oOpageModel = &getModel('opage'); $module_info = $oOpageModel->getOpage($this->module_srl); Context::set('module_info', $module_info); // Get a path/caching interval on the external page $this->path = $module_info->path; $this->caching_interval = $module_info->caching_interval; // Specify the cache file $this->cache_file = sprintf("./files/cache/opage/%d.cache.php", $module_info->module_srl); } /** * @brief Display when receiving a request **/ function dispOpageIndex() { // check if it is http or internal file if($this->path) { if(preg_match("/^([a-z]+):\/\//i",$this->path)) $content = $this->getHtmlPage($this->path, $this->caching_interval, $this->cache_file); else $content = $this->executeFile($this->path, $this->caching_interval, $this->cache_file); } Context::set('opage_content', $content); // Set a template for result output $this->setTemplateFile('content'); } /** * @brief Save the file and return if a file is requested by http **/ function getHtmlPage($path, $caching_interval, $cache_file) { // Verify cache if($caching_interval > 0 && file_exists($cache_file) && filemtime($cache_file) + $caching_interval*60 > time()) { $content = FileHandler::readFile($cache_file); } else { FileHandler::getRemoteFile($path, $cache_file); $content = FileHandler::readFile($cache_file); } // Create opage controller $oOpageController = &getController('opage'); // change url of image, css, javascript and so on if the page is from external server $content = $oOpageController->replaceSrc($content, $path); // Change the document to utf-8 format $buff->content = $content; $buff = Context::convertEncoding($buff); $content = $buff->content; // Extract a title $title = $oOpageController->getTitle($content); if($title) Context::setBrowserTitle($title); // Extract header script $head_script = $oOpageController->getHeadScript($content); if($head_script) Context::addHtmlHeader($head_script); // Extract content from the body $body_script = $oOpageController->getBodyScript($content); if(!$body_script) $body_script = $content; return $content; } /** * @brief Create a cache file in order to include if it is an internal file **/ function executeFile($path, $caching_interval, $cache_file) { // Cancel if the file doesn't exist if(!file_exists($path)) return; // Get a path and filename $tmp_path = explode('/',$cache_file); $filename = $tmp_path[count($tmp_path)-1]; $filepath = preg_replace('/'.$filename."$/i","",$cache_file); // Verify cache if($caching_interval <1 || !file_exists($cache_file) || filemtime($cache_file) + $caching_interval*60 <= time() || filemtime($cache_file)path = str_replace('\\', '/', realpath($path_info['dirname'])).'/'; $content = preg_replace_callback('/(target=|src=|href=|url\()("|\')?([^"\'\)]+)("|\'\))?/is',array($this,'_replacePath'),$content); $content = preg_replace_callback('/(