0fd19b87746ed7c59df63846c037fcf606c5fd25
[mtweb] / mw / env / modules / mw_env_init.php
1 <?php
2
3   class mw_env_init extends mw_env{
4
5     function init(){
6       $init_files = array();
7       if(($plugins = $this->plugins()) !== false){
8         foreach($plugins as $plugin_name => $plugin){
9           $init_path = $this->path("mw_dir")."plugins/".$plugin_name."/app/init/";
10           if(
11                $plugin["installed"]
12             && $plugin["enabled"]
13             && file_exists($init_path)
14             && is_dir($init_path)
15           ){
16             if($dh = opendir($init_path)){
17               $files = array();
18               while(($file = readdir($dh)) !== false){
19                 if(
20                      substr($file, 0, 1) != "."
21                   && !is_dir($init_path.$file)
22                   && strcmp(substr($file, -4), ".php") == 0
23                   && !isset($init_files[$file])
24                 ) $init_files[$file] = $init_path;
25               }
26               closedir($dh);
27             }
28             else $this->erreur("impossible d'ouvrir le dossier init du plugin ".$plugin_name, true);
29           }
30           if($this->erreurs()) return;
31         }
32         $init_path = $this->path("mw_dir")."app/init/";
33         if(
34              file_exists($init_path)
35           && is_dir($init_path)
36         ){
37           if($dh = opendir($init_path)){
38             $files = array();
39             while(($file = readdir($dh)) !== false){
40               if(
41                    substr($file, 0, 1) != "."
42                 && !is_dir($init_path.$file)
43                 && strcmp(substr($file, -4), ".php") == 0
44               ) $init_files[$file] = $init_path;
45             }
46             closedir($dh);
47           }
48           else $this->erreur("impossible d'ouvrir le dossier init", true);
49         }
50       }
51       if($this->erreurs()) return;
52       if($init_files){
53         ksort($init_files);
54         foreach($init_files as $file => $init_path){
55           require $init_path.$file;
56           if($this->erreurs()) return;
57         }
58       }
59     }
60
61   }
62
63 ?>