L::get PHP Method

get() public static method

public static get ( $string, $variables = [], $language = null )
    public static function get($string, $variables = [], $language = null)
    {
        if (!$language || $language && !in_array($language, Config::$languages)) {
            $language = self::$defaultLanguage;
        }
        if (!self::$cache[$language]) {
            self::$cache[$language] = json_decode(file_get_contents("locales/" . $language . ".json"), true);
        }
        $sentence = self::$cache[$language][$string];
        if (!$sentence) {
            return $string;
        }
        for ($i = 0; $i < count($variables); $i++) {
            $sentence = str_replace("{" . $i . "}", $variables[$i], $sentence);
        }
        return $sentence;
    }

Usage Example

Example #1
0
 public function query($postdata)
 {
     if ($this->user->getClass() < User::CLASS_ADMIN) {
         throw new Exception(L::get("PERMISSION_DENIED"), 401);
     }
     $limit = (int) $postdata["limit"] ?: 25;
     $index = (int) $postdata["index"] ?: 0;
     $search = $postdata["search"] ?: "";
     $where = "";
     if (strlen($search) > 0) {
         $searchWords = Helper::searchTextToWordParams($search);
         $where = "WHERE MATCH (adminlog.search_text) AGAINST (" . $this->db->quote($searchWords) . " IN BOOLEAN MODE)";
     }
     $sth = $this->db->query("SELECT COUNT(*) FROM adminlog " . $where);
     $res = $sth->fetch();
     $totalCount = $res[0];
     $sth = $this->db->prepare("SELECT adminlog.added, adminlog.id AS aid, adminlog.txt, users.id, users.username FROM adminlog LEFT JOIN users ON adminlog.userid = users.id " . $where . " ORDER BY adminlog.id DESC LIMIT ?, ?");
     $sth->bindParam(1, $index, PDO::PARAM_INT);
     $sth->bindParam(2, $limit, PDO::PARAM_INT);
     $sth->execute();
     $result = array();
     while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
         $r = array();
         $r["id"] = $row["aid"];
         $r["added"] = $row["added"];
         $r["txt"] = str_replace("{{username}}", "[url=/user/" . $row["id"] . "/" . $row["username"] . "][b]" . $row["username"] . "[/b][/url]", $row["txt"]);
         array_push($result, $r);
     }
     return array($result, $totalCount);
 }
All Usage Examples Of L::get