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