MDL-19342 - small fixes from Tatsuva Shirai + UTF-8 global straighten up

This commit is contained in:
diml
2009-05-30 22:11:53 +00:00
parent b8523467c7
commit 4021d539aa
16 changed files with 73 additions and 35 deletions
+3 -2
View File
@@ -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);
}
/**
+6 -1
View File
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Valery Fremaux [[email protected]] > 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;
+3
View File
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Valery Fremaux [[email protected]] > 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;
+10 -3
View File
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Valery Fremaux [[email protected]] > 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;
+4 -2
View File
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Michael Campanis (mchampan) [[email protected]], Valery Fremaux [[email protected]] > 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;
+3
View File
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Michael Campanis (mchampan) [[email protected]], Valery Fremaux [[email protected]] > 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;
}
+4
View File
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Valery Fremaux [[email protected]] > 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
+3
View File
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Michael Campanis (mchampan) [[email protected]], Valery Fremaux [[email protected]] > 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;
+1 -1
View File
@@ -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}");
+1 -1
View File
@@ -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}");
+1 -1
View File
@@ -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;
}
?>
+11 -7
View File
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Michael Campanis (mchampan) [[email protected]], Valery Fremaux [[email protected]] > 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);
+8 -6
View File
@@ -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){
+4
View File
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Michael Campanis (mchampan) [[email protected]], Valery Fremaux [[email protected]] > 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;
+7 -7
View File
@@ -7,7 +7,6 @@
* @subpackage search_engine
* @author Michael Champanis (mchampan) [[email protected]], Valery Fremaux [[email protected]] > 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 @@
?>
</form>
<br/>
<div class="mdl-align">
<div align="center">
<?php
print_string('searching', 'search') . ': ';
@@ -334,7 +334,7 @@
foreach ($hits as $listing) {
if ($listing->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 = "<img align=\"top\" src=\"".$iconpath."\" class=\"activityicon\" alt=\"\"/>";
@@ -368,7 +368,7 @@
}
print_box_end();
?>
<div class="mdl-align">
<div align="center">
<?php
print_string('ittook', 'search');
search_stopwatch();
+4 -4
View File
@@ -7,7 +7,6 @@
* @subpackage search_engine
* @author Michael Champanis (mchampan) [[email protected]], Valery Fremaux [[email protected]] > 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 = "<div class='mdl-align' id='search_page_links'>";
$ret = "<div align='center' id='search_page_links'>";
//Back is disabled if we're on page 1
if ($page > 1) {
@@ -492,4 +492,4 @@ class SearchQuery {
return $this->results_per_page;
}
}
?>
?>