/** * Loads the rights and check for access. * * @param array $rights Rights to check * * @return boolean */ protected function getRights($rights) { $select = array("a.aid", "a.founder", "ar.CAN_MANAGE", "ar.CAN_SEE_MEMBERLIST", "ar.CAN_SEE_APPLICATIONS", "ar.CAN_BAN_MEMBER", "ar.CAN_SEE_ONLINE_STATE", "ar.CAN_WRITE_GLOBAL_MAILS"); $joins = "LEFT JOIN " . PREFIX . "alliance a ON (a.aid = u2a.aid)"; $joins .= "LEFT JOIN " . PREFIX . "allyrank ar ON (ar.rankid = u2a.rank)"; $result = Core::getQuery()->select("user2ally u2a", $select, $joins, Core::getDB()->quoteInto("u2a.userid = ?", Core::getUser()->get("userid"))); if ($_row = $result->fetchRow()) { $result->closeCursor(); Hook::event("GetAllianceRights", array($rights, &$_row)); if ($_row["founder"] == Core::getUser()->get("userid")) { return true; } if (!is_array($rights)) { $rights = Arr::trim(explode(",", $rights)); } foreach ($rights as $right) { if ($_row[$right] == 0) { return false; } } return true; } else { $result->closeCursor(); } return false; }
/** * Checks if user has permissions. * * @param mixed $perms The permissions; Splitted with commas * * @return boolean True, if all permissions are valid, false, if not */ public function ifPermissions($perms) { if (!is_array($perms)) { $perms = Arr::trim(explode(",", $perms)); } Hook::event("USER_HAS_PERMISSIONS", array($perms)); foreach ($perms as $p) { if (!isset($this->permissions[$p]) || $this->permissions[$p] == 0 || !$this->permissions[$p]) { return false; } } return true; }
/** * Caches only a group of language phrases. * * @param string $groupname Phrase group * @param integer $langcode Languageid * @param integer $lifetime Life time [optional] * * @return Recipe_Cache */ public function cachePhraseGroup($groupname, $langcode, $lifetime = self::DEFAULT_CACHE_LIFE_TIME) { if (!is_array($groupname)) { $groupname = explode(",", $groupname); $groupname = Arr::trim($groupname); } foreach ($groupname as $group) { $filename = $this->getLanguageCacheDir() . "lang." . $langcode . "." . $group . ".php"; try { File::rmFile($filename); } catch (Exception $e) { } $cacheContent = $this->setCacheFileHeader("Language [" . $langcode . "] Cache File"); $cacheContent .= "//### Variables for phrase group \"" . $group . "\" ###//\n"; $cacheContent .= "\$lifetime=" . (TIME + $lifetime) . ";"; $joins = "LEFT JOIN " . PREFIX . "languages l ON (l.languageid = p.languageid) "; $joins .= "LEFT JOIN " . PREFIX . "phrasesgroups pg ON (pg.phrasegroupid = p.phrasegroupid)"; $where = Core::getDB()->quoteInto("l.langcode = ?", $langcode); $where .= Core::getDB()->quoteInto(" AND pg.title = ?", $group); $result = Core::getQuery()->select("phrases p", array("p.title AS phrasetitle", "p.content"), $joins, $where, "p.phrasegroupid ASC, p.title ASC"); $compiler = new Recipe_Language_Compiler(""); foreach ($result->fetchAll() as $row) { $compiler->setPhrase($row["content"]); $cacheContent .= "\$item[\"" . $group . "\"][\"" . $row["phrasetitle"] . "\"]=\"" . $compiler->getPhrase() . "\";"; } $result->closeCursor(); $compiler->shutdown(); $cacheContent .= $this->cacheFileClose; try { $this->putCacheContent($filename, $cacheContent); } catch (Recipe_Exception_Generic $e) { $e->printError(); } } return $this; }
/** * Set phrases groups. * * @param string|array $groups List of groups, separated by comma * * @return array All language variables */ public function load($groups = array()) { if (!is_array($groups)) { $groups = Arr::trim(explode(",", $groups)); } $this->grouplist = array_merge($this->grouplist, $groups); $this->grouplist = Arr::clean($this->grouplist); return $this->fetch(); }
/** * Applies trim() to each element. * * @return Map */ public function trim() { $this->map = Arr::trim($this->map); return $this; }
/** * Returns the data of the XML element as an array. * * @param string $name Element name [optional] * * @return array */ public function getArray($name = null) { return Arr::trim(explode(",", $this->getString($name))); }
/** * Checks a string for valid email address. * * @param string * * @return boolean */ function checkEmail($mail) { if (!preg_match("#^[a-zA-Z0-9-]+([._a-zA-Z0-9.-]+)*@[a-zA-Z0-9.-]+\\.([a-zA-Z]{2,4})\$#is", $mail)) { return false; } $banned = Core::getConfig()->get("BANNED_EMAILS"); if (!empty($banned)) { $banned = Arr::trim(explode(",", $banned)); foreach ($banned as $expr) { if (Str::inString($expr, $mail)) { return false; } } } return true; }
/** * Generates a select query. * * @param string $table * @param string|array $select * @param string $join * @param string $where * @param string $order * @param string $limit * @param string $groupby * @param string $other * @param array $bind * * @return Recipe_Database_Statement_Abstract */ public function select($table, $select, $join = "", $where = "", $order = "", $limit = "", $groupby = "", $other = "", array $bind = null) { if (!is_array($select)) { $select = Arr::trim(explode(",", $select)); } if (!empty($join)) { $join = " " . $join; } if (!empty($where)) { $where = " WHERE " . $where; } if (!empty($groupby)) { $groupby = " GROUP BY " . $groupby; } if (!empty($order)) { $order = " ORDER BY " . $order; } if (!empty($limit)) { $limit = " LIMIT " . $limit; } $other = !empty($other) ? " " . $other : ""; $select = implode(", ", $select); $sql = "SELECT " . $select . " FROM " . PREFIX . $table . $join . $where . $groupby . $order . $limit . $other; return $this->send($sql, $bind); }
/** * Check incoming cron time data and put them into separate arrays. * * @param array $row Database row to validate * * @return array Validated row */ protected function validate($row) { $row["minute"] = Arr::trim(explode(",", $row["minute"])); $row["hour"] = Arr::trim(explode(",", $row["hour"])); $row["day"] = Arr::trim(explode(",", $row["day"])); $row["weekday"] = Arr::trim(explode(",", $row["weekday"])); $row["month"] = Arr::trim(explode(",", $row["month"])); if (empty($row["xtime"])) { $row["xtime"] = TIME; } return $row; }
/** * @param array $options * @return string */ protected function serialize($options) { if (!empty($options)) { $hasKeys = Str::inString("=>", $options); $options = Arr::trim(explode(",", $options)); $opts = $options; if ($hasKeys) { $opts = array(); $size = count($options); for ($i = 0; $i < $size; $i++) { $cell = Arr::trim(explode("=>", $options[$i])); $opts[$cell[0]] = $cell[1]; } } return serialize($opts); } return ""; }
/** * Split the URL into arguments. * * @return Recipe_Request */ protected function splitURL() { $requestedUrl = $this->getRequestedUrl(); // Remove query string if (!empty($_SERVER["QUERY_STRING"])) { $requestedUrl = Str::replace("?" . $_SERVER["QUERY_STRING"], "", $requestedUrl); } $splitted = @parse_url($requestedUrl); // Sometimes the first slash causes errors if (!$splitted) { $splitted = parse_url(Str::substring($requestedUrl, 1)); } // Remove real path from virtual path. if (MOD_REWRITE) { $path = Str::replace(dirname($_SERVER["SCRIPT_NAME"]) . "/", "", $splitted["path"]); } else { $path = Str::substring(Str::replace($_SERVER["SCRIPT_NAME"], "", $splitted["path"]), 1); } if (Str::length($path) > 0) { Hook::event("SplitUrlStart", array($this, &$path)); $path = explode("/", $path); foreach ($path as $value) { if (strpos($value, ":") > 0) { $value = explode(":", Str::replace(" ", "_", $value)); $this->args[] = Arr::trim($value); } else { if ($value != "") { $this->args[] = $value; } } } Hook::event("SplitUrlClose", array($this, &$path)); } return $this; }