public function load_page($url_path = false) { global $htmlwarrior, $smarty; if ($url_path === false) { $url_path = $htmlwarrior->runtime['parsed_url']['path']; } $page_tpl_path = get_page_template_path($url_path); $page_object = $smarty->createTemplate($page_tpl_path); $page_content_before_assigns = $smarty->fetch($page_object); $page_variables = parse_variables($page_content_before_assigns); if (isset($page_variables['php'])) { $page_template_php_path = $htmlwarrior->config['basepath'] . '/' . $htmlwarrior->runtime['site_dir'] . $htmlwarrior->config['path_templates_pages'] . '/' . $page_variables['php']; } else { $page_template_php_path = str_replace('.tpl', '.php', $page_tpl_path); } // load page php if (file_exists($page_template_php_path)) { $__init_page_php = function ($page_template_php_path) { global $htmlwarrior; require_once $page_template_php_path; return $params; }; $params = $__init_page_php($page_template_php_path); } $page_object = $smarty->createTemplate($page_tpl_path); foreach ($params as $key => $val) { $page_object->assign($key, $val); } $page_object->assign('page', $htmlwarrior->page); $page_content = $smarty->fetch($page_object); if ($htmlwarrior->config['build']) { $template_filetime = filemtime($page_tpl_path); } return array($page_content, $page_variables); }
if (strpos($filename_tpl, '__') === 0 || strpos($filename_tpl, 'index.tpl') === 0) { continue; } $f = explode('.', $filename); $f = explode('/', $f[0]); $group = end($f); if (!$sorted[$group]) { $sorted[$group] = array(); } $sorted[$group][] = $filename; } $out = ''; foreach ($sorted as $key => $group) { foreach ($group as $index => $filename) { $tplcontent = file_get_contents($filename); $page_variables = parse_variables($tplcontent); list($grouptitle, $filetitle) = explode('::', $page_variables['title']); if ($index == 0) { if (!$grouptitle) { $grouptitle = ucfirst($key); } $out .= '<h3>' . $grouptitle . '</h3>' . "\n"; $out .= '<ul>' . "\n"; } $filename_tpl = end(explode('/', $filename)); $filename_html = str_replace('.tpl', '.html', $filename_tpl); if (!$filetitle) { $filetitle = $filename_html; } $out .= '<li><a href="' . $filename_html . '">' . $filetitle . '</a>' . "\n"; }
function smarty_function_partial($params, &$smarty) { global $smarty, $smartysh; if (isset($params["tpl"])) { $params["template"] = $params["tpl"]; } elseif (isset($params["name"])) { $params["template"] = $params["name"]; } foreach ($params as $key => $var) { if ($key != "template") { $smarty->assign($key, $var); } } if ($params["showcss"]) { echo '<script type="text/javascript" src="http://www.google.com/jsapi"></script>'; echo '<script type="text/javascript" src="' . $smartysh->config["path_code"] . '/core/js/general.js"></script>'; echo '<script type="text/javascript">var partialName = "' . $params["template"] . '";</script>'; echo '<script type="text/javascript" src="' . $smartysh->config["path_code"] . '/core/js/showcss.js"></script>'; } // copy template from code to site if template does not exist if (!file_exists($smarty->template_dir . "/partials/" . $params["template"] . ".tpl")) { echo '<div style="background: red">Templatet ei ole olemas. Kopeerin uue?. <a href="?copy=yes">jah</a></div>'; if (@$_GET["copy"] == "yes") { if (copy($smartysh->config["code_path"] . "/templates/partials/" . $params["template"] . ".tpl", $smarty->template_dir . "/partials/" . $params["template"] . ".tpl")) { echo "done"; } else { echo $smartysh->config["code_path"] . "/templates/partials/" . $params["template"] . ".tpl does not exist!"; } } } $output = $smarty->fetch("partials/" . $params["template"] . ".tpl"); $output = remove_bom($output); $page_variables = parse_variables($output); $output = remove_variables($output); // copy files if these are listed in template if (@$_GET["copy"] == "yes") { if ($page_variables["_files"]) { foreach ($page_variables["_files"] as $key => $var) { if (file_exists($smartysh->config["code_path"] . "/" . $var) && !file_exists($smartysh->config["basepath"] . "/" . $smartysh->runtime["site_dir"] . "/" . $var)) { if (copy($smartysh->config["code_path"] . "/" . $var, $smartysh->config["basepath"] . "/" . $smartysh->runtime["site_dir"] . "/" . $var)) { echo "done copying {$var}"; } } } } if ($page_variables["stylefile"]) { // todo? } // get help if exists? todo } // reset vars foreach ($params as $key => $var) { if ($key != "template" && $key != "indent") { $smarty->clearAssign($key); } } $a_output = explode("\n", $output); $first_line = true; foreach ($a_output as $key => $var) { if (!$first_line || $params["fullindent"]) { $a_output[$key] = $params["indent"] . $var; } else { $first_line = false; $a_output[$key] = $var; } } // fix: remove lines with only spaces $a_outputFinal = array(); foreach ($a_output as $key => $var) { if (trim($var) != "") { $a_outputFinal[$key] = $var; } } $s_outputFinal = implode("\n", $a_outputFinal); // write placeholders with script tag so they don't mess up the docs // validity if ($smartysh->config["show_partial_edit_links"] && $params["template"] != "script") { $s_outputFinal = trim($s_outputFinal); if (strlen($s_outputFinal)) { if (!isset($smarty->partial_index)) { $smarty->partial_index = 1; } else { $smarty->partial_index++; } $placeholder_params_begin = 'id="' . $smartysh->config["smartysh_prefix"] . '_placeholder_begin__' . $smarty->partial_index . '"'; $placeholder_params_end = 'id="' . $smartysh->config["smartysh_prefix"] . '_placeholder_end__' . $smarty->partial_index . '"'; if (get_first_tag_name($s_outputFinal) == "li") { $s_outputFinal = '<li ' . $placeholder_params_begin . ' style="display:none"><script type="text/javascript">smartysh_partial_edit_links[' . $smarty->partial_index . ']={"name":"' . $params["template"] . '", "path_edit":"' . mk_partial_edit_link($params["template"] . ".tpl") . '"}</script></li>' . $s_outputFinal . '<li ' . $placeholder_params_end . ' style="display:none"></li>'; } else { $s_outputFinal = ' <script type="text/javascript" ' . $placeholder_params_begin . '>smartysh_partial_edit_links[' . $smarty->partial_index . ']={"name":"' . $params["template"] . '", "path_edit":"' . mk_partial_edit_link($params["template"] . ".tpl") . '"}</script>' . $s_outputFinal . '<script type="text/javascript" ' . $placeholder_params_end . '></script>'; } } } return $s_outputFinal; }
if (@strpos($request_uri[1], "__logged")) { $smarty->assign("logged_sufix", "__logged"); $smartysh->logged_sufix = "__logged"; $smarty->assign("logged", true); $smartysh->logged = true; } else { $smarty->assign("logged_sufix", ""); $smartysh->logged_sufix = ""; $smarty->assign("logged", false); $smartysh->logged = false; } $page_content = $smarty->fetch(get_page_template_path($smartysh->runtime["parsed_url"]["path"])); if ($smartysh->config["build"]) { $template_filetime = filemtime(get_page_template_path($smartysh->runtime["parsed_url"]["path"])); } $page_variables = parse_variables($page_content); if (!isset($page_variables["layout"])) { $smartysh->layout = "default"; } else { $smartysh->layout = $page_variables["layout"]; } $layout_path = "layouts/" . $smartysh->layout . ".tpl"; $variable_indents = get_indents_for_variables(file_get_contents($smarty->template_dir . "/" . $layout_path)); if (isset($page_variables["title"])) { $smarty->assign("title", $page_variables["title"]); } else { $smarty->assign("title", ""); } if (isset($page_variables["custom1"])) { $smarty->assign("custom1", $page_variables["custom1"]); } else {