Blame view

application/blocks.php 1.38 KB
8d65d0ce   andryeyev   init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  <?php
  Class Blocks{
   private $tpl;
   private $classes = array();
   private $path;
   private $controller;
   public static $load = true;
   
   function __construct() {
        //  $this->tpl = $tpl;
   }
   
   function setParams($tpl,&$error,$lang,$url,$getParam,$postParam){
          $this->tpl = $tpl;
          $this->error = &$error;
          $this->lang = $lang;
          $this->url = $url;
          $this->getParam = $getParam;
          $this->postParam = $postParam;
   }
   
   private function runDirBlocks(){
           $dir = $this->path . "/blocks/";
           if (is_dir($dir)) {
           $includes_dir = opendir($dir);
           while ( ($inc_file = readdir($includes_dir)) != false )
           if (strstr($inc_file,".php"))
            {include $dir . $inc_file;
             $arr = explode('.',$inc_file);
             $class_name = ucfirst($arr[0]) . ucfirst($arr[1]);
             $this->addClass($class_name);
            }}
   }
  
  private function addClass($class_name){
   array_push($this->classes, $class_name);
  }
  
          public function loader($path_module,$controller){
           if(self::$load){
           $this->path = $path_module;
           $this->controller = $controller;
           $this->runDirBlocks();
           foreach($this->classes as $class_name){
            $class = new $class_name($this->tpl,$this->error,$this->lang,$this->url,$this->getParam,$this->postParam);
            $class->run();
           }
           }
          }
  }
  ?>