2001-11-17 17:44:31 +00:00
< ? php
2007-10-05 14:30:11 +00:00
/**
2005-04-09 12:26:45 +00:00
*
* @ package phpBB3
2007-10-05 14:30:11 +00:00
* @ copyright ( c ) 2005 phpBB Group
2011-12-31 13:32:52 +00:00
* @ license http :// opensource . org / licenses / gpl - 2.0 . php GNU General Public License v2
2005-04-09 12:26:45 +00:00
*
*/
2003-06-06 15:24:26 +00:00
2005-04-09 12:26:45 +00:00
/**
2006-05-05 17:56:33 +00:00
* @ ignore
2005-04-09 12:26:45 +00:00
*/
2002-03-18 13:35:43 +00:00
define ( 'IN_PHPBB' , true );
2007-07-26 15:51:11 +00:00
$phpbb_root_path = ( defined ( 'PHPBB_ROOT_PATH' )) ? PHPBB_ROOT_PATH : './' ;
2003-09-15 16:33:12 +00:00
$phpEx = substr ( strrchr ( __FILE__ , '.' ), 1 );
2006-06-06 20:53:46 +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
2006-03-26 01:36:26 +00:00
$submit = request_var ( 'submit' , false );
2007-07-22 20:11:45 +00:00
$keywords = utf8_normalize_nfc ( request_var ( 'keywords' , '' , true ));
$add_keywords = utf8_normalize_nfc ( request_var ( 'add_keywords' , '' , true ));
2007-06-19 12:36:07 +00:00
$author = request_var ( 'author' , '' , true );
2006-05-28 19:06:21 +00:00
$author_id = request_var ( 'author_id' , 0 );
2006-02-12 18:35:16 +00:00
$show_results = ( $topic_id ) ? 'posts' : request_var ( 'sr' , 'posts' );
2006-03-26 01:36:26 +00:00
$show_results = ( $show_results == 'posts' ) ? 'posts' : 'topics' ;
2006-01-11 18:56:07 +00:00
$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
2007-07-15 20:53:27 +00:00
$return_chars = request_var ( 'ch' , ( $topic_id ) ? - 1 : 300 );
2006-01-11 18:56:07 +00:00
$search_forum = request_var ( 'fid' , array ( 0 ));
2010-10-17 15:42:13 +08:00
// We put login boxes for the case if search_id is newposts, egosearch or unreadposts
2010-01-18 15:50:13 +00:00
// because a guest should be able to log in even if guests search is not permitted
2010-10-17 15:42:13 +08:00
switch ( $search_id )
2010-01-18 15:50:13 +00:00
{
2010-10-17 15:42:13 +08:00
// Egosearch is an author search
case 'egosearch' :
$author_id = $user -> data [ 'user_id' ];
if ( $user -> data [ 'user_id' ] == ANONYMOUS )
{
login_box ( '' , $user -> lang [ 'LOGIN_EXPLAIN_EGOSEARCH' ]);
}
break ;
2010-01-18 15:50:13 +00:00
2010-10-17 15:42:13 +08:00
// Search for unread posts needs to be allowed and user to be logged in if topics tracking for guests is disabled
case 'unreadposts' :
if ( ! $config [ 'load_unreads_search' ])
{
$template -> assign_var ( 'S_NO_SEARCH' , true );
trigger_error ( 'NO_SEARCH_UNREADS' );
}
else if ( ! $config [ 'load_anon_lastread' ] && ! $user -> data [ 'is_registered' ])
{
login_box ( '' , $user -> lang [ 'LOGIN_EXPLAIN_UNREADSEARCH' ]);
}
break ;
2011-08-15 20:00:47 -04:00
2010-10-17 15:42:13 +08:00
// The "new posts" search uses user_lastvisit which is user based, so it should require user to log in.
case 'newposts' :
if ( $user -> data [ 'user_id' ] == ANONYMOUS )
{
login_box ( '' , $user -> lang [ 'LOGIN_EXPLAIN_NEWPOSTS' ]);
}
break ;
2011-08-15 20:00:47 -04:00
2010-10-17 15:42:13 +08:00
default :
// There's nothing to do here for now ;)
break ;
2010-01-18 15:50:13 +00:00
}
2003-04-15 23:21:05 +00:00
// Is user able to search? Has search been disabled?
2006-02-12 18:35:16 +00:00
if ( ! $auth -> acl_get ( 'u_search' ) || ! $auth -> acl_getf_global ( 'f_search' ) || ! $config [ 'load_search' ])
2003-04-15 23:21:05 +00:00
{
2007-07-15 13:47:01 +00:00
$template -> assign_var ( 'S_NO_SEARCH' , true );
2007-07-22 14:04:26 +00:00
trigger_error ( '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' ])))
{
2007-07-15 13:47:01 +00:00
$template -> assign_var ( 'S_NO_SEARCH' , true );
2007-07-22 14:04:26 +00:00
trigger_error ( 'NO_SEARCH_TIME' );
2006-01-11 18:56:07 +00:00
}
2003-10-05 12:56:53 +00:00
2010-08-20 14:22:56 -05:00
// It is applicable if the configuration setting is non-zero, and the user cannot
// ignore the flood setting, and the search is a keyword search.
2006-05-28 19:06:21 +00:00
$interval = ( $user -> data [ 'user_id' ] == ANONYMOUS ) ? $config [ 'search_anonymous_interval' ] : $config [ 'search_interval' ];
2010-08-20 14:22:56 -05:00
if ( $interval && ! in_array ( $search_id , array ( 'unreadposts' , 'unanswered' , 'active_topics' , 'egosearch' )) && ! $auth -> acl_get ( 'u_ignoreflood' ))
2003-10-05 12:56:53 +00:00
{
2006-05-28 19:06:21 +00:00
if ( $user -> data [ 'user_last_search' ] > time () - $interval )
2003-10-05 12:56:53 +00:00
{
2007-07-15 13:47:01 +00:00
$template -> assign_var ( 'S_NO_SEARCH' , true );
2007-07-22 14:04:26 +00:00
trigger_error ( '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
2006-03-23 19:23:52 +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' ], 365 => $user -> lang [ '1_YEAR' ]);
2006-01-11 18:56:07 +00:00
$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 );
2006-05-28 19:06:21 +00:00
if ( $keywords || $author || $author_id || $search_id || $submit )
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 ();
2006-11-25 20:00:56 +00:00
// If we are looking for authors get their ids
$author_id_ary = array ();
2009-07-02 10:28:32 +00:00
$sql_author_match = '' ;
2006-11-25 20:00:56 +00:00
if ( $author_id )
{
$author_id_ary [] = $author_id ;
}
else if ( $author )
{
2007-01-28 13:43:46 +00:00
if (( strpos ( $author , '*' ) !== false ) && ( utf8_strlen ( str_replace ( array ( '*' , '%' ), '' , $author )) < $config [ 'min_search_author_chars' ]))
2006-11-25 20:00:56 +00:00
{
2011-09-14 00:28:52 +02:00
trigger_error ( $user -> lang ( 'TOO_FEW_AUTHOR_CHARS' , ( int ) $config [ 'min_search_author_chars' ]));
2006-11-25 20:00:56 +00:00
}
2007-06-24 12:49:13 +00:00
$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 )) . " ' " ;
2007-06-23 12:16:20 +00:00
2006-11-25 20:00:56 +00:00
$sql = ' SELECT user_id
FROM ' . USERS_TABLE . "
2007-06-23 12:16:20 +00:00
WHERE $sql_where
2009-07-08 12:48:07 +00:00
AND user_type <> " . USER_IGNORE;
2006-11-25 20:00:56 +00:00
$result = $db -> sql_query_limit ( $sql , 100 );
while ( $row = $db -> sql_fetchrow ( $result ))
{
$author_id_ary [] = ( int ) $row [ 'user_id' ];
}
$db -> sql_freeresult ( $result );
2009-07-02 10:28:32 +00:00
$sql_where = ( strpos ( $author , '*' ) !== false ) ? ' post_username ' . $db -> sql_like_expression ( str_replace ( '*' , $db -> any_char , utf8_clean_string ( $author ))) : " post_username = ' " . $db -> sql_escape ( utf8_clean_string ( $author )) . " ' " ;
$sql = ' SELECT 1 as guest_post
FROM ' . POSTS_TABLE . "
WHERE $sql_where
AND poster_id = " . ANONYMOUS;
$result = $db -> sql_query_limit ( $sql , 1 );
$found_guest_post = $db -> sql_fetchfield ( 'guest_post' );
$db -> sql_freeresult ( $result );
if ( $found_guest_post )
{
$author_id_ary [] = ANONYMOUS ;
$sql_author_match = ( strpos ( $author , '*' ) !== false ) ? ' ' . $db -> sql_like_expression ( str_replace ( '*' , $db -> any_char , utf8_clean_string ( $author ))) : " = ' " . $db -> sql_escape ( utf8_clean_string ( $author )) . " ' " ;
}
2006-11-25 20:00:56 +00:00
if ( ! sizeof ( $author_id_ary ))
{
2007-07-22 14:04:26 +00:00
trigger_error ( 'NO_SEARCH_RESULTS' );
2006-11-25 20:00:56 +00:00
}
}
// 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' ;
2006-11-27 19:32:18 +00:00
$keywords = implode ( ' |' , explode ( ' ' , preg_replace ( '#\s+#u' , ' ' , $keywords ))) . ' ' . $add_keywords ;
2006-11-25 20:00:56 +00:00
}
}
// Which forums should not be searched? Author searches are also carried out in unindexed forums
2007-05-13 16:15:20 +00:00
if ( empty ( $keywords ) && sizeof ( $author_id_ary ))
2006-11-25 20:00:56 +00:00
{
$ex_fid_ary = array_keys ( $auth -> acl_getf ( '!f_read' , true ));
}
else
{
$ex_fid_ary = array_unique ( array_merge ( array_keys ( $auth -> acl_getf ( '!f_read' , true )), array_keys ( $auth -> acl_getf ( '!f_search' , true ))));
}
2003-09-15 16:33:12 +00:00
2006-08-12 13:14:39 +00:00
$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' ] . ')' : " " ;
2006-06-06 20:53:46 +00:00
2009-06-17 09:08:24 +00:00
$sql = ' SELECT f . forum_id , f . forum_name , f . parent_id , f . forum_type , f . right_id , f . forum_password , f . forum_flags , fa . user_id
2005-11-28 18:38:49 +00:00
FROM ' . FORUMS_TABLE . ' f
2007-01-26 16:09:51 +00:00
LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id
2006-05-28 19:06:21 +00:00
AND fa . session_id = '" . $db->sql_escape($user->session_id) . "' )
2006-07-12 23:21:57 +00:00
$not_in_fid
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-09-15 14:08:48 +00:00
if ( $row [ 'forum_password' ] && $row [ 'user_id' ] != $user -> data [ 'user_id' ])
2006-01-11 18:56:07 +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
continue ;
}
2009-06-17 09:08:24 +00:00
// Exclude forums from active topics
if ( ! ( $row [ 'forum_flags' ] & FORUM_FLAG_ACTIVE_TOPICS ) && ( $search_id == 'active_topics' ))
{
$ex_fid_ary [] = ( int ) $row [ 'forum_id' ];
continue ;
}
2006-01-11 18:56:07 +00:00
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
2012-08-30 22:57:00 +02:00
// find out in which forums the user is allowed to view posts
2012-10-01 22:44:39 +02:00
$m_approve_posts_fid_sql = phpbb_content_visibility :: get_global_visibility_sql ( 'post' , $ex_fid_ary , 'p.' );
$m_approve_topics_fid_sql = phpbb_content_visibility :: get_global_visibility_sql ( 'topic' , $ex_fid_ary , 't.' );
2006-03-06 18:21:54 +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
// Select which method we'll use to obtain the post_id or topic_id information
2011-08-15 20:00:47 -04:00
$search_type = $config [ 'search_type' ];
2006-01-11 18:56:07 +00:00
2011-08-15 20:00:47 -04:00
if ( ! class_exists ( $search_type ))
2006-01-11 18:56:07 +00:00
{
trigger_error ( 'NO_SUCH_SEARCH_MODULE' );
2003-09-15 16:33:12 +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 ;
2012-08-08 11:07:47 +05:30
$search = new $search_type ( $error , $phpbb_root_path , $phpEx , $auth , $config , $db , $user );
2006-01-11 18:56:07 +00:00
if ( $error )
{
trigger_error ( $error );
}
// let the search module split up the keywords
if ( $keywords )
{
2006-11-27 20:31:06 +00:00
$correct_query = $search -> split_keywords ( $keywords , $search_terms );
if ( ! $correct_query || ( empty ( $search -> search_query ) && ! sizeof ( $author_id_ary ) && ! $search_id ))
2006-01-11 18:56:07 +00:00
{
2007-02-25 22:09:53 +00:00
$ignored = ( sizeof ( $search -> common_words )) ? sprintf ( $user -> lang [ 'IGNORED_TERMS_EXPLAIN' ], implode ( ' ' , $search -> common_words )) . '<br />' : '' ;
2011-09-20 01:33:33 +02:00
trigger_error ( $ignored . $user -> lang ( 'NO_KEYWORDS' , $user -> lang ( 'CHARACTERS' , ( int ) $search -> word_length [ 'min' ]), $user -> lang ( 'CHARACTERS' , ( int ) $search -> word_length [ 'max' ])));
2006-01-11 18:56:07 +00:00
}
}
2006-01-22 19:13:12 +00:00
if ( ! $keywords && sizeof ( $author_id_ary ))
{
2006-05-28 19:06:21 +00:00
// if it is an author search we want to show topics by default
2006-02-12 18:35:16 +00:00
$show_results = ( $topic_id ) ? 'posts' : request_var ( 'sr' , ( $search_id == 'egosearch' ) ? 'topics' : 'posts' );
2006-03-26 01:36:26 +00:00
$show_results = ( $show_results == 'posts' ) ? 'posts' : 'topics' ;
2006-01-22 19:13:12 +00:00
}
2006-01-11 18:56:07 +00:00
// define some variables needed for retrieving post_id/topic_id information
2006-11-24 14:59:26 +00:00
$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' ));
2006-01-11 18:56:07 +00:00
// pre-made searches
2006-12-27 00:06:39 +00:00
$sql = $field = $l_search_title = '' ;
2003-09-15 16:33:12 +00:00
if ( $search_id )
{
switch ( $search_id )
{
2005-06-13 17:51:55 +00:00
// Oh holy Bob, bring us some activity...
case 'active_topics' :
2006-12-27 00:06:39 +00:00
$l_search_title = $user -> lang [ 'SEARCH_ACTIVE_TOPICS' ];
2005-06-13 17:51:55 +00:00
$show_results = 'topics' ;
2006-01-11 18:56:07 +00:00
$sort_key = 't' ;
$sort_dir = 'd' ;
2006-11-23 16:15:46 +00:00
$sort_days = request_var ( 'st' , 7 );
2006-01-11 18:56:07 +00:00
$sort_by_sql [ 't' ] = 't.topic_last_post_time' ;
2005-06-13 17:51:55 +00:00
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 );
2006-09-17 22:02:28 +00:00
$s_sort_key = $s_sort_dir = '' ;
2005-06-13 17:51:55 +00:00
2006-11-23 16:15:46 +00:00
$last_post_time_sql = ( $sort_days ) ? ' AND t.topic_last_post_time > ' . ( time () - ( $sort_days * 24 * 3600 )) : '' ;
2005-06-13 17:51:55 +00:00
2006-09-17 22:02:28 +00:00
$sql = ' SELECT t . topic_last_post_time , t . topic_id
FROM ' . TOPICS_TABLE . " t
2006-11-23 16:15:46 +00:00
WHERE t . topic_moved_id = 0
$last_post_time_sql
2012-08-30 22:20:52 +02:00
AND " . $m_approve_topics_fid_sql . '
2006-09-17 22:02:28 +00:00
' . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set(' t . forum_id ', $ex_fid_ary, true) : ' ') . '
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-12-27 00:06:39 +00:00
$l_search_title = $user -> lang [ 'SEARCH_UNANSWERED' ];
2006-02-12 18:35:16 +00:00
$show_results = request_var ( 'sr' , 'topics' );
2006-03-26 01:36:26 +00:00
$show_results = ( $show_results == 'posts' ) ? 'posts' : 'topics' ;
2006-02-12 18:35:16 +00:00
$sort_by_sql [ 't' ] = ( $show_results == 'posts' ) ? 'p.post_time' : 't.topic_last_post_time' ;
$sort_by_sql [ 's' ] = ( $show_results == 'posts' ) ? 'p.post_subject' : 't.topic_title' ;
2006-03-26 01:36:26 +00:00
$sql_sort = 'ORDER BY ' . $sort_by_sql [ $sort_key ] . (( $sort_dir == 'a' ) ? ' ASC' : ' DESC' );
2006-02-12 18:35:16 +00:00
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 ;
2006-06-06 20:53:46 +00:00
2006-09-17 22:02:28 +00:00
if ( $sort_days )
{
$last_post_time = 'AND p.post_time > ' . ( time () - ( $sort_days * 24 * 3600 ));
}
else
{
$last_post_time = '' ;
}
2007-06-19 11:45:29 +00:00
if ( $sort_key == 'a' )
{
$sort_join = USERS_TABLE . ' u, ' ;
$sql_sort = ' AND u.user_id = p.poster_id ' . $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
$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-09-17 22:02:28 +00:00
$last_post_time
2012-08-30 22:20:52 +02:00
AND $m_approve_posts_fid_sql
2006-08-12 13:14:39 +00:00
" . ((sizeof( $ex_fid_ary )) ? ' AND ' . $db->sql_in_set ('p.forum_id', $ex_fid_ary , true) : '') . "
2006-01-11 18:56:07 +00:00
$sql_sort " ;
2003-09-15 16:33:12 +00:00
$field = 'post_id' ;
2002-02-25 01:00:48 +00:00
}
else
{
2006-03-26 01:36:26 +00:00
$sql = 'SELECT DISTINCT ' . $sort_by_sql [ $sort_key ] . " , p.topic_id
2006-01-11 18:56:07 +00:00
FROM $sort_join " . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
2005-10-02 16:48:17 +00:00
WHERE t . topic_replies = 0
2006-08-12 18:46:47 +00:00
AND t . topic_moved_id = 0
2003-10-27 13:18:06 +00:00
AND p . topic_id = t . topic_id
2006-09-17 22:02:28 +00:00
$last_post_time
2012-08-30 22:20:52 +02:00
AND $m_approve_topics_fid_sql
2006-08-12 13:14:39 +00:00
" . ((sizeof( $ex_fid_ary )) ? ' AND ' . $db->sql_in_set ('p.forum_id', $ex_fid_ary , true) : '') . "
2006-01-11 18:56:07 +00:00
$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
2009-07-14 14:46:38 +00:00
case 'unreadposts' :
2009-09-07 12:39:37 +00:00
$l_search_title = $user -> lang [ 'SEARCH_UNREAD' ];
// force sorting
$show_results = 'topics' ;
$sort_key = 't' ;
$sort_by_sql [ 't' ] = 't.topic_last_post_time' ;
$sql_sort = 'ORDER BY ' . $sort_by_sql [ $sort_key ] . (( $sort_dir == 'a' ) ? ' ASC' : ' DESC' );
$sql_where = ' AND t . topic_moved_id = 0
2012-08-30 22:20:52 +02:00
AND ' . $m_approve_topics_fid_sql . '
2009-09-07 12:39:37 +00:00
' . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set(' t . forum_id ', $ex_fid_ary, true) : ' ' );
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 = $s_limit_days = '' ;
2009-08-17 13:28:28 +00:00
break ;
2009-07-14 14:46:38 +00:00
2003-09-15 16:33:12 +00:00
case 'newposts' :
2006-12-27 00:06:39 +00:00
$l_search_title = $user -> lang [ 'SEARCH_NEW' ];
2006-06-23 12:19:27 +00:00
// force sorting
$show_results = ( request_var ( 'sr' , 'topics' ) == 'posts' ) ? 'posts' : 'topics' ;
$sort_key = 't' ;
$sort_dir = 'd' ;
2006-02-12 18:35:16 +00:00
$sort_by_sql [ 't' ] = ( $show_results == 'posts' ) ? 'p.post_time' : 't.topic_last_post_time' ;
2006-03-26 01:36:26 +00:00
$sql_sort = 'ORDER BY ' . $sort_by_sql [ $sort_key ] . (( $sort_dir == 'a' ) ? ' ASC' : ' DESC' );
2006-02-12 18:35:16 +00:00
2006-06-23 12:19:27 +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 = $s_limit_days = '' ;
2006-06-06 20:53:46 +00:00
2003-09-15 16:33:12 +00:00
if ( $show_results == 'posts' )
{
2006-06-23 12:19:27 +00:00
$sql = ' SELECT p . post_id
FROM ' . POSTS_TABLE . ' p
2012-08-30 19:47:16 +02:00
WHERE p . post_time > ' . $user->data[' user_lastvisit '] . '
2012-08-30 22:20:52 +02:00
AND ' . $m_approve_posts_fid_sql . '
2012-08-30 19:47:16 +02:00
' . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set(' p . forum_id ', $ex_fid_ary, true) : ' ' ) . "
2006-01-11 18:56:07 +00:00
$sql_sort " ;
2003-09-15 16:33:12 +00:00
$field = 'post_id' ;
2002-02-25 01:00:48 +00:00
}
else
{
2009-04-26 14:53:05 +00:00
$sql = ' SELECT t . topic_id
FROM ' . TOPICS_TABLE . ' t
WHERE t . topic_last_post_time > ' . $user->data[' user_lastvisit '] . '
AND t . topic_moved_id = 0
2012-08-30 22:20:52 +02:00
AND ' . $m_approve_topics_fid_sql . '
2009-04-26 14:53:05 +00:00
' . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set(' t . forum_id ', $ex_fid_ary, true) : ' ' ) . "
$sql_sort " ;
/*
2009-04-26 15:12:54 +00:00
[ Fix ] queued replies missing from " view new posts " ( Bug #42705 - Patch by Paul)
- Creates temporary table , query is far from optimized
2009-04-26 14:53:05 +00:00
$sql = ' SELECT t . topic_id
2009-04-24 17:27:10 +00:00
FROM ' . TOPICS_TABLE . ' t , ' . POSTS_TABLE . ' p
WHERE p . post_time > ' . $user->data[' user_lastvisit '] . '
AND t . topic_id = p . topic_id
2009-04-26 14:53:05 +00:00
AND t . topic_moved_id = 0
2012-08-30 22:20:52 +02:00
AND ' . $m_approve_topics_fid_sql . "
2009-04-26 15:11:32 +00:00
GROUP BY t . topic_id
2009-04-26 14:53:05 +00:00
$sql_sort " ;
*/
2003-09-15 16:33:12 +00:00
$field = 'topic_id' ;
}
2006-01-22 19:13:12 +00:00
break ;
2006-12-27 00:06:39 +00:00
case 'egosearch' :
$l_search_title = $user -> lang [ 'SEARCH_SELF' ];
break ;
2005-06-13 17:51:55 +00:00
}
2006-05-28 19:06:21 +00:00
}
2002-08-13 16:34:17 +00:00
2006-05-28 19:06:21 +00:00
// show_results should not change after this
$per_page = ( $show_results == 'posts' ) ? $config [ 'posts_per_page' ] : $config [ 'topics_per_page' ];
2006-11-23 16:15:46 +00:00
$total_match_count = 0 ;
2006-05-28 19:06:21 +00:00
2012-01-14 15:50:47 +08:00
// Set limit for the $total_match_count to reduce server load
$total_matches_limit = 1000 ;
$found_more_search_matches = false ;
2006-05-28 19:06:21 +00:00
if ( $search_id )
{
2006-01-11 18:56:07 +00:00
if ( $sql )
2005-06-13 17:51:55 +00:00
{
2012-02-26 02:19:12 +01:00
// Only return up to $total_matches_limit+1 ids (the last one will be removed later)
2012-02-26 02:29:49 +01:00
$result = $db -> sql_query_limit ( $sql , $total_matches_limit + 1 );
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
{
2009-03-19 13:25:00 +00:00
$id_ary [] = ( int ) $row [ $field ];
2005-06-13 17:51:55 +00:00
}
2006-01-11 18:56:07 +00:00
$db -> sql_freeresult ( $result );
2001-11-09 13:00:04 +00:00
}
2010-05-17 21:14:02 +08:00
else if ( $search_id == 'unreadposts' )
{
2012-02-26 02:19:12 +01:00
// Only return up to $total_matches_limit+1 ids (the last one will be removed later)
2012-02-26 02:29:49 +01:00
$id_ary = array_keys ( get_unread_topics ( $user -> data [ 'user_id' ], $sql_where , $sql_sort , $total_matches_limit + 1 ));
2010-05-17 21:14:02 +08: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
}
2002-01-25 00:48:46 +00:00
2012-02-26 02:19:12 +01:00
$total_match_count = sizeof ( $id_ary );
if ( $total_match_count )
{
// Limit the number to $total_matches_limit for pre-made searches
if ( $total_match_count > $total_matches_limit )
2011-12-18 16:28:35 +08:00
{
2012-02-26 02:19:12 +01:00
$found_more_search_matches = true ;
$total_match_count = $total_matches_limit ;
2011-12-18 16:28:35 +08:00
}
2012-02-26 02:19:12 +01:00
// Make sure $start is set to the last page if it exceeds the amount
if ( $start < 0 )
2012-01-14 15:50:47 +08:00
{
$start = 0 ;
}
2012-02-26 02:19:12 +01:00
else if ( $start >= $total_match_count )
{
$start = floor (( $total_match_count - 1 ) / $per_page ) * $per_page ;
}
$id_ary = array_slice ( $id_ary , $start , $per_page );
2010-05-17 21:14:02 +08:00
}
2006-01-11 18:56:07 +00:00
else
2001-05-31 11:47:43 +00:00
{
2012-02-26 02:19:12 +01:00
// Set $start to 0 if no matches were found
$start = 0 ;
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-05-28 19:06:21 +00:00
// make sure that some arrays are always in the same order
sort ( $ex_fid_ary );
2010-06-17 23:58:18 -05:00
// @TODO sort($m_approve_fid_ary);
2006-05-28 19:06:21 +00:00
sort ( $author_id_ary );
2006-07-27 19:02:47 +00:00
if ( ! empty ( $search -> search_query ))
2006-01-11 18:56:07 +00:00
{
2012-08-30 19:47:16 +02:00
$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_posts_fid_sql , $topic_id , $author_id_ary , $sql_author_match , $id_ary , $start , $per_page );
2006-01-11 18:56:07 +00:00
}
else if ( sizeof ( $author_id_ary ))
{
2008-11-01 19:00:50 +00:00
$firstpost_only = ( $search_fields === 'firstpost' || $search_fields == 'titleonly' ) ? true : false ;
2012-08-30 19:47:16 +02:00
$total_match_count = $search -> author_search ( $show_results , $firstpost_only , $sort_by_sql , $sort_key , $sort_dir , $sort_days , $ex_fid_ary , $m_approve_posts_fid_sql , $topic_id , $author_id_ary , $sql_author_match , $id_ary , $start , $per_page );
2006-01-11 18:56:07 +00:00
}
2004-10-19 19:26:58 +00:00
2006-11-23 16:15:46 +00:00
// For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options.
2006-11-25 20:00:56 +00:00
if ( ! sizeof ( $id_ary ) && ! $search_id )
2006-01-11 18:56:07 +00:00
{
2007-07-22 14:04:26 +00:00
trigger_error ( 'NO_SEARCH_RESULTS' );
2003-09-15 16:33:12 +00:00
}
2001-09-17 00:42:17 +00:00
2006-11-23 16:15:46 +00:00
$sql_where = '' ;
if ( sizeof ( $id_ary ))
{
$sql_where .= $db -> sql_in_set (( $show_results == 'posts' ) ? 'p.post_id' : 't.topic_id' , $id_ary );
$sql_where .= ( sizeof ( $ex_fid_ary )) ? ' AND (' . $db -> sql_in_set ( 'f.forum_id' , $ex_fid_ary , true ) . ' OR f.forum_id IS NULL)' : '' ;
2012-08-30 22:20:52 +02:00
$sql_where .= ' AND ' . (( $show_results == 'posts' ) ? $m_approve_posts_fid_sql : $m_approve_topics_fid_sql );
2006-11-23 16:15:46 +00:00
}
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
2007-09-12 15:32:11 +00:00
$user -> add_lang ( 'viewtopic' );
2003-09-15 16:33:12 +00:00
// Grab icons
2006-11-12 15:35:43 +00:00
$icons = $cache -> obtain_icons ();
2002-08-13 16:34:17 +00:00
2003-09-15 16:33:12 +00:00
// Output header
2012-01-14 15:50:47 +08:00
if ( $found_more_search_matches )
2006-01-11 18:56:07 +00:00
{
2011-09-14 00:28:52 +02:00
$l_search_matches = $user -> lang ( 'FOUND_MORE_SEARCH_MATCHES' , ( int ) $total_match_count );
2006-01-11 18:56:07 +00:00
}
else
{
2011-09-14 00:28:52 +02:00
$l_search_matches = $user -> lang ( 'FOUND_SEARCH_MATCHES' , ( int ) $total_match_count );
2006-01-11 18:56:07 +00:00
}
2001-09-17 00:42:17 +00:00
2006-01-11 18:56:07 +00:00
// define some vars for urls
2007-04-22 17:12:31 +00:00
$hilit = implode ( '|' , explode ( ' ' , preg_replace ( '#\s+#u' , ' ' , str_replace ( array ( '+' , '-' , '|' , '(' , ')' , '"' ), ' ' , $keywords ))));
2008-06-22 11:02:04 +00:00
// Do not allow *only* wildcard being used for hilight
$hilit = ( strspn ( $hilit , '*' ) === strlen ( $hilit )) ? '' : $hilit ;
2007-04-22 17:12:31 +00:00
$u_hilit = urlencode ( htmlspecialchars_decode ( str_replace ( '|' , ' ' , $hilit )));
2009-09-07 12:39:37 +00:00
$u_show_results = '&sr=' . $show_results ;
2006-01-11 18:56:07 +00:00
$u_search_forum = implode ( '&fid%5B%5D=' , $search_forum );
2006-06-06 20:53:46 +00:00
$u_search = append_sid ( " { $phpbb_root_path } search. $phpEx " , $u_sort_param . $u_show_results );
2006-01-11 18:56:07 +00:00
$u_search .= ( $search_id ) ? '&search_id=' . $search_id : '' ;
2009-07-25 12:35:46 +00:00
$u_search .= ( $u_hilit ) ? '&keywords=' . urlencode ( htmlspecialchars_decode ( $keywords )) : '' ;
2008-09-15 11:11:39 +00:00
$u_search .= ( $search_terms != 'all' ) ? '&terms=' . $search_terms : '' ;
2006-06-06 20:53:46 +00:00
$u_search .= ( $topic_id ) ? '&t=' . $topic_id : '' ;
2007-04-01 22:15:59 +00:00
$u_search .= ( $author ) ? '&author=' . urlencode ( htmlspecialchars_decode ( $author )) : '' ;
2006-05-28 19:06:21 +00:00
$u_search .= ( $author_id ) ? '&author_id=' . $author_id : '' ;
2006-01-11 18:56:07 +00:00
$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 : '' ;
2007-07-15 20:53:27 +00:00
$u_search .= ( $return_chars != 300 ) ? '&ch=' . $return_chars : '' ;
2006-01-11 18:56:07 +00:00
2012-06-26 01:27:14 +05:30
// Check if search backend supports phrase search or not
2012-06-28 19:07:24 +05:30
$phrase_search_disabled = '' ;
2012-07-03 03:54:01 +05:30
if ( strpos ( html_entity_decode ( $keywords ), '"' ) !== false && method_exists ( $search , 'supports_phrase_search' ))
2012-07-01 12:45:18 +05:30
{
2012-07-03 03:54:01 +05:30
$phrase_search_disabled = $search -> supports_phrase_search () ? false : true ;
2012-07-01 12:45:18 +05:30
}
2012-07-12 02:36:00 +01:00
phpbb_generate_template_pagination ( $template , $u_search , 'pagination' , 'start' , $total_match_count , $per_page , $start );
2012-07-04 23:19:59 +01:00
2003-09-15 16:33:12 +00:00
$template -> assign_vars ( array (
2006-12-27 00:06:39 +00:00
'SEARCH_TITLE' => $l_search_title ,
2003-09-15 16:33:12 +00:00
'SEARCH_MATCHES' => $l_search_matches ,
2012-06-20 11:14:16 +05:30
'SEARCH_WORDS' => $keywords ,
2012-06-22 15:16:13 +05:30
'SEARCHED_QUERY' => $search -> search_query ,
2007-02-25 22:09:53 +00:00
'IGNORED_WORDS' => ( sizeof ( $search -> common_words )) ? implode ( ' ' , $search -> common_words ) : '' ,
2012-07-08 21:07:28 +01:00
'PAGE_NUMBER' => phpbb_on_page ( $template , $user , $u_search , $total_match_count , $per_page , $start ),
2012-07-01 12:45:18 +05:30
2012-06-28 19:07:24 +05:30
'PHRASE_SEARCH_DISABLED' => $phrase_search_disabled ,
2012-07-01 12:45:18 +05:30
2004-10-19 19:26:58 +00:00
'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 ,
2006-08-08 19:02:44 +00:00
'GOTO_PAGE_IMG' => $user -> img ( 'icon_post_target' , 'GOTO_PAGE' ),
'NEWEST_POST_IMG' => $user -> img ( 'icon_topic_newest' , 'VIEW_NEWEST_POST' ),
'REPORTED_IMG' => $user -> img ( 'icon_topic_reported' , 'TOPIC_REPORTED' ),
'UNAPPROVED_IMG' => $user -> img ( 'icon_topic_unapproved' , 'TOPIC_UNAPPROVED' ),
#10005, #10003, #10001, #9999, #9945, #9965, #9909, #9906, #9877, #9861, #9831, #9830, #9815, #9665, #9624
prosilver adjustments for important announcements in ucp - #9995
MCP fixes for user notes/warnings - #9981
Preserving imageset values on save/edit
find a member link for Mass PM's - #9925
syndicate window.onload events where necessary - #9878
Duplicate topics in forums with announcements - #9840
Email template for forced re-activation - #9808
Topic pagination adjustment - #9763
Changed compose message layout in UCP - #9706, #9702
Fixed inline attachment font size (hopefully)
git-svn-id: file:///svn/phpbb/trunk@7384 89ea8834-ac86-4346-8a33-228a782c2dd0
2007-04-22 15:27:40 +00:00
'LAST_POST_IMG' => $user -> img ( 'icon_topic_latest' , 'VIEW_LATEST_POST' ),
2001-11-09 13:00:04 +00:00
#10005, #10003, #10001, #9999, #9945, #9965, #9909, #9906, #9877, #9861, #9831, #9830, #9815, #9665, #9624
prosilver adjustments for important announcements in ucp - #9995
MCP fixes for user notes/warnings - #9981
Preserving imageset values on save/edit
find a member link for Mass PM's - #9925
syndicate window.onload events where necessary - #9878
Duplicate topics in forums with announcements - #9840
Email template for forced re-activation - #9808
Topic pagination adjustment - #9763
Changed compose message layout in UCP - #9706, #9702
Fixed inline attachment font size (hopefully)
git-svn-id: file:///svn/phpbb/trunk@7384 89ea8834-ac86-4346-8a33-228a782c2dd0
2007-04-22 15:27:40 +00:00
'U_SEARCH_WORDS' => $u_search ,
));
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
{
2007-01-05 11:21:09 +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 );
2006-12-02 13:19:40 +00:00
$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
2006-02-12 18:35:16 +00:00
FROM ' . POSTS_TABLE . ' p
LEFT JOIN ' . TOPICS_TABLE . ' t ON ( p . topic_id = t . topic_id )
LEFT JOIN ' . FORUMS_TABLE . ' f ON ( p . forum_id = f . forum_id )
LEFT JOIN ' . USERS_TABLE . " u ON (p.poster_id = u.user_id)
WHERE $sql_where " ;
2003-09-15 16:33:12 +00:00
}
else
{
2006-02-12 18:35:16 +00:00
$sql_from = TOPICS_TABLE . ' t
LEFT JOIN ' . FORUMS_TABLE . ' f ON ( f . forum_id = t . forum_id )
' . (($sort_key == ' a ') ? ' LEFT JOIN ' . USERS_TABLE . ' u ON ( u . user_id = t . topic_poster ) ' : ' ' );
2006-01-22 19:13:12 +00:00
$sql_select = 't.*, f.forum_id, f.forum_name' ;
2006-06-06 20:53:46 +00:00
2006-01-22 19:13:12 +00:00
if ( $user -> data [ 'is_registered' ])
{
2008-09-15 11:11:39 +00:00
if ( $config [ 'load_db_track' ] && $author_id !== $user -> data [ 'user_id' ])
2006-01-22 19:13:12 +00:00
{
$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' ;
}
2006-03-06 14:03:56 +00:00
2006-01-22 19:13:12 +00:00
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' ;
}
}
2006-08-09 21:03:46 +00:00
if ( $config [ 'load_anon_lastread' ] || ( $user -> data [ 'is_registered' ] && ! $config [ 'load_db_lastread' ]))
2006-01-22 19:13:12 +00:00
{
2010-10-14 22:03:09 +02:00
$tracking_topics = $request -> variable ( $config [ 'cookie_name' ] . '_track' , '' , true , phpbb_request_interface :: COOKIE );
2007-03-04 22:08:44 +00:00
$tracking_topics = ( $tracking_topics ) ? tracking_unserialize ( $tracking_topics ) : array ();
2006-01-22 19:13:12 +00:00
}
$sql = " SELECT $sql_select
2006-02-12 18:35:16 +00:00
FROM $sql_from
WHERE $sql_where " ;
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-07-07 18:43:52 +00:00
$rowset = array ();
2006-02-12 18:35:16 +00:00
if ( $show_results == 'topics' )
2006-01-22 19:13:12 +00:00
{
2006-08-12 18:46:47 +00:00
$forums = $rowset = $shadow_topic_list = array ();
2006-01-22 19:13:12 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
{
2009-12-14 17:43:37 +00:00
$row [ 'forum_id' ] = ( int ) $row [ 'forum_id' ];
$row [ 'topic_id' ] = ( int ) $row [ 'topic_id' ];
2006-08-12 18:46:47 +00:00
if ( $row [ 'topic_status' ] == ITEM_MOVED )
{
$shadow_topic_list [ $row [ 'topic_moved_id' ]] = $row [ 'topic_id' ];
}
2006-01-22 19:13:12 +00:00
$rowset [ $row [ 'topic_id' ]] = $row ;
2006-01-27 18:49:02 +00:00
if ( ! isset ( $forums [ $row [ 'forum_id' ]]) && $user -> data [ 'is_registered' ] && $config [ 'load_db_lastread' ])
2006-01-22 19:13:12 +00:00
{
$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 );
2007-10-05 14:30:11 +00:00
2006-11-24 14:59:26 +00:00
// If we have some shadow topics, update the rowset to reflect their topic information
2006-08-12 18:46:47 +00:00
if ( sizeof ( $shadow_topic_list ))
{
$sql = ' SELECT *
FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set(' topic_id ' , array_keys ( $shadow_topic_list ));
$result = $db -> sql_query ( $sql );
2008-06-22 11:02:04 +00:00
2006-08-12 18:46:47 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
{
$orig_topic_id = $shadow_topic_list [ $row [ 'topic_id' ]];
2008-06-22 11:02:04 +00:00
2006-08-12 18:46:47 +00:00
// We want to retain some values
$row = array_merge ( $row , array (
'topic_moved_id' => $rowset [ $orig_topic_id ][ 'topic_moved_id' ],
'topic_status' => $rowset [ $orig_topic_id ][ 'topic_status' ],
'forum_name' => $rowset [ $orig_topic_id ][ 'forum_name' ])
);
2008-06-22 11:02:04 +00:00
2006-08-12 18:46:47 +00:00
$rowset [ $orig_topic_id ] = $row ;
}
$db -> sql_freeresult ( $result );
}
unset ( $shadow_topic_list );
2006-01-22 19:13:12 +00:00
foreach ( $forums as $forum_id => $forum )
{
2006-01-27 18:49:02 +00:00
if ( $user -> data [ 'is_registered' ] && $config [ 'load_db_lastread' ])
2006-01-22 19:13:12 +00:00
{
2010-03-11 23:53:40 +01:00
$topic_tracking_info [ $forum_id ] = get_topic_tracking ( $forum_id , $forum [ 'topic_list' ], $forum [ 'rowset' ], array ( $forum_id => $forum [ 'mark_time' ]));
2006-01-22 19:13:12 +00:00
}
2006-08-09 21:03:46 +00:00
else if ( $config [ 'load_anon_lastread' ] || $user -> data [ 'is_registered' ])
2006-01-22 19:13:12 +00:00
{
2010-03-11 23:53:40 +01:00
$topic_tracking_info [ $forum_id ] = get_complete_topic_tracking ( $forum_id , $forum [ 'topic_list' ]);
2008-06-22 11:02:04 +00:00
2006-01-22 19:13:12 +00:00
if ( ! $user -> data [ 'is_registered' ])
{
2006-06-06 20:53:46 +00:00
$user -> data [ 'user_lastmark' ] = ( isset ( $tracking_topics [ 'l' ])) ? ( int ) ( base_convert ( $tracking_topics [ 'l' ], 36 , 10 ) + $config [ 'board_startdate' ]) : 0 ;
2006-01-22 19:13:12 +00:00
}
}
}
unset ( $forums );
}
else
{
2007-01-05 11:21:09 +00:00
$bbcode_bitfield = $text_only_message = '' ;
2006-08-28 17:20:21 +00:00
$attach_list = array ();
2006-01-22 19:13:12 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
{
2007-01-05 11:21:09 +00:00
// We pre-process some variables here for later usage
$row [ 'post_text' ] = censor_text ( $row [ 'post_text' ]);
$text_only_message = $row [ 'post_text' ];
// make list items visible as such
if ( $row [ 'bbcode_uid' ])
{
$text_only_message = str_replace ( '[*:' . $row [ 'bbcode_uid' ] . ']' , '⋅ ' , $text_only_message );
// no BBCode in text only message
strip_bbcode ( $text_only_message , $row [ 'bbcode_uid' ]);
}
if ( $return_chars == - 1 || utf8_strlen ( $text_only_message ) < ( $return_chars + 3 ))
2006-08-28 17:20:21 +00:00
{
2007-01-05 11:21:09 +00:00
$row [ 'display_text_only' ] = false ;
2006-08-28 17:20:21 +00:00
$bbcode_bitfield = $bbcode_bitfield | base64_decode ( $row [ 'bbcode_bitfield' ]);
// Does this post have an attachment? If so, add it to the list
if ( $row [ 'post_attachment' ] && $config [ 'allow_attachments' ])
{
2006-10-22 13:32:33 +00:00
$attach_list [ $row [ 'forum_id' ]][] = $row [ 'post_id' ];
2006-08-28 17:20:21 +00:00
}
}
2007-01-05 11:21:09 +00:00
else
{
$row [ 'post_text' ] = $text_only_message ;
$row [ 'display_text_only' ] = true ;
}
$rowset [] = $row ;
2006-01-22 19:13:12 +00:00
}
$db -> sql_freeresult ( $result );
2006-08-28 17:20:21 +00:00
2007-01-05 11:21:09 +00:00
unset ( $text_only_message );
2006-08-28 17:20:21 +00:00
// Instantiate BBCode if needed
if ( $bbcode_bitfield !== '' )
{
include_once ( $phpbb_root_path . 'includes/bbcode.' . $phpEx );
$bbcode = new bbcode ( base64_encode ( $bbcode_bitfield ));
}
// Pull attachment data
if ( sizeof ( $attach_list ))
{
2006-10-22 13:32:33 +00:00
$use_attach_list = $attach_list ;
$attach_list = array ();
foreach ( $use_attach_list as $forum_id => $_list )
2006-08-28 17:20:21 +00:00
{
2006-10-22 13:32:33 +00:00
if ( $auth -> acl_get ( 'u_download' ) && $auth -> acl_get ( 'f_download' , $forum_id ))
2006-08-28 17:20:21 +00:00
{
2006-10-22 13:32:33 +00:00
$attach_list = array_merge ( $attach_list , $_list );
2006-08-28 17:20:21 +00:00
}
}
2006-10-22 13:32:33 +00:00
}
if ( sizeof ( $attach_list ))
{
$sql = ' SELECT *
FROM ' . ATTACHMENTS_TABLE . '
WHERE ' . $db->sql_in_set(' post_msg_id ', $attach_list) . '
AND in_message = 0
2006-11-21 18:15:53 +00:00
ORDER BY filetime DESC , post_msg_id ASC ' ;
2006-10-22 13:32:33 +00:00
$result = $db -> sql_query ( $sql );
2008-06-22 11:02:04 +00:00
2006-10-22 13:32:33 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
2006-08-28 17:20:21 +00:00
{
2006-10-22 13:32:33 +00:00
$attachments [ $row [ 'post_msg_id' ]][] = $row ;
2006-08-28 17:20:21 +00:00
}
2006-10-22 13:32:33 +00:00
$db -> sql_freeresult ( $result );
2006-08-28 17:20:21 +00:00
}
2006-01-22 19:13:12 +00:00
}
2006-07-27 19:02:47 +00:00
if ( $hilit )
{
// Remove bad highlights
$hilit_array = array_filter ( explode ( '|' , $hilit ), 'strlen' );
foreach ( $hilit_array as $key => $value )
{
2007-05-13 16:15:20 +00:00
$hilit_array [ $key ] = str_replace ( '\*' , '\w*?' , preg_quote ( $value , '#' ));
$hilit_array [ $key ] = preg_replace ( '#(^|\s)\\\\w\*\?(\s|$)#' , '$1\w+?$2' , $hilit_array [ $key ]);
2006-07-27 19:02:47 +00:00
}
$hilit = implode ( '|' , $hilit_array );
}
2006-01-22 19:13:12 +00:00
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' ]);
2012-10-22 11:14:00 +02:00
$replies = phpbb_content_visibility :: get_count ( 'topic_posts' , $row , $forum_id ) - 1 ;
2003-10-05 12:56:53 +00:00
2010-03-11 00:38:56 +01:00
$view_topic_url_params = " f= $forum_id &t= $result_topic_id " . (( $u_hilit ) ? " &hilit= $u_hilit " : '' );
2009-04-17 15:08:09 +00:00
$view_topic_url = append_sid ( " { $phpbb_root_path } viewtopic. $phpEx " , $view_topic_url_params );
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
{
2008-09-15 11:11:39 +00:00
if ( $config [ 'load_db_track' ] && $author_id === $user -> data [ 'user_id' ])
{
$row [ 'topic_posted' ] = 1 ;
}
2005-06-13 17:51:55 +00:00
$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
2006-03-06 18:21:54 +00:00
$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 ;
2010-06-17 23:58:18 -05:00
$topic_unapproved = ( $row [ 'topic_visibility' ] == ITEM_UNAPPROVED && $auth -> acl_get ( 'm_approve' , $forum_id )) ? true : false ;
$posts_unapproved = ( $row [ 'topic_visibility' ] == ITEM_APPROVED && $row [ 'topic_replies' ] < $row [ 'topic_replies_real' ] && $auth -> acl_get ( 'm_approve' , $forum_id )) ? true : false ;
$topic_deleted = ( $row [ 'topic_visibility' ] == ITEM_DELETED ) ? true : false ;
2006-06-06 20:53:46 +00:00
$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 ) : '' ;
2006-05-28 19:15:24 +00:00
2007-08-17 23:53:06 +00:00
$row [ 'topic_title' ] = preg_replace ( '#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is' , '<span class="posthilit">$1</span>' , $row [ 'topic_title' ]);
2005-06-13 17:51:55 +00:00
$tpl_ary = array (
2006-11-16 16:51:19 +00:00
'TOPIC_AUTHOR' => get_username_string ( 'username' , $row [ 'topic_poster' ], $row [ 'topic_first_poster_name' ], $row [ 'topic_first_poster_colour' ]),
'TOPIC_AUTHOR_COLOUR' => get_username_string ( 'colour' , $row [ 'topic_poster' ], $row [ 'topic_first_poster_name' ], $row [ 'topic_first_poster_colour' ]),
'TOPIC_AUTHOR_FULL' => get_username_string ( 'full' , $row [ 'topic_poster' ], $row [ 'topic_first_poster_name' ], $row [ 'topic_first_poster_colour' ]),
2006-08-22 11:01:56 +00:00
'FIRST_POST_TIME' => $user -> format_date ( $row [ 'topic_time' ]),
2006-09-08 18:00:38 +00:00
'LAST_POST_SUBJECT' => $row [ 'topic_last_post_subject' ],
2006-08-22 11:01:56 +00:00
'LAST_POST_TIME' => $user -> format_date ( $row [ 'topic_last_post_time' ]),
'LAST_VIEW_TIME' => $user -> format_date ( $row [ 'topic_last_view_time' ]),
2006-11-16 16:51:19 +00:00
'LAST_POST_AUTHOR' => get_username_string ( 'username' , $row [ 'topic_last_poster_id' ], $row [ 'topic_last_poster_name' ], $row [ 'topic_last_poster_colour' ]),
'LAST_POST_AUTHOR_COLOUR' => get_username_string ( 'colour' , $row [ 'topic_last_poster_id' ], $row [ 'topic_last_poster_name' ], $row [ 'topic_last_poster_colour' ]),
'LAST_POST_AUTHOR_FULL' => get_username_string ( 'full' , $row [ 'topic_last_poster_id' ], $row [ 'topic_last_poster_name' ], $row [ 'topic_last_poster_colour' ]),
2006-08-22 11:01:56 +00:00
2006-06-06 20:53:46 +00:00
'TOPIC_TYPE' => $topic_type ,
2005-06-13 17:51:55 +00:00
2011-01-18 22:39:50 -05:00
'TOPIC_IMG_STYLE' => $folder_img ,
2006-05-28 19:15:24 +00:00
'TOPIC_FOLDER_IMG' => $user -> img ( $folder_img , $folder_alt ),
2008-09-16 15:06:19 +00:00
'TOPIC_FOLDER_IMG_ALT' => $user -> lang [ $folder_alt ],
2006-05-28 19:15:24 +00:00
'TOPIC_ICON_IMG' => ( ! empty ( $icons [ $row [ 'icon_id' ]])) ? $icons [ $row [ 'icon_id' ]][ 'img' ] : '' ,
2005-06-13 17:51:55 +00:00
'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' ] : '' ,
2006-09-04 13:47:56 +00:00
'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' ]) : '' ,
2006-08-05 15:49:28 +00:00
'UNAPPROVED_IMG' => ( $topic_unapproved || $posts_unapproved ) ? $user -> img ( 'icon_topic_unapproved' , ( $topic_unapproved ) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED' ) : '' ,
2010-06-17 23:58:18 -05:00
'DELETED_IMG' => ( $topic_deleted ) ? $user -> img ( /*TODO*/ ) : '' ,
2005-06-13 17:51:55 +00:00
'S_TOPIC_TYPE' => $row [ 'topic_type' ],
2010-07-26 23:57:22 +02:00
'S_USER_POSTED' => ( ! empty ( $row [ 'topic_posted' ])) ? true : false ,
2006-03-06 18:21:54 +00:00
'S_UNREAD_TOPIC' => $unread_topic ,
2005-06-13 17:51:55 +00:00
2006-09-04 13:47:56 +00:00
'S_TOPIC_REPORTED' => ( ! empty ( $row [ 'topic_reported' ]) && $auth -> acl_get ( 'm_report' , $forum_id )) ? true : false ,
2006-05-28 19:15:24 +00:00
'S_TOPIC_UNAPPROVED' => $topic_unapproved ,
'S_POSTS_UNAPPROVED' => $posts_unapproved ,
2010-06-17 23:58:18 -05:00
'S_TOPIC_DELETED' => $topic_deleted ,
2005-06-13 17:51:55 +00:00
2009-04-17 15:08:09 +00:00
'U_LAST_POST' => append_sid ( " { $phpbb_root_path } viewtopic. $phpEx " , $view_topic_url_params . '&p=' . $row [ 'topic_last_post_id' ]) . '#p' . $row [ 'topic_last_post_id' ],
2006-11-16 16:51:19 +00:00
'U_LAST_POST_AUTHOR' => get_username_string ( 'profile' , $row [ 'topic_last_poster_id' ], $row [ 'topic_last_poster_name' ], $row [ 'topic_last_poster_colour' ]),
'U_TOPIC_AUTHOR' => get_username_string ( 'profile' , $row [ 'topic_poster' ], $row [ 'topic_first_poster_name' ], $row [ 'topic_first_poster_colour' ]),
2009-04-17 15:08:09 +00:00
'U_NEWEST_POST' => append_sid ( " { $phpbb_root_path } viewtopic. $phpEx " , $view_topic_url_params . '&view=unread' ) . '#unread' ,
2006-06-06 20:53:46 +00:00
'U_MCP_REPORT' => append_sid ( " { $phpbb_root_path } mcp. $phpEx " , 'i=reports&mode=reports&t=' . $result_topic_id , true , $user -> session_id ),
'U_MCP_QUEUE' => $u_mcp_queue ,
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
2007-05-13 16:15:20 +00:00
'L_IGNORE_POST' => sprintf ( $user -> lang [ 'POST_BY_FOE' ], $row [ 'username' ], " <a href= \" $u_search &start= $start &p= " . $row [ 'post_id' ] . '&view=show#p' . $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
2006-08-28 17:20:21 +00:00
// Replace naughty words such as farty pants
$row [ 'post_subject' ] = censor_text ( $row [ 'post_subject' ]);
2006-08-28 21:15:05 +00:00
2007-01-05 11:21:09 +00:00
if ( $row [ 'display_text_only' ])
2006-12-27 00:06:39 +00:00
{
2006-08-28 17:20:21 +00:00
// now find context for the searched words
2007-01-05 11:21:09 +00:00
$row [ 'post_text' ] = get_context ( $row [ 'post_text' ], array_filter ( explode ( '|' , $hilit ), 'strlen' ), $return_chars );
2007-08-19 13:40:53 +00:00
$row [ 'post_text' ] = bbcode_nl2br ( $row [ 'post_text' ]);
2005-06-13 17:51:55 +00:00
}
2006-08-28 17:20:21 +00:00
else
{
// Second parse bbcode here
if ( $row [ 'bbcode_bitfield' ])
{
2007-01-05 11:21:09 +00:00
$bbcode -> bbcode_second_pass ( $row [ 'post_text' ], $row [ 'bbcode_uid' ], $row [ 'bbcode_bitfield' ]);
2006-08-28 17:20:21 +00:00
}
2006-01-11 18:56:07 +00:00
2007-08-19 13:40:53 +00:00
$row [ 'post_text' ] = bbcode_nl2br ( $row [ 'post_text' ]);
$row [ 'post_text' ] = smiley_text ( $row [ 'post_text' ]);
2006-12-24 13:11:54 +00:00
if ( ! empty ( $attachments [ $row [ 'post_id' ]]))
2006-08-28 17:20:21 +00:00
{
2007-01-05 11:21:09 +00:00
parse_attachments ( $forum_id , $row [ 'post_text' ], $attachments [ $row [ 'post_id' ]], $update_count );
2008-06-22 11:02:04 +00:00
2006-08-28 17:20:21 +00:00
// we only display inline attachments
unset ( $attachments [ $row [ 'post_id' ]]);
}
}
2006-08-29 20:25:28 +00:00
if ( $hilit )
{
// post highlighting
2007-01-05 11:21:09 +00:00
$row [ 'post_text' ] = preg_replace ( '#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is' , '<span class="posthilit">$1</span>' , $row [ 'post_text' ]);
2007-08-17 23:53:06 +00:00
$row [ 'post_subject' ] = preg_replace ( '#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is' , '<span class="posthilit">$1</span>' , $row [ 'post_subject' ]);
2006-08-29 20:25:28 +00:00
}
2004-10-19 19:26:58 +00:00
2005-06-13 17:51:55 +00:00
$tpl_ary = array (
2006-11-16 16:51:19 +00:00
'POST_AUTHOR_FULL' => get_username_string ( 'full' , $row [ 'poster_id' ], $row [ 'username' ], $row [ 'user_colour' ], $row [ 'post_username' ]),
'POST_AUTHOR_COLOUR' => get_username_string ( 'colour' , $row [ 'poster_id' ], $row [ 'username' ], $row [ 'user_colour' ], $row [ 'post_username' ]),
'POST_AUTHOR' => get_username_string ( 'username' , $row [ 'poster_id' ], $row [ 'username' ], $row [ 'user_colour' ], $row [ 'post_username' ]),
'U_POST_AUTHOR' => get_username_string ( 'profile' , $row [ 'poster_id' ], $row [ 'username' ], $row [ 'user_colour' ], $row [ 'post_username' ]),
2008-06-22 11:02:04 +00:00
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' ]) : '' ,
2007-01-05 11:21:09 +00:00
'MESSAGE' => $row [ 'post_text' ]
2005-06-13 17:51:55 +00:00
);
}
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 (
2006-06-06 20:53:46 +00:00
'FORUM_ID' => $forum_id ,
'TOPIC_ID' => $result_topic_id ,
2006-01-11 18:56:07 +00:00
'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' ],
2006-06-06 20:53:46 +00:00
'TOPIC_TITLE' => $topic_title ,
'TOPIC_REPLIES' => $replies ,
'TOPIC_VIEWS' => $row [ 'topic_views' ],
2002-03-31 00:06:34 +00:00
2005-06-13 17:51:55 +00:00
'U_VIEW_TOPIC' => $view_topic_url ,
2006-06-06 20:53:46 +00:00
'U_VIEW_FORUM' => append_sid ( " { $phpbb_root_path } viewforum. $phpEx " , 'f=' . $forum_id ),
2007-08-15 17:32:48 +00:00
'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' ] : '' )
2005-06-13 17:51:55 +00:00
));
2012-07-04 23:19:59 +01:00
if ( $show_results == 'topics' )
{
2012-07-12 02:36:00 +01:00
phpbb_generate_template_pagination ( $template , $view_topic_url , 'searchresults.pagination' , 'start' , $replies + 1 , $config [ 'posts_per_page' ], 1 , true , true );
2012-07-04 23:19:59 +01:00
}
2005-06-13 17:51:55 +00:00
}
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
2006-12-27 00:06:39 +00:00
page_header (( $l_search_title ) ? $l_search_title : $user -> lang [ 'SEARCH' ]);
2001-05-29 14:25:09 +00:00
2003-09-15 16:33:12 +00:00
$template -> set_filenames ( array (
2007-01-26 16:09:51 +00:00
'body' => 'search_results.html' )
2003-09-15 16:33:12 +00:00
);
2006-06-06 20:53:46 +00:00
make_jumpbox ( append_sid ( " { $phpbb_root_path } 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 = '' ;
2008-09-06 12:23:59 +00:00
$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
2005-11-28 18:38:49 +00:00
FROM ' . FORUMS_TABLE . ' f
2007-01-26 16:09:51 +00:00
LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id
2006-05-28 19:06:21 +00:00
AND fa . session_id = '" . $db->sql_escape($user->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
2008-09-06 12:23:59 +00:00
if ( $row [ 'forum_type' ] == FORUM_POST && ( $row [ 'left_id' ] + 1 == $row [ 'right_id' ]) && ! $row [ 'enable_indexing' ])
{
// Postable forum with no subforums and indexing disabled, don't display
continue ;
}
2007-08-18 13:52:33 +00:00
if ( $row [ 'forum_type' ] == FORUM_LINK || ( $row [ 'forum_password' ] && ! $row [ 'user_id' ]))
2003-09-15 16:33:12 +00:00
{
2007-08-18 13:52:33 +00:00
// if this forum is a link or password protected (user has not entered the password yet) then skip to the next branch
2003-09-15 16:33:12 +00:00
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
{
2006-03-19 22:25:43 +00:00
if ( isset ( $pad_store [ $row [ 'parent_id' ]]))
{
$padding = $pad_store [ $row [ 'parent_id' ]];
}
else
{
continue ;
}
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
2007-08-18 13:52:33 +00:00
if ( $auth -> acl_gets ( '!f_search' , '!f_list' , $row [ 'forum_id' ]))
2006-02-12 18:35:16 +00:00
{
2007-08-18 13:52:33 +00:00
// if the user does not have permissions to search or see this forum skip only this forum/category
2006-02-12 18:35:16 +00:00
continue ;
}
$selected = ( 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
{
2007-02-25 22:09:53 +00:00
// make sure we don't forget anything
$s_forums .= $holding ;
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
}
}
2006-12-10 17:44:45 +00:00
if ( $holding )
{
$s_forums .= $holding ;
}
2003-09-15 16:33:12 +00:00
$db -> sql_freeresult ( $result );
unset ( $pad_store );
2006-09-17 22:02:28 +00:00
if ( ! $s_forums )
{
2007-07-22 14:04:26 +00:00
trigger_error ( 'NO_SEARCH' );
2006-09-17 22:02:28 +00:00
}
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
{
2007-07-15 20:53:27 +00:00
$selected = ( $i == 300 ) ? ' 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
}
2007-07-10 15:14:25 +00:00
$s_hidden_fields = array ( 't' => $topic_id );
if ( $_SID )
{
$s_hidden_fields [ 'sid' ] = $_SID ;
}
if ( ! empty ( $_EXTRA_URL ))
{
foreach ( $_EXTRA_URL as $url_param )
{
$url_param = explode ( '=' , $url_param , 2 );
$s_hidden_fields [ $url_param [ 0 ]] = $url_param [ 1 ];
}
}
2003-09-15 16:33:12 +00:00
$template -> assign_vars ( array (
2008-09-18 15:24:40 +00:00
'S_SEARCH_ACTION' => append_sid ( " { $phpbb_root_path } search. $phpEx " , false , true , 0 ), // We force no ?sid= appending by using 0
2007-07-10 15:14:25 +00:00
'S_HIDDEN_FIELDS' => build_hidden_fields ( $s_hidden_fields ),
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 ,
2007-05-02 16:19:35 +00:00
'S_SELECT_SORT_DAYS' => $s_limit_days ,
'S_IN_SEARCH' => true ,
));
2001-09-17 00:42:17 +00:00
2007-08-23 13:41:34 +00:00
// only show recent searches to search administrators
if ( $auth -> acl_get ( 'a_search' ))
2006-08-30 00:58:36 +00:00
{
2007-08-23 13:41:34 +00:00
// Handle large objects differently for Oracle and MSSQL
switch ( $db -> sql_layer )
{
case 'oracle' :
$sql = ' SELECT search_time , search_keywords
FROM ' . SEARCH_RESULTS_TABLE . '
WHERE dbms_lob . getlength ( search_keywords ) > 0
ORDER BY search_time DESC ' ;
break ;
2008-06-22 11:02:04 +00:00
2007-08-23 13:41:34 +00:00
case 'mssql' :
case 'mssql_odbc' :
2010-05-01 01:58:50 +01:00
case 'mssqlnative' :
2007-08-23 13:41:34 +00:00
$sql = ' SELECT search_time , search_keywords
FROM ' . SEARCH_RESULTS_TABLE . '
WHERE DATALENGTH ( search_keywords ) > 0
ORDER BY search_time DESC ' ;
break ;
2008-06-22 11:02:04 +00:00
2007-08-23 13:41:34 +00:00
default :
$sql = ' SELECT search_time , search_keywords
FROM ' . SEARCH_RESULTS_TABLE . '
WHERE search_keywords <> \ ' \ '
ORDER BY search_time DESC ' ;
break ;
}
$result = $db -> sql_query_limit ( $sql , 5 );
2003-09-15 16:33:12 +00:00
2007-08-23 13:41:34 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
{
$keywords = $row [ 'search_keywords' ];
2003-09-15 16:33:12 +00:00
2007-08-23 13:41:34 +00:00
$template -> assign_block_vars ( 'recentsearch' , array (
'KEYWORDS' => $keywords ,
'TIME' => $user -> format_date ( $row [ 'search_time' ]),
2003-09-15 16:33:12 +00:00
2007-08-23 13:41:34 +00:00
'U_KEYWORDS' => append_sid ( " { $phpbb_root_path } search. $phpEx " , 'keywords=' . urlencode ( htmlspecialchars_decode ( $keywords )))
));
}
$db -> sql_freeresult ( $result );
2003-09-15 16:33:12 +00:00
}
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' )
);
2006-06-06 20:53:46 +00:00
make_jumpbox ( append_sid ( " { $phpbb_root_path } viewforum. $phpEx " ));
2001-05-29 14:25:09 +00:00
2003-05-03 23:58:45 +00:00
page_footer ();