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; }
/** * This function instantiates all the other core objects required to make the forum run. * It also sets all options specified in config.php. * * @param Array $options (optional) * Array of options set in config.php. * @param String $siteFolder (optional) * Site folder relative to the URL root set in config.php. */ public function init($config) { define('SITE_FOLDER', $config['site_folder']); if (!defined('IS_ADMIN_PAGE')) { define('IS_ADMIN_PAGE', false); } $this->loadIncludes(SITE_FOLDER); ConfigManager::instance()->register_user_config($config); $this->add_module('paths', new OsimoPaths()); /* Initialize modules */ $this->add_module('debug', new OsimoDebug()); $this->add_module('cache', new OsimoCache()); OsimoDB::instance()->init(); $this->loadConfig(); UserManager::set_logged_in_user(); $this->add_module('theme', new OsimoTheme()); $this->add_module('data', new OsimoData()); $this->add_module('bbparser', new OsimoBBParser()); if (IS_ADMIN_PAGE == true) { $this->add_module('admin', new OsimoAdmin()); } }
public static function update_user_info($user, $info) { if(!is_array($info)) { throw new OsimoException(OSIMO_EXPECTED_ARRAY, "Expected array for second argument to update_user_info"); } $userID = 0; if(is_numeric($user)) { $userID = $user; } elseif(is_object($user) && $user instanceof OsimoUser) { $userID = $user->id; } $info = OsimoDB::escape($info, true); $result = get('db')->update('users')->set($info)->where("id = %d", $userID)->update(); if(!$result) { throw new OsimoException(USER_UPDATE_FAIL, "There was an error updating the information for this user"); } }
private function parseWhere() { if (isset($this->where['vars'])) { return call_user_func_array('sprintf', array_merge((array) $this->where['str'], OsimoDB::escape($this->where['vars'], true))); } return $this->where['str']; }
/** * 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; } }
function get($name) { if($name == 'debug') { return new DummyDebug(); } elseif($name == 'db') { return OsimoDB::instance(); } }