Example #1
0
if (!isset($page_variables['layout'])) {
    $htmlwarrior->layout = 'default';
} else {
    $htmlwarrior->layout = $page_variables['layout'];
}
// Get full layout path
$layout_path = $htmlwarrior->config['basepath'] . '/' . $htmlwarrior->runtime['site_dir'] . $htmlwarrior->config["path_templates_layouts"] . '/' . $htmlwarrior->layout . '.tpl';
// Get all variables indents so we can indent the content right
// We're after the $yield variable indent now
$variable_indents = get_indents_for_variables(file_get_contents($layout_path));
// set variables
// should these be added to layout template object (which we don't have yet)
foreach ($page_variables as $key => $var) {
    $smarty->assign($key, $var);
}
$yield = indent(remove_variables($page_content), $variable_indents['yield']);
$yield = ltrim($yield);
$smarty->assign('yield', $yield);
unset($yield);
// add access log; must be after frontpage so we don't log that
if ($htmlwarrior->config['log']) {
    add_access_log(array('site_dir' => $htmlwarrior->runtime['site_dir'], 'url' => $_SERVER['REQUEST_URI']));
}
//require_once('filelist.php');
ob_start('callback');
if ($page_variables['layout'] === false) {
    $layout_path = $htmlwarrior->config['code_path'] . $htmlwarrior->config['path_templates_layouts'] . '/' . 'empty.tpl';
}
$smarty->display($layout_path);
$htmlwarrior->config['devmode'] = false;
$content = $smarty->fetch($layout_path);
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;
}
Example #3
0
function html_create_list($form_data, $column_display, $column_id, $form_previous_value, $trim_display_length = 0) {
	require_once(CACTI_BASE_PATH . "/lib/sys/variable.php");

	if (empty($column_display)) {
		foreach (array_keys($form_data) as $id) {
			if (empty($trim_display_length)) {
				$item_text = htmlspecialchars((remove_variables($form_data[$id])), ENT_QUOTES);
			}else{
				$item_text = htmlspecialchars((title_trim(remove_variables($form_data[$id]), $trim_display_length)), ENT_QUOTES);
			}

			echo '<option value="' . htmlspecialchars($id, ENT_QUOTES) . '"';

			if (strval($form_previous_value) == $id) {
				echo " selected";
			}

			echo ">$item_text</option>\n";
		}
	}else{
		if (sizeof($form_data) > 0) {
			foreach ($form_data as $row) {
				if (empty($trim_display_length)) {
					$item_text = htmlspecialchars((remove_variables($row[$column_display])), ENT_QUOTES);
				}else{
					$item_text = htmlspecialchars((title_trim(remove_variables($row[$column_display]), $trim_display_length)), ENT_QUOTES);
				}

				echo "<option value='" . htmlspecialchars($row[$column_id], ENT_QUOTES) . "'";

				if (strval($form_previous_value) == $row[$column_id]) {
					echo " selected";
				}

				//if (isset($row["host_id"])) {
				//	print ">" . htmlspecialchars(title_trim($row[$column_display], 75), ENT_QUOTES) . "</option>\n";
				//}else{
				echo ">$item_text</option>\n";
				//}
			}
		}
	}
}
Example #4
0
function api_data_source_title_get($data_source_id, $remove_unsubstituted_variables = false) {
	require_once(CACTI_BASE_PATH . "/lib/sys/variable.php");

	$data_source = db_fetch_row("select host_id,name,name_cache from data_source where id = $data_source_id");

	$title = $data_source["name"];

	if ((strstr($data_source["name"], "|host_")) && (!empty($data_source["host_id"]))) {
		$title = substitute_host_variables($title, $data_source["host_id"]);
	}

	if ((strstr($data_source["name"], "|query_")) && (!empty($data_source["host_id"]))) {
		$data_query = array_rekey(db_fetch_assoc("select
			data_source_field.name,
			data_source_field.value
			from data_source_field,data_source
			where data_source.id=data_source_field.data_source_id
			and data_source.id = $data_source_id"), "name", "value");

		if ((isset($data_query["data_query_id"])) && (isset($data_query["data_query_index"]))) {
			$title = substitute_data_query_variables($title, $data_source["host_id"], $data_query["data_query_id"], $data_query["data_query_index"], read_config_option("max_data_query_field_length"));
		}
	}

	if ($remove_unsubstituted_variables == true) {
		$title = remove_variables($title);
	}

	if (((empty($title)) || (substr_count($title,"|"))) && (!empty($data_source["name_cache"]))) {
		$title = $data_source["name_cache"];
	}

	return $title;
}
Example #5
0
} 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 {
    $smarty->assign("custom1", "");
}
$smarty->assign("yield", indent(remove_variables($page_content), $variable_indents["yield"]));
// add access log; must be after frontpage so we don't log that
if ($smartysh->config["log"]) {
    add_access_log(array("site_dir" => $smartysh->runtime["site_dir"], "url" => $_SERVER["REQUEST_URI"]));
}
require_once $smartysh->config["basepath"] . "/" . $smartysh->runtime["site_dir"] . "/cfg/config.php";
//require_once("filelist.php");
ob_start("callback");
$smarty->display($layout_path);
$smarty->assign("debug", 0);
$content = $smarty->fetch($layout_path);
@ob_end_flush();
if ($smartysh->config["build"]) {
    build_template($smartysh->config["basepath"] . "/" . $smartysh->runtime["site_dir"] . "/" . $smartysh->config["build_dir"] . "/" . $smartysh->page . ".html", $content, $template_filetime);
}
if ($smartysh->config["debug"]) {
Example #6
0
function api_graph_title_get($graph_id, $remove_unsubstituted_variables = false) {
	require_once(CACTI_BASE_PATH . "/lib/sys/variable.php");

	$graph = db_fetch_row("select host_id,title from graph where id = $graph_id");

	$title = $graph["title"];

	if ((strstr($graph["title"], "|host_")) && (!empty($graph["host_id"]))) {
		$title = substitute_host_variables($title, $graph["host_id"]);
	}

	if ((strstr($graph["title"], "|query_")) && (!empty($graph["host_id"]))) {
		$data_query = array_rekey(db_fetch_assoc("select distinct
			data_source_field.name,
			data_source_field.value
			from data_source_field,graph_item,data_source_item
			where graph_item.data_source_item_id=data_source_item.id
			and data_source_item.data_source_id=data_source_field.data_source_id
			and graph_item.graph_id = $graph_id"), "name", "value");

		if ((isset($data_query["data_query_id"])) && (isset($data_query["data_query_index"]))) {
			$title = substitute_data_query_variables($title, $graph["host_id"], $data_query["data_query_id"], $data_query["data_query_index"], read_config_option("max_data_query_field_length"));
		}
	}

	if ($remove_unsubstituted_variables == true) {
		return remove_variables($title);
	}else{
		return $title;
	}
}