Skip to content

Commit

Permalink
MDL-38654 do not test $CFG->gdversion
Browse files Browse the repository at this point in the history
GD PHP extension is now required. Add-ons need to remove $CFG->gdversion tests. The worst case regression is that add-on will think GD is not available.
  • Loading branch information
skodak committed Mar 22, 2013
1 parent 373a8e0 commit 689096b
Show file tree
Hide file tree
Showing 24 changed files with 101 additions and 147 deletions.
4 changes: 1 addition & 3 deletions admin/settings/server.php
Expand Up @@ -7,9 +7,7 @@

// "systempaths" settingpage
$temp = new admin_settingpage('systempaths', new lang_string('systempaths','admin'));
$temp->add(new admin_setting_configselect('gdversion', new lang_string('gdversion','admin'), new lang_string('configgdversion', 'admin'), check_gd_version(), array('0' => new lang_string('gdnot'),
'1' => new lang_string('gd1'),
'2' => new lang_string('gd2'))));

$temp->add(new admin_setting_configexecutable('pathtodu', new lang_string('pathtodu', 'admin'), new lang_string('configpathtodu', 'admin'), ''));
$temp->add(new admin_setting_configexecutable('aspellpath', new lang_string('aspellpath', 'admin'), new lang_string('edhelpaspellpath'), ''));
$temp->add(new admin_setting_configexecutable('pathtodot', new lang_string('pathtodot', 'admin'), new lang_string('pathtodot_help', 'admin'), ''));
Expand Down
10 changes: 4 additions & 6 deletions group/group_form.php
Expand Up @@ -67,13 +67,11 @@ function definition () {
$mform->addHelpButton('enrolmentkey', 'enrolmentkey', 'group');
$mform->setType('enrolmentkey', PARAM_RAW);

if (!empty($CFG->gdversion)) {
$options = array(get_string('no'), get_string('yes'));
$mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);
$options = array(get_string('no'), get_string('yes'));
$mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);

$mform->addElement('filepicker', 'imagefile', get_string('newpicture', 'group'));
$mform->addHelpButton('imagefile', 'newpicture', 'group');
}
$mform->addElement('filepicker', 'imagefile', get_string('newpicture', 'group'));
$mform->addHelpButton('imagefile', 'newpicture', 'group');

$mform->addElement('hidden','id');
$mform->setType('id', PARAM_INT);
Expand Down
24 changes: 11 additions & 13 deletions group/lib.php
Expand Up @@ -324,20 +324,18 @@ function groups_update_group_icon($group, $data, $editform) {
$context = context_course::instance($group->courseid, MUST_EXIST);

//TODO: it would make sense to allow picture deleting too (skodak)
if (!empty($CFG->gdversion)) {
if ($iconfile = $editform->save_temp_file('imagefile')) {
if (process_new_icon($context, 'group', 'icon', $group->id, $iconfile)) {
$DB->set_field('groups', 'picture', 1, array('id'=>$group->id));
$group->picture = 1;
} else {
$fs->delete_area_files($context->id, 'group', 'icon', $group->id);
$DB->set_field('groups', 'picture', 0, array('id'=>$group->id));
$group->picture = 0;
}
@unlink($iconfile);
// Invalidate the group data as we've updated the group record.
cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($group->courseid));
if ($iconfile = $editform->save_temp_file('imagefile')) {
if (process_new_icon($context, 'group', 'icon', $group->id, $iconfile)) {
$DB->set_field('groups', 'picture', 1, array('id'=>$group->id));
$group->picture = 1;
} else {
$fs->delete_area_files($context->id, 'group', 'icon', $group->id);
$DB->set_field('groups', 'picture', 0, array('id'=>$group->id));
$group->picture = 0;
}
@unlink($iconfile);
// Invalidate the group data as we've updated the group record.
cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($group->courseid));
}
}

Expand Down
2 changes: 0 additions & 2 deletions lang/en/admin.php
Expand Up @@ -224,7 +224,6 @@
$string['configfrontpage'] = 'The items selected above will be displayed on the site\'s front page.';
$string['configfrontpageloggedin'] = 'The items selected above will be displayed on the site\'s front page when a user is logged in.';
$string['configfullnamedisplay'] = 'This defines how names are shown when they are displayed in full. For most mono-lingual sites the most efficient setting is "First name + Surname", but you may choose to hide surnames altogether, or to leave it up to the current language pack to decide (some languages have different conventions).';
$string['configgdversion'] = 'Indicate the version of GD that is installed. The version shown by default is the one that has been auto-detected. Don\'t change this unless you really know what you\'re doing.';
$string['configgeoipfile'] = 'Location of GeoIP City binary data file. This file is not part of Moodle distribution and must be obtained separately from <a href="http://www.maxmind.com/">MaxMind</a>. You can either buy a commercial version or use the free version.<br />Simply download <a href="http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz" >http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz</a> and extract it into "{$a}" directory on your server.';
$string['configgetremoteaddrconf'] = 'If your server is behind a reverse proxy, you can use this setting to specify which HTTP headers can be trusted to contain the remote IP address. The headers are read in order, using the first one that is available.';
$string['configgradebookroles'] = 'This setting allows you to control who appears on the gradebook. Users need to have at least one of these roles in a course to be shown in the gradebook for that course.';
Expand Down Expand Up @@ -546,7 +545,6 @@
$string['frontpagesettings'] = 'Front page settings';
$string['fullnamedisplay'] = 'Full name format';
$string['gdrecommended'] = 'GD extension is used for conversion of images, some features such as user profile images will not be available if missing.';
$string['gdversion'] = 'GD version';
$string['generalsettings'] = 'General settings';
$string['geoipfile'] = 'GeoIP city data file';
$string['getremoteaddrconf'] = 'Logged IP address source';
Expand Down
12 changes: 0 additions & 12 deletions lang/en/install.php
Expand Up @@ -226,18 +226,6 @@
<p>To enable file uploading you (or your system administrator) will need to
edit the main php.ini file on your system and change the setting for
<b>file_uploads</b> to \'1\'.</p>';
$string['gdversion'] = 'GD version';
$string['gdversionerror'] = 'The GD library should be present to process and create images';
$string['gdversionhelp'] = '<p>Your server does not seem to have GD installed.</p>
<p>GD is a library that is required by PHP to allow Moodle to process images
(such as the user profile icons) and to create new images (such as
the log graphs). Moodle will still work without GD - these features
will just not be available to you.</p>
<p>To add GD to PHP under Unix, compile PHP using the --with-gd parameter.</p>
<p>Under Windows you can usually edit php.ini and uncomment the line referencing php_gd2.dll.</p>';
$string['globalsquotes'] = 'Insecure handling of globals';
$string['globalsquoteserror'] = 'Fix your PHP settings: disable register_globals and/or enable magic_quotes_gpc';
$string['globalsquoteshelp'] = '<p>Combination of disabled magic quotes GPC and enabled register globals both at the same time is not recommended.</p>
Expand Down
4 changes: 0 additions & 4 deletions lang/en/moodle.php
Expand Up @@ -731,10 +731,6 @@
$string['fullprofile'] = 'Full profile';
$string['fullsitename'] = 'Full site name';
$string['functiondisabled'] = 'That functionality is currently disabled';
$string['gdneed'] = 'GD must be installed to see this graph';
$string['gdnot'] = 'GD is not installed';
$string['gd1'] = 'GD 1.x is installed';
$string['gd2'] = 'GD 2.x is installed';
$string['general'] = 'General';
$string['geolocation'] = 'latitude - longitude';
$string['gettheselogs'] = 'Get these logs';
Expand Down
7 changes: 7 additions & 0 deletions lib/db/upgrade.php
Expand Up @@ -1756,5 +1756,12 @@ function xmldb_main_upgrade($oldversion) {
// No savepoint needed for this change.
}

if ($oldversion < 2013032200.01) {
// GD is now always available
unset_config('gdversion');

upgrade_main_savepoint(true, 2013032200.01);
}

return true;
}
45 changes: 45 additions & 0 deletions lib/deprecatedlib.php
Expand Up @@ -30,6 +30,51 @@

defined('MOODLE_INTERNAL') || die();

/**
* Hack to find out the GD version by parsing phpinfo output
*
* @return int GD version (1, 2, or 0)
*/
function check_gd_version() {
// TODO: delete function in Moodle 2.7
debugging('check_gd_version() is deprecated, GD extension is always available now');

$gdversion = 0;

if (function_exists('gd_info')){
$gd_info = gd_info();
if (substr_count($gd_info['GD Version'], '2.')) {
$gdversion = 2;
} else if (substr_count($gd_info['GD Version'], '1.')) {
$gdversion = 1;
}

} else {
ob_start();
phpinfo(INFO_MODULES);
$phpinfo = ob_get_contents();
ob_end_clean();

$phpinfo = explode("\n", $phpinfo);


foreach ($phpinfo as $text) {
$parts = explode('</td>', $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]);
}
}
}

return $gdversion; // 1, 2 or 0
}

/**
* Not used any more, the account lockout handling is now
* part of authenticate_user_login().
Expand Down
4 changes: 0 additions & 4 deletions lib/filestorage/tests/file_storage_test.php
Expand Up @@ -67,10 +67,6 @@ public function test_create_file_from_pathname() {
public function test_get_file_preview(stored_file $file) {
global $CFG;

if (empty($CFG->gdversion)) {
$this->markTestSkipped('GD extension is disabled');
}

$this->resetAfterTest(true);
$fs = get_file_storage();

Expand Down
12 changes: 4 additions & 8 deletions lib/gdlib.php
Expand Up @@ -48,7 +48,7 @@
function imagecopybicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) {
global $CFG;

if (function_exists('imagecopyresampled') and $CFG->gdversion >= 2) {
if (function_exists('imagecopyresampled')) {
return imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y,
$dst_w, $dst_h, $src_w, $src_h);
}
Expand Down Expand Up @@ -100,10 +100,6 @@ function imagecopybicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $d
function process_new_icon($context, $component, $filearea, $itemid, $originalfile) {
global $CFG;

if (empty($CFG->gdversion)) {
return false;
}

if (!is_file($originalfile)) {
return false;
}
Expand Down Expand Up @@ -169,7 +165,7 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil
return false;
}

if (function_exists('imagecreatetruecolor') and $CFG->gdversion >= 2) {
if (function_exists('imagecreatetruecolor')) {
$im1 = imagecreatetruecolor(100, 100);
$im2 = imagecreatetruecolor(35, 35);
$im3 = imagecreatetruecolor(512, 512);
Expand Down Expand Up @@ -274,7 +270,7 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil
function generate_image_thumbnail($filepath, $width, $height) {
global $CFG;

if (empty($CFG->gdversion) or empty($filepath) or empty($width) or empty($height)) {
if (empty($filepath) or empty($width) or empty($height)) {
return false;
}

Expand Down Expand Up @@ -306,7 +302,7 @@ function generate_image_thumbnail($filepath, $width, $height) {
return false;
}

if (function_exists('imagecreatetruecolor') and $CFG->gdversion >= 2) {
if (function_exists('imagecreatetruecolor')) {
$thumbnail = imagecreatetruecolor($width, $height);
if ($imagefnc === 'imagepng') {
imagealphablending($thumbnail, false);
Expand Down
42 changes: 0 additions & 42 deletions lib/moodlelib.php
Expand Up @@ -9081,48 +9081,6 @@ function can_use_rotated_text() {
check_browser_version('Opera', 12) || check_browser_version('Safari iOS', 533);
}

/**
* Hack to find out the GD version by parsing phpinfo output
*
* @return int GD version (1, 2, or 0)
*/
function check_gd_version() {
$gdversion = 0;

if (function_exists('gd_info')){
$gd_info = gd_info();
if (substr_count($gd_info['GD Version'], '2.')) {
$gdversion = 2;
} else if (substr_count($gd_info['GD Version'], '1.')) {
$gdversion = 1;
}

} else {
ob_start();
phpinfo(INFO_MODULES);
$phpinfo = ob_get_contents();
ob_end_clean();

$phpinfo = explode("\n", $phpinfo);


foreach ($phpinfo as $text) {
$parts = explode('</td>', $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]);
}
}
}

return $gdversion; // 1, 2 or 0
}

/**
* Determine if moodle installation requires update
*
Expand Down
1 change: 1 addition & 0 deletions lib/upgrade.txt
Expand Up @@ -34,6 +34,7 @@ information provided here is intended especially for developers.
* condition_info:get_condition_user_fields($formatoptions) now accepts the optional
param $formatoptions, that will determine if the field names are processed by
format_string() with the passed options.
* remove all references to $CFG->gdversion, GD PHP extension is now required

YUI changes:
* M.util.help_icon has been deprecated. Code should be updated to use moodle-core-popuphelp
Expand Down
6 changes: 1 addition & 5 deletions mod/quiz/renderer.php
Expand Up @@ -1166,11 +1166,7 @@ public function quiz_attempt_summary_link_to_reports($quiz, $cm, $context,
public function graph(moodle_url $url, $title) {
global $CFG;

if (empty($CFG->gdversion)) {
$graph = get_string('gdneed');
} else {
$graph = html_writer::empty_tag('img', array('src' => $url, 'alt' => $title));
}
$graph = html_writer::empty_tag('img', array('src' => $url, 'alt' => $title));

return $this->heading($title) . html_writer::tag('div', $graph, array('class' => 'graph'));
}
Expand Down
9 changes: 2 additions & 7 deletions mod/survey/lib.php
Expand Up @@ -665,13 +665,8 @@ function survey_question_rowclass($qnum) {
function survey_print_graph($url) {
global $CFG, $SURVEY_GHEIGHT, $SURVEY_GWIDTH;

if (empty($CFG->gdversion)) {
echo "(".get_string("gdneed").")";

} else {
echo "<img class='resultgraph' height=\"$SURVEY_GHEIGHT\" width=\"$SURVEY_GWIDTH\"".
" src=\"$CFG->wwwroot/mod/survey/graph.php?$url\" alt=\"".get_string("surveygraph", "survey")."\" />";
}
echo "<img class='resultgraph' height=\"$SURVEY_GHEIGHT\" width=\"$SURVEY_GWIDTH\"".
" src=\"$CFG->wwwroot/mod/survey/graph.php?$url\" alt=\"".get_string("surveygraph", "survey")."\" />";
}

/**
Expand Down
6 changes: 1 addition & 5 deletions report/courseoverview/index.php
Expand Up @@ -113,11 +113,7 @@
echo '</td></tr></table>';

} else {
if (empty($CFG->gdversion)) {
echo '<div class="graph">(' . get_string("gdneed") .')</div>';
} else {
echo '<div class="graph"><img alt="'.get_string('courseoverviewgraph').'" src="'.$CFG->wwwroot.'/report/courseoverview/reportsgraph.php?time='.$time.'&report='.$report.'&numcourses='.$numcourses.'" /></div>';
}
echo '<div class="graph"><img alt="'.get_string('courseoverviewgraph').'" src="'.$CFG->wwwroot.'/report/courseoverview/reportsgraph.php?time='.$time.'&report='.$report.'&numcourses='.$numcourses.'" /></div>';

$table = new html_table();
$table->align = array('left','center','center','center');
Expand Down
8 changes: 2 additions & 6 deletions report/log/locallib.php
Expand Up @@ -45,12 +45,8 @@
function report_log_print_graph($course, $userid, $type, $date=0) {
global $CFG;

if (empty($CFG->gdversion)) {
echo "(".get_string("gdneed").")";
} else {
echo '<img src="'.$CFG->wwwroot.'/report/log/graph.php?id='.$course->id.
'&amp;user='.$userid.'&amp;type='.$type.'&amp;date='.$date.'" alt="" />';
}
echo '<img src="'.$CFG->wwwroot.'/report/log/graph.php?id='.$course->id.
'&amp;user='.$userid.'&amp;type='.$type.'&amp;date='.$date.'" alt="" />';
}
/**
* This function is used to generate and display Mnet selector form
Expand Down
10 changes: 3 additions & 7 deletions report/stats/locallib.php
Expand Up @@ -201,14 +201,10 @@ function report_stats_report($course, $report, $mode, $user, $roleid, $time) {
.((!empty($roleid)) ? ' '.$DB->get_field('role','name', array('id'=>$roleid)) : ''));


if (empty($CFG->gdversion)) {
echo "(".get_string("gdneed").")";
if ($mode == STATS_MODE_DETAILED) {
echo '<div class="graph"><img src="'.$CFG->wwwroot.'/report/stats/graph.php?mode='.$mode.'&amp;course='.$course->id.'&amp;time='.$time.'&amp;report='.$report.'&amp;userid='.$userid.'" alt="'.get_string('statisticsgraph').'" /></div>';
} else {
if ($mode == STATS_MODE_DETAILED) {
echo '<div class="graph"><img src="'.$CFG->wwwroot.'/report/stats/graph.php?mode='.$mode.'&amp;course='.$course->id.'&amp;time='.$time.'&amp;report='.$report.'&amp;userid='.$userid.'" alt="'.get_string('statisticsgraph').'" /></div>';
} else {
echo '<div class="graph"><img src="'.$CFG->wwwroot.'/report/stats/graph.php?mode='.$mode.'&amp;course='.$course->id.'&amp;time='.$time.'&amp;report='.$report.'&amp;roleid='.$roleid.'" alt="'.get_string('statisticsgraph').'" /></div>';
}
echo '<div class="graph"><img src="'.$CFG->wwwroot.'/report/stats/graph.php?mode='.$mode.'&amp;course='.$course->id.'&amp;time='.$time.'&amp;report='.$report.'&amp;roleid='.$roleid.'" alt="'.get_string('statisticsgraph').'" /></div>';
}

$table = new html_table();
Expand Down
4 changes: 1 addition & 3 deletions report/stats/user.php
Expand Up @@ -113,9 +113,7 @@
print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
}

if (!empty($CFG->gdversion)) {
echo '<center><img src="'.$CFG->wwwroot.'/report/stats/graph.php?mode='.STATS_MODE_DETAILED.'&course='.$course->id.'&time='.$time.'&report='.STATS_REPORT_USER_VIEW.'&userid='.$user->id.'" alt="'.get_string('statisticsgraph').'" /></center>';
}
echo '<center><img src="'.$CFG->wwwroot.'/report/stats/graph.php?mode='.STATS_MODE_DETAILED.'&course='.$course->id.'&time='.$time.'&report='.STATS_REPORT_USER_VIEW.'&userid='.$user->id.'" alt="'.get_string('statisticsgraph').'" /></center>';

// What the heck is this about? -- MD
$stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3)));
Expand Down
2 changes: 1 addition & 1 deletion user/edit.php
Expand Up @@ -224,7 +224,7 @@
}

//update user picture
if (!empty($CFG->gdversion) and empty($CFG->disableuserimages)) {
if (empty($CFG->disableuserimages)) {
useredit_update_picture($usernew, $userform, $filemanageroptions);
}

Expand Down

0 comments on commit 689096b

Please sign in to comment.