Ejemplo n.º 1
0
 /**
  * A widget containing a menu
  * @param string $id The HTML #id of the element
  * @param string $class The HTML .class of element
  * @param string[][] $links The links in the menu
  * @param string $selected The title of the selected item in the menu
  * @param HtmlAttributes $args Allows custom html tag arguments to be specified (not recommended)
  **/
 public function __construct($id, $class, $links, $selected = null, $args = null)
 {
     HtmlAttributes::Assure($args);
     $args->Add('id', $id);
     $args->Add('class', $class);
     $url = $title = null;
     $items = array();
     foreach ($links as $link) {
         if (_array::IsLongerThan($link, 1)) {
             $url = $link[0];
             $title = $link[1];
         } else {
             $url = $title = $link;
         }
         $linkargs = null;
         $forcehttps = false;
         if (_string::StartsWith($title, '_')) {
             $title = _string::RemovePrefix($title, '_');
             $forcehttps = true;
         }
         if ($selected != null && $selected == $title) {
             $linkargs = array('selected' => true);
         }
         $items[] = new RTK_Link($url, $title, $forcehttps, $linkargs);
     }
     parent::__construct($items, $args);
 }
Ejemplo n.º 2
0
 public static function init()
 {
     MCached::connect();
     $key = 'ord::chars::bin';
     $chars = MCached::get($key);
     if (!is_array($chars)) {
         $chrs = $ords = array();
         for ($i = 0; $i <= 0xff; $i++) {
             $char = chr($i);
             $bin = sprintf('%08b', $i);
             $chrs[$i] = $char;
             $ords[$char] = $i;
             $b2cs[$bin] = $char;
             $c2bs[$char] = $bin;
         }
         $chars = array($chrs, $ords, $b2cs, $c2bs);
         MCached::set($key, $chars, 86400);
     }
     self::$chr = $chars[0];
     self::$ord = $chars[1];
     self::$b2c = $chars[2];
     self::$c2b = $chars[3];
 }
Ejemplo n.º 3
0
 public static function Insert($message, $recipe, $id = EMPTYSTRING)
 {
     $result = false;
     if (Site::HasHttps() && Login::IsLoggedIn()) {
         if (Value::SetAndNotEmpty($message) && Value::SetAndNotNull($recipe)) {
             $path = 'R=' . $recipe;
             if ($id != EMPTYSTRING) {
                 if ($stmt = Database::GetLink()->prepare('SELECT `comment_path` FROM `Comment` WHERE `comment_path` LIKE ?;')) {
                     $stmt->bindParam(1, $path, PDO::PARAM_STR, 255);
                     $stmt->execute();
                     $stmt->bindColumn(1, $result);
                     $stmt->fetch();
                     $stmt->closeCursor();
                     if ($result != null && _string::StartsWith($result, $path)) {
                         $path = $result . '>' . $id;
                     } else {
                         $path = null;
                     }
                 }
             }
             if ($path != null) {
                 $userid = Login::GetId();
                 $timestamp = time();
                 if ($stmt = Database::GetLink()->prepare('INSERT INTO `Comment` (`user_id`, `comment_path`, `comment_contents`, `sent_at`) VALUES (?, ?, ?, ?);')) {
                     $stmt->bindParam(1, $userid, PDO::PARAM_INT);
                     $stmt->bindParam(2, $path, PDO::PARAM_STR, 255);
                     $stmt->bindParam(3, $message, PDO::PARAM_STR, 255);
                     $stmt->bindParam(4, $timestamp, PDO::PARAM_INT);
                     $stmt->execute();
                     $stmt->closeCursor();
                 }
             }
         }
     }
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * Gets the last folder of a URL appends something to a URL
  * @param url, the URL to look in.
  **/
 public static function LastFolder($url)
 {
     $pieces = explode(SINGLESLASH, $url);
     $last = sizeof($pieces) - 1;
     $foldername = $pieces[$last];
     if ($foldername == EMPTYSTRING || _string::Contains($foldername, SINGLEDOT)) {
         $foldername = $pieces[$last - 1];
     }
     return $foldername;
 }
Ejemplo n.º 5
0
 /**
  * Object representing a single element in HTML
  * @param string $tag The tag name of the element
  * @param HtmlAttributes $attributes The attributes of the element
  * @param string $content The content of the element
  * @param HtmlElement $child child (or children) to insert into the element
  **/
 public function __construct($tag = EMPTYSTRING, $attributes = EMPTYSTRING, $content = EMPTYSTRING, $child = null)
 {
     if ($tag == 'comment' || $tag == '!--') {
         $this->_tag = '!--';
         $this->_endtag = '--';
     } else {
         $this->_tag = $tag;
     }
     if (is_a($attributes, 'HtmlAttributes')) {
         $this->_attributes = $attributes;
     } elseif (is_array($attributes)) {
         $this->_attributes = new HtmlAttributes($attributes);
     } else {
         $this->_attributes = new HtmlAttributes();
     }
     $this->_content = _string::EnforceProperLineEndings($content);
     if ($child !== null) {
         if (!is_array($child)) {
             $this->AddChild($child);
         } else {
             foreach ($child as $c) {
                 $this->AddChild($c);
             }
         }
     }
 }
Ejemplo n.º 6
0
function mksecret($len = 20)
{
    return _string::random($len);
}
Ejemplo n.º 7
0
 public static function strrempre($a, $b)
 {
     return _string::string_remove_prefix($a, $b);
 }
Ejemplo n.º 8
0
function userlogin()
{
    global $db, $tpl;
    unset($GLOBALS['CURUSER']);
    require_once CLASS_PATH . 'class.Cached.php';
    $ip = vars::$ip;
    $nip = ip2long($ip);
    $ipf = vars::$realip;
    #Check if User is Banned...
    #if (!($row['flags'] & BIT_26)) -- TO-DO
    #$banned = false;
    if (Cached::bans($ip, $reason)) {
        $banned = true;
    } else {
        if ($ip != $ipf) {
            if (Cached::bans($ipf, $reason)) {
                $banned = true;
            }
        }
    }
    if ($banned) {
        header('Content-Type: text/html; charset=utf-8');
        $banned_message = security::html_safe($reason);
        $tpl->assign('banned_message', $banned_message);
        $banned_msg = $tpl->draw('style/base/tpl/banned_message', $return_string = true);
        echo $banned_msg;
        die;
    }
    #End Banned User...
    // guest
    if (empty($_COOKIE["uid"]) || empty($_COOKIE["pass"])) {
        $id = 1;
    }
    if (!isset($_COOKIE["uid"]) && _string::is_hex($_COOKIE["uid"])) {
        $_COOKIE["uid"] = 1;
    }
    $id = max(1, (int) $_COOKIE["uid"]);
    // it's guest
    if (!$id) {
        $id = 1;
    }
    $res = $db->query("SELECT users.pid, users.topicsperpage, users.postsperpage, users.torrentsperpage, users.flag, users.avatar, UNIX_TIMESTAMP(users.lastconnect) AS lastconnect, UNIX_TIMESTAMP(users.joined) AS joined, users.id AS uid, users.username, users.password, users.loginhash, users.random, users.email, users.language, users.style, users.time_offset, users_level.* \n\t    FROM users INNER JOIN users_level ON users.id_level = users_level.id \n\t\tWHERE users.id = " . $id);
    $row = $res->fetch_array(MYSQLI_BOTH);
    user::prepare_user($row);
    if (!$row) {
        $id = 1;
        $res = $db->query("SELECT users.topicsperpage, users.postsperpage, users.torrentsperpage, users.flag, users.avatar, UNIX_TIMESTAMP(users.lastconnect) AS lastconnect, UNIX_TIMESTAMP(users.joined) AS joined, users.id AS uid, users.username, users.password, users.loginhash, users.random, users.email, users.language, users.style, users.time_offset, users_level.* \n\t\t    FROM users INNER JOIN users_level ON users.id_level = users_level.id WHERE users.id = 1");
        $row = $res->fetch_array(MYSQLI_BOTH);
    }
    if (!isset($_COOKIE["pass"])) {
        $_COOKIE["pass"] = "";
    }
    if ($_COOKIE["pass"] != md5($GLOBALS["salting"] . $row["random"] . $row["password"] . $row["random"]) && $id != 1) {
        $id = 1;
        $res = $db->query("SELECT users.topicsperpage, users.postsperpage, users.torrentsperpage, users.flag, users.avatar, UNIX_TIMESTAMP(users.lastconnect) AS lastconnect, UNIX_TIMESTAMP(users.joined) AS joined, users.id AS uid, users.username, users.password, users.loginhash, users.random, users.email, users.language, users.style, users.time_offset, users_level.* \n\t\t    FROM users INNER JOIN users_level ON users.id_level = users_level.id \n\t\t\tWHERE users.id = 1");
        $row = $res->fetch_array(MYSQLI_BOTH);
    }
    #Hide Staff IP's by Yupy...
    $hide_ips = array("Moderator" => 6, "Administrator" => 7, "Owner" => 8);
    // Staff ID level's
    $ip = $row["id_level"] != $hide_ips["Moderator"] ? $ip : "127.0.0.1";
    $ip = $row["id_level"] != $hide_ips["Administrator"] ? $ip : "127.0.0.1";
    $ip = $row["id_level"] != $hide_ips["Owner"] ? $ip : "127.0.0.1";
    if ($id > 1) {
        $db->query("UPDATE users SET lastconnect = NOW(), lip = " . $nip . ", cip = '" . AddSlashes($ip) . "' WHERE id = " . $id);
    } else {
        $db->query("UPDATE users SET lastconnect = NOW(), lip = 0, cip = NULL WHERE id = 1");
    }
    user::$current = $row;
    $GLOBALS['CURUSER'] =& user::$current;
    unset($row);
}
Ejemplo n.º 9
0
 public static function ip_match($allow, $ip)
 {
     if (strpos($allow, '*') === false && strpos($allow, '?') === false) {
         return self::net_match($ip, $allow);
     } else {
         return _string::glob_match($ip, $allow, true);
     }
 }