From aa0959690cb6ac88e952a97d48140961961710a0 Mon Sep 17 00:00:00 2001 From: gregb_cc Date: Thu, 1 May 2003 23:12:05 +0000 Subject: [PATCH] fixed isadmin so that it checks once on each page view if the user is an admin fixed check_gd_version to properly identify bundled gd versions (old check_gd_version was returning 0 instead of 2 for bundled gd). --- lib/moodlelib.php | 62 +++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index eb667a14f9..dc3a52b97f 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -366,26 +366,32 @@ function reset_login_count() { $SESSION->logincount = 0; } - -function isadmin($userid=0) { +function isadmin($userid=false) { /// Is the user an admin? global $USER; + static $admins = array(); + static $nonadmins = array(); if (empty($USER->id)) { return false; } - if (empty($userid)) { - if (!empty($USER->admin)) { - return true; - } - return record_exists("user_admins", "userid", $USER->id); + $checkid = $userid ? $userid : $USER->id; + + if (in_array($checkid, $admins)) { + return true; + } elseif (in_array($ceckid, $nonadmins)) { + return false; + } elseif (record_exists("user_admins", "userid", $checkid)){ + $admins[] = $checkid; + return true; + } else { + $nonadmins[] = $checkid; + return false; } - return record_exists("user_admins", "userid", $userid); } - function isteacher($courseid, $userid=0) { /// Is the user a teacher or admin? global $USER; @@ -1193,26 +1199,34 @@ function can_use_richtext_editor() { function check_gd_version() { /// Hack to find out the GD version by parsing phpinfo output - ob_start(); - phpinfo(8); - $phpinfo = ob_get_contents(); - ob_end_clean(); + $gdversion = 0; - $phpinfo = explode("\n",$phpinfo); + if (function_exists('gd_info')){ + $gd_info = gd_info(); + /// THIS IS UGLY AND NEEDS TO BE IMPROVED + if($gd_info['GD Version'] == 'bundled (2.0 compatible)'){ + $gdversion = 2; + } + } else { + ob_start(); + phpinfo(8); + $phpinfo = ob_get_contents(); + ob_end_clean(); - $gdversion = 0; + $phpinfo = explode("\n",$phpinfo); - foreach ($phpinfo as $text) { - $parts = explode('',$text); - foreach ($parts as $key => $val) { - $parts[$key] = trim(strip_tags($val)); - } - if ($parts[0] == "GD Version") { - if (substr_count($parts[1], "2.0")) { - $parts[1] = "2.0"; + foreach ($phpinfo as $text) { + $parts = explode('',$text); + foreach ($parts as $key => $val) { + $parts[$key] = trim(strip_tags($val)); + } + if ($parts[0] == "GD Version") { + if (substr_count($parts[1], "2.0")) { + $parts[1] = "2.0"; + } + $gdversion = intval($parts[1]); } - $gdversion = intval($parts[1]); } } -- 2.39.5