diff --git a/index.php b/index.php index 6a66bb1e2ca..93644e2e565 100644 --- a/index.php +++ b/index.php @@ -79,7 +79,7 @@ } } } else { // if upgrading from 1.6 or below - if (isadmin() && moodle_needs_upgrading()) { + if (is_siteadmin() && moodle_needs_upgrading()) { redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php'); } } diff --git a/lib/accesslib.php b/lib/accesslib.php index 87c56ff2f4d..427b67874b4 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -514,7 +514,7 @@ function has_any_capability($capabilities, $context, $userid=NULL, $doanything=t * - moodle/site:doanything * * @param int $userid - * @returns bool $isadmin + * @returns bool true is user can administer server settings */ function is_siteadmin($userid) { global $CFG, $DB; @@ -532,8 +532,7 @@ function is_siteadmin($userid) { HAVING SUM(rc.permission) > 0"; $params = array($userid, 'moodle/site:config', 'moodle/legacy:admin', 'moodle/site:doanything'); - $isadmin = $DB->record_exists_sql($sql, $params); - return $isadmin; + return $DB->record_exists_sql($sql, $params); } function get_course_from_path ($path) { diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index aa35cebd9fa..28f987748a0 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -35,38 +35,6 @@ * @package moodlecore */ - -/** - * Determines if a user an admin - * - * @uses $USER - * @param int $userid The id of the user as is found in the 'user' table - * @staticvar array $admins List of users who have been found to be admins by user id - * @staticvar array $nonadmins List of users who have been found not to be admins by user id - * @return bool - */ -function isadmin($userid=0) { - global $USER, $CFG; - - if (empty($CFG->rolesactive)) { // Then the user is likely to be upgrading NOW - if (!$userid) { - if (empty($USER->id)) { - return false; - } - if (!empty($USER->admin)) { - return true; - } - $userid = $USER->id; - } - - return record_exists('user_admins', 'userid', $userid); - } - - $context = get_context_instance(CONTEXT_SYSTEM); - - return has_capability('moodle/legacy:admin', $context, $userid, false); -} - /** * Determines if a user is a teacher (or better) * diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index 1b1999c4919..8f61d0daeb3 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -1477,7 +1477,7 @@ function feedback_get_groupid($course, $cm) { $groupmode = groupmode($course, $cm); //get groupid - if($groupmode > 0 && !isadmin()) { + if($groupmode > 0 && !has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { if($mygroupid = mygroupid($course->id)) { return $mygroupid[0]; //get the first groupid } diff --git a/mod/feedback/show_entries.php b/mod/feedback/show_entries.php index d6ee4cd3962..62e91bf22f9 100644 --- a/mod/feedback/show_entries.php +++ b/mod/feedback/show_entries.php @@ -114,7 +114,7 @@ //get students in conjunction with groupmode if($groupmode > 0) { if($SESSION->feedback->lstgroupid == -2) { - if(isadmin()) { + if(has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { $mygroupid = false; $SESSION->feedback->lstgroupid = false; }else{ diff --git a/search/add.php b/search/add.php index 69e3e80c580..be33ab3494a 100644 --- a/search/add.php +++ b/search/add.php @@ -34,7 +34,7 @@ error(get_string('globalsearchdisabled', 'search')); } - if (!isadmin()) { + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php"); } diff --git a/search/delete.php b/search/delete.php index 2e844d4aa9c..c269f666104 100644 --- a/search/delete.php +++ b/search/delete.php @@ -31,7 +31,7 @@ error(get_string('globalsearchdisabled', 'search')); } - if (!isadmin()) { + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php"); } //if diff --git a/search/documents/forum_document.php b/search/documents/forum_document.php index 3cbe2e108a3..a26afd4a4ce 100644 --- a/search/documents/forum_document.php +++ b/search/documents/forum_document.php @@ -166,7 +166,8 @@ function forum_get_discussions_fast($forum_id) { $timelimit=''; if (!empty($CFG->forum_enabletimedposts)) { - if (!((isadmin() and !empty($CFG->admineditalways)) || isteacher(get_field('forum', 'course', 'id', $forum_id)))) { + if (!((has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM)) + and !empty($CFG->admineditalways)) || isteacher(get_field('forum', 'course', 'id', $forum_id)))) { $now = time(); $timelimit = " AND ((d.timestart = 0 OR d.timestart <= '$now') AND (d.timeend = 0 OR d.timeend > '$now')"; if (!empty($USER->id)) { @@ -302,7 +303,8 @@ function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $ * @param string $title */ function forum_link_post_processing($title){ - return mb_convert_encoding($title, 'UTF-8', 'auto'); + // return mb_convert_encoding($title, 'UTF-8', 'auto'); + return mb_convert_encoding($title, 'auto', 'UTF-8'); } ?> \ No newline at end of file diff --git a/search/documents/physical_doc.php b/search/documents/physical_doc.php index ca053bde51d..9586ff12cc5 100644 --- a/search/documents/physical_doc.php +++ b/search/documents/physical_doc.php @@ -18,11 +18,11 @@ * @param object $resource * @uses CFG, USER */ -function get_text_for_indexing_doc(&$resource){ +function get_text_for_indexing_doc(&$resource, $directfile = ''){ global $CFG, $USER; // SECURITY : do not allow non admin execute anything on system !! - if (!isadmin($USER->id)) return; + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return; $moodleroot = (@$CFG->block_search_usemoodleroot) ? "{$CFG->dirroot}/" : '' ; @@ -30,11 +30,14 @@ function get_text_for_indexing_doc(&$resource){ if (!empty($CFG->block_search_word_to_text_cmd)){ if (!file_exists("{$moodleroot}{$CFG->block_search_word_to_text_cmd}")){ mtrace('Error with MSWord to text converter command : exectuable not found.'); - } - else{ - $file = escapeshellarg($CFG->dataroot.'/'.$resource->course.'/'.$resource->reference); + } else { + if ($directfile == ''){ + $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"); + } else { + $file = escapeshellarg("{$CFG->dataroot}/{$directfile}"); + } $command = trim($CFG->block_search_word_to_text_cmd); - $text_converter_cmd = "{$moodleroot}{$command} $file"; + $text_converter_cmd = "{$moodleroot}{$command} -m UTF-8.txt $file"; if ($CFG->block_search_word_to_text_env){ putenv($CFG->block_search_word_to_text_env); } @@ -42,14 +45,12 @@ function get_text_for_indexing_doc(&$resource){ $result = shell_exec($text_converter_cmd); if ($result){ return mb_convert_encoding($result, 'UTF8', 'auto'); - } - else{ + } else { mtrace('Error with MSWord to text converter command : execution failed. '); return ''; } } - } - else { + } else { mtrace('Error with MSWord to text converter command : command not set up. Execute once search block configuration.'); return ''; } diff --git a/search/documents/physical_htm.php b/search/documents/physical_htm.php index 76d6073dd69..aa3e6bc0f11 100644 --- a/search/documents/physical_htm.php +++ b/search/documents/physical_htm.php @@ -17,14 +17,18 @@ * @param object $resource * @uses CFG, USER */ -function get_text_for_indexing_htm(&$resource){ +function get_text_for_indexing_htm(&$resource, $directfile = ''){ global $CFG, $USER; // SECURITY : do not allow non admin execute anything on system !! - if (!isadmin($USER->id)) return; + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return; // just get text - $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}")); + if ($directfile == ''){ + $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}")); + } else { + $text = implode('', file("{$CFG->dataroot}/{$directfile}")); + } // extract keywords and other interesting meta information and put it back as real content for indexing if (preg_match('/(.*)]*)>(.*)/is', $text, $matches)){ @@ -40,7 +44,7 @@ function get_text_for_indexing_htm(&$resource){ $text = preg_replace("/<[^>]*>/", '', $text); $text = preg_replace("//", '', $text); $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8'); - $text = mb_convert_encoding($text, 'UTF-8', 'AUTO'); + $text = mb_convert_encoding($text, 'UTF-8', 'auto'); /* * debug code for tracing input diff --git a/search/documents/physical_pdf.php b/search/documents/physical_pdf.php index 291e0f4a05c..347b61f975e 100644 --- a/search/documents/physical_pdf.php +++ b/search/documents/physical_pdf.php @@ -17,11 +17,11 @@ * @param object $resource * @uses CFG, USER */ -function get_text_for_indexing_pdf(&$resource){ +function get_text_for_indexing_pdf(&$resource, $directfile = ''){ global $CFG, $USER; // SECURITY : do not allow non admin execute anything on system !! - if (!isadmin($USER->id)) return; + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return; // adds moodle root switch if none was defined if (!isset($CFG->block_search_usemoodleroot)){ @@ -34,23 +34,24 @@ function get_text_for_indexing_pdf(&$resource){ if (!empty($CFG->block_search_pdf_to_text_cmd)){ preg_match("/^\S+/", $CFG->block_search_pdf_to_text_cmd, $matches); if (!file_exists("{$moodleroot}{$matches[0]}")){ - mtrace('Error with pdf to text converter command : exectuable not found at '.$moodleroot.$matches[0]); - } - else{ - $file = escapeshellarg($CFG->dataroot.'/'.$resource->course.'/'.$resource->reference); + mtrace('Error with pdf to text converter command : executable not found at '.$moodleroot.$matches[0]); + } else { + if ($directfile == ''){ + $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"); + } else { + $file = escapeshellarg("{$CFG->dataroot}/{$directfile}"); + } $command = trim($CFG->block_search_pdf_to_text_cmd); $text_converter_cmd = "{$moodleroot}{$command} $file -"; $result = shell_exec($text_converter_cmd); if ($result){ return $result; - } - else{ + } else { mtrace('Error with pdf to text converter command : execution failed for '.$text_converter_cmd.'. Check for execution permission on pdf converter executable.'); return ''; } } - } - else { + } else { mtrace('Error with pdf to text converter command : command not set up. Execute once search block configuration.'); return ''; } diff --git a/search/documents/physical_ppt.php b/search/documents/physical_ppt.php index 2de768ffaf8..840d7dff266 100644 --- a/search/documents/physical_ppt.php +++ b/search/documents/physical_ppt.php @@ -31,15 +31,19 @@ * @param object $resource * @uses CFG, USER */ -function get_text_for_indexing_ppt(&$resource){ +function get_text_for_indexing_ppt(&$resource, $directfile = ''){ global $CFG, $USER; $indextext = null; // SECURITY : do not allow non admin execute anything on system !! - if (!isadmin($USER->id)) return; + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return; - $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}")); + if ($directfile == ''){ + $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}")); + } else { + $text = implode('', file("{$CFG->dataroot}/{$directfile}")); + } $remains = $text; $fragments = array(); diff --git a/search/documents/physical_swf.php b/search/documents/physical_swf.php new file mode 100644 index 00000000000..b6d33445a04 --- /dev/null +++ b/search/documents/physical_swf.php @@ -0,0 +1,69 @@ + 1.8 +* @date 2008/03/31 +* @license http://www.gnu.org/copyleft/gpl.html GNU Public License +* +* @note : The Adobe SWF Converters library is not GPL, although it can be of free use in some +* situations. This file is provided for convenience, but should use having a glance at +* {@link http://www.adobe.com/licensing/developer/} +* +* this is a format handler for getting text out of a proprietary binary format +* so it can be indexed by Lucene search engine +*/ + +/** +* @param object $resource +* @uses CFG, USER +*/ +function get_text_for_indexing_swf(&$resource, $directfile = ''){ + global $CFG, $USER; + + // SECURITY : do not allow non admin execute anything on system !! + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return; + + // adds moodle root switch if none was defined + if (!isset($CFG->block_search_usemoodleroot)){ + set_config('block_search_usemoodleroot', 1); + } + + $moodleroot = ($CFG->block_search_usemoodleroot) ? "{$CFG->dirroot}/" : '' ; + + // just call pdftotext over stdout and capture the output + if (!empty($CFG->block_search_pdf_to_text_cmd)){ + if (!file_exists("{$moodleroot}{$command}")){ + mtrace('Error with swf to text converter command : executable not found as '.$moodleroot.$command); + } else { + if ($directfile == ''){ + $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"); + } else { + $file = escapeshellarg("{$CFG->dataroot}/{$directfile}"); + } + $command = trim($CFG->block_search_swf_to_text_cmd); + $text_converter_cmd = "{$moodleroot}{$command} -t $file"; + $result = shell_exec($text_converter_cmd); + + // result is in html. We must strip it off + $result = preg_replace("/<[^>]*>/", '', $result); + $result = preg_replace("//", '', $result); + $result = html_entity_decode($result, ENT_COMPAT, 'UTF-8'); + $result = mb_convert_encoding($result, 'UTF-8', 'auto'); + + if ($result){ + return $result; + } else { + mtrace('Error with swf to text converter command : execution failed for '.$text_converter_cmd.'. Check for execution permission on swf converter executable.'); + return ''; + } + } + } else { + mtrace('Error with swf to text converter command : command not set up. Execute once search block configuration.'); + return ''; + } +} +?> \ No newline at end of file diff --git a/search/documents/physical_txt.php b/search/documents/physical_txt.php index b20be4152f0..4917f032b67 100644 --- a/search/documents/physical_txt.php +++ b/search/documents/physical_txt.php @@ -17,14 +17,19 @@ * @param object $resource * @uses CFG, USER */ -function get_text_for_indexing_txt(&$resource){ +function get_text_for_indexing_txt(&$resource, $directfile = ''){ global $CFG, $USER; // SECURITY : do not allow non admin execute anything on system !! - if (!isadmin($USER->id)) return; + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return; // just try to get text empirically from ppt binary flow - $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}")); + if ($directfile == ''){ + $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}")); + } else { + $text = implode('', file("{$CFG->dataroot}/{$directfile}")); + } + if (!empty($CFG->block_search_limit_index_body)){ $text = shorten($text, $CFG->block_search_limit_index_body); } diff --git a/search/documents/physical_xml.php b/search/documents/physical_xml.php index 85f9ba8f721..68e39c5c2bb 100644 --- a/search/documents/physical_xml.php +++ b/search/documents/physical_xml.php @@ -21,7 +21,7 @@ function get_text_for_indexing_xml(&$resource, $directfile = ''){ global $CFG, $USER; // SECURITY : do not allow non admin execute anything on system !! - if (!isadmin($USER->id)) return; + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return; // just get text if ($directfile == ''){ diff --git a/search/documents/user_document.php b/search/documents/user_document.php index 668f87c2022..e85c2c4a5c3 100644 --- a/search/documents/user_document.php +++ b/search/documents/user_document.php @@ -334,7 +334,7 @@ function user_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c $userrecord = get_record('user', 'id', $this_id); // we cannot see nothing from unconfirmed users - if (!$userrecord->confirmed and !isadmin()){ + if (!$userrecord->confirmed and !has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))){ if (!empty($CFG->search_access_debug)) echo "search reject : unconfirmed user "; return false; } diff --git a/search/indexer.php b/search/indexer.php index a48d505ab4e..95443167c2a 100644 --- a/search/indexer.php +++ b/search/indexer.php @@ -35,6 +35,10 @@ */ require_once('../config.php'); require_once("$CFG->dirroot/search/lib.php"); +//require_once("debugging.php"); + +$separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ; + ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path')); /// only administrators can index the moodle installation, because access to all pages is required @@ -44,7 +48,7 @@ require_once("$CFG->dirroot/search/lib.php"); error(get_string('globalsearchdisabled', 'search')); } - if (!isadmin()) { + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php"); } @@ -59,6 +63,13 @@ require_once("$CFG->dirroot/search/lib.php"); exit(0); } +/// check for php5 (lib.php) + + if (!search_check_php5()) { + mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version ".phpversion().")"); + exit(0); + } + //php5 found, continue including php5-only files //require_once("$CFG->dirroot/search/Zend/Search/Lucene.php"); require_once("$CFG->dirroot/search/indexlib.php"); @@ -86,13 +97,16 @@ require_once("$CFG->dirroot/search/lib.php"); mtrace("Data directory ($index_path) does not exist, attempting to create."); if (!mkdir($index_path)) { search_pexit("Error creating data directory at: $index_path. Please correct."); - } else { + } + else { mtrace("Directory successfully created."); } - } else { + } + else { mtrace("Using $index_path as data directory."); } + Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8()); $index = new Zend_Search_Lucene($index_path, true); /* @@ -116,31 +130,37 @@ require_once("$CFG->dirroot/search/lib.php"); // * mod_iterator // * mod_get_content_for_index //are the sole basis for including a module in the index at the moment. - $searchables = array(); + + $searchables = search_collect_searchables(); -/// collects modules +/// start indexation - if ($mods = get_records('modules', '', '', '', 'id,name')) { - $searchables = array_merge($searchables, $mods); - } - mtrace(count($searchables).' modules found.'); - - // collects blocks as indexable information may be found in blocks either - if ($blocks = get_records('block', '', '', '', 'id,name')) { - // prepend the "block_" prefix to discriminate document type plugins - foreach(array_keys($blocks) as $aBlockId){ - $blocks[$aBlockId]->name = 'block_'.$blocks[$aBlockId]->name; - } - $searchables = array_merge($searchables, $blocks); - mtrace(count($blocks).' blocks found.'); - } - -/// add virtual modules onto the back of the array - - $searchables = array_merge($searchables, search_get_additional_modules()); if ($searchables){ foreach ($searchables as $mod) { - $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php'; + + $key = 'search_in_'.$mod->name; + if (isset($CFG->$key) && !$CFG->$key) { + mtrace("module $key has been administratively disabled. Skipping...\n"); + continue; + } + + if ($mod->location == 'internal'){ + $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php'; + } else { + $class_file = $CFG->dirroot.'/'.$mod->location.'/'.$mod->name.'/search_document.php'; + } + + /* + if (!file_exists($class_file)){ + if (defined("PATH_FOR_SEARCH_TYPE_{$mod->name}")){ + eval("\$pluginpath = PATH_FOR_SEARCH_TYPE_{$mod->name}"); + $class_file = "{$CFG->dirroot}/{$pluginpath}/searchlib.php"; + } else { + mtrace ("No search document found for plugin {$mod->name}. Ignoring."); + continue; + } + } + */ if (file_exists($class_file)) { include_once($class_file); @@ -187,6 +207,8 @@ require_once("$CFG->dirroot/search/lib.php"); mtrace("-- $counter documents indexed"); mtrace("done.\n"); } + } else { + mtrace ("No search document found for plugin {$mod->name}. Ignoring."); } } } diff --git a/search/indexersplash.php b/search/indexersplash.php index bd8b9208f32..01f1238c4a4 100644 --- a/search/indexersplash.php +++ b/search/indexersplash.php @@ -18,7 +18,11 @@ * includes and requires */ require_once('../config.php'); -require_once("$CFG->dirroot/search/lib.php"); +require_once("{$CFG->dirroot}/search/lib.php"); + +/// makes inclusions of the Zend Engine more reliable +$separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ; +ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path')); /// check global search is enabled @@ -28,10 +32,18 @@ require_once("$CFG->dirroot/search/lib.php"); error(get_string('globalsearchdisabled', 'search')); } - if (!isadmin()) { + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php"); } +/// check for php5 (lib.php) + + if (!search_check_php5()) { + $phpversion = phpversion(); + mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version ".phpversion().")"); + exit(0); + } + require_once("$CFG->dirroot/search/indexlib.php"); $indexinfo = new IndexInfo(); diff --git a/search/query.php b/search/query.php index 38ae1b76f14..b9024166e79 100644 --- a/search/query.php +++ b/search/query.php @@ -50,90 +50,102 @@ /// check for php5, but don't die yet (see line 52) - require_once("{$CFG->dirroot}/search/querylib.php"); - - $page_number = optional_param('page', -1, PARAM_INT); - $pages = ($page_number == -1) ? false : true; - $advanced = (optional_param('a', '0', PARAM_INT) == '1') ? true : false; - $query_string = optional_param('query_string', '', PARAM_CLEAN); - - if ($pages && isset($_SESSION['search_advanced_query'])) { - // if both are set, then we are busy browsing through the result pages of an advanced query - $adv = unserialize($_SESSION['search_advanced_query']); - } else if ($advanced) { - // otherwise we are dealing with a new advanced query - unset($_SESSION['search_advanced_query']); - session_unregister('search_advanced_query'); + if ($check = search_check_php5()) { + require_once("{$CFG->dirroot}/search/querylib.php"); + + $page_number = optional_param('page', -1, PARAM_INT); + $pages = ($page_number == -1) ? false : true; + $advanced = (optional_param('a', '0', PARAM_INT) == '1') ? true : false; + $query_string = optional_param('query_string', '', PARAM_CLEAN); - // chars to strip from strings (whitespace) - $chars = " \t\n\r\0\x0B,-+"; + /** + * discard harmfull searches + */ + if (preg_match("/^[\*\?]+$/", $query_string)){ + $query_string = ''; + $error = get_string('fullwildcardquery','search'); + } - // retrieve advanced query variables - $adv->mustappear = trim(optional_param('mustappear', '', PARAM_CLEAN), $chars); - $adv->notappear = trim(optional_param('notappear', '', PARAM_CLEAN), $chars); - $adv->canappear = trim(optional_param('canappear', '', PARAM_CLEAN), $chars); - $adv->module = optional_param('module', '', PARAM_CLEAN); - $adv->title = trim(optional_param('title', '', PARAM_CLEAN), $chars); - $adv->author = trim(optional_param('author', '', PARAM_CLEAN), $chars); + + if ($pages && isset($_SESSION['search_advanced_query'])) { + // if both are set, then we are busy browsing through the result pages of an advanced query + $adv = unserialize($_SESSION['search_advanced_query']); + } elseif ($advanced) { + // otherwise we are dealing with a new advanced query + unset($_SESSION['search_advanced_query']); + session_unregister('search_advanced_query'); + + // chars to strip from strings (whitespace) + $chars = " \t\n\r\0\x0B,-+"; + + // retrieve advanced query variables + $adv->mustappear = trim(optional_param('mustappear', '', PARAM_CLEAN), $chars); + $adv->notappear = trim(optional_param('notappear', '', PARAM_CLEAN), $chars); + $adv->canappear = trim(optional_param('canappear', '', PARAM_CLEAN), $chars); + $adv->module = optional_param('module', '', PARAM_CLEAN); + $adv->title = trim(optional_param('title', '', PARAM_CLEAN), $chars); + $adv->author = trim(optional_param('author', '', PARAM_CLEAN), $chars); + } + + if ($advanced) { + //parse the advanced variables into a query string + //TODO: move out to external query class (QueryParse?) + + $query_string = ''; + + // get all available module types + $module_types = array_merge(array('all'), array_values(search_get_document_types())); + $adv->module = in_array($adv->module, $module_types) ? $adv->module : 'all'; + + // convert '1 2' into '+1 +2' for required words field + if (strlen(trim($adv->mustappear)) > 0) { + $query_string = ' +'.implode(' +', preg_split("/[\s,;]+/", $adv->mustappear)); + } + + // convert '1 2' into '-1 -2' for not wanted words field + if (strlen(trim($adv->notappear)) > 0) { + $query_string .= ' -'.implode(' -', preg_split("/[\s,;]+/", $adv->notappear)); + } + + // this field is left untouched, apart from whitespace being stripped + if (strlen(trim($adv->canappear)) > 0) { + $query_string .= ' '.implode(' ', preg_split("/[\s,;]+/", $adv->canappear)); + } + + // add module restriction + $doctypestr = get_string('doctype', 'search'); + $titlestr = get_string('title', 'search'); + $authorstr = get_string('author', 'search'); + if ($adv->module != 'all') { + $query_string .= " +{$doctypestr}:".$adv->module; + } + + // create title search string + if (strlen(trim($adv->title)) > 0) { + $query_string .= " +{$titlestr}:".implode(" +{$titlestr}:", preg_split("/[\s,;]+/", $adv->title)); + } + + // create author search string + if (strlen(trim($adv->author)) > 0) { + $query_string .= " +{$authorstr}:".implode(" +{$authorstr}:", preg_split("/[\s,;]+/", $adv->author)); + } + + // save our options if the query is valid + if (!empty($query_string)) { + $_SESSION['search_advanced_query'] = serialize($adv); + } + } + + // normalise page number + if ($page_number < 1) { + $page_number = 1; + } + + //run the query against the index + Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8()); + $sq = new SearchQuery($query_string, $page_number, 10, false); } - - if ($advanced) { - //parse the advanced variables into a query string - //TODO: move out to external query class (QueryParse?) - - $query_string = ''; - - // get all available module types - $module_types = array_merge(array('all'), array_values(search_get_document_types())); - $adv->module = in_array($adv->module, $module_types) ? $adv->module : 'all'; - - // convert '1 2' into '+1 +2' for required words field - if (strlen(trim($adv->mustappear)) > 0) { - $query_string = ' +'.implode(' +', preg_split("/[\s,;]+/", $adv->mustappear)); - } - - // convert '1 2' into '-1 -2' for not wanted words field - if (strlen(trim($adv->notappear)) > 0) { - $query_string .= ' -'.implode(' -', preg_split("/[\s,;]+/", $adv->notappear)); - } - - // this field is left untouched, apart from whitespace being stripped - if (strlen(trim($adv->canappear)) > 0) { - $query_string .= ' '.implode(' ', preg_split("/[\s,;]+/", $adv->canappear)); - } - - // add module restriction - $doctypestr = get_string('doctype', 'search'); - $titlestr = get_string('title', 'search'); - $authorstr = get_string('author', 'search'); - if ($adv->module != 'all') { - $query_string .= " +{$doctypestr}:".$adv->module; - } - - // create title search string - if (strlen(trim($adv->title)) > 0) { - $query_string .= " +{$titlestr}:".implode(" +{$titlestr}:", preg_split("/[\s,;]+/", $adv->title)); - } - - // create author search string - if (strlen(trim($adv->author)) > 0) { - $query_string .= " +{$authorstr}:".implode(" +{$authorstr}:", preg_split("/[\s,;]+/", $adv->author)); - } - - // save our options if the query is valid - if (!empty($query_string)) { - $_SESSION['search_advanced_query'] = serialize($adv); - } - } - - // normalise page number - if ($page_number < 1) { - $page_number = 1; - } - - //run the query against the index - $sq = new SearchQuery($query_string, $page_number, 10, false); - + if (!$site = get_site()) { redirect("index.php"); } @@ -153,6 +165,17 @@ print_header("$strsearch", "$site->fullname" , $navigation, "", "", true, " ", navmenu($site)); } + //keep things pretty, even if php5 isn't available + if (!$check) { + print_heading(search_check_php5(true)); + print_footer(); + exit(0); + } + + if (!empty($error)){ + notice ($error); + } + print_box_start(); print_heading($strquery); @@ -168,7 +191,6 @@ } } ?> -