3 /* Move this stuff to lib/searchlib.php?
4 * Author: Michael Champanis
6 * This file must not contain any PHP 5, because it is used to test for PHP 5
7 * itself, and needs to be able to be executed on PHP 4 installations.
10 define('SEARCH_INDEX_PATH', "$CFG->dataroot/search");
11 define('SEARCH_DATABASE_TABLE', 'search_documents');
13 //document types that can be searched
14 //define('SEARCH_TYPE_NONE', 'none');
15 define('SEARCH_TYPE_WIKI', 'wiki');
16 define('SEARCH_TYPE_FORUM', 'forum');
17 define('SEARCH_TYPE_GLOSSARY', 'glossary');
18 define('SEARCH_TYPE_RESOURCE', 'resource');
20 //returns all the document type constants
21 function search_get_document_types($prefix='SEARCH_TYPE') {
24 foreach (get_defined_constants() as $key=>$value) {
25 if (substr($key, 0, strlen($prefix)) == $prefix) {
33 } //search_get_document_types
35 // additional virtual modules to index
37 // By adding 'moo' to the extras array, an additional document type
38 // documents/moo_document.php will be indexed - this allows for
39 // virtual modules to be added to the index, i.e. non-module specific
41 function search_get_additional_modules() {
42 $extras = array(/* additional keywords go here */);
45 foreach($extras as $extra) {
47 $ret[] = clone($temp);
51 } //search_get_additional_modules
53 //shortens a url so it can fit on the results page
54 function search_shorten_url($url, $length=30) {
55 return substr($url, 0, $length)."...";
56 } //search_shorten_url
58 function search_escape_string($str) {
61 switch ($CFG->dbfamily
) {
63 $s = mysql_real_escape_string($str);
66 $s = pg_escape_string($str);
69 $s = addslashes($str);
73 } //search_escape_string
75 //get a real php 5 version number, using 5.0.0 arbitrarily
76 function search_check_php5($feedback=false) {
77 if (!check_php_version("5.0.0")) {
79 $phpversion = phpversion();
80 print_heading("Sorry, global search requires PHP 5.0.0 or later (currently using version $phpversion)");
89 //simple timer function, outputs result on 2nd call
90 function search_stopwatch($cli = false) {
91 if (!empty($GLOBALS['search_script_start_time'])) {
92 if (!$cli) print '<em>';
93 print round(microtime(true) - $GLOBALS['search_script_start_time'], 6).' seconds';
94 if (!$cli) print '</em>';
96 unset($GLOBALS['search_script_start_time']);
98 $GLOBALS['search_script_start_time'] = microtime(true);
102 //print and exit (for debugging)
103 function search_pexit($str = "") {
104 if (is_array($str) or is_object($str)) {