function mo_set_option($option, $data) { global $mo_settings, $db; if (is_array($data) || is_object($data)) { $to_write = serialize($data); } else { $to_write = $data; } if (isset($mo_settings[$option])) { $rt = $mo_settings[$option]; $mo_settings[$option] = $data; $sql = 'UPDATE `mo_site_options` SET `value` = ? WHERE `item` = ?'; $db->prepare($sql); $db->bind('ss', $to_write, $option); } else { $rt = True; $mo_settings[$option] = $data; $sql = 'INSERT INTO `mo_site_options` (`item`, `value`) VALUES (?, ?)'; $db->prepare($sql); $db->bind('ss', $option, $to_write); } $db->execute(); mo_write_cache('mo_cache_settings', $mo_settings); mo_write_note("Site option: '{$option}' has been update."); return $rt; }
function connect() { $this->mysqli = new mysqli('p:' . $this->host, $this->user, $this->pass, $this->name); if (mysqli_connect_errno()) { die('<h1>Error Connecting to the Database</h1>'); } $this->mysqli->set_charset('utf8'); mo_write_note('Connected to the database successfully.'); }
function mo_add_new_discussion($category, $title, $content, $parent = 0, $uid = 0, $extra = array()) { global $user; if (!$uid) { $uid = $user->getUID(); } if (!($uid && ($parent || $title) && $content)) { return False; } global $db; $sql = 'INSERT INTO `mo_discussion` (`uid`, `parent`, `title`, `category`, `content`, `post_time`, `extra`, `ip`) VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?, ?)'; $db->prepare($sql); $db->bind('iisissi', $uid, $parent, $title, $category, $content, serialize($extra), mo_get_user_ip()); $db->execute(); $did = $db->getInsID(); mo_write_note('A new discussion has been added.'); mo_log_user("User added a new discussion (DID = {$did})."); return $did; }
function mo_del_user($uid) { global $db; $sql = 'DELETE FROM `mo_user` WHERE `id` = ?'; $db->prepare($sql); $db->bind('i', $uid); $db->execute(); $sql = 'DELETE FROM `mo_user_info` WHERE `uid` = ?'; $db->prepare($sql); $db->bind('i', $uid); $db->execute(); $sql = 'DELETE FROM `mo_user_record` WHERE `uid` = ?'; $db->prepare($sql); $db->bind('i', $uid); $db->execute(); mo_write_note("The user (ID = {$uid}) has been deleted."); mo_log_user("The user (ID = {$uid}) has been deleted."); return True; }
function mo_add_new_solution($pid, $lang, $post, $uid = 0) { global $user; if (!$uid) { $uid = $user->getUID(); } if (!($uid && $pid && $post)) { return False; } global $db; $length = strlen($post); $post = base64_encode($post); $sql = 'SELECT `submit`, `try`, `submit_problem` FROM `mo_user_record` WHERE `uid` = ?'; $db->prepare($sql); $db->bind('i', $uid); $result = $db->execute(); $submit_problem = explode(' ', $result[0]['submit_problem']); if (!in_array((string) $pid, $submit_problem)) { $result[0]['submit_problem'] .= "{$pid} "; $result[0]['try'] = (int) $result[0]['try'] + 1; mo_problem_add_submit($pid, True); } else { mo_problem_add_submit($pid); } $result[0]['submit'] = (int) $result[0]['submit'] + 1; $sql = 'UPDATE `mo_user_record` SET `submit` = ?, `try` = ?, `submit_problem` = ? WHERE `uid` = ?'; $db->prepare($sql); $db->bind('iisi', $result[0]['submit'], $result[0]['try'], $result[0]['submit_problem'], $uid); $db->execute(); $sql = 'INSERT INTO `mo_judge_solution` (`pid`, `uid`, `code`, `post_time`, `language`, `code_length`) VALUES (?, ?, ?, CURRENT_TIMESTAMP, ?, ?)'; $db->prepare($sql); $db->bind('iisii', $pid, $uid, $post, $lang, $length); $db->execute(); $sid = $db->getInsID(); $data = array('sid' => $sid, 'pid' => $pid, 'uid' => $uid, 'lang' => $lang, 'code' => $post); mo_write_note('A new solution has been added.'); mo_log_user("User added a new solution (SID = {$sid})."); socket_push($data); return $sid; }
function apply_filter($hook, $content) { global $mo_actions, $mo_actions_sorted; if (!isset($mo_actions[$hook])) { return $content; } if ($mo_actions_sorted[$hook] == false) { ksort($mo_actions[$hook]); $mo_actions_sorted[$hook] = true; } $all_args = func_get_args(); foreach ($mo_actions[$hook] as $priority) { foreach ($priority as $func => $value) { $arg[] = $content; if ($value > 1) { $arg = array_merge($arg, array_slice($all_args, 2, $value)); } $content = call_user_func_array($func, $arg); } } mo_write_note('Hook "' . $hook . '" has been run as a filter.'); return $content; }
$user = new User(); $mo_settings = array(); $mo_request = ''; $mo_plugin = array(); $mo_theme = ''; $mo_theme_floder = ''; $mo_theme_file = ''; mo_load_settings(); $mo_request = mo_analyze(); getPT(); if (count($mo_plugin)) { foreach ($mo_plugin as $plugin) { require_once $plugin; } } if ($mo_theme_file) { require_once $mo_theme_file; } do_action('loadPT'); // Check if logged in or trying to if ($user->autoLogin()) { $user->loadAll($_SESSION['uid']); $user->check(); } do_action('loadBasic'); if (defined('OUTPUT') && OUTPUT == True && $mo_theme_file) { call_user_func($mo_theme); } do_action('loadDone'); mo_write_note('The page has been processed successfully.');
function mo_in_check($autoExit = True) { if (!defined('RUN')) { mo_write_note('Invaild entrance.'); if ($autoExit) { exit(0); } else { return False; } } return True; }
public function login($login_name, $password) { if (strlen($login_name) > 50 || strlen($password) > 50 || strlen($password) < 6 || !$login_name || !$password) { return False; } global $db; $sql = 'SELECT `id`, `password`, `mask`FROM `mo_user` WHERE '; if (strstr($login_name, '@')) { $sql .= '`email` = ? LIMIT 1'; } else { $sql .= '`username` = ? LIMIT 1'; } $db->prepare($sql); $db->bind('s', $login_name); $result = $db->execute(); if (!$result || !password_verify($password, $result[0]['password'])) { mo_log_login($this->uid, 0, False); return False; } $this->uid = $result[0]['id']; $_SESSION['uid'] = $this->uid; $_SESSION['mask'] = $result[0]['mask']; if ($_POST['auto_login']) { $random = (string) rand(10000, 99999); $cookie_to_write = $this->uid . '&' . $random . '&' . md5($result[0]['password'] . $random); setcookie('mo_auth', $cookie_to_write, time() + 31536000); } mo_log_login($this->uid, 0); mo_write_note('Logged in with a password.'); return True; }