(file) Return to search.php CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / phpBB2

   1 rizwank 1.1 <?php
   2             /***************************************************************************
   3              *                                search.php
   4              *                            -------------------
   5              *   begin                : Saturday, Feb 13, 2001
   6              *   copyright            : (C) 2001 The phpBB Group
   7              *   email                : support@phpbb.com
   8              *
   9              *   $Id: search.php,v 1.72.2.6 2003/01/09 00:17:23 psotfx Exp $
  10              *
  11              *
  12              ***************************************************************************/
  13             
  14             /***************************************************************************
  15              *
  16              *   This program is free software; you can redistribute it and/or modify
  17              *   it under the terms of the GNU General Public License as published by
  18              *   the Free Software Foundation; either version 2 of the License, or
  19              *   (at your option) any later version.
  20              *
  21              ***************************************************************************/
  22 rizwank 1.1 
  23             define('IN_PHPBB', true);
  24             $phpbb_root_path = './';
  25             include($phpbb_root_path . 'extension.inc');
  26             include($phpbb_root_path . 'common.'.$phpEx);
  27             include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
  28             include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
  29             
  30             //
  31             // Start session management
  32             //
  33             $userdata = session_pagestart($user_ip, PAGE_SEARCH);
  34             init_userprefs($userdata);
  35             //
  36             // End session management
  37             //
  38             
  39             //
  40             // Define initial vars
  41             //
  42             if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
  43 rizwank 1.1 {
  44             	$mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
  45             }
  46             else
  47             {
  48             	$mode = '';
  49             }
  50             
  51             if ( isset($HTTP_POST_VARS['search_keywords']) || isset($HTTP_GET_VARS['search_keywords']) )
  52             {
  53             	$search_keywords = ( isset($HTTP_POST_VARS['search_keywords']) ) ? $HTTP_POST_VARS['search_keywords'] : $HTTP_GET_VARS['search_keywords'];
  54             }
  55             else
  56             {
  57             	$search_keywords = '';
  58             }
  59             
  60             if ( isset($HTTP_POST_VARS['search_author']) || isset($HTTP_GET_VARS['search_author']))
  61             {
  62             	$search_author = ( isset($HTTP_POST_VARS['search_author']) ) ? $HTTP_POST_VARS['search_author'] : $HTTP_GET_VARS['search_author'];
  63             }
  64 rizwank 1.1 else
  65             {
  66             	$search_author = '';
  67             }
  68             
  69             $search_id = ( isset($HTTP_GET_VARS['search_id']) ) ? $HTTP_GET_VARS['search_id'] : '';
  70             
  71             $show_results = ( isset($HTTP_POST_VARS['show_results']) ) ? $HTTP_POST_VARS['show_results'] : 'posts';
  72             
  73             if ( isset($HTTP_POST_VARS['search_terms']) )
  74             {
  75             	$search_terms = ( $HTTP_POST_VARS['search_terms'] == 'all' ) ? 1 : 0;
  76             }
  77             else
  78             {
  79             	$search_terms = 0;
  80             }
  81             
  82             if ( isset($HTTP_POST_VARS['search_fields']) )
  83             {
  84             	$search_fields = ( $HTTP_POST_VARS['search_fields'] == 'all' ) ? 1 : 0;
  85 rizwank 1.1 }
  86             else
  87             {
  88             	$search_fields = 0;
  89             }
  90             
  91             $return_chars = ( isset($HTTP_POST_VARS['return_chars']) ) ? intval($HTTP_POST_VARS['return_chars']) : 200;
  92             
  93             $search_cat = ( isset($HTTP_POST_VARS['search_cat']) ) ? intval($HTTP_POST_VARS['search_cat']) : -1;
  94             $search_forum = ( isset($HTTP_POST_VARS['search_forum']) ) ? intval($HTTP_POST_VARS['search_forum']) : -1;
  95             
  96             $sort_by = ( isset($HTTP_POST_VARS['sort_by']) ) ? intval($HTTP_POST_VARS['sort_by']) : 0;
  97             
  98             if ( isset($HTTP_POST_VARS['sort_dir']) )
  99             {
 100             	$sort_dir = ( $HTTP_POST_VARS['sort_dir'] == 'DESC' ) ? 'DESC' : 'ASC';
 101             }
 102             else
 103             {
 104             	$sort_dir =  'DESC';
 105             }
 106 rizwank 1.1 
 107             if ( !empty($HTTP_POST_VARS['search_time']) || !empty($HTTP_GET_VARS['search_time']))
 108             {
 109             	$search_time = time() - ( ( ( !empty($HTTP_POST_VARS['search_time']) ) ? intval($HTTP_POST_VARS['search_time']) : intval($HTTP_GET_VARS['search_time']) ) * 86400 );
 110             }
 111             else
 112             {
 113             	$search_time = 0;
 114             }
 115             
 116             $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
 117             
 118             $sort_by_types = array($lang['Sort_Time'], $lang['Sort_Post_Subject'], $lang['Sort_Topic_Title'], $lang['Sort_Author'], $lang['Sort_Forum']);
 119             
 120             //
 121             // encoding match for workaround
 122             //
 123             $multibyte_charset = 'utf-8, big5, shift_jis, euc-kr, gb2312';
 124             
 125             //
 126             // Begin core code
 127 rizwank 1.1 //
 128             if ( $mode == 'searchuser' )
 129             {
 130             	//
 131             	// This handles the simple windowed user search functions called from various other scripts
 132             	//
 133             	if ( isset($HTTP_POST_VARS['search_username']) )
 134             	{
 135             		username_search($HTTP_POST_VARS['search_username']);
 136             	}
 137             	else
 138             	{
 139             		username_search('');
 140             	}
 141             
 142             	exit;
 143             }
 144             else if ( $search_keywords != '' || $search_author != '' || $search_id )
 145             {
 146             	$store_vars = array('search_results', 'total_match_count', 'split_search', 'sort_by', 'sort_dir', 'show_results', 'return_chars');
 147             
 148 rizwank 1.1 	//
 149             	// Cycle through options ...
 150             	//
 151             	if ( $search_id == 'newposts' || $search_id == 'egosearch' || $search_id == 'unanswered' || $search_keywords != '' || $search_author != '' )
 152             	{
 153             		if ( $search_id == 'newposts' || $search_id == 'egosearch' || ( $search_author != '' && $search_keywords == '' )  )
 154             		{
 155             			if ( $search_id == 'newposts' )
 156             			{
 157             				if ( $userdata['session_logged_in'] )
 158             				{
 159             					$sql = "SELECT post_id 
 160             						FROM " . POSTS_TABLE . " 
 161             						WHERE post_time >= " . $userdata['user_lastvisit'];
 162             				}
 163             				else
 164             				{
 165             					redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=newposts", true));
 166             				}
 167             
 168             				$show_results = 'topics';
 169 rizwank 1.1 				$sort_by = 0;
 170             				$sort_dir = 'DESC';
 171             			}
 172             			else if ( $search_id == 'egosearch' )
 173             			{
 174             				if ( $userdata['session_logged_in'] )
 175             				{
 176             					$sql = "SELECT post_id 
 177             						FROM " . POSTS_TABLE . " 
 178             						WHERE poster_id = " . $userdata['user_id'];;
 179             				}
 180             				else
 181             				{
 182             					redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=egosearch", true));
 183             				}
 184             
 185             				$show_results = 'topics';
 186             				$sort_by = 0;
 187             				$sort_dir = 'DESC';
 188             			}
 189             			else
 190 rizwank 1.1 			{
 191             				$search_author = str_replace('*', '%', trim($search_author));
 192             				
 193             				$sql = "SELECT user_id
 194             					FROM " . USERS_TABLE . "
 195             					WHERE username LIKE '" . str_replace("\'", "''", $search_author) . "'";
 196             				if ( !($result = $db->sql_query($sql)) )
 197             				{
 198             					message_die(GENERAL_ERROR, "Couldn't obtain list of matching users (searching for: $search_author)", "", __LINE__, __FILE__, $sql);
 199             				}
 200             
 201             				$matching_userids = '';
 202             				if ( $row = $db->sql_fetchrow($result) )
 203             				{
 204             					do
 205             					{
 206             						$matching_userids .= ( ( $matching_userids != '' ) ? ', ' : '' ) . $row['user_id'];
 207             					}
 208             					while( $row = $db->sql_fetchrow($result) );
 209             				}
 210             				else
 211 rizwank 1.1 				{
 212             					message_die(GENERAL_MESSAGE, $lang['No_search_match']);
 213             				}
 214             
 215             				$sql = "SELECT post_id 
 216             					FROM " . POSTS_TABLE . " 
 217             					WHERE poster_id IN ($matching_userids)";
 218             			}
 219             
 220             			if ( !($result = $db->sql_query($sql)) )
 221             			{
 222             				message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
 223             			}
 224             
 225             			$search_ids = array();
 226             			while( $row = $db->sql_fetchrow($result) )
 227             			{
 228             				$search_ids[] = $row['post_id'];
 229             			}
 230             			$db->sql_freeresult($result);
 231             
 232 rizwank 1.1 			$total_match_count = count($search_ids);
 233             
 234             		}
 235             		else if ( $search_keywords != '' )
 236             		{
 237             			$stopword_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_stopwords.txt'); 
 238             			$synonym_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_synonyms.txt'); 
 239             		
 240             			$split_search = array();
 241             			$split_search = ( !strstr($multibyte_charset, $lang['ENCODING']) ) ?  split_words(clean_words('search', stripslashes($search_keywords), $stopword_array, $synonym_array), 'search') : split(' ', $search_keywords);	
 242             
 243             			$search_msg_only = ( !$search_fields ) ? "AND m.title_match = 0" : ( ( strstr($multibyte_charset, $lang['ENCODING']) ) ? '' : '' );
 244             
 245             			$word_count = 0;
 246             			$current_match_type = 'or';
 247             
 248             			$word_match = array();
 249             			$result_list = array();
 250             
 251             			for($i = 0; $i < count($split_search); $i++)
 252             			{
 253 rizwank 1.1 				switch ( $split_search[$i] )
 254             				{
 255             					case 'and':
 256             						$current_match_type = 'and';
 257             						break;
 258             
 259             					case 'or':
 260             						$current_match_type = 'or';
 261             						break;
 262             
 263             					case 'not':
 264             						$current_match_type = 'not';
 265             						break;
 266             
 267             					default:
 268             						if ( !empty($search_terms) )
 269             						{
 270             							$current_match_type = 'and';
 271             						}
 272             
 273             						if ( !strstr($multibyte_charset, $lang['ENCODING']) )
 274 rizwank 1.1 						{
 275             							$match_word = str_replace('*', '%', $split_search[$i]);
 276             							$sql = "SELECT m.post_id 
 277             								FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m 
 278             								WHERE w.word_text LIKE '$match_word' 
 279             									AND m.word_id = w.word_id 
 280             									AND w.word_common <> 1 
 281             									$search_msg_only";
 282             						}
 283             						else
 284             						{
 285             							$match_word =  addslashes('%' . str_replace('*', '', $split_search[$i]) . '%');
 286             							$search_msg_only = ( $search_fields ) ? "OR post_subject LIKE '$match_word'" : '';
 287             							$sql = "SELECT post_id
 288             								FROM " . POSTS_TEXT_TABLE . "
 289             								WHERE post_text LIKE '$match_word'
 290             								$search_msg_only";
 291             						}
 292             						if ( !($result = $db->sql_query($sql)) )
 293             						{
 294             							message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
 295 rizwank 1.1 						}
 296             
 297             						$row = array();
 298             						while( $temp_row = $db->sql_fetchrow($result) )
 299             						{
 300             							$row[$temp_row['post_id']] = 1;
 301             
 302             							if ( !$word_count )
 303             							{
 304             								$result_list[$temp_row['post_id']] = 1;
 305             							}
 306             							else if ( $current_match_type == 'or' )
 307             							{
 308             								$result_list[$temp_row['post_id']] = 1;
 309             							}
 310             							else if ( $current_match_type == 'not' )
 311             							{
 312             								$result_list[$temp_row['post_id']] = 0;
 313             							}
 314             						}
 315             
 316 rizwank 1.1 						if ( $current_match_type == 'and' && $word_count )
 317             						{
 318             							@reset($result_list);
 319             							while( list($post_id, $match_count) = @each($result_list) )
 320             							{
 321             								if ( !$row[$post_id] )
 322             								{
 323             									$result_list[$post_id] = 0;
 324             								}
 325             							}
 326             						}
 327             
 328             						$word_count++;
 329             
 330             						$db->sql_freeresult($result);
 331             					}
 332             			}
 333             
 334             			@reset($result_list);
 335             
 336             			$search_ids = array();
 337 rizwank 1.1 			while( list($post_id, $matches) = each($result_list) )
 338             			{
 339             				if ( $matches )
 340             				{
 341             					$search_ids[] = $post_id;
 342             				}
 343             			}	
 344             			
 345             			unset($result_list);
 346             			$total_match_count = count($search_ids);
 347             		}
 348             
 349             		//
 350             		// If user is logged in then we'll check to see which (if any) private
 351             		// forums they are allowed to view and include them in the search.
 352             		//
 353             		// If not logged in we explicitly prevent searching of private forums
 354             		//
 355             		$auth_sql = '';
 356             		if ( $search_forum != -1 )
 357             		{
 358 rizwank 1.1 			$is_auth = auth(AUTH_READ, $search_forum, $userdata);
 359             
 360             			if ( !$is_auth['auth_read'] )
 361             			{
 362             				message_die(GENERAL_MESSAGE, $lang['No_searchable_forums']);
 363             			}
 364             
 365             			$auth_sql = "f.forum_id = $search_forum";
 366             		}
 367             		else
 368             		{
 369             			$is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); 
 370             
 371             			if ( $search_cat != -1 )
 372             			{
 373             				$auth_sql = "f.cat_id = $search_cat";
 374             			}
 375             
 376             			$ignore_forum_sql = '';
 377             			while( list($key, $value) = each($is_auth_ary) )
 378             			{
 379 rizwank 1.1 				if ( !$value['auth_read'] )
 380             				{
 381             					$ignore_forum_sql .= ( ( $ignore_forum_sql != '' ) ? ', ' : '' ) . $key;
 382             				}
 383             			}
 384             
 385             			if ( $ignore_forum_sql != '' )
 386             			{
 387             				$auth_sql .= ( $auth_sql != '' ) ? " AND f.forum_id NOT IN ($ignore_forum_sql) " : "f.forum_id NOT IN ($ignore_forum_sql) ";
 388             			}
 389             		}
 390             
 391             		//
 392             		// Author name search 
 393             		//
 394             		if ( $search_author != '' )
 395             		{
 396             			$search_author = str_replace('*', '%', trim(str_replace("\'", "''", $search_author)));
 397             		}
 398             
 399             		if ( $total_match_count )
 400 rizwank 1.1 		{
 401             			if ( $show_results == 'topics' )
 402             			{
 403             				$where_sql = '';
 404             
 405             				if ( $search_time )
 406             				{
 407             					$where_sql .= ( $search_author == '' && $auth_sql == ''  ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time ";
 408             				}
 409             
 410             				if ( $search_author == '' && $auth_sql == '' )
 411             				{
 412             					$sql = "SELECT topic_id 
 413             						FROM " . POSTS_TABLE . "
 414             						WHERE post_id IN (" . implode(", ", $search_ids) . ") 
 415             							$where_sql 
 416             						GROUP BY topic_id";
 417             				}
 418             				else
 419             				{
 420             					$from_sql = POSTS_TABLE . " p"; 
 421 rizwank 1.1 
 422             					if ( $search_author != '' )
 423             					{
 424             						$from_sql .= ", " . USERS_TABLE . " u";
 425             						$where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author' ";
 426             					}
 427             
 428             					if ( $auth_sql != '' )
 429             					{
 430             						$from_sql .= ", " . FORUMS_TABLE . " f";
 431             						$where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql";
 432             					}
 433             
 434             					$sql = "SELECT p.topic_id 
 435             						FROM $from_sql 
 436             						WHERE p.post_id IN (" . implode(", ", $search_ids) . ") 
 437             							$where_sql 
 438             						GROUP BY p.topic_id";
 439             				}
 440             
 441             				if ( !($result = $db->sql_query($sql)) )
 442 rizwank 1.1 				{
 443             					message_die(GENERAL_ERROR, 'Could not obtain topic ids', '', __LINE__, __FILE__, $sql);
 444             				}
 445             
 446             				$search_ids = array();
 447             				while( $row = $db->sql_fetchrow($result) )
 448             				{
 449             					$search_ids[] = $row['topic_id'];
 450             				}
 451             				$db->sql_freeresult($result);
 452             
 453             				$total_match_count = sizeof($search_ids);
 454             		
 455             			}
 456             			else if ( $search_author != '' || $search_time || $auth_sql != '' )
 457             			{
 458             				$where_sql = ( $search_author == '' && $auth_sql == '' ) ? 'post_id IN (' . implode(', ', $search_ids) . ')' : 'p.post_id IN (' . implode(', ', $search_ids) . ')';
 459             				$from_sql = (  $search_author == '' && $auth_sql == '' ) ? POSTS_TABLE : POSTS_TABLE . ' p';
 460             
 461             				if ( $search_time )
 462             				{
 463 rizwank 1.1 					$where_sql .= ( $search_author == '' && $auth_sql == '' ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time";
 464             				}
 465             
 466             				if ( $auth_sql != '' )
 467             				{
 468             					$from_sql .= ", " . FORUMS_TABLE . " f";
 469             					$where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql";
 470             				}
 471             
 472             				if ( $search_author != '' )
 473             				{
 474             					$from_sql .= ", " . USERS_TABLE . " u";
 475             					$where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author'";
 476             				}
 477             
 478             				$sql = "SELECT p.post_id 
 479             					FROM $from_sql 
 480             					WHERE $where_sql";
 481             				if ( !($result = $db->sql_query($sql)) )
 482             				{
 483             					message_die(GENERAL_ERROR, 'Could not obtain post ids', '', __LINE__, __FILE__, $sql);
 484 rizwank 1.1 				}
 485             
 486             				$search_ids = array();
 487             				while( $row = $db->sql_fetchrow($result) )
 488             				{
 489             					$search_ids[] = $row['post_id'];
 490             				}
 491             
 492             				$db->sql_freeresult($result);
 493             
 494             				$total_match_count = count($search_ids);
 495             			}
 496             		}
 497             		else if ( $search_id == 'unanswered' )
 498             		{
 499             			if ( $auth_sql != '' )
 500             			{
 501             				$sql = "SELECT t.topic_id, f.forum_id
 502             					FROM " . TOPICS_TABLE . "  t, " . FORUMS_TABLE . " f
 503             					WHERE t.topic_replies = 0 
 504             						AND t.forum_id = f.forum_id
 505 rizwank 1.1 						AND t.topic_moved_id = 0
 506             						AND $auth_sql";
 507             			}
 508             			else
 509             			{
 510             				$sql = "SELECT topic_id 
 511             					FROM " . TOPICS_TABLE . "  
 512             					WHERE topic_replies = 0 
 513             						AND topic_moved_id = 0";
 514             			}
 515             				
 516             			if ( !($result = $db->sql_query($sql)) )
 517             			{
 518             				message_die(GENERAL_ERROR, 'Could not obtain post ids', '', __LINE__, __FILE__, $sql);
 519             			}
 520             
 521             			$search_ids = array();
 522             			while( $row = $db->sql_fetchrow($result) )
 523             			{
 524             				$search_ids[] = $row['topic_id'];
 525             			}
 526 rizwank 1.1 			$db->sql_freeresult($result);
 527             
 528             			$total_match_count = count($search_ids);
 529             
 530             			//
 531             			// Basic requirements
 532             			//
 533             			$show_results = 'topics';
 534             			$sort_by = 0;
 535             			$sort_dir = 'DESC';
 536             		}
 537             		else
 538             		{
 539             			message_die(GENERAL_MESSAGE, $lang['No_search_match']);
 540             		}
 541             
 542             		//
 543             		// Finish building query (for all combinations)
 544             		// and run it ...
 545             		//
 546             		$sql = "SELECT session_id 
 547 rizwank 1.1 			FROM " . SESSIONS_TABLE;
 548             		if ( $result = $db->sql_query($sql) )
 549             		{
 550             			$delete_search_ids = array();
 551             			while( $row = $db->sql_fetchrow($result) )
 552             			{
 553             				$delete_search_ids[] = "'" . $row['session_id'] . "'";
 554             			}
 555             
 556             			if ( count($delete_search_ids) )
 557             			{
 558             				$sql = "DELETE FROM " . SEARCH_TABLE . " 
 559             					WHERE session_id NOT IN (" . implode(", ", $delete_search_ids) . ")";
 560             				if ( !$result = $db->sql_query($sql) )
 561             				{
 562             					message_die(GENERAL_ERROR, 'Could not delete old search id sessions', '', __LINE__, __FILE__, $sql);
 563             				}
 564             			}
 565             		}
 566             
 567             		//
 568 rizwank 1.1 		// Store new result data
 569             		//
 570             		$search_results = implode(', ', $search_ids);
 571             		$per_page = ( $show_results == 'posts' ) ? $board_config['posts_per_page'] : $board_config['topics_per_page'];
 572             
 573             		//
 574             		// Combine both results and search data (apart from original query)
 575             		// so we can serialize it and place it in the DB
 576             		//
 577             		$store_search_data = array();
 578             		for($i = 0; $i < count($store_vars); $i++)
 579             		{
 580             			$store_search_data[$store_vars[$i]] = $$store_vars[$i];
 581             		}
 582             
 583             		$result_array = serialize($store_search_data);
 584             		unset($store_search_data);
 585             
 586             		mt_srand ((double) microtime() * 1000000);
 587             		$search_id = mt_rand();
 588             
 589 rizwank 1.1 		$sql = "UPDATE " . SEARCH_TABLE . " 
 590             			SET search_id = $search_id, search_array = '$result_array'
 591             			WHERE session_id = '" . $userdata['session_id'] . "'";
 592             		if ( !($result = $db->sql_query($sql)) || !$db->sql_affectedrows() )
 593             		{
 594             			$sql = "INSERT INTO " . SEARCH_TABLE . " (search_id, session_id, search_array) 
 595             				VALUES($search_id, '" . $userdata['session_id'] . "', '" . str_replace("\'", "''", $result_array) . "')";
 596             			if ( !($result = $db->sql_query($sql)) )
 597             			{
 598             				message_die(GENERAL_ERROR, 'Could not insert search results', '', __LINE__, __FILE__, $sql);
 599             			}
 600             		}
 601             	}
 602             	else
 603             	{
 604             		if ( intval($search_id) )
 605             		{
 606             			$sql = "SELECT search_array 
 607             				FROM " . SEARCH_TABLE . " 
 608             				WHERE search_id = $search_id  
 609             					AND session_id = '". $userdata['session_id'] . "'";
 610 rizwank 1.1 			if ( !($result = $db->sql_query($sql)) )
 611             			{
 612             				message_die(GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql);
 613             			}
 614             
 615             			if ( $row = $db->sql_fetchrow($result) )
 616             			{
 617             				$search_data = unserialize($row['search_array']);
 618             				for($i = 0; $i < count($store_vars); $i++)
 619             				{
 620             					$$store_vars[$i] = $search_data[$store_vars[$i]];
 621             				}
 622             			}
 623             		}
 624             	}
 625             
 626             	//
 627             	// Look up data ...
 628             	//
 629             	if ( $search_results != '' )
 630             	{
 631 rizwank 1.1 		if ( $show_results == 'posts' )
 632             		{
 633             			$sql = "SELECT pt.post_text, pt.bbcode_uid, pt.post_subject, p.*, f.forum_id, f.forum_name, t.*, u.username, u.user_id, u.user_sig, u.user_sig_bbcode_uid  
 634             				FROM " . FORUMS_TABLE . " f, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " pt 
 635             				WHERE p.post_id IN ($search_results)
 636             					AND pt.post_id = p.post_id
 637             					AND f.forum_id = p.forum_id
 638             					AND p.topic_id = t.topic_id
 639             					AND p.poster_id = u.user_id";
 640             		}
 641             		else
 642             		{
 643             			$sql = "SELECT t.*, f.forum_id, f.forum_name, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time 
 644             				FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
 645             				WHERE t.topic_id IN ($search_results) 
 646             					AND t.topic_poster = u.user_id
 647             					AND f.forum_id = t.forum_id 
 648             					AND p.post_id = t.topic_first_post_id
 649             					AND p2.post_id = t.topic_last_post_id
 650             					AND u2.user_id = p2.poster_id";
 651             		}
 652 rizwank 1.1 
 653             		$per_page = ( $show_results == 'posts' ) ? $board_config['posts_per_page'] : $board_config['topics_per_page'];
 654             
 655             		$sql .= " ORDER BY ";
 656             		switch ( $sort_by )
 657             		{
 658             			case 1:
 659             				$sql .= ( $show_results == 'posts' ) ? 'pt.post_subject' : 't.topic_title';
 660             				break;
 661             			case 2:
 662             				$sql .= 't.topic_title';
 663             				break;
 664             			case 3:
 665             				$sql .= 'u.username';
 666             				break;
 667             			case 4:
 668             				$sql .= 'f.forum_id';
 669             				break;
 670             			default:
 671             				$sql .= ( $show_results == 'posts' ) ? 'p.post_time' : 'p2.post_time';
 672             				break;
 673 rizwank 1.1 		}
 674             		$sql .= " $sort_dir LIMIT $start, " . $per_page;
 675             
 676             		if ( !$result = $db->sql_query($sql) )
 677             		{
 678             			message_die(GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql);
 679             		}
 680             
 681             		$searchset = array();
 682             		while( $row = $db->sql_fetchrow($result) )
 683             		{
 684             			$searchset[] = $row;
 685             		}
 686             		
 687             		$db->sql_freeresult($result);		
 688             		
 689             		//
 690             		// Define censored word matches
 691             		//
 692             		$orig_word = array();
 693             		$replacement_word = array();
 694 rizwank 1.1 		obtain_word_list($orig_word, $replacement_word);
 695             
 696             		//
 697             		// Output header
 698             		//
 699             		$page_title = $lang['Search'];
 700             		include($phpbb_root_path . 'includes/page_header.'.$phpEx);	
 701             
 702             		if ( $show_results == 'posts' )
 703             		{
 704             			$template->set_filenames(array(
 705             				'body' => 'search_results_posts.tpl')
 706             			);
 707             		}
 708             		else
 709             		{
 710             			$template->set_filenames(array(
 711             				'body' => 'search_results_topics.tpl')
 712             			);
 713             		}
 714             		make_jumpbox('viewforum.'.$phpEx);
 715 rizwank 1.1 
 716             		$l_search_matches = ( $total_match_count == 1 ) ? sprintf($lang['Found_search_match'], $total_match_count) : sprintf($lang['Found_search_matches'], $total_match_count);
 717             
 718             		$template->assign_vars(array(
 719             			'L_SEARCH_MATCHES' => $l_search_matches, 
 720             			'L_TOPIC' => $lang['Topic'])
 721             		);
 722             
 723             		$highlight_active = '';
 724             		$highlight_match = array();
 725             		for($j = 0; $j < count($split_search); $j++ )
 726             		{
 727             			$split_word = $split_search[$j];
 728             
 729             			if ( $split_word != 'and' && $split_word != 'or' && $split_word != 'not' )
 730             			{
 731             				$highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $split_word) . ')\b#is';
 732             				$highlight_active .= " " . $split_word;
 733             
 734             				for ($k = 0; $k < count($synonym_array); $k++)
 735             				{ 
 736 rizwank 1.1 					list($replace_synonym, $match_synonym) = split(' ', trim(strtolower($synonym_array[$k]))); 
 737             
 738             					if ( $replace_synonym == $split_word )
 739             					{
 740             						$highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $replace_synonym) . ')\b#is';
 741             						$highlight_active .= ' ' . $match_synonym;
 742             					}
 743             				} 
 744             			}
 745             		}
 746             
 747             		$highlight_active = urlencode(trim($highlight_active));
 748             
 749             		$tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
 750             		$tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
 751             
 752             		for($i = 0; $i < count($searchset); $i++)
 753             		{
 754             			$forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $searchset[$i]['forum_id']);
 755             			$topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $searchset[$i]['topic_id'] . "&amp;highlight=$highlight_active");
 756             			$post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $searchset[$i]['post_id'] . "&amp;highlight=$highlight_active") . '#' . $searchset[$i]['post_id'];
 757 rizwank 1.1 
 758             			$post_date = create_date($board_config['default_dateformat'], $searchset[$i]['post_time'], $board_config['board_timezone']);
 759             
 760             			$message = $searchset[$i]['post_text'];
 761             			$topic_title = $searchset[$i]['topic_title'];
 762             
 763             			$forum_id = $searchset[$i]['forum_id'];
 764             			$topic_id = $searchset[$i]['topic_id'];
 765             
 766             			if ( $show_results == 'posts' )
 767             			{
 768             				if ( isset($return_chars) )
 769             				{
 770             					$bbcode_uid = $searchset[$i]['bbcode_uid'];
 771             
 772             					//
 773             					// If the board has HTML off but the post has HTML
 774             					// on then we process it, else leave it alone
 775             					//
 776             					if ( $return_chars != -1 )
 777             					{
 778 rizwank 1.1 						$message = strip_tags($message);
 779             						$message = preg_replace("/\[.*?:$bbcode_uid:?.*?\]/si", '', $message);
 780             						$message = preg_replace('/\[url\]|\[\/url\]/si', '', $message);
 781             						$message = ( strlen($message) > $return_chars ) ? substr($message, 0, $return_chars) . ' ...' : $message;
 782             
 783             						if ( count($search_string) )
 784             						{
 785             							$message = preg_replace($search_string, $replace_string, $message);
 786             						}
 787             					}
 788             					else
 789             					{
 790             						if ( !$board_config['allow_html'] )
 791             						{
 792             							if ( $postrow[$i]['enable_html'] )
 793             							{
 794             								$message = preg_replace('#(<)([\/]?.*?)(>)#is', '&lt;\\2&gt;', $message);
 795             							}
 796             						}
 797             
 798             						if ( $bbcode_uid != '' )
 799 rizwank 1.1 						{
 800             							$message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
 801             						}
 802             
 803             						$message = make_clickable($message);
 804             
 805             						if ( $highlight_active )
 806             						{
 807             							if ( preg_match('/<.*>/', $message) )
 808             							{
 809             								$message = preg_replace($highlight_match, '<!-- #sh -->\1<!-- #eh -->', $message);
 810             
 811             								$end_html = 0;
 812             								$start_html = 1;
 813             								$temp_message = '';
 814             								$message = ' ' . $message . ' ';
 815             
 816             								while( $start_html = strpos($message, '<', $start_html) )
 817             								{
 818             									$grab_length = $start_html - $end_html - 1;
 819             									$temp_message .= substr($message, $end_html + 1, $grab_length);
 820 rizwank 1.1 
 821             									if ( $end_html = strpos($message, '>', $start_html) )
 822             									{
 823             										$length = $end_html - $start_html + 1;
 824             										$hold_string = substr($message, $start_html, $length);
 825             
 826             										if ( strrpos(' ' . $hold_string, '<') != 1 )
 827             										{
 828             											$end_html = $start_html + 1;
 829             											$end_counter = 1;
 830             
 831             											while ( $end_counter && $end_html < strlen($message) )
 832             											{
 833             												if ( substr($message, $end_html, 1) == '>' )
 834             												{
 835             													$end_counter--;
 836             												}
 837             												else if ( substr($message, $end_html, 1) == '<' )
 838             												{
 839             													$end_counter++;
 840             												}
 841 rizwank 1.1 
 842             												$end_html++;
 843             											}
 844             
 845             											$length = $end_html - $start_html + 1;
 846             											$hold_string = substr($message, $start_html, $length);
 847             											$hold_string = str_replace('<!-- #sh -->', '', $hold_string);
 848             											$hold_string = str_replace('<!-- #eh -->', '', $hold_string);
 849             										}
 850             										else if ( $hold_string == '<!-- #sh -->' )
 851             										{
 852             											$hold_string = str_replace('<!-- #sh -->', '<span style="color:#' . $theme['fontcolor3'] . '"><b>', $hold_string);
 853             										}
 854             										else if ( $hold_string == '<!-- #eh -->' )
 855             										{
 856             											$hold_string = str_replace('<!-- #eh -->', '</b></span>', $hold_string);
 857             										}
 858             
 859             										$temp_message .= $hold_string;
 860             
 861             										$start_html += $length;
 862 rizwank 1.1 									}
 863             									else
 864             									{
 865             										$start_html = strlen($message);
 866             									}
 867             								}
 868             
 869             								$grab_length = strlen($message) - $end_html - 1;
 870             								$temp_message .= substr($message, $end_html + 1, $grab_length);
 871             
 872             								$message = trim($temp_message);
 873             							}
 874             							else
 875             							{
 876             								$message = preg_replace($highlight_match, '<span style="color:#' . $theme['fontcolor3'] . '"><b>\1</b></span>', $message);
 877             							}
 878             						}
 879             					}
 880             
 881             					if ( count($orig_word) )
 882             					{
 883 rizwank 1.1 						$topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
 884             						$post_subject = ( $searchset[$i]['post_subject'] != "" ) ? preg_replace($orig_word, $replacement_word, $searchset[$i]['post_subject']) : $topic_title;
 885             
 886             						$message = preg_replace($orig_word, $replacement_word, $message);
 887             					}
 888             					else
 889             					{
 890             						$post_subject = ( $searchset[$i]['post_subject'] != '' ) ? $searchset[$i]['post_subject'] : $topic_title;
 891             					}
 892             
 893             					if ($board_config['allow_smilies'] && $searchset[$i]['enable_smilies'])
 894             					{
 895             						$message = smilies_pass($message);
 896             					}
 897             
 898             					$message = str_replace("\n", '<br />', $message);
 899             
 900             				}
 901             
 902             				$poster = ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=" . $searchset[$i]['user_id']) . '">' : '';
 903             				$poster .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? $searchset[$i]['username'] : ( ( $searchset[$i]['post_username'] != "" ) ? $searchset[$i]['post_username'] : $lang['Guest'] );
 904 rizwank 1.1 				$poster .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '</a>' : '';
 905             
 906             				if ( $userdata['session_logged_in'] && $searchset[$i]['post_time'] > $userdata['user_lastvisit'] )
 907             				{
 908             					if ( !empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]) )
 909             					{
 910             						$topic_last_read = ( $tracking_topics[$topic_id] > $tracking_forums[$forum_id] ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
 911             					}
 912             					else if ( !empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]) )
 913             					{
 914             						$topic_last_read = ( !empty($tracking_topics[$topic_id]) ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
 915             					}
 916             
 917             					if ( $searchset[$i]['post_time'] > $topic_last_read )
 918             					{
 919             						$mini_post_img = $images['icon_minipost_new'];
 920             						$mini_post_alt = $lang['New_post'];
 921             					}
 922             					else
 923             					{
 924             						$mini_post_img = $images['icon_minipost'];
 925 rizwank 1.1 						$mini_post_alt = $lang['Post'];
 926             					}
 927             				}
 928             				else
 929             				{
 930             					$mini_post_img = $images['icon_minipost'];
 931             					$mini_post_alt = $lang['Post'];
 932             				}
 933             
 934             				$template->assign_block_vars("searchresults", array( 
 935             					'TOPIC_TITLE' => $topic_title,
 936             					'FORUM_NAME' => $searchset[$i]['forum_name'],
 937             					'POST_SUBJECT' => $post_subject,
 938             					'POST_DATE' => $post_date,
 939             					'POSTER_NAME' => $poster,
 940             					'TOPIC_REPLIES' => $searchset[$i]['topic_replies'],
 941             					'TOPIC_VIEWS' => $searchset[$i]['topic_views'],
 942             					'MESSAGE' => $message,
 943             					'MINI_POST_IMG' => $mini_post_img, 
 944             
 945             					'L_MINI_POST_ALT' => $mini_post_alt, 
 946 rizwank 1.1 
 947             					'U_POST' => $post_url,
 948             					'U_TOPIC' => $topic_url,
 949             					'U_FORUM' => $forum_url)
 950             				);
 951             			}
 952             			else
 953             			{
 954             				$message = '';
 955             
 956             				if ( count($orig_word) )
 957             				{
 958             					$topic_title = preg_replace($orig_word, $replacement_word, $searchset[$i]['topic_title']);
 959             				}
 960             
 961             				$topic_type = $searchset[$i]['topic_type'];
 962             
 963             				if ($topic_type == POST_ANNOUNCE)
 964             				{
 965             					$topic_type = $lang['Topic_Announcement'] . ' ';
 966             				}
 967 rizwank 1.1 				else if ($topic_type == POST_STICKY)
 968             				{
 969             					$topic_type = $lang['Topic_Sticky'] . ' ';
 970             				}
 971             				else
 972             				{
 973             					$topic_type = '';
 974             				}
 975             
 976             				if ( $searchset[$i]['topic_vote'] )
 977             				{
 978             					$topic_type .= $lang['Topic_Poll'] . ' ';
 979             				}
 980             
 981             				$views = $searchset[$i]['topic_views'];
 982             				$replies = $searchset[$i]['topic_replies'];
 983             
 984             				if ( ( $replies + 1 ) > $board_config['posts_per_page'] )
 985             				{
 986             					$total_pages = ceil( ( $replies + 1 ) / $board_config['posts_per_page'] );
 987             					$goto_page = ' [ <img src="' . $images['icon_gotopost'] . '" alt="' . $lang['Goto_page'] . '" title="' . $lang['Goto_page'] . '" />' . $lang['Goto_page'] . ': ';
 988 rizwank 1.1 
 989             					$times = 1;
 990             					for($j = 0; $j < $replies + 1; $j += $board_config['posts_per_page'])
 991             					{
 992             						$goto_page .= '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $topic_id . "&amp;start=$j") . '">' . $times . '</a>';
 993             						if ( $times == 1 && $total_pages > 4 )
 994             						{
 995             							$goto_page .= ' ... ';
 996             							$times = $total_pages - 3;
 997             							$j += ( $total_pages - 4 ) * $board_config['posts_per_page'];
 998             						}
 999             						else if ( $times < $total_pages )
1000             						{
1001             							$goto_page .= ', ';
1002             						}
1003             						$times++;
1004             					}
1005             					$goto_page .= ' ] ';
1006             				}
1007             				else
1008             				{
1009 rizwank 1.1 					$goto_page = '';
1010             				}
1011             
1012             				if ( $searchset[$i]['topic_status'] == TOPIC_MOVED )
1013             				{
1014             					$topic_type = $lang['Topic_Moved'] . ' ';
1015             					$topic_id = $searchset[$i]['topic_moved_id'];
1016             
1017             					$folder_image = '<img src="' . $images['folder'] . '" alt="' . $lang['No_new_posts'] . '" />';
1018             					$newest_post_img = '';
1019             				}
1020             				else
1021             				{
1022             					if ( $searchset[$i]['topic_status'] == TOPIC_LOCKED )
1023             					{
1024             						$folder = $images['folder_locked'];
1025             						$folder_new = $images['folder_locked_new'];
1026             					}
1027             					else if ( $searchset[$i]['topic_type'] == POST_ANNOUNCE )
1028             					{
1029             						$folder = $images['folder_announce'];
1030 rizwank 1.1 						$folder_new = $images['folder_announce_new'];
1031             					}
1032             					else if ( $searchset[$i]['topic_type'] == POST_STICKY )
1033             					{
1034             						$folder = $images['folder_sticky'];
1035             						$folder_new = $images['folder_sticky_new'];
1036             					}
1037             					else
1038             					{
1039             						if ( $replies >= $board_config['hot_threshold'] )
1040             						{
1041             							$folder = $images['folder_hot'];
1042             							$folder_new = $images['folder_hot_new'];
1043             						}
1044             						else
1045             						{
1046             							$folder = $images['folder'];
1047             							$folder_new = $images['folder_new'];
1048             						}
1049             					}
1050             
1051 rizwank 1.1 					if ( $userdata['session_logged_in'] )
1052             					{
1053             						if ( $searchset[$i]['post_time'] > $userdata['user_lastvisit'] ) 
1054             						{
1055             							if ( !empty($tracking_topics) || !empty($tracking_forums) || isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
1056             							{
1057             
1058             								$unread_topics = true;
1059             
1060             								if ( !empty($tracking_topics[$topic_id]) )
1061             								{
1062             									if ( $tracking_topics[$topic_id] > $searchset[$i]['post_time'] )
1063             									{
1064             										$unread_topics = false;
1065             									}
1066             								}
1067             
1068             								if ( !empty($tracking_forums[$forum_id]) )
1069             								{
1070             									if ( $tracking_forums[$forum_id] > $searchset[$i]['post_time'] )
1071             									{
1072 rizwank 1.1 										$unread_topics = false;
1073             									}
1074             								}
1075             
1076             								if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
1077             								{
1078             									if ( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] > $searchset[$i]['post_time'] )
1079             									{
1080             										$unread_topics = false;
1081             									}
1082             								}
1083             
1084             								if ( $unread_topics )
1085             								{
1086             									$folder_image = $folder_new;
1087             									$folder_alt = $lang['New_posts'];
1088             
1089             									$newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
1090             								}
1091             								else
1092             								{
1093 rizwank 1.1 									$folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
1094             
1095             									$folder_image = $folder;
1096             									$folder_alt = $folder_alt;
1097             									$newest_post_img = '';
1098             								}
1099             
1100             							}
1101             							else if ( $searchset[$i]['post_time'] > $userdata['user_lastvisit'] ) 
1102             							{
1103             								$folder_image = $folder_new;
1104             								$folder_alt = $lang['New_posts'];
1105             
1106             								$newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> ';
1107             							}
1108             							else 
1109             							{
1110             								$folder_image = $folder;
1111             								$folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
1112             								$newest_post_img = '';
1113             							}
1114 rizwank 1.1 						}
1115             						else
1116             						{
1117             							$folder_image = $folder;
1118             							$folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
1119             							$newest_post_img = '';
1120             						}
1121             					}
1122             					else
1123             					{
1124             						$folder_image = $folder;
1125             						$folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
1126             						$newest_post_img = '';
1127             					}
1128             				}
1129             
1130             
1131             				$topic_author = ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $searchset[$i]['user_id']) . '">' : '';
1132             				$topic_author .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? $searchset[$i]['username'] : ( ( $searchset[$i]['post_username'] != '' ) ? $searchset[$i]['post_username'] : $lang['Guest'] );
1133             
1134             				$topic_author .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '</a>' : '';
1135 rizwank 1.1 
1136             				$first_post_time = create_date($board_config['default_dateformat'], $searchset[$i]['topic_time'], $board_config['board_timezone']);
1137             
1138             				$last_post_time = create_date($board_config['default_dateformat'], $searchset[$i]['post_time'], $board_config['board_timezone']);
1139             
1140             				$last_post_author = ( $searchset[$i]['id2'] == ANONYMOUS ) ? ( ($searchset[$i]['post_username2'] != '' ) ? $searchset[$i]['post_username2'] . ' ' : $lang['Guest'] . ' ' ) : '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '='  . $searchset[$i]['id2']) . '">' . $searchset[$i]['user2'] . '</a>';
1141             
1142             				$last_post_url = '<a href="' . append_sid("viewtopic.$phpEx?"  . POST_POST_URL . '=' . $searchset[$i]['topic_last_post_id']) . '#' . $searchset[$i]['topic_last_post_id'] . '"><img src="' . $images['icon_latest_reply'] . '" alt="' . $lang['View_latest_post'] . '" title="' . $lang['View_latest_post'] . '" border="0" /></a>';
1143             
1144             				$template->assign_block_vars('searchresults', array( 
1145             					'FORUM_NAME' => $searchset[$i]['forum_name'],
1146             					'FORUM_ID' => $forum_id,
1147             					'TOPIC_ID' => $topic_id,
1148             					'FOLDER' => $folder_image,
1149             					'NEWEST_POST_IMG' => $newest_post_img, 
1150             					'TOPIC_FOLDER_IMG' => $folder_image, 
1151             					'GOTO_PAGE' => $goto_page,
1152             					'REPLIES' => $replies,
1153             					'TOPIC_TITLE' => $topic_title,
1154             					'TOPIC_TYPE' => $topic_type,
1155             					'VIEWS' => $views,
1156 rizwank 1.1 					'TOPIC_AUTHOR' => $topic_author, 
1157             					'FIRST_POST_TIME' => $first_post_time, 
1158             					'LAST_POST_TIME' => $last_post_time,
1159             					'LAST_POST_AUTHOR' => $last_post_author,
1160             					'LAST_POST_IMG' => $last_post_url,
1161             
1162             					'L_TOPIC_FOLDER_ALT' => $folder_alt, 
1163             
1164             					'U_VIEW_FORUM' => $forum_url, 
1165             					'U_VIEW_TOPIC' => $topic_url)
1166             				);
1167             			}
1168             		}
1169             
1170             		$base_url = "search.$phpEx?search_id=$search_id";
1171             
1172             		$template->assign_vars(array(
1173             			'PAGINATION' => generate_pagination($base_url, $total_match_count, $per_page, $start),
1174             			'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $per_page ) + 1 ), ceil( $total_match_count / $per_page )), 
1175             
1176             			'L_AUTHOR' => $lang['Author'],
1177 rizwank 1.1 			'L_MESSAGE' => $lang['Message'],
1178             			'L_FORUM' => $lang['Forum'],
1179             			'L_TOPICS' => $lang['Topics'],
1180             			'L_REPLIES' => $lang['Replies'],
1181             			'L_VIEWS' => $lang['Views'],
1182             			'L_POSTS' => $lang['Posts'],
1183             			'L_LASTPOST' => $lang['Last_Post'], 
1184             			'L_POSTED' => $lang['Posted'], 
1185             			'L_SUBJECT' => $lang['Subject'],
1186             
1187             			'L_GOTO_PAGE' => $lang['Goto_page'])
1188             		);
1189             
1190             		$template->pparse('body');
1191             
1192             		include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
1193             	}
1194             	else
1195             	{
1196             		message_die(GENERAL_MESSAGE, $lang['No_search_match']);
1197             	}
1198 rizwank 1.1 }
1199             
1200             //
1201             // Search forum
1202             //
1203             $sql = "SELECT c.cat_title, c.cat_id, f.forum_name, f.forum_id  
1204             	FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f
1205             	WHERE f.cat_id = c.cat_id 
1206             	ORDER BY c.cat_id, f.forum_order";
1207             $result = $db->sql_query($sql);
1208             if ( !$result )
1209             {
1210             	message_die(GENERAL_ERROR, 'Could not obtain forum_name/forum_id', '', __LINE__, __FILE__, $sql);
1211             }
1212             
1213             $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
1214             
1215             $s_forums = '';
1216             while( $row = $db->sql_fetchrow($result) )
1217             {
1218             	if ( $is_auth_ary[$row['forum_id']]['auth_read'] )
1219 rizwank 1.1 	{
1220             		$s_forums .= '<option value="' . $row['forum_id'] . '">' . $row['forum_name'] . '</option>';
1221             		if ( empty($list_cat[$row['cat_id']]) )
1222             		{
1223             			$list_cat[$row['cat_id']] = $row['cat_title'];
1224             		}
1225             	}
1226             }
1227             
1228             if ( $s_forums != '' )
1229             {
1230             	$s_forums = '<option value="-1">' . $lang['All_available'] . '</option>' . $s_forums;
1231             
1232             	//
1233             	// Category to search
1234             	//
1235             	$s_categories = '<option value="-1">' . $lang['All_available'] . '</option>';
1236             	while( list($cat_id, $cat_title) = @each($list_cat))
1237             	{
1238             		$s_categories .= '<option value="' . $cat_id . '">' . $cat_title . '</option>';
1239             	}
1240 rizwank 1.1 }
1241             else
1242             {
1243             	message_die(GENERAL_MESSAGE, $lang['No_searchable_forums']);
1244             }
1245             
1246             //
1247             // Number of chars returned
1248             //
1249             $s_characters = '<option value="-1">' . $lang['All_available'] . '</option>';
1250             $s_characters .= '<option value="0">0</option>';
1251             $s_characters .= '<option value="25">25</option>';
1252             $s_characters .= '<option value="50">50</option>';
1253             
1254             for($i = 100; $i < 1100 ; $i += 100)
1255             {
1256             	$selected = ( $i == 200 ) ? ' selected="selected"' : '';
1257             	$s_characters .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
1258             }
1259             
1260             //
1261 rizwank 1.1 // Sorting
1262             //
1263             $s_sort_by = "";
1264             for($i = 0; $i < count($sort_by_types); $i++)
1265             {
1266             	$s_sort_by .= '<option value="' . $i . '">' . $sort_by_types[$i] . '</option>';
1267             }
1268             
1269             //
1270             // Search time
1271             //
1272             $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
1273             $previous_days_text = array($lang['All_Posts'], $lang['1_Day'], $lang['7_Days'], $lang['2_Weeks'], $lang['1_Month'], $lang['3_Months'], $lang['6_Months'], $lang['1_Year']);
1274             
1275             $s_time = '';
1276             for($i = 0; $i < count($previous_days); $i++)
1277             {
1278             	$selected = ( $topic_days == $previous_days[$i] ) ? ' selected="selected"' : '';
1279             	$s_time .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
1280             }
1281             
1282 rizwank 1.1 //
1283             // Output the basic page
1284             //
1285             $page_title = $lang['Search'];
1286             include($phpbb_root_path . 'includes/page_header.'.$phpEx);
1287             
1288             $template->set_filenames(array(
1289             	'body' => 'search_body.tpl')
1290             );
1291             make_jumpbox('viewforum.'.$phpEx);
1292             
1293             $template->assign_vars(array(
1294             	'L_SEARCH_QUERY' => $lang['Search_query'], 
1295             	'L_SEARCH_OPTIONS' => $lang['Search_options'], 
1296             	'L_SEARCH_KEYWORDS' => $lang['Search_keywords'], 
1297             	'L_SEARCH_KEYWORDS_EXPLAIN' => $lang['Search_keywords_explain'], 
1298             	'L_SEARCH_AUTHOR' => $lang['Search_author'],
1299             	'L_SEARCH_AUTHOR_EXPLAIN' => $lang['Search_author_explain'], 
1300             	'L_SEARCH_ANY_TERMS' => $lang['Search_for_any'],
1301             	'L_SEARCH_ALL_TERMS' => $lang['Search_for_all'], 
1302             	'L_SEARCH_MESSAGE_ONLY' => $lang['Search_msg_only'], 
1303 rizwank 1.1 	'L_SEARCH_MESSAGE_TITLE' => $lang['Search_title_msg'], 
1304             	'L_CATEGORY' => $lang['Category'], 
1305             	'L_RETURN_FIRST' => $lang['Return_first'],
1306             	'L_CHARACTERS' => $lang['characters_posts'], 
1307             	'L_SORT_BY' => $lang['Sort_by'],
1308             	'L_SORT_ASCENDING' => $lang['Sort_Ascending'],
1309             	'L_SORT_DESCENDING' => $lang['Sort_Descending'],
1310             	'L_SEARCH_PREVIOUS' => $lang['Search_previous'], 
1311             	'L_DISPLAY_RESULTS' => $lang['Display_results'], 
1312             	'L_FORUM' => $lang['Forum'],
1313             	'L_TOPICS' => $lang['Topics'],
1314             	'L_POSTS' => $lang['Posts'],
1315             
1316             	'S_SEARCH_ACTION' => append_sid("search.$phpEx?mode=results"),
1317             	'S_CHARACTER_OPTIONS' => $s_characters,
1318             	'S_FORUM_OPTIONS' => $s_forums, 
1319             	'S_CATEGORY_OPTIONS' => $s_categories, 
1320             	'S_TIME_OPTIONS' => $s_time, 
1321             	'S_SORT_OPTIONS' => $s_sort_by,
1322             	'S_HIDDEN_FIELDS' => '')
1323             );
1324 rizwank 1.1 
1325             $template->pparse('body');
1326             
1327             include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
1328             
1329             ?>

Rizwan Kassim
Powered by
ViewCVS 0.9.2