From 70f52c703b5839e9473cb0154827eb249528137d Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Mon, 10 Aug 2009 05:49:33 +0000 Subject: [PATCH] MDL-19822 Converted print_box* to $OUTPUT->box* --- search/query.php | 182 +++++++++++++++++++++++------------------------ search/stats.php | 86 +++++++++++----------- 2 files changed, 134 insertions(+), 134 deletions(-) diff --git a/search/query.php b/search/query.php index 41e6f6eed1..269f1fd7b7 100644 --- a/search/query.php +++ b/search/query.php @@ -30,7 +30,7 @@ * All articles written by Helen Foster * */ - + /** * includes and requires */ @@ -40,13 +40,13 @@ if ($CFG->forcelogin) { require_login(); } - + if (empty($CFG->enableglobalsearch)) { print_error('globalsearchdisabled', 'search'); } - + $adv = new Object(); - + /// check for php5, but don't die yet (see line 52) require_once($CFG->dirroot.'/search/querylib.php'); @@ -56,19 +56,19 @@ $advanced = (optional_param('a', '0', PARAM_INT) == '1') ? true : false; $query_string = stripslashes(optional_param('query_string', '', PARAM_CLEAN)); -/// discard harmfull searches +/// discard harmfull searches if (!isset($CFG->block_search_utf8dir)){ set_config('block_search_utf8dir', 1); } - -/// discard harmfull searches + +/// discard harmfull searches if (preg_match("/^[\*\?]+$/", $query_string)){ $query_string = ''; $error = get_string('fullwildcardquery','search'); } - + if ($pages && isset($_SESSION['search_advanced_query'])) { // if both are set, then we are busy browsing through the result pages of an advanced query @@ -77,10 +77,10 @@ // 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); @@ -88,137 +88,137 @@ $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 adding third party modules $module_types = array_merge(array('all'), array_values(search_get_document_types())); $module_types = array_merge($module_types, array_values(search_get_document_types('X_SEARCH_TYPE'))); $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 = 'doctype'; $titlestr = 'title'; $authorstr = 'author'; 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 ensuring internal coding works in UTF-8 Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive()); $sq = new SearchQuery($query_string, $page_number, 10, false); - + if (!$site = get_site()) { redirect("index.php"); - } - + } + $strsearch = get_string('search', 'search'); $strquery = get_string('enteryoursearchquery', 'search'); - + // print the header $navlinks[] = array('name' => $strsearch, 'link' => "index.php", 'type' => 'misc'); $navlinks[] = array('name' => $strquery, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); $site = get_site(); print_header("$strsearch", "$site->fullname" , $navigation, '', '', true, ' ', navmenu($site)); - + if (!empty($error)){ notice ($error); } - - print_box_start(); + + echo $OUTPUT->box_start(); echo $OUTPUT->heading($strquery); - - print_box_start(); - + + echo $OUTPUT->box_start(); + $vars = get_object_vars($adv); - + if (isset($vars)) { foreach ($vars as $key => $value) { // htmlentities breaks non-ascii chars ?? $adv->key = stripslashes($value); //$adv->$key = stripslashes(htmlentities($value)); - } + } } ?>
-     | - box_start(); ?> - + - + - + - + - + - + - + - + - +
:
:
:
:
:
:

@@ -268,72 +268,72 @@
box_end(); + } ?>
- +
is_valid_index()) { //use cached variable to show up-to-date index size (takes deletions into account) print $CFG->search_index_size; - } + } else { print "0"; - } - + } + print ' '; print_string('documents', 'search'); print '.'; - + if (!$sq->is_valid_index() and has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { print '

' . get_string('noindexmessage', 'search') . '' . get_string('createanindex', 'search')."

\n"; - } - + } + ?>
box_end(); + /// prints all the results in a box if ($sq->is_valid()) { - print_box_start(); - + echo $OUTPUT->box_start(); + search_stopwatch(); $hit_count = $sq->count(); - + print "
"; - + print $hit_count.' '.get_string('resultsreturnedfor', 'search') . " '".s($query_string)."'."; print "
"; - + if ($hit_count > 0) { $page_links = $sq->page_numbers(); $hits = $sq->results(); - + if ($advanced) { // if in advanced mode, search options are saved in the session, so // we can remove the query string var from the page links, and replace // it with a=1 (Advanced = on) instead $page_links = preg_replace("/query_string=[^&]+/", 'a=1', $page_links); - } - + } + print "
    "; - + $typestr = get_string('type', 'search'); $scorestr = get_string('score', 'search'); $authorstr = get_string('author', 'search'); $searchables = search_collect_searchables(false, false); - foreach ($hits as $listing) { - - if ($listing->doctype == 'user'){ // A special handle for users + foreach ($hits as $listing) { + + if ($listing->doctype == 'user'){ // A special handle for users $icon = print_user_picture ($listing->userid, 0, true, 0, true, false) ; } else { $iconpath = $OUTPUT->mod_icon_url('icon', $listing->doctype); @@ -353,7 +353,7 @@ if (function_exists($title_post_processing_function)) { $listing->title = $title_post_processing_function($listing->title); } - + echo "
  1. url) ."'>$icon $listing->title $course
    \n"; @@ -362,22 +362,22 @@ echo ", {$authorstr}: ".$listing->author."\n" ."
  2. \n"; } - } + } echo "
"; echo $page_links; - } - print_box_end(); + } + echo $OUTPUT->box_end(); ?>
- .
- + box_end(); echo $OUTPUT->footer(); ?> diff --git a/search/stats.php b/search/stats.php index e74671a897..6fea080459 100644 --- a/search/stats.php +++ b/search/stats.php @@ -1,5 +1,5 @@ dirroot.'/search/lib.php'); if ($CFG->forcelogin) { require_login(); } - + if (empty($CFG->enableglobalsearch)) { print_error('globalsearchdisabled', 'search'); } - + /// check for php5, but don't die yet require_once($CFG->dirroot.'/search/indexlib.php'); - + $indexinfo = new IndexInfo(); - + if (!$site = get_site()) { redirect($CFG->wwwroot.'index.php'); - } - + } + $strsearch = get_string('search', 'search'); - $strquery = get_string('statistics', 'search'); - + $strquery = get_string('statistics', 'search'); + $navlinks[] = array('name' => $strsearch, 'link' => "index.php", 'type' => 'misc'); $navlinks[] = array('name' => $strquery, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); $site = get_site(); print_header("$strsearch", "$site->fullname" , $navigation, '', '', true, ' ', navmenu($site)); - + /// keep things pretty, even if php5 isn't available - print_box_start(); + echo $OUTPUT->box_start(); echo $OUTPUT->heading($strquery); - - print_box_start(); - + + echo $OUTPUT->box_start(); + $databasestr = get_string('database', 'search'); $documentsinindexstr = get_string('documentsinindex', 'search'); $deletionsinindexstr = get_string('deletionsinindex', 'search'); $documentsindatabasestr = get_string('documentsindatabase', 'search'); $databasestatestr = get_string('databasestate', 'search'); - + /// this table is only for admins, shows index directory size and location if (has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { @@ -77,54 +77,54 @@ require_once($CFG->dirroot.'/search/lib.php'); $checkdbadvicestr = get_string('checkdbadvice', 'search'); $runindexerteststr = get_string('runindexertest', 'search'); $runindexerstr = get_string('runindexer', 'search'); - + $admin_table->tablealign = 'center'; $admin_table->align = array ('right', 'left'); $admin_table->wrap = array ('nowrap', 'nowrap'); $admin_table->cellpadding = 5; $admin_table->cellspacing = 0; $admin_table->width = '500'; - + $admin_table->data[] = array("{$datadirectorystr}", ''.$indexinfo->path.''); $admin_table->data[] = array($inindexdirectorystr, $indexinfo->filecount); $admin_table->data[] = array($totalsizestr, $indexinfo->size); - + if ($indexinfo->time > 0) { $admin_table->data[] = array(get_string('createdon', 'search'), date('r', $indexinfo->time)); - } + } else { $admin_table->data[] = array(get_string('createdon', 'search'), '-'); - } - + } + if (!$indexinfo->valid($errors)) { $admin_table->data[] = array("{$errorsstr}", ' '); foreach ($errors as $key => $value) { $admin_table->data[] = array($key.' ... ', $value); - } + } } - + print_table($admin_table); $spacer = new html_image(); $spacer->height = 20; echo $OUTPUT->spacer(clone($spacer)) . '
'; echo $OUTPUT->heading($solutionsstr); - + unset($admin_table->data); if (isset($errors['dir'])) { $admin_table->data[] = array($checkdirstr, $checkdiradvicestr); - } + } if (isset($errors['db'])) { $admin_table->data[] = array($checkdbstr, $checkdbadvicestr); - } - + } + $admin_table->data[] = array($runindexerteststr, 'tests/index.php'); $admin_table->data[] = array($runindexerstr, 'indexersplash.php'); - + print_table($admin_table); echo $OUTPUT->spacer($spacer) . '
'; print_spacer(20); - } - + } + /// this is the standard summary table for normal users, shows document counts $table->tablealign = 'center'; @@ -133,22 +133,22 @@ require_once($CFG->dirroot.'/search/lib.php'); $table->cellpadding = 5; $table->cellspacing = 0; $table->width = '500'; - + $table->data[] = array("{$databasestr}", "{$CFG->prefix}".SEARCH_DATABASE_TABLE.''); - + /// add extra fields if we're admin if (has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { //don't want to confuse users if the two totals don't match (hint: they should) $table->data[] = array($documentsinindexstr, $indexinfo->indexcount); - + //*cough* they should match if deletions were actually removed from the index, //as it turns out, they're only marked as deleted and not returned in search results $table->data[] = array($deletionsinindexstr, (int)$indexinfo->indexcount - (int)$indexinfo->dbcount); - } - + } + $table->data[] = array($documentsindatabasestr, $indexinfo->dbcount); - + foreach($indexinfo->types as $type) { if ($type->type == 'mod'){ $table->data[] = array(get_string('documentsfor', 'search') . " '".get_string('modulenameplural', $type->name)."'", $type->records); @@ -157,13 +157,13 @@ require_once($CFG->dirroot.'/search/lib.php'); } else { $table->data[] = array(get_string('documentsfor', 'search') . " '".get_string($type->name)."'", $type->records); } - - } - + + } + echo $OUTPUT->heading($databasestatestr); print_table($table); - - print_box_end(); - print_box_end(); + + echo $OUTPUT->box_end(); + echo $OUTPUT->box_end(); echo $OUTPUT->footer(); ?> -- 2.39.5