Blame Extras/phpBB/3.0.4/includes/acp/acp_search.php

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