3 * Author: Michael Champanis
5 * This file must not contain any PHP 5, because it is used to test for PHP 5
6 * itself, and needs to be able to be executed on PHP 4 installations.
8 * Reviewed by: Valery Fremaux (2007)
9 * - adding techproject search capabilities
10 * - adding full internationalization
15 function search_get_document_types($prefix = 'SEARCH_TYPE_') {
16 function search_get_additional_modules() {
17 function search_shorten_url($url, $length=30) {
18 function search_escape_string($str) {
19 function search_check_php5($feedback = false) {
20 function search_stopwatch($cli = false) {
21 function search_pexit($str = "") {
24 define('SEARCH_INDEX_PATH', "$CFG->dataroot/search");
25 define('SEARCH_DATABASE_TABLE', 'search_documents');
27 //document types that can be searched
28 //define('SEARCH_TYPE_NONE', 'none');
29 define('SEARCH_TYPE_WIKI', 'wiki');
30 define('PATH_FOR_SEARCH_TYPE_WIKI', 'mod/wiki');
31 define('SEARCH_TYPE_FORUM', 'forum');
32 define('PATH_FOR_SEARCH_TYPE_FORUM', 'mod/forum');
33 define('SEARCH_TYPE_GLOSSARY', 'glossary');
34 define('PATH_FOR_SEARCH_TYPE_GLOSSARY', 'mod/glossary');
35 define('SEARCH_TYPE_RESOURCE', 'resource');
36 define('PATH_FOR_SEARCH_TYPE_RESOURCE', 'mod/resource');
37 define('SEARCH_TYPE_TECHPROJECT', 'techproject');
38 define('PATH_FOR_SEARCH_TYPE_TECHPROJECT', 'mod/techproject');
39 define('SEARCH_TYPE_DATA', 'data');
40 define('PATH_FOR_SEARCH_TYPE_DATA', 'mod/data');
41 define('SEARCH_TYPE_CHAT', 'chat');
42 define('PATH_FOR_SEARCH_TYPE_CHAT', 'mod/chat');
45 * returns all the document type constants
46 * @param prefix a pattern for recognizing constants
47 * @return an array of type labels
49 function search_get_document_types($prefix = 'SEARCH_TYPE_') {
51 foreach (get_defined_constants() as $key => $value) {
52 if (preg_match("/^{$prefix}/", $key)){
58 } //search_get_document_types
61 * additional virtual modules to index
63 * By adding 'moo' to the extras array, an additional document type
64 * documents/moo_document.php will be indexed - this allows for
65 * virtual modules to be added to the index, i.e. non-module specific
68 function search_get_additional_modules() {
69 $extras = array(/* additional keywords go here */);
71 foreach($extras as $extra) {
73 $ret[] = clone($temp);
76 } //search_get_additional_modules
79 * shortens a url so it can fit on the results page
81 * @param length the size limit we want
83 function search_shorten_url($url, $length=30) {
84 return substr($url, 0, $length)."...";
85 } //search_shorten_url
88 * a local function for escaping
89 * @param str the string to escape
90 * @return the escaped string
92 function search_escape_string($str) {
95 switch ($CFG->dbfamily
) {
97 $s = mysql_real_escape_string($str);
100 $s = pg_escape_string($str);
103 $s = addslashes($str);
106 } //search_escape_string
109 * get a real php 5 version number, using 5.0.0 arbitrarily
110 * @param feedback if true, prints a feedback message to output.
111 * @return true if version of PHP is high enough
113 function search_check_php5($feedback = false) {
114 if (!check_php_version("5.0.0")) {
116 print_heading(get_string('versiontoolow', 'search'));
123 } //search_check_php5
126 * simple timer function, on first call, records a current microtime stamp, outputs result on 2nd call
127 * @param cli an output formatting switch
130 function search_stopwatch($cli = false) {
131 if (!empty($GLOBALS['search_script_start_time'])) {
132 if (!$cli) print '<em>';
133 print round(microtime(true) - $GLOBALS['search_script_start_time'], 6).' '.get_string('seconds', 'search');
134 if (!$cli) print '</em>';
135 unset($GLOBALS['search_script_start_time']);
138 $GLOBALS['search_script_start_time'] = microtime(true);
143 * print and exit (for debugging)
144 * @param str a variable to explore
147 function search_pexit($str = "") {
148 if (is_array($str) or is_object($str)) {