3 class mw_env_helpers extends mw_env{
7 function init_helpers(){
8 $this->helpers = false;
9 $helpers_files = array();
10 if(($plugins = $this->plugins()) !== false){
11 foreach($plugins as $plugin_name => $plugin){
12 $helpers_path = $this->path("mw_dir")."plugins/".$plugin_name."/app/helpers/";
16 && file_exists($helpers_path)
17 && is_dir($helpers_path)
19 if($dh = opendir($helpers_path)){
20 while(($file = readdir($dh)) !== false){
22 substr($file, 0, 1) != "."
23 && !is_dir($helpers_path.$file)
24 && strcmp(substr($file, -4), ".php") == 0
25 && !isset($helpers_files[$file])
26 ) $helpers_files[$file] = $helpers_path;
33 $helpers_path = $this->path("mw_dir")."app/helpers/";
35 file_exists($helpers_path)
36 && is_dir($helpers_path)
38 if($dh = opendir($helpers_path)){
39 while(($file = readdir($dh)) !== false){
41 substr($file, 0, 1) != "."
42 && !is_dir($helpers_path.$file)
43 && strcmp(substr($file, -4), ".php") == 0
44 && !isset($helpers_files[$file])
45 ) $helpers_files[$file] = $helpers_path;
52 $this->helpers = array();
53 foreach($helpers_files as $file => $helpers_path){
54 $this->helpers[substr($file, 0, -4)] = array("file" => $helpers_path.$file);
59 function helper($helper_name){
60 if(!isset($this->helpers)) $this->init_helpers();
61 if($this->helpers === false || !isset($this->helpers[$helper_name])) return false;
62 if(!isset($this->helpers[$helper_name]["file"])) return false;
63 if($this->init_helper($helper_name)) return $this->helpers[$helper_name]["impl"];
67 function init_helper($helper_name){
68 if(!isset($this->helpers[$helper_name]["impl"])){
69 if(!class_exists($helper_name)){
71 !isset($this->helpers[$helper_name]["file"])
72 || !$this->helpers[$helper_name]["file"]
73 || !file_exists($this->helpers[$helper_name]["file"])
75 require_once $this->helpers[$helper_name]["file"];
76 if(!class_exists($helper_name)) return false;
78 $this->helpers[$helper_name]["impl"] = new $helper_name();
79 $this->helpers[$helper_name]["impl"]->set_env($this);
82 if($this->helpers[$helper_name]["impl"] === false) return false;
92 function set_env(&$env){