public function remove() { $db = DB::get_db(); $tables = ['pms_data', 'pms_folders', 'pms_messages', 'pms_conversations', 'pms_blocks']; $req = 'DROP TABLE IF EXISTS ' . implode(', ', $tables); return $db->exec($req); }
public function print_users($username, $start_from, $sort_by, $sort_dir, $show_group) { $userlist_data = array(); $username = Container::get('hooks')->fire('model.userlist.print_users_start', $username, $start_from, $sort_by, $sort_dir, $show_group); // Retrieve a list of user IDs, LIMIT is (really) expensive so we only fetch the IDs here then later fetch the remaining data $result = DB::for_table('users')->select('u.id')->table_alias('u')->where_gt('u.id', 1)->where_not_equal('u.group_id', ForumEnv::get('FEATHER_UNVERIFIED')); if ($username != '') { $result = $result->where_like('u.username', str_replace('*', '%', $username)); } if ($show_group > -1) { $result = $result->where('u.group_id', $show_group); } $result = $result->order_by($sort_by, $sort_dir)->order_by_asc('u.id')->limit(50)->offset($start_from); $result = Container::get('hooks')->fireDB('model.userlist.print_users_query', $result); $result = $result->find_many(); if ($result) { $user_ids = array(); foreach ($result as $cur_user_id) { $user_ids[] = $cur_user_id['id']; } // Grab the users $result['select'] = array('u.id', 'u.username', 'u.title', 'u.num_posts', 'u.registered', 'g.g_id', 'g.g_user_title'); $result = DB::for_table('users')->table_alias('u')->select_many($result['select'])->left_outer_join('groups', array('g.g_id', '=', 'u.group_id'), 'g')->where_in('u.id', $user_ids)->order_by($sort_by, $sort_dir)->order_by_asc('u.id'); $result = Container::get('hooks')->fireDB('model.userlist.print_users_grab_query', $result); $result = $result->find_many(); foreach ($result as $user_data) { $userlist_data[] = $user_data; } } $userlist_data = Container::get('hooks')->fire('model.userlist.print_users', $userlist_data); return $userlist_data; }
public static function set_new_password($pass, $key, $user_id) { $query['update'] = array('activate_string' => hash($pass), 'activate_key' => $key, 'last_email_sent' => time()); $query = DB::for_table('users')->where('id', $user_id)->find_one()->set($query['update']); $query = Container::get('hooks')->fireDB('password_forgotten_mail_query', $query); return $query->save(); }
public static function get_info() { $data = array('exec_time' => Utils::get_microtime() - Container::get('start')); $data['nb_queries'] = isset(DB::get_query_log()[0]) ? count(DB::get_query_log()[0]) : 'N/A'; $data['mem_usage'] = function_exists('memory_get_usage') ? Utils::file_size(memory_get_usage()) : 'N/A'; $data['mem_peak_usage'] = function_exists('memory_get_peak_usage') ? Utils::file_size(memory_get_peak_usage()) : 'N/A'; return $data; }
public function get_words() { $word_data = array(); $word_data = DB::for_table('censoring')->order_by_asc('id'); $word_data = Container::get('hooks')->fireDB('model.admin.censoring.update_censoring_word_query', $word_data); $word_data = $word_data->find_array(); return $word_data; }
public function get_cat_list() { $cat_list = array(); $select_get_cat_list = array('id', 'cat_name', 'disp_position'); $cat_list = DB::for_table('categories')->select($select_get_cat_list)->order_by_asc('disp_position'); $cat_list = Container::get('hooks')->fireDB('model.admin.categories.get_cat_list', $cat_list); $cat_list = $cat_list->find_array(); return $cat_list; }
public function setActivePlugins() { $activePlugins = []; $results = DB::for_table('plugins')->select('name')->where('active', 1)->find_array(); foreach ($results as $plugin) { $activePlugins[] = $plugin['name']; } Container::get('cache')->store('activePlugins', $activePlugins); return $activePlugins; }
public function get_zapped_reports() { $zapped_reports = array(); $select_zapped_reports = array('r.id', 'r.topic_id', 'r.forum_id', 'r.reported_by', 'r.message', 'r.zapped', 'zapped_by_id' => 'r.zapped_by', 'pid' => 'p.id', 't.subject', 'f.forum_name', 'reporter' => 'u.username', 'zapped_by' => 'u2.username'); $zapped_reports = DB::for_table('reports')->table_alias('r')->select_many($select_zapped_reports)->left_outer_join('posts', array('r.post_id', '=', 'p.id'), 'p')->left_outer_join('topics', array('r.topic_id', '=', 't.id'), 't')->left_outer_join('forums', array('r.forum_id', '=', 'f.id'), 'f')->left_outer_join('users', array('r.reported_by', '=', 'u.id'), 'u')->left_outer_join('users', array('r.zapped_by', '=', 'u2.id'), 'u2')->where_not_null('r.zapped')->order_by_desc('zapped')->limit(10); $zapped_reports = Container::get('hooks')->fireDB('model.admin.reports.get_zapped_reports.query', $zapped_reports); $zapped_reports = $zapped_reports->find_array(); $zapped_reports = Container::get('hooks')->fire('model.admin.reports.get_zapped_reports', $zapped_reports); return $zapped_reports; }
public function get_total_size() { $total = array(); if (ForumSettings::get('db_type') == 'mysql' || ForumSettings::get('db_type') == 'mysqli' || ForumSettings::get('db_type') == 'mysql_innodb' || ForumSettings::get('db_type') == 'mysqli_innodb') { // Calculate total db size/row count $result = DB::for_table('users')->raw_query('SHOW TABLE STATUS LIKE \'' . ForumSettings::get('db_prefix') . '%\'')->find_many(); $result = Container::get('hooks')->fire('model.admin.model.statistics.get_total_size.raw_data', $result); $total['size'] = $total['records'] = 0; foreach ($result as $status) { $total['records'] += $status['Rows']; $total['size'] += $status['Data_length'] + $status['Index_length']; } $total['size'] = Utils::file_size($total['size']); } $total = Container::get('hooks')->fire('model.admin.model.statistics.get_total_size.total', $total); return $total; }
public function remove() { $db = DB::get_db(); $tables = ['pms_data', 'pms_folders', 'pms_messages', 'pms_conversations', 'pms_blocks']; foreach ($tables as $i) { $tableExists = DB::for_table($i)->raw_query('SHOW TABLES LIKE "' . ForumSettings::get('db_prefix') . $i . '"')->find_one(); if ($tableExists) { $db->exec('DROP TABLE ' . ForumSettings::get('db_prefix') . $i); } } $columns = ['g_pm_limit', 'g_use_pm', 'g_pm_folder_limit']; foreach ($columns as $i) { $columnExists = DB::for_table('groups')->raw_query('SHOW COLUMNS FROM ' . ForumSettings::get('db_prefix') . 'groups LIKE \'' . $i . '\'')->find_one(); if ($columnExists) { $db->exec('ALTER TABLE ' . ForumSettings::get('db_prefix') . 'groups DROP COLUMN ' . $i); } } }
public function update_permissions() { $form = array_map('intval', Input::post('form')); $form = Container::get('hooks')->fire('model.admin.permissions.update_permissions.form', $form); foreach ($form as $key => $input) { // Make sure the input is never a negative value if ($input < 0) { $input = 0; } // Only update values that have changed if (array_key_exists('p_' . $key, Container::get('forum_settings')) && ForumSettings::get('p_' . $key) != $input) { DB::for_table('config')->where('conf_name', 'p_' . $key)->update_many('conf_value', $input); } } // Regenerate the config cache Container::get('cache')->store('config', Cache::get_config()); // $this->clear_feed_cache(); return Router::redirect(Router::pathFor('adminPermissions'), __('Perms updated redirect')); }
/** * Uninstall a plugin after deactivated */ public function uninstall($name) { $name = Container::get('hooks')->fire('model.plugin.uninstall.name', $name); $activePlugins = $this->manager->getActivePlugins(); // Check if plugin is disabled, for security if (!in_array($name, $activePlugins)) { $plugin = DB::for_table('plugins')->where('name', $name)->find_one(); if ($plugin) { $plugin->delete(); } // Allow additional uninstalling functions $this->manager->uninstall($name); if (file_exists(ForumEnv::get('FEATHER_ROOT') . 'plugins' . DIRECTORY_SEPARATOR . $name)) { AdminUtils::delete_folder(ForumEnv::get('FEATHER_ROOT') . 'plugins' . DIRECTORY_SEPARATOR . $name); } $this->manager->setActivePlugins(); } return true; }
public static function get_quickjump() { $select_quickjump = array('g_id', 'g_read_board'); $read_perms = DB::for_table('groups')->select_many($select_quickjump)->where('g_read_board', 1)->find_array(); $output = array(); foreach ($read_perms as $item) { $select_quickjump = array('cid' => 'c.id', 'c.cat_name', 'fid' => 'f.id', 'f.forum_name', 'f.redirect_url'); $where_quickjump = array(array('fp.read_forum' => 'IS NULL'), array('fp.read_forum' => '1')); $order_by_quickjump = array('c.disp_position', 'c.id', 'f.disp_position'); $result = DB::for_table('categories')->table_alias('c')->select_many($select_quickjump)->inner_join('forums', array('c.id', '=', 'f.cat_id'), 'f')->left_outer_join('forum_perms', array('fp.forum_id', '=', 'f.id'), 'fp')->left_outer_join('forum_perms', array('fp.group_id', '=', $item['g_id']), null, true)->where_any_is($where_quickjump)->where_null('f.redirect_url')->order_by_many($order_by_quickjump)->find_many(); $forum_data = array(); foreach ($result as $forum) { if (!isset($forum_data[$forum['cid']])) { $forum_data[$forum['cid']] = array('cat_name' => $forum['cat_name'], 'cat_position' => $forum['cat_position'], 'cat_forums' => array()); } $forum_data[$forum['cid']]['cat_forums'][] = array('forum_id' => $forum['fid'], 'forum_name' => $forum['forum_name'], 'position' => $forum['forum_position']); } $output[(int) $item['g_id']] = $forum_data; } return $output; }
public static function init_db(array $config, $log_queries = false) { $config['db_prefix'] = !empty($config['db_prefix']) ? $config['db_prefix'] : ''; switch ($config['db_type']) { case 'mysql': DB::configure('mysql:host=' . $config['db_host'] . ';dbname=' . $config['db_name']); DB::configure('driver_options', array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); break; case 'sqlite': case 'sqlite3': DB::configure('sqlite:./' . $config['db_name']); break; case 'pgsql': DB::configure('pgsql:host=' . $config['db_host'] . 'dbname=' . $config['db_name']); break; } DB::configure('username', $config['db_user']); DB::configure('password', $config['db_pass']); DB::configure('prefix', $config['db_prefix']); if ($log_queries) { DB::configure('logging', true); } DB::configure('id_column_overrides', array($config['db_prefix'] . 'groups' => 'g_id')); }
function authenticate_user($user, $password, $password_is_hash = false) { // Check if there's a user matching $user and $password $select_check_cookie = array('u.*', 'g.*', 'o.logged', 'o.idle'); $result = DB::for_table('users')->table_alias('u')->select_many($select_check_cookie)->inner_join('groups', array('u.group_id', '=', 'g.g_id'), 'g')->left_outer_join('online', array('o.user_id', '=', 'u.id'), 'o'); if (is_int($user)) { $result = $result->where('u.id', intval($user)); } else { $result = $result->where('u.username', $user); } $result = $result->find_result_set(); foreach ($result as User::get()) { } if (!isset(User::get()->id) || $password_is_hash && $password != User::get()->password || !$password_is_hash && \FeatherBB\Core\Random::hash($password) != User::get()->password) { set_default_user(); } else { User::get()->is_guest = false; } translate('common'); translate('index'); }
public function increment_views($id) { if (ForumSettings::get('o_topic_views') == '1') { $query = DB::for_table('topics')->where('id', $id)->find_one()->set_expr('num_views', 'num_views+1'); $query = Container::get('hooks')->fire('model.topic.increment_views', $query); $query = $query->save(); } }
public function update_permissions() { $form = array_map('intval', Request::getParsedBody()); $form = Container::get('hooks')->fire('model.admin.permissions.plugins.private-messages.form', $form); $update = array(); foreach ($form as $key => $input) { // Make sure the input is never a negative value if ($input < 0) { $input = 0; } // Get the group ID from key_gX $group_id = filter_var($key, FILTER_SANITIZE_NUMBER_INT); if ($group_id != '') { // Clean key without the group ID if ($group_id < 10) { $key_cleaned = substr($key, 0, -3); } elseif ($group_id < 100) { $key_cleaned = substr($key, 0, -4); } else { $key_cleaned = substr($key, 0, -5); } // Build the array for the query $update[$group_id]['g_' . $key_cleaned] = $input; } } foreach ($update as $group_id => $values) { DB::for_table('groups')->find_one($group_id)->set($values)->save(); } return Router::redirect(Router::pathFor('infoPlugin', ['name' => 'private-messages']), __('Perms updated redirect')); }
public function find_ban($start_from = false) { $ban_info = array(); Container::get('hooks')->fire('model.admin.bans.find_ban_start'); // trim() all elements in $form $ban_info['conditions'] = $ban_info['query_str'] = array(); $expire_after = Input::query('expire_after') ? Utils::trim(Input::query('expire_after')) : ''; $expire_before = Input::query('expire_before') ? Utils::trim(Input::query('expire_before')) : ''; $ban_info['order_by'] = Input::query('order_by') && in_array(Input::query('order_by'), array('username', 'ip', 'email', 'expire')) ? 'b.' . Input::query('order_by') : 'b.username'; $ban_info['direction'] = Input::query('direction') && Input::query('direction') == 'DESC' ? 'DESC' : 'ASC'; $ban_info['query_str'][] = 'order_by=' . $ban_info['order_by']; $ban_info['query_str'][] = 'direction=' . $ban_info['direction']; // Build the query $result = DB::for_table('bans')->table_alias('b')->where_gt('b.id', 0); // Try to convert date/time to timestamps if ($expire_after != '') { $ban_info['query_str'][] = 'expire_after=' . $expire_after; $expire_after = strtotime($expire_after); if ($expire_after === false || $expire_after == -1) { throw new Error(__('Invalid date message'), 400); } $result = $result->where_gt('b.expire', $expire_after); } if ($expire_before != '') { $ban_info['query_str'][] = 'expire_before=' . $expire_before; $expire_before = strtotime($expire_before); if ($expire_before === false || $expire_before == -1) { throw new Error(__('Invalid date message'), 400); } $result = $result->where_lt('b.expire', $expire_before); } if (Input::query('username')) { $result = $result->where_like('b.username', str_replace('*', '%', Input::query('username'))); $ban_info['query_str'][] = 'username='******'username')); } if (Input::query('ip')) { $result = $result->where_like('b.ip', str_replace('*', '%', Input::query('ip'))); $ban_info['query_str'][] = 'ip=' . urlencode(Input::query('ip')); } if (Input::query('email')) { $result = $result->where_like('b.email', str_replace('*', '%', Input::query('email'))); $ban_info['query_str'][] = 'email=' . urlencode(Input::query('email')); } if (Input::query('message')) { $result = $result->where_like('b.message', str_replace('*', '%', Input::query('message'))); $ban_info['query_str'][] = 'message=' . urlencode(Input::query('message')); } // Fetch ban count if (is_numeric($start_from)) { $ban_info['data'] = array(); $select_bans = array('b.id', 'b.username', 'b.ip', 'b.email', 'b.message', 'b.expire', 'b.ban_creator', 'ban_creator_username' => 'u.username'); $result = $result->select_many($select_bans)->left_outer_join('users', array('b.ban_creator', '=', 'u.id'), 'u')->order_by($ban_info['order_by'], $ban_info['direction'])->offset($start_from)->limit(50)->find_many(); foreach ($result as $cur_ban) { $ban_info['data'][] = $cur_ban; } } else { $ban_info['num_bans'] = $result->count('id'); } Container::get('hooks')->fire('model.admin.bans.find_ban', $ban_info); return $ban_info; }
public function send_email($mail) { $mail = Container::get('hooks')->fire('model.profile.send_email_start', $mail); // Clean up message and subject from POST $subject = Utils::trim(Input::post('req_subject')); $message = Utils::trim(Input::post('req_message')); if ($subject == '') { throw new Error(__('No email subject'), 400); } elseif ($message == '') { throw new Error(__('No email message'), 400); } elseif (strlen($message) > ForumEnv::get('FEATHER_MAX_POSTSIZE')) { throw new Error(__('Too long email message'), 400); } if (User::get()->last_email_sent != '' && time() - User::get()->last_email_sent < User::get()->g_email_flood && time() - User::get()->last_email_sent >= 0) { throw new Error(sprintf(__('Email flood'), User::get()->g_email_flood, User::get()->g_email_flood - (time() - User::get()->last_email_sent)), 429); } // Load the "form email" template $mail_tpl = trim(file_get_contents(ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/mail_templates/form_email.tpl')); $mail_tpl = Container::get('hooks')->fire('model.profile.send_email_mail_tpl', $mail_tpl); // The first row contains the subject $first_crlf = strpos($mail_tpl, "\n"); $mail_subject = Utils::trim(substr($mail_tpl, 8, $first_crlf - 8)); $mail_message = Utils::trim(substr($mail_tpl, $first_crlf)); $mail_subject = str_replace('<mail_subject>', $subject, $mail_subject); $mail_message = str_replace('<sender>', User::get()->username, $mail_message); $mail_message = str_replace('<board_title>', ForumSettings::get('o_board_title'), $mail_message); $mail_message = str_replace('<mail_message>', $message, $mail_message); $mail_message = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message); $mail_message = Container::get('hooks')->fire('model.profile.send_email_mail_message', $mail_message); Container::get('email')->feather_mail($mail['recipient_email'], $mail_subject, $mail_message, User::get()->email, User::get()->username); $update_last_mail_sent = DB::for_table('users')->where('id', User::get()->id)->find_one()->set('last_email_sent', time()); $update_last_mail_sent = Container::get('hooks')->fireDB('model.profile.send_email_update_last_mail_sent', $update_last_mail_sent); $update_last_mail_sent = $update_last_mail_sent->save(); // Try to determine if the data in redirect_url is valid (if not, we redirect to index.php after the email is sent) TODO //$redirect_url = validate_redirect(Input::post('redirect_url'), 'index.php'); return Router::redirect(Router::pathFor('home'), __('Email sent redirect')); }
public function delete_permissions($forum_id, $group_id = null) { $result = DB::for_table('forum_perms')->where('forum_id', $forum_id); if ($group_id) { $result->where('group_id', $group_id); } $result = Container::get('hooks')->fireDB('model.admin.forums.delete_permissions_query', $result); return $result->delete_many(); }
public function __invoke($req, $res, $next) { $authCookie = Container::get('cookie')->get(ForumSettings::get('cookie_name')); if ($jwt = $this->get_cookie_data($authCookie)) { $user = AuthModel::load_user($jwt->data->userId); $expires = $jwt->exp > Container::get('now') + ForumSettings::get('o_timeout_visit') ? Container::get('now') + 1209600 : Container::get('now') + ForumSettings::get('o_timeout_visit'); $user->is_guest = false; $user->is_admmod = $user->g_id == ForumEnv::get('FEATHER_ADMIN') || $user->g_moderator == '1'; if (!$user->disp_topics) { $user->disp_topics = ForumSettings::get('o_disp_topics_default'); } if (!$user->disp_posts) { $user->disp_posts = ForumSettings::get('o_disp_posts_default'); } if (!file_exists(ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . $user->language)) { $user->language = ForumSettings::get('o_default_lang'); } if (!file_exists(ForumEnv::get('FEATHER_ROOT') . 'style/themes/' . $user->style . '/style.css')) { $user->style = ForumSettings::get('o_default_style'); } // Refresh cookie to avoid re-logging between idle $jwt = AuthModel::generate_jwt($user, $expires); AuthModel::feather_setcookie('Bearer ' . $jwt, $expires); // Add user to DIC Container::set('user', $user); $this->update_online(); } else { $user = AuthModel::load_user(1); $user->disp_topics = ForumSettings::get('o_disp_topics_default'); $user->disp_posts = ForumSettings::get('o_disp_posts_default'); $user->timezone = ForumSettings::get('o_default_timezone'); $user->dst = ForumSettings::get('o_default_dst'); $user->language = ForumSettings::get('o_default_lang'); $user->style = ForumSettings::get('o_default_style'); $user->is_guest = true; $user->is_admmod = false; // Update online list if (!$user->logged) { $user->logged = time(); // With MySQL/MySQLi/SQLite, REPLACE INTO avoids a user having two rows in the online table switch (ForumSettings::get('db_type')) { case 'mysql': case 'mysqli': case 'mysql_innodb': case 'mysqli_innodb': case 'sqlite': case 'sqlite3': DB::for_table('online')->raw_execute('REPLACE INTO ' . ForumSettings::get('db_prefix') . 'online (user_id, ident, logged) VALUES(1, :ident, :logged)', array(':ident' => Utils::getIp(), ':logged' => $user->logged)); break; default: DB::for_table('online')->raw_execute('INSERT INTO ' . ForumSettings::get('db_prefix') . 'online (user_id, ident, logged) SELECT 1, :ident, :logged WHERE NOT EXISTS (SELECT 1 FROM ' . ForumSettings::get('db_prefix') . 'online WHERE ident=:ident)', array(':ident' => Utils::getIp(), ':logged' => $user->logged)); break; } } else { DB::for_table('online')->where('ident', Utils::getIp())->update_many('logged', time()); } // $jwt = AuthModel::generate_jwt($user, Container::get('now') + 31536000); // AuthModel::feather_setcookie('Bearer '.$jwt, Container::get('now') + 31536000); // Add $user as guest to DIC Container::set('user', $user); } translate('common'); // Load bans from cache if (!Container::get('cache')->isCached('bans')) { Container::get('cache')->store('bans', Cache::get_bans()); } // Add bans to the container Container::set('bans', Container::get('cache')->retrieve('bans')); // Check if current user is banned $this->check_bans(); // Update online list $this->update_users_online(); return $next($req, $res); }
public function get_first_id() { $first_id = ''; $first_id_sql = DB::for_table('posts')->order_by_asc('id')->find_one_col('id'); if ($first_id_sql) { $first_id = $first_id_sql; } $first_id = Container::get('hooks')->fire('model.admin.maintenance.get_first_id', $first_id); return $first_id; }
public function add_data($table_name, array $data) { return (bool) DB::for_table($table_name)->create()->set($data)->save(); }
public function insert_user($user) { $user = Container::get('hooks')->fire('model.register.insert_user_start', $user); // Insert the new user into the database. We do this now to get the last inserted ID for later use $now = time(); $intial_group_id = ForumSettings::get('o_regs_verify') == '0' ? ForumSettings::get('o_default_user_group') : ForumEnv::get('FEATHER_UNVERIFIED'); $password_hash = Random::hash($user['password1']); // Add the user $user['insert'] = array('username' => $user['username'], 'group_id' => $intial_group_id, 'password' => $password_hash, 'email' => $user['email1'], 'email_setting' => ForumSettings::get('o_default_email_setting'), 'timezone' => ForumSettings::get('o_default_timezone'), 'dst' => 0, 'language' => $user['language'], 'style' => ForumSettings::get('o_default_style'), 'registered' => $now, 'registration_ip' => Utils::getIp(), 'last_visit' => $now); $user = DB::for_table('users')->create()->set($user['insert']); $user = Container::get('hooks')->fireDB('model.register.insert_user_query', $user); $user = $user->save(); $new_uid = DB::get_db()->lastInsertId(ForumSettings::get('db_prefix') . 'users'); // If the mailing list isn't empty, we may need to send out some alerts if (ForumSettings::get('o_mailing_list') != '') { // If we previously found out that the email was banned if (isset($user['banned_email'])) { // Load the "banned email register" template $mail_tpl = trim(file_get_contents(ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/mail_templates/banned_email_register.tpl')); $mail_tpl = Container::get('hooks')->fire('model.register.insert_user_banned_mail_tpl', $mail_tpl); // The first row contains the subject $first_crlf = strpos($mail_tpl, "\n"); $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8)); $mail_subject = Container::get('hooks')->fire('model.register.insert_user_banned_mail_subject', $mail_subject); $mail_message = trim(substr($mail_tpl, $first_crlf)); $mail_message = str_replace('<username>', $user['username'], $mail_message); $mail_message = str_replace('<email>', $user['email1'], $mail_message); $mail_message = str_replace('<profile_url>', Router::pathFor('userProfile', ['id' => $new_uid]), $mail_message); $mail_message = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message); $mail_message = Container::get('hooks')->fire('model.register.insert_user_banned_mail_message', $mail_message); Container::get('email')->feather_mail(ForumSettings::get('o_mailing_list'), $mail_subject, $mail_message); } // If we previously found out that the email was a dupe if (!empty($dupe_list)) { // Load the "dupe email register" template $mail_tpl = trim(file_get_contents(ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/mail_templates/dupe_email_register.tpl')); $mail_tpl = Container::get('hooks')->fire('model.register.insert_user_dupe_mail_tpl', $mail_tpl); // The first row contains the subject $first_crlf = strpos($mail_tpl, "\n"); $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8)); $mail_subject = Container::get('hooks')->fire('model.register.insert_user_dupe_mail_subject', $mail_subject); $mail_message = trim(substr($mail_tpl, $first_crlf)); $mail_message = str_replace('<username>', $user['username'], $mail_message); $mail_message = str_replace('<dupe_list>', implode(', ', $dupe_list), $mail_message); $mail_message = str_replace('<profile_url>', Router::pathFor('userProfile', ['id' => $new_uid]), $mail_message); $mail_message = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message); $mail_message = Container::get('hooks')->fire('model.register.insert_user_dupe_mail_message', $mail_message); Container::get('email')->feather_mail(ForumSettings::get('o_mailing_list'), $mail_subject, $mail_message); } // Should we alert people on the admin mailing list that a new user has registered? if (ForumSettings::get('o_regs_report') == '1') { // Load the "new user" template $mail_tpl = trim(file_get_contents(ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/mail_templates/new_user.tpl')); $mail_tpl = Container::get('hooks')->fire('model.register.insert_user_new_mail_tpl', $mail_tpl); // The first row contains the subject $first_crlf = strpos($mail_tpl, "\n"); $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8)); $mail_subject = Container::get('hooks')->fire('model.register.insert_user_new_mail_subject', $mail_subject); $mail_message = trim(substr($mail_tpl, $first_crlf)); $mail_message = str_replace('<username>', $user['username'], $mail_message); $mail_message = str_replace('<base_url>', Router::pathFor('home'), $mail_message); $mail_message = str_replace('<profile_url>', Router::pathFor('userProfile', ['id' => $new_uid]), $mail_message); $mail_message = str_replace('<admin_url>', Router::pathFor('profileSection', ['id' => $new_uid, 'section' => 'admin']), $mail_message); $mail_message = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message); $mail_message = Container::get('hooks')->fire('model.register.insert_user_new_mail_message', $mail_message); Container::get('email')->feather_mail(ForumSettings::get('o_mailing_list'), $mail_subject, $mail_message); } } // Must the user verify the registration or do we log him/her in right now? if (ForumSettings::get('o_regs_verify') == '1') { // Load the "welcome" template $mail_tpl = trim(file_get_contents(ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/mail_templates/welcome.tpl')); $mail_tpl = Container::get('hooks')->fire('model.register.insert_user_welcome_mail_tpl', $mail_tpl); // The first row contains the subject $first_crlf = strpos($mail_tpl, "\n"); $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8)); $mail_subject = Container::get('hooks')->fire('model.register.insert_user_welcome_mail_subject', $mail_subject); $mail_message = trim(substr($mail_tpl, $first_crlf)); $mail_subject = str_replace('<board_title>', ForumSettings::get('o_board_title'), $mail_subject); $mail_message = str_replace('<base_url>', Router::pathFor('home'), $mail_message); $mail_message = str_replace('<username>', $user['username'], $mail_message); $mail_message = str_replace('<password>', $user['password1'], $mail_message); $mail_message = str_replace('<login_url>', Router::pathFor('login'), $mail_message); $mail_message = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message); $mail_message = Container::get('hooks')->fire('model.register.insert_user_welcome_mail_message', $mail_message); Container::get('email')->feather_mail($user['email1'], $mail_subject, $mail_message); return Router::redirect(Router::pathFor('home'), __('Reg email') . ' <a href="mailto:' . Utils::escape(ForumSettings::get('o_admin_email')) . '">' . Utils::escape(ForumSettings::get('o_admin_email')) . '</a>.'); } $user_object = new \stdClass(); $user_object->id = $new_uid; $user_object->username = $user['username']; $expire = time() + ForumSettings::get('o_timeout_visit'); $jwt = AuthModel::generate_jwt($user_object, $expire); AuthModel::feather_setcookie('Bearer ' . $jwt, $expire); // Refresh cache Container::get('cache')->store('users_info', Cache::get_users_info()); Container::get('hooks')->fire('model.register.insert_user'); return Router::redirect(Router::pathFor('home'), __('Reg complete')); }
public function fetch_users_online() { Container::get('hooks')->fire('model.index.fetch_users_online_start'); // Fetch users online info and generate strings for output $online = array(); $online['num_guests'] = 0; $query['select'] = array('user_id', 'ident'); $query['where'] = array('idle' => '0'); $query['order_by'] = array('ident'); $query = DB::for_table('online')->select_many($query['select'])->where($query['where'])->order_by_many($query['order_by']); $query = Container::get('hooks')->fireDB('model.index.query_fetch_users_online', $query); $query = $query->find_result_set(); foreach ($query as $user_online) { if ($user_online->user_id > 1) { if (User::get()->g_view_users == '1') { $online['users'][] = "\n\t\t\t\t" . '<dd><a href="' . Router::pathFor('userProfile', ['id' => $user_online->user_id]) . '">' . Utils::escape($user_online->ident) . '</a>'; } else { $online['users'][] = "\n\t\t\t\t" . '<dd>' . Utils::escape($user_online->ident); } } else { ++$online['num_guests']; } } if (isset($online['users'])) { $online['num_users'] = count($online['users']); } else { $online['num_users'] = 0; } $online = Container::get('hooks')->fire('model.index.fetch_users_online', $online); return $online; }
public function get_title_members($group_id) { $group_id = Container::get('hooks')->fire('model.admin.groups.get_title_members.group_id', $group_id); $group = DB::for_table('groups')->table_alias('g')->select('g.g_title')->select_expr('COUNT(u.id)', 'members')->inner_join('users', array('g.g_id', '=', 'u.group_id'), 'u')->where('g.g_id', $group_id)->group_by('g.g_id')->group_by('g_title'); $group = Container::get('hooks')->fireDB('model.admin.groups.get_title_members.query', $group); $group = $group->find_one(); $group_info['title'] = $group['g_title']; $group_info['members'] = $group['members']; $group_info = Container::get('hooks')->fire('model.admin.groups.get_title_members.group_info', $group_info); return $group_info; }
protected function getInfosFromUser($user = null) { if (is_object($user)) { $uid = $user->id; $gid = $user->group_id; } elseif ((int) $user > 0) { $data = DB::for_table('users')->find_one($user); if (!$data) { throw new \ErrorException('Internal error : Unknown user ID', 500); } $uid = $data['id']; $gid = $data['group_id']; } else { throw new \ErrorException('Internal error : wrong user object type', 500); } return array((int) $uid, (int) $gid); }
public function removeFolder($user_id, $block_id) { $result = DB::for_table('pms_folders')->where('id', $block_id)->where('user_id', $user_id)->find_one(); return $result->delete(); }
public function send($uid = null, $conv_id = null) { if ($this->feather->request->isPost()) { // First raw validation $data = array_merge(array('username' => null, 'subject' => null, 'message' => null, 'smilies' => 0, 'preview' => null), $this->feather->request->post()); $data = array_map(array('FeatherBB\\Core\\Utils', 'trim'), $data); $conv = false; if (!is_null($conv_id)) { if ($conv_id < 1) { throw new Error('Wrong conversation ID', 400); } if (!($conv = $this->model->getConversation($conv_id, $this->feather->user->id))) { throw new Error('Unknown conversation ID', 400); } } // Preview message if ($this->feather->request->post('preview')) { // Make breadcrumbs $this->crumbs[] = __('Reply', 'private_messages'); $this->crumbs[] = __('Preview'); Utils::generateBreadcrumbs($this->crumbs); $this->feather->hooks->fire('conversationsPlugin.send.preview'); $msg = $this->feather->parser->parse_message($data['req_message'], $data['smilies']); $this->feather->template->setPageInfo(array('parsed_message' => $msg, 'username' => Utils::escape($data['username']), 'subject' => Utils::escape($data['subject']), 'message' => Utils::escape($data['req_message'])))->addTemplate('send.php')->display(); } else { // Prevent flood if (!is_null($data['preview']) && $this->feather->user['last_post'] != '' && $this->feather->now - $this->feather->user['last_post'] < $this->feather->user['g_post_flood']) { throw new Error(sprintf($lang_post['Flood start'], $this->feather->user['g_post_flood'], $this->feather->user['g_post_flood'] - ($this->feather->now - $this->feather->user['last_post'])), 429); } if (!$conv) { // Validate username / TODO : allow multiple usernames if (!($user = $this->model->isAllowed($data['username']))) { throw new Error('You can\'t send an PM to ' . ($data['username'] ? $data['username'] : '******'), 400); } // Avoid self messages if ($user->id == $this->feather->user->id) { throw new Error('No self message', 403); } // Validate subject if ($this->feather->forum_settings['o_censoring'] == '1') { $data['subject'] = Utils::trim(Utils::censor($data['subject'])); } if (empty($data['subject'])) { throw new Error('No subject or censored subject', 400); } else { if (Utils::strlen($data['subject']) > 70) { throw new Error('Too long subject', 400); } else { if ($this->feather->forum_settings['p_subject_all_caps'] == '0' && Utils::is_all_uppercase($data['subject']) && !$this->feather->user->is_admmod) { throw new Error('All caps subject forbidden', 400); } } } } // TODO : inbox full // Validate message if ($this->feather->forum_settings['o_censoring'] == '1') { $data['req_message'] = Utils::trim(Utils::censor($data['req_message'])); } if (empty($data['req_message'])) { throw new Error('No message or censored message', 400); } else { if (Utils::strlen($data['req_message']) > $this->feather->forum_env['FEATHER_MAX_POSTSIZE']) { throw new Error('Too long message', 400); } else { if ($this->feather->forum_settings['p_subject_all_caps'] == '0' && Utils::is_all_uppercase($data['subject']) && !$this->feather->user->is_admmod) { throw new Error('All caps message forbidden', 400); } } } // Send ... TODO : when perms will be ready // Check if the receiver has the PM enabled // Check if he has reached his max limit of PM // Block feature ? if (!$conv) { $conv_data = array('subject' => $data['subject'], 'poster' => $this->feather->user->username, 'poster_id' => $this->feather->user->id, 'num_replies' => 0, 'last_post' => $this->feather->now, 'last_poster' => $this->feather->user->username); $conv_id = $this->model->addConversation($conv_data); } if ($conv_id) { $msg_data = array('poster' => $this->feather->user->username, 'poster_id' => $this->feather->user->id, 'poster_ip' => $this->feather->request->getIp(), 'message' => $data['req_message'], 'hide_smilies' => $data['smilies'], 'sent' => $this->feather->now); if ($conv) { // Reply to an existing conversation if ($msg_id = $this->model->addMessage($msg_data, $conv_id)) { Url::redirect($this->feather->urlFor('Conversations.home'), sprintf(__('Reply success', 'private_messages'), $conv->subject)); } } else { // Add message in conversation + add receiver (create new conversation) if ($msg_id = $this->model->addMessage($msg_data, $conv_id, array($user->id, $this->feather->user->id))) { Url::redirect($this->feather->urlFor('Conversations.home'), sprintf(__('Send success', 'private_messages'), $user->username)); } } } else { throw new Error('Unable to create conversation'); } } } else { $this->feather->hooks->fire('conversationsPlugin.send.display'); // New conversation if (!is_null($uid)) { if ($uid < 2) { throw new Error('Wrong user ID', 400); } if ($user = $this->model->getUserByID($uid)) { $this->feather->template->setPageInfo(array('username' => Utils::escape($user->username))); } else { throw new Error('Unable to find user', 400); } } // Reply if (!is_null($conv_id)) { if ($conv_id < 1) { throw new Error('Wrong conversation ID', 400); } if ($conv = $this->model->getConversation($conv_id, $this->feather->user->id)) { $inbox = DB::for_table('pms_folders')->find_one($conv->folder_id); $this->crumbs[$this->feather->urlFor('Conversations.home', ['inbox_id' => $inbox['id']])] = $inbox['name']; $this->crumbs[] = __('Reply', 'private_messages'); $this->crumbs[] = $conv['subject']; Utils::generateBreadcrumbs($this->crumbs); return $this->feather->template->setPageInfo(array('current_inbox' => $inbox, 'conv' => $conv, 'msg_data' => $this->model->getMessagesFromConversation($conv_id, $this->feather->user->id, 5)))->addTemplate('reply.php')->display(); } else { throw new Error('Unknown conversation ID', 400); } } $this->crumbs[] = __('Send', 'private_messages'); if (isset($user)) { $this->crumbs[] = $user->username; } Utils::generateBreadcrumbs($this->crumbs); $this->feather->template->addTemplate('send.php')->display(); } }
public function display_ip_address($pid) { $pid = Container::get('hooks')->fire('model.post.display_ip_address_post_start', $pid); $ip = DB::for_table('posts')->where('id', $pid); $ip = Container::get('hooks')->fireDB('model.post.display_ip_address_post_query', $ip); $ip = $ip->find_one_col('poster_ip'); if (!$ip) { throw new Error(__('Bad request'), 404); } $ip = Container::get('hooks')->fire('model.post.display_ip_address_post', $ip); throw new Error(sprintf(__('Host info 1'), $ip) . '<br />' . sprintf(__('Host info 2'), @gethostbyaddr($ip)) . '<br /><br /><a href="' . Router::pathFor('usersIpShow', ['ip' => $ip]) . '">' . __('Show more users') . '</a>'); }