|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
*
|
|
|
f2e824 |
* @package phpBB3
|
|
|
f2e824 |
* @version $Id: search.php 9040 2008-11-01 19:00:50Z naderman $
|
|
|
f2e824 |
* @copyright (c) 2005 phpBB Group
|
|
|
f2e824 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
f2e824 |
*
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
|
|
|
f2e824 |
/**
|
|
|
f2e824 |
* @ignore
|
|
|
f2e824 |
*/
|
|
|
f2e824 |
define('IN_PHPBB', true);
|
|
|
f2e824 |
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
|
|
|
f2e824 |
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
|
|
f2e824 |
include($phpbb_root_path . 'common.' . $phpEx);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Start session management
|
|
|
f2e824 |
$user->session_begin();
|
|
|
f2e824 |
$auth->acl($user->data);
|
|
|
f2e824 |
$user->setup('search');
|
|
|
f2e824 |
|
|
|
f2e824 |
// Define initial vars
|
|
|
f2e824 |
$mode = request_var('mode', '');
|
|
|
f2e824 |
$search_id = request_var('search_id', '');
|
|
|
f2e824 |
$start = max(request_var('start', 0), 0);
|
|
|
f2e824 |
$post_id = request_var('p', 0);
|
|
|
f2e824 |
$topic_id = request_var('t', 0);
|
|
|
f2e824 |
$view = request_var('view', '');
|
|
|
f2e824 |
|
|
|
f2e824 |
$submit = request_var('submit', false);
|
|
|
f2e824 |
$keywords = utf8_normalize_nfc(request_var('keywords', '', true));
|
|
|
f2e824 |
$add_keywords = utf8_normalize_nfc(request_var('add_keywords', '', true));
|
|
|
f2e824 |
$author = request_var('author', '', true);
|
|
|
f2e824 |
$author_id = request_var('author_id', 0);
|
|
|
f2e824 |
$show_results = ($topic_id) ? 'posts' : request_var('sr', 'posts');
|
|
|
f2e824 |
$show_results = ($show_results == 'posts') ? 'posts' : 'topics';
|
|
|
f2e824 |
$search_terms = request_var('terms', 'all');
|
|
|
f2e824 |
$search_fields = request_var('sf', 'all');
|
|
|
f2e824 |
$search_child = request_var('sc', true);
|
|
|
f2e824 |
|
|
|
f2e824 |
$sort_days = request_var('st', 0);
|
|
|
f2e824 |
$sort_key = request_var('sk', 't');
|
|
|
f2e824 |
$sort_dir = request_var('sd', 'd');
|
|
|
f2e824 |
|
|
|
f2e824 |
$return_chars = request_var('ch', ($topic_id) ? -1 : 300);
|
|
|
f2e824 |
$search_forum = request_var('fid', array(0));
|
|
|
f2e824 |
|
|
|
f2e824 |
// Is user able to search? Has search been disabled?
|
|
|
f2e824 |
if (!$auth->acl_get('u_search') || !$auth->acl_getf_global('f_search') || !$config['load_search'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$template->assign_var('S_NO_SEARCH', true);
|
|
|
f2e824 |
trigger_error('NO_SEARCH');
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Check search load limit
|
|
|
f2e824 |
if ($user->load && $config['limit_search_load'] && ($user->load > doubleval($config['limit_search_load'])))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$template->assign_var('S_NO_SEARCH', true);
|
|
|
f2e824 |
trigger_error('NO_SEARCH_TIME');
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Check flood limit ... if applicable
|
|
|
f2e824 |
$interval = ($user->data['user_id'] == ANONYMOUS) ? $config['search_anonymous_interval'] : $config['search_interval'];
|
|
|
f2e824 |
if ($interval && !$auth->acl_get('u_ignoreflood'))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($user->data['user_last_search'] > time() - $interval)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$template->assign_var('S_NO_SEARCH', true);
|
|
|
f2e824 |
trigger_error('NO_SEARCH_TIME');
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Define some vars
|
|
|
f2e824 |
$limit_days = array(0 => $user->lang['ALL_RESULTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
|
|
|
f2e824 |
$sort_by_text = array('a' => $user->lang['SORT_AUTHOR'], 't' => $user->lang['SORT_TIME'], 'f' => $user->lang['SORT_FORUM'], 'i' => $user->lang['SORT_TOPIC_TITLE'], 's' => $user->lang['SORT_POST_SUBJECT']);
|
|
|
f2e824 |
|
|
|
f2e824 |
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
|
|
|
f2e824 |
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($keywords || $author || $author_id || $search_id || $submit)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// clear arrays
|
|
|
f2e824 |
$id_ary = array();
|
|
|
f2e824 |
|
|
|
f2e824 |
// egosearch is an author search
|
|
|
f2e824 |
if ($search_id == 'egosearch')
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$author_id = $user->data['user_id'];
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($user->data['user_id'] == ANONYMOUS)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
login_box('', $user->lang['LOGIN_EXPLAIN_EGOSEARCH']);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// If we are looking for authors get their ids
|
|
|
f2e824 |
$author_id_ary = array();
|
|
|
f2e824 |
if ($author_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$author_id_ary[] = $author_id;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else if ($author)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ((strpos($author, '*') !== false) && (utf8_strlen(str_replace(array('*', '%'), '', $author)) < $config['min_search_author_chars']))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
trigger_error(sprintf($user->lang['TOO_FEW_AUTHOR_CHARS'], $config['min_search_author_chars']));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql_where = (strpos($author, '*') !== false) ? ' username_clean ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($author))) : " username_clean = '" . $db->sql_escape(utf8_clean_string($author)) . "'";
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = 'SELECT user_id
|
|
|
f2e824 |
FROM ' . USERS_TABLE . "
|
|
|
f2e824 |
WHERE $sql_where
|
|
|
f2e824 |
AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
|
|
|
f2e824 |
$result = $db->sql_query_limit($sql, 100);
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$author_id_ary[] = (int) $row['user_id'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!sizeof($author_id_ary))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
trigger_error('NO_SEARCH_RESULTS');
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// if we search in an existing search result just add the additional keywords. But we need to use "all search terms"-mode
|
|
|
f2e824 |
// so we can keep the old keywords in their old mode, but add the new ones as required words
|
|
|
f2e824 |
if ($add_keywords)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($search_terms == 'all')
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$keywords .= ' ' . $add_keywords;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$search_terms = 'all';
|
|
|
f2e824 |
$keywords = implode(' |', explode(' ', preg_replace('#\s+#u', ' ', $keywords))) . ' ' .$add_keywords;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Which forums should not be searched? Author searches are also carried out in unindexed forums
|
|
|
f2e824 |
if (empty($keywords) && sizeof($author_id_ary))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$ex_fid_ary = array_keys($auth->acl_getf('!f_read', true));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$ex_fid_ary = array_unique(array_merge(array_keys($auth->acl_getf('!f_read', true)), array_keys($auth->acl_getf('!f_search', true))));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$not_in_fid = (sizeof($ex_fid_ary)) ? 'WHERE ' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . " OR (f.forum_password <> '' AND fa.user_id <> " . (int) $user->data['user_id'] . ')' : "";
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.right_id, f.forum_password, fa.user_id
|
|
|
f2e824 |
FROM ' . FORUMS_TABLE . ' f
|
|
|
f2e824 |
LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id
|
|
|
f2e824 |
AND fa.session_id = '" . $db->sql_escape($user->session_id) . "')
|
|
|
f2e824 |
$not_in_fid
|
|
|
f2e824 |
ORDER BY f.left_id";
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
$right_id = 0;
|
|
|
f2e824 |
$reset_search_forum = true;
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$ex_fid_ary[] = (int) $row['forum_id'];
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if (sizeof($search_forum))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($search_child)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if (in_array($row['forum_id'], $search_forum) && $row['right_id'] > $right_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$right_id = (int) $row['right_id'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else if ($row['right_id'] < $right_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!in_array($row['forum_id'], $search_forum))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$ex_fid_ary[] = (int) $row['forum_id'];
|
|
|
f2e824 |
$reset_search_forum = false;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
// find out in which forums the user is allowed to view approved posts
|
|
|
f2e824 |
if ($auth->acl_get('m_approve'))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$m_approve_fid_ary = array(-1);
|
|
|
f2e824 |
$m_approve_fid_sql = '';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else if ($auth->acl_getf_global('m_approve'))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$m_approve_fid_ary = array_diff(array_keys($auth->acl_getf('!m_approve', true)), $ex_fid_ary);
|
|
|
f2e824 |
$m_approve_fid_sql = ' AND (p.post_approved = 1' . ((sizeof($m_approve_fid_ary)) ? ' OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) : '') . ')';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$m_approve_fid_ary = array();
|
|
|
f2e824 |
$m_approve_fid_sql = ' AND p.post_approved = 1';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($reset_search_forum)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$search_forum = array();
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Select which method we'll use to obtain the post_id or topic_id information
|
|
|
f2e824 |
$search_type = basename($config['search_type']);
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
trigger_error('NO_SUCH_SEARCH_MODULE');
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
require("{$phpbb_root_path}includes/search/$search_type.$phpEx");
|
|
|
f2e824 |
|
|
|
f2e824 |
// We do some additional checks in the module to ensure it can actually be utilised
|
|
|
f2e824 |
$error = false;
|
|
|
f2e824 |
$search = new $search_type($error);
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($error)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
trigger_error($error);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// let the search module split up the keywords
|
|
|
f2e824 |
if ($keywords)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$correct_query = $search->split_keywords($keywords, $search_terms);
|
|
|
f2e824 |
if (!$correct_query || (empty($search->search_query) && !sizeof($author_id_ary) && !$search_id))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$ignored = (sizeof($search->common_words)) ? sprintf($user->lang['IGNORED_TERMS_EXPLAIN'], implode(' ', $search->common_words)) . ' ' : '';
|
|
|
f2e824 |
trigger_error($ignored . sprintf($user->lang['NO_KEYWORDS'], $search->word_length['min'], $search->word_length['max']));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!$keywords && sizeof($author_id_ary))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// if it is an author search we want to show topics by default
|
|
|
f2e824 |
$show_results = ($topic_id) ? 'posts' : request_var('sr', ($search_id == 'egosearch') ? 'topics' : 'posts');
|
|
|
f2e824 |
$show_results = ($show_results == 'posts') ? 'posts' : 'topics';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// define some variables needed for retrieving post_id/topic_id information
|
|
|
f2e824 |
$sort_by_sql = array('a' => 'u.username_clean', 't' => (($show_results == 'posts') ? 'p.post_time' : 't.topic_last_post_time'), 'f' => 'f.forum_id', 'i' => 't.topic_title', 's' => (($show_results == 'posts') ? 'p.post_subject' : 't.topic_title'));
|
|
|
f2e824 |
|
|
|
f2e824 |
// pre-made searches
|
|
|
f2e824 |
$sql = $field = $l_search_title = '';
|
|
|
f2e824 |
if ($search_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
switch ($search_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// Oh holy Bob, bring us some activity...
|
|
|
f2e824 |
case 'active_topics':
|
|
|
f2e824 |
$l_search_title = $user->lang['SEARCH_ACTIVE_TOPICS'];
|
|
|
f2e824 |
$show_results = 'topics';
|
|
|
f2e824 |
$sort_key = 't';
|
|
|
f2e824 |
$sort_dir = 'd';
|
|
|
f2e824 |
$sort_days = request_var('st', 7);
|
|
|
f2e824 |
$sort_by_sql['t'] = 't.topic_last_post_time';
|
|
|
f2e824 |
|
|
|
f2e824 |
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
|
|
|
f2e824 |
$s_sort_key = $s_sort_dir = '';
|
|
|
f2e824 |
|
|
|
f2e824 |
$last_post_time_sql = ($sort_days) ? ' AND t.topic_last_post_time > ' . (time() - ($sort_days * 24 * 3600)) : '';
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = 'SELECT t.topic_last_post_time, t.topic_id
|
|
|
f2e824 |
FROM ' . TOPICS_TABLE . " t
|
|
|
f2e824 |
WHERE t.topic_moved_id = 0
|
|
|
f2e824 |
$last_post_time_sql
|
|
|
f2e824 |
" . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
|
|
|
f2e824 |
' . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . '
|
|
|
f2e824 |
ORDER BY t.topic_last_post_time DESC';
|
|
|
f2e824 |
$field = 'topic_id';
|
|
|
f2e824 |
break;
|
|
|
f2e824 |
|
|
|
f2e824 |
case 'unanswered':
|
|
|
f2e824 |
$l_search_title = $user->lang['SEARCH_UNANSWERED'];
|
|
|
f2e824 |
$show_results = request_var('sr', 'topics');
|
|
|
f2e824 |
$show_results = ($show_results == 'posts') ? 'posts' : 'topics';
|
|
|
f2e824 |
$sort_by_sql['t'] = ($show_results == 'posts') ? 'p.post_time' : 't.topic_last_post_time';
|
|
|
f2e824 |
$sort_by_sql['s'] = ($show_results == 'posts') ? 'p.post_subject' : 't.topic_title';
|
|
|
f2e824 |
$sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC');
|
|
|
f2e824 |
|
|
|
f2e824 |
$sort_join = ($sort_key == 'f') ? FORUMS_TABLE . ' f, ' : '';
|
|
|
f2e824 |
$sql_sort = ($sort_key == 'f') ? ' AND f.forum_id = p.forum_id ' . $sql_sort : $sql_sort;
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($sort_days)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$last_post_time = 'AND p.post_time > ' . (time() - ($sort_days * 24 * 3600));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$last_post_time = '';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($sort_key == 'a')
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sort_join = USERS_TABLE . ' u, ';
|
|
|
f2e824 |
$sql_sort = ' AND u.user_id = p.poster_id ' . $sql_sort;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
if ($show_results == 'posts')
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = "SELECT p.post_id
|
|
|
f2e824 |
FROM $sort_join" . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
|
|
|
f2e824 |
WHERE t.topic_replies = 0
|
|
|
f2e824 |
AND p.topic_id = t.topic_id
|
|
|
f2e824 |
$last_post_time
|
|
|
f2e824 |
$m_approve_fid_sql
|
|
|
f2e824 |
" . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . "
|
|
|
f2e824 |
$sql_sort";
|
|
|
f2e824 |
$field = 'post_id';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT DISTINCT ' . $sort_by_sql[$sort_key] . ", p.topic_id
|
|
|
f2e824 |
FROM $sort_join" . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
|
|
|
f2e824 |
WHERE t.topic_replies = 0
|
|
|
f2e824 |
AND t.topic_moved_id = 0
|
|
|
f2e824 |
AND p.topic_id = t.topic_id
|
|
|
f2e824 |
$last_post_time
|
|
|
f2e824 |
$m_approve_fid_sql
|
|
|
f2e824 |
" . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . "
|
|
|
f2e824 |
$sql_sort";
|
|
|
f2e824 |
$field = 'topic_id';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
break;
|
|
|
f2e824 |
|
|
|
f2e824 |
case 'newposts':
|
|
|
f2e824 |
$l_search_title = $user->lang['SEARCH_NEW'];
|
|
|
f2e824 |
// force sorting
|
|
|
f2e824 |
$show_results = (request_var('sr', 'topics') == 'posts') ? 'posts' : 'topics';
|
|
|
f2e824 |
$sort_key = 't';
|
|
|
f2e824 |
$sort_dir = 'd';
|
|
|
f2e824 |
$sort_by_sql['t'] = ($show_results == 'posts') ? 'p.post_time' : 't.topic_last_post_time';
|
|
|
f2e824 |
$sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC');
|
|
|
f2e824 |
|
|
|
f2e824 |
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
|
|
|
f2e824 |
$s_sort_key = $s_sort_dir = $u_sort_param = $s_limit_days = '';
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($show_results == 'posts')
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT p.post_id
|
|
|
f2e824 |
FROM ' . POSTS_TABLE . ' p
|
|
|
f2e824 |
WHERE p.post_time > ' . $user->data['user_lastvisit'] . "
|
|
|
f2e824 |
$m_approve_fid_sql
|
|
|
f2e824 |
" . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . "
|
|
|
f2e824 |
$sql_sort";
|
|
|
f2e824 |
$field = 'post_id';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT t.topic_id
|
|
|
f2e824 |
FROM ' . TOPICS_TABLE . ' t
|
|
|
f2e824 |
WHERE t.topic_last_post_time > ' . $user->data['user_lastvisit'] . '
|
|
|
f2e824 |
AND t.topic_moved_id = 0
|
|
|
f2e824 |
' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
|
|
|
f2e824 |
' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . "
|
|
|
f2e824 |
$sql_sort";
|
|
|
f2e824 |
$field = 'topic_id';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
break;
|
|
|
f2e824 |
|
|
|
f2e824 |
case 'egosearch':
|
|
|
f2e824 |
$l_search_title = $user->lang['SEARCH_SELF'];
|
|
|
f2e824 |
break;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// show_results should not change after this
|
|
|
f2e824 |
$per_page = ($show_results == 'posts') ? $config['posts_per_page'] : $config['topics_per_page'];
|
|
|
f2e824 |
$total_match_count = 0;
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($search_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($sql)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// only return up to 1000 ids (the last one will be removed later)
|
|
|
f2e824 |
$result = $db->sql_query_limit($sql, 1001 - $start, $start);
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$id_ary[] = $row[$field];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
$total_match_count = sizeof($id_ary) + $start;
|
|
|
f2e824 |
$id_ary = array_slice($id_ary, 0, $per_page);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$search_id = '';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// make sure that some arrays are always in the same order
|
|
|
f2e824 |
sort($ex_fid_ary);
|
|
|
f2e824 |
sort($m_approve_fid_ary);
|
|
|
f2e824 |
sort($author_id_ary);
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!empty($search->search_query))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $id_ary, $start, $per_page);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else if (sizeof($author_id_ary))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$firstpost_only = ($search_fields === 'firstpost' || $search_fields == 'titleonly') ? true : false;
|
|
|
f2e824 |
$total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $id_ary, $start, $per_page);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options.
|
|
|
f2e824 |
if (!sizeof($id_ary) && !$search_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
trigger_error('NO_SEARCH_RESULTS');
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql_where = '';
|
|
|
f2e824 |
|
|
|
f2e824 |
if (sizeof($id_ary))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql_where .= $db->sql_in_set(($show_results == 'posts') ? 'p.post_id' : 't.topic_id', $id_ary);
|
|
|
f2e824 |
$sql_where .= (sizeof($ex_fid_ary)) ? ' AND (' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . ' OR f.forum_id IS NULL)' : '';
|
|
|
f2e824 |
$sql_where .= ($show_results == 'posts') ? $m_approve_fid_sql : str_replace(array('p.post_approved', 'p.forum_id'), array('t.topic_approved', 't.forum_id'), $m_approve_fid_sql);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($show_results == 'posts')
|
|
|
f2e824 |
{
|
|
|
f2e824 |
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$user->add_lang('viewtopic');
|
|
|
f2e824 |
|
|
|
f2e824 |
// Grab icons
|
|
|
f2e824 |
$icons = $cache->obtain_icons();
|
|
|
f2e824 |
|
|
|
f2e824 |
// Output header
|
|
|
f2e824 |
if ($search_id && ($total_match_count > 1000))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// limit the number to 1000 for pre-made searches
|
|
|
f2e824 |
$total_match_count--;
|
|
|
f2e824 |
$l_search_matches = sprintf($user->lang['FOUND_MORE_SEARCH_MATCHES'], $total_match_count);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$l_search_matches = ($total_match_count == 1) ? sprintf($user->lang['FOUND_SEARCH_MATCH'], $total_match_count) : sprintf($user->lang['FOUND_SEARCH_MATCHES'], $total_match_count);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// define some vars for urls
|
|
|
f2e824 |
$hilit = implode('|', explode(' ', preg_replace('#\s+#u', ' ', str_replace(array('+', '-', '|', '(', ')', '"'), ' ', $keywords))));
|
|
|
f2e824 |
// Do not allow *only* wildcard being used for hilight
|
|
|
f2e824 |
$hilit = (strspn($hilit, '*') === strlen($hilit)) ? '' : $hilit;
|
|
|
f2e824 |
|
|
|
f2e824 |
$u_hilit = urlencode(htmlspecialchars_decode(str_replace('|', ' ', $hilit)));
|
|
|
f2e824 |
$u_show_results = ($show_results != 'posts') ? '&sr=' . $show_results : '';
|
|
|
f2e824 |
$u_search_forum = implode('&fid%5B%5D=', $search_forum);
|
|
|
f2e824 |
|
|
|
f2e824 |
$u_search = append_sid("{$phpbb_root_path}search.$phpEx", $u_sort_param . $u_show_results);
|
|
|
f2e824 |
$u_search .= ($search_id) ? '&search_id=' . $search_id : '';
|
|
|
f2e824 |
$u_search .= ($u_hilit) ? '&keywords=' . urlencode(htmlspecialchars_decode($search->search_query)) : '';
|
|
|
f2e824 |
$u_search .= ($search_terms != 'all') ? '&terms=' . $search_terms : '';
|
|
|
f2e824 |
$u_search .= ($topic_id) ? '&t=' . $topic_id : '';
|
|
|
f2e824 |
$u_search .= ($author) ? '&author=' . urlencode(htmlspecialchars_decode($author)) : '';
|
|
|
f2e824 |
$u_search .= ($author_id) ? '&author_id=' . $author_id : '';
|
|
|
f2e824 |
$u_search .= ($u_search_forum) ? '&fid%5B%5D=' . $u_search_forum : '';
|
|
|
f2e824 |
$u_search .= (!$search_child) ? '&sc=0' : '';
|
|
|
f2e824 |
$u_search .= ($search_fields != 'all') ? '&sf=' . $search_fields : '';
|
|
|
f2e824 |
$u_search .= ($return_chars != 300) ? '&ch=' . $return_chars : '';
|
|
|
f2e824 |
|
|
|
f2e824 |
$template->assign_vars(array(
|
|
|
f2e824 |
'SEARCH_TITLE' => $l_search_title,
|
|
|
f2e824 |
'SEARCH_MATCHES' => $l_search_matches,
|
|
|
f2e824 |
'SEARCH_WORDS' => $search->search_query,
|
|
|
f2e824 |
'IGNORED_WORDS' => (sizeof($search->common_words)) ? implode(' ', $search->common_words) : '',
|
|
|
f2e824 |
'PAGINATION' => generate_pagination($u_search, $total_match_count, $per_page, $start),
|
|
|
f2e824 |
'PAGE_NUMBER' => on_page($total_match_count, $per_page, $start),
|
|
|
f2e824 |
'TOTAL_MATCHES' => $total_match_count,
|
|
|
f2e824 |
'SEARCH_IN_RESULTS' => ($search_id) ? false : true,
|
|
|
f2e824 |
|
|
|
f2e824 |
'S_SELECT_SORT_DIR' => $s_sort_dir,
|
|
|
f2e824 |
'S_SELECT_SORT_KEY' => $s_sort_key,
|
|
|
f2e824 |
'S_SELECT_SORT_DAYS' => $s_limit_days,
|
|
|
f2e824 |
'S_SEARCH_ACTION' => $u_search,
|
|
|
f2e824 |
'S_SHOW_TOPICS' => ($show_results == 'posts') ? false : true,
|
|
|
f2e824 |
|
|
|
f2e824 |
'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'),
|
|
|
f2e824 |
'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
|
|
|
f2e824 |
'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
|
|
|
f2e824 |
'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
|
|
|
f2e824 |
'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
|
|
|
f2e824 |
|
|
|
f2e824 |
'U_SEARCH_WORDS' => $u_search,
|
|
|
f2e824 |
));
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($sql_where)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($show_results == 'posts')
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// @todo Joining this query to the one below?
|
|
|
f2e824 |
$sql = 'SELECT zebra_id, friend, foe
|
|
|
f2e824 |
FROM ' . ZEBRA_TABLE . '
|
|
|
f2e824 |
WHERE user_id = ' . $user->data['user_id'];
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
$zebra = array();
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$zebra[($row['friend']) ? 'friend' : 'foe'][] = $row['zebra_id'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = 'SELECT p.*, f.forum_id, f.forum_name, t.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_colour
|
|
|
f2e824 |
FROM ' . POSTS_TABLE . ' p
|
|
|
f2e824 |
LEFT JOIN ' . TOPICS_TABLE . ' t ON (p.topic_id = t.topic_id)
|
|
|
f2e824 |
LEFT JOIN ' . FORUMS_TABLE . ' f ON (p.forum_id = f.forum_id)
|
|
|
f2e824 |
LEFT JOIN ' . USERS_TABLE . " u ON (p.poster_id = u.user_id)
|
|
|
f2e824 |
WHERE $sql_where";
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql_from = TOPICS_TABLE . ' t
|
|
|
f2e824 |
LEFT JOIN ' . FORUMS_TABLE . ' f ON (f.forum_id = t.forum_id)
|
|
|
f2e824 |
' . (($sort_key == 'a') ? ' LEFT JOIN ' . USERS_TABLE . ' u ON (u.user_id = t.topic_poster) ' : '');
|
|
|
f2e824 |
$sql_select = 't.*, f.forum_id, f.forum_name';
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($user->data['is_registered'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($config['load_db_track'] && $author_id !== $user->data['user_id'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.user_id = ' . $user->data['user_id'] . '
|
|
|
f2e824 |
AND t.topic_id = tp.topic_id)';
|
|
|
f2e824 |
$sql_select .= ', tp.topic_posted';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($config['load_db_lastread'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $user->data['user_id'] . '
|
|
|
f2e824 |
AND t.topic_id = tt.topic_id)
|
|
|
f2e824 |
LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
|
|
|
f2e824 |
AND ft.forum_id = f.forum_id)';
|
|
|
f2e824 |
$sql_select .= ', tt.mark_time, ft.mark_time as f_mark_time';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($config['load_anon_lastread'] || ($user->data['is_registered'] && !$config['load_db_lastread']))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
|
|
|
f2e824 |
$tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$sql = "SELECT $sql_select
|
|
|
f2e824 |
FROM $sql_from
|
|
|
f2e824 |
WHERE $sql_where";
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$sql .= ' ORDER BY ' . $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
$result_topic_id = 0;
|
|
|
f2e824 |
|
|
|
f2e824 |
$rowset = array();
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($show_results == 'topics')
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$forums = $rowset = $shadow_topic_list = array();
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($row['topic_status'] == ITEM_MOVED)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$rowset[$row['topic_id']] = $row;
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!isset($forums[$row['forum_id']]) && $user->data['is_registered'] && $config['load_db_lastread'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$forums[$row['forum_id']]['mark_time'] = $row['f_mark_time'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$forums[$row['forum_id']]['topic_list'][] = $row['topic_id'];
|
|
|
f2e824 |
$forums[$row['forum_id']]['rowset'][$row['topic_id']] = &$rowset[$row['topic_id']];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
// If we have some shadow topics, update the rowset to reflect their topic information
|
|
|
f2e824 |
if (sizeof($shadow_topic_list))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT *
|
|
|
f2e824 |
FROM ' . TOPICS_TABLE . '
|
|
|
f2e824 |
WHERE ' . $db->sql_in_set('topic_id', array_keys($shadow_topic_list));
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$orig_topic_id = $shadow_topic_list[$row['topic_id']];
|
|
|
f2e824 |
|
|
|
f2e824 |
// We want to retain some values
|
|
|
f2e824 |
$row = array_merge($row, array(
|
|
|
f2e824 |
'topic_moved_id' => $rowset[$orig_topic_id]['topic_moved_id'],
|
|
|
f2e824 |
'topic_status' => $rowset[$orig_topic_id]['topic_status'],
|
|
|
f2e824 |
'forum_name' => $rowset[$orig_topic_id]['forum_name'])
|
|
|
f2e824 |
);
|
|
|
f2e824 |
|
|
|
f2e824 |
$rowset[$orig_topic_id] = $row;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
unset($shadow_topic_list);
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($forums as $forum_id => $forum)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($user->data['is_registered'] && $config['load_db_lastread'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$topic_tracking_info[$forum_id] = get_topic_tracking($forum_id, $forum['topic_list'], $forum['rowset'], array($forum_id => $forum['mark_time']), ($forum_id) ? false : $forum['topic_list']);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $forum['topic_list'], ($forum_id) ? false : $forum['topic_list']);
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!$user->data['is_registered'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
unset($forums);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$bbcode_bitfield = $text_only_message = '';
|
|
|
f2e824 |
$attach_list = array();
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// We pre-process some variables here for later usage
|
|
|
f2e824 |
$row['post_text'] = censor_text($row['post_text']);
|
|
|
f2e824 |
|
|
|
f2e824 |
$text_only_message = $row['post_text'];
|
|
|
f2e824 |
// make list items visible as such
|
|
|
f2e824 |
if ($row['bbcode_uid'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$text_only_message = str_replace('[*:' . $row['bbcode_uid'] . ']', '⋅ ', $text_only_message);
|
|
|
f2e824 |
// no BBCode in text only message
|
|
|
f2e824 |
strip_bbcode($text_only_message, $row['bbcode_uid']);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($return_chars == -1 || utf8_strlen($text_only_message) < ($return_chars + 3))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$row['display_text_only'] = false;
|
|
|
f2e824 |
$bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Does this post have an attachment? If so, add it to the list
|
|
|
f2e824 |
if ($row['post_attachment'] && $config['allow_attachments'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$attach_list[$row['forum_id']][] = $row['post_id'];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$row['post_text'] = $text_only_message;
|
|
|
f2e824 |
$row['display_text_only'] = true;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$rowset[] = $row;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
|
|
|
f2e824 |
unset($text_only_message);
|
|
|
f2e824 |
|
|
|
f2e824 |
// Instantiate BBCode if needed
|
|
|
f2e824 |
if ($bbcode_bitfield !== '')
|
|
|
f2e824 |
{
|
|
|
f2e824 |
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
|
|
|
f2e824 |
$bbcode = new bbcode(base64_encode($bbcode_bitfield));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Pull attachment data
|
|
|
f2e824 |
if (sizeof($attach_list))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$use_attach_list = $attach_list;
|
|
|
f2e824 |
$attach_list = array();
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($use_attach_list as $forum_id => $_list)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$attach_list = array_merge($attach_list, $_list);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if (sizeof($attach_list))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql = 'SELECT *
|
|
|
f2e824 |
FROM ' . ATTACHMENTS_TABLE . '
|
|
|
f2e824 |
WHERE ' . $db->sql_in_set('post_msg_id', $attach_list) . '
|
|
|
f2e824 |
AND in_message = 0
|
|
|
f2e824 |
ORDER BY filetime DESC, post_msg_id ASC';
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$attachments[$row['post_msg_id']][] = $row;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($hilit)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// Remove bad highlights
|
|
|
f2e824 |
$hilit_array = array_filter(explode('|', $hilit), 'strlen');
|
|
|
f2e824 |
foreach ($hilit_array as $key => $value)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$hilit_array[$key] = str_replace('\*', '\w*?', preg_quote($value, '#'));
|
|
|
f2e824 |
$hilit_array[$key] = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $hilit_array[$key]);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$hilit = implode('|', $hilit_array);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
foreach ($rowset as $row)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$forum_id = $row['forum_id'];
|
|
|
f2e824 |
$result_topic_id = $row['topic_id'];
|
|
|
f2e824 |
$topic_title = censor_text($row['topic_title']);
|
|
|
f2e824 |
|
|
|
f2e824 |
// we need to select a forum id for this global topic
|
|
|
f2e824 |
if (!$forum_id)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if (!isset($g_forum_id))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// Get a list of forums the user cannot read
|
|
|
f2e824 |
$forum_ary = array_unique(array_keys($auth->acl_getf('!f_read', true)));
|
|
|
f2e824 |
|
|
|
f2e824 |
// Determine first forum the user is able to read (must not be a category)
|
|
|
f2e824 |
$sql = 'SELECT forum_id
|
|
|
f2e824 |
FROM ' . FORUMS_TABLE . '
|
|
|
f2e824 |
WHERE forum_type = ' . FORUM_POST;
|
|
|
f2e824 |
|
|
|
f2e824 |
if (sizeof($forum_ary))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$sql .= ' AND ' . $db->sql_in_set('forum_id', $forum_ary, true);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$result = $db->sql_query_limit($sql, 1);
|
|
|
f2e824 |
$g_forum_id = (int) $db->sql_fetchfield('forum_id');
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$u_forum_id = $g_forum_id;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$u_forum_id = $forum_id;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$u_forum_id&t=$result_topic_id" . (($u_hilit) ? "&hilit=$u_hilit" : ''));
|
|
|
f2e824 |
|
|
|
f2e824 |
$replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($show_results == 'topics')
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($config['load_db_track'] && $author_id === $user->data['user_id'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$row['topic_posted'] = 1;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$folder_img = $folder_alt = $topic_type = '';
|
|
|
f2e824 |
topic_status($row, $replies, (isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']]) ? true : false, $folder_img, $folder_alt, $topic_type);
|
|
|
f2e824 |
|
|
|
f2e824 |
$unread_topic = (isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']]) ? true : false;
|
|
|
f2e824 |
|
|
|
f2e824 |
$topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $forum_id)) ? true : false;
|
|
|
f2e824 |
$posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id)) ? true : false;
|
|
|
f2e824 |
$u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&t=$result_topic_id", true, $user->session_id) : '';
|
|
|
f2e824 |
|
|
|
f2e824 |
$row['topic_title'] = preg_replace('#(?!<.*)(?]*(?:</s(?:cript|tyle))?>)#is', '$1', $row['topic_title']);
|
|
|
f2e824 |
|
|
|
f2e824 |
$tpl_ary = array(
|
|
|
f2e824 |
'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
|
|
|
f2e824 |
'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
|
|
|
f2e824 |
'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
|
|
|
f2e824 |
'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
|
|
|
f2e824 |
'LAST_POST_SUBJECT' => $row['topic_last_post_subject'],
|
|
|
f2e824 |
'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
|
|
|
f2e824 |
'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
|
|
|
f2e824 |
'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
|
|
|
f2e824 |
'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
|
|
|
f2e824 |
'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
|
|
|
f2e824 |
|
|
|
f2e824 |
'PAGINATION' => topic_generate_pagination($replies, $view_topic_url),
|
|
|
f2e824 |
'TOPIC_TYPE' => $topic_type,
|
|
|
f2e824 |
|
|
|
f2e824 |
'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
|
|
|
f2e824 |
'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
|
|
|
f2e824 |
'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt],
|
|
|
f2e824 |
'TOPIC_FOLDER_IMG_WIDTH'=> $user->img($folder_img, '', false, '', 'width'),
|
|
|
f2e824 |
'TOPIC_FOLDER_IMG_HEIGHT' => $user->img($folder_img, '', false, '', 'height'),
|
|
|
f2e824 |
|
|
|
f2e824 |
'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
|
|
|
f2e824 |
'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
|
|
|
f2e824 |
'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
|
|
|
f2e824 |
'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
|
|
|
f2e824 |
'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
|
|
|
f2e824 |
|
|
|
f2e824 |
'S_TOPIC_GLOBAL' => (!$forum_id) ? true : false,
|
|
|
f2e824 |
'S_TOPIC_TYPE' => $row['topic_type'],
|
|
|
f2e824 |
'S_USER_POSTED' => (!empty($row['mark_type'])) ? true : false,
|
|
|
f2e824 |
'S_UNREAD_TOPIC' => $unread_topic,
|
|
|
f2e824 |
|
|
|
f2e824 |
'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $forum_id)) ? true : false,
|
|
|
f2e824 |
'S_TOPIC_UNAPPROVED' => $topic_unapproved,
|
|
|
f2e824 |
'S_POSTS_UNAPPROVED' => $posts_unapproved,
|
|
|
f2e824 |
|
|
|
f2e824 |
'U_LAST_POST' => $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'],
|
|
|
f2e824 |
'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
|
|
|
f2e824 |
'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
|
|
|
f2e824 |
'U_NEWEST_POST' => $view_topic_url . '&view=unread#unread',
|
|
|
f2e824 |
'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=reports&t=' . $result_topic_id, true, $user->session_id),
|
|
|
f2e824 |
'U_MCP_QUEUE' => $u_mcp_queue,
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ((isset($zebra['foe']) && in_array($row['poster_id'], $zebra['foe'])) && (!$view || $view != 'show' || $post_id != $row['post_id']))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$template->assign_block_vars('searchresults', array(
|
|
|
f2e824 |
'S_IGNORE_POST' => true,
|
|
|
f2e824 |
|
|
|
f2e824 |
'L_IGNORE_POST' => sprintf($user->lang['POST_BY_FOE'], $row['username'], "', ''))
|
|
|
f2e824 |
);
|
|
|
f2e824 |
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Replace naughty words such as farty pants
|
|
|
f2e824 |
$row['post_subject'] = censor_text($row['post_subject']);
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($row['display_text_only'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// now find context for the searched words
|
|
|
f2e824 |
$row['post_text'] = get_context($row['post_text'], array_filter(explode('|', $hilit), 'strlen'), $return_chars);
|
|
|
f2e824 |
$row['post_text'] = bbcode_nl2br($row['post_text']);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// Second parse bbcode here
|
|
|
f2e824 |
if ($row['bbcode_bitfield'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$bbcode->bbcode_second_pass($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield']);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$row['post_text'] = bbcode_nl2br($row['post_text']);
|
|
|
f2e824 |
$row['post_text'] = smiley_text($row['post_text']);
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!empty($attachments[$row['post_id']]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
parse_attachments($forum_id, $row['post_text'], $attachments[$row['post_id']], $update_count);
|
|
|
f2e824 |
|
|
|
f2e824 |
// we only display inline attachments
|
|
|
f2e824 |
unset($attachments[$row['post_id']]);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($hilit)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// post highlighting
|
|
|
f2e824 |
$row['post_text'] = preg_replace('#(?!<.*)(?]*(?:</s(?:cript|tyle))?>)#is', '$1', $row['post_text']);
|
|
|
f2e824 |
$row['post_subject'] = preg_replace('#(?!<.*)(?]*(?:</s(?:cript|tyle))?>)#is', '$1', $row['post_subject']);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$tpl_ary = array(
|
|
|
f2e824 |
'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
|
|
|
f2e824 |
'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
|
|
|
f2e824 |
'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
|
|
|
f2e824 |
'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
|
|
|
f2e824 |
|
|
|
f2e824 |
'POST_SUBJECT' => $row['post_subject'],
|
|
|
f2e824 |
'POST_DATE' => (!empty($row['post_time'])) ? $user->format_date($row['post_time']) : '',
|
|
|
f2e824 |
'MESSAGE' => $row['post_text']
|
|
|
f2e824 |
);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$template->assign_block_vars('searchresults', array_merge($tpl_ary, array(
|
|
|
f2e824 |
'FORUM_ID' => $forum_id,
|
|
|
f2e824 |
'TOPIC_ID' => $result_topic_id,
|
|
|
f2e824 |
'POST_ID' => ($show_results == 'posts') ? $row['post_id'] : false,
|
|
|
f2e824 |
|
|
|
f2e824 |
'FORUM_TITLE' => $row['forum_name'],
|
|
|
f2e824 |
'TOPIC_TITLE' => $topic_title,
|
|
|
f2e824 |
'TOPIC_REPLIES' => $replies,
|
|
|
f2e824 |
'TOPIC_VIEWS' => $row['topic_views'],
|
|
|
f2e824 |
|
|
|
f2e824 |
'U_VIEW_TOPIC' => $view_topic_url,
|
|
|
f2e824 |
'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
|
|
|
f2e824 |
'U_VIEW_POST' => (!empty($row['post_id'])) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=" . $row['topic_id'] . '&p=' . $row['post_id'] . (($u_hilit) ? '&hilit=' . $u_hilit : '')) . '#p' . $row['post_id'] : '')
|
|
|
f2e824 |
));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($topic_id && ($topic_id == $result_topic_id))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$template->assign_vars(array(
|
|
|
f2e824 |
'SEARCH_TOPIC' => $topic_title,
|
|
|
f2e824 |
'U_SEARCH_TOPIC' => $view_topic_url
|
|
|
f2e824 |
));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
unset($rowset);
|
|
|
f2e824 |
|
|
|
f2e824 |
page_header(($l_search_title) ? $l_search_title : $user->lang['SEARCH']);
|
|
|
f2e824 |
|
|
|
f2e824 |
$template->set_filenames(array(
|
|
|
f2e824 |
'body' => 'search_results.html')
|
|
|
f2e824 |
);
|
|
|
f2e824 |
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
|
|
|
f2e824 |
|
|
|
f2e824 |
page_footer();
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
|
|
|
f2e824 |
// Search forum
|
|
|
f2e824 |
$s_forums = '';
|
|
|
f2e824 |
$sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.left_id, f.right_id, f.forum_password, f.enable_indexing, fa.user_id
|
|
|
f2e824 |
FROM ' . FORUMS_TABLE . ' f
|
|
|
f2e824 |
LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id
|
|
|
f2e824 |
AND fa.session_id = '" . $db->sql_escape($user->session_id) . "')
|
|
|
f2e824 |
ORDER BY f.left_id ASC";
|
|
|
f2e824 |
$result = $db->sql_query($sql);
|
|
|
f2e824 |
|
|
|
f2e824 |
$right = $cat_right = $padding_inc = 0;
|
|
|
f2e824 |
$padding = $forum_list = $holding = '';
|
|
|
f2e824 |
$pad_store = array('0' => '');
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// Non-postable forum with no subforums, don't display
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($row['forum_type'] == FORUM_POST && ($row['left_id'] + 1 == $row['right_id']) && !$row['enable_indexing'])
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// Postable forum with no subforums and indexing disabled, don't display
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($row['forum_type'] == FORUM_LINK || ($row['forum_password'] && !$row['user_id']))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// if this forum is a link or password protected (user has not entered the password yet) then skip to the next branch
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($row['left_id'] < $right)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$padding .= ' ';
|
|
|
f2e824 |
$pad_store[$row['parent_id']] = $padding;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else if ($row['left_id'] > $right + 1)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
if (isset($pad_store[$row['parent_id']]))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$padding = $pad_store[$row['parent_id']];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$right = $row['right_id'];
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($auth->acl_gets('!f_search', '!f_list', $row['forum_id']))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// if the user does not have permissions to search or see this forum skip only this forum/category
|
|
|
f2e824 |
continue;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$selected = (in_array($row['forum_id'], $search_forum)) ? ' selected="selected"' : '';
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($row['left_id'] > $cat_right)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// make sure we don't forget anything
|
|
|
f2e824 |
$s_forums .= $holding;
|
|
|
f2e824 |
$holding = '';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($row['right_id'] - $row['left_id'] > 1)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$cat_right = max($cat_right, $row['right_id']);
|
|
|
f2e824 |
|
|
|
f2e824 |
$holding .= '<option value="' . $row['forum_id'] . '"' . $selected . '>' . $padding . $row['forum_name'] . '</option>';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
else
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$s_forums .= $holding . '<option value="' . $row['forum_id'] . '"' . $selected . '>' . $padding . $row['forum_name'] . '</option>';
|
|
|
f2e824 |
$holding = '';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($holding)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$s_forums .= $holding;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
unset($pad_store);
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!$s_forums)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
trigger_error('NO_SEARCH');
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Number of chars returned
|
|
|
f2e824 |
$s_characters = '<option value="-1">' . $user->lang['ALL_AVAILABLE'] . '</option>';
|
|
|
f2e824 |
$s_characters .= '<option value="0">0</option>';
|
|
|
f2e824 |
$s_characters .= '<option value="25">25</option>';
|
|
|
f2e824 |
$s_characters .= '<option value="50">50</option>';
|
|
|
f2e824 |
|
|
|
f2e824 |
for ($i = 100; $i <= 1000 ; $i += 100)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$selected = ($i == 300) ? ' selected="selected"' : '';
|
|
|
f2e824 |
$s_characters .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$s_hidden_fields = array('t' => $topic_id);
|
|
|
f2e824 |
|
|
|
f2e824 |
if ($_SID)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$s_hidden_fields['sid'] = $_SID;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
if (!empty($_EXTRA_URL))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
foreach ($_EXTRA_URL as $url_param)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$url_param = explode('=', $url_param, 2);
|
|
|
f2e824 |
$s_hidden_fields[$url_param[0]] = $url_param[1];
|
|
|
f2e824 |
}
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
$template->assign_vars(array(
|
|
|
f2e824 |
'S_SEARCH_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx", false, true, 0), // We force no ?sid= appending by using 0
|
|
|
f2e824 |
'S_HIDDEN_FIELDS' => build_hidden_fields($s_hidden_fields),
|
|
|
f2e824 |
'S_CHARACTER_OPTIONS' => $s_characters,
|
|
|
f2e824 |
'S_FORUM_OPTIONS' => $s_forums,
|
|
|
f2e824 |
'S_SELECT_SORT_DIR' => $s_sort_dir,
|
|
|
f2e824 |
'S_SELECT_SORT_KEY' => $s_sort_key,
|
|
|
f2e824 |
'S_SELECT_SORT_DAYS' => $s_limit_days,
|
|
|
f2e824 |
'S_IN_SEARCH' => true,
|
|
|
f2e824 |
));
|
|
|
f2e824 |
|
|
|
f2e824 |
// only show recent searches to search administrators
|
|
|
f2e824 |
if ($auth->acl_get('a_search'))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
// Handle large objects differently for Oracle and MSSQL
|
|
|
f2e824 |
switch ($db->sql_layer)
|
|
|
f2e824 |
{
|
|
|
f2e824 |
case 'oracle':
|
|
|
f2e824 |
$sql = 'SELECT search_time, search_keywords
|
|
|
f2e824 |
FROM ' . SEARCH_RESULTS_TABLE . '
|
|
|
f2e824 |
WHERE dbms_lob.getlength(search_keywords) > 0
|
|
|
f2e824 |
ORDER BY search_time DESC';
|
|
|
f2e824 |
break;
|
|
|
f2e824 |
|
|
|
f2e824 |
case 'mssql':
|
|
|
f2e824 |
case 'mssql_odbc':
|
|
|
f2e824 |
$sql = 'SELECT search_time, search_keywords
|
|
|
f2e824 |
FROM ' . SEARCH_RESULTS_TABLE . '
|
|
|
f2e824 |
WHERE DATALENGTH(search_keywords) > 0
|
|
|
f2e824 |
ORDER BY search_time DESC';
|
|
|
f2e824 |
break;
|
|
|
f2e824 |
|
|
|
f2e824 |
default:
|
|
|
f2e824 |
$sql = 'SELECT search_time, search_keywords
|
|
|
f2e824 |
FROM ' . SEARCH_RESULTS_TABLE . '
|
|
|
f2e824 |
WHERE search_keywords <> \'\'
|
|
|
f2e824 |
ORDER BY search_time DESC';
|
|
|
f2e824 |
break;
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$result = $db->sql_query_limit($sql, 5);
|
|
|
f2e824 |
|
|
|
f2e824 |
while ($row = $db->sql_fetchrow($result))
|
|
|
f2e824 |
{
|
|
|
f2e824 |
$keywords = $row['search_keywords'];
|
|
|
f2e824 |
|
|
|
f2e824 |
$template->assign_block_vars('recentsearch', array(
|
|
|
f2e824 |
'KEYWORDS' => $keywords,
|
|
|
f2e824 |
'TIME' => $user->format_date($row['search_time']),
|
|
|
f2e824 |
|
|
|
f2e824 |
'U_KEYWORDS' => append_sid("{$phpbb_root_path}search.$phpEx", 'keywords=' . urlencode(htmlspecialchars_decode($keywords)))
|
|
|
f2e824 |
));
|
|
|
f2e824 |
}
|
|
|
f2e824 |
$db->sql_freeresult($result);
|
|
|
f2e824 |
}
|
|
|
f2e824 |
|
|
|
f2e824 |
// Output the basic page
|
|
|
f2e824 |
page_header($user->lang['SEARCH']);
|
|
|
f2e824 |
|
|
|
f2e824 |
$template->set_filenames(array(
|
|
|
f2e824 |
'body' => 'search_body.html')
|
|
|
f2e824 |
);
|
|
|
f2e824 |
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
|
|
|
f2e824 |
|
|
|
f2e824 |
page_footer();
|
|
|
f2e824 |
|
|
|
f2e824 |
?>
|