function throwErrorPage($code) { if ($code == "404") { $header = $_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'; } else { if ($code == "403") { $header = $_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'; } else { $header = $_SERVER['SERVER_PROTOCOL'] . ' ' . $code; } } header($header); $errorPage = sConfig()->getVar('CONFIG/ERRORPAGES/ERROR_' . $code); if ($errorPage && $errorPage != '') { $request_path_string = getRequestPathString(explode('/', 'page' . $errorPage)); $request_path = getRequestPathArray($request_path_string); $psite = $request_path[1]; if ((int) $psite > 0) { $sinfo = sSites()->get($psite); $siteID = (int) $psite; } else { $sinfo = sSites()->getByPName($psite); $siteID = $sinfo['ID']; } $pageMgr = new PageMgr($siteID); $pageID = $pageMgr->getPageIdByPname($request_path[count($request_path) - 1]); $page = $pageMgr->getPage($pageID); $pageInfo = $page->get(); $version = $page->getLatestVersion(); renderPage($page, $version, $pageInfo, $pageMgr, $sinfo); } else { echo $header; } die; }
<?php // Includes include_once "error.php"; // Set frontend timezone date_default_timezone_set($this->frontendTimezone); // Normalize and remove webroot-prefix $webroot_path_string = implode('/', sApp()->webroot); $request_path_string = getRequestPathString(sApp()->request->path); $request_path = getRequestPathArray($request_path_string); $psite = $request_path[1]; $ppage = (int) $request_path[2]; $action = sYDB()->escape_string($this->request->parameters['action']); // Default if (strlen($psite) < 1) { if (strlen($request_path_string) === 0) { // Webroot was requested, use first site and first page from that site $sites = sSites()->getList(); $siteID = $sites[0]['ID']; if ($siteID) { $pageMgr = new PageMgr($siteID); $pagesList = $pageMgr->getTree($pageMgr->tree->getRoot(), 2); foreach ($pagesList as $currPage) { if ($currPage['LEVEL'] == 2 && $pageID == 0) { $pageID = $currPage['ID']; $pagePName = $currPage['PNAME']; } } $newUrl = $webroot_path_string . '/' . $sites[0]['PNAME'] . '/' . $pagePName . '/'; // Throw status 301 and redirect $header = $_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently';