enhancing security of command injections.
allowing space in pathes for files.
allowing binding with tools out of moodleroot
} ?>"/><br/><br/>
</td>
</tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('usemoodleroot', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <?php
+ $usemoodleroot = (isset($CFG->block_search_usemoodleroot)) ? 'checked="checked"' : '' ;
+ $notusemoodleroot = (!isset($CFG->block_search_usemoodleroot)) ? 'checked="checked"' : '' ;
+ ?>
+ <input id="block_search_usemoodleroot" type="radio" name="block_search_usemoodleroot" <?php echo $usemoodleroot ?> value="1"/> <?php print_string('yes') ?> -
+ <input id="block_search_usemoodleroot" type="radio" name="block_search_usemoodleroot" <?php echo $notusemoodleroot ?> value="0"/> <?php print_string('no') ?>
+ <br/><br/>
+ </td>
+ </tr>
<tr>
<td valign="top" align="right">
<b><?php print_string('configpdftotextcmd', 'block_search') ?>:</b>
* fetches all the records for a given session and assemble them as a unique track
* we revamped here the code of report.php for making sessions, but without any output.
* note that we should collect sessions "by groups" if groupmode() is SEPARATEGROUPS.
-* @param chat_id the database
+* @param int $chat_id the database
+* @param int $fromtime
+* @param int $totime
* @uses CFG
* @return an array of objects representing the chat sessions.
*/
foreach($messages as $aMessage){
$groupedMessages[$aMessage->groupid][] = $aMessage;
}
- }
- else{
+ } else {
$groupedMessages[-1] = &$messages;
}
$sessiongap = 5 * 60; // 5 minutes silence means a new session
$tracks[count($tracks) - 1]->content .= ' '.$message->message;
$tracks[count($tracks) - 1]->sessionstart = $message->timestamp;
}
- }
+ } else {
// we initiate a new session track (backwards)
- else {
$track = new Object();
$track->sessionend = $message->timestamp;
$track->sessionstart = $message->timestamp;
foreach($sessionTracks as $aTrackId => $aTrack) {
foreach($aTrack->sessionusers as $aUserId){
$user = get_record('user', 'id', $aUserId);
- $aTrack->authors = ($user) ? $user->firstname.' '.$user->lastname : '' ;
+ $aTrack->authors = ($user) ? fullname($user) : '' ;
$documents[] = new ChatTrackSearchDocument(get_object_vars($aTrack), $cm->id, $chat->course, $aTrack->groupid, $context->id);
}
}
if ($tracks){
$aTrack = $tracks[0];
$document = new ChatTrackSearchDocument(get_object_vars($aTrack), $cm->id, $chat->course, $aTrack->groupid, $context->id);
+ return $document;
}
- return $document;
}
return null;
}
// SECURITY : do not allow non admin execute anything on system !!
if (!isadmin($USER->id)) return;
-
+
$moodleroot = (@$CFG->block_search_usemoodleroot) ? "{$CFG->dirroot}/" : '' ;
// 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 : executable not found.');
+ mtrace('Error with MSWord to text converter command : exectuable not found.');
}
else{
$file = escapeshellarg($CFG->dataroot.'/'.$resource->course.'/'.$resource->reference);
- $text_converter_cmd = "\"{$moodleroot}{$CFG->block_search_word_to_text_cmd}\" \"$file\"";
+ $command = trim($CFG->block_search_word_to_text_cmd);
+ $text_converter_cmd = "{$moodleroot}{$command} \"$file\"";
if ($CFG->block_search_word_to_text_env){
putenv($CFG->block_search_word_to_text_env);
}
+ mtrace("Executing : $text_converter_cmd");
$result = shell_exec($text_converter_cmd);
if ($result){
return mb_convert_encoding($result, 'UTF8', 'auto');
}
else{
- mtrace('Error with MSWord to text converter command : execution failed.');
+ mtrace('Error with MSWord to text converter command : execution failed. ');
return '';
}
}
// filter all html tags
// $text = clean_text($text, FORMAT_PLAIN);
// NOTE : this is done in ResourceSearchDocument __constructor
+ $text = preg_replace("/<!--[^>]*?-->/", '', $text);
if (!empty($CFG->block_search_limit_index_body)){
$text = shorten($text, $CFG->block_search_limit_index_body);
// just call pdftotext over stdout and capture the output
if (!empty($CFG->block_search_pdf_to_text_cmd)){
preg_match("/^\S+/", $CFG->block_search_pdf_to_text_cmd, $matches);
- if (!file_exists("{$moodleroot}{$matches[0]}")){
+ if (!file_exists("{$moodleroot}/{$matches[0]}")){
mtrace('Error with pdf to text converter command : exectuable not found.');
}
else{
$file = escapeshellarg($CFG->dataroot.'/'.$resource->course.'/'.$resource->reference);
- $text_converter_cmd = "\"{$moodleroot}{$CFG->block_search_pdf_to_text_cmd}\" \"$file\" -";
+ $command = trim($CFG->block_search_pdf_to_text_cmd);
+ $text_converter_cmd = "{$moodleroot}/{$command} \"$file\" -";
$result = shell_exec($text_converter_cmd);
if ($result){
return $result;
* this function does not need a content iterator, returns all the info
* itself;
* @param notneeded to comply API, remember to fake the iterator array though
+* @uses CFG
* @return an array of searchable documents
*/
function resource_get_content_for_index(&$notneeded) {
global $CFG;
// cannot index empty references
- if (empty($resource->reference)) return false;
+ if (empty($resource->reference)){
+ mtrace("Cannot index, empty reference.");
+ return false;
+ }
// cannot index remote resources
if (resource_is_url($resource->reference)){
$fileparts = pathinfo($resource->reference);
// cannot index unknown or masked types
if (empty($fileparts['extension'])) {
+ mtrace("Cannot index without explicit extension.");
return false;
}
$resource->alltext = $function_name($resource);
if (!empty($resource->alltext)){
if ($getsingle){
- return new ResourceSearchDocument(get_object_vars($resource), $context_id);
- }
- else{
+ $single = new ResourceSearchDocument(get_object_vars($resource), $context_id);
+ mtrace("finished file $resource->name as {$resource->reference}");
+ return $single;
+ } else {
$documents[] = new ResourceSearchDocument(get_object_vars($resource), $context_id);
}
mtrace("finished file $resource->name as {$resource->reference}");
}
- }
- else{
+ } else {
mtrace("fulltext handler not found for $ext type");
}
return false;
$document = resource_get_physical_file($resource, true, $context->id);
if (!$document) mtrace("Warning : this document {$resource->name} will not be indexed");
return $document;
- }
- else{
+ } else {
return new ResourceSearchDocument(get_object_vars($resource), $context->id);
}
}
foreach($entries as $anEntry) {
if ($anEntry) {
if (strlen($anEntry->description) > 0) {
+ $anEntry->author = '';
$documents[] = new TechprojectEntrySearchDocument(get_object_vars($anEntry), $techproject->course, $context->id);
}
}
switch ($itemtype){
case 'requirement':{
$entry = get_record('techproject_requirement', 'id', $id);
+ $entry->author = '';
break;
}
case 'specification':{
$entry = get_record('techproject_specification', 'id', $id);
+ $entry->author = '';
break;
}
case 'milestone':{
$entry = get_record('techproject_milestone', 'id', $id);
+ $entry->author = '';
break;
}
case 'deliverable':{
$entry = get_record('techproject_deliverable', 'id', $id);
+ $entry->author = '';
break;
}
case 'task':{
$doc->contextid = $context_id;
$doc->title = $page['pagename'];
- $doc->date = $page['timemodified'];
+ $doc->date = $page['lastmodified'];
//remove '(ip.ip.ip.ip)' from wiki author field
$doc->author = preg_replace('/\(.*?\)/', '', $page['author']);
$doc->contents = $page['content'];
if ($ids = get_records('wiki_pages', 'wiki', $entry->id, '', 'distinct pagename')) {
if ($pagesets = get_records('wiki_pages', 'wiki', $entry->id, '', 'distinct pagename')) {
foreach ($pagesets as $aPageset) {
- $pages[] = wiki_get_latest_page($entry, $aPageset->id);
+ $pages[] = wiki_get_latest_page($entry, $aPageset->pagename);
}
} else {
return false;