define('OS', strtoupper(substr(PHP_OS, 0, 3))); define('PATH', dirname(__FILE__)); $uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; new TSession(); ob_start(); $menu = TMenuBar::newFromXML('menu.xml'); $menu->show(); $menu_string = ob_get_contents(); ob_end_clean(); // verifica se o usuario esta logado para redirecionar // para o layout e login if (TSession::getValue('logado')) { $template = 'theme1'; } else { $template = 'loja'; } $content = file_get_contents("app/templates/{$template}/layout.html"); $content = TApplicationTranslator::translateTemplate($content); $content = str_replace('{LIBRARIES}', file_get_contents("app/templates/{$template}/libraries.html"), $content); $content = str_replace('{URI}', $uri, $content); $content = str_replace('{class}', isset($_REQUEST['class']) ? $_REQUEST['class'] : '', $content); $content = str_replace('{template}', $template, $content); $content = str_replace('{MENU}', $menu_string, $content); $css = TPage::getLoadedCSS(); $js = TPage::getLoadedJS(); $content = str_replace('{HEAD}', $css . $js, $content); if (isset($_REQUEST['class'])) { $url = http_build_query($_REQUEST); $content = str_replace('//#javascript_placeholder#', "__adianti_load_page('engine.php?{$url}');", $content); } echo $content;
/** * Show the HTML and the enabled sections */ public function show() { $sections_stack = array('main'); $array_content = array(); $buffer = array(); if (file_exists($this->path)) { $array_content = file($this->path); // iterate line by line foreach ($array_content as $line) { $line_ = trim($line); $line_ = str_replace("\n", '', $line_); $line_ = str_replace("\r", '', $line_); $line = TApplicationTranslator::translateTemplate($line_); // detect section start if (substr($line_, 0, 5) == '<!--[' and substr($line_, -4) == ']-->' and substr($line_, 0, 6) !== '<!--[/') { $sectionName = substr($line_, 5, strpos($line_, ']-->') - 5); $sections_stack[] = $sectionName; $buffer[$sectionName] = ''; } // detect section end if (substr($line_, 0, 6) == '<!--[/') { $sectionName = substr($line_, 6, strpos($line_, ']-->') - 6); if (isset($this->repeatSection[$sectionName]) and $this->repeatSection[$sectionName]) { // if the section is repeatable, repeat the content according to its replacements if (isset($this->replacements[$sectionName])) { foreach ($this->replacements[$sectionName] as $iteration_replacement) { $row = $buffer[$sectionName]; $row = $this->replace($iteration_replacement, $row); print $row; } } } $buffer[$sectionName] = ''; array_pop($sections_stack); } $sectionName = end($sections_stack); if (in_array($sectionName, $this->enabledSections)) { // if the section is repeatable, then put the line inside the buffer if (isset($this->repeatSection[$sectionName]) and $this->repeatSection[$sectionName]) { $buffer[$sectionName] .= $line; } else { // print the line with the replacements if (isset($this->replacements[$sectionName])) { print $this->replace($this->replacements[$sectionName], $line); } else { print $line; } } } } } }