public function display($req, $res, $args) { Container::get('hooks')->fire('controller.userlist.display'); if (User::get()->g_view_users == '0') { throw new Error(__('No permission'), 403); } // Determine if we are allowed to view post counts $show_post_count = ForumSettings::get('o_show_post_count') == '1' || User::get()->is_admmod ? true : false; $username = Input::query('username') && User::get()->g_search_users == '1' ? Utils::trim(Input::query('username')) : ''; $show_group = Input::query('show_group') ? intval(Input::query('show_group')) : -1; $sort_by = Input::query('sort_by') && (in_array(Input::query('sort_by'), array('username', 'registered')) || Input::query('sort_by') == 'num_posts' && $show_post_count) ? Input::query('sort_by') : 'username'; $sort_dir = Input::query('sort_dir') && Input::query('sort_dir') == 'DESC' ? 'DESC' : 'ASC'; $num_users = $this->model->fetch_user_count($username, $show_group); // Determine the user offset (based on $page) $num_pages = ceil($num_users / 50); $p = !Input::query('p') || $page <= 1 || $page > $num_pages ? 1 : intval($page); $start_from = 50 * ($p - 1); if (User::get()->g_search_users == '1') { $focus_element = array('userlist', 'username'); } else { $focus_element = array(); } // Generate paging links $paging_links = '<span class="pages-label">' . __('Pages') . ' </span>' . Url::paginate_old($num_pages, $p, '?username='******'&show_group=' . $show_group . '&sort_by=' . $sort_by . '&sort_dir=' . $sort_dir); View::setPageInfo(array('title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('User list')), 'active_page' => 'userlist', 'page_number' => $p, 'paging_links' => $paging_links, 'focus_element' => $focus_element, 'is_indexed' => true, 'username' => $username, 'show_group' => $show_group, 'sort_by' => $sort_by, 'sort_dir' => $sort_dir, 'show_post_count' => $show_post_count, 'dropdown_menu' => $this->model->generate_dropdown_menu($show_group), 'userlist_data' => $this->model->print_users($username, $start_from, $sort_by, $sort_dir, $show_group)))->addTemplate('userlist.php')->display(); }
public function display() { // Display bans if ($this->request->get('find_ban')) { $ban_info = $this->model->find_ban(); // Determine the ban offset (based on $_GET['p']) $num_pages = ceil($ban_info['num_bans'] / 50); $p = !$this->request->get('p') || $this->request->get('p') <= 1 || $this->request->get('p') > $num_pages ? 1 : intval($this->request->get('p')); $start_from = 50 * ($p - 1); $ban_data = $this->model->find_ban($start_from); $this->feather->template->setPageInfo(array('admin_console' => true, 'page' => $p, 'title' => array(Utils::escape($this->config['o_board_title']), __('Admin'), __('Bans'), __('Results head')), 'paging_links' => '<span class="pages-label">' . __('Pages') . ' </span>' . Url::paginate_old($num_pages, $p, '?find_ban=&' . implode('&', $ban_info['query_str'])), 'ban_data' => $ban_data['data']))->addTemplate('admin/bans/search_ban.php')->display(); } else { AdminUtils::generateAdminMenu('bans'); $this->feather->template->setPageInfo(array('admin_console' => true, 'focus_element' => array('bans', 'new_ban_user'), 'title' => array(Utils::escape($this->config['o_board_title']), __('Admin'), __('Bans'))))->addTemplate('admin/bans/admin_bans.php')->display(); } }
public function display($req, $res, $args) { Container::get('hooks')->fire('controller.admin.bans.display'); // Display bans if (Input::query('find_ban')) { $ban_info = $this->model->find_ban(); // Determine the ban offset (based on $_GET['p']) $num_pages = ceil($ban_info['num_bans'] / 50); $p = !Input::query('p') || Input::query('p') <= 1 || Input::query('p') > $num_pages ? 1 : intval(Input::query('p')); $start_from = 50 * ($p - 1); $ban_data = $this->model->find_ban($start_from); View::setPageInfo(array('admin_console' => true, 'page' => $p, 'title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Bans'), __('Results head')), 'paging_links' => '<span class="pages-label">' . __('Pages') . ' </span>' . Url::paginate_old($num_pages, $p, '?find_ban=&' . implode('&', $ban_info['query_str'])), 'ban_data' => $ban_data['data']))->addTemplate('admin/bans/search_ban.php')->display(); } else { AdminUtils::generateAdminMenu('bans'); View::setPageInfo(array('admin_console' => true, 'focus_element' => array('bans', 'new_ban_user'), 'title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Bans'))))->addTemplate('admin/bans/admin_bans.php')->display(); } }
public function get_search_results() { $search = array(); $search = $this->hook->fire('get_search_results_start', $search); $action = $this->request->get('action') ? $this->request->get('action') : null; $forums = $this->request->get('forums') ? is_array($this->request->get('forums')) ? $this->request->get('forums') : array_filter(explode(',', $this->request->get('forums'))) : ($this->request->get('forums') ? array($this->request->get('forums')) : array()); $sort_dir = $this->request->get('sort_dir') && $this->request->get('sort_dir') == 'DESC' ? 'DESC' : 'ASC'; $forums = array_map('intval', $forums); // Allow the old action names for backwards compatibility reasons if ($action == 'show_user') { $action = 'show_user_posts'; } elseif ($action == 'show_24h') { $action = 'show_recent'; } // If a search_id was supplied if ($this->request->get('search_id')) { $search_id = intval($this->request->get('search_id')); if ($search_id < 1) { throw new Error(__('Bad request'), 400); } } elseif ($action == 'search') { $keywords = $this->request->get('keywords') ? utf8_strtolower(Utils::trim($this->request->get('keywords'))) : null; $author = $this->request->get('author') ? utf8_strtolower(Utils::trim($this->request->get('author'))) : null; if (preg_match('%^[\\*\\%]+$%', $keywords) || Utils::strlen(str_replace(array('*', '%'), '', $keywords)) < $this->feather->forum_env['FEATHER_SEARCH_MIN_WORD'] && !$this->search->is_cjk($keywords)) { $keywords = ''; } if (preg_match('%^[\\*\\%]+$%', $author) || Utils::strlen(str_replace(array('*', '%'), '', $author)) < 2) { $author = ''; } if (!$keywords && !$author) { throw new Error(__('No terms'), 400); } if ($author) { $author = str_replace('*', '%', $author); } $show_as = $this->request->get('show_as') && $this->request->get('show_as') == 'topics' ? 'topics' : 'posts'; $sort_by = $this->request->get('sort_by') ? intval($this->request->get('sort_by')) : 0; $search_in = !$this->request->get('search_in') || $this->request->get('search_in') == '0' ? 0 : ($this->request->get('search_in') == '1' ? 1 : -1); } elseif ($action == 'show_user_posts' || $action == 'show_user_topics' || $action == 'show_subscriptions') { $user_id = $this->request->get('user_id') ? intval($this->request->get('user_id')) : $this->user->id; if ($user_id < 2) { throw new Error(__('Bad request'), 404); } // Subscribed topics can only be viewed by admins, moderators and the users themselves if ($action == 'show_subscriptions' && !$this->user->is_admmod && $user_id != $this->user->id) { throw new Error(__('No permission'), 403); } } elseif ($action == 'show_recent') { $interval = $this->request->get('value') ? intval($this->request->get('value')) : 86400; } elseif ($action == 'show_replies') { if ($this->user->is_guest) { throw new Error(__('Bad request'), 404); } } elseif ($action != 'show_new' && $action != 'show_unanswered') { throw new Error(__('Bad request'), 404); } // If a valid search_id was supplied we attempt to fetch the search results from the db if (isset($search_id)) { $ident = $this->user->is_guest ? $this->request->getIp() : $this->user->username; $search_data = DB::for_table('search_cache')->where('id', $search_id)->where('ident', $ident); $search_data = $this->hook->fireDB('get_search_results_search_data_query', $search_data); $search_data = $search_data->find_one_col('search_data'); if ($search_data) { $temp = unserialize($search_data); $temp = $this->hook->fire('get_search_results_temp', $temp); $search_ids = unserialize($temp['search_ids']); $num_hits = $temp['num_hits']; $sort_by = $temp['sort_by']; $sort_dir = $temp['sort_dir']; $show_as = $temp['show_as']; $search_type = $temp['search_type']; unset($temp); } else { throw new Error(__('No hits'), 204); } } else { $keyword_results = $author_results = array(); // Search a specific forum? $forum_sql = !empty($forums) || empty($forums) && $this->config['o_search_all_forums'] == '0' && !$this->user->is_admmod ? ' AND t.forum_id IN (' . implode(',', $forums) . ')' : ''; if (!empty($author) || !empty($keywords)) { // Flood protection if ($this->user->last_search && time() - $this->user->last_search < $this->user->g_search_flood && time() - $this->user->last_search >= 0) { throw new Error(sprintf(__('Search flood'), $this->user->g_search_flood, $this->user->g_search_flood - (time() - $this->user->last_search)), 429); } if (!$this->user->is_guest) { $update_last_search = DB::for_table('users')->where('id', $this->user->id); } else { $update_last_search = DB::for_table('online')->where('ident', $this->request->getIp()); } $update_last_search = $this->hook->fireDB('get_search_results_update_last_search', $update_last_search); $update_last_search = $update_last_search->update_many('last_search', time()); switch ($sort_by) { case 1: $sort_by_sql = $show_as == 'topics' ? 't.poster' : 'p.poster'; $sort_type = SORT_STRING; break; case 2: $sort_by_sql = 't.subject'; $sort_type = SORT_STRING; break; case 3: $sort_by_sql = 't.forum_id'; $sort_type = SORT_NUMERIC; break; case 4: $sort_by_sql = 't.last_post'; $sort_type = SORT_NUMERIC; break; default: $sort_by_sql = $show_as == 'topics' ? 't.last_post' : 'p.posted'; $sort_type = SORT_NUMERIC; break; } $sort_by = $this->hook->fire('get_search_results_sort_by', $sort_by); // If it's a search for keywords if ($keywords) { // split the keywords into words $keywords_array = $this->search->split_words($keywords, false); $keywords_array = $this->hook->fire('get_search_results_keywords_array', $keywords_array); if (empty($keywords_array)) { throw new Error(__('No hits'), 400); } // Should we search in message body or topic subject specifically? $search_in_cond = $search_in ? $search_in > 0 ? ' AND m.subject_match = 0' : ' AND m.subject_match = 1' : ''; $search_in_cond = $this->hook->fire('get_search_results_search_cond', $search_in_cond); $word_count = 0; $match_type = 'and'; $sort_data = array(); foreach ($keywords_array as $cur_word) { switch ($cur_word) { case 'and': case 'or': case 'not': $match_type = $cur_word; break; default: if ($this->search->is_cjk($cur_word)) { $where_cond = str_replace('*', '%', $cur_word); $where_cond_cjk = $search_in ? $search_in > 0 ? 'p.message LIKE %:where_cond%' : 't.subject LIKE %:where_cond%' : 'p.message LIKE %:where_cond% OR t.subject LIKE %:where_cond%'; $result = DB::for_table('posts')->raw_query('SELECT p.id AS post_id, p.topic_id, ' . $sort_by_sql . ' AS sort_by FROM ' . $this->feather->forum_settings['db_prefix'] . 'posts AS p INNER JOIN ' . $this->feather->forum_settings['db_prefix'] . 'topics AS t ON t.id=p.topic_id LEFT JOIN ' . $this->feather->forum_settings['db_prefix'] . 'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id=' . $this->user->g_id . ') WHERE (' . $where_cond_cjk . ') AND (fp.read_forum IS NULL OR fp.read_forum=1)' . $forum_sql, array(':where_cond' => $where_cond)); } else { $result = DB::for_table('posts')->raw_query('SELECT m.post_id, p.topic_id, ' . $sort_by_sql . ' AS sort_by FROM ' . $this->feather->forum_settings['db_prefix'] . 'search_words AS w INNER JOIN ' . $this->feather->forum_settings['db_prefix'] . 'search_matches AS m ON m.word_id = w.id INNER JOIN ' . $this->feather->forum_settings['db_prefix'] . 'posts AS p ON p.id=m.post_id INNER JOIN ' . $this->feather->forum_settings['db_prefix'] . 'topics AS t ON t.id=p.topic_id LEFT JOIN ' . $this->feather->forum_settings['db_prefix'] . 'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id=' . $this->user->g_id . ') WHERE w.word LIKE :where_cond' . $search_in_cond . ' AND (fp.read_forum IS NULL OR fp.read_forum=1)' . $forum_sql, array(':where_cond' => str_replace('*', '%', $cur_word))); } $result = $this->hook->fireDB('get_search_results_search_first_query', $result); $result = $result->find_many(); $row = array(); foreach ($result as $temp) { $row[$temp['post_id']] = $temp['topic_id']; if (!$word_count) { $keyword_results[$temp['post_id']] = $temp['topic_id']; $sort_data[$temp['post_id']] = $temp['sort_by']; } elseif ($match_type == 'or') { $keyword_results[$temp['post_id']] = $temp['topic_id']; $sort_data[$temp['post_id']] = $temp['sort_by']; } elseif ($match_type == 'not') { unset($keyword_results[$temp['post_id']]); unset($sort_data[$temp['post_id']]); } } if ($match_type == 'and' && $word_count) { foreach ($keyword_results as $post_id => $topic_id) { if (!isset($row[$post_id])) { unset($keyword_results[$post_id]); unset($sort_data[$post_id]); } } } ++$word_count; $pdo = DB::get_db(); $pdo = null; break; } } $keyword_results = $this->hook->fire('get_search_results_search_keyword_results', $keyword_results); // Sort the results - annoyingly array_multisort re-indexes arrays with numeric keys, so we need to split the keys out into a separate array then combine them again after $post_ids = array_keys($keyword_results); $topic_ids = array_values($keyword_results); array_multisort(array_values($sort_data), $sort_dir == 'DESC' ? SORT_DESC : SORT_ASC, $sort_type, $post_ids, $topic_ids); // combine the arrays back into a key => value array $keyword_results = array_combine($post_ids, $topic_ids); unset($sort_data, $post_ids, $topic_ids); } // If it's a search for author name (and that author name isn't Guest) if ($author && $author != 'guest' && $author != utf8_strtolower(__('Guest'))) { $username_exists = DB::for_table('users')->select('id')->where_like('username', $author); $username_exists = $this->hook->fireDB('get_search_results_username_exists', $username_exists); $username_exists = $username_exists->find_many(); if ($username_exists) { $user_ids = array(); foreach ($username_exists as $row) { $user_ids[] = $row['id']; } $result = DB::for_table('posts')->raw_query('SELECT p.id AS post_id, p.topic_id FROM ' . $this->feather->forum_settings['db_prefix'] . 'posts AS p INNER JOIN ' . $this->feather->forum_settings['db_prefix'] . 'topics AS t ON t.id=p.topic_id LEFT JOIN ' . $this->feather->forum_settings['db_prefix'] . 'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id=' . $this->user->g_id . ') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND p.poster_id IN(' . implode(',', $user_ids) . ')' . $forum_sql . ' ORDER BY ' . $sort_by_sql . ' ' . $sort_dir); $result = $this->hook->fireDB('get_search_results_search_second_query', $result); $result = $result->find_many(); foreach ($result as $temp) { $author_results[$temp['post_id']] = $temp['topic_id']; } $pdo = DB::get_db(); $pdo = null; } } // If we searched for both keywords and author name we want the intersection between the results if ($author && $keywords) { $search_ids = array_intersect_assoc($keyword_results, $author_results); $search_type = array('both', array($keywords, Utils::trim($this->request->get('author'))), implode(',', $forums), $search_in); } elseif ($keywords) { $search_ids = $keyword_results; $search_type = array('keywords', $keywords, implode(',', $forums), $search_in); } else { $search_ids = $author_results; $search_type = array('author', Utils::trim($this->request->get('author')), implode(',', $forums), $search_in); } $search_ids = $this->hook->fire('get_search_results_search_ids', $search_ids); $search_type = $this->hook->fire('get_search_results_search_type', $search_type); unset($keyword_results, $author_results); if ($show_as == 'topics') { $search_ids = array_values($search_ids); } else { $search_ids = array_keys($search_ids); } $search_ids = array_unique($search_ids); $search_ids = $this->hook->fire('get_search_results_search_ids', $search_ids); $search_type = $this->hook->fire('get_search_results_search_type', $search_type); $num_hits = count($search_ids); if (!$num_hits) { throw new Error(__('No hits'), 400); } } elseif ($action == 'show_new' || $action == 'show_recent' || $action == 'show_replies' || $action == 'show_user_posts' || $action == 'show_user_topics' || $action == 'show_subscriptions' || $action == 'show_unanswered') { $search_type = array('action', $action); $show_as = 'topics'; // We want to sort things after last post $sort_by = 0; $sort_dir = 'DESC'; $result['where'] = array(array('fp.read_forum' => 'IS NULL'), array('fp.read_forum' => '1')); // If it's a search for new posts since last visit if ($action == 'show_new') { if ($this->user->is_guest) { throw new Error(__('No permission'), 403); } $result = DB::for_table('topics')->table_alias('t')->select('t.id')->left_outer_join('forum_perms', array('fp.forum_id', '=', 't.forum_id'), 'fp')->left_outer_join('forum_perms', array('fp.group_id', '=', $this->user->g_id), null, true)->where_any_is($result['where'])->where_gt('t.last_post', $this->user->last_visit)->where_null('t.moved_to')->order_by_desc('t.last_post'); if ($this->request->get('fid')) { $result = $result->where('t.forum_id', intval($this->request->get('fid'))); } $result = $this->hook->fire('get_search_results_topic_query', $result); $result = $result->find_many(); $num_hits = count($result); if (!$num_hits) { throw new Error(__('No new posts'), 204); } } elseif ($action == 'show_recent') { $result = DB::for_table('topics')->table_alias('t')->select('t.id')->left_outer_join('forum_perms', array('fp.forum_id', '=', 't.forum_id'), 'fp')->left_outer_join('forum_perms', array('fp.group_id', '=', $this->user->g_id), null, true)->where_any_is($result['where'])->where_gt('t.last_post', time() - $interval)->where_null('t.moved_to')->order_by_desc('t.last_post'); if ($this->request->get('fid')) { $result = $result->where('t.forum_id', intval($this->request->get('fid'))); } $result = $this->hook->fire('get_search_results_topic_query', $result); $result = $result->find_many(); $num_hits = count($result); if (!$num_hits) { throw new Error(__('No recent posts'), 204); } } elseif ($action == 'show_replies') { $result = DB::for_table('topics')->table_alias('t')->select('t.id')->inner_join('posts', array('t.id', '=', 'p.topic_id'), 'p')->left_outer_join('forum_perms', array('fp.forum_id', '=', 't.forum_id'), 'fp')->left_outer_join('forum_perms', array('fp.group_id', '=', $this->user->g_id), null, true)->where_any_is($result['where'])->where('p.poster_id', $this->user->id)->group_by('t.id'); if ($this->feather->forum_settings['db_type'] == 'pgsql') { $result = $result->group_by('t.last_post'); } $result = $this->hook->fire('get_search_results_topic_query', $result); $result = $result->find_many(); $num_hits = count($result); if (!$num_hits) { throw new Error(__('No user posts'), 204); } } elseif ($action == 'show_user_posts') { $show_as = 'posts'; $result = DB::for_table('posts')->table_alias('p')->select('p.id')->inner_join('topics', array('p.topic_id', '=', 't.id'), 't')->left_outer_join('forum_perms', array('fp.forum_id', '=', 't.forum_id'), 'fp')->left_outer_join('forum_perms', array('fp.group_id', '=', $this->user->g_id), null, true)->where_any_is($result['where'])->where('p.poster_id', $user_id)->order_by_desc('p.posted'); $result = $this->hook->fire('get_search_results_post_query', $result); $result = $result->find_many(); $num_hits = count($result); if (!$num_hits) { throw new Error(__('No user posts'), 404); } // Pass on the user ID so that we can later know whose posts we're searching for $search_type[2] = $user_id; } elseif ($action == 'show_user_topics') { $result = DB::for_table('topics')->table_alias('t')->select('t.id')->inner_join('posts', array('t.first_post_id', '=', 'p.id'), 'p')->left_outer_join('forum_perms', array('fp.forum_id', '=', 't.forum_id'), 'fp')->left_outer_join('forum_perms', array('fp.group_id', '=', $this->user->g_id), null, true)->where_any_is($result['where'])->where('p.poster_id', $user_id)->order_by_desc('t.last_post'); $result = $this->hook->fire('get_search_results_topic_query', $result); $result = $result->find_many(); $num_hits = count($result); if (!$num_hits) { throw new Error(__('No user topics'), 404); } // Pass on the user ID so that we can later know whose topics we're searching for $search_type[2] = $user_id; } elseif ($action == 'show_subscriptions') { if ($this->user->is_guest) { throw new Error(__('Bad request'), 404); } $result = DB::for_table('topics')->table_alias('t')->select('t.id')->inner_join('topic_subscriptions', array('t.id', '=', 's.topic_id'), 's')->inner_join('topic_subscriptions', array('s.user_id', '=', $user_id), null, true)->left_outer_join('forum_perms', array('fp.forum_id', '=', 't.forum_id'), 'fp')->left_outer_join('forum_perms', array('fp.group_id', '=', $this->user->g_id), null, true)->where_any_is($result['where'])->order_by_desc('t.last_post'); $result = $this->hook->fire('get_search_results_topic_query', $result); $result = $result->find_many(); $num_hits = count($result); if (!$num_hits) { throw new Error(__('No subscriptions'), 404); } // Pass on user ID so that we can later know whose subscriptions we're searching for $search_type[2] = $user_id; } else { $result = DB::for_table('topics')->table_alias('t')->select('t.id')->left_outer_join('forum_perms', array('fp.forum_id', '=', 't.forum_id'), 'fp')->left_outer_join('forum_perms', array('fp.group_id', '=', $this->user->g_id), null, true)->where('t.num_replies', 0)->where_null('t.moved_to')->where_any_is($result['where'])->order_by_desc('t.last_post'); $result = $this->hook->fire('get_search_results_topic_query', $result); $result = $result->find_many(); $num_hits = count($result); if (!$num_hits) { throw new Error(__('No unanswered'), 404); } } $search_ids = array(); foreach ($result as $row) { $search_ids[] = $row['id']; } $pdo = DB::get_db(); $pdo = null; } else { throw new Error(__('Bad request'), 404); } // Prune "old" search results $old_searches = array(); $result = DB::for_table('online')->select('ident'); $result = $this->hook->fireDB('get_search_results_prune_search', $result); $result = $result->find_many(); if ($result) { foreach ($result as $row) { $old_searches[] = $row['ident']; } $delete_cache = DB::for_table('search_cache')->where_not_in('ident', $old_searches); $delete_cache = $this->hook->fireDB('get_search_results_delete_cache', $delete_cache); $delete_cache = $delete_cache->delete_many(); } // Fill an array with our results and search properties $temp = serialize(array('search_ids' => serialize($search_ids), 'num_hits' => $num_hits, 'sort_by' => $sort_by, 'sort_dir' => $sort_dir, 'show_as' => $show_as, 'search_type' => $search_type)); $search_id = mt_rand(1, 2147483647); $ident = $this->user->is_guest ? $this->request->getIp() : $this->user->username; $cache['insert'] = array('id' => $search_id, 'ident' => $ident, 'search_data' => $temp); $cache = DB::for_table('search_cache')->create()->set($cache['insert']); $cache = $this->hook->fireDB('get_search_results_update_cache', $cache); $cache = $cache->save(); } // If we're on the new posts search, display a "mark all as read" link if (!$this->user->is_guest && $search_type[0] == 'action' && $search_type[1] == 'show_new') { $search['forum_actions'][] = '<a href="' . $this->feather->urlFor('markRead') . '">' . __('Mark all as read') . '</a>'; } // Fetch results to display if (!empty($search_ids)) { // We have results $search['is_result'] = true; switch ($sort_by) { case 1: $sort_by_sql = $show_as == 'topics' ? 't.poster' : 'p.poster'; break; case 2: $sort_by_sql = 't.subject'; break; case 3: $sort_by_sql = 't.forum_id'; break; default: $sort_by_sql = $show_as == 'topics' ? 't.last_post' : 'p.posted'; break; } // Determine the topic or post offset (based on $_GET['p']) $per_page = $show_as == 'posts' ? $this->user->disp_posts : $this->user->disp_topics; $num_pages = ceil($num_hits / $per_page); $p = !$this->request->get('p') || $this->request->get('p') <= 1 || $this->request->get('p') > $num_pages ? 1 : intval($this->request->get('p')); $start_from = $per_page * ($p - 1); $search['start_from'] = $start_from; // Generate paging links $search['paging_links'] = '<span class="pages-label">' . __('Pages') . ' </span>' . Url::paginate_old($num_pages, $p, '?search_id=' . $search_id); // throw away the first $start_from of $search_ids, only keep the top $per_page of $search_ids $search_ids = array_slice($search_ids, $start_from, $per_page); // Run the query and fetch the results if ($show_as == 'posts') { $result['select'] = array('pid' => 'p.id', 'pposter' => 'p.poster', 'pposted' => 'p.posted', 'p.poster_id', 'p.message', 'p.hide_smilies', 'tid' => 't.id', 't.poster', 't.subject', 't.first_post_id', 't.last_post', 't.last_post_id', 't.last_poster', 't.num_replies', 't.forum_id', 'f.forum_name'); $result = DB::for_table('posts')->table_alias('p')->select_many($result['select'])->inner_join('topics', array('t.id', '=', 'p.topic_id'), 't')->inner_join('forums', array('f.id', '=', 't.forum_id'), 'f')->where_in('p.id', $search_ids)->order_by($sort_by_sql, $sort_dir); $result = $this->hook->fireDB('get_search_results_select_posts_query', $result); } else { $result['select'] = array('tid' => 't.id', 't.poster', 't.subject', 't.last_post', 't.last_post_id', 't.last_poster', 't.num_replies', 't.closed', 't.sticky', 't.forum_id', 'f.forum_name'); $result = DB::for_table('topics')->table_alias('t')->select_many($result['select'])->inner_join('forums', array('f.id', '=', 't.forum_id'), 'f')->where_in('t.id', $search_ids)->order_by($sort_by_sql, $sort_dir); $result = $this->hook->fireDB('get_search_results_select_topics_query', $result); } $result = $result->find_many(); $search['search_set'] = array(); foreach ($result as $row) { $search['search_set'][] = $row; } $search['crumbs_text']['show_as'] = __('Search'); if ($search_type[0] == 'action') { if ($search_type[1] == 'show_user_topics') { $search['crumbs_text']['search_type'] = '<a href="' . $this->feather->urlFor('search') . '?action=show_user_topics&user_id=' . $search_type[2] . '">' . sprintf(__('Quick search show_user_topics'), Utils::escape($search['search_set'][0]['poster'])) . '</a>'; } elseif ($search_type[1] == 'show_user_posts') { $search['crumbs_text']['search_type'] = '<a href="' . $this->feather->urlFor('search') . '?action=show_user_posts&user_id=' . $search_type[2] . '">' . sprintf(__('Quick search show_user_posts'), Utils::escape($search['search_set'][0]['pposter'])) . '</a>'; } elseif ($search_type[1] == 'show_subscriptions') { // Fetch username of subscriber $subscriber_id = $search_type[2]; $subscriber_name = DB::for_table('users')->where('id', $subscriber_id); $subscriber_name = $this->hook->fireDB('get_search_results_subscriber_name', $result); $subscriber_name = $subscriber_name->find_one_col('username'); if (!$subscriber_name) { throw new Error(__('Bad request'), 404); } $search['crumbs_text']['search_type'] = '<a href="' . $this->feather->urlFor('search') . '?action=show_subscription&user_id=' . $subscriber_id . '">' . sprintf(__('Quick search show_subscriptions'), Utils::escape($subscriber_name)) . '</a>'; } else { $search_url = str_replace('_', '/', $search_type[1]); $search['crumbs_text']['search_type'] = '<a href="' . $this->feather->urlFor('search') . $search_url . '">' . __('Quick search ' . $search_type[1]) . '</a>'; } } else { $keywords = $author = ''; if ($search_type[0] == 'both') { list($keywords, $author) = $search_type[1]; $search['crumbs_text']['search_type'] = sprintf(__('By both show as ' . $show_as), Utils::escape($keywords), Utils::escape($author)); } elseif ($search_type[0] == 'keywords') { $keywords = $search_type[1]; $search['crumbs_text']['search_type'] = sprintf(__('By keywords show as ' . $show_as), Utils::escape($keywords)); } elseif ($search_type[0] == 'author') { $author = $search_type[1]; $search['crumbs_text']['search_type'] = sprintf(__('By user show as ' . $show_as), Utils::escape($author)); } $search['crumbs_text']['search_type'] = '<a href="' . $this->feather->urlFor('search') . '?action=search&keywords=' . urlencode($keywords) . '&author=' . urlencode($author) . '&forums=' . $search_type[2] . '&search_in=' . $search_type[3] . '&sort_by=' . $sort_by . '&sort_dir=' . $sort_dir . '&show_as=' . $show_as . '">' . $search['crumbs_text']['search_type'] . '</a>'; } } $search['show_as'] = $show_as; $search = $this->hook->fire('get_search_results', $search); return $search; }
public function showusers($ip) { if (!@preg_match('%^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$%', $ip) && !@preg_match('%^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b)\\.){3}(\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b)\\.){3}(\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b)\\.){3}(\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$%', $ip)) { throw new Error(__('Bad IP message'), 400); } // Fetch user count $num_users = $this->model->get_num_users_ip($ip); // Determine the user offset (based on $_GET['p']) $num_pages = ceil($num_users / 50); $p = !$this->request->get('p') || $this->request->get('p') <= 1 || $this->request->get('p') > $num_pages ? 1 : intval($this->request->get('p')); $start_from = 50 * ($p - 1); $this->feather->template->setPageInfo(array('title' => array(Utils::escape($this->config['o_board_title']), __('Admin'), __('Users'), __('Results head')), 'active_page' => 'admin', 'admin_console' => true, 'paging_links' => '<span class="pages-label">' . __('Pages') . ' </span>' . Url::paginate_old($num_pages, $p, '?ip_stats=' . $ip), 'page' => $p, 'start_from' => $start_from, 'info' => $this->model->get_info_poster($ip, $start_from)))->addTemplate('admin/users/show_users.php')->display(); }