Skip to content

Commit

Permalink
MDL-14978 removed obsoleted isadmin()
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed May 25, 2008
1 parent 72f563b commit e3c7f15
Show file tree
Hide file tree
Showing 23 changed files with 430 additions and 261 deletions.
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
}
}
} else { // if upgrading from 1.6 or below
if (isadmin() && moodle_needs_upgrading()) {
if (is_siteadmin() && moodle_needs_upgrading()) {
redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ function has_any_capability($capabilities, $context, $userid=NULL, $doanything=t
* - moodle/site:doanything
*
* @param int $userid
* @returns bool $isadmin
* @returns bool true is user can administer server settings
*/
function is_siteadmin($userid) {
global $CFG, $DB;
Expand All @@ -532,8 +532,7 @@ function is_siteadmin($userid) {
HAVING SUM(rc.permission) > 0";
$params = array($userid, 'moodle/site:config', 'moodle/legacy:admin', 'moodle/site:doanything');

$isadmin = $DB->record_exists_sql($sql, $params);
return $isadmin;
return $DB->record_exists_sql($sql, $params);
}

function get_course_from_path ($path) {
Expand Down
32 changes: 0 additions & 32 deletions lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,6 @@
* @package moodlecore
*/


/**
* Determines if a user an admin
*
* @uses $USER
* @param int $userid The id of the user as is found in the 'user' table
* @staticvar array $admins List of users who have been found to be admins by user id
* @staticvar array $nonadmins List of users who have been found not to be admins by user id
* @return bool
*/
function isadmin($userid=0) {
global $USER, $CFG;

if (empty($CFG->rolesactive)) { // Then the user is likely to be upgrading NOW
if (!$userid) {
if (empty($USER->id)) {
return false;
}
if (!empty($USER->admin)) {
return true;
}
$userid = $USER->id;
}

return record_exists('user_admins', 'userid', $userid);
}

$context = get_context_instance(CONTEXT_SYSTEM);

return has_capability('moodle/legacy:admin', $context, $userid, false);
}

/**
* Determines if a user is a teacher (or better)
*
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ function feedback_get_groupid($course, $cm) {
$groupmode = groupmode($course, $cm);
//get groupid
if($groupmode > 0 && !isadmin()) {
if($groupmode > 0 && !has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
if($mygroupid = mygroupid($course->id)) {
return $mygroupid[0]; //get the first groupid
}
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/show_entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
//get students in conjunction with groupmode
if($groupmode > 0) {
if($SESSION->feedback->lstgroupid == -2) {
if(isadmin()) {
if(has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
$mygroupid = false;
$SESSION->feedback->lstgroupid = false;
}else{
Expand Down
2 changes: 1 addition & 1 deletion search/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
error(get_string('globalsearchdisabled', 'search'));
}

if (!isadmin()) {
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php");
}

Expand Down
2 changes: 1 addition & 1 deletion search/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
error(get_string('globalsearchdisabled', 'search'));
}

if (!isadmin()) {
if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
error(get_string('beadmin', 'search'), "$CFG->wwwroot/login/index.php");
} //if

Expand Down
6 changes: 4 additions & 2 deletions search/documents/forum_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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');
}

?>
21 changes: 11 additions & 10 deletions search/documents/physical_doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,39 @@
* @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}/" : '' ;

// 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.');
}
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);
}
mtrace("Executing : $text_converter_cmd");
$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 '';
}
Expand Down
12 changes: 8 additions & 4 deletions search/documents/physical_htm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand All @@ -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
Expand Down
21 changes: 11 additions & 10 deletions search/documents/physical_pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand All @@ -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 '';
}
Expand Down
10 changes: 7 additions & 3 deletions search/documents/physical_ppt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
69 changes: 69 additions & 0 deletions search/documents/physical_swf.php
Original file line number Diff line number Diff line change
@@ -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 '';
}
}
?>
11 changes: 8 additions & 3 deletions search/documents/physical_txt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion search/documents/physical_xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ''){
Expand Down
2 changes: 1 addition & 1 deletion search/documents/user_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit e3c7f15

Please sign in to comment.