OpenSencillo  2016.106
Long live the simplicity of PHP
 All Data Structures Namespaces Files Functions Pages
lib_identificator.php
1 <?php
11 class library
12 {
13  protected $all_data_sencillo;
14  protected $readsql;
15  protected $files;
16  protected $modules;
17 
18  private $config = array();
19 
20  public $lib;
21 
22  public function __construct()
23  {
24  $this->config('lib_folder','fw_libraries');
25  $this->config('mod_folder','fw_modules');
26  $this->config('lib_ignore','lib_identificator.php');
27  }
28 
32  private function createStructure()
33  {
34  $this->lib=array("id"=>array(),
35  "function"=>array(),
36  "boxid"=>array(),
37  "status"=>array());
38  $this->all_data_sencillo=array("left"=>array(),
39  "center"=>array(),
40  "right"=>array(),
41  "foot"=>array(),
42  "admin"=>array());
43  $this->files = scandir('./' . $this->config['lib_folder'] . '/');
44  //var_dump($this->config,$this->files);
45  if(file_exists('./' . $this->config['mod_folder'] . '/'))
46  {
47  $this->modules = scandir('./' . $this->config['mod_folder'] . '/');
48  }
49  }
50 
54  private function openFiles()
55  {
56  foreach($this->files as $value)
57  {
58  $test=(($value!='.')&&($value!='..')&&($value!=$this->config['lib_ignore'])&&($value!='examples')?true:false);
59 
60  if(($value!='.')&&($value!='..')&&($value!=$this->config['lib_ignore'])&&($value!='examples'))
61  {
62  $this->lib['id'][]=$value;
63  }
64  }
65 
66  foreach($this->lib['id'] as $value)
67  {
68  try
69  {
70  //require("./fw_libraries/".$value);
71  $NAME=explode(".",$value);
72  $MOD_DESC=$NAME[0].','.$NAME[1];
73  $this->lib['name'][]=$NAME[2];
74  $this->lib['function'][]=$MOD_DESC;
75  $this->lib['version'][]=$VERSION;
76  $this->lib['status'][]='OK:'.$value;
77  $this->lib['path'][]='./' . $this->config['lib_folder'] . '/'.$value;
78  $this->lib['install'][]='../' . $this->config['lib_folder'] . '/'.$value;
79  }
80  catch(Exception $e)
81  {
82  $this->lib['status']=array('ERROR:'.$value.':'.$e);
83  }
84  }
85  }
86 
90  private function openModules()
91  {
92  foreach($this->modules as $value)
93  {
94  $test=((file_exists('./' . $this->config['mod_folder'] . '/'.$value.'/'))&&($value!='.')&&($value!='..')&&($value!=$this->config['lib_ignore'])&&($value!='examples')?true:false);
95 
96  if((file_exists('./' . $this->config['mod_folder'] . '/'.$value.'/'))&&($value!='.')&&($value!='..')&&($value!=$this->config['lib_ignore'])&&($value!='examples'))
97  {
98  $this->lib['id'][]=$value;
99  }
100  }
101 
102  foreach($this->lib['id'] as $value)
103  {
104  try
105  {
106  $this->lib['name'][]=$value;
107  $this->lib['function'][]='custom_module';
108  $this->lib['status'][]='OK:'.$value;
109  $this->lib['path'][]='./' . $this->config['mod_folder'] . '/'.$value.'/info_'.$value.'.php';//information about module
110  $this->lib['path'][]='./' . $this->config['mod_folder'] . '/'.$value.'/update_'.$value.'.php';//update database for module
111  $this->lib['path'][]='./' . $this->config['mod_folder'] . '/'.$value.'/install_'.$value.'.php';//installer
112  $this->lib['path'][]='./' . $this->config['mod_folder'] . '/'.$value.'/main_'.$value.'.php';//main module
113  $this->lib['path'][]='./' . $this->config['mod_folder'] . '/'.$value.'/'.$value.'.php';//basic module
114  }
115  catch(Exception $e)
116  {
117  $this->lib['status'][]='ERROR:'.$value.':'.$e;
118  }
119  }
120  }
121 
126  public function install($ignored)
127  {
128  $this->createStructure();
129  $this->files = array_diff(scandir('../' . $this->config['lib_folder'] . '/'),$ignored);
130  $this->openFiles();
131  }
132 
133  /*
134  * Set one value and his key in config
135  * @param string $key
136  * @param string $val
137  * @return bool
138  */
139  public function config($key,$val)
140  {
141  unset($this->config[$key]);
142  if(empty($this->config[$key]))
143  {
144  $this->config[$key] = $val;
145  return true;
146  }
147  else
148  {
149  return false;
150  }
151  }
152 
156  public function start()
157  {
158  $this->createStructure();
159  $this->openFiles();
160  //$this->openModules();
161  }
162 
167  public function export()
168  {
169  return $this->all_data_sencillo;
170  }
171 
176  public function status()
177  {
178  return $this->lib;
179  }
180 
185  public function exportPath()
186  {
187  return array_unique($this->lib['path']);
188  }
189 
194  public function installerPath()
195  {
196  return array_unique($this->lib['install']);
197  }
198 }
199 ?>