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]; }
public static function init() { self::$utf8validator = (bool) extension_loaded('utf8validator'); mb_internal_encoding('UTF-8'); mb_language('uni'); mb_regex_encoding('UTF-8'); mb_detect_order(array('UTF-8', 'ISO-8859-1')); mb_substitute_character(0xfffd); MCached::connect(); $trans = MCached::get(self::TRANSKEY); if ($trans === MCached::NO_RESULT) { $win = "€" . implode('', range("‚", "Œ")) . "Ž" . implode('', range("‘", "œ")) . implode('', range("ž", "ÿ")); $win_iso = "�����"; $iso = implode('', range("€", "ÿ")); $winlen = strlen($win); $winisolen = strlen($win_iso); $isolen = strlen($iso); $trans = array('iso_to_utf8' => array(), 'win_to_utf8' => array(), 'from_utf8' => array()); for ($i = 0; $i < $isolen; $i++) { $utf8 = mb_convert_encoding($iso[$i], 'UTF-8', 'ISO-8859-1'); $trans['iso_to_utf8'][$iso[$i]] = $utf8; $trans['from_utf8'][$utf8] = $iso[$i]; } for ($i = 0; $i < $winlen; $i++) { $utf8 = mb_convert_encoding($win[$i], 'UTF-8', 'Windows-1252'); $trans['win_to_utf8'][$win[$i]] = $utf8; $trans['from_utf8'][$utf8] = $win[$i]; } for ($i = 0; $i < $winisolen; $i++) { $utf8 = mb_convert_encoding($win_iso[$i], 'UTF-8', 'ISO-8859-1'); $trans['win_to_utf8'][$win_iso[$i]] = $utf8; } MCached::add(self::TRANSKEY, $trans, 86400); } self::$trans_table = $trans; }
function runSpeed($info_hash, $delta) { global $db; MCached::connect(); // stick in our latest data before we calc it out quickQuery("INSERT IGNORE INTO timestamps (info_hash, bytes, delta, sequence) SELECT '" . $info_hash . "' AS info_hash, dlbytes, UNIX_TIMESTAMP() - lastSpeedCycle, NULL FROM summary WHERE info_hash = '" . $info_hash . "'"); $key = 'ann::bytes::timestamps::' . $info_hash; $data = MCached::get($key); if ($data === MCached::NO_RESULT) { $results = $db->query('SELECT (MAX(bytes) - MIN(bytes)) / SUM(delta), COUNT(*), MIN(sequence) FROM timestamps WHERE info_hash = "' . $info_hash . '"'); $data = $results->fetch_row(); MCached::add($key, $data, 300); } summaryAdd("speed", $data[0], true); summaryAdd("lastSpeedCycle", "UNIX_TIMESTAMP()", true); // if we have more than 20 drop the rest if ($data[1] == 21) { quickQuery("DELETE FROM timestamps WHERE info_hash='" . $info_hash . "' AND sequence = " . $data['2']); MCached::del($key); } elseif ($data[1] > 21) { quickQuery('DELETE FROM timestamps WHERE info_hash = "' . $info_hash . '" ORDER BY sequence LIMIT ' . ($data['1'] - 20)); MCached::del($key); } }
function insert_compose_frame($id, $newtopic = true, $quote = false) { global $maxsubjectlength, $db; MCached::connect(); if ($newtopic) { $arr = MCached::get('forums::name::' . $id); if ($arr === MCached::NO_RESULT) { $res = $db->query("SELECT name FROM forums WHERE id = " . $id) or sqlerr(__FILE__, __LINE__); $arr = $res->fetch_assoc() or die(BAD_FORUM_ID); MCached::add('forums::name::' . $id, $arr, 9600); } $forumname = security::html_safe(unesc($arr["name"])); block_begin(WORD_NEW . " " . TOPIC . " " . IN . " <a href='?action=viewforum&forumid=" . $id . "'>" . $forumname . "</a> " . FORUM); } else { $arr = MCached::get('quick::jump::topics::' . $id); if ($arr === MCached::NO_RESULT) { $res = $db->query("SELECT * FROM topics WHERE id = " . $id) or sqlerr(__FILE__, __LINE__); $arr = $res->fetch_assoc() or stderr(ERROR, FORUM_ERROR . TOPIC_NOT_FOUND); MCached::add('quick::jump::topics::' . $id, $arr, 9600); } $subject = security::html_safe(unesc($arr["subject"])); block_begin(REPLY . " " . TOPIC . ": <a href='?action=viewtopic&topicid=" . $id . "'>" . $subject . "</a>"); } begin_frame(); print "<form method='post' name='compose' action='?action=post'>\n"; if ($newtopic) { print "<input type='hidden' name='forumid' value='" . $id . "'>\n"; } else { print "<input type='hidden' name='topicid' value='" . $id . "'>\n"; } begin_table(); if ($newtopic) { print "<tr><td class='header'>" . SUBJECT . "</td>" . "<td class='lista' align='left' style='padding: 0px'><input type='text' size='50' maxlength='" . $maxsubjectlength . "' name='subject' " . "style='border: 0px; height: 19px'></td></tr>\n"; } if ($quote) { $postid = 0 + (int) $_GET["postid"]; if (!is_valid_id($postid)) { die; } $res = $db->query("SELECT posts.*, users.username FROM posts INNER JOIN users ON posts.userid = users.id WHERE posts.id = " . $postid) or sqlerr(__FILE__, __LINE__); if ($res->num_rows != 1) { stderr(ERROR, ERR_NO_POST_WITH_ID . "" . $postid); } $arr = $res->fetch_assoc(); } print "<tr><td class='header'>" . BODY . "</td><td class='lista' align='left' style='padding: 0px'>"; textbbcode("compose", "body", $quote ? "[quote=" . security::html_safe($arr["username"]) . "]" . security::html_safe(unesc($arr["body"])) . "[/quote]" : ""); print "<tr><td colspan='2' align='center'><input type='submit' class='btn' value='" . FRM_CONFIRM . "'></td></tr>\n"; print "</td></tr>"; end_table(); print "</form>\n"; end_frame(); //------ Get 10 last posts if this is a reply if (!$newtopic) { $postres = $db->query("SELECT * FROM posts WHERE topicid = " . $id . " ORDER BY id DESC LIMIT 10") or sqlerr(__FILE__, __LINE__); begin_frame(LAST_10_POSTS, true); while ($post = $postres->fetch_assoc()) { //-- Get poster details $userres = $db->query("SELECT * FROM users WHERE id = " . (int) $post["userid"] . " LIMIT 1") or sqlerr(__FILE__, __LINE__); $user = $userres->fetch_assoc(); $avatar = $user["avatar"] && $user["avatar"] != "" ? security::html_safe($user["avatar"]) : ""; begin_table(true); print "<tr valign='top'><td width='150' align='center' style='padding: 0px'>#" . (int) $post["id"] . " by " . security::html_safe($user["username"]) . "<br />" . get_date_time($post["added"]) . ($avatar != "" ? "<br /><img width='80' src='" . $avatar . "'>" : "") . "</td><td class='lista'>" . format_comment(unesc($post["body"])) . "</td></tr><br>\n"; end_table(); } end_frame(); } if (!isset($forumid)) { $forumid = 0; } insert_quick_jump_menu($forumid); block_end(); }
require_once INCL_PATH . 'common.php'; // protection against sql injection, xss attack require_once INCL_PATH . 'crk_protection.php'; // protection against sql injection, xss attack require_once INCL_PATH . 'theme_functions.php'; require_once CLASS_PATH . 'class.Captcha.php'; require_once CLASS_PATH . 'class.Cookie.php'; require_once CLASS_PATH . 'class.Template.php'; require_once CLASS_PATH . 'class.Misc.php'; require_once CLASS_PATH . 'class.Security.php'; require_once CLASS_PATH . 'class.Vars.php'; require_once CLASS_PATH . 'class.User.php'; require_once CLASS_PATH . 'class.Memcached.php'; require_once CLASS_PATH . 'class.Cached.php'; #Connect to Memcached... MCached::connect(); raintpl::configure("base_url", null); raintpl::configure("tpl_dir", ""); raintpl::configure("cache_dir", "cache/"); $tpl = new RainTPL(); // default for disabling DHT network if (!isset($DHT_PRIVATE)) { $DHT_PRIVATE = true; } if (!isset($LIVESTATS)) { $LIVESTATS = false; } if (!isset($LOG_ACTIVE)) { $LOG_ACTIVE = false; } if (!isset($LOG_HISTORY)) {
public static function get_topic_forum($topicid) { global $db; MCached::connect(); $key = 'forum::id::' . $topicid; $arr = MCached::get($key); if ($arr === MCached::NO_RESULT) { $res = $db->query("SELECT forumid FROM topics WHERE id = " . $topicid); if ($res->num_rows != 1) { return false; } $arr = $res->fetch_row(); MCached::add($key, $arr, self::SIX_HOURS); } return (int) $arr[0]; }
public static function ip_port($in, &$ip, &$port, &$type, &$addr) { MCached::connect(); $key = 'ip::ip_port::' . sha1($in); $ip_port = MCached::get($key); if ($ip_port === MCached::NO_RESULT) { if (!preg_match('#^([0-9a-f:]+)$#i', $in, $matches) && !preg_match('#^\\[([0-9a-f:]+)\\](?::([0-9]{1,5}))?$#i', $in, $matches) && !preg_match('#^([0-9.]+)(?::([0-9]{1,5}))?$#', $in, $matches)) { return false; } $tip = $matches[1]; $taddr = self::type($tip, $ttype); if (!$taddr) { MCached::add($key, 0, 86400); return false; } $taddr6 = self::ip2addr6($tip); $tport = 0; if (isset($matches[2])) { $tport = (int) $matches[2]; if ($tport < 1 || $tport > 65535) { MCached::add($key, 0, 86400); return false; } } if (!self::valid_ip($tip)) { MCached::add($key, 0, 86400); return false; } $ip_port = array($tip, $tport, $ttype, $taddr, $taddr6); MCached::add($key, $ip_port, 86400); } elseif (!$ip_port) { return false; } list($ip, $port, $type, $addr, $addr6) = $ip_port; return $addr6; }