From: diml Date: Sat, 30 May 2009 22:11:53 +0000 (+0000) Subject: MDL-19342 - small fixes from Tatsuva Shirai + UTF-8 global straighten up X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4021d539aaf3db1da650ab39e075b1f442f3ceba;p=moodle.git MDL-19342 - small fixes from Tatsuva Shirai + UTF-8 global straighten up --- diff --git a/search/Zend/Search/Lucene.php b/search/Zend/Search/Lucene.php index 0cd4d8a12c..3b9fd8e972 100644 --- a/search/Zend/Search/Lucene.php +++ b/search/Zend/Search/Lucene.php @@ -62,6 +62,7 @@ require_once "Zend/Search/Lucene/Index/SegmentInfoPriorityQueue.php"; /** Zend_Search_Lucene_LockManager */ require_once "Zend/Search/Lucene/LockManager.php"; +//require_once "Zend/Search/Lucene/SoftLockManager.php"; @@ -409,7 +410,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface Zend_Search_Lucene_LockManager::obtainReadLock($this->_directory); // Escalate read lock to prevent current generation index files to be deleted while opening process is not done -// Zend_Search_Lucene_LockManager::escalateReadLock($this->_directory); + Zend_Search_Lucene_LockManager::escalateReadLock($this->_directory); $this->_generation = self::getActualGeneration($this->_directory); @@ -452,7 +453,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface } // De-escalate read lock to prevent current generation index files to be deleted while opening process is not done -// Zend_Search_Lucene_LockManager::escalateReadLock($this->_directory); + Zend_Search_Lucene_LockManager::deEscalateReadLock($this->_directory); } /** diff --git a/search/documents/assignment_document.php b/search/documents/assignment_document.php index 8712d75237..caf5f007a5 100644 --- a/search/documents/assignment_document.php +++ b/search/documents/assignment_document.php @@ -6,6 +6,7 @@ * @category core * @subpackage document_wrappers * @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 +* @contributor Tatsuva Shirai 20090530 * @date 2008/03/31 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @version Moodle 2.0 @@ -230,7 +231,9 @@ function assignment_single_document($id, $itemtype) { } } elseif ($itemtype == 'submission') { if ($submission = $DB->get_record('assignment_submissions', array('id' => $id))){ - $assignment = $DB->get_record('assignment', array('id' => $submission->assignment)); + if (!$assignment = $DB->get_record('assignment', array('id' => $submission->assignment))){ + return null; + } } else { return null; } @@ -308,6 +311,8 @@ function assignment_check_text_access($path, $itemtype, $this_id, $user, $group_ $context = $DB->get_record('context', array('id' => $context_id)); $cm = $DB->get_record('course_modules', array('id' => $context->instanceid)); + if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete + if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){ if (!empty($CFG->search_access_debug)) echo "search reject : hidden assignment "; return false; diff --git a/search/documents/chat_document.php b/search/documents/chat_document.php index d17edc5e12..dd8962242b 100644 --- a/search/documents/chat_document.php +++ b/search/documents/chat_document.php @@ -6,6 +6,7 @@ * @category core * @subpackage document_wrappers * @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 +* @contributor Tatsuva Shirai 20090530 * @date 2008/03/31 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @version Moodle 2.0 @@ -272,6 +273,8 @@ function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c $context = $DB->get_record('context', array('id' => $context_id)); $cm = $DB->get_record('course_modules', array('id' => $context->instanceid)); + if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete + if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){ if (!empty($CFG->search_access_debug)) echo "search reject : hidden chat "; return false; diff --git a/search/documents/data_document.php b/search/documents/data_document.php index a05bf67a76..8fafd52233 100644 --- a/search/documents/data_document.php +++ b/search/documents/data_document.php @@ -6,6 +6,7 @@ * @category core * @subpackage document_wrappers * @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 +* @contributor Tatsuva Shirai 20090530 * @date 2008/03/31 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @version Moodle 2.0 @@ -82,7 +83,7 @@ class DataCommentSearchDocument extends SearchDocument { //remove '(ip.ip.ip.ip)' from data record author field $doc->author = preg_replace('/\(.*?\)/', '', $comment['author']); $doc->contents = $comment['content']; - $doc->url = data_make_link($data_id, $comment['recordid']); + $doc->url = data_make_link($comment['dataid'], $comment['recordid']); // module specific information; optional $data->database = $comment['dataid']; @@ -205,7 +206,7 @@ function data_get_content_for_index(&$database) { $context = get_context_instance(CONTEXT_MODULE, $cm->id); // getting records for indexing - $records_content = data_get_records($database->id, 'text'); + $records_content = data_get_records($database->id, 'text,textarea'); if ($records_content){ foreach(array_keys($records_content) as $arecordid) { @@ -232,6 +233,8 @@ function data_get_content_for_index(&$database) { if ($records_comments){ foreach($records_comments as $aComment){ $aComment->title = $recordsTitle[$aComment->recordid]; + $authoruser = $DB->get_record('user', array('id' => $aComment->userid)); + $aComment->author = fullname($authoruser); $documents[] = new DataCommentSearchDocument(get_object_vars($aComment), $database->course, $context->id); } } @@ -257,7 +260,7 @@ function data_single_document($id, $itemtype) { $cm = $DB->get_record('course_modules', array('course' => $record_course, 'module' => $coursemodule, 'instance' => $recordMetaData->dataid)); $context = get_context_instance(CONTEXT_MODULE, $cm->id); // compute text - $recordData = data_get_records($recordMetaData->dataid, 'text', $id); + $recordData = data_get_records($recordMetaData->dataid, 'text,textarea', $id); if ($recordData){ $dataArray = array_values($recordData); $record_content = $dataArray[0]; // We cannot have more than one record here @@ -290,6 +293,8 @@ function data_single_document($id, $itemtype) { $comment->title = $DB->get_field('search_document', 'title', array('docid' => $record->id, 'itemtype' => 'record')); $comment->dataid = $record->dataid; $comment->groupid = $record->groupid; + $authoruser = $DB->get_record('user', array('id' => $comment->userid)); + $comment->author = fullname($authoruser); // make document return new DataCommentSearchDocument(get_object_vars($comment), $record_course, $context->id); } else { @@ -356,6 +361,8 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c $context = $DB->get_record('context', array('id' => $context_id)); $cm = $DB->get_record('course_modules', array('id' => $context->instanceid)); + if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete + if (!$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $context)) { if (!empty($CFG->search_access_debug)) echo "search reject : hidden database "; return false; diff --git a/search/documents/forum_document.php b/search/documents/forum_document.php index 259b0782f9..8e5c939c00 100644 --- a/search/documents/forum_document.php +++ b/search/documents/forum_document.php @@ -6,6 +6,7 @@ * @category core * @subpackage document_wrappers * @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 +* @contributor Tatsuva Shirai 20090530 * @date 2008/03/31 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @version Moodle 2.0 @@ -291,8 +292,9 @@ function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $ $discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion)); $context = $DB->get_record('context', array('id' => $context_id)); $cm = $DB->get_record('course_modules', array('id' => $context->instanceid)); - // $cm = get_coursemodule_from_instance('forum', $discussion->forum, $discussion->course); - // $context = get_context_instance(CONTEXT_MODULE, $cm->id); + + if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete + if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){ if (!empty($CFG->search_access_debug)) echo "search reject : hidden forum resource "; return false; diff --git a/search/documents/glossary_document.php b/search/documents/glossary_document.php index 034897ae25..b923866b31 100644 --- a/search/documents/glossary_document.php +++ b/search/documents/glossary_document.php @@ -6,6 +6,7 @@ * @category core * @subpackage document_wrappers * @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 +* @contributor Tatsuva Shirai 20090530 * @date 2008/03/31 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @version Moodle 2.0 @@ -246,6 +247,8 @@ function glossary_check_text_access($path, $itemtype, $this_id, $user, $group_id $context = $DB->get_record('context', array('id' => $context_id)); $cm = $DB->get_record('course_modules', array('id' => $context->instanceid)); + if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete + if (!$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $context)) { return false; } diff --git a/search/documents/label_document.php b/search/documents/label_document.php index 915d22f624..7c9bcef3d7 100644 --- a/search/documents/label_document.php +++ b/search/documents/label_document.php @@ -6,6 +6,7 @@ * @category core * @subpackage document_wrappers * @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.9 +* @contributor Tatsuva Shirai 20090530 * @date 2008/03/31 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @version Moodle 2.0 @@ -158,6 +159,9 @@ function label_check_text_access($path, $itemtype, $this_id, $user, $group_id, $ $r = $DB->get_record('label', array('id' => $this_id)); $module_context = $DB->get_record('context', array('id' => $context_id)); $cm = $DB->get_record('course_modules', array('id' => $module_context->instanceid)); + + if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete + $course_context = get_context_instance(CONTEXT_COURSE, $r->course); //check if englobing course is visible diff --git a/search/documents/lesson_document.php b/search/documents/lesson_document.php index cc874a31d3..54759a9428 100644 --- a/search/documents/lesson_document.php +++ b/search/documents/lesson_document.php @@ -6,6 +6,7 @@ * @category core * @subpackage document_wrappers * @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 +* @contributor Tatsuva Shirai 20090530 * @date 2008/03/31 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @version Moodle 2.0 @@ -182,6 +183,8 @@ function lesson_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context = $DB->get_record('context', array('id' => $context_id)); $cm = $DB->get_record('course_modules', array('id' => $context->instanceid)); + if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete + if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){ if (!empty($CFG->search_access_debug)) echo "search reject : hidden lesson "; return false; diff --git a/search/documents/physical_doc.php b/search/documents/physical_doc.php index 8c002d1315..2679800c5d 100644 --- a/search/documents/physical_doc.php +++ b/search/documents/physical_doc.php @@ -36,7 +36,7 @@ function get_text_for_indexing_doc(&$resource, $directfile = ''){ // just call pdftotext over stdout and capture the output 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.'); + mtrace('Error with MSWord to text converter command : executable not found at '.$moodleroot.$CFG->block_search_word_to_text_cmd); } else { if ($directfile == ''){ $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"); diff --git a/search/documents/physical_odt.php b/search/documents/physical_odt.php index adde07fd0a..e7539a0998 100644 --- a/search/documents/physical_odt.php +++ b/search/documents/physical_odt.php @@ -36,7 +36,7 @@ function get_text_for_indexing_odt(&$resource, $directfile = ''){ // just call pdftotext over stdout and capture the output if (!empty($CFG->block_search_odt_to_text_cmd)){ if (!file_exists("{$moodleroot}{$CFG->block_search_odt_to_text_cmd}")){ - mtrace('Error with OpenOffice ODT to text converter command : exectuable not found.'); + mtrace('Error with OpenOffice ODT to text converter command : exectuable not found at '.$moodleroot.$CFG->block_search_odt_to_text_cmd); } else { if ($directfile == ''){ $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"); diff --git a/search/documents/physical_ppt.php b/search/documents/physical_ppt.php index 2332b29b10..7dd14e6c8b 100644 --- a/search/documents/physical_ppt.php +++ b/search/documents/physical_ppt.php @@ -90,7 +90,7 @@ function get_text_for_indexing_ppt(&$resource, $directfile = ''){ $indextext = shorten($text, $CFG->block_search_limit_index_body); } - $indextext = mb_convert_encoding($indextext, 'UTF8', 'auto'); + $indextext = mb_convert_encoding($indextext, 'UTF-8', 'auto'); return $indextext; } ?> \ No newline at end of file diff --git a/search/documents/resource_document.php b/search/documents/resource_document.php index 271e318114..ffa0422c18 100644 --- a/search/documents/resource_document.php +++ b/search/documents/resource_document.php @@ -6,6 +6,7 @@ * @category core * @subpackage document_wrappers * @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 +* @contributor Tatsuva Shirai 20090530 * @date 2008/03/31 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @version Moodle 2.0 @@ -89,7 +90,7 @@ function resource_get_content_for_index(&$notneeded) { id as trueid, r.* FROM - {resource} r + {resource} as r WHERE alltext != '' AND alltext != ' ' AND @@ -126,9 +127,9 @@ function resource_get_content_for_index(&$notneeded) { r.type as type, r.timemodified as timemodified FROM - {resource} r, - {course_modules} cm, - {modules} m + {resource} as r, + {course_modules} as cm, + {modules} as m WHERE r.type = 'file' AND cm.instance = r.id AND @@ -239,9 +240,9 @@ function resource_single_document($id, $itemtype) { r.type as type, r.timemodified as timemodified FROM - {resource} r, - {course_modules} cm, - {modules} m + {resource} as r, + {course_modules} as cm, + {modules} as m WHERE cm.instance = r.id AND cm.course = r.course AND @@ -312,6 +313,9 @@ function resource_check_text_access($path, $itemtype, $this_id, $user, $group_id $r = $DB->get_record('resource', array('id' => $this_id)); $module_context = $DB->get_record('context', array('id' => $context_id)); $cm = $DB->get_record('course_modules', array('id' => $module_context->instanceid)); + + if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete + $course = $DB->get_record('course', array('id' => $r->course)); $course_context = get_context_instance(CONTEXT_COURSE, $r->course); diff --git a/search/documents/user_document.php b/search/documents/user_document.php index a77faaaaf5..5df1e340fd 100644 --- a/search/documents/user_document.php +++ b/search/documents/user_document.php @@ -51,7 +51,7 @@ class UserSearchDocument extends SearchDocument { // module specific information; optional // construct the parent class - parent::__construct($doc, $data, 0, 0, 0, PATH_FOR_SEARCH_TYPE_USER); + parent::__construct($doc, $data, 0, 0, $user_id, PATH_FOR_SEARCH_TYPE_USER); } } @@ -77,18 +77,20 @@ class UserPostSearchDocument extends SearchDocument { $user = $DB->get_record('user', array('id' => $user_id)); // we cannot call userdate with relevant locale at indexing time. - $doc->title = get_string('post').': '.fullname($user); + //$doc->title = get_string('post').': '.fullname($user); + $doc->title = $post['subject']; $doc->date = $post['created']; //remove '(ip.ip.ip.ip)' from chat author list $doc->author = fullname($user); $doc->contents = $post['description']; - $doc->url = user_make_link($user_id, 'post'); + // $doc->url = user_make_link($user_id, 'post'); + $doc->url = user_make_link($post['id'], 'post'); // module specific information; optional // construct the parent class - parent::__construct($doc, $data, 0, 0, 0, PATH_FOR_SEARCH_TYPE_USER); + parent::__construct($doc, $data, 0, 0, $user_id, PATH_FOR_SEARCH_TYPE_USER); } } @@ -125,7 +127,7 @@ class UserBlogAttachmentSearchDocument extends SearchDocument { // module specific information; optional // construct the parent class - parent::__construct($doc, $data, 0, 0, 0, PATH_FOR_SEARCH_TYPE_USER); + parent::__construct($doc, $data, 0, 0, $post['userid'], PATH_FOR_SEARCH_TYPE_USER); } } @@ -143,7 +145,7 @@ function user_make_link($itemid, $itemtype) { if ($itemtype == 'user'){ return $CFG->wwwroot.'/user/view.php?id='.$itemid; } elseif ($itemtype == 'post') { - return $CFG->wwwroot.'/blog/index.php?userid='.$itemid; + return $CFG->wwwroot.'/blog/index.php?postid='.$itemid; } elseif ($itemtype == 'attachment') { $post = $DB->get_record('post', array('id' => $itemid)); if (!$CFG->slasharguments){ diff --git a/search/documents/wiki_document.php b/search/documents/wiki_document.php index dd30807587..d3c6cc809f 100644 --- a/search/documents/wiki_document.php +++ b/search/documents/wiki_document.php @@ -6,6 +6,7 @@ * @category core * @subpackage document_wrappers * @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 +* @contributor Tatsuva Shirai 20090530 * @date 2008/03/31 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @version Moodle 2.0 @@ -264,6 +265,9 @@ function wiki_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c $course = $DB->get_record('course', array('id' => $entry->course)); $context = $DB->get_record('context', array('id' => $context_id)); $cm = $DB->get_record('course_modules', array('id' => $context->instanceid)); + + if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete + if (!$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $context)) { if (!empty($CFG->search_access_debug)) echo "search reject : hidden wiki "; return false; diff --git a/search/query.php b/search/query.php index 68990e56b5..5da64bfdfc 100644 --- a/search/query.php +++ b/search/query.php @@ -7,7 +7,6 @@ * @subpackage search_engine * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8 * @date 2008/03/31 - * @version prepared for 2.0 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * * The query page - accepts a user-entered query string and returns results. @@ -118,9 +117,9 @@ } // add module restriction - $doctypestr = get_string('doctype', 'search'); - $titlestr = get_string('title', 'search'); - $authorstr = get_string('author', 'search'); + $doctypestr = 'doctype'; + $titlestr = 'title'; + $authorstr = 'author'; if ($adv->module != 'all') { $query_string .= " +{$doctypestr}:".$adv->module; } @@ -274,7 +273,8 @@ ?>
-
+ +
doctype == 'user'){ // A special handle for users - $icon = print_user_picture ($listing->author, 0, true, 0, true, false) ; + $icon = print_user_picture ($listing->userid, 0, true, 0, true, false) ; } else { $iconpath = $CFG->modpixpath.'/'.$listing->doctype.'/icon.gif'; $icon = "\"\"/"; @@ -368,7 +368,7 @@ } print_box_end(); ?> -
+
1.8 * @date 2008/03/31 -* @version prepared for 2.0 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ @@ -278,6 +277,7 @@ class SearchQuery { $resultdoc->doctype = $hit->doctype; $resultdoc->author = $hit->author; $resultdoc->courseid = $hit->course_id; + $resultdoc->userid = $hit->user_id; //and store it $resultdocs[] = clone($resultdoc); @@ -326,12 +326,12 @@ class SearchQuery { */ public function page_numbers() { $pages = $this->total_pages(); - $query = htmlentities($this->term); + $query = htmlentities($this->term,ENT_NOQUOTES,'utf-8'); $page = $this->pagenumber; $next = get_string('next', 'search'); $back = get_string('back', 'search'); - $ret = "