X-Git-Url: http://git.dj3c1t.com/index.cgi?a=blobdiff_plain;f=mw%2Fenv%2Fmodules%2Fmw_env_out.php;h=f405fca79bd2e901f0dfb11db004d198f3f05123;hb=0df77b6e0e0eee4060e73ca0d6955bf232aa23cc;hp=e61b8ccc260e671b6784fba0d90bcca6e01fa571;hpb=eefcb5168f6353f56399fd6fa594e2b221d43e5d;p=mtweb diff --git a/mw/env/modules/mw_env_out.php b/mw/env/modules/mw_env_out.php index e61b8cc..f405fca 100644 --- a/mw/env/modules/mw_env_out.php +++ b/mw/env/modules/mw_env_out.php @@ -6,6 +6,11 @@ var $out_config; var $layout; + var $js_files; + var $css_files; + + var $template; + // --------------------------------------------------------------------------------- // out vars // @@ -27,6 +32,37 @@ // templates // + function templates(){ + if(($out_pathes = $this->out_pathes()) === false) return false; + $templates = array(); + $current_out_path = $this->config("out"); + foreach($out_pathes as $out_path){ + $this->set_config(array("out" => $out_path)); + $templates[$out_path] = $this->_get_template(); + } + $this->set_config(array("out" => $current_out_path)); + return $templates; + } + + function get_template(){ + if(isset($this->template)) return $this->template; + $this->template = $this->_get_template(); + return $this->template; + } + + function _get_template(){ + $template_class_name = "mw_template"; + if($this->out_file_exists("template.php")){ + $template_class_file = $this->out_file("template.php"); + $template_class_name = "mw_template_".basename(dirname($template_class_file)); + if(!class_exists($template_class_name)) require_once $template_class_file; + if(!class_exists($template_class_name)) $template_class_name = "mw_template"; + } + $template = new $template_class_name(true); + $template->set_env($this->root_inst); + return $template; + } + function out_pathes(){ $pathes = array(); if(($plugins = $this->plugins()) !== false){ @@ -126,6 +162,50 @@ } // --------------------------------------------------------------------------------- + // js / css files + // + + function js_files(){ + if(!isset($this->js_files)) $this->js_files = array(); + $files = array(); + foreach($this->js_files as $url => $enabled){ + if($enabled) $files[] = $url; + } + return $files; + } + + function add_js_file($url){ + if(!isset($this->js_files)) $this->js_files = array(); + $this->js_files[$url] = true; + } + + function remove_js_file($url){ + if(isset($this->js_files) && isset($this->js_files[$url])){ + unset($this->js_files[$url]); + } + } + + function css_files(){ + if(!isset($this->css_files)) $this->css_files = array(); + $files = array(); + foreach($this->css_files as $url => $enabled){ + if($enabled) $files[] = $url; + } + return $files; + } + + function add_css_file($url){ + if(!isset($this->css_files)) $this->css_files = array(); + $this->css_files[$url] = true; + } + + function remove_css_file($url){ + if(isset($this->css_files) && isset($this->css_files[$url])){ + unset($this->css_files[$url]); + } + } + + // --------------------------------------------------------------------------------- // out config // @@ -154,46 +234,6 @@ return $this->layout; } - function render_layout($layout = null){ - if(!isset($layout)) $layout = $this->init_layout(); - if(($plugins = $this->plugins("ASC")) !== false){ - foreach($plugins as $plugin_name => $plugin){ - if($plugin["installed"] && $plugin["enabled"]){ - $FOUND = false; - $functions_file = $this->path("mw_dir")."plugins/".$plugin_name."/app/out/".$this->config("out")."/functions.php"; - if(file_exists($functions_file)){ - $FOUND = true; - require $functions_file; - } - if(!$FOUND){ - $functions_file = $this->path("mw_dir")."plugins/".$plugin_name."/app/out/".$this->config("default_out")."/functions.php"; - if($plugin["installed"] && $plugin["enabled"] && file_exists($functions_file)){ - require $functions_file; - } - } - } - } - $FOUND = false; - $functions_file = $this->path("mw_dir")."app/out/".$this->config("out")."/functions.php"; - if(file_exists($functions_file)){ - $FOUND = true; - require $functions_file; - } - if(!$FOUND){ - $functions_file = $this->path("mw_dir")."app/out/".$this->config("default_out")."/functions.php"; - if(file_exists($functions_file)){ - require $functions_file; - } - } - if($layout["page"]){ - if($this->out_file_exists($layout["page"])) require $this->out_file($layout["page"]); - } - elseif($layout["content"]){ - if($this->out_file_exists($layout["content"])) require $this->out_file($layout["content"]); - } - } - } - function init_layout(){ $this->layout = array(); $this->_init_layout("index"); @@ -323,4 +363,60 @@ } + class mw_template extends empty_class{ + + var $out; + var $ENV_SET; + var $template_infos; + + function set_env(&$env){ + $this->modules = array("env" => $env); + $this->ENV_SET = true; + $this->set_out_config($this->get_out_config()); + $this->set_template_infos($this->get_template_infos()); + } + + function render_layout($layout = null){ + if(!isset($this->ENV_SET) || !$this->ENV_SET) return false; + if(!isset($layout)) $layout = $this->init_layout(); + $this->out = $this->get_out(); + $this->init(); + if( + ($init_script = $this->init_script()) + && $this->out_file_exists($init_script) + ) require $this->out_file($init_script); + if($layout["page"]){ + if($this->out_file_exists($layout["page"])) require $this->out_file($layout["page"]); + } + elseif($layout["content"]){ + if($this->out_file_exists($layout["content"])) require $this->out_file($layout["content"]); + } + } + + function get_template_info($key){ + return isset($this->template_infos[$key]) ? $this->template_infos[$key] : ""; + } + + function init(){ + return true; + } + + function init_script(){ + return false; + } + + function get_out_config(){ + return array(); + } + + function set_template_infos($template_infos){ + $this->template_infos = $template_infos; + } + + function get_template_infos(){ + return array(); + } + + } + ?> \ No newline at end of file