]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14129, remove error() and white space in search module.
authordongsheng <dongsheng>
Mon, 21 Jul 2008 08:28:26 +0000 (08:28 +0000)
committerdongsheng <dongsheng>
Mon, 21 Jul 2008 08:28:26 +0000 (08:28 +0000)
lang/en_utf8/search.php
search/add.php
search/delete.php
search/indexer.php
search/indexersplash.php
search/query.php
search/stats.php
search/tests/index.php
search/update.php

index a56404a362592cf50eb9d983c8ef65d6586de1d7..9e21fc891642bc422932ccd8609e04df4dc52c51 100644 (file)
@@ -1,5 +1,5 @@
 <?php  // $Id$
-  
+
 $string['advancedsearch'] = 'Advanced search';
 $string['all'] = 'All';
 $string['author'] = 'Author';
index 61fff17a1ebdc57ac856c801dcd557ba0a9217c5..8973ed9e77c43859460bd756f84a8bc21d1161b3 100644 (file)
     * Major chages in this review is passing the xxxx_db_names return to
     * multiple arity to handle multiple document types modules
     */
-    
+
     /**
-    * includes and requires 
+    * includes and requires
     */
     require_once('../config.php');
     require_once("$CFG->dirroot/search/lib.php");
     require_once("$CFG->dirroot/search/indexlib.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'));
 
 /// checks global search activation
-    
+
     require_login();
-    
+
     if (empty($CFG->enableglobalsearch)) {
-        error(get_string('globalsearchdisabled', 'search'));
+        print_error('globalsearchdisabled', 'search');
     }
-    
+
     if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
-        error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php");
-    } 
-    
+        print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
+    }
+
 /// check for php5 (lib.php)
 
     try {
     $dbcontrol = new IndexDBControl();
     $addition_count = 0;
     $startindextime = time();
-    
+
     $indexdate = $CFG->search_indexer_run_date;
-    
+
     mtrace('Starting index update (additions)...');
     mtrace('Index size before: '.$CFG->search_index_size."\n");
-    
+
 /// get all modules
     if ($mods = get_records_select('modules')) {
-    
+
 /// append virtual modules onto array
 
     $mods = array_merge($mods, search_get_additional_modules());
             $get_document_function = $mod->name.'_single_document';
             $get_newrecords_function = $mod->name.'_new_records';
             $additions = array();
-            
+
             if (file_exists($class_file)) {
                 require_once($class_file);
-                
+
                 //if both required functions exist
                 if (function_exists($db_names_function) and function_exists($get_document_function)) {
                     mtrace("Checking $mod->name module for additions.");
                         foreach($valuesArray as $values){
                             $where = (isset($values[5])) ? 'AND ('.$values[5].')' : '';
                             $itemtypes = ($values[4] != '*' && $values[4] != 'any') ? " AND itemtype = '{$values[4]}' " : '' ;
-                            
+
                             //select records in MODULE table, but not in SEARCH_DATABASE_TABLE
                             $table = SEARCH_DATABASE_TABLE;
                             $query = "
-                                SELECT 
+                                SELECT
                                     docid,
-                                    itemtype 
-                                FROM 
+                                    itemtype
+                                FROM
                                     {$CFG->prefix}{$table}
-                                WHERE 
+                                WHERE
                                     doctype = ?
                                     $itemtypes
                             ";
                             $docIds = $DB->get_records_sql_menu($query, array($mod->name));
                             $docIdList = ($docIds) ? implode("','", array_keys($docIds)) : '' ;
-                            
+
                             $query =  "
-                                SELECT id, 
-                                    {$values[0]} as docid 
-                                FROM 
-                                    {$CFG->prefix}{$values[1]} 
-                                WHERE 
-                                    id NOT IN ('{$docIdList}') and 
+                                SELECT id,
+                                    {$values[0]} as docid
+                                FROM
+                                    {$CFG->prefix}{$values[1]}
+                                WHERE
+                                    id NOT IN ('{$docIdList}') and
                                     {$values[2]} > {$indexdate}
                                     $where
                             ";
                             $records = get_records_sql($query);
-                            
+
                             // foreach record, build a module specific search document using the get_document function
                             if (is_array($records)) {
                                 foreach($records as $record) {
                                     // some documents may not be indexable
                                     if ($add)
                                         $additions[] = $add;
-                                } 
-                            } 
-                        } 
-                        
+                                }
+                            }
+                        }
+
                         // foreach document, add it to the index and database table
                         foreach ($additions as $add) {
                             ++$addition_count;
-                            
+
                             // object to insert into db
                             $dbid = $dbcontrol->addDocument($add);
-                            
+
                             // synchronise db with index
                             $add->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
-                            
+
                             mtrace("  Add: $add->title (database id = $add->dbid, moodle instance id = $add->docid)");
-                            
+
                             $index->addDocument($add);
-                        } 
+                        }
                     }
                     else{
                         mtrace("No types to add.\n");
                     }
                     mtrace("Finished $mod->name.\n");
-                } 
-            } 
-        } 
-    } 
-    
+                }
+            }
+        }
+    }
+
 /// commit changes
 
     $index->commit();
-    
+
 /// update index date and size
 
     set_config("search_indexer_run_date", $startindextime);
     set_config("search_index_size", (int)$CFG->search_index_size + (int)$addition_count);
-    
+
 /// print some additional info
 
     mtrace("Added $addition_count documents.");
     mtrace('Index size after: '.$index->count());
 
-?>
\ No newline at end of file
+?>
index 47a07ec4815e9a3e79b682aa1a5f2859bce46d4d..4f4790d2b6258a116365e31976027fb60a905238 100644 (file)
     * Major chages in this review is passing the xxxx_db_names return to
     * multiple arity to handle multiple document types modules
     */
-    
+
     /**
     * includes and requires
     */
     require_once('../config.php');
     require_once("$CFG->dirroot/search/lib.php");
-    require_once("$CFG->dirroot/search/indexlib.php");    
-    
-/// makes inclusions of the Zend Engine more reliable                               
-    $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;                   
+    require_once("$CFG->dirroot/search/indexlib.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'));require_login();
-    
+
 /// checks global search activation
     if (empty($CFG->enableglobalsearch)) {
-        error(get_string('globalsearchdisabled', 'search'));
+        print_error('globalsearchdisabled', 'search');
     }
-    
+
     if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
-        error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php");
+        print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
     } //if
-    
+
     try {
         $index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
     } catch(LuceneException $e) {
     $dbcontrol = new IndexDBControl();
     $deletion_count = 0;
     $startcleantime = time();
-    
+
     mtrace('Starting clean-up of removed records...');
     mtrace('Index size before: '.$CFG->search_index_size."\n");
-    
+
 /// check all modules
     if ($mods = get_records_select('modules')) {
         $mods = array_merge($mods, search_get_additional_modules());
-        
+
         foreach ($mods as $mod) {
             //build function names
             $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
             $delete_function = $mod->name.'_delete';
             $db_names_function = $mod->name.'_db_names';
             $deletions = array();
-            
+
             if (file_exists($class_file)) {
                 require_once($class_file);
-                
+
                 //if both required functions exist
                 if (function_exists($delete_function) and function_exists($db_names_function)) {
                     mtrace("Checking $mod->name module for deletions.");
                            $where = (isset($values[5])) ? 'WHERE '.$values[5] : '';
                            $itemtypes = ($values[4] != '*' && $values[4] != 'any') ? " itemtype = '{$values[4]}' AND " : '' ;
                            $query = "
-                                SELECT 
+                                SELECT
                                     id,
                                     {$values[0]}
-                                FROM 
+                                FROM
                                     {$CFG->prefix}{$values[1]}
                                     $where
                             ";
                             $docIds = get_records_sql($query);
                             $docIdList = ($docIds) ? implode("','", array_keys($docIds)) : '' ;
-                            
+
                             $table = SEARCH_DATABASE_TABLE;
                             $query = "
-                                SELECT 
-                                    id, 
-                                    docid 
-                                FROM 
+                                SELECT
+                                    id,
+                                    docid
+                                FROM
                                     {$CFG->prefix}{$table}
-                                WHERE 
-                                    doctype = '{$mod->name}' AND 
+                                WHERE
+                                    doctype = '{$mod->name}' AND
                                     $itemtypes
                                     docid not in ('{$docIdList}')
                             ";
                             $records = get_records_sql($query);
-                            
+
                             // build an array of all the deleted records
                             if (is_array($records)) {
                                 foreach($records as $record) {
                                 }
                             }
                         }
-                        
+
                         foreach ($deletions as $delete) {
                             // find the specific document in the index, using it's docid and doctype as keys
                             $doc = $index->find("+docid:{$delete->id} +doctype:$mod->name +itemtype:{$delete->itemtype}");
-                            
+
                             // get the record, should only be one
                             foreach ($doc as $thisdoc) {
                                 ++$deletion_count;
                                 mtrace("  Delete: $thisdoc->title (database id = $thisdoc->dbid, index id = $thisdoc->id, moodle instance id = $thisdoc->docid)");
-                                
+
                                 //remove it from index and database table
                                 $dbcontrol->delDocument($thisdoc);
                                 $index->delete($thisdoc->id);
             }
         }
     }
-    
+
 /// commit changes
 
     $index->commit();
-    
+
 /// update index date and index size
 
     set_config("search_indexer_cleanup_date", $startcleantime);
     set_config("search_index_size", (int)$CFG->search_index_size - (int)$deletion_count);
-    
+
     mtrace("Finished $deletion_count removals.");
     mtrace('Index size after: '.$index->count());
 
-?>
\ No newline at end of file
+?>
index 33658319507a5231ba5239b1c2ab16fd0c0141f9..84bfb842d7ce54b7dfd537386c90405fa2f88ad0 100644 (file)
@@ -43,101 +43,101 @@ $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
 /// only administrators can index the moodle installation, because access to all pages is required
 
     require_login();
-    
+
     if (empty($CFG->enableglobalsearch)) {
-        error(get_string('globalsearchdisabled', 'search'));
+        print_error('globalsearchdisabled', 'search');
     }
-    
+
     if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
-        error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php");
-    } 
-    
+        print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
+    }
+
 /// confirmation flag to prevent accidental reindexing (indexersplash.php is the correct entry point)
 
     $sure = strtolower(optional_param('areyousure', '', PARAM_ALPHA));
-    
+
     if ($sure != 'yes') {
         mtrace("<pre>Sorry, you need to confirm indexing via <a href='indexersplash.php'>indexersplash.php</a>"
               .". (<a href='index.php'>Back to query page</a>).</pre>");
-    
+
         exit(0);
     }
-    
+
 /// check for php5 (lib.php)
 
     //php5 found, continue including php5-only files
     //require_once("$CFG->dirroot/search/Zend/Search/Lucene.php");
     require_once("$CFG->dirroot/search/indexlib.php");
-    
+
     mtrace('<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /></head><body>');
     mtrace('<pre>Server Time: '.date('r',time())."\n");
-    
+
     if (isset($CFG->search_indexer_busy) && $CFG->search_indexer_busy == '1') {
         //means indexing was not finished previously
         mtrace("Warning: Indexing was not successfully completed last time, restarting.\n");
     }
-    
+
 /// turn on busy flag
 
     set_config('search_indexer_busy', '1');
-    
+
     //paths
     $index_path = SEARCH_INDEX_PATH;
     $index_db_file = "{$CFG->dirroot}/search/db/$CFG->dbtype.sql";
     $dbcontrol = new IndexDBControl();
-    
+
 /// setup directory in data root
 
     if (!file_exists($index_path)) {
         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 {
             mtrace("Directory successfully created.");
-        } 
-    } 
+        }
+    }
     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);
-    
+
 /// New regeneration
 
     mtrace('Deleting old index entries.');
     delete_records(SEARCH_DATABASE_TABLE);
-    
+
 /// begin timer
 
     search_stopwatch();
     mtrace("Starting activity modules\n");
-    
+
     //the presence of the required search functions -
     // * mod_iterator
     // * mod_get_content_for_index
     //are the sole basis for including a module in the index at the moment.
 
     $searchables = search_collect_searchables();
-    
+
 /// start indexation
 
     if ($searchables){
         foreach ($searchables as $mod) {
-        
+
             $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}")){
@@ -149,10 +149,10 @@ $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
                 }
             }
             */
-         
+
             if (file_exists($class_file)) {
                 include_once($class_file);
-    
+
                 //build function names
                 $iter_function = $mod->name.'_iterator';
                 $index_function = $mod->name.'_get_content_for_index';
@@ -163,35 +163,35 @@ $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
                     if ($sources){
                         foreach ($sources as $i) {
                             $documents = $index_function($i);
-                  
+
                             //begin transaction
                             if ($documents){
                                 foreach($documents as $document) {
                                     $counter++;
-                                    
+
                                     //object to insert into db
                                     $dbid = $dbcontrol->addDocument($document);
-                                    
+
                                     //synchronise db with index
                                     $document->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
-                                    
+
                                     //add document to index
                                     $index->addDocument($document);
-                                    
+
                                     //commit every x new documents, and print a status message
                                     if (($counter % 2000) == 0) {
                                         $index->commit();
                                         mtrace(".. $counter");
-                                    } 
+                                    }
                                 }
                             }
                             //end transaction
                         }
                     }
-            
+
                     //commit left over documents, and finish up
                     $index->commit();
-          
+
                     mtrace("-- $counter documents indexed");
                     mtrace("done.\n");
                 }
@@ -200,25 +200,25 @@ $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
             }
         }
     }
-      
+
 /// finished modules
 
     mtrace('Finished activity modules');
     search_stopwatch();
-        
+
     mtrace(".<br/><a href='index.php'>Back to query page</a>.");
     mtrace('</pre>');
-    
+
 /// finished, turn busy flag off
 
     set_config('search_indexer_busy', '0');
-    
+
 /// mark the time we last updated
 
     set_config('search_indexer_run_date', time());
-    
+
 /// and the index size
 
     set_config('search_index_size', (int)$index->count());
 
-?>
\ No newline at end of file
+?>
index cf400cb416d9061ef9aac1befdd086cd27ac6dc8..c5790ae1d1ed72e76d4d029c22a2b5cdb3f0f479 100644 (file)
@@ -24,25 +24,25 @@ require_once("{$CFG->dirroot}/search/lib.php");
 $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;
 ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path'));
 
-/// check global search is enabled 
+/// check global search is enabled
 
     require_login();
-    
+
     if (empty($CFG->enableglobalsearch)) {
-        error(get_string('globalsearchdisabled', 'search'));
+        print_error('globalsearchdisabled', 'search');
     }
-    
+
     if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
-        error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php");
-    } 
-    
+        print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
+    }
+
     require_once("$CFG->dirroot/search/indexlib.php");
     $indexinfo = new IndexInfo();
-    
+
     if ($indexinfo->valid()) {
         $strsearch = get_string('search', 'search');
         $strquery  = get_string('stats');
-        
+
         $navlinks[] = array('name' => $strsearch, 'link' => "index.php", 'type' => 'misc');
         $navlinks[] = array('name' => $strquery, 'link' => "stats.php", 'type' => 'misc');
         $navlinks[] = array('name' => get_string('runindexer','search'), 'link' => null, 'type' => 'misc');
@@ -54,7 +54,7 @@ ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path
         }
         $site = get_site();
         print_header("$strsearch", "$site->fullname" , $navigation, "", "", true, "&nbsp;", navmenu($site));
-     
+
         mtrace("<pre>The data directory ($indexinfo->path) contains $indexinfo->filecount files, and\n"
               ."there are ".$indexinfo->dbcount." records in the <em>block_search_documents</em> table.\n"
               ."\n"
@@ -70,8 +70,8 @@ ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path
               ."<a href='indexer.php?areyousure=yes'>Continue indexing</a> or <a href='index.php'>Back to query page</a>."
               ."</pre>");
         print_footer();
-    } 
+    }
     else {
         header('Location: indexer.php?areyousure=yes');
     }
-?>
\ No newline at end of file
+?>
index cd0aaf2d7dbc472f36cc71983759147952a8c610..89d07652225cad947bb1dd955f65e1c870fe6534 100644 (file)
@@ -30,7 +30,7 @@
     *   All articles written by Helen Foster
     *
     */
-    
+
     /**
     * includes and requires
     */
     if ($CFG->forcelogin) {
         require_login();
     }
-    
+
     if (empty($CFG->enableglobalsearch)) {
-        error(get_string('globalsearchdisabled', 'search'));
+        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");
-    
+
         $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);
-        
+
         /**
-        * 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
             $adv = unserialize($_SESSION['search_advanced_query']);
             // 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->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 = 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 ensuring internal coding works in UTF-8
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
         $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');
-    
+
 //    if ($CFG->version < 2007032200){ NOT RELIABLE
     if (!function_exists('build_navigation')){
         print_header("$site->shortname: $strsearch: $strquery", "$site->fullname",
         $site = get_site();
         print_header("$strsearch", "$site->fullname" , $navigation, "", "", true, "&nbsp;", navmenu($site));
     }
-    
+
     if (!empty($error)){
         notice ($error);
     }
-    
+
     print_box_start();
     print_heading($strquery);
-    
+
     print_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));
-        } 
+        }
     }
     ?>
     <form id="query" method="get" action="query.php">
-    <?php 
-    if (!$advanced) { 
+    <?php
+    if (!$advanced) {
     ?>
         <input type="text" name="query_string" length="50" value="<?php print stripslashes($query_string) ?>" />
         &nbsp;<input type="submit" value="<?php print_string('search', 'search') ?>" /> &nbsp;
         <a href="query.php?a=1"><?php print_string('advancedsearch', 'search') ?></a> |
         <a href="stats.php"><?php print_string('statistics', 'search') ?></a>
-    <?php 
-    } 
+    <?php
+    }
     else {
         print_box_start();
       ?>
         <input type="hidden" name="a" value="<?php print $advanced; ?>"/>
-    
+
         <table border="0" cellpadding="3" cellspacing="3">
-    
+
         <tr>
           <td width="240"><?php print_string('thesewordsmustappear', 'search') ?>:</td>
           <td><input type="text" name="mustappear" length="50" value="<?php print $adv->mustappear; ?>" /></td>
         </tr>
-    
+
         <tr>
           <td><?php print_string('thesewordsmustnotappear', 'search') ?>:</td>
           <td><input type="text" name="notappear" length="50" value="<?php print $adv->notappear; ?>" /></td>
         </tr>
-    
+
         <tr>
           <td><?php print_string('thesewordshelpimproverank', 'search') ?>:</td>
           <td><input type="text" name="canappear" length="50" value="<?php print $adv->canappear; ?>" /></td>
         </tr>
-    
+
         <tr>
           <td><?php print_string('whichmodulestosearch?', 'search') ?>:</td>
           <td>
             <select name="module">
-    <?php 
+    <?php
         foreach($module_types as $mod) {
             if ($mod == $adv->module) {
                 if ($mod != 'all'){
                 else{
                     print "<option value='$mod' selected=\"selected\">".get_string('all', 'search')."</option>\n";
                 }
-            } 
+            }
             else {
                 if ($mod != 'all'){
                     print "<option value='$mod'>".get_string('modulenameplural', $mod)."</option>\n";
                 else{
                     print "<option value='$mod'>".get_string('all', 'search')."</option>\n";
                 }
-            } 
-        } 
+            }
+        }
     ?>
             </select>
           </td>
         </tr>
-    
+
         <tr>
           <td><?php print_string('wordsintitle', 'search') ?>:</td>
           <td><input type="text" name="title" length="50" value="<?php print $adv->title; ?>" /></td>
         </tr>
-    
+
         <tr>
           <td><?php print_string('authorname', 'search') ?>:</td>
           <td><input type="text" name="author" length="50" value="<?php print $adv->author; ?>" /></td>
         </tr>
-    
+
         <tr>
           <td colspan="3" align="center"><br /><input type="submit" value="<?php print_string('search', 'search') ?>" /></td>
         </tr>
-    
+
         <tr>
           <td colspan="3" align="center">
             <table border="0" cellpadding="0" cellspacing="0">
         </table>
     <?php
         print_box_end();
-        } 
+        }
     ?>
     </form>
     <br/>
-    
+
     <div align="center">
     <?php
     print_string('searching', 'search') . ': ';
-    
+
     if ($sq->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 '<p>' . get_string('noindexmessage', 'search') . '<a href="indexersplash.php">' . get_string('createanindex', 'search')."</a></p>\n";
-    } 
-    
+    }
+
     ?>
     </div>
     <?php
     print_box_end();
-    
+
 /// prints all the results in a box
 
     if ($sq->is_valid()) {
         print_box_start();
-        
+
         search_stopwatch();
         $hit_count = $sq->count();
-        
+
         print "<br />";
-        
+
         print $hit_count.' '.get_string('resultsreturnedfor', 'search') . " '".stripslashes($query_string)."'.";
         print "<br />";
-        
+
         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 "<ol>";
-            
+
             $typestr = get_string('type', 'search');
             $scorestr = get_string('score', 'search');
             $authorstr = get_string('author', 'search');
             foreach ($hits as $listing) {
 
                 $iconpath = $CFG->modpixpath.'/'.$listing->doctype.'/icon.gif';
-               $coursename = get_field('course', 'fullname', 'id', $listing->courseid);
+                $coursename = get_field('course', 'fullname', 'id', $listing->courseid);
                 $courseword = mb_convert_case(get_string('course', 'moodle'), MB_CASE_LOWER, 'UTF-8');
                 //if ($CFG->unicodedb) {
                 //$listing->title = mb_convert_encoding($listing->title, 'auto', 'UTF8');
                 if (function_exists($title_post_processing_function)) {
                     $listing->title = $title_post_processing_function($listing->title);
                 }
-    
+
                 echo "<li value='".($listing->number+1)."'><a href='"
                     .str_replace('DEFAULT_POPUP_SETTINGS', DEFAULT_POPUP_SETTINGS ,$listing->url)
                     ."'><img align=\"top\" src=\"".$iconpath
                     echo ", {$authorstr}: ".$listing->author."\n"
                         ."</li>\n";
                 }
-            }            
+            }
             echo "</ol>";
             echo $page_links;
-        }     
+        }
         print_box_end();
     ?>
     <div align="center">
-    <?php 
+    <?php
         print_string('ittook', 'search');
-        search_stopwatch(); 
+        search_stopwatch();
         print_string('tofetchtheseresults', 'search');
     ?>.
     </div>
-    
+
     <?php
     }
     print_box_end();
     print_footer();
-?>
\ No newline at end of file
+?>
index 84e4d12429d7c81177a0826f372a92c8a8bd447a..4e6feae67880e8baf320a838e755fc1ee91ad7b5 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-/** 
+/**
 * Global Search Engine for Moodle
 *
 * @package search
@@ -11,7 +11,7 @@
 *
 * Prints some basic statistics about the current index.
 * Does some diagnostics if you are logged in as an administrator.
-* 
+*
 */
 
 /**
@@ -25,24 +25,24 @@ require_once("{$CFG->dirroot}/search/lib.php");
     if ($CFG->forcelogin) {
         require_login();
     }
-    
+
     if (empty($CFG->enableglobalsearch)) {
-        error(get_string('globalsearchdisabled', 'search'));
+        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("index.php");
-    } 
-    
+    }
+
     $strsearch = get_string('search', 'search');
-    $strquery  = get_string('statistics', 'search'); 
-    
+    $strquery  = get_string('statistics', 'search');
+
     if (!function_exists('build_navigation')){
         print_header("$site->shortname: $strsearch: $strquery", "$site->fullname",
                    "<a href=\"index.php\">$strsearch</a> -> $strquery");
@@ -53,20 +53,20 @@ require_once("{$CFG->dirroot}/search/lib.php");
         $site = get_site();
         print_header("$strsearch", "$site->fullname" , $navigation, "", "", true, "&nbsp;", navmenu($site));
     }
-    
+
 /// keep things pretty, even if php5 isn't available
 
     print_box_start();
     print_heading($strquery);
-    
+
     print_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))) {
@@ -81,51 +81,51 @@ 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("<strong>{$datadirectorystr}</strong>", '<em><strong>'.$indexinfo->path.'</strong></em>');
         $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("<strong>{$errorsstr}</strong>", '&nbsp;');
             foreach ($errors as $key => $value) {
                 $admin_table->data[] = array($key.' ... ', $value);
-            } 
+            }
         }
-    
+
         print_table($admin_table);
         print_spacer(20);
         print_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, '<a href="tests/index.php" target="_blank">tests/index.php</a>');
         $admin_table->data[] = array($runindexerstr, '<a href="indexersplash.php" target="_blank">indexersplash.php</a>');
-        
+
         print_table($admin_table);
         print_spacer(20);
-    } 
-    
+    }
+
 /// this is the standard summary table for normal users, shows document counts
 
     $table->tablealign = "center";
@@ -134,30 +134,30 @@ require_once("{$CFG->dirroot}/search/lib.php");
     $table->cellpadding = 5;
     $table->cellspacing = 0;
     $table->width = '500';
-    
+
     $table->data[] = array("<strong>{$databasestr}</strong>", "<em><strong>{$CFG->prefix}".SEARCH_DATABASE_TABLE.'</strong></em>');
-    
+
 /// 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 $key => $value) {
         $table->data[] = array(get_string('documentsfor', 'search') . " '".get_string('modulenameplural', $key)."'", $value);
-    } 
-    
+    }
+
     print_heading($databasestatestr);
     print_table($table);
-    
+
     print_box_end();
     print_box_end();
     print_footer();
-?>
\ No newline at end of file
+?>
index 651014043799006ffcdb825a2ecccc75cdf5b027..31cb5e66130a61185256fd42d646602d53cfb0ce 100644 (file)
     ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path'));
 
     require_login();
-    
+
     if (empty($CFG->enableglobalsearch)) {
-      error('Global searching is not enabled.');
+      print_error('globalsearchdisabled', 'search');
     }
-    
+
     if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
-      error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
+      print_error('onlyadmins', 'error', "$CFG->wwwroot/login/index.php");
     } //if
-    
+
     mtrace('<pre>Server Time: '.date('r',time()));
     mtrace("Testing global search capabilities:\n");
-    
+
     $phpversion = phpversion();
-    
+
     //fix paths for testing
     set_include_path(get_include_path().":../");
     require_once("$CFG->dirroot/search/Zend/Search/Lucene.php");
-    
+
     mtrace("Checking activity modules:\n");
-    
+
     //the presence of the required search functions -
     // * mod_iterator
     // * mod_get_content_for_index
     //are the sole basis for including a module in the index at the moment.
-    
+
 /// get all installed modules
     if ($mods = get_records('modules', '', '', 'name', 'id,name')){
 
                 if (file_exists($documentfile)){
                     $searchables[] = $mod;
                 }
-            }        
-        }    
+            }
+        }
         mtrace(count($searchables).' modules to search in / '.count($mods).' modules found.');
     }
-      
+
 /// collects blocks as indexable information may be found in blocks either
     if ($blocks = get_records('block', '', '', 'name', 'id,name')) {
         $blocks_searchables = array();
                     $mod->location = 'blocks';
                     $blocks_searchables[] = $block;
                 }
-            }        
-        }    
+            }
+        }
         mtrace(count($blocks_searchables).' blocks to search in / '.count($blocks).' blocks found.');
         $searchables = array_merge($searchables, $blocks_searchables);
     }
-      
+
 /// add virtual modules onto the back of the array
 
     $additional = search_get_additional_modules();
     mtrace(count($additional).' additional to search in.');
     $searchables = array_merge($searchables, $additional);
-    
+
     foreach ($searchables as $mod) {
         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)) {
             include_once($class_file);
-    
+
             if (!defined('SEARCH_TYPE_'.strtoupper($mod->name))) {
                 mtrace("ERROR: Constant 'SEARCH_TYPE_".strtoupper($mod->name)."' is not defined in search/searchtypes.php or in module");
                 continue;
             }
-            
+
             $iter_function = $mod->name.'_iterator';
             $index_function = $mod->name.'_get_content_for_index';
-            
+
             if (function_exists($index_function) && function_exists($iter_function)) {
                 if (is_array($iter_function())) {
                     $documents = $index_function(array_pop($iter_function()));
-            
+
                     if (is_array($documents)) {
                         mtrace("Success: '$mod->name' module seems to be ready for indexing.");
                     } else {
                         mtrace("ERROR: $index_function() doesn't seem to be returning an array.");
-                    } 
+                    }
                 } else {
                     mtrace("ERROR: $iter_function() doesn't seem to be returning an object array.");
-                } 
+                }
             } else {
                 mtrace("ERROR: $iter_function() and/or $index_function() does not exist in $class_file");
-            } 
+            }
         } else {
             mtrace("Notice: $class_file does not exist, this module will not be indexed.");
-        } 
-    } 
-    
+        }
+    }
+
     //finished modules
     mtrace("\nFinished checking activity modules.");
-    
+
     //now blocks...
     //
-    
+
     mtrace("<br/><a href='../index.php'>Back to query page</a> or <a href='../indexersplash.php'>Start indexing</a>.");
     mtrace('</pre>');
-?>
\ No newline at end of file
+?>
index d1a38dcd4983888056edaf6e267f25fe85bbde0d..b5eaa445e2b8a8def5dbb046be50c512cbd410e8 100644 (file)
@@ -14,7 +14,7 @@
     * Major chages in this review is passing the xxxx_db_names return to
     * multiple arity to handle multiple document types modules
     */
-    
+
     /**
     * includes and requires
     */
     require_once("$CFG->dirroot/search/lib.php");
     require_once("$CFG->dirroot/search/indexlib.php");
 
-/// makes inclusions of the Zend Engine more reliable                               
-    $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ;                   
+/// 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'));require_login();
 
 /// checks global search activation
 
     require_login();
-    
+
     if (empty($CFG->enableglobalsearch)) {
-        error(get_string('globalsearchdisabled', 'search'));
+        print_error('globalsearchdisabled', 'search');
     }
-    
+
     if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
-        error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php");
-    } 
-    
+        print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
+    }
+
     try {
         $index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
     } catch(LuceneException $e) {
     $startupdatedate = time();
 
 /// indexing changed resources
-    
+
     mtrace("Starting index update (updates)...\n");
-    
+
     if ($mods = get_records_select('modules')) {
         $mods = array_merge($mods, search_get_additional_modules());
-        
+
         foreach ($mods as $mod) {
             $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
             $get_document_function = $mod->name.'_single_document';
             $delete_function = $mod->name.'_delete';
             $db_names_function = $mod->name.'_db_names';
             $updates = array();
-            
+
             if (file_exists($class_file)) {
                 require_once($class_file);
-                
+
                 //if both required functions exist
                 if (function_exists($delete_function) and function_exists($db_names_function) and function_exists($get_document_function)) {
                     mtrace("Checking $mod->name module for updates.");
                     $valuesArray = $db_names_function();
                     if ($valuesArray){
                         foreach($valuesArray as $values){
-                        
+
                             $where = (isset($values[5])) ? 'AND ('.$values[5].')' : '';
                             $itemtypes = ($values[4] != '*' && $values[4] != 'any') ? " AND itemtype = '{$values[4]}' " : '' ;
-    
+
                             //TODO: check 'in' syntax with other RDBMS' (add and update.php as well)
                             $table = SEARCH_DATABASE_TABLE;
                             $query = "
-                                SELECT 
+                                SELECT
                                     docid,
                                     itemtype
-                                FROM 
+                                FROM
                                     {$CFG->prefix}{$table}
                                 WHERE
                                     doctype = ?
                             ";
                             $docIds = $DB->get_records_sql_menu($query, array($mod->name));
                             $docIdList = ($docIds) ? implode("','", array_keys($docIds)) : '' ;
-                            
+
                             $query = "
-                                SELECT 
-                                    id, 
+                                SELECT
+                                    id,
                                     {$values[0]} as docid
-                                FROM 
-                                    {$CFG->prefix}{$values[1]} 
-                                WHERE 
-                                    {$values[3]} > {$indexdate} AND 
+                                FROM
+                                    {$CFG->prefix}{$values[1]}
+                                WHERE
+                                    {$values[3]} > {$indexdate} AND
                                     id IN ('{$docIdList}')
                                     $where
                             ";
                             if (is_array($records)) {
                                 foreach($records as $record) {
                                     $updates[] = $delete_function($record->docid, $docIds[$record->docid]);
-                                } 
-                            } 
+                                }
+                            }
                         }
-                        
+
                         foreach ($updates as $update) {
                             ++$update_count;
-                            
+
                             //delete old document
                             $doc = $index->find("+docid:{$update->id} +doctype:{$mod->name} +itemtype:{$update->itemtype}");
-                            
+
                             //get the record, should only be one
                             foreach ($doc as $thisdoc) {
                                 mtrace("  Delete: $thisdoc->title (database id = $thisdoc->dbid, index id = $thisdoc->id, moodle instance id = $thisdoc->docid)");
                                 $dbcontrol->delDocument($thisdoc);
                                 $index->delete($thisdoc->id);
-                            } 
-                            
+                            }
+
                             //add new modified document back into index
                             $add = $get_document_function($update->id, $update->itemtype);
-                            
+
                             //object to insert into db
                             $dbid = $dbcontrol->addDocument($add);
-                            
+
                             //synchronise db with index
                             $add->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
                             mtrace("  Add: $add->title (database id = $add->dbid, moodle instance id = $add->docid)");
                             $index->addDocument($add);
-                        } 
+                        }
                     }
                     else{
                         mtrace("No types to update.\n");
                     }
                     mtrace("Finished $mod->name.\n");
-                } 
-            } 
-        } 
-    } 
-    
+                }
+            }
+        }
+    }
+
     //commit changes
     $index->commit();
-    
+
     //update index date
     set_config("search_indexer_update_date", $startupdatedate);
-    
+
     mtrace("Finished $update_count updates");
 
-?>
\ No newline at end of file
+?>