Initial commit
[moodle.git] / search / lib.php
CommitLineData
682d4032 1<?php
2
3 //Move this stuff to lib/searchlib.php?
4 // Author: Michael Champanis
5
6 //document types that can be searched
7 define('SEARCH_NO_TYPE', 'none');
8 define('SEARCH_WIKI_TYPE', 'wiki');
9
10 //returns all the document type constants
11 function search_get_document_types() {
12 $r = Array(SEARCH_WIKI_TYPE, SEARCH_NO_TYPE);
13 return $r;
14 } //search_get_document_types
15
16 //shortens a url so it can fit on the results page
17 function search_shorten_url($url, $length=30) {
18 return substr($url, 0, $length)."...";
19 } //search_shorten_url
20
21 //get a real php 5 version number, using 5.0.0 arbitrarily
22 function search_check_php5($feedback=false) {
23 if (!check_php_version("5.0.0")) {
24 if ($feedback) {
25 $phpversion = phpversion();
26 print_heading("Sorry, global search requires PHP 5.0.0 or later (currently using version $phpversion)");
27 } //if
28
29 return false;
30 } else {
31 return true;
32 } //else
33 } //search_check_php5
34
35 //simple timer function, outputs result on 2nd call
36 function search_stopwatch($cli = false) {
37 if (!empty($GLOBALS['search_script_start_time'])) {
38 if (!$cli) print '<em>';
39 print round(microtime(true) - $GLOBALS['search_script_start_time'], 6).' seconds';
40 if (!$cli) print '</em>';
41
42 unset($GLOBALS['search_script_start_time']);
43 } else {
44 $GLOBALS['search_script_start_time'] = microtime(true);
45 } //else
46 } //search_stopwatch
47
48 //print and exit (for debugging)
49 function search_pexit($str = "") {
50 if (is_array($str) or is_object($str)) {
51 print_r($str);
52 } else if ($str) {
53 print $str."<br>";
54 } //if
55
56 exit(0);
57 } //search_pexit
58
59?>