mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 09:56:38 +02:00
MDL-14978 removed obsoleted isadmin()
This commit is contained in:
parent
72f563b91c
commit
e3c7f155d8
23 changed files with 432 additions and 263 deletions
|
@ -166,7 +166,8 @@ function forum_get_discussions_fast($forum_id) {
|
|||
|
||||
$timelimit='';
|
||||
if (!empty($CFG->forum_enabletimedposts)) {
|
||||
if (!((isadmin() and !empty($CFG->admineditalways)) || isteacher(get_field('forum', 'course', 'id', $forum_id)))) {
|
||||
if (!((has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))
|
||||
and !empty($CFG->admineditalways)) || isteacher(get_field('forum', 'course', 'id', $forum_id)))) {
|
||||
$now = time();
|
||||
$timelimit = " AND ((d.timestart = 0 OR d.timestart <= '$now') AND (d.timeend = 0 OR d.timeend > '$now')";
|
||||
if (!empty($USER->id)) {
|
||||
|
@ -302,7 +303,8 @@ function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $
|
|||
* @param string $title
|
||||
*/
|
||||
function forum_link_post_processing($title){
|
||||
return mb_convert_encoding($title, 'UTF-8', 'auto');
|
||||
// return mb_convert_encoding($title, 'UTF-8', 'auto');
|
||||
return mb_convert_encoding($title, 'auto', 'UTF-8');
|
||||
}
|
||||
|
||||
?>
|
|
@ -18,11 +18,11 @@
|
|||
* @param object $resource
|
||||
* @uses CFG, USER
|
||||
*/
|
||||
function get_text_for_indexing_doc(&$resource){
|
||||
function get_text_for_indexing_doc(&$resource, $directfile = ''){
|
||||
global $CFG, $USER;
|
||||
|
||||
// SECURITY : do not allow non admin execute anything on system !!
|
||||
if (!isadmin($USER->id)) return;
|
||||
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
|
||||
|
||||
$moodleroot = (@$CFG->block_search_usemoodleroot) ? "{$CFG->dirroot}/" : '' ;
|
||||
|
||||
|
@ -30,11 +30,14 @@ function get_text_for_indexing_doc(&$resource){
|
|||
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.');
|
||||
}
|
||||
else{
|
||||
$file = escapeshellarg($CFG->dataroot.'/'.$resource->course.'/'.$resource->reference);
|
||||
} else {
|
||||
if ($directfile == ''){
|
||||
$file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
|
||||
} else {
|
||||
$file = escapeshellarg("{$CFG->dataroot}/{$directfile}");
|
||||
}
|
||||
$command = trim($CFG->block_search_word_to_text_cmd);
|
||||
$text_converter_cmd = "{$moodleroot}{$command} $file";
|
||||
$text_converter_cmd = "{$moodleroot}{$command} -m UTF-8.txt $file";
|
||||
if ($CFG->block_search_word_to_text_env){
|
||||
putenv($CFG->block_search_word_to_text_env);
|
||||
}
|
||||
|
@ -42,14 +45,12 @@ function get_text_for_indexing_doc(&$resource){
|
|||
$result = shell_exec($text_converter_cmd);
|
||||
if ($result){
|
||||
return mb_convert_encoding($result, 'UTF8', 'auto');
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
mtrace('Error with MSWord to text converter command : execution failed. ');
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mtrace('Error with MSWord to text converter command : command not set up. Execute once search block configuration.');
|
||||
return '';
|
||||
}
|
||||
|
|
|
@ -17,14 +17,18 @@
|
|||
* @param object $resource
|
||||
* @uses CFG, USER
|
||||
*/
|
||||
function get_text_for_indexing_htm(&$resource){
|
||||
function get_text_for_indexing_htm(&$resource, $directfile = ''){
|
||||
global $CFG, $USER;
|
||||
|
||||
// SECURITY : do not allow non admin execute anything on system !!
|
||||
if (!isadmin($USER->id)) return;
|
||||
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
|
||||
|
||||
// just get text
|
||||
$text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
|
||||
if ($directfile == ''){
|
||||
$text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
|
||||
} else {
|
||||
$text = implode('', file("{$CFG->dataroot}/{$directfile}"));
|
||||
}
|
||||
|
||||
// extract keywords and other interesting meta information and put it back as real content for indexing
|
||||
if (preg_match('/(.*)<meta ([^>]*)>(.*)/is', $text, $matches)){
|
||||
|
@ -40,7 +44,7 @@ function get_text_for_indexing_htm(&$resource){
|
|||
$text = preg_replace("/<[^>]*>/", '', $text);
|
||||
$text = preg_replace("/<!--[^>]*-->/", '', $text);
|
||||
$text = html_entity_decode($text, ENT_COMPAT, 'UTF-8');
|
||||
$text = mb_convert_encoding($text, 'UTF-8', 'AUTO');
|
||||
$text = mb_convert_encoding($text, 'UTF-8', 'auto');
|
||||
|
||||
/*
|
||||
* debug code for tracing input
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
* @param object $resource
|
||||
* @uses CFG, USER
|
||||
*/
|
||||
function get_text_for_indexing_pdf(&$resource){
|
||||
function get_text_for_indexing_pdf(&$resource, $directfile = ''){
|
||||
global $CFG, $USER;
|
||||
|
||||
// SECURITY : do not allow non admin execute anything on system !!
|
||||
if (!isadmin($USER->id)) return;
|
||||
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
|
||||
|
||||
// adds moodle root switch if none was defined
|
||||
if (!isset($CFG->block_search_usemoodleroot)){
|
||||
|
@ -34,23 +34,24 @@ function get_text_for_indexing_pdf(&$resource){
|
|||
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]}")){
|
||||
mtrace('Error with pdf to text converter command : exectuable not found at '.$moodleroot.$matches[0]);
|
||||
}
|
||||
else{
|
||||
$file = escapeshellarg($CFG->dataroot.'/'.$resource->course.'/'.$resource->reference);
|
||||
mtrace('Error with pdf to text converter command : executable not found at '.$moodleroot.$matches[0]);
|
||||
} else {
|
||||
if ($directfile == ''){
|
||||
$file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
|
||||
} else {
|
||||
$file = escapeshellarg("{$CFG->dataroot}/{$directfile}");
|
||||
}
|
||||
$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;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
mtrace('Error with pdf to text converter command : execution failed for '.$text_converter_cmd.'. Check for execution permission on pdf converter executable.');
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mtrace('Error with pdf to text converter command : command not set up. Execute once search block configuration.');
|
||||
return '';
|
||||
}
|
||||
|
|
|
@ -31,15 +31,19 @@
|
|||
* @param object $resource
|
||||
* @uses CFG, USER
|
||||
*/
|
||||
function get_text_for_indexing_ppt(&$resource){
|
||||
function get_text_for_indexing_ppt(&$resource, $directfile = ''){
|
||||
global $CFG, $USER;
|
||||
|
||||
$indextext = null;
|
||||
|
||||
// SECURITY : do not allow non admin execute anything on system !!
|
||||
if (!isadmin($USER->id)) return;
|
||||
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
|
||||
|
||||
$text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
|
||||
if ($directfile == ''){
|
||||
$text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
|
||||
} else {
|
||||
$text = implode('', file("{$CFG->dataroot}/{$directfile}"));
|
||||
}
|
||||
|
||||
$remains = $text;
|
||||
$fragments = array();
|
||||
|
|
69
search/documents/physical_swf.php
Normal file
69
search/documents/physical_swf.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Global Search Engine for Moodle
|
||||
*
|
||||
* @package search
|
||||
* @category core
|
||||
* @subpackage document_wrappers
|
||||
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
|
||||
* @date 2008/03/31
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
*
|
||||
* @note : The Adobe SWF Converters library is not GPL, although it can be of free use in some
|
||||
* situations. This file is provided for convenience, but should use having a glance at
|
||||
* {@link http://www.adobe.com/licensing/developer/}
|
||||
*
|
||||
* this is a format handler for getting text out of a proprietary binary format
|
||||
* so it can be indexed by Lucene search engine
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param object $resource
|
||||
* @uses CFG, USER
|
||||
*/
|
||||
function get_text_for_indexing_swf(&$resource, $directfile = ''){
|
||||
global $CFG, $USER;
|
||||
|
||||
// SECURITY : do not allow non admin execute anything on system !!
|
||||
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
|
||||
|
||||
// adds moodle root switch if none was defined
|
||||
if (!isset($CFG->block_search_usemoodleroot)){
|
||||
set_config('block_search_usemoodleroot', 1);
|
||||
}
|
||||
|
||||
$moodleroot = ($CFG->block_search_usemoodleroot) ? "{$CFG->dirroot}/" : '' ;
|
||||
|
||||
// just call pdftotext over stdout and capture the output
|
||||
if (!empty($CFG->block_search_pdf_to_text_cmd)){
|
||||
if (!file_exists("{$moodleroot}{$command}")){
|
||||
mtrace('Error with swf to text converter command : executable not found as '.$moodleroot.$command);
|
||||
} else {
|
||||
if ($directfile == ''){
|
||||
$file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
|
||||
} else {
|
||||
$file = escapeshellarg("{$CFG->dataroot}/{$directfile}");
|
||||
}
|
||||
$command = trim($CFG->block_search_swf_to_text_cmd);
|
||||
$text_converter_cmd = "{$moodleroot}{$command} -t $file";
|
||||
$result = shell_exec($text_converter_cmd);
|
||||
|
||||
// result is in html. We must strip it off
|
||||
$result = preg_replace("/<[^>]*>/", '', $result);
|
||||
$result = preg_replace("/<!--[^>]*-->/", '', $result);
|
||||
$result = html_entity_decode($result, ENT_COMPAT, 'UTF-8');
|
||||
$result = mb_convert_encoding($result, 'UTF-8', 'auto');
|
||||
|
||||
if ($result){
|
||||
return $result;
|
||||
} else {
|
||||
mtrace('Error with swf to text converter command : execution failed for '.$text_converter_cmd.'. Check for execution permission on swf converter executable.');
|
||||
return '';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mtrace('Error with swf to text converter command : command not set up. Execute once search block configuration.');
|
||||
return '';
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -17,14 +17,19 @@
|
|||
* @param object $resource
|
||||
* @uses CFG, USER
|
||||
*/
|
||||
function get_text_for_indexing_txt(&$resource){
|
||||
function get_text_for_indexing_txt(&$resource, $directfile = ''){
|
||||
global $CFG, $USER;
|
||||
|
||||
// SECURITY : do not allow non admin execute anything on system !!
|
||||
if (!isadmin($USER->id)) return;
|
||||
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
|
||||
|
||||
// just try to get text empirically from ppt binary flow
|
||||
$text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
|
||||
if ($directfile == ''){
|
||||
$text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
|
||||
} else {
|
||||
$text = implode('', file("{$CFG->dataroot}/{$directfile}"));
|
||||
}
|
||||
|
||||
if (!empty($CFG->block_search_limit_index_body)){
|
||||
$text = shorten($text, $CFG->block_search_limit_index_body);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ function get_text_for_indexing_xml(&$resource, $directfile = ''){
|
|||
global $CFG, $USER;
|
||||
|
||||
// SECURITY : do not allow non admin execute anything on system !!
|
||||
if (!isadmin($USER->id)) return;
|
||||
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
|
||||
|
||||
// just get text
|
||||
if ($directfile == ''){
|
||||
|
|
|
@ -334,7 +334,7 @@ function user_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
|
|||
$userrecord = get_record('user', 'id', $this_id);
|
||||
|
||||
// we cannot see nothing from unconfirmed users
|
||||
if (!$userrecord->confirmed and !isadmin()){
|
||||
if (!$userrecord->confirmed and !has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))){
|
||||
if (!empty($CFG->search_access_debug)) echo "search reject : unconfirmed user ";
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue