public function create($post, &$thread) { $this->original_post_time = OsimoDB::formatDateForDB(); $this->title = get('db')->escape($this->title); $this->desc = get('db')->escape($this->description); $this->original_poster = get('db')->escape($this->original_poster); if (!is_numeric($this->forum) || !is_numeric($this->original_poster_id)) { return false; } $query = "\n\t\t\tINSERT INTO threads (\n\t\t\t\tforum,\n\t\t\t\ttitle,\n\t\t\t\tdescription,\n\t\t\t\toriginal_poster,\n\t\t\t\toriginal_poster_id,\n\t\t\t\toriginal_post_time\n\t\t\t) VALUES (\n\t\t\t\t'" . $this->forum . "',\n\t\t\t\t'" . $this->title . "',\n\t\t\t\t'" . $this->description . "',\n\t\t\t\t'" . $this->original_poster . "',\n\t\t\t\t'" . $this->original_poster_id . "',\n\t\t\t\t'" . $this->original_post_time . "'\n\t\t\t)"; $result = get('db')->query($query)->insert($threadID); if ($result) { $this->id = $threadID; $post->thread = $threadID; $post->poster_id = $this->original_poster_id; $result2 = $post->create($thePost); if ($result2) { get('db')->update('forums')->set(array('threads' => 'threads+1', 'last_thread_id' => $this->id, 'last_thread_title' => $this->title, 'last_poster' => "'" . $this->original_poster . "'", 'last_poster_id' => "'" . $this->original_poster_id . "'", 'last_post_time' => "'" . OsimoDB::formatDateForDB() . "'"))->where('id=%d', $this->forum)->limit(1)->update(); $thread = $this; return true; } else { // rollback the creation of this thread to prevent empty threads from lying around. $this->delete(); } } return false; }
public static function register_user($username, $password, $email, $autologin = true) { $username = OsimoDB::escape($username); $email = OsimoDB::escape($email); $time_joined = OsimoDB::formatDateForDB(); /* Error checking */ if(strlen($username)<3||strlen($username)>24||preg_match('/[^\w]/', $username)){ throw new OsimoException('invalid_username', "The username given is invalid, please choose a different one"); } if(!preg_match('/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/', $email)) { throw new OsimoException('invalid_email', "The email address given is not valid."); } if(strlen($password) < 3) { throw new OsimoException('password_too_short', "The password entered is too short, please choose a different one"); } $password = self::hash_password($password); if(self::user_exists($username)) { throw new OsimoException('username_exists', "The username given already exists, please login or choose a different username."); } /* Create the new user */ $query = " INSERT INTO users ( username, email, password, ip_address, time_joined ) VALUES ( '$username', '$email', '$password', '{$_SERVER['REMOTE_ADDR']}', '$time_joined' )"; $result = get('db')->query($query)->insert($userID); if($result) { if($autologin) { self::set_logged_in_user(new OsimoUser($userID)); } return $userID; } else { throw new OsimoException('fail', "There was an error registering your username, please try again"); } }
/** * Create a new post based on the data that was * loaded into this class upon instantiation. * * @param OsimoPost $post (reference) * Reference to the OsimoPost object that is created * after it is inserted into the database. * @return Boolean based on the success of inserting a post. */ public function create(&$post) { $this->post_time = OsimoDB::formatDateForDB(); $this->body = get('db')->escape($this->body); if (!is_numeric($this->thread) || !is_numeric($this->poster_id)) { return false; } $query = "\n\t\t\tINSERT INTO posts (\n\t\t\t\tthread,\n\t\t\t\tbody,\n\t\t\t\tposter_id,\n\t\t\t\tpost_time\n\t\t\t) VALUES (\n\t\t\t\t'" . $this->thread . "',\n\t\t\t\t'" . $this->body . "',\n\t\t\t\t'" . $this->poster_id . "',\n\t\t\t\t'" . $this->post_time . "'\n\t\t\t)"; $result = get('db')->query($query)->insert($postID); if ($result) { $this->id = $postID; $post = $this; get('user')->increase_post_count(); get('db')->update('threads')->set(array('posts' => 'posts+1', 'last_poster' => "'" . get('user')->username . "'", 'last_poster_id' => "'" . get('user')->id . "'", 'last_post_time' => "'" . get('db')->formatDateForDB() . "'"))->where('id=%d', $this->thread)->limit(1)->update(); get('db')->update('forums')->set(array('posts' => 'posts+1', 'last_thread_id' => $this->thread, 'last_poster' => "'" . get('user')->username . "'", 'last_poster_id' => "'" . get('user')->id . "'", 'last_post_time' => "'" . get('db')->formatDateForDB() . "'"))->where('id=(SELECT forum FROM threads WHERE id=%d LIMIT 1)', $this->thread)->limit(1)->update(); return true; } else { return false; } }