2001-11-17 17:44:31 +00:00
|
|
|
<?php
|
2005-04-09 12:26:45 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package phpBB3
|
|
|
|
* @version $Id$
|
|
|
|
* @copyright (c) 2005 phpBB Group
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
|
*
|
|
|
|
*/
|
2003-06-06 15:24:26 +00:00
|
|
|
|
2005-04-09 12:26:45 +00:00
|
|
|
/**
|
|
|
|
*/
|
2002-03-18 13:35:43 +00:00
|
|
|
define('IN_PHPBB', true);
|
2002-03-31 00:06:34 +00:00
|
|
|
$phpbb_root_path = './';
|
2003-09-15 16:33:12 +00:00
|
|
|
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
2001-07-13 16:14:37 +00:00
|
|
|
include($phpbb_root_path . 'common.'.$phpEx);
|
2001-05-29 14:25:09 +00:00
|
|
|
|
|
|
|
// Start session management
|
2005-10-02 16:48:17 +00:00
|
|
|
$user->session_begin();
|
2002-10-20 19:19:07 +00:00
|
|
|
$auth->acl($user->data);
|
2004-02-28 21:16:15 +00:00
|
|
|
$user->setup('search');
|
2001-05-29 14:25:09 +00:00
|
|
|
|
2004-09-01 15:47:46 +00:00
|
|
|
// Define initial vars
|
2006-01-11 18:56:07 +00:00
|
|
|
$mode = request_var('mode', '');
|
|
|
|
$search_id = request_var('search_id', '');
|
|
|
|
$start = max(request_var('start', 0), 0);
|
|
|
|
$post_id = request_var('p', 0);
|
|
|
|
$topic_id = request_var('t', 0);
|
|
|
|
$view = request_var('view', '');
|
2004-09-01 15:47:46 +00:00
|
|
|
|
2005-10-02 16:48:17 +00:00
|
|
|
$keywords = request_var('keywords', '');
|
2006-01-11 18:56:07 +00:00
|
|
|
$add_keywords = request_var('add_keywords', '');
|
2005-10-02 16:48:17 +00:00
|
|
|
$author = request_var('author', '');
|
2006-01-11 18:56:07 +00:00
|
|
|
$show_results = ($topic_id) ? 'posts' : request_var('sr', 'topics');
|
|
|
|
$search_terms = request_var('terms', 'all');
|
|
|
|
$search_fields = request_var('sf', 'all');
|
|
|
|
$search_child = request_var('sc', true);
|
2004-09-01 15:47:46 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
$sort_days = request_var('st', 0);
|
|
|
|
$sort_key = request_var('sk', 't');
|
|
|
|
$sort_dir = request_var('sd', 'd');
|
2004-09-01 15:47:46 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
$return_chars = request_var('ch', ($topic_id) ? -1 : 200);
|
|
|
|
$search_forum = request_var('fid', array(0));
|
|
|
|
|
|
|
|
if ($search_forum == array(0))
|
|
|
|
{
|
|
|
|
$search_forum = array();
|
|
|
|
}
|
2004-09-01 15:47:46 +00:00
|
|
|
|
2003-04-15 23:21:05 +00:00
|
|
|
// Is user able to search? Has search been disabled?
|
2003-09-15 16:33:12 +00:00
|
|
|
if (!$auth->acl_get('u_search') || !$config['load_search'])
|
2003-04-15 23:21:05 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
trigger_error($user->lang['NO_SEARCH']);
|
2003-04-15 23:21:05 +00:00
|
|
|
}
|
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
// Check search load limit
|
|
|
|
if ($user->load && $config['limit_search_load'] && ($user->load > doubleval($config['limit_search_load'])))
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['NO_SEARCH_TIME']);
|
|
|
|
}
|
2003-10-05 12:56:53 +00:00
|
|
|
|
|
|
|
// Check last search time ... if applicable
|
|
|
|
if ($config['search_interval'])
|
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
if ($config['last_search_time'] > time() - $config['search_interval'])
|
2003-10-05 12:56:53 +00:00
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
trigger_error($user->lang['NO_SEARCH_TIME']);
|
2003-10-05 12:56:53 +00:00
|
|
|
}
|
|
|
|
}
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
// Define some vars
|
|
|
|
$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'], 364 => $user->lang['1_YEAR']);
|
|
|
|
$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']);
|
|
|
|
|
|
|
|
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
|
|
|
|
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);
|
|
|
|
|
|
|
|
if ($keywords || $author || $search_id)
|
2003-09-15 16:33:12 +00:00
|
|
|
{
|
2005-10-02 16:48:17 +00:00
|
|
|
// clear arrays
|
2006-01-11 18:56:07 +00:00
|
|
|
$id_ary = array();
|
|
|
|
|
|
|
|
// Which forums should not be searched?
|
|
|
|
$ex_fid_ary = array_keys($auth->acl_getf('!f_read', true));
|
2003-09-15 16:33:12 +00:00
|
|
|
|
2006-01-11 21:52:41 +00:00
|
|
|
$not_in_fid = (sizeof($ex_fid_ary)) ? 'f.forum_id NOT IN (' . implode(', ', $ex_fid_ary) . ') OR ' : '';
|
2003-09-15 16:33:12 +00:00
|
|
|
$sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.right_id, f.forum_password, fa.user_id
|
2005-11-28 18:38:49 +00:00
|
|
|
FROM ' . FORUMS_TABLE . ' f
|
2005-10-02 16:48:17 +00:00
|
|
|
LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id
|
2005-11-28 18:38:49 +00:00
|
|
|
AND fa.session_id = '" . $db->sql_escape($user->data['session_id']) . "')
|
2006-01-11 21:52:41 +00:00
|
|
|
WHERE $not_in_fid(f.forum_password <> '' AND fa.user_id <> " . (int) $user->data['user_id'] . ')
|
2006-01-11 18:56:07 +00:00
|
|
|
ORDER BY f.left_id';
|
2003-09-15 16:33:12 +00:00
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
|
|
|
$right_id = 0;
|
2006-01-11 18:56:07 +00:00
|
|
|
$reset_search_forum = true;
|
2003-09-15 16:33:12 +00:00
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
if ($row['forum_password'] && ($row['user_id'] != $user->data['user_id']))
|
|
|
|
{
|
2006-01-22 19:13:12 +00:00
|
|
|
$ex_fid_ary[] = (int) $row['forum_id'];
|
2006-01-11 18:56:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sizeof($search_forum))
|
2003-09-15 16:33:12 +00:00
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
if ($search_child)
|
2003-09-15 16:33:12 +00:00
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
if (in_array($row['forum_id'], $search_forum) && $row['right_id'] > $right_id)
|
|
|
|
{
|
2006-01-22 19:13:12 +00:00
|
|
|
$right_id = (int) $row['right_id'];
|
2006-01-11 18:56:07 +00:00
|
|
|
}
|
|
|
|
else if ($row['right_id'] < $right_id)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
}
|
2006-01-11 18:56:07 +00:00
|
|
|
|
|
|
|
if (!in_array($row['forum_id'], $search_forum))
|
2003-09-15 16:33:12 +00:00
|
|
|
{
|
2006-01-22 19:13:12 +00:00
|
|
|
$ex_fid_ary[] = (int) $row['forum_id'];
|
2006-01-11 18:56:07 +00:00
|
|
|
$reset_search_forum = false;
|
2003-09-15 16:33:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
if ($reset_search_forum)
|
2003-10-27 13:18:06 +00:00
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
$search_forum = array();
|
2003-10-27 13:18:06 +00:00
|
|
|
}
|
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
// egosearch is an author search
|
2003-09-15 16:33:12 +00:00
|
|
|
if ($search_id == 'egosearch')
|
|
|
|
{
|
2005-10-02 16:48:17 +00:00
|
|
|
$author = $user->data['username'];
|
2003-09-15 16:33:12 +00:00
|
|
|
}
|
2002-02-25 01:00:48 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
// If we are looking for authors get their ids
|
|
|
|
$author_id_ary = array();
|
2005-10-02 16:48:17 +00:00
|
|
|
if ($author)
|
2001-12-05 00:20:56 +00:00
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
if ((strstr($author, '*') !== false) && (str_replace(array('*', '%'), '', $author) < $config['min_search_author_chars']))
|
|
|
|
{
|
|
|
|
trigger_error(sprintf($user->lang['TOO_FEW_AUTHOR_CHARS'], $config['min_search_author_chars']));
|
|
|
|
}
|
|
|
|
|
2005-10-02 16:48:17 +00:00
|
|
|
$sql_where = (strstr($author, '*') !== false) ? ' LIKE ' : ' = ';
|
|
|
|
$sql = 'SELECT user_id
|
2003-09-15 16:33:12 +00:00
|
|
|
FROM ' . USERS_TABLE . "
|
2005-10-02 16:48:17 +00:00
|
|
|
WHERE username $sql_where '" . $db->sql_escape(preg_replace('#\*+#', '%', $author)) . "'
|
2005-03-21 22:43:07 +00:00
|
|
|
AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
|
2006-01-11 18:56:07 +00:00
|
|
|
$result = $db->sql_query_limit($sql, 100);
|
2003-09-15 16:33:12 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
while ($row = $db->sql_fetchrow($result))
|
2001-09-17 00:42:17 +00:00
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
$author_id_ary[] = (int) $row['user_id'];
|
2003-09-15 16:33:12 +00:00
|
|
|
}
|
2006-01-11 18:56:07 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
if (!sizeof($author_id_ary))
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['NO_SEARCH_RESULTS']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we search in an existing search result just add the additional keywords. But we need to use "all search terms"-mode
|
|
|
|
// so we can keep the old keywords in their old mode, but add the new ones as required words
|
|
|
|
if ($add_keywords)
|
|
|
|
{
|
|
|
|
if ($search_terms == 'all')
|
|
|
|
{
|
|
|
|
$keywords .= ' ' . $add_keywords;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$search_terms = 'all';
|
|
|
|
$keywords = implode(' |', explode(' ', preg_replace('#\s+#', ' ', $keywords))) . ' ' .$add_keywords;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select which method we'll use to obtain the post_id or topic_id information
|
|
|
|
$search_type = $config['search_type'];
|
|
|
|
|
|
|
|
if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
|
|
|
|
{
|
|
|
|
trigger_error('NO_SUCH_SEARCH_MODULE');
|
2003-09-15 16:33:12 +00:00
|
|
|
}
|
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
require("{$phpbb_root_path}includes/search/$search_type.$phpEx");
|
2005-10-02 16:48:17 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
// We do some additional checks in the module to ensure it can actually be utilised
|
|
|
|
$error = false;
|
|
|
|
$search = new $search_type($error);
|
|
|
|
|
|
|
|
if ($error)
|
|
|
|
{
|
|
|
|
trigger_error($error);
|
|
|
|
}
|
|
|
|
|
|
|
|
// let the search module split up the keywords
|
|
|
|
if ($keywords)
|
|
|
|
{
|
|
|
|
$search->split_keywords($keywords, $search_terms);
|
|
|
|
if (!sizeof($search->split_words) && !sizeof($author_id_ary) && !$search_id)
|
|
|
|
{
|
|
|
|
trigger_error(sprintf($user->lang['NO_KEYWORDS'], $config['min_search_chars'], $config['max_search_chars']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-22 19:13:12 +00:00
|
|
|
if (!$keywords && sizeof($author_id_ary))
|
|
|
|
{
|
|
|
|
// default to showing results as posts when performing an author search
|
|
|
|
$show_results = ($topic_id) ? 'posts' : request_var('sr', 'posts');
|
|
|
|
}
|
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
// define some variables needed for retrieving post_id/topic_id information
|
|
|
|
$per_page = ($show_results == 'posts') ? $config['posts_per_page'] : $config['topics_per_page'];
|
2006-01-22 19:13:12 +00:00
|
|
|
$sort_by_sql = array('a' => 'u.username', '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'));
|
2006-01-11 18:56:07 +00:00
|
|
|
|
|
|
|
// pre-made searches
|
|
|
|
$sql = $field = '';
|
2003-09-15 16:33:12 +00:00
|
|
|
if ($search_id)
|
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
// Build sql string for sorting
|
|
|
|
$sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC');
|
2004-10-19 19:26:58 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
switch ($search_id)
|
|
|
|
{
|
2005-06-13 17:51:55 +00:00
|
|
|
// Oh holy Bob, bring us some activity...
|
|
|
|
case 'active_topics':
|
|
|
|
$show_results = 'topics';
|
2006-01-11 18:56:07 +00:00
|
|
|
$sort_key = 't';
|
|
|
|
$sort_dir = 'd';
|
|
|
|
$sort_by_sql['t'] = 't.topic_last_post_time';
|
2005-06-13 17:51:55 +00:00
|
|
|
|
|
|
|
if (!$sort_days)
|
|
|
|
{
|
|
|
|
$sort_days = 1;
|
|
|
|
}
|
2006-01-11 18:56:07 +00:00
|
|
|
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);
|
|
|
|
$s_sort_key = $s_sort_dir = $u_sort_param = '';
|
2005-06-13 17:51:55 +00:00
|
|
|
|
|
|
|
$last_post_time = (time() - ($sort_days * 24 * 3600));
|
|
|
|
|
|
|
|
$sql = 'SELECT DISTINCT t.topic_id
|
|
|
|
FROM ' . POSTS_TABLE . ' p
|
|
|
|
LEFT JOIN ' . TOPICS_TABLE . " t ON (t.topic_approved = 1 AND p.topic_id = t.topic_id)
|
|
|
|
WHERE p.post_time > $last_post_time
|
2006-01-11 18:56:07 +00:00
|
|
|
" . ((sizeof($ex_fid_ary)) ? ' AND p.forum_id NOT IN (' . implode(',', $ex_fid_ary) . ')' : '') . '
|
2005-10-02 16:48:17 +00:00
|
|
|
ORDER BY t.topic_last_post_time DESC';
|
2006-01-11 18:56:07 +00:00
|
|
|
$field = 'topic_id';
|
2006-01-22 19:13:12 +00:00
|
|
|
break;
|
2003-09-15 16:33:12 +00:00
|
|
|
|
|
|
|
case 'unanswered':
|
2006-01-11 18:56:07 +00:00
|
|
|
$sort_join = ($sort_key == 'f') ? FORUMS_TABLE . ' f, ' : '';
|
|
|
|
$sql_sort = ($sort_key == 'f') ? ' AND f.forum_id = p.forum_id ' . $sql_sort : $sql_sort;
|
2003-09-15 16:33:12 +00:00
|
|
|
if ($show_results == 'posts')
|
2002-02-25 01:00:48 +00:00
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
if ($sort_key == 'a')
|
|
|
|
{
|
|
|
|
$sort_join = USERS_TABLE . ' u, ';
|
|
|
|
$sql_sort = ' AND u.user_id = p.poster_id ' . $sql_sort;
|
|
|
|
}
|
|
|
|
$sql = "SELECT p.post_id
|
|
|
|
FROM $sort_join" . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
|
2003-09-15 16:33:12 +00:00
|
|
|
WHERE t.topic_replies = 0
|
2003-10-27 13:18:06 +00:00
|
|
|
AND p.topic_id = t.topic_id
|
2006-01-11 18:56:07 +00:00
|
|
|
" . ((sizeof($ex_fid_ary)) ? ' AND p.forum_id NOT IN (' . implode(',', $ex_fid_ary) . ')' : '') . "
|
|
|
|
$sql_sort";
|
2003-09-15 16:33:12 +00:00
|
|
|
$field = 'post_id';
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
$sql = "SELECT DISTINCT p.topic_id
|
|
|
|
FROM $sort_join" . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
|
2005-10-02 16:48:17 +00:00
|
|
|
WHERE t.topic_replies = 0
|
2003-10-27 13:18:06 +00:00
|
|
|
AND p.topic_id = t.topic_id
|
2006-01-11 18:56:07 +00:00
|
|
|
" . ((sizeof($ex_fid_ary)) ? ' AND p.forum_id NOT IN (' . implode(',', $ex_fid_ary) . ')' : '') . "
|
|
|
|
$sql_sort";
|
2003-09-15 16:33:12 +00:00
|
|
|
$field = 'topic_id';
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
2006-01-22 19:13:12 +00:00
|
|
|
break;
|
2003-09-15 16:33:12 +00:00
|
|
|
|
|
|
|
case 'newposts':
|
2006-01-11 18:56:07 +00:00
|
|
|
$sort_join = ($sort_key == 'f') ? FORUMS_TABLE . ' f, ' : '';
|
|
|
|
$sql_sort = ($sort_key == 'f') ? ' AND f.forum_id = p.forum_id ' . $sql_sort : $sql_sort;
|
2003-09-15 16:33:12 +00:00
|
|
|
if ($show_results == 'posts')
|
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
if ($sort_key == 'i')
|
|
|
|
{
|
|
|
|
$sort_join = TOPICS_TABLE . ' t, ';
|
|
|
|
$sql_sort = ' AND t.topic_id = p.topic_id ' . $sql_sort;
|
|
|
|
}
|
|
|
|
elseif ($sort_key == 'a')
|
|
|
|
{
|
|
|
|
$sort_join = USERS_TABLE . ' u, ';
|
|
|
|
$sql_sort = ' AND u.user_id = p.poster_id ' . $sql_sort;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT p.post_id
|
|
|
|
FROM $sort_join" . POSTS_TABLE . ' p
|
2003-10-27 13:18:06 +00:00
|
|
|
WHERE p.post_time > ' . $user->data['user_lastvisit'] . "
|
2006-01-11 18:56:07 +00:00
|
|
|
" . ((sizeof($ex_fid_ary)) ? ' AND p.forum_id NOT IN (' . implode(',', $ex_fid_ary) . ')' : '') . "
|
|
|
|
$sql_sort";
|
2003-09-15 16:33:12 +00:00
|
|
|
$field = 'post_id';
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
$sql = "SELECT DISTINCT p.topic_id
|
|
|
|
FROM $sort_join" . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p
|
2005-10-02 16:48:17 +00:00
|
|
|
WHERE p.post_time > ' . $user->data['user_lastvisit'] . "
|
|
|
|
AND t.topic_id = p.topic_id
|
2006-01-11 18:56:07 +00:00
|
|
|
" . ((sizeof($ex_fid_ary)) ? ' AND p.forum_id NOT IN (' . implode(',', $ex_fid_ary) . ')' : '') . "
|
|
|
|
$sql_sort";
|
2003-09-15 16:33:12 +00:00
|
|
|
$field = 'topic_id';
|
|
|
|
}
|
2006-01-22 19:13:12 +00:00
|
|
|
break;
|
2005-06-13 17:51:55 +00:00
|
|
|
}
|
2002-08-13 16:34:17 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
if ($sql)
|
2005-06-13 17:51:55 +00:00
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
// only return up to 1000 ids (the last one will be removed later)
|
|
|
|
$result = $db->sql_query_limit($sql, 1001 - $start, $start);
|
2001-12-20 01:25:00 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
while ($row = $db->sql_fetchrow($result))
|
2005-06-13 17:51:55 +00:00
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
$id_ary[] = $row[$field];
|
2005-06-13 17:51:55 +00:00
|
|
|
}
|
2006-01-11 18:56:07 +00:00
|
|
|
$db->sql_freeresult($result);
|
2002-01-25 00:48:46 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
$total_match_count = sizeof($id_ary) + $start;
|
|
|
|
$id_ary = array_slice($id_ary, 0, $per_page);
|
2001-11-09 13:00:04 +00:00
|
|
|
}
|
2006-01-11 18:56:07 +00:00
|
|
|
else
|
2001-05-31 11:47:43 +00:00
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
$search_id = '';
|
2001-09-17 00:42:17 +00:00
|
|
|
}
|
2006-01-11 18:56:07 +00:00
|
|
|
}
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
if (sizeof($search->split_words))
|
|
|
|
{
|
|
|
|
$total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $topic_id, $author_id_ary, $id_ary, $start, $per_page);
|
|
|
|
}
|
|
|
|
else if (sizeof($author_id_ary))
|
|
|
|
{
|
|
|
|
$total_match_count = $search->author_search($show_results, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $topic_id, $author_id_ary, $id_ary, $start, $per_page);
|
|
|
|
}
|
2004-10-19 19:26:58 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
if (!sizeof($id_ary))
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['NO_SEARCH_RESULTS']);
|
2003-09-15 16:33:12 +00:00
|
|
|
}
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
$sql_where = (($show_results == 'posts') ? 'p.post_id' : 't.topic_id') . ' IN (' . implode(', ', $id_ary) . ')';
|
2006-01-21 22:57:42 +00:00
|
|
|
$sql_where .= (sizeof($ex_fid_ary)) ? ' AND (f.forum_id NOT IN (' . implode(',', $ex_fid_ary) . ') OR f.forum_id IS NULL)' : '';
|
2006-01-11 18:56:07 +00:00
|
|
|
|
2004-10-19 19:26:58 +00:00
|
|
|
if ($show_results == 'posts')
|
|
|
|
{
|
2005-10-02 16:48:17 +00:00
|
|
|
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
|
2004-10-19 19:26:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-02 16:48:17 +00:00
|
|
|
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
|
2004-10-19 19:26:58 +00:00
|
|
|
}
|
2002-01-25 00:48:46 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
// Grab icons
|
2004-02-21 12:47:35 +00:00
|
|
|
$icons = array();
|
2005-10-02 16:48:17 +00:00
|
|
|
$cache->obtain_icons($icons);
|
2002-08-13 16:34:17 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
// Output header
|
2006-01-11 18:56:07 +00:00
|
|
|
if ($search_id && ($total_match_count > 1000))
|
|
|
|
{
|
|
|
|
// limit the number to 1000 for pre-made searches
|
|
|
|
$total_match_count--;
|
|
|
|
$l_search_matches = sprintf($user->lang['FOUND_MORE_SEARCH_MATCHES'], $total_match_count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$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);
|
|
|
|
}
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
// define some vars for urls
|
2005-10-02 16:48:17 +00:00
|
|
|
$hilit = htmlspecialchars(implode('|', str_replace(array('+', '-', '|'), '', $search->split_words)));
|
|
|
|
$split_words = (sizeof($search->split_words)) ? htmlspecialchars(implode(' ', $search->split_words)) : '';
|
2006-01-11 18:56:07 +00:00
|
|
|
$u_hilit = urlencode($split_words);
|
|
|
|
$u_show_results = ($show_results != 'topic') ? '&sr=' . $show_results : '';
|
|
|
|
$u_search_forum = implode('&fid%5B%5D=', $search_forum);
|
|
|
|
|
|
|
|
$u_search = "{$phpbb_root_path}search.$phpEx$SID";
|
|
|
|
$u_search .= ($search_id) ? '&search_id=' . $search_id : '';
|
|
|
|
$u_search .= ($u_hilit) ? '&keywords=' . $u_hilit : '';
|
|
|
|
$u_search .= ($topic_id) ? '&ch=' . $topic_id : '';
|
|
|
|
$u_search .= ($author) ? '&author=' . urlencode($author) : '';
|
|
|
|
$u_search .= ($u_search_forum) ? '&fid%5B%5D=' . $u_search_forum : '';
|
|
|
|
$u_search .= (!$search_child) ? '&sc=0' : '';
|
|
|
|
$u_search .= ($search_fields != 'all') ? '&sf=' . $search_fields : '';
|
|
|
|
$u_search .= '&' . $u_sort_param . $u_show_results;
|
|
|
|
$u_search .= ($return_chars != 200) ? '&ch=' . $return_chars : '';
|
|
|
|
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$template->assign_vars(array(
|
|
|
|
'SEARCH_MATCHES' => $l_search_matches,
|
2006-01-11 18:56:07 +00:00
|
|
|
'SEARCH_WORDS' => $split_words,
|
|
|
|
'IGNORED_WORDS' => (sizeof($search->common_words)) ? htmlspecialchars(implode(' ', $search->common_words)) : '',
|
|
|
|
'PAGINATION' => generate_pagination($u_search, $total_match_count, $per_page, $start),
|
2004-10-19 19:26:58 +00:00
|
|
|
'PAGE_NUMBER' => on_page($total_match_count, $per_page, $start),
|
|
|
|
'TOTAL_MATCHES' => $total_match_count,
|
2006-01-11 18:56:07 +00:00
|
|
|
'SEARCH_IN_RESULTS' => ($search_id) ? false : true,
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
'S_SELECT_SORT_DIR' => $s_sort_dir,
|
|
|
|
'S_SELECT_SORT_KEY' => $s_sort_key,
|
2005-06-13 17:51:55 +00:00
|
|
|
'S_SELECT_SORT_DAYS' => $s_limit_days,
|
2006-01-11 18:56:07 +00:00
|
|
|
'S_SEARCH_ACTION' => $u_search,
|
2004-10-19 19:26:58 +00:00
|
|
|
'S_SHOW_TOPICS' => ($show_results == 'posts') ? false : true,
|
|
|
|
|
|
|
|
'REPORTED_IMG' => $user->img('icon_reported', 'TOPIC_REPORTED'),
|
|
|
|
'UNAPPROVED_IMG' => $user->img('icon_unapproved', 'TOPIC_UNAPPROVED'),
|
|
|
|
'GOTO_PAGE_IMG' => $user->img('icon_post', 'GOTO_PAGE'),
|
2001-11-09 13:00:04 +00:00
|
|
|
|
2006-01-22 19:13:12 +00:00
|
|
|
'U_SEARCH_WORDS' => "{$phpbb_root_path}search.$phpEx$SID$u_show_results&keywords=$u_hilit" . (($author) ? '&author=' . urlencode($author) : ''))
|
2003-09-15 16:33:12 +00:00
|
|
|
);
|
2001-11-09 13:00:04 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
if ($sql_where)
|
2003-09-15 16:33:12 +00:00
|
|
|
{
|
2005-06-13 17:51:55 +00:00
|
|
|
if ($show_results == 'posts')
|
2003-10-05 12:56:53 +00:00
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
/**
|
|
|
|
* @todo Joining this query to the one below?
|
|
|
|
*/
|
2005-06-13 17:51:55 +00:00
|
|
|
$sql = 'SELECT zebra_id, friend, foe
|
2006-01-11 18:56:07 +00:00
|
|
|
FROM ' . ZEBRA_TABLE . '
|
2005-06-13 17:51:55 +00:00
|
|
|
WHERE user_id = ' . $user->data['user_id'];
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
|
|
|
$zebra = array();
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
2003-10-05 12:56:53 +00:00
|
|
|
{
|
2005-06-13 17:51:55 +00:00
|
|
|
$zebra[($row['friend']) ? 'friend' : 'foe'][] = $row['zebra_id'];
|
2003-10-05 12:56:53 +00:00
|
|
|
}
|
2005-06-13 17:51:55 +00:00
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
|
|
|
$sql = 'SELECT p.*, f.forum_id, f.forum_name, t.*, u.username, u.user_sig, u.user_sig_bbcode_uid
|
2006-01-21 22:57:42 +00:00
|
|
|
FROM (' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . POSTS_TABLE . ' p)
|
|
|
|
LEFT JOIN ' . FORUMS_TABLE . " f ON (p.forum_id = f.forum_id)
|
2006-01-11 18:56:07 +00:00
|
|
|
WHERE $sql_where
|
2005-06-13 17:51:55 +00:00
|
|
|
AND p.topic_id = t.topic_id
|
|
|
|
AND p.poster_id = u.user_id";
|
2003-09-15 16:33:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-22 19:13:12 +00:00
|
|
|
$sql_from = TOPICS_TABLE . ' t' . (($sort_key == 'a') ? ', ' . USERS_TABLE . ' u' : '');
|
|
|
|
$sql_select = 't.*, f.forum_id, f.forum_name';
|
|
|
|
if ($user->data['is_registered'])
|
|
|
|
{
|
|
|
|
if ($config['load_db_track'])
|
|
|
|
{
|
|
|
|
$sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.user_id = ' . $user->data['user_id'] . '
|
|
|
|
AND t.topic_id = tp.topic_id)';
|
|
|
|
$sql_select .= ', tp.topic_posted';
|
|
|
|
}
|
|
|
|
if ($config['load_db_lastread'])
|
|
|
|
{
|
|
|
|
$sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $user->data['user_id'] . '
|
|
|
|
AND t.topic_id = tt.topic_id)
|
|
|
|
LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
|
|
|
|
AND ft.forum_id = f.forum_id)';
|
|
|
|
$sql_select .= ', tt.mark_time, ft.mark_time as f_mark_time';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!$user->data['is_registered']) || (!$config['load_db_lastread']))
|
|
|
|
{
|
|
|
|
$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT $sql_select
|
|
|
|
FROM ($sql_from)
|
|
|
|
LEFT JOIN " . FORUMS_TABLE . " f ON (f.forum_id = t.forum_id)
|
|
|
|
WHERE $sql_where" . (($sort_key == 'a') ? ' AND u.user_id = t.topic_poster' : '');
|
2005-06-13 17:51:55 +00:00
|
|
|
}
|
2005-10-02 16:48:17 +00:00
|
|
|
$sql .= ' ORDER BY ' . $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
|
2006-01-11 18:56:07 +00:00
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
$result_topic_id = 0;
|
2003-10-05 12:56:53 +00:00
|
|
|
|
2006-01-22 19:13:12 +00:00
|
|
|
if ($show_results = 'topics')
|
|
|
|
{
|
|
|
|
$forums = $rowset = array();
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
$rowset[$row['topic_id']] = $row;
|
|
|
|
|
|
|
|
if ((!isset($forums[$row['forum_id']])) && ($user->data['is_registered']) && ($config['load_db_lastread']))
|
|
|
|
{
|
|
|
|
$forums[$row['forum_id']]['mark_time'] = $row['f_mark_time'];
|
|
|
|
}
|
|
|
|
$forums[$row['forum_id']]['topic_list'][] = $row['topic_id'];
|
|
|
|
$forums[$row['forum_id']]['rowset'][$row['topic_id']] = &$rowset[$row['topic_id']];
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
|
|
|
foreach ($forums as $forum_id => $forum)
|
|
|
|
{
|
|
|
|
if (($user->data['is_registered']) && ($config['load_db_lastread']))
|
|
|
|
{
|
|
|
|
$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']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $forum['topic_list'], ($forum_id) ? false : $forum['topic_list']);
|
|
|
|
|
|
|
|
if (!$user->data['is_registered'])
|
|
|
|
{
|
|
|
|
$user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($forums);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
$rowset[] = $row;
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($rowset as $row)
|
2005-06-13 17:51:55 +00:00
|
|
|
{
|
|
|
|
$forum_id = $row['forum_id'];
|
2006-01-11 18:56:07 +00:00
|
|
|
$result_topic_id = $row['topic_id'];
|
|
|
|
$topic_title = censor_text($row['topic_title']);
|
2003-10-05 12:56:53 +00:00
|
|
|
|
2006-01-22 19:13:12 +00:00
|
|
|
if (!$forum_id)
|
|
|
|
{
|
|
|
|
if (!isset($g_forum_id))
|
|
|
|
{
|
|
|
|
$availible_forums = array_values(array_diff(array_keys($auth->acl_getf('f_read', true)), $ex_fid_ary));
|
|
|
|
$g_forum_id = $availible_forums[0];
|
|
|
|
}
|
|
|
|
$u_forum_id = $g_forum_id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$u_forum_id = $forum_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$view_topic_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$u_forum_id&t=$result_topic_id&hilit=$u_hilit";
|
2003-10-05 12:56:53 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
if ($show_results == 'topics')
|
2003-09-15 16:33:12 +00:00
|
|
|
{
|
2005-06-13 17:51:55 +00:00
|
|
|
$replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
|
|
|
|
|
|
|
|
$folder_img = $folder_alt = $topic_type = '';
|
2006-01-22 19:13:12 +00:00
|
|
|
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);
|
2005-06-13 17:51:55 +00:00
|
|
|
|
|
|
|
$tpl_ary = array(
|
|
|
|
'TOPIC_AUTHOR' => topic_topic_author($row),
|
|
|
|
'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
|
|
|
|
'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
|
|
|
|
'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
|
|
|
|
'LAST_POST_AUTHOR' => ($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] : $user->lang['GUEST'],
|
|
|
|
'PAGINATION' => topic_generate_pagination($replies, $view_topic_url),
|
|
|
|
'REPLIES' => $replies,
|
|
|
|
'VIEWS' => $row['topic_views'],
|
|
|
|
'TOPIC_TYPE' => $topic_type,
|
|
|
|
|
|
|
|
'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'),
|
|
|
|
'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
|
2005-12-29 01:46:05 +00:00
|
|
|
'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
|
2005-06-13 17:51:55 +00:00
|
|
|
'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
|
|
|
|
'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
|
|
|
|
'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
|
|
|
|
'ATTACH_ICON_IMG' => ($auth->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
|
|
|
|
|
2006-01-21 22:57:42 +00:00
|
|
|
'S_TOPIC_GLOBAL' => (!$forum_id) ? true : false,
|
2005-06-13 17:51:55 +00:00
|
|
|
'S_TOPIC_TYPE' => $row['topic_type'],
|
|
|
|
'S_USER_POSTED' => (!empty($row['mark_type'])) ? true : false,
|
|
|
|
|
|
|
|
'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_gets('m_', $forum_id)) ? true : false,
|
|
|
|
'S_TOPIC_UNAPPROVED' => (!$row['topic_approved'] && $auth->acl_gets('m_approve', $forum_id)) ? true : false,
|
|
|
|
|
|
|
|
'U_LAST_POST' => $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id'],
|
2005-10-02 16:48:17 +00:00
|
|
|
'U_LAST_POST_AUTHOR'=> ($row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&mode=viewprofile&u={$row['topic_last_poster_id']}" : '',
|
2006-01-11 18:56:07 +00:00
|
|
|
'U_MCP_REPORT' => "{$phpbb_root_path}mcp.$phpEx?sid={$user->session_id}&mode=reports&t=$result_topic_id",
|
|
|
|
'U_MCP_QUEUE' => "{$phpbb_root_path}mcp.$phpEx?sid={$user->session_id}&i=queue&mode=approve_details&t=$result_topic_id"
|
2005-06-13 17:51:55 +00:00
|
|
|
);
|
2003-09-15 16:33:12 +00:00
|
|
|
}
|
2005-06-13 17:51:55 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((isset($zebra['foe']) && in_array($row['poster_id'], $zebra['foe'])) && (!$view || $view != 'show' || $post_id != $row['post_id']))
|
|
|
|
{
|
|
|
|
$template->assign_block_vars('searchresults', array(
|
2006-01-11 18:56:07 +00:00
|
|
|
'S_IGNORE_POST' => true,
|
2005-06-13 17:51:55 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
'L_IGNORE_POST' => sprintf($user->lang['POST_BY_FOE'], $row['username'], "<a href=\"$u_search&p=" . $row['post_id'] . '&view=show#' . $row['post_id'] . '">', '</a>'))
|
2005-06-13 17:51:55 +00:00
|
|
|
);
|
2006-01-11 18:56:07 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-05-29 14:25:09 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
if ($row['enable_html'])
|
|
|
|
{
|
|
|
|
$row['post_text'] = preg_replace('#(<!\-\- h \-\-><)([\/]?.*?)(><!\-\- h \-\->)#is', "<\\2>", $row['post_text']);
|
|
|
|
}
|
2004-10-19 19:26:58 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
decode_message($row['post_text'], $row['bbcode_uid']);
|
2006-01-11 18:56:07 +00:00
|
|
|
|
|
|
|
if ($return_chars != -1)
|
2005-06-13 17:51:55 +00:00
|
|
|
{
|
|
|
|
$row['post_text'] = (strlen($row['post_text']) < $return_chars + 3) ? $row['post_text'] : substr($row['post_text'], 0, $return_chars) . '...';
|
|
|
|
}
|
2001-05-29 14:25:09 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
// Replace naughty words such as farty pants
|
|
|
|
$row['post_subject'] = censor_text($row['post_subject']);
|
|
|
|
$row['post_text'] = str_replace("\n", '<br />', censor_text($row['post_text']));
|
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
if ($hilit)
|
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
$row['post_text'] = preg_replace('#(?!<.*)(?<!\w)(' . preg_quote($hilit) . ')(?!\w|[^<>]*>)#i', '<span class="posthilit">$1</span>', $row['post_text']);
|
2005-06-13 17:51:55 +00:00
|
|
|
}
|
2001-05-29 14:25:09 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
$row['post_text'] = smiley_text($row['post_text']);
|
2004-10-19 19:26:58 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
$tpl_ary = array(
|
2006-01-11 18:56:07 +00:00
|
|
|
'POSTER_NAME' => ($row['poster_id'] == ANONYMOUS) ? ((!empty($row['post_username'])) ? $row['post_username'] : $user->lang['GUEST']) : $row['username'],
|
2005-12-30 00:16:43 +00:00
|
|
|
'U_PROFILE' => ($row['poster_id'] != ANONYMOUS) ? "{$phpbb_root_path}memberlist.$phpEx$SID&mode=viewprofile&u={$row['poster_id']}" : '',
|
2006-01-11 18:56:07 +00:00
|
|
|
'POST_SUBJECT' => $row['post_subject'],
|
|
|
|
'POST_DATE' => (!empty($row['post_time'])) ? $user->format_date($row['post_time']) : '',
|
2005-06-13 17:51:55 +00:00
|
|
|
'MESSAGE' => $row['post_text']
|
|
|
|
);
|
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
$template->assign_block_vars('searchresults', array_merge($tpl_ary, array(
|
|
|
|
'FORUM_ID' => $forum_id,
|
2006-01-11 18:56:07 +00:00
|
|
|
'TOPIC_ID' => $result_topic_id,
|
|
|
|
'POST_ID' => ($show_results == 'posts') ? $row['post_id'] : false,
|
2003-09-15 16:33:12 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
'FORUM_TITLE' => $row['forum_name'],
|
|
|
|
'TOPIC_TITLE' => $topic_title,
|
2002-03-31 00:06:34 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
'U_VIEW_TOPIC' => $view_topic_url,
|
2006-01-11 18:56:07 +00:00
|
|
|
'U_VIEW_FORUM' => "viewforum.$phpEx$SID&f=$forum_id",
|
2005-06-13 17:51:55 +00:00
|
|
|
'U_VIEW_POST' => (!empty($row['post_id'])) ? "viewtopic.$phpEx$SID&f=$forum_id&t=" . $row['topic_id'] . '&p=' . $row['post_id'] . '&hilit=' . $u_hilit . '#' . $row['post_id'] : '')
|
|
|
|
));
|
|
|
|
}
|
2006-01-11 18:56:07 +00:00
|
|
|
|
|
|
|
if ($topic_id && ($topic_id == $result_topic_id))
|
|
|
|
{
|
|
|
|
$template->assign_vars(array(
|
|
|
|
'SEARCH_TOPIC' => $topic_title,
|
|
|
|
'U_SEARCH_TOPIC' => $view_topic_url
|
|
|
|
));
|
|
|
|
}
|
2005-06-13 17:51:55 +00:00
|
|
|
}
|
2006-01-22 19:13:12 +00:00
|
|
|
unset($rowset);
|
2002-03-18 22:59:39 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
page_header($user->lang['SEARCH']);
|
2001-05-29 14:25:09 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$template->set_filenames(array(
|
2004-10-19 19:26:58 +00:00
|
|
|
'body' => 'search_results.html')
|
2003-09-15 16:33:12 +00:00
|
|
|
);
|
|
|
|
make_jumpbox('viewforum.'.$phpEx);
|
2001-08-30 22:20:23 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
page_footer();
|
|
|
|
}
|
2002-10-20 19:19:07 +00:00
|
|
|
|
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
// Search forum
|
|
|
|
$s_forums = '';
|
|
|
|
$sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.left_id, f.right_id, f.forum_password, fa.user_id
|
2005-11-28 18:38:49 +00:00
|
|
|
FROM ' . FORUMS_TABLE . ' f
|
2005-10-02 16:48:17 +00:00
|
|
|
LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id
|
2005-11-28 18:38:49 +00:00
|
|
|
AND fa.session_id = '" . $db->sql_escape($user->data['session_id']) . "')
|
2003-09-15 16:33:12 +00:00
|
|
|
ORDER BY f.left_id ASC";
|
|
|
|
$result = $db->sql_query($sql);
|
2001-05-29 14:25:09 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$right = $cat_right = $padding_inc = 0;
|
|
|
|
$padding = $forum_list = $holding = '';
|
|
|
|
$pad_store = array('0' => '');
|
2005-10-02 16:48:17 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
|
|
|
|
{
|
|
|
|
// Non-postable forum with no subforums, don't display
|
|
|
|
continue;
|
|
|
|
}
|
2002-10-04 13:09:10 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
if (!$auth->acl_get('f_list', $row['forum_id']) || $row['forum_type'] == FORUM_LINK || ($row['forum_password'] && !$row['user_id']))
|
|
|
|
{
|
|
|
|
// if the user does not have permissions to list this forum skip
|
|
|
|
continue;
|
|
|
|
}
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
if ($row['left_id'] < $right)
|
|
|
|
{
|
|
|
|
$padding .= ' ';
|
|
|
|
$pad_store[$row['parent_id']] = $padding;
|
2001-05-29 14:25:09 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
else if ($row['left_id'] > $right + 1)
|
2002-03-31 19:13:06 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$padding = $pad_store[$row['parent_id']];
|
2002-03-31 19:13:06 +00:00
|
|
|
}
|
2001-05-29 14:25:09 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$right = $row['right_id'];
|
2001-06-02 16:49:22 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
$selected = (!sizeof($search_forum) || in_array($row['forum_id'], $search_forum)) ? ' selected="selected"' : '';
|
2003-09-15 16:33:12 +00:00
|
|
|
|
|
|
|
if ($row['left_id'] > $cat_right)
|
2001-06-02 16:49:22 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$holding = '';
|
2001-06-02 16:49:22 +00:00
|
|
|
}
|
2001-11-29 13:05:03 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
if ($row['right_id'] - $row['left_id'] > 1)
|
2001-11-29 13:05:03 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$cat_right = max($cat_right, $row['right_id']);
|
|
|
|
|
|
|
|
$holding .= '<option value="' . $row['forum_id'] . '"' . $selected . '>' . $padding . $row['forum_name'] . '</option>';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$s_forums .= $holding . '<option value="' . $row['forum_id'] . '"' . $selected . '>' . $padding . $row['forum_name'] . '</option>';
|
|
|
|
$holding = '';
|
2001-11-29 13:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
$db->sql_freeresult($result);
|
|
|
|
unset($pad_store);
|
|
|
|
|
2001-09-17 00:42:17 +00:00
|
|
|
// Number of chars returned
|
2003-09-15 16:33:12 +00:00
|
|
|
$s_characters = '<option value="-1">' . $user->lang['ALL_AVAILABLE'] . '</option>';
|
2002-02-25 01:00:48 +00:00
|
|
|
$s_characters .= '<option value="0">0</option>';
|
|
|
|
$s_characters .= '<option value="25">25</option>';
|
|
|
|
$s_characters .= '<option value="50">50</option>';
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2005-10-02 16:48:17 +00:00
|
|
|
for ($i = 100; $i <= 1000 ; $i += 100)
|
2001-05-29 14:25:09 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$selected = ($i == 200) ? ' selected="selected"' : '';
|
2002-02-25 01:00:48 +00:00
|
|
|
$s_characters .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
|
2001-05-29 14:25:09 +00:00
|
|
|
}
|
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$template->assign_vars(array(
|
2006-01-11 18:56:07 +00:00
|
|
|
'S_SEARCH_ACTION' => "{$phpbb_root_path}search.$phpEx",
|
|
|
|
'S_HIDDEN_FIELDS' => build_hidden_fields(array('sid' => $user->session_id)),
|
2003-09-15 16:33:12 +00:00
|
|
|
'S_CHARACTER_OPTIONS' => $s_characters,
|
|
|
|
'S_FORUM_OPTIONS' => $s_forums,
|
|
|
|
'S_SELECT_SORT_DIR' => $s_sort_dir,
|
|
|
|
'S_SELECT_SORT_KEY' => $s_sort_key,
|
2004-10-19 19:26:58 +00:00
|
|
|
'S_SELECT_SORT_DAYS' => $s_limit_days)
|
2003-09-15 16:33:12 +00:00
|
|
|
);
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
$sql = 'SELECT search_time, search_keywords
|
2004-10-19 19:26:58 +00:00
|
|
|
FROM ' . SEARCH_TABLE . '
|
2006-01-11 18:56:07 +00:00
|
|
|
WHERE search_keywords <> \'\'
|
2004-10-19 19:26:58 +00:00
|
|
|
ORDER BY search_time DESC';
|
2006-01-11 18:56:07 +00:00
|
|
|
$result = $db->sql_query_limit($sql, 5);
|
2003-09-15 16:33:12 +00:00
|
|
|
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
2001-09-17 00:42:17 +00:00
|
|
|
{
|
2006-01-11 18:56:07 +00:00
|
|
|
$keywords = htmlspecialchars($row['search_keywords']);
|
2003-09-15 16:33:12 +00:00
|
|
|
|
|
|
|
$template->assign_block_vars('recentsearch', array(
|
2006-01-11 18:56:07 +00:00
|
|
|
'KEYWORDS' => $keywords,
|
2005-10-02 16:48:17 +00:00
|
|
|
'TIME' => $user->format_date($row['search_time']),
|
2003-09-15 16:33:12 +00:00
|
|
|
|
2006-01-11 18:56:07 +00:00
|
|
|
'U_KEYWORDS' => "{$phpbb_root_path}search.$phpEx$SID&keywords=" . urlencode($keywords))
|
2003-09-15 16:33:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
2001-05-29 14:25:09 +00:00
|
|
|
|
2002-07-27 16:37:31 +00:00
|
|
|
// Output the basic page
|
2003-05-03 23:58:45 +00:00
|
|
|
page_header($user->lang['SEARCH']);
|
2002-07-27 16:37:31 +00:00
|
|
|
|
|
|
|
$template->set_filenames(array(
|
|
|
|
'body' => 'search_body.html')
|
|
|
|
);
|
|
|
|
make_jumpbox('viewforum.'.$phpEx);
|
2001-05-29 14:25:09 +00:00
|
|
|
|
2003-05-03 23:58:45 +00:00
|
|
|
page_footer();
|
2001-05-29 14:25:09 +00:00
|
|
|
|
2002-04-20 00:22:29 +00:00
|
|
|
?>
|