private function _parse($pid) { $tpl = new Template(); $template = $tpl->getTemplateDefinitionByPageId($pid); if ((int) $template->templatetype != 1) { throw $this->throwException(7008); } $_SESSION['language'] = 'tpl'; $page = new Page(); $opage = $page->getPageById($pid, false, true); $tn = new OTreeNode(); $tn->page = $opage; $tname = $template->itemtype; if (!file_exists(BASEPATH . '/bright/site/views/' . $tname . 'View.php')) { throw $this->throwException(7010, array($tname . 'View')); } // include_once('views/' . $tname . 'View.php'); $viewclass = $tname . 'View'; $view = new $viewclass($tn); // Simplify page for parsing // @deprecated Should not be used anymore foreach ($opage->content as $cfield => $value) { $opage->{$cfield} = $value; } $deactivationlink = BASEURL . 'bright/'; if (defined('USEACTIONDIR') && USEACTIONDIR) { $deactivationlink .= 'actions/'; } $deactivationlink .= 'registration.php?action=deactivate&email={email}&code={code}'; $view->deactivationlink = $deactivationlink; define('DEACTIVATIONLINK', $deactivationlink); if (method_exists($view, 'parseTemplate')) { // Bright parser $parsed = $view->parseTemplate($view, $template->itemtype); } else { // Smarty parser \Smarty::muteExpectedErrors(); $parsed = $view->output(); \Smarty::unmuteExpectedErrors(); } $parsed = preg_replace_callback('/<img([^>]*)src="\\/([^"]*)"([^>]*)\\/>/ism', array($this, '_replaceImage'), $parsed); $result = new \stdClass(); $result->page = $opage; $result->parsed = $parsed; return $result; }
/** * Gets the content of a page * @param OPage $page The page without content * @param boolean $tpllang Defines whether or not the tpl lang should be included (For CMS true, for frontend false) * @param string $table The table with the content * @return OPage The page with content */ public function getContent($page, $tpllang = false, $table = 'content') { $pid = 'pageId'; switch ($table) { case 'content': $pid = 'pageId'; break; case 'userfields': $pid = 'userId'; break; case 'calendarcontent': $pid = 'calendarId'; break; } $id = (int) $page->{$pid}; $table = Connection::getInstance()->escape_string($table); $sql = "SELECT * FROM `{$table}` WHERE {$pid}={$id} ORDER BY `field`, `index`"; $content = $this->conn->getRows($sql); $page->content = new OContent(); $template = new Template(); // Just to be sure, the old method used getTemplateDefinitionByPageId, but since a user doesn't have a page id, // we'll have to cut some corners if ($page->itemType > 0) { $definition = $template->getTemplateDefinition($page->itemType, true); } else { $definition = $template->getTemplateDefinitionByPageId($page->pageId, true); } $gm_maps = new Maps(); $gm_layers = new Layers(); foreach ($content as $row) { $field = $row->field; // Skip fields which aren't present anymore (template has changed) if (!isset($definition->{$field}) && $field != 'title') { continue; } $lang = $row->lang; $isnew = true; if (isset($page->content->{$field})) { $isnew = false; } if (!isset($page->content->{$field})) { if (!$tpllang && $lang != 'tpl' || $tpllang) { $page->content->{$field} = new \stdClass(); } } if ($lang != 'tpl' && !$tpllang && isset($page->content->{$field}->{$lang})) { $isnew = false; } else { if ($lang != 'tpl' && !isset($page->content->{$field}->{$lang})) { $isnew = true; } } if ($isnew) { if ($field == 'title') { $value = $row->value; } else { $value = $this->_processValue($row->value, $definition, $field); } if ($lang == 'tpl' && !$tpllang) { $page->content->{$field} = $value; } else { $page->content->{$field}->{$lang} = $value; } } else { $raw = $row->value; $val = json_decode($row->value); if ($val == null && ($raw != null && $raw != '')) { // Value is not a json string $val = $raw; } if ($lang == 'tpl' && !$tpllang) { $page->content->{$field}[] = $val; } else { array_push($page->content->{$field}->{$lang}, $val); } } } return $page; }