3 require_once("AOOSException.php");
4 require_once("AOOSModel.php");
5 require_once("AOOSStorageDevice.php");
11 * The core class of AOOS
13 * @author Sebastian Skejø
18 private $_exceptions = array();
19 private $_modules = null;
20 private $_settings = array();
21 private $_transStrings = array();
22 private $_log = array();
25 * During constructing a model is built with module names and properties
27 public function __construct()
29 require_once("config.php");
30 $this->_settings
= $settings; /* Set in config.php */
31 $l = $this->getSetting("lang");
32 require_once("lang.php");
33 if (!in_array($l, array_keys($lang))) /* $lang set in lang.php */
35 throw new AOOSException($this, "Language not found in lang.php. You will not be able to translate strings","",true, 1);
39 $this->_transStrings
= $lang[$l];
43 $s = new AOOSStorageDevice($this);
44 $s->setStorageType("mysql");
45 $s->setTable("modules");
46 $this->_modules
= $s->selectModel("*");
47 $this->_modules
->setEscape(false);
50 public function log($str)
57 * @param AOOSException $e The exception
59 public function setException($e)
61 $this->_exceptions
[$e->getName()] = $e;
62 if ($e->getEcode() == 0)
70 public function printExceptions()
72 $str = "<div class=\"Exceptions\">";
73 foreach ($this->_exceptions
as $e)
81 public function getSetting($name, $module = "no")
83 $a = $this->_settings
;
84 if ($module != "no" && $this->isLoaded($module))
88 if (!in_array($name, array_keys($a)))
90 throw new AOOSException($this, "Settingkey not found", "Key: ".$name, true, 2);
96 public function getTranslatedString($string, $module = "no")
98 $a = $this->_transStrings
;
99 if ($module != "no" && $this->isLoaded($module))
103 if (!in_array($string, array_keys($a)))
105 throw new AOOSException($this, "Translated string not found", "String name: ".$string, true, 2);
111 public function modules()
113 return $this->_modules
;
116 public function loadModule($name)
118 $this->log("Loading ".$name);
119 $m = $this->modules();
120 if (($r = $m->getRowFromValue("name", $name)) === false)
122 $this->log("Failed!");
123 throw new AOOSException($this, $this->getTranslatedString("module_not_loadable"), "", true, 1);
127 $row = $m->getRow($r);
128 $dir = $this->getSetting("module_dir")."/".$row["name"]."/";
129 $filename = $row["name"].$this->getSetting("extension");
131 $deps = explode(",", $row["deps"]);
132 if (!empty($deps[0]))
134 foreach($deps as $dep)
136 if (!$this->isLoaded($dep))
140 $this->loadModule($dep);
142 catch(AOOSException
$e)
144 throw new AOOSException($this, $this->getTranslatedString("deps_not_loadable"), $row["name"], true, 1);
151 if ($row["instance"])
154 return $row["instance"];
157 require_once($dir.$filename);
158 if (file_exists($dir."settings".$this->getSetting("extension")))
160 require_once($dir."settings".$this->getSetting("extension"));
161 $this->_settings
[$row["name"]] = $settings;
163 if (file_exists($dir."lang".$this->getSetting("extension")))
165 require_once($dir."lang".$this->getSetting("extension"));
166 $this->_transStrings
[$row["name"]] = $lang;
168 $i = new $row["name"]($this);
169 $m->setData($i, $r, "instance");
176 * Returns true if $module is loaded, otherwise return false.
177 * @param string $name Module name
180 public function isLoaded($name)
182 $m = $this->modules();
183 if (($row = $m->getRowFromValue("name", $name)) === false)
185 // TODO: throw exception
193 * Returns an instance to the given $module
194 * @param string $module The name of the module
195 * @return false|AOOSModule
197 public function getModule($module)
199 $m = $this->modules();
200 if (($row = $m->getRowFromValue("name", $module)) === false)
202 throw new AOOSException($this, $this->getTranslatedString("module_not_found"), "", true, 1);
205 return $this->loadModule($module);
208 public function __toString()