public static function parseNonPhtml(Response $response, $file) { if (!file_exists($file = file_exists($file = self::getPath() . $file) ? $file : (file_exists($file . '.html') ? $file . '.html' : (file_exists($file . '.xhtml') ? $file . '.xhtml' : (file_exists($file . '.php') ? $file . '.php' : $file))))) { if ($response->getStatusCode() == 200) { $response->setStatusCode(404); } $response->setContent($file = (string) new Phtml('/errors/' . $response->getStatusCode(), FALSE, 'default')); } else { if (strpos($file = realpath($file), realpath(Skin::getPath())) !== 0) { throw new \Exception('Unknown skin path: "' . $file . '".'); } $file = str_replace('sitemap.xml.php', 'sitemap.xml', $file); $repository = new PhpRepository(); $response->headers->set('Content-Type', $repository->findType(strtolower(substr(strrchr($file, '.'), 1)) ?: $file) ?: 'text/plain'); if (basename($file) == 'sitemap.xml') { $phtml = new Phtml(NULL); $file = $phtml->parsePhtml($file . '.php'); } else { $file = file_get_contents($file); } $response->setContent($file); } $response->headers->set('Cache-Control', 'max-age=604800'); $response->headers->set('Content-Length', strlen($file)); return $response; }
public static function getResponse() { $response = strpos($uri = self::fixFriendlyUrl(preg_replace('/^\\/$/', '/index', Keyserver::getRequest()->server->get('REQUEST_URI'))), '/pks/') === 0 ? Skin::parseContent(self::getHKPResponse($uri)) : Skin::parsePhtml(new Response(), rtrim(strtok($uri, '?'), '/')); if (($errno = (int) $response->getStatusCode()) !== 200) { $response = Skin::parsePhtml($response, '/errors/' . $errno); } return $response; }
public function parsePhtml($file) { if (strpos(realpath($file), realpath(Skin::getPath($this->_skin))) !== 0) { throw new \Exception('Unknown skin path: "' . $file . '".'); } ob_start(); require $file; return ob_get_clean(); }
protected function getPage($phtml = NULL) { if (is_null($phtml)) { if (!$this->_page && $this->_content) { return $this->_content; } $phtml = $this->_page; } if (!is_readable($file = realpath($path = Skin::getPath($this->_skin) . '/pages/' . ltrim($phtml, '/') . '.phtml'))) { throw new \Exception('Unknown page: "' . $path . '".'); } return $this->parsePhtml($file); }