function optCompileCacheReset($filename, $compile) { if ($filename == NULL) { $dir = opendir($compile); while ($f = readdir($dir)) { if (is_file($compile . $f)) { unlink($compile . $f); } } closedir($dir); return 1; } elseif (file_exists($compile . optCompileFilename($filename) . '.php')) { unlink($compile . optCompileFilename($filename) . '.php'); return 1; } return 0; }
private function needCompile($filename, $noException = false) { $compiled = optCompileFilename($filename); $resource = 'file'; if (strpos($filename, ':') !== FALSE) { $data = explode(':', $filename); $filename = $data[1]; $resource = $data[0]; if (!isset($this->resources[$resource])) { if ($noException) { return NULL; } $this->error(E_USER_ERROR, 'Specified resource type: "' . $resource . '" does not exist.', OPT_E_RESOURCE_NOT_FOUND); } $callback = $this->resources[$resource]; } $compiledTime = @filemtime($this->compile . $compiled); $result = false; if ($resource == 'file') { $rootTime = @filemtime($this->root . $filename); if ($rootTime === false) { if ($noException) { return NULL; } $this->error(E_USER_ERROR, '"' . $filename . '" not found in ' . $this->root . ' directory.', OPT_E_FILE_NOT_FOUND); } if ($compiledTime === false || $compiledTime < $rootTime || $this->alwaysRebuild) { $result = file_get_contents($this->root . $filename); } } else { $result = $callback($this, $filename, $compiledTime); } if ($result === false) { return $compiled; } if (!is_object($this->compiler)) { require_once OPT_DIR . 'opt.compiler.php'; $this->compiler = new optCompiler($this); } $this->compiler->parse($this->compile . $compiled, $result); return $compiled; }
protected function needCompile($filename, $noException = false) { // This method returns the compiled file name. If the compiled version // Does not exist, the template is compiled. $compiled = optCompileFilename($filename); // Both the modification time and the file existence are checked by filemtime() function // The fewer disk operation, the better $compiledTime = @filemtime($this->compile . $compiled); $result = false; $rootTime = @filemtime($this->root . $filename); if ($rootTime === false) { if ($noException) { return NULL; } $this->error(E_USER_ERROR, '"' . $filename . '" not found in ' . $this->root . ' directory.', 6); } if ($compiledTime === false || $compiledTime < $rootTime || $this->alwaysRebuild) { // If it is the time to (re)compilation, read the file content to this variable $result = file_get_contents($this->root . $filename); } if ($result === false) { // The script goes here, if the source template is not loaded. It simply returns the // Compiled version filename return $compiled; } // Otherwise, we set up the compiler and parse the template. if (!is_object($this->compiler)) { require_once OPT_DIR . 'opt.compiler.php'; $this->compiler = new optCompiler($this); } $this->compiler->parse($this->compile . $compiled, $result); return $compiled; }
} else { $view->setTemplate('compiler.tpl'); $tpl->assign('splValue', $config->splDir); $tpl->assign('cplValue', $config->cplDir); $tpl->assign('plgValue', $config->plgDir); $tpl->assign('masValue', $config->masDir); $tpl->assign('sel' . $config->xmlDir, 'checked="checked"'); $dir = opendir($config->splDir); $templates = array(); if (is_resource($dir)) { $i = 0; while ($file = readdir($dir)) { if (is_file($config->splDir . $file)) { $templates[$i] = array(); $templates[$i]['filename'] = $file; $cplFile = optCompileFilename($file); $cpl = @filemtime($config->cplDir . $cplFile); if ($cpl === false) { $templates[$i]['cdate'] = '<strong>Not compiled</strong>'; $templates[$i]['cplSize'] = '<em>N/A</em>'; } else { $templates[$i]['cdate'] = date('m.d.Y, H:i', $cpl); $templates[$i]['cplSize'] = filesize($config->cplDir . $cplFile) . ' b'; } $templates[$i]['srcSize'] = filesize($config->splDir . $file) . ' b'; $i++; } } closedir($dir); } $tpl->assign('templates', $templates);
protected function needCompile($filename, $noException = false) { $compiled = optCompileFilename($filename); # CUSTOM_RESOURCES $resource = 'file'; if (strpos($filename, ':') !== FALSE) { $data = explode(':', $filename); $filename = $data[1]; $resource = $data[0]; if (!isset($this->resources[$resource])) { if ($noException) { return NULL; } $this->error(E_USER_ERROR, 'Specified resource type: "' . $resource . '" does not exist.', OPT_E_RESOURCE_NOT_FOUND); } $callback = $this->resources[$resource]; } # /CUSTOM_RESOURCES $compiledTime = @filemtime($this->compile . $compiled); $result = false; # CUSTOM_RESOURCES if ($resource == 'file') { # /CUSTOM_RESOURCES $rootTime = @filemtime($this->root . $filename); if ($rootTime === false) { if ($noException) { return NULL; } $this->error(E_USER_ERROR, '"' . $filename . '" not found in ' . $this->root . ' directory.', OPT_E_FILE_NOT_FOUND); } if ($compiledTime === false || $compiledTime < $rootTime || $this->alwaysRebuild) { $result = file_get_contents($this->root . $filename); } # CUSTOM_RESOURCES } else { $result = $callback($this, $filename, $compiledTime); } # /CUSTOM_RESOURCES if ($result === false) { return $compiled; } if (!is_object($this->compiler)) { require_once OPT_DIR . 'opt.compiler.php'; $this->compiler = new optCompiler($this); # MASTER_TEMPLATES if (sizeof($this->compileMasterPages) > 0) { // Load master pages now foreach ($this->compileMasterPages as $page) { $this->getTemplate($page, $this->compiler, true); } } # /MASTER_TEMPLATES } $this->compiler->parse($this->compile . $compiled, $result); return $compiled; }