public function loadFromID($id, $loadmeta = true, $loadelements = true)
 {
     // Loads content with given ID
     $cachekey = "content:id:" . $id;
     $content = Cache::load($cachekey);
     if (!isset($content['id'])) {
         // No cache found, load from database
         $sql = new SqlManager();
         // ...here server and language (both coming from controller if available) should be included!
         $sql->setQuery("SELECT * FROM content WHERE id={{id}}");
         $sql->bindParam("{{id}}", $id, "int");
         $content = $sql->result();
         if (!isset($content['id'])) {
             throw new Exception("No content for ID '{$id}' found!");
             return false;
         }
         $this->id = $content['id'];
         $this->data = $content;
         // Load other content data as well
         if ($loadmeta) {
             $this->data['meta'] = $this->loadMeta();
         }
         if ($loadelements) {
             $this->data['elements'] = $this->loadElements();
         }
         // Save cache for later
         Cache::save($cachekey, $this->data);
         Cache::save("content:url:" . $this->data['url'], $this->data);
     }
     return true;
 }
 public static function save($code, $value, $lang = null)
 {
     // Save specific locale value by given key
     if (!$lang) {
         $lang = self::getLanguage();
     }
     // Check if locale already exists
     $sql = new SqlManager();
     $sql->setQuery("\n\t\t\tSELECT code FROM locale \n\t\t\tWHERE code = '{{code}}' \n\t\t\tAND language = {{lang}}\n\t\t\tLIMIT 1");
     $sql->bindParam('{{code}}', $code);
     $sql->bindParam('{{lang}}', $lang, "int");
     $check = $sql->result();
     $loc = array('code' => $sql->escape($code), 'language' => $sql->escape($lang, "int"), 'text' => $sql->escape($value), 'lastchanged' => DateManager::now());
     // Either update database or insert new entry for given locale
     if (!$check['code']) {
         $loc['created'] = DateManager::now();
         $sql->insert("locale", $loc);
     } else {
         $sql->update("locale", $loc);
     }
     // Refresh cache to make sure new locale entry will be used
     $cachekey = "locale:" . $lang;
     Cache::clear($cachekey);
     self::load($lang);
 }
 public function applyRules()
 {
     $sql = new SqlManager();
     $sql->setQuery("\n\t\t\tSELECT * FROM rewrite\n\t\t\tWHERE request = '{{url}}'\n\t\t\t");
     $sql->bindParam("{{url}}", $this->request_url);
     $rule = $sql->result();
     if (isset($rule['rewrite'])) {
         $this->target_url = $rule['rewrite'];
         $this->data = $rule;
     }
 }
Exemple #4
0
 public function loadByLogin($username, $password, $groups = array())
 {
     // Load user from database by given login data
     $sql = new SqlManager();
     if (count($groups) > 0) {
         $in = $sql->arrayToInString($groups, true);
         $sql->setQuery("\n\t\t\t\tSELECT user.id, user.password FROM user\n\t\t\t\tJOIN meta ON (meta.name = 'usergroup' AND meta.value IN (" . $in . "))\n\t\t\t\tJOIN assortment ON (assortment.type = 'usergroup' AND assortment.id = meta.value)\n\t\t\t\tWHERE username = '******'\n\t\t\t\t");
     } else {
         $sql->setQuery("SELECT id, password FROM user WHERE username = '******'");
     }
     $sql->bindParam("{{username}}", $username);
     $user = $sql->result();
     if (isset($user['id']) && isset($user['password']) && Crypt::checkHash($password, $user['password'])) {
         $this->load($user['id']);
     }
 }
 public static function save($type, $id, $data)
 {
     $data['object_type'] = $type;
     $data['object_id'] = $id;
     $sql = new SqlManager();
     if (!isset($data['id'])) {
         $sql->insert("version", $data);
     } else {
         $sql->setQuery("\n\t\t\t\tSELECT id FROM version\n\t\t\t\tWHERE id = {{id}}\n\t\t\t\tLIMIT 1\n\t\t\t\t");
         $sql->bindParam("{{id}}", $data['id']);
         $check = $sql->result();
         if (isset($check['id'])) {
             $sql->update("version", $data);
         } else {
             $sql->insert("version", $data);
         }
     }
 }
 public function userRegister($request)
 {
     // Register new user from request
     if (empty($request['username'])) {
         return array("message" => array("type" => "error", "code" => "MandatoryInputMissing"), "missing_fields" => "username");
     }
     $sql = new SqlManager();
     $sql->setQuery("SELECT * FROM user WHERE username = '******'");
     $sql->bindParam("{{username}}", $request['username']);
     $check = $sql->result();
     if (isset($check['id'])) {
         return array("message" => array("type" => "error", "code" => "UsernameUsed"));
     }
     $newuser = new User();
     $id = $newuser->create(array("username" => $request['username']));
     if (!$id) {
         return array("message" => array("type" => "error", "code" => "UnknownError"));
     }
     $newuser->load($id);
     $groups = array();
     if (isset($request['usergroups'])) {
         $groups = split(",", $request['usergroups']);
     }
     foreach ($groups as $group) {
         Meta::save("user", $newuser->getID(), "usergroup", $group);
     }
     $newuser->createAuthCode();
     return array("redirect" => array("url" => "/bestaetige-account", "post" => array("username" => $request['username'])));
 }