Blame Identity/Webenv/phpBB/3.0.4/includes/acp/acp_search.php

ef5584
ef5584
/**
ef5584
*
ef5584
* @package acp
ef5584
* @version $Id: acp_search.php 8479 2008-03-29 00:22:48Z naderman $
ef5584
* @copyright (c) 2005 phpBB Group
ef5584
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
ef5584
*
ef5584
*/
ef5584
ef5584
/**
ef5584
* @ignore
ef5584
*/
ef5584
if (!defined('IN_PHPBB'))
ef5584
{
ef5584
	exit;
ef5584
}
ef5584
ef5584
/**
ef5584
* @package acp
ef5584
*/
ef5584
class acp_search
ef5584
{
ef5584
	var $u_action;
ef5584
	var $state;
ef5584
	var $search;
ef5584
	var $max_post_id;
ef5584
	var $batch_size = 100;
ef5584
ef5584
	function main($id, $mode)
ef5584
	{
ef5584
		global $user;
ef5584
ef5584
		$user->add_lang('acp/search');
ef5584
ef5584
		// For some this may be of help...
ef5584
		@ini_set('memory_limit', '128M');
ef5584
ef5584
		switch ($mode)
ef5584
		{
ef5584
			case 'settings':
ef5584
				$this->settings($id, $mode);
ef5584
			break;
ef5584
ef5584
			case 'index':
ef5584
				$this->index($id, $mode);
ef5584
			break;
ef5584
		}
ef5584
	}
ef5584
ef5584
	function settings($id, $mode)
ef5584
	{
ef5584
		global $db, $user, $auth, $template, $cache;
ef5584
		global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
ef5584
ef5584
		$submit = (isset($_POST['submit'])) ? true : false;
ef5584
ef5584
		$search_types = $this->get_search_types();
ef5584
ef5584
		$settings = array(
ef5584
			'search_interval'			=> 'float',
ef5584
			'search_anonymous_interval'	=> 'float',
ef5584
			'load_search'				=> 'bool',
ef5584
			'limit_search_load'			=> 'float',
ef5584
			'min_search_author_chars'	=> 'integer',
ef5584
			'search_store_results'		=> 'integer',
ef5584
		);
ef5584
ef5584
		$search = null;
ef5584
		$error = false;
ef5584
		$search_options = '';
ef5584
		foreach ($search_types as $type)
ef5584
		{
ef5584
			if ($this->init_search($type, $search, $error))
ef5584
			{
ef5584
				continue;
ef5584
			}
ef5584
ef5584
			$name = ucfirst(strtolower(str_replace('_', ' ', $type)));
ef5584
			$selected = ($config['search_type'] == $type) ? ' selected="selected"' : '';
ef5584
			$search_options .= '<option value="' . $type . '"' . $selected . '>' . $name . '</option>';
ef5584
ef5584
			if (method_exists($search, 'acp'))
ef5584
			{
ef5584
				$vars = $search->acp();
ef5584
ef5584
				if (!$submit)
ef5584
				{
ef5584
					$template->assign_block_vars('backend', array(
ef5584
						'NAME'		=> $name,
ef5584
						'SETTINGS'	=> $vars['tpl'])
ef5584
					);
ef5584
				}
ef5584
				else if (is_array($vars['config']))
ef5584
				{
ef5584
					$settings = array_merge($settings, $vars['config']);
ef5584
				}
ef5584
			}
ef5584
		}
ef5584
		unset($search);
ef5584
		unset($error);
ef5584
ef5584
		$cfg_array = (isset($_REQUEST['config'])) ? request_var('config', array('' => ''), true) : array();
ef5584
		$updated = request_var('updated', false);
ef5584
ef5584
		foreach ($settings as $config_name => $var_type)
ef5584
		{
ef5584
			if (!isset($cfg_array[$config_name]))
ef5584
			{
ef5584
				continue;
ef5584
			}
ef5584
ef5584
			// e.g. integer:4:12 (min 4, max 12)
ef5584
			$var_type = explode(':', $var_type);
ef5584
ef5584
			$config_value = $cfg_array[$config_name];
ef5584
			settype($config_value, $var_type[0]);
ef5584
ef5584
			if (isset($var_type[1]))
ef5584
			{
ef5584
				$config_value = max($var_type[1], $config_value);
ef5584
			}
ef5584
ef5584
			if (isset($var_type[2]))
ef5584
			{
ef5584
				$config_value = min($var_type[2], $config_value);
ef5584
			}
ef5584
ef5584
			// only change config if anything was actually changed
ef5584
			if ($submit && ($config[$config_name] != $config_value))
ef5584
			{
ef5584
				set_config($config_name, $config_value);
ef5584
				$updated = true;
ef5584
			}
ef5584
		}
ef5584
ef5584
		if ($submit)
ef5584
		{
ef5584
			$extra_message = '';
ef5584
			if ($updated)
ef5584
			{
ef5584
				add_log('admin', 'LOG_CONFIG_SEARCH');
ef5584
			}
ef5584
ef5584
			if (isset($cfg_array['search_type']) && in_array($cfg_array['search_type'], $search_types, true) && ($cfg_array['search_type'] != $config['search_type']))
ef5584
			{
ef5584
				$search = null;
ef5584
				$error = false;
ef5584
ef5584
				if (!$this->init_search($cfg_array['search_type'], $search, $error))
ef5584
				{
ef5584
					if (confirm_box(true))
ef5584
					{
ef5584
						if (!method_exists($search, 'init') || !($error = $search->init()))
ef5584
						{
ef5584
							set_config('search_type', $cfg_array['search_type']);
ef5584
ef5584
							if (!$updated)
ef5584
							{
ef5584
								add_log('admin', 'LOG_CONFIG_SEARCH');
ef5584
							}
ef5584
							$extra_message = '
' . $user->lang['SWITCHED_SEARCH_BACKEND'] . '
» ' . $user->lang['GO_TO_SEARCH_INDEX'] . '';
ef5584
						}
ef5584
						else
ef5584
						{
ef5584
							trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
						}
ef5584
					}
ef5584
					else
ef5584
					{
ef5584
						confirm_box(false, $user->lang['CONFIRM_SEARCH_BACKEND'], build_hidden_fields(array(
ef5584
							'i'			=> $id,
ef5584
							'mode'		=> $mode,
ef5584
							'submit'	=> true,
ef5584
							'updated'	=> $updated,
ef5584
							'config'	=> array('search_type' => $cfg_array['search_type']),
ef5584
						)));
ef5584
					}
ef5584
				}
ef5584
				else
ef5584
				{
ef5584
					trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
				}
ef5584
			}
ef5584
ef5584
			$search = null;
ef5584
			$error = false;
ef5584
			if (!$this->init_search($config['search_type'], $search, $error))
ef5584
			{
ef5584
				if ($updated)
ef5584
				{
ef5584
					if (method_exists($search, 'config_updated'))
ef5584
					{
ef5584
						if ($search->config_updated())
ef5584
						{
ef5584
							trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
						}
ef5584
					}
ef5584
				}
ef5584
			}
ef5584
			else
ef5584
			{
ef5584
				trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
			}
ef5584
ef5584
			trigger_error($user->lang['CONFIG_UPDATED'] . $extra_message . adm_back_link($this->u_action));
ef5584
		}
ef5584
		unset($cfg_array);
ef5584
ef5584
		$this->tpl_name = 'acp_search';
ef5584
		$this->page_title = 'ACP_SEARCH_SETTINGS';
ef5584
ef5584
		$template->assign_vars(array(
ef5584
			'LIMIT_SEARCH_LOAD'		=> (float) $config['limit_search_load'],
ef5584
			'MIN_SEARCH_AUTHOR_CHARS'	=> (int) $config['min_search_author_chars'],
ef5584
			'SEARCH_INTERVAL'		=> (float) $config['search_interval'],
ef5584
			'SEARCH_GUEST_INTERVAL'	=> (float) $config['search_anonymous_interval'],
ef5584
			'SEARCH_STORE_RESULTS'	=> (int) $config['search_store_results'],
ef5584
ef5584
			'S_SEARCH_TYPES'		=> $search_options,
ef5584
			'S_YES_SEARCH'			=> (bool) $config['load_search'],
ef5584
			'S_SETTINGS'			=> true,
ef5584
ef5584
			'U_ACTION'				=> $this->u_action)
ef5584
		);
ef5584
	}
ef5584
ef5584
	function index($id, $mode)
ef5584
	{
ef5584
		global $db, $user, $auth, $template, $cache;
ef5584
		global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
ef5584
ef5584
		if (isset($_REQUEST['action']) && is_array($_REQUEST['action']))
ef5584
		{
ef5584
			$action = request_var('action', array('' => false));
ef5584
			$action = key($action);
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			$action = request_var('action', '');
ef5584
		}
ef5584
		$this->state = explode(',', $config['search_indexing_state']);
ef5584
ef5584
		if (isset($_POST['cancel']))
ef5584
		{
ef5584
			$action = '';
ef5584
			$this->state = array();
ef5584
			$this->save_state();
ef5584
		}
ef5584
ef5584
		if ($action)
ef5584
		{
ef5584
			switch ($action)
ef5584
			{
ef5584
				case 'progress_bar':
ef5584
					$type = request_var('type', '');
ef5584
					$this->display_progress_bar($type);
ef5584
				break;
ef5584
ef5584
				case 'delete':
ef5584
					$this->state[1] = 'delete';
ef5584
				break;
ef5584
ef5584
				case 'create':
ef5584
					$this->state[1] = 'create';
ef5584
				break;
ef5584
ef5584
				default:
ef5584
					trigger_error('NO_ACTION', E_USER_ERROR);
ef5584
				break;
ef5584
			}
ef5584
ef5584
			if (empty($this->state[0]))
ef5584
			{
ef5584
				$this->state[0] = request_var('search_type', '');
ef5584
			}
ef5584
ef5584
			$this->search = null;
ef5584
			$error = false;
ef5584
			if ($this->init_search($this->state[0], $this->search, $error))
ef5584
			{
ef5584
				trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
			}
ef5584
			$name = ucfirst(strtolower(str_replace('_', ' ', $this->state[0])));
ef5584
ef5584
			$action = &$this->state[1];
ef5584
ef5584
			$this->max_post_id = $this->get_max_post_id();
ef5584
ef5584
			$post_counter = (isset($this->state[2])) ? $this->state[2] : 0;
ef5584
			$this->state[2] = &$post_counter;
ef5584
			$this->save_state();
ef5584
ef5584
			switch ($action)
ef5584
			{
ef5584
				case 'delete':
ef5584
					if (method_exists($this->search, 'delete_index'))
ef5584
					{
ef5584
						// pass a reference to myself so the $search object can make use of save_state() and attributes
ef5584
						if ($error = $this->search->delete_index($this, append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=delete", false)))
ef5584
						{
ef5584
							$this->state = array('');
ef5584
							$this->save_state();
ef5584
							trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
ef5584
						}
ef5584
					}
ef5584
					else
ef5584
					{
ef5584
						$starttime = explode(' ', microtime());
ef5584
						$starttime = $starttime[1] + $starttime[0];
ef5584
						$row_count = 0;
ef5584
						while (still_on_time() && $post_counter <= $this->max_post_id)
ef5584
						{
ef5584
							$sql = 'SELECT post_id, poster_id, forum_id
ef5584
								FROM ' . POSTS_TABLE . '
ef5584
								WHERE post_id >= ' . (int) ($post_counter + 1) . '
ef5584
									AND post_id <= ' . (int) ($post_counter + $this->batch_size);
ef5584
							$result = $db->sql_query($sql);
ef5584
ef5584
							$ids = $posters = $forum_ids = array();
ef5584
							while ($row = $db->sql_fetchrow($result))
ef5584
							{
ef5584
								$ids[] = $row['post_id'];
ef5584
								$posters[] = $row['poster_id'];
ef5584
								$forum_ids[] = $row['forum_id'];
ef5584
							}
ef5584
							$db->sql_freeresult($result);
ef5584
							$row_count += sizeof($ids);
ef5584
ef5584
							if (sizeof($ids))
ef5584
							{
ef5584
								$this->search->index_remove($ids, $posters, $forum_ids);
ef5584
							}
ef5584
ef5584
							$post_counter += $this->batch_size;
ef5584
						}
ef5584
						// save the current state
ef5584
						$this->save_state();
ef5584
ef5584
						if ($post_counter <= $this->max_post_id)
ef5584
						{
ef5584
							$mtime = explode(' ', microtime());
ef5584
							$totaltime = $mtime[0] + $mtime[1] - $starttime;
ef5584
							$rows_per_second = $row_count / $totaltime;
ef5584
							meta_refresh(1, append_sid($this->u_action . '&action=delete&skip_rows=' . $post_counter));
ef5584
							trigger_error(sprintf($user->lang['SEARCH_INDEX_DELETE_REDIRECT'], $post_counter, $row_count, $rows_per_second));
ef5584
						}
ef5584
					}
ef5584
ef5584
					$this->search->tidy();
ef5584
ef5584
					$this->state = array('');
ef5584
					$this->save_state();
ef5584
ef5584
					add_log('admin', 'LOG_SEARCH_INDEX_REMOVED', $name);
ef5584
					trigger_error($user->lang['SEARCH_INDEX_REMOVED'] . adm_back_link($this->u_action) . $this->close_popup_js());
ef5584
				break;
ef5584
ef5584
				case 'create':
ef5584
					if (method_exists($this->search, 'create_index'))
ef5584
					{
ef5584
						// pass a reference to acp_search so the $search object can make use of save_state() and attributes
ef5584
						if ($error = $this->search->create_index($this, append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=create", false)))
ef5584
						{
ef5584
							$this->state = array('');
ef5584
							$this->save_state();
ef5584
							trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
ef5584
						}
ef5584
					}
ef5584
					else
ef5584
					{
ef5584
						$sql = 'SELECT forum_id, enable_indexing
ef5584
							FROM ' . FORUMS_TABLE;
ef5584
						$result = $db->sql_query($sql, 3600);
ef5584
ef5584
						while ($row = $db->sql_fetchrow($result))
ef5584
						{
ef5584
							$forums[$row['forum_id']] = (bool) $row['enable_indexing'];
ef5584
						}
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
						$starttime = explode(' ', microtime());
ef5584
						$starttime = $starttime[1] + $starttime[0];
ef5584
						$row_count = 0;
ef5584
						while (still_on_time() && $post_counter <= $this->max_post_id)
ef5584
						{
ef5584
							$sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id
ef5584
								FROM ' . POSTS_TABLE . '
ef5584
								WHERE post_id >= ' . (int) ($post_counter + 1) . '
ef5584
									AND post_id <= ' . (int) ($post_counter + $this->batch_size);
ef5584
							$result = $db->sql_query($sql);
ef5584
ef5584
							while ($row = $db->sql_fetchrow($result))
ef5584
							{
ef5584
								// Indexing enabled for this forum or global announcement?
ef5584
								// Global announcements get indexed by default.
ef5584
								if (!$row['forum_id'] || (isset($forums[$row['forum_id']]) && $forums[$row['forum_id']]))
ef5584
								{
ef5584
									$this->search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']);
ef5584
								}
ef5584
								$row_count++;
ef5584
							}
ef5584
							$db->sql_freeresult($result);
ef5584
ef5584
							$post_counter += $this->batch_size;
ef5584
						}
ef5584
						// save the current state
ef5584
						$this->save_state();
ef5584
ef5584
						// pretend the number of posts was as big as the number of ids we indexed so far
ef5584
						// just an estimation as it includes deleted posts
ef5584
						$num_posts = $config['num_posts'];
ef5584
						$config['num_posts'] = min($config['num_posts'], $post_counter);
ef5584
						$this->search->tidy();
ef5584
						$config['num_posts'] = $num_posts;
ef5584
ef5584
						if ($post_counter <= $this->max_post_id)
ef5584
						{
ef5584
							$mtime = explode(' ', microtime());
ef5584
							$totaltime = $mtime[0] + $mtime[1] - $starttime;
ef5584
							$rows_per_second = $row_count / $totaltime;
ef5584
							meta_refresh(1, append_sid($this->u_action . '&action=create&skip_rows=' . $post_counter));
ef5584
							trigger_error(sprintf($user->lang['SEARCH_INDEX_CREATE_REDIRECT'], $post_counter, $row_count, $rows_per_second));
ef5584
						}
ef5584
					}
ef5584
ef5584
					$this->search->tidy();
ef5584
ef5584
					$this->state = array('');
ef5584
					$this->save_state();
ef5584
ef5584
					add_log('admin', 'LOG_SEARCH_INDEX_CREATED', $name);
ef5584
					trigger_error($user->lang['SEARCH_INDEX_CREATED'] . adm_back_link($this->u_action) . $this->close_popup_js());
ef5584
				break;
ef5584
			}
ef5584
		}
ef5584
ef5584
		$search_types = $this->get_search_types();
ef5584
ef5584
		$search = null;
ef5584
		$error = false;
ef5584
		$search_options = '';
ef5584
		foreach ($search_types as $type)
ef5584
		{
ef5584
			if ($this->init_search($type, $search, $error) || !method_exists($search, 'index_created'))
ef5584
			{
ef5584
				continue;
ef5584
			}
ef5584
ef5584
			$name = ucfirst(strtolower(str_replace('_', ' ', $type)));
ef5584
ef5584
			$data = array();
ef5584
			if (method_exists($search, 'index_stats'))
ef5584
			{
ef5584
				$data = $search->index_stats();
ef5584
			}
ef5584
ef5584
			$statistics = array();
ef5584
			foreach ($data as $statistic => $value)
ef5584
			{
ef5584
				$n = sizeof($statistics);
ef5584
				if ($n && sizeof($statistics[$n - 1]) < 3)
ef5584
				{
ef5584
					$statistics[$n - 1] += array('statistic_2' => $statistic, 'value_2' => $value);
ef5584
				}
ef5584
				else
ef5584
				{
ef5584
					$statistics[] = array('statistic_1' => $statistic, 'value_1' => $value);
ef5584
				}
ef5584
			}
ef5584
ef5584
			$template->assign_block_vars('backend', array(
ef5584
				'L_NAME'			=> $name,
ef5584
				'NAME'				=> $type,
ef5584
ef5584
				'S_ACTIVE'			=> ($type == $config['search_type']) ? true : false,
ef5584
				'S_HIDDEN_FIELDS'	=> build_hidden_fields(array('search_type' => $type)),
ef5584
				'S_INDEXED'			=> (bool) $search->index_created(),
ef5584
				'S_STATS'			=> (bool) sizeof($statistics))
ef5584
			);
ef5584
ef5584
			foreach ($statistics as $statistic)
ef5584
			{
ef5584
				$template->assign_block_vars('backend.data', array(
ef5584
					'STATISTIC_1'	=> $statistic['statistic_1'],
ef5584
					'VALUE_1'		=> $statistic['value_1'],
ef5584
					'STATISTIC_2'	=> (isset($statistic['statistic_2'])) ? $statistic['statistic_2'] : '',
ef5584
					'VALUE_2'		=> (isset($statistic['value_2'])) ? $statistic['value_2'] : '')
ef5584
				);
ef5584
			}
ef5584
		}
ef5584
		unset($search);
ef5584
		unset($error);
ef5584
		unset($statistics);
ef5584
		unset($data);
ef5584
ef5584
		$this->tpl_name = 'acp_search';
ef5584
		$this->page_title = 'ACP_SEARCH_INDEX';
ef5584
ef5584
		$template->assign_vars(array(
ef5584
			'S_INDEX'				=> true,
ef5584
			'U_ACTION'				=> $this->u_action,
ef5584
			'U_PROGRESS_BAR'		=> append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=progress_bar"),
ef5584
			'UA_PROGRESS_BAR'		=> addslashes(append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=progress_bar")),
ef5584
		));
ef5584
ef5584
		if (isset($this->state[1]))
ef5584
		{
ef5584
			$template->assign_vars(array(
ef5584
				'S_CONTINUE_INDEXING'	=> $this->state[1],
ef5584
				'U_CONTINUE_INDEXING'	=> $this->u_action . '&action=' . $this->state[1],
ef5584
				'L_CONTINUE'			=> ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING'] : $user->lang['CONTINUE_DELETING_INDEX'],
ef5584
				'L_CONTINUE_EXPLAIN'	=> ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING_EXPLAIN'] : $user->lang['CONTINUE_DELETING_INDEX_EXPLAIN'])
ef5584
			);
ef5584
		}
ef5584
	}
ef5584
ef5584
	function display_progress_bar($type)
ef5584
	{
ef5584
		global $template, $user;
ef5584
ef5584
		$l_type = ($type == 'create') ? 'INDEXING_IN_PROGRESS' : 'DELETING_INDEX_IN_PROGRESS';
ef5584
ef5584
		adm_page_header($user->lang[$l_type]);
ef5584
ef5584
		$template->set_filenames(array(
ef5584
			'body'	=> 'progress_bar.html')
ef5584
		);
ef5584
ef5584
		$template->assign_vars(array(
ef5584
			'L_PROGRESS'			=> $user->lang[$l_type],
ef5584
			'L_PROGRESS_EXPLAIN'	=> $user->lang[$l_type . '_EXPLAIN'])
ef5584
		);
ef5584
ef5584
		adm_page_footer();
ef5584
	}
ef5584
ef5584
	function close_popup_js()
ef5584
	{
ef5584
		return "<script type=\"text/javascript\">\n" .
ef5584
			"// 
ef5584
			"	close_waitscreen = 1;\n" .
ef5584
			"// ]]>\n" .
ef5584
			"</script>\n";
ef5584
	}
ef5584
ef5584
	function get_search_types()
ef5584
	{
ef5584
		global $phpbb_root_path, $phpEx;
ef5584
ef5584
		$search_types = array();
ef5584
ef5584
		$dp = @opendir($phpbb_root_path . 'includes/search');
ef5584
ef5584
		if ($dp)
ef5584
		{
ef5584
			while (($file = readdir($dp)) !== false)
ef5584
			{
ef5584
				if ((preg_match('#\.' . $phpEx . '$#', $file)) && ($file != "search.$phpEx"))
ef5584
				{
ef5584
					$search_types[] = preg_replace('#^(.*?)\.' . $phpEx . '$#', '\1', $file);
ef5584
				}
ef5584
			}
ef5584
			closedir($dp);
ef5584
ef5584
			sort($search_types);
ef5584
		}
ef5584
ef5584
		return $search_types;
ef5584
	}
ef5584
ef5584
	function get_max_post_id()
ef5584
	{
ef5584
		global $db;
ef5584
ef5584
		$sql = 'SELECT MAX(post_id) as max_post_id
ef5584
			FROM '. POSTS_TABLE;
ef5584
		$result = $db->sql_query($sql);
ef5584
		$max_post_id = (int) $db->sql_fetchfield('max_post_id');
ef5584
		$db->sql_freeresult($result);
ef5584
ef5584
		return $max_post_id;
ef5584
	}
ef5584
ef5584
	function save_state($state = false)
ef5584
	{
ef5584
		if ($state)
ef5584
		{
ef5584
			$this->state = $state;
ef5584
		}
ef5584
ef5584
		ksort($this->state);
ef5584
ef5584
		set_config('search_indexing_state', implode(',', $this->state));
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Initialises a search backend object
ef5584
	*
ef5584
	* @return false if no error occurred else an error message
ef5584
	*/
ef5584
	function init_search($type, &$search, &$error)
ef5584
	{
ef5584
		global $phpbb_root_path, $phpEx, $user;
ef5584
ef5584
		if (!preg_match('#^\w+$#', $type) || !file_exists("{$phpbb_root_path}includes/search/$type.$phpEx"))
ef5584
		{
ef5584
			$error = $user->lang['NO_SUCH_SEARCH_MODULE'];
ef5584
			return $error;
ef5584
		}
ef5584
ef5584
		include_once("{$phpbb_root_path}includes/search/$type.$phpEx");
ef5584
ef5584
		if (!class_exists($type))
ef5584
		{
ef5584
			$error = $user->lang['NO_SUCH_SEARCH_MODULE'];
ef5584
			return $error;
ef5584
		}
ef5584
ef5584
		$error = false;
ef5584
		$search = new $type($error);
ef5584
ef5584
		return $error;
ef5584
	}
ef5584
}
ef5584
ef5584
?>