getDB();
$agent = $system->getRequest()->getUserAgent();
$site = $db->getObject("SELECT * FROM websites WHERE id=" . $system->getSiteId());
$this->layout = $system->getSiteParam($system->getSiteId(), '', 'layout', 'default');
$filebase = __DS__ . $this->layout . __DS__;
// start offline part
if($site->online == 'offline') {
foreach(array(
_LAYOUTPATHX_ . $filebase . '_offline_.php',
_LAYOUTPATH_ . $filebase . '_offline_.php',
_LAYOUTPATH_ . __DS__ . '_system_' . __DS__ . '_offline_.php') as $layoutPath) {
if(file_exists($layoutPath)) {
$layout = $this->getFileOutput($layoutPath);
break;
}
}
$template = new MFCTemplate();
$template->setRoot('');
$template->loadString($layout);
unset($layout);
$usrSvc = $system->getUserSvc();
$usr = $usrSvc->getUser();
if(is_null($usr)) {
$template->setParam('isUser', false);
$template->setParam('isMasterAdmin', false);
}
else {
$template->setParam('isUser', true);
$template->setParam('isMasterAdmin', $usrSvc->userHasPriv($usr, $system->getSiteId(), false, false));
}
foreach($this->getRegions() as $region)
$template->setParam($region, $this->getRegionContent($region));
$headdata = "";
$headdata .= "";
$headdata .= "generator}\"/>";
$headdata .= "";
if($this->addHtml5Fixes)
$headdata .= "";
$headdata .= "\n";
$template->setParam('HEADDATA', $headdata);
$template->setParam('DEBUGINFO', false);
return $template->getDocument();
} // end offline part
if(defined('_SERVICE_'))
return $this->fragments['CONTENT'];
$num = 0;
$layout = NULL;
if($media == 'error') {
foreach(array(
_LAYOUTPATHX_ . $filebase . '_error_.php',_LAYOUTPATH_ . $filebase . '_error_.php',
_LAYOUTPATH_ . '_system_' . __DS__ . '_error_.php') as $layoutPath) {
if(file_exists($layoutPath)) {
$layout = $this->getFileOutput($layoutPath);
break;
}
$num++;
}
}
else {
if($agent->isConsole()) {
switch($media) {
case 'print':
$file = 'print.php';
break;
default:
$file = 'console.php';
break;
}
}
elseif($agent->isMobile()) {
switch($media) {
case 'print':
$file = 'print.php';
break;
default:
if($agent->isSmallScreen())
$file = 'small.php';
else
$file = 'mobile.php';
break;
}
}
elseif($agent->isSmallScreen()) {
switch($media) {
case 'print':
$file = 'print.php';
break;
case 'popup':
$file = 'popup.php';
break;
default:
$file = 'small.php';
break;
}
}
else {
switch($media) {
case 'print':
$file = 'print.php';
break;
case 'popup':
$file = 'popup.php';
break;
default:
$file = 'default.php';
break;
}
}
foreach(array(
_LAYOUTPATHX_ . $filebase . $file,_LAYOUTPATHX_ . $filebase . 'default.php',
_LAYOUTPATH_ . $filebase . $file,_LAYOUTPATH_ . $filebase . 'default.php') as $layoutPath) {
if(file_exists($layoutPath)) {
$layout = $this->getFileOutput($layoutPath);
break;
}
$num++;
}
}
if(is_null($layout))
throw new RuntimeException($system->getConfig('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 = _BASEURL_ . $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();
if(is_null($usr)) {
$template->setParam('isUser', false);
$template->setParam('isMasterAdmin', false);
}
else {
$template->setParam('isUser', true);
$template->setParam('isMasterAdmin', $usrSvc->userHasPriv($usr, $system->getSiteId(), false, false));
}
if($media == 'error')
$template->setParam('ERROR', $this->getRegionContent('ERROR'));
foreach($this->getRegions() as $region)
$template->setParam($region, $this->getRegionContent($region));
$headdata = "";
$headdata .= "";
$headdata .= "generator}\"/>";
$headdata .= "";
if($this->addHtml5Fixes)
$headdata .= "";
$headdata .= "\n";
$template->setParam('HEADDATA', $headdata);
$template->setParam('DEBUGINFO', false);
$keyfield = $db->escapeColumnName('key');
$fields = $db->getObjectListP("SELECT * FROM blocks WHERE site_id=? AND plugin='mcms.mmpilayoutx'", array(
$system->getSiteId()));
foreach($fields as $field) {
$fieldType = $db->getObjectP("SELECT * FROM websitesettings WHERE site_id=? AND INSTANCE='?layout' AND {$keyfield}=?", array(
$system->getSiteId(),$field->name . ':type'));
switch($fieldType->value) {
case 'string':
$fieldValue = $db->getObjectP("SELECT * FROM websitesettings WHERE site_id=? AND INSTANCE='?layout' AND {$keyfield}=?", array(
$system->getSiteId(),$field->name . ':value'));
$template->setParam($field->name, $fieldValue->value);
break;
case 'text':
$fieldValue = $db->getObjectP("SELECT * FROM websitesettings WHERE site_id=? AND INSTANCE='?layout' AND {$keyfield}=?", array(
$system->getSiteId(),$field->name . ':value'));
$template->setParam($field->name, $fieldValue->value);
break;
}
}
return $template->getDocument();
}
}