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
|
|
|
|
*
|
|
|
|
* @todo Introduce phrase searching?
|
|
|
|
* @todo Stemmers?
|
|
|
|
* @todo Find similar?
|
|
|
|
* @todo Relevancy?
|
|
|
|
*/
|
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
|
2002-10-20 19:19:07 +00:00
|
|
|
$user->start();
|
|
|
|
$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
|
|
|
|
$mode = request_var('mode', '');
|
|
|
|
$search_id = request_var('search_id', '');
|
2005-06-13 17:51:55 +00:00
|
|
|
$search_session_id = request_var('search_session_id', 0);
|
2004-09-01 15:47:46 +00:00
|
|
|
$start = request_var('start', 0);
|
|
|
|
$post_id = request_var('p', 0);
|
|
|
|
$view = request_var('view', '');
|
|
|
|
|
|
|
|
$search_keywords = request_var('search_keywords', '');
|
|
|
|
$search_author = request_var('search_author', '');
|
|
|
|
$show_results = request_var('show_results', 'posts');
|
|
|
|
$search_terms = request_var('search_terms', 'all');
|
|
|
|
$search_fields = request_var('search_fields', 'all');
|
|
|
|
$search_child = request_var('search_child', true);
|
|
|
|
|
|
|
|
$return_chars = request_var('return_chars', 200);
|
2004-10-19 19:26:58 +00:00
|
|
|
$search_forum = request_var('search_forum', 0);
|
2004-09-01 15:47:46 +00:00
|
|
|
|
|
|
|
$sort_days = request_var('st', 0);
|
|
|
|
$sort_key = request_var('sk', 't');
|
|
|
|
$sort_dir = request_var('sd', 'd');
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-10-05 12:56:53 +00:00
|
|
|
// Define some vars
|
2003-09-15 16:33:12 +00:00
|
|
|
$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']);
|
2001-05-29 14:25:09 +00:00
|
|
|
|
2004-10-19 19:26:58 +00:00
|
|
|
$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);
|
2001-05-29 14:25:09 +00:00
|
|
|
|
2004-10-19 19:26:58 +00:00
|
|
|
$store_vars = array('sort_key', 'sort_dir', 'sort_days', 'show_results', 'return_chars', 'total_match_count');
|
2003-10-05 12:56:53 +00:00
|
|
|
$current_time = time();
|
|
|
|
|
|
|
|
// Check last search time ... if applicable
|
|
|
|
if ($config['search_interval'])
|
|
|
|
{
|
|
|
|
$sql = 'SELECT MAX(search_time) as last_time
|
|
|
|
FROM ' . SEARCH_TABLE;
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
|
|
|
if ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
if ($row['last_time'] > time() - $config['search_interval'])
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['NO_SEARCH_TIME']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
if ($search_keywords || $search_author || $search_id || $search_session_id)
|
2003-09-15 16:33:12 +00:00
|
|
|
{
|
|
|
|
$post_id_ary = $split_words = $old_split_words = $common_words = array();
|
|
|
|
|
|
|
|
// Which forums can we view?
|
|
|
|
$sql_where = (sizeof($search_forum) && !$search_child) ? 'WHERE f.forum_id IN (' . implode(', ', $search_forum) . ')' : '';
|
|
|
|
$sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.right_id, f.forum_password, fa.user_id
|
|
|
|
FROM (' . FORUMS_TABLE . ' f
|
|
|
|
LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id
|
|
|
|
AND fa.session_id = '" . $db->sql_escape($user->data['session_id']) . "'))
|
|
|
|
$sql_where
|
|
|
|
ORDER BY f.left_id";
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
|
|
|
$right_id = 0;
|
|
|
|
$sql_forums = array();
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
if ($search_child)
|
|
|
|
{
|
2004-09-01 15:47:46 +00:00
|
|
|
if (!$search_forum || (in_array($row['forum_id'], $search_forum) && $row['right_id'] > $right_id))
|
2003-09-15 16:33:12 +00:00
|
|
|
{
|
|
|
|
$right_id = $row['right_id'];
|
|
|
|
}
|
|
|
|
else if ($row['right_id'] > $right_id)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2002-01-25 00:48:46 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
if ($auth->acl_get('f_read', $row['forum_id']) && (!$row['forum_password'] || $row['user_id'] == $user->data['user_id']))
|
|
|
|
{
|
|
|
|
$sql_forums[] = $row['forum_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2003-10-27 13:18:06 +00:00
|
|
|
if (!sizeof($sql_forums))
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['NO_SEARCH_RESULTS']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql_forums = ' AND p.forum_id IN (' . implode(', ', $sql_forums) . ')';
|
2003-09-15 16:33:12 +00:00
|
|
|
unset($search_forum);
|
2001-05-29 14:25:09 +00:00
|
|
|
|
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
if ($search_id == 'egosearch')
|
|
|
|
{
|
|
|
|
$search_author = $user->data['username'];
|
|
|
|
}
|
2002-02-25 01:00:48 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
|
|
|
|
// Are we looking for a user?
|
|
|
|
$sql_author = '';
|
|
|
|
if ($search_author)
|
2001-12-05 00:20:56 +00:00
|
|
|
{
|
2004-10-19 19:26:58 +00:00
|
|
|
$sql_where = (strstr($search_author, '*') !== false) ? ' LIKE ' : ' = ';
|
2003-09-15 16:33:12 +00:00
|
|
|
$sql = 'SELECT user_id
|
|
|
|
FROM ' . USERS_TABLE . "
|
2005-03-21 22:43:07 +00:00
|
|
|
WHERE username $sql_where '" . $db->sql_escape(preg_replace('#\*+#', '%', $search_author)) . "'
|
|
|
|
AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
|
2003-09-15 16:33:12 +00:00
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
|
|
|
if (!$row = $db->sql_fetchrow($result))
|
2001-09-17 00:42:17 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
trigger_error($user->lang['NO_SEARCH_RESULTS']);
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
|
|
|
$sql_author = ' p.poster_id = ' . $row['user_id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($search_id)
|
|
|
|
{
|
2004-10-19 19:26:58 +00:00
|
|
|
$stopped_words = array();
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
if (!$sort_days)
|
|
|
|
{
|
|
|
|
$sort_days = 1;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
$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
|
|
|
|
$sql_forums
|
|
|
|
ORDER BY t.topic_last_post_time DESC";
|
|
|
|
$result = $db->sql_query_limit($sql, 1000);
|
|
|
|
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
$post_id_ary[] = $row['topic_id'];
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
break;
|
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
case 'egosearch':
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'unanswered':
|
|
|
|
if ($show_results == 'posts')
|
2002-02-25 01:00:48 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$sql = 'SELECT p.post_id
|
2003-10-27 13:18:06 +00:00
|
|
|
FROM ' . 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
|
|
|
|
$sql_forums";
|
2003-09-15 16:33:12 +00:00
|
|
|
$field = 'post_id';
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-10-27 13:18:06 +00:00
|
|
|
$sql = 'SELECT t.topic_id
|
|
|
|
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
|
|
|
|
WHERE t.topic_replies = 0
|
|
|
|
AND p.topic_id = t.topic_id
|
|
|
|
$sql_forums
|
|
|
|
GROUP BY p.topic_id";
|
2003-09-15 16:33:12 +00:00
|
|
|
$field = 'topic_id';
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
$result = $db->sql_query($sql);
|
2002-02-25 01:00:48 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
$post_id_ary[] = $row[$field];
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
|
|
|
if (!sizeof($post_id_ary))
|
2002-02-25 01:00:48 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
trigger_error($user->lang['NO_SEARCH_RESULTS']);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'newposts':
|
|
|
|
if ($show_results == 'posts')
|
|
|
|
{
|
2003-10-27 13:18:06 +00:00
|
|
|
$sql = 'SELECT p.post_id
|
|
|
|
FROM ' . POSTS_TABLE . ' p
|
|
|
|
WHERE p.post_time > ' . $user->data['user_lastvisit'] . "
|
|
|
|
$sql_forums";
|
2003-09-15 16:33:12 +00:00
|
|
|
$field = 'post_id';
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$sql = 'SELECT t.topic_id
|
|
|
|
FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p
|
2003-10-27 13:18:06 +00:00
|
|
|
WHERE p.post_time > ' . $user->data['user_lastvisit'] . "
|
|
|
|
AND t.topic_id = p.topic_id
|
|
|
|
$sql_forums
|
|
|
|
GROUP by p.topic_id";
|
2003-09-15 16:33:12 +00:00
|
|
|
$field = 'topic_id';
|
|
|
|
}
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
$post_id_ary[] = $row[$field];
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
$db->sql_freeresult($result);
|
2002-02-25 01:00:48 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
if (!sizeof($post_id_ary))
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['NO_SEARCH_RESULTS']);
|
|
|
|
}
|
|
|
|
break;
|
2005-06-13 17:51:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($search_session_id)
|
|
|
|
{
|
|
|
|
$sql = 'SELECT search_array
|
|
|
|
FROM ' . SEARCH_TABLE . "
|
|
|
|
WHERE search_id = $search_session_id
|
|
|
|
AND session_id = '" . $db->sql_escape($user->data['session_id']) . "'";
|
|
|
|
$result = $db->sql_query($sql);
|
2002-08-13 16:34:17 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
if ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
$data = explode('#', $row['search_array']);
|
2001-12-20 01:25:00 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
$split_words = unserialize(array_shift($data));
|
|
|
|
if ($search_keywords)
|
|
|
|
{
|
|
|
|
// If we're wanting to search on these results we store the existing split word array
|
|
|
|
$old_split_words = $split_words;
|
|
|
|
}
|
|
|
|
$stopped_words = unserialize(array_shift($data));
|
|
|
|
foreach ($store_vars as $var)
|
|
|
|
{
|
|
|
|
$$var = array_shift($data);
|
|
|
|
}
|
2004-10-30 17:01:27 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
$sql_where = (($show_results == 'posts') ? 'p.post_id' : 't.topic_id') . ' IN (' . implode(', ', $data) . ')';
|
|
|
|
unset($data);
|
2003-09-15 16:33:12 +00:00
|
|
|
}
|
2005-06-13 17:51:55 +00:00
|
|
|
$db->sql_freeresult($result);
|
2003-09-15 16:33:12 +00:00
|
|
|
}
|
2001-12-20 01:25:00 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
// TODO: hook in fulltext_phpbb/mysql
|
2002-02-25 01:00:48 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
// Are we looking for words
|
|
|
|
if ($search_keywords)
|
|
|
|
{
|
|
|
|
$sql_author = ($sql_author) ? ' AND ' . $sql_author : '';
|
2002-02-25 01:00:48 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$split_words = $stopped_words = $smllrg_words = array();
|
2004-10-19 19:26:58 +00:00
|
|
|
$drop_char_match = array('-', '^', '$', ';', '#', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '\'', '!', '*');
|
|
|
|
$drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '' , ' ', ' ', ' ', ' ', ' ');
|
2001-12-05 00:20:56 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
if ($fp = @fopen($user->lang_path . '/search_stopwords.txt', 'rb'))
|
|
|
|
{
|
2004-10-19 19:26:58 +00:00
|
|
|
$stopwords = explode("\n", str_replace("\r\n", "\n", fread($fp, filesize($user->lang_path . '/search_stopwords.txt'))));
|
2003-09-15 16:33:12 +00:00
|
|
|
}
|
2004-10-19 19:26:58 +00:00
|
|
|
fclose($fp);
|
2001-12-20 01:25:00 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
if ($fp = @fopen($user->lang_path . '/search_synonyms.txt', 'rb'))
|
|
|
|
{
|
2004-10-19 19:26:58 +00:00
|
|
|
preg_match_all('#^(.*?) (.*?)$#ms', fread($fp, filesize($user->lang_path . '/search_synonyms.txt')), $match);
|
|
|
|
$replace_synonym = &$match[1];
|
|
|
|
$match_synonym = &$match[2];
|
2001-12-05 00:20:56 +00:00
|
|
|
}
|
2004-10-19 19:26:58 +00:00
|
|
|
fclose($fp);
|
2003-09-15 16:33:12 +00:00
|
|
|
|
|
|
|
$match = array('#\sand\s#i', '#\sor\s#i', '#\snot\s#i', '#\+#', '#-#', '#\|#');
|
|
|
|
$replace = array(' + ', ' | ', ' - ', ' + ', ' - ', ' | ');
|
2004-10-19 19:26:58 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$search_keywords = preg_replace($match, $replace, $search_keywords);
|
|
|
|
|
|
|
|
$match = array();
|
2004-10-19 19:26:58 +00:00
|
|
|
// Comments for hardcoded bbcode elements (urls, smilies, html)
|
|
|
|
$match[] = '#<!\-\- .* \-\->(.*?)<!\-\- .* \-\->#is';
|
2003-09-15 16:33:12 +00:00
|
|
|
// New lines, carriage returns
|
|
|
|
$match[] = "#[\n\r]+#";
|
|
|
|
// NCRs like etc.
|
2004-10-19 19:26:58 +00:00
|
|
|
$match[] = '#(&|&)[\#a-z0-9]+?;#i';
|
2003-09-15 16:33:12 +00:00
|
|
|
// BBcode
|
2004-10-19 19:26:58 +00:00
|
|
|
$match[] = '#\[\/?[a-z\*\+\-]+(=.*)?(\:?[0-9a-z]{5,})\]#';
|
2003-09-15 16:33:12 +00:00
|
|
|
|
|
|
|
// Filter out as above
|
2004-10-19 19:26:58 +00:00
|
|
|
$search_keywords = preg_replace($match, ' ', strtolower(trim($search_keywords)));
|
2003-09-15 16:33:12 +00:00
|
|
|
$search_keywords = str_replace($drop_char_match, $drop_char_replace, $search_keywords);
|
|
|
|
|
|
|
|
// Split words
|
|
|
|
$split_words = explode(' ', preg_replace('#\s+#', ' ', $search_keywords));
|
|
|
|
|
2004-10-19 19:26:58 +00:00
|
|
|
if (sizeof($stopwords))
|
2001-12-05 00:20:56 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$stopped_words = array_intersect($split_words, $stopwords);
|
|
|
|
$split_words = array_diff($split_words, $stopwords);
|
|
|
|
}
|
2002-08-13 16:34:17 +00:00
|
|
|
|
2004-10-19 19:26:58 +00:00
|
|
|
if (sizeof($replace_synonym))
|
2003-09-15 16:33:12 +00:00
|
|
|
{
|
|
|
|
$split_words = str_replace($replace_synonym, $match_synonym, $split_words);
|
|
|
|
}
|
|
|
|
}
|
2002-01-12 17:00:32 +00:00
|
|
|
|
2004-10-30 17:01:27 +00:00
|
|
|
if (isset($old_split_words) && sizeof($old_split_words))
|
|
|
|
{
|
|
|
|
$split_words = (sizeof($split_words)) ? array_diff($split_words, $old_split_words) : $old_split_words;
|
|
|
|
}
|
2002-01-14 14:16:54 +00:00
|
|
|
|
2004-10-30 17:01:27 +00:00
|
|
|
if (sizeof($split_words))
|
2003-09-15 16:33:12 +00:00
|
|
|
{
|
2004-09-01 15:47:46 +00:00
|
|
|
|
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
// This "entire" section may be switched out to allow for alternative search systems
|
|
|
|
// such as that built-in to MySQL, MSSQL, etc. or external solutions which provide
|
|
|
|
// an appropriate API
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2004-09-01 15:47:46 +00:00
|
|
|
$bool = ($search_terms == 'all') ? 'AND' : 'OR';
|
2003-09-15 16:33:12 +00:00
|
|
|
$sql_words = '';
|
|
|
|
foreach ($split_words as $word)
|
|
|
|
{
|
|
|
|
switch ($word)
|
2001-11-09 13:00:04 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
case '-':
|
|
|
|
$bool = 'NOT';
|
|
|
|
continue;
|
|
|
|
case '+':
|
|
|
|
$bool = 'AND';
|
|
|
|
continue;
|
|
|
|
case '|':
|
|
|
|
$bool = 'OR';
|
|
|
|
continue;
|
|
|
|
default:
|
2004-09-01 15:47:46 +00:00
|
|
|
$bool = ($search_terms != 'all') ? 'OR' : $bool;
|
2003-09-15 16:33:12 +00:00
|
|
|
$sql_words[$bool][] = "'" . preg_replace('#\*+#', '%', trim($word)) . "'";
|
2004-09-01 15:47:46 +00:00
|
|
|
$bool = ($search_terms == 'all') ? 'AND' : 'OR';
|
2003-09-15 16:33:12 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-22 01:00:14 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
switch ($search_fields)
|
|
|
|
{
|
|
|
|
case 'titleonly':
|
|
|
|
$sql_match = ' AND m.title_match = 1';
|
|
|
|
break;
|
|
|
|
case 'msgonly':
|
|
|
|
$sql_match = ' AND m.title_match = 0';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$sql_match = '';
|
|
|
|
}
|
2001-11-20 23:45:27 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
// Build some display specific variable strings
|
|
|
|
$sql_select = ($show_results == 'posts') ? 'm.post_id' : 'DISTINCT t.topic_id';
|
|
|
|
$sql_from = ($show_results == 'posts') ? '' : TOPICS_TABLE . ' t, ';
|
|
|
|
$sql_topic = ($show_results == 'posts') ? '' : 'AND t.topic_id = p.topic_id';
|
|
|
|
$sql_time = ($sort_days) ? 'AND p.post_time >= ' . ($current_time - ($sort_days * 86400)) : '';
|
|
|
|
$field = ($show_results == 'posts') ? 'm.post_id' : 't.topic_id';
|
2001-11-20 23:45:27 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
// Are we searching within an existing search set? Yes, then include the old ids
|
|
|
|
$sql_find_in = ($sql_where) ? "AND $sql_where" : '';
|
2001-11-20 23:45:27 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$result_ary = array();
|
|
|
|
foreach (array('AND', 'OR', 'NOT') as $bool)
|
|
|
|
{
|
2004-10-19 19:26:58 +00:00
|
|
|
if (isset($sql_words[$bool]) && is_array($sql_words[$bool]))
|
2003-09-15 16:33:12 +00:00
|
|
|
{
|
|
|
|
switch ($bool)
|
|
|
|
{
|
|
|
|
case 'AND':
|
|
|
|
case 'NOT':
|
|
|
|
foreach ($sql_words[$bool] as $word)
|
2001-11-22 01:00:14 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
if (strlen($word) < 4)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2002-02-25 01:00:48 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$sql_where = (strstr($word, '%')) ? "LIKE $word" : "= $word";
|
|
|
|
|
2004-10-19 19:26:58 +00:00
|
|
|
$sql_and = (isset($result_ary['AND']) && sizeof($result_ary['AND'])) ? "AND $field IN (" . implode(', ', $result_ary['AND']) . ')' : '';
|
2003-09-15 16:33:12 +00:00
|
|
|
|
|
|
|
$sql = "SELECT $sql_select
|
|
|
|
FROM $sql_from" . POSTS_TABLE . ' p, ' . SEARCH_MATCH_TABLE . ' m, ' . SEARCH_WORD_TABLE . " w
|
|
|
|
WHERE w.word_text $sql_where
|
|
|
|
AND m.word_id = w.word_id
|
|
|
|
AND w.word_common <> 1
|
|
|
|
AND p.post_id = m.post_id
|
|
|
|
$sql_topic
|
|
|
|
$sql_forums
|
|
|
|
$sql_author
|
|
|
|
$sql_and
|
|
|
|
$sql_time
|
|
|
|
$sql_match
|
|
|
|
$sql_find_in";
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
|
|
|
if (!($row = $db->sql_fetchrow($result)) && $bool == 'AND')
|
2002-02-25 01:00:48 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
trigger_error($user->lang['NO_SEARCH_RESULTS']);
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
|
|
|
|
if ($bool == 'AND')
|
2002-02-25 01:00:48 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$result_ary['AND'] = array();
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
|
|
|
|
do
|
2002-02-25 01:00:48 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$result_ary[$bool][] = ($show_results == 'topics') ? $row['topic_id'] : $row['post_id'];
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
while ($row = $db->sql_fetchrow($result));
|
|
|
|
$db->sql_freeresult($result);
|
2001-11-22 01:00:14 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
break;
|
2002-01-14 14:16:54 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
case 'OR':
|
|
|
|
$sql_where = $sql_in = '';
|
|
|
|
foreach ($sql_words[$bool] as $word)
|
2002-02-25 01:00:48 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
if (strlen($word) < 4)
|
2002-02-25 01:00:48 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
continue;
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
2002-01-14 14:16:54 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
if (strstr($word, '%'))
|
|
|
|
{
|
|
|
|
$sql_where .= (($sql_where) ? ' OR w.word_text ' : 'w.word_text ') . "LIKE $word";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$sql_in .= (($sql_in) ? ', ' : '') . $word;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$sql_where = ($sql_in) ? (($sql_where) ? ' OR ' : '') . 'w.word_text IN (' . $sql_in . ')' : $sql_where;
|
|
|
|
|
|
|
|
$sql_and = (sizeof($result_ary['AND'])) ? "AND $field IN (" . implode(', ', $result_ary['AND']) . ')' : '';
|
|
|
|
$sql = "SELECT $sql_select
|
|
|
|
FROM $sql_from" . POSTS_TABLE . ' p, ' . SEARCH_MATCH_TABLE . ' m, ' . SEARCH_WORD_TABLE . " w
|
|
|
|
WHERE ($sql_where)
|
|
|
|
AND m.word_id = w.word_id
|
|
|
|
AND w.word_common <> 1
|
|
|
|
AND p.post_id = m.post_id
|
|
|
|
$sql_topic
|
|
|
|
$sql_forums
|
|
|
|
$sql_author
|
|
|
|
$sql_and
|
|
|
|
$sql_time
|
2004-09-01 15:47:46 +00:00
|
|
|
$sql_match
|
2003-09-15 16:33:12 +00:00
|
|
|
$sql_find_in";
|
|
|
|
$result = $db->sql_query($sql);
|
2002-01-14 14:16:54 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
$result_ary[$bool][] = ($show_results == 'topics') ? $row['topic_id'] : $row['post_id'];
|
|
|
|
}
|
2002-02-25 01:00:48 +00:00
|
|
|
$db->sql_freeresult($result);
|
2003-09-15 16:33:12 +00:00
|
|
|
break;
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
2002-08-13 16:34:17 +00:00
|
|
|
}
|
2004-10-19 19:26:58 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$sql_words[$bool] = array();
|
|
|
|
}
|
2001-11-09 13:00:04 +00:00
|
|
|
}
|
|
|
|
|
2004-10-19 19:26:58 +00:00
|
|
|
if (isset($result_ary['OR']) && sizeof($result_ary['OR']))
|
2002-02-25 01:00:48 +00:00
|
|
|
{
|
2004-10-19 19:26:58 +00:00
|
|
|
$post_id_ary = (isset($result_ary['AND']) && sizeof($result_ary['AND'])) ? array_diff($result_ary['AND'], $result_ary['OR']) : $result_ary['OR'];
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
|
|
|
else
|
2001-11-09 13:00:04 +00:00
|
|
|
{
|
2004-10-19 19:26:58 +00:00
|
|
|
$post_id_ary = (isset($result_ary['AND'])) ? $result_ary['AND'] : array();
|
2001-12-05 00:20:56 +00:00
|
|
|
}
|
2001-11-09 13:00:04 +00:00
|
|
|
|
2004-10-19 19:26:58 +00:00
|
|
|
if (isset($result_ary['NOT']) && sizeof($result_ary['NOT']))
|
2001-12-05 00:20:56 +00:00
|
|
|
{
|
2004-10-19 19:26:58 +00:00
|
|
|
$post_id_ary = (sizeof($post_id_ary)) ? array_diff($post_id_ary, $result_ary['NOT']) : array();
|
2001-12-05 00:20:56 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
unset($result_ary);
|
2002-08-13 16:34:17 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$post_id_ary = array_unique($post_id_ary);
|
2002-01-25 00:48:46 +00:00
|
|
|
|
2004-09-01 15:47:46 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
if (!sizeof($post_id_ary))
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['NO_SEARCH_RESULTS']);
|
|
|
|
}
|
2002-01-25 00:48:46 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$sql = 'SELECT word_text
|
|
|
|
FROM ' . SEARCH_WORD_TABLE . '
|
|
|
|
WHERE word_text IN (' . implode(', ', array_unique(array_merge($sql_words['AND'], $sql_words['OR'], $sql_words['NOT']))) . ')
|
|
|
|
AND word_common = 1';
|
|
|
|
$result = $db->sql_query($sql);
|
2002-02-25 01:00:48 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
while ($row = $db->sql_fetchrow($result))
|
2002-02-03 18:54:56 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$common_words[] = $row['word_text'];
|
2002-01-25 00:48:46 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
$db->sql_freeresult($result);
|
|
|
|
}
|
|
|
|
else if ($search_author)
|
|
|
|
{
|
|
|
|
if ($show_results == 'posts')
|
2001-12-05 00:20:56 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$sql = 'SELECT p.post_id
|
|
|
|
FROM ' . POSTS_TABLE . " p
|
|
|
|
WHERE $sql_author
|
|
|
|
$sql_forums";
|
|
|
|
$field = 'post_id';
|
2001-12-05 00:20:56 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
else
|
2002-02-25 01:00:48 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$sql = 'SELECT t.topic_id
|
|
|
|
FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p
|
|
|
|
WHERE $sql_author
|
|
|
|
$sql_forums
|
|
|
|
AND t.topic_id = p.topic_id
|
|
|
|
GROUP BY t.topic_id";
|
|
|
|
$field = 'topic_id';
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
$result = $db->sql_query($sql);
|
2002-01-25 00:48:46 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
while ($row = $db->sql_fetchrow($result))
|
2002-02-25 01:00:48 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$post_id_ary[] = $row[$field];
|
2001-11-09 13:00:04 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
$db->sql_freeresult($result);
|
2001-09-17 00:42:17 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
$total_match_count = 0;
|
2003-09-15 16:33:12 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
if ($post_id_ary && sizeof($post_id_ary))
|
2001-09-17 00:42:17 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
// Finish building query (for all combinations) and run it ...
|
|
|
|
$sql = 'SELECT session_id
|
|
|
|
FROM ' . SESSIONS_TABLE;
|
|
|
|
if ($result = $db->sql_query($sql))
|
2001-05-31 11:47:43 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$delete_search_ids = array();
|
2004-10-19 19:26:58 +00:00
|
|
|
while ($row = $db->sql_fetchrow($result))
|
2002-03-31 13:47:53 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$delete_search_ids[] = "'" . $db->sql_escape($row['session_id']) . "'";
|
2002-03-31 13:47:53 +00:00
|
|
|
}
|
2001-05-29 14:25:09 +00:00
|
|
|
|
2004-10-19 19:26:58 +00:00
|
|
|
if (sizeof($delete_search_ids))
|
2002-02-25 01:00:48 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$sql = 'DELETE FROM ' . SEARCH_TABLE . '
|
|
|
|
WHERE session_id NOT IN (' . implode(", ", $delete_search_ids) . ')';
|
|
|
|
$db->sql_query($sql);
|
2002-02-25 01:00:48 +00:00
|
|
|
}
|
2001-09-17 00:42:17 +00:00
|
|
|
}
|
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$total_match_count = sizeof($post_id_ary);
|
|
|
|
$sql_where = (($show_results == 'posts') ? 'p.post_id' : 't.topic_id') . ' IN (' . implode(', ', $post_id_ary) . ')';
|
|
|
|
|
|
|
|
if (sizeof($old_split_words) && array_diff($split_words, $old_split_words))
|
2002-01-25 00:48:46 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$split_words = array_merge($split_words, $old_split_words);
|
2002-01-25 00:48:46 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
$data = serialize(array_diff($split_words, $common_words));
|
|
|
|
$data .= '#' . serialize(array_merge($stopped_words, $common_words));
|
|
|
|
foreach ($store_vars as $var)
|
2002-01-25 00:48:46 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
$data .= '#' . $$var;
|
2002-01-25 00:48:46 +00:00
|
|
|
}
|
2003-09-15 16:33:12 +00:00
|
|
|
$data .= '#' . implode('#', $post_id_ary);
|
|
|
|
unset($post_id_ary);
|
2002-04-20 00:22:29 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
srand ((double) microtime() * 1000000);
|
2005-06-13 17:51:55 +00:00
|
|
|
$search_session_id = rand();
|
2002-01-25 00:48:46 +00:00
|
|
|
|
2004-10-19 19:26:58 +00:00
|
|
|
$sql_ary = array(
|
2005-06-13 17:51:55 +00:00
|
|
|
'search_id' => $search_session_id,
|
2004-10-19 19:26:58 +00:00
|
|
|
'session_id' => $user->data['session_id'],
|
|
|
|
'search_time' => $current_time,
|
|
|
|
'search_array' => $data
|
|
|
|
);
|
|
|
|
|
|
|
|
$sql = 'INSERT INTO ' . SEARCH_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
|
2003-09-15 16:33:12 +00:00
|
|
|
$db->sql_query($sql);
|
|
|
|
unset($data);
|
|
|
|
}
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2004-10-19 19:26:58 +00:00
|
|
|
if ($show_results == 'posts')
|
|
|
|
{
|
|
|
|
include($phpbb_root_path . 'includes/functions_posting.'.$phpEx);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
include($phpbb_root_path . 'includes/functions_display.'.$phpEx);
|
|
|
|
}
|
2002-01-25 00:48:46 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
// Look up data ...
|
|
|
|
$per_page = ($show_results == 'posts') ? $config['posts_per_page'] : $config['topics_per_page'];
|
2002-08-13 16:34:17 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
// Grab icons
|
2004-02-21 12:47:35 +00:00
|
|
|
$icons = array();
|
2003-09-15 16:33:12 +00:00
|
|
|
obtain_icons($icons);
|
2002-08-13 16:34:17 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
// Output header
|
|
|
|
$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
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$hilit = htmlspecialchars(implode('|', str_replace(array('+', '-', '|'), '', $split_words)));
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$split_words = htmlspecialchars(implode(' ', $split_words));
|
|
|
|
$ignored_words = htmlspecialchars(implode(' ', $stopped_words));
|
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,
|
|
|
|
'SEARCH_WORDS' => $split_words,
|
2004-10-19 19:26:58 +00:00
|
|
|
'IGNORED_WORDS' => ($ignored_words) ? $ignored_words : '',
|
2005-06-13 17:51:55 +00:00
|
|
|
'PAGINATION' => generate_pagination("search.$phpEx$SID&search_session_id=$search_session_id&search_id=$search_id&hilit=$hilit&$u_sort_param", $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,
|
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,
|
|
|
|
'S_SEARCH_ACTION' => "{$phpbb_root_path}search.$phpEx$SID&search_session_id=$search_session_id&search_id=$search_id",
|
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
|
|
|
|
2004-10-19 19:26:58 +00:00
|
|
|
'U_SEARCH_WORDS' => "search.$phpEx$SID&show_results=$show_results&search_keywords=" . urlencode($split_words))
|
2003-09-15 16:33:12 +00:00
|
|
|
);
|
2001-11-09 13:00:04 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$u_hilit = urlencode($split_words);
|
2001-11-09 13:00:04 +00:00
|
|
|
|
2003-10-05 12:56:53 +00:00
|
|
|
// Define ordering sql field, do it here because the order may be defined
|
|
|
|
// within an existing search result set
|
|
|
|
$sort_by_sql = array('a' => (($show_results == 'posts') ? 'u.username' : 't.topic_poster'), 't' => (($show_results == 'posts') ? 'p.post_time' : 't.topic_last_post_time'), 'f' => 'f.forum_id', 'i' => 't.topic_title', 's' => (($show_results == 'posts') ? 'pt.post_subject' : 't.topic_title'));
|
|
|
|
|
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
|
|
|
{
|
2005-06-13 17:51:55 +00:00
|
|
|
// Not joining this query to the one below at present ... may do in future
|
|
|
|
$sql = 'SELECT zebra_id, friend, foe
|
|
|
|
FROM ' . ZEBRA_TABLE . '
|
|
|
|
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
|
|
|
|
FROM ' . FORUMS_TABLE . ' f, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . POSTS_TABLE . " p
|
|
|
|
WHERE $sql_where
|
|
|
|
AND f.forum_id = p.forum_id
|
|
|
|
AND p.topic_id = t.topic_id
|
|
|
|
AND p.poster_id = u.user_id";
|
2003-09-15 16:33:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-13 17:51:55 +00:00
|
|
|
$sql = 'SELECT t.*, f.forum_id, f.forum_name
|
|
|
|
FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
|
|
|
|
WHERE $sql_where
|
|
|
|
AND f.forum_id = t.forum_id";
|
|
|
|
}
|
|
|
|
$sql .= ' ORDER BY ' . $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC') . " LIMIT $start, $per_page";
|
|
|
|
$result = $db->sql_query($sql);
|
2003-10-05 12:56:53 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
|
|
|
$forum_id = $row['forum_id'];
|
|
|
|
$topic_id = $row['topic_id'];
|
2003-10-05 12:56:53 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
$view_topic_url = "viewtopic.$phpEx$SID&f=$forum_id&t=$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 = '';
|
|
|
|
topic_status($row, $replies, time(), time(), $folder_img, $folder_alt, $topic_type);
|
|
|
|
|
|
|
|
$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),
|
|
|
|
'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']) : '',
|
|
|
|
|
|
|
|
'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'],
|
|
|
|
'U_LAST_POST_AUTHOR'=> ($row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id']) ? "memberlist.$phpEx$SID&mode=viewprofile&u={$row['topic_last_poster_id']}" : '',
|
|
|
|
'U_MCP_REPORT' => "mcp.$phpEx?sid={$user->session_id}&mode=reports&t=$topic_id",
|
|
|
|
'U_MCP_QUEUE' => "mcp.$phpEx?sid={$user->session_id}&i=queue&mode=approve_details&t=$topic_id"
|
|
|
|
);
|
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(
|
|
|
|
'S_IGNORE_POST' => true,
|
|
|
|
|
|
|
|
'L_IGNORE_POST' => sprintf($user->lang['POST_BY_FOE'], $row['username'], "<a href=\"search.$phpEx$SID&search_session_id=$search_session_id&$u_sort_param&p=" . $row['post_id'] . '&view=show#' . $row['post_id'] . '">', '</a>'))
|
|
|
|
);
|
|
|
|
|
|
|
|
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
|
|
|
$row['post_text'] = censor_text($row['post_text']);
|
|
|
|
decode_message($row['post_text'], $row['bbcode_uid']);
|
2004-10-19 19:26:58 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
if ($return_chars)
|
|
|
|
{
|
|
|
|
$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
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
if ($hilit)
|
|
|
|
{
|
|
|
|
// This was shamelessly 'borrowed' from volker at multiartstudio dot de
|
|
|
|
// via php.net's annotated manual
|
|
|
|
$row['post_text'] = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace('#\b(" . str_replace('\\', '\\\\', $hilit) . ")\b#i', '<span class=\"posthilit\">\\\\1</span>', '\\0')", '>' . $row['post_text'] . '<'), 1, -1));
|
|
|
|
}
|
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
|
|
|
// 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']));
|
2002-03-18 22:59:39 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
$tpl_ary = array(
|
|
|
|
'POSTER_NAME' => ($row['poster_id'] == ANONYMOUS) ? ((!empty($row['post_username'])) ? $row['post_username'] : $user->lang['GUEST']) : $row['username'],
|
|
|
|
'POST_SUBJECT' => censor_text($row['post_subject']),
|
|
|
|
'POST_DATE' => (!empty($row['post_time'])) ? $user->format_date($row['post_time']) : '',
|
|
|
|
'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,
|
|
|
|
'TOPIC_ID' => $topic_id,
|
|
|
|
'POST_ID' => ($show_results == 'posts') ? $row['post_id'] : false,
|
2003-09-15 16:33:12 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
'FORUM_TITLE' => $row['forum_name'],
|
|
|
|
'TOPIC_TITLE' => censor_text($row['topic_title']),
|
2002-03-31 00:06:34 +00:00
|
|
|
|
2005-06-13 17:51:55 +00:00
|
|
|
'U_VIEW_TOPIC' => $view_topic_url,
|
|
|
|
'U_VIEW_FORUM' => "viewforum.$phpEx$SID&f=$forum_id",
|
|
|
|
'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'] : '')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$template->assign_vars(array(
|
|
|
|
'S_NO_SEARCH_RESULTS' => true)
|
|
|
|
);
|
|
|
|
}
|
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
|
|
|
|
FROM (' . FORUMS_TABLE . ' f
|
|
|
|
LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id
|
|
|
|
AND fa.session_id = '" . $db->sql_escape($user->data['session_id']) . "'))
|
|
|
|
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' => '');
|
2004-10-19 19:26:58 +00:00
|
|
|
$search_forums = array();
|
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
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$selected = (!sizeof($search_forums) || in_array($row['forum_id'], $search_forums)) ? ' selected="selected"' : '';
|
|
|
|
|
|
|
|
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
|
|
|
|
2003-09-15 16:33:12 +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(
|
|
|
|
'S_SEARCH_ACTION' => "search.$phpEx$SID&mode=results",
|
|
|
|
'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
|
|
|
|
2003-10-05 12:56:53 +00:00
|
|
|
$sql = 'SELECT search_id, search_time, search_array
|
2004-10-19 19:26:58 +00:00
|
|
|
FROM ' . SEARCH_TABLE . '
|
|
|
|
ORDER BY search_time DESC';
|
2003-09-15 16:33:12 +00:00
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
2001-09-17 00:42:17 +00:00
|
|
|
{
|
2003-09-15 16:33:12 +00:00
|
|
|
if ($i == 5)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2001-09-17 00:42:17 +00:00
|
|
|
|
2003-09-15 16:33:12 +00:00
|
|
|
$data = explode('#', $row['search_array']);
|
|
|
|
$split_words = htmlspecialchars(implode(' ', unserialize(array_shift($data))));
|
|
|
|
|
|
|
|
if (!$split_words)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$stopped_words = htmlspecialchars(implode(' ', unserialize(array_shift($data))));
|
|
|
|
unset($data);
|
|
|
|
|
|
|
|
$template->assign_block_vars('recentsearch', array(
|
|
|
|
'KEYWORDS' => $split_words,
|
2003-10-05 12:56:53 +00:00
|
|
|
'TIME' => $user->format_date($row['search_time']),
|
2003-09-15 16:33:12 +00:00
|
|
|
|
2004-07-08 22:41:04 +00:00
|
|
|
'U_KEYWORDS' => "search.$phpEx$SID&search_keywords=" . urlencode($split_words))
|
2003-09-15 16:33:12 +00:00
|
|
|
);
|
2004-07-08 22:41:04 +00:00
|
|
|
|
|
|
|
$i++;
|
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
|
|
|
?>
|