Exemplo n.º 1
0
 public function load()
 {
     // Load config
     // Try from cache
     $cachekey = "config";
     if ($this->user) {
         $cachekey .= ":" . $this->user;
     }
     $this->config = Cache::load("config");
     if (!is_array($this->config) || $this->get('cache.active') != 1) {
         // Load config from database
         $sql = new SqlManager();
         if (!is_null($this->user)) {
             $sql->setQuery("SELECT * FROM config WHERE user_id = {{user}}");
             $sql->bindParam("{{user}}", $this->user);
         } else {
             $sql->setQuery("SELECT * FROM config WHERE user_id IS NULL");
         }
         $sql->execute();
         $this->config = array();
         while ($row = $sql->fetch()) {
             $this->config[$row['name']] = $row['value'];
         }
         if (!isset($this->config['cache.active']) || $this->config['cache.active'] != 1) {
             // If cache is deactivated, clear possible cache file
             Cache::clear($cachekey);
         } else {
             // If cache is activeated, save config for later use
             Cache::save($cachekey, $this->config);
         }
     }
 }
Exemplo n.º 2
0
 public static function loadVersions($type, $id)
 {
     $versions = Cache::load("version:" . $type . ":" . $id);
     if (!is_array($versions)) {
         $sql = new SqlManager();
         $sql->setQuery("\n\t\t\t\tSELECT id, date FROM version\n\t\t\t\tWHERE object_table = '{{type}}'\n\t\t\t\t\tAND object_id = {{id}}\n\t\t\t\t\tAND draft IS NULL\n\t\t\t\tORDER BY date ASC\n\t\t\t\t");
         $sql->bindParam("{{type}}", $type);
         $sql->bindParam("{{id}}", $id, "int");
         $sql->execute();
         $versions = array("_index" => array());
         while ($row = $sql->fetch()) {
             $versions['_index'][] = $row['id'];
             $versions[$row['id']] = $row;
         }
         Cache::save("version:" . $type . ":" . $id, $versions);
     }
     return $versions;
 }
Exemplo n.º 3
0
 public static function load($lang = null)
 {
     if (!$lang) {
         $lang = self::getLanguage();
     }
     $cachekey = "locale:" . $lang;
     $locale = Cache::load($cachekey);
     if (!is_array($locale)) {
         // No cache available -> load from database
         $sql = new SqlManager();
         $sql->setQuery("SELECT * FROM locale WHERE language = {{lang}}");
         $sql->bindParam('{{lang}}', $lang, "int");
         $sql->execute();
         $locale = array();
         while ($res = $sql->fetch()) {
             self::$locales[$lang][$res['code']] = $res['text'];
         }
         // Save loaded locales into cache file for later use
         Cache::save($cachekey, $locale);
     }
 }
Exemplo n.º 4
0
 public static function load($name, $parent = null, $level = 0, $maxlevel = 0)
 {
     $assortment = array();
     $sql = new SqlManager();
     if (is_null($parent)) {
         $sql->setQuery("\n\t\t\t\tSELECT assortment.*, COUNT(*) AS cnt FROM assortment\n\t\t\t\tLEFT JOIN meta ON (meta.name = 'assortment' AND meta.value = assortment.id)\n\t\t\t\tWHERE assortment.name = '{{name}}'\n\t\t\t\t\tAND assortment.parent_id IS NULL\n\t\t\t\tGROUP BY assortment.id\n\t\t\t\tORDER BY assortment.sortkey ASC\n\t\t\t\t");
     } else {
         $sql->setQuery("\n\t\t\t\tSELECT assortment.*, COUNT(*) AS count FROM assortment\n\t\t\t\tLEFT JOIN meta ON (meta.name = 'assortment' AND meta.value = assortment.id)\n\t\t\t\tWHERE assortment.name = '{{name}}'\n\t\t\t\t\tAND assortment.parent_id = {{parent}}\n\t\t\t\tGROUP BY assortment.id\n\t\t\t\tORDER BY assortment.sortkey ASC\n\t\t\t\t");
         $sql->bindParam("{{parent}}", $parent, "int");
     }
     $sql->bindParam("{{name}}", $name);
     $sql->execute();
     $i = 0;
     while ($row = $sql->fetch()) {
         $assortment[$i] = $row;
         if ($level < $maxlevel) {
             $assortment[$i]['_children'] = self::load($name, $row['id'], $level + 1, $maxlevel);
             $assortment[$i]['count'] += $assortment[$i]['_children']['cnt'];
         }
         $i++;
     }
     return $assortment;
 }
Exemplo n.º 5
0
 public static function load($table, $id, $name = null, $single = false)
 {
     // Load meta data from database
     $sql = new SqlManager();
     $sql->setQuery("SELECT * FROM meta WHERE object_table = '{{table}}' AND object_id = {{id}}");
     $sql->bindParam("{{table}}", $table);
     $sql->bindParam("{{id}}", $id, "int");
     $sql->execute();
     $return = array();
     while ($meta = $sql->fetch()) {
         if (!is_null($name) && $meta['name'] != $name) {
             continue;
         }
         if (!$single) {
             if (!isset($return[$meta['name']])) {
                 $return[$meta['name']] = array();
             }
             $return[$meta['name']][] = $meta['value'];
         } else {
             $return[$meta['name']] = $meta['value'];
         }
     }
     return $return;
 }
Exemplo n.º 6
0
 public function check()
 {
     // Check rights for setup instance
     // Check if neccessary fields are all set
     if (!$this->table) {
         throw new Exception("Table not set!");
         return;
     }
     if (!$this->id) {
         throw new Exception("ID not set!");
         return;
     }
     if (!is_object($this->user)) {
         throw new Exception("User not set!");
         return;
     }
     // Check users access rights to any object
     $cachekey = "access:" . $this->table . ":" . $this->id . ":" . $this->user->getID();
     $this->access = Cache::load($cachekey);
     if (is_null($this->access)) {
         // No cache found, load access rights from database
         $this->access = true;
         $sql = new SqlManager();
         $sql->setQuery("\n\t\t\t\tSELECT * FROM access\n\t\t\t\tWHERE object_table = '{{table}}'\n\t\t\t\t\tAND object_id = {{id}}\n\t\t\t\t");
         $sql->bindParam("{{table}}", $this->table);
         $sql->bindParam("{{id}}", $this->id, "int");
         $sql->execute();
         $rulescnt = 0;
         while ($row = $sql->fetch()) {
             $rulescnt++;
             switch ($row['access_type']) {
                 case "password":
                     // Check somehow if user entered password already
                     $this->access = false;
                     $this->access_data = $row;
                     break;
                 case "usergroup":
                     // Check if user is part of the usergroup
                     if (!in_array($row['access_key'], $this->user->getUserGroups())) {
                         $this->access = false;
                         $this->access_data = $row;
                     }
                     break;
                 default:
                     $this->access = false;
                     break;
             }
             if ($this->access) {
                 // If one of the access settings allows access, it's enough
                 // Stop loop
                 $this->access_data = array();
                 break;
             }
         }
         if ($this->access && count($this->parents) > 0) {
             foreach ($this->parents as $parent) {
                 $check = $this->parents[count($this->parents) - 1];
                 unset($this->parents[count($this->parents) - 1]);
                 $check = new AccessOfficer($this->table, $check, $this->user, $this->parents);
                 $this->access = $check->check();
                 $this->access_data = $check->getAccessData();
             }
         }
         // Save determined access in cahce for later use
         Cache::save($cachekey, $this->access);
     }
     return $this->access;
 }
Exemplo n.º 7
0
 public function loadElements($parent = null)
 {
     // Get elements to loaded content from the database for given parent id
     // Is used recursiv to load the hierarchical structure of the content elements
     if (!isset($this->id)) {
         throw new Exception("Cannot get content elements! No content set!");
         return;
     }
     // Try from cache first
     $elements = array();
     // No cache found, load from database
     $sql = new SqlManager();
     if ($parent > 0) {
         $sql->setQuery("SELECT * FROM element WHERE object_table = 'content' AND object_id = {{id}} AND parent_id = {{parent}} ORDER BY sortkey");
         $sql->bindParam("{{parent}}", $parent, "int");
     } else {
         $sql->setQuery("SELECT * FROM element WHERE object_table = 'content' AND object_id = {{id}} AND parent_id IS NULL ORDER BY sortkey");
     }
     $sql->bindParam("{{id}}", $this->id, "int");
     $sql->execute();
     while ($element = $sql->fetch()) {
         if (!isset($elements[$element['position']])) {
             $elements[$element['position']] = array();
         }
         $element['parameters'] = unserialize($element['parameters']);
         $index = count($elements[$element['position']]);
         $elements[$element['position']][$index] = $element;
         // Created parent-children array tree
         $elements[$element['position']][$index]['_children'] = $this->loadElements($element['id']);
     }
     return $elements;
 }
Exemplo n.º 8
0
 public function initPlugins()
 {
     // Init installed and actived plugins
     $sql = new SqlManager();
     $sql->setQuery("SELECT * FROM plugin WHERE active = 1");
     $sql->execute();
     while ($plugin = $sql->fetch()) {
         // Check plugin core file
         $path = __DIR__ . "/" . $this->plugin_root . "/" . strtolower($plugin['name']) . "/" . $plugin['name'] . ".php";
         if (is_file($path)) {
             // ... and include it
             include_once $path;
             // Then check for class and init method and call if possible
             if (class_exists($plugin['name'])) {
                 $instance = new $plugin['name']();
                 if (method_exists($instance, "init")) {
                     $instance->init();
                 } else {
                     throw new Exception("Init method in plugin '{$plugin['name']}' core file not found!");
                 }
             } else {
                 throw new Exception("Class for plugin '{$plugin['name']} not found!");
             }
         } else {
             throw new Exception("Core file for plugin '{$plugin['name']}' not found!");
         }
     }
 }