fragments[$region] = $content; } public function registerRegion($name) { } public function getRegionContent($region) { if(isset($this->fragments[$region])) return (string) $this->fragments[$region]; return NULL; } /** * helper method, which separates the layout variables from the local variables of a * method */ private function getFileOutput($filename) { if(!file_exists($filename)) return NULL; ob_start(); include ($filename); return ob_get_clean(); } public function getDocument($media, Response $response = NULL) { $system = System::getInstance(); $db = $system->getDB(); //$this->layout = $system->getSiteParam($system->getSiteId(), '', 'layout', 'default'); $this->layout = 'default'; if(defined('_SERVICE_')) return $this->fragments['CONTENT']; $filebase = __DS__ . $this->layout . __DS__; if(is_dir($filebase . 'admin' . __DS__)) $filebase = $filebase . 'admin' . __DS__; else $filebase = __DS__ . 'default' . __DS__ . 'admin' . __DS__; switch($media) { case 'print': $file = 'print.php'; break; case 'popup': $file = 'popup.php'; break; default: $file = 'default.php'; break; } $num = 0; $layout = NULL; foreach(array( _LAYOUTPATHX_ . $filebase . $file,_LAYOUTPATHX_ . $filebase . 'default.php', _LAYOUTPATH_ . $filebase . $file,_LAYOUTPATHX_ . $filebase . 'default.php') as $layoutPath) { if(file_exists($layoutPath)) { $layout = $this->getFileOutput($layoutPath); break; } $num++; } if(is_null($layout)) throw new \RuntimeException($this->layout . ' is an invalid layout (base: ' . $filebase . ')'); // modifiy relative links to match new location $layout = preg_replace('##', '', $layout); // remove hidden comments $layoutPath = array( _LAYOUTPATHX_,_LAYOUTPATHX_,_LAYOUTPATH_,_LAYOUTPATH_); $layoutPath = $layoutPath[$num] . $filebase; $layoutPath = preg_replace('#^' . addslashes(_BASEPATH_) . '#', '', $layoutPath, 1); $layoutPath = dirname($_SERVER['PHP_SELF']) . $layoutPath; $layoutPath = str_replace('\\', '/', $layoutPath); $layout = preg_replace('#((href|src)=["\'])\\.[/\\\\]#is', '\\1' . $layoutPath, $layout); unset($file, $filebase, $layoutPath, $num); $template = new CTemplate(); $template->setRoot(''); $template->loadString($layout); unset($layout); $usrSvc = $system->getUserSvc(); $usr = $usrSvc->getUser(); $template->setParam('self', _SELF_); if(is_null($usr)) { $template->setParam('isUser', false); $template->setParam('isMasterAdmin', false); if(isset($_GET['error']) && ((int) $_GET['error']) != 0) { $errmsg[-1] = 'User not found'; $errmsg[-2] = 'Unable to authenticate'; $template->setParam('withError', true); $msgid = (int) $_GET['error']; $template->setParam('errormsg', $msgid . ':' . $errmsg[$msgid]); } else $template->setParam('withError', false); } else { $template->setParam('isUser', true); $template->setParam('withError', false); $template->setParam('isMasterAdmin', $usrSvc->userHasPriv($usr, $system->getSiteId(), false, false)); } foreach($this->getRegions() as $region) $template->setParam($region, $this->getRegionContent($region)); $template->setParam('title', 'Administration Interface'); $template->setParam('HEADDATA', $this->buildHeadData($response)); return $template->getDocument(); } protected function buildHeadData(Response $response = NULL) { $headdata = ""; $headdata .= ""; $headdata .= ""; $headdata .= ""; // if($this->addHtml5Fixes) // $headdata .= ""; if(!empty($response) && !empty($response->addons[Response::ADDON_CSS])) { foreach($response->addons[Response::ADDON_CSS] as $cssAddOn) { $headdata .= ''; } } if(!empty($this->addHeaders)) { foreach($this->addHeaders as $headAddOn) { $headdata .= $headAddOn; } } if(!empty($response) && !empty($response->addons[Response::ADDON_JSLIB])) { $jsLibs = $response->addons[Response::ADDON_JSLIB]; $jsLibs = array_unique($jsLibs); foreach($jsLibs as $jsAddOn) $headdata .= ''; unset($jsLibs,$jsAddOn); } $headdata .= "\n"; return $headdata; } }