1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/acp/acp_search.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,643 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package acp
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* @package acp
1.24 +*/
1.25 +class acp_search
1.26 +{
1.27 + var $u_action;
1.28 + var $state;
1.29 + var $search;
1.30 + var $max_post_id;
1.31 + var $batch_size = 100;
1.32 +
1.33 + function main($id, $mode)
1.34 + {
1.35 + global $user;
1.36 +
1.37 + $user->add_lang('acp/search');
1.38 +
1.39 + // For some this may be of help...
1.40 + @ini_set('memory_limit', '128M');
1.41 +
1.42 + switch ($mode)
1.43 + {
1.44 + case 'settings':
1.45 + $this->settings($id, $mode);
1.46 + break;
1.47 +
1.48 + case 'index':
1.49 + $this->index($id, $mode);
1.50 + break;
1.51 + }
1.52 + }
1.53 +
1.54 + function settings($id, $mode)
1.55 + {
1.56 + global $db, $user, $auth, $template, $cache;
1.57 + global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
1.58 +
1.59 + $submit = (isset($_POST['submit'])) ? true : false;
1.60 +
1.61 + $search_types = $this->get_search_types();
1.62 +
1.63 + $settings = array(
1.64 + 'search_interval' => 'float',
1.65 + 'search_anonymous_interval' => 'float',
1.66 + 'load_search' => 'bool',
1.67 + 'limit_search_load' => 'float',
1.68 + 'min_search_author_chars' => 'integer',
1.69 + 'max_num_search_keywords' => 'integer',
1.70 + 'search_store_results' => 'integer',
1.71 + );
1.72 +
1.73 + $search = null;
1.74 + $error = false;
1.75 + $search_options = '';
1.76 + foreach ($search_types as $type)
1.77 + {
1.78 + if ($this->init_search($type, $search, $error))
1.79 + {
1.80 + continue;
1.81 + }
1.82 +
1.83 + $name = ucfirst(strtolower(str_replace('_', ' ', $type)));
1.84 + $selected = ($config['search_type'] == $type) ? ' selected="selected"' : '';
1.85 + $search_options .= '<option value="' . $type . '"' . $selected . '>' . $name . '</option>';
1.86 +
1.87 + if (method_exists($search, 'acp'))
1.88 + {
1.89 + $vars = $search->acp();
1.90 +
1.91 + if (!$submit)
1.92 + {
1.93 + $template->assign_block_vars('backend', array(
1.94 + 'NAME' => $name,
1.95 + 'SETTINGS' => $vars['tpl'])
1.96 + );
1.97 + }
1.98 + else if (is_array($vars['config']))
1.99 + {
1.100 + $settings = array_merge($settings, $vars['config']);
1.101 + }
1.102 + }
1.103 + }
1.104 + unset($search);
1.105 + unset($error);
1.106 +
1.107 + $cfg_array = (isset($_REQUEST['config'])) ? request_var('config', array('' => ''), true) : array();
1.108 + $updated = request_var('updated', false);
1.109 +
1.110 + foreach ($settings as $config_name => $var_type)
1.111 + {
1.112 + if (!isset($cfg_array[$config_name]))
1.113 + {
1.114 + continue;
1.115 + }
1.116 +
1.117 + // e.g. integer:4:12 (min 4, max 12)
1.118 + $var_type = explode(':', $var_type);
1.119 +
1.120 + $config_value = $cfg_array[$config_name];
1.121 + settype($config_value, $var_type[0]);
1.122 +
1.123 + if (isset($var_type[1]))
1.124 + {
1.125 + $config_value = max($var_type[1], $config_value);
1.126 + }
1.127 +
1.128 + if (isset($var_type[2]))
1.129 + {
1.130 + $config_value = min($var_type[2], $config_value);
1.131 + }
1.132 +
1.133 + // only change config if anything was actually changed
1.134 + if ($submit && ($config[$config_name] != $config_value))
1.135 + {
1.136 + set_config($config_name, $config_value);
1.137 + $updated = true;
1.138 + }
1.139 + }
1.140 +
1.141 + if ($submit)
1.142 + {
1.143 + $extra_message = '';
1.144 + if ($updated)
1.145 + {
1.146 + add_log('admin', 'LOG_CONFIG_SEARCH');
1.147 + }
1.148 +
1.149 + if (isset($cfg_array['search_type']) && in_array($cfg_array['search_type'], $search_types, true) && ($cfg_array['search_type'] != $config['search_type']))
1.150 + {
1.151 + $search = null;
1.152 + $error = false;
1.153 +
1.154 + if (!$this->init_search($cfg_array['search_type'], $search, $error))
1.155 + {
1.156 + if (confirm_box(true))
1.157 + {
1.158 + if (!method_exists($search, 'init') || !($error = $search->init()))
1.159 + {
1.160 + set_config('search_type', $cfg_array['search_type']);
1.161 +
1.162 + if (!$updated)
1.163 + {
1.164 + add_log('admin', 'LOG_CONFIG_SEARCH');
1.165 + }
1.166 + $extra_message = '<br />' . $user->lang['SWITCHED_SEARCH_BACKEND'] . '<br /><a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=search&mode=index') . '">» ' . $user->lang['GO_TO_SEARCH_INDEX'] . '</a>';
1.167 + }
1.168 + else
1.169 + {
1.170 + trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
1.171 + }
1.172 + }
1.173 + else
1.174 + {
1.175 + confirm_box(false, $user->lang['CONFIRM_SEARCH_BACKEND'], build_hidden_fields(array(
1.176 + 'i' => $id,
1.177 + 'mode' => $mode,
1.178 + 'submit' => true,
1.179 + 'updated' => $updated,
1.180 + 'config' => array('search_type' => $cfg_array['search_type']),
1.181 + )));
1.182 + }
1.183 + }
1.184 + else
1.185 + {
1.186 + trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
1.187 + }
1.188 + }
1.189 +
1.190 + $search = null;
1.191 + $error = false;
1.192 + if (!$this->init_search($config['search_type'], $search, $error))
1.193 + {
1.194 + if ($updated)
1.195 + {
1.196 + if (method_exists($search, 'config_updated'))
1.197 + {
1.198 + if ($search->config_updated())
1.199 + {
1.200 + trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
1.201 + }
1.202 + }
1.203 + }
1.204 + }
1.205 + else
1.206 + {
1.207 + trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
1.208 + }
1.209 +
1.210 + trigger_error($user->lang['CONFIG_UPDATED'] . $extra_message . adm_back_link($this->u_action));
1.211 + }
1.212 + unset($cfg_array);
1.213 +
1.214 + $this->tpl_name = 'acp_search';
1.215 + $this->page_title = 'ACP_SEARCH_SETTINGS';
1.216 +
1.217 + $template->assign_vars(array(
1.218 + 'LIMIT_SEARCH_LOAD' => (float) $config['limit_search_load'],
1.219 + 'MIN_SEARCH_AUTHOR_CHARS' => (int) $config['min_search_author_chars'],
1.220 + 'SEARCH_INTERVAL' => (float) $config['search_interval'],
1.221 + 'SEARCH_GUEST_INTERVAL' => (float) $config['search_anonymous_interval'],
1.222 + 'SEARCH_STORE_RESULTS' => (int) $config['search_store_results'],
1.223 + 'MAX_NUM_SEARCH_KEYWORDS' => (int) $config['max_num_search_keywords'],
1.224 +
1.225 + 'S_SEARCH_TYPES' => $search_options,
1.226 + 'S_YES_SEARCH' => (bool) $config['load_search'],
1.227 + 'S_SETTINGS' => true,
1.228 +
1.229 + 'U_ACTION' => $this->u_action)
1.230 + );
1.231 + }
1.232 +
1.233 + function index($id, $mode)
1.234 + {
1.235 + global $db, $user, $auth, $template, $cache;
1.236 + global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
1.237 +
1.238 + if (isset($_REQUEST['action']) && is_array($_REQUEST['action']))
1.239 + {
1.240 + $action = request_var('action', array('' => false));
1.241 + $action = key($action);
1.242 + }
1.243 + else
1.244 + {
1.245 + $action = request_var('action', '');
1.246 + }
1.247 + $this->state = explode(',', $config['search_indexing_state']);
1.248 +
1.249 + if (isset($_POST['cancel']))
1.250 + {
1.251 + $action = '';
1.252 + $this->state = array();
1.253 + $this->save_state();
1.254 + }
1.255 +
1.256 + if ($action)
1.257 + {
1.258 + switch ($action)
1.259 + {
1.260 + case 'progress_bar':
1.261 + $type = request_var('type', '');
1.262 + $this->display_progress_bar($type);
1.263 + break;
1.264 +
1.265 + case 'delete':
1.266 + $this->state[1] = 'delete';
1.267 + break;
1.268 +
1.269 + case 'create':
1.270 + $this->state[1] = 'create';
1.271 + break;
1.272 +
1.273 + default:
1.274 + trigger_error('NO_ACTION', E_USER_ERROR);
1.275 + break;
1.276 + }
1.277 +
1.278 + if (empty($this->state[0]))
1.279 + {
1.280 + $this->state[0] = request_var('search_type', '');
1.281 + }
1.282 +
1.283 + $this->search = null;
1.284 + $error = false;
1.285 + if ($this->init_search($this->state[0], $this->search, $error))
1.286 + {
1.287 + trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
1.288 + }
1.289 + $name = ucfirst(strtolower(str_replace('_', ' ', $this->state[0])));
1.290 +
1.291 + $action = &$this->state[1];
1.292 +
1.293 + $this->max_post_id = $this->get_max_post_id();
1.294 +
1.295 + $post_counter = (isset($this->state[2])) ? $this->state[2] : 0;
1.296 + $this->state[2] = &$post_counter;
1.297 + $this->save_state();
1.298 +
1.299 + switch ($action)
1.300 + {
1.301 + case 'delete':
1.302 + if (method_exists($this->search, 'delete_index'))
1.303 + {
1.304 + // pass a reference to myself so the $search object can make use of save_state() and attributes
1.305 + if ($error = $this->search->delete_index($this, append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=delete", false)))
1.306 + {
1.307 + $this->state = array('');
1.308 + $this->save_state();
1.309 + trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
1.310 + }
1.311 + }
1.312 + else
1.313 + {
1.314 + $starttime = explode(' ', microtime());
1.315 + $starttime = $starttime[1] + $starttime[0];
1.316 + $row_count = 0;
1.317 + while (still_on_time() && $post_counter <= $this->max_post_id)
1.318 + {
1.319 + $sql = 'SELECT post_id, poster_id, forum_id
1.320 + FROM ' . POSTS_TABLE . '
1.321 + WHERE post_id >= ' . (int) ($post_counter + 1) . '
1.322 + AND post_id <= ' . (int) ($post_counter + $this->batch_size);
1.323 + $result = $db->sql_query($sql);
1.324 +
1.325 + $ids = $posters = $forum_ids = array();
1.326 + while ($row = $db->sql_fetchrow($result))
1.327 + {
1.328 + $ids[] = $row['post_id'];
1.329 + $posters[] = $row['poster_id'];
1.330 + $forum_ids[] = $row['forum_id'];
1.331 + }
1.332 + $db->sql_freeresult($result);
1.333 + $row_count += sizeof($ids);
1.334 +
1.335 + if (sizeof($ids))
1.336 + {
1.337 + $this->search->index_remove($ids, $posters, $forum_ids);
1.338 + }
1.339 +
1.340 + $post_counter += $this->batch_size;
1.341 + }
1.342 + // save the current state
1.343 + $this->save_state();
1.344 +
1.345 + if ($post_counter <= $this->max_post_id)
1.346 + {
1.347 + $mtime = explode(' ', microtime());
1.348 + $totaltime = $mtime[0] + $mtime[1] - $starttime;
1.349 + $rows_per_second = $row_count / $totaltime;
1.350 + meta_refresh(1, append_sid($this->u_action . '&action=delete&skip_rows=' . $post_counter));
1.351 + trigger_error(sprintf($user->lang['SEARCH_INDEX_DELETE_REDIRECT'], $post_counter, $row_count, $rows_per_second));
1.352 + }
1.353 + }
1.354 +
1.355 + $this->search->tidy();
1.356 +
1.357 + $this->state = array('');
1.358 + $this->save_state();
1.359 +
1.360 + add_log('admin', 'LOG_SEARCH_INDEX_REMOVED', $name);
1.361 + trigger_error($user->lang['SEARCH_INDEX_REMOVED'] . adm_back_link($this->u_action) . $this->close_popup_js());
1.362 + break;
1.363 +
1.364 + case 'create':
1.365 + if (method_exists($this->search, 'create_index'))
1.366 + {
1.367 + // pass a reference to acp_search so the $search object can make use of save_state() and attributes
1.368 + if ($error = $this->search->create_index($this, append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=create", false)))
1.369 + {
1.370 + $this->state = array('');
1.371 + $this->save_state();
1.372 + trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
1.373 + }
1.374 + }
1.375 + else
1.376 + {
1.377 + $sql = 'SELECT forum_id, enable_indexing
1.378 + FROM ' . FORUMS_TABLE;
1.379 + $result = $db->sql_query($sql, 3600);
1.380 +
1.381 + while ($row = $db->sql_fetchrow($result))
1.382 + {
1.383 + $forums[$row['forum_id']] = (bool) $row['enable_indexing'];
1.384 + }
1.385 + $db->sql_freeresult($result);
1.386 +
1.387 + $starttime = explode(' ', microtime());
1.388 + $starttime = $starttime[1] + $starttime[0];
1.389 + $row_count = 0;
1.390 + while (still_on_time() && $post_counter <= $this->max_post_id)
1.391 + {
1.392 + $sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id
1.393 + FROM ' . POSTS_TABLE . '
1.394 + WHERE post_id >= ' . (int) ($post_counter + 1) . '
1.395 + AND post_id <= ' . (int) ($post_counter + $this->batch_size);
1.396 + $result = $db->sql_query($sql);
1.397 +
1.398 + $buffer = $db->sql_buffer_nested_transactions();
1.399 +
1.400 + if ($buffer)
1.401 + {
1.402 + $rows = $db->sql_fetchrowset($result);
1.403 + $rows[] = false; // indicate end of array for while loop below
1.404 +
1.405 + $db->sql_freeresult($result);
1.406 + }
1.407 +
1.408 + $i = 0;
1.409 + while ($row = ($buffer ? $rows[$i++] : $db->sql_fetchrow($result)))
1.410 + {
1.411 + // Indexing enabled for this forum or global announcement?
1.412 + // Global announcements get indexed by default.
1.413 + if (!$row['forum_id'] || (isset($forums[$row['forum_id']]) && $forums[$row['forum_id']]))
1.414 + {
1.415 + $this->search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']);
1.416 + }
1.417 + $row_count++;
1.418 + }
1.419 + if (!$buffer)
1.420 + {
1.421 + $db->sql_freeresult($result);
1.422 + }
1.423 +
1.424 + $post_counter += $this->batch_size;
1.425 + }
1.426 + // save the current state
1.427 + $this->save_state();
1.428 +
1.429 + // pretend the number of posts was as big as the number of ids we indexed so far
1.430 + // just an estimation as it includes deleted posts
1.431 + $num_posts = $config['num_posts'];
1.432 + $config['num_posts'] = min($config['num_posts'], $post_counter);
1.433 + $this->search->tidy();
1.434 + $config['num_posts'] = $num_posts;
1.435 +
1.436 + if ($post_counter <= $this->max_post_id)
1.437 + {
1.438 + $mtime = explode(' ', microtime());
1.439 + $totaltime = $mtime[0] + $mtime[1] - $starttime;
1.440 + $rows_per_second = $row_count / $totaltime;
1.441 + meta_refresh(1, append_sid($this->u_action . '&action=create&skip_rows=' . $post_counter));
1.442 + trigger_error(sprintf($user->lang['SEARCH_INDEX_CREATE_REDIRECT'], $post_counter, $row_count, $rows_per_second));
1.443 + }
1.444 + }
1.445 +
1.446 + $this->search->tidy();
1.447 +
1.448 + $this->state = array('');
1.449 + $this->save_state();
1.450 +
1.451 + add_log('admin', 'LOG_SEARCH_INDEX_CREATED', $name);
1.452 + trigger_error($user->lang['SEARCH_INDEX_CREATED'] . adm_back_link($this->u_action) . $this->close_popup_js());
1.453 + break;
1.454 + }
1.455 + }
1.456 +
1.457 + $search_types = $this->get_search_types();
1.458 +
1.459 + $search = null;
1.460 + $error = false;
1.461 + $search_options = '';
1.462 + foreach ($search_types as $type)
1.463 + {
1.464 + if ($this->init_search($type, $search, $error) || !method_exists($search, 'index_created'))
1.465 + {
1.466 + continue;
1.467 + }
1.468 +
1.469 + $name = ucfirst(strtolower(str_replace('_', ' ', $type)));
1.470 +
1.471 + $data = array();
1.472 + if (method_exists($search, 'index_stats'))
1.473 + {
1.474 + $data = $search->index_stats();
1.475 + }
1.476 +
1.477 + $statistics = array();
1.478 + foreach ($data as $statistic => $value)
1.479 + {
1.480 + $n = sizeof($statistics);
1.481 + if ($n && sizeof($statistics[$n - 1]) < 3)
1.482 + {
1.483 + $statistics[$n - 1] += array('statistic_2' => $statistic, 'value_2' => $value);
1.484 + }
1.485 + else
1.486 + {
1.487 + $statistics[] = array('statistic_1' => $statistic, 'value_1' => $value);
1.488 + }
1.489 + }
1.490 +
1.491 + $template->assign_block_vars('backend', array(
1.492 + 'L_NAME' => $name,
1.493 + 'NAME' => $type,
1.494 +
1.495 + 'S_ACTIVE' => ($type == $config['search_type']) ? true : false,
1.496 + 'S_HIDDEN_FIELDS' => build_hidden_fields(array('search_type' => $type)),
1.497 + 'S_INDEXED' => (bool) $search->index_created(),
1.498 + 'S_STATS' => (bool) sizeof($statistics))
1.499 + );
1.500 +
1.501 + foreach ($statistics as $statistic)
1.502 + {
1.503 + $template->assign_block_vars('backend.data', array(
1.504 + 'STATISTIC_1' => $statistic['statistic_1'],
1.505 + 'VALUE_1' => $statistic['value_1'],
1.506 + 'STATISTIC_2' => (isset($statistic['statistic_2'])) ? $statistic['statistic_2'] : '',
1.507 + 'VALUE_2' => (isset($statistic['value_2'])) ? $statistic['value_2'] : '')
1.508 + );
1.509 + }
1.510 + }
1.511 + unset($search);
1.512 + unset($error);
1.513 + unset($statistics);
1.514 + unset($data);
1.515 +
1.516 + $this->tpl_name = 'acp_search';
1.517 + $this->page_title = 'ACP_SEARCH_INDEX';
1.518 +
1.519 + $template->assign_vars(array(
1.520 + 'S_INDEX' => true,
1.521 + 'U_ACTION' => $this->u_action,
1.522 + 'U_PROGRESS_BAR' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=progress_bar"),
1.523 + 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=progress_bar")),
1.524 + ));
1.525 +
1.526 + if (isset($this->state[1]))
1.527 + {
1.528 + $template->assign_vars(array(
1.529 + 'S_CONTINUE_INDEXING' => $this->state[1],
1.530 + 'U_CONTINUE_INDEXING' => $this->u_action . '&action=' . $this->state[1],
1.531 + 'L_CONTINUE' => ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING'] : $user->lang['CONTINUE_DELETING_INDEX'],
1.532 + 'L_CONTINUE_EXPLAIN' => ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING_EXPLAIN'] : $user->lang['CONTINUE_DELETING_INDEX_EXPLAIN'])
1.533 + );
1.534 + }
1.535 + }
1.536 +
1.537 + function display_progress_bar($type)
1.538 + {
1.539 + global $template, $user;
1.540 +
1.541 + $l_type = ($type == 'create') ? 'INDEXING_IN_PROGRESS' : 'DELETING_INDEX_IN_PROGRESS';
1.542 +
1.543 + adm_page_header($user->lang[$l_type]);
1.544 +
1.545 + $template->set_filenames(array(
1.546 + 'body' => 'progress_bar.html')
1.547 + );
1.548 +
1.549 + $template->assign_vars(array(
1.550 + 'L_PROGRESS' => $user->lang[$l_type],
1.551 + 'L_PROGRESS_EXPLAIN' => $user->lang[$l_type . '_EXPLAIN'])
1.552 + );
1.553 +
1.554 + adm_page_footer();
1.555 + }
1.556 +
1.557 + function close_popup_js()
1.558 + {
1.559 + return "<script type=\"text/javascript\">\n" .
1.560 + "// <![CDATA[\n" .
1.561 + " close_waitscreen = 1;\n" .
1.562 + "// ]]>\n" .
1.563 + "</script>\n";
1.564 + }
1.565 +
1.566 + function get_search_types()
1.567 + {
1.568 + global $phpbb_root_path, $phpEx;
1.569 +
1.570 + $search_types = array();
1.571 +
1.572 + $dp = @opendir($phpbb_root_path . 'includes/search');
1.573 +
1.574 + if ($dp)
1.575 + {
1.576 + while (($file = readdir($dp)) !== false)
1.577 + {
1.578 + if ((preg_match('#\.' . $phpEx . '$#', $file)) && ($file != "search.$phpEx"))
1.579 + {
1.580 + $search_types[] = preg_replace('#^(.*?)\.' . $phpEx . '$#', '\1', $file);
1.581 + }
1.582 + }
1.583 + closedir($dp);
1.584 +
1.585 + sort($search_types);
1.586 + }
1.587 +
1.588 + return $search_types;
1.589 + }
1.590 +
1.591 + function get_max_post_id()
1.592 + {
1.593 + global $db;
1.594 +
1.595 + $sql = 'SELECT MAX(post_id) as max_post_id
1.596 + FROM '. POSTS_TABLE;
1.597 + $result = $db->sql_query($sql);
1.598 + $max_post_id = (int) $db->sql_fetchfield('max_post_id');
1.599 + $db->sql_freeresult($result);
1.600 +
1.601 + return $max_post_id;
1.602 + }
1.603 +
1.604 + function save_state($state = false)
1.605 + {
1.606 + if ($state)
1.607 + {
1.608 + $this->state = $state;
1.609 + }
1.610 +
1.611 + ksort($this->state);
1.612 +
1.613 + set_config('search_indexing_state', implode(',', $this->state), true);
1.614 + }
1.615 +
1.616 + /**
1.617 + * Initialises a search backend object
1.618 + *
1.619 + * @return false if no error occurred else an error message
1.620 + */
1.621 + function init_search($type, &$search, &$error)
1.622 + {
1.623 + global $phpbb_root_path, $phpEx, $user;
1.624 +
1.625 + if (!preg_match('#^\w+$#', $type) || !file_exists("{$phpbb_root_path}includes/search/$type.$phpEx"))
1.626 + {
1.627 + $error = $user->lang['NO_SUCH_SEARCH_MODULE'];
1.628 + return $error;
1.629 + }
1.630 +
1.631 + include_once("{$phpbb_root_path}includes/search/$type.$phpEx");
1.632 +
1.633 + if (!class_exists($type))
1.634 + {
1.635 + $error = $user->lang['NO_SUCH_SEARCH_MODULE'];
1.636 + return $error;
1.637 + }
1.638 +
1.639 + $error = false;
1.640 + $search = new $type($error);
1.641 +
1.642 + return $error;
1.643 + }
1.644 +}
1.645 +
1.646 +?>
1.647 \ No newline at end of file