From b958e941229585e9a08581dd5852b1a55febdfbd Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Thu, 24 Jul 2008 13:37:05 +0000 Subject: [PATCH] MDL-14731 Improved Bryce's patch and applied. YUI version number is kept in a simple version.php file, to be updated manually when updating the YUI libraries. --- admin/settings/appearance.php | 1 + lang/en_utf8/admin.php | 2 ++ lib/ajax/ajaxlib.php | 21 +++++++++++++++++---- lib/yui/version.php | 3 +++ version.php | 2 +- 5 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 lib/yui/version.php diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 041230844c..436157e013 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -95,6 +95,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $temp = new admin_settingpage('ajax', get_string('ajaxuse')); $temp->add(new admin_setting_configcheckbox('enableajax', get_string('enableajax', 'admin'), get_string('configenableajax', 'admin'), 1)); + $temp->add(new admin_setting_configcheckbox('useexternalyui', get_string('useexternalyui', 'admin'), get_string('configuseexternalyui', 'admin'), 1)); $temp->add(new admin_setting_configcheckbox('disablecourseajax', get_string('disablecourseajax', 'admin'), get_string('configdisablecourseajax', 'admin'), isset($CFG->disablecourseajax) ? 1 : empty($CFG->enableajax))); $ADMIN->add('appearance', $temp); diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 081d3ab642..f6bfa2fb1f 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -242,6 +242,7 @@ $string['configthemelist'] = 'Leave this blank to allow any valid theme to be us For example: standard,orangewhite.'; $string['configtimezone'] = 'You can set the default timezone here. This is the only the DEFAULT timezone for displaying dates - each user can override this by setting their own in their profile. \"Server time\" here will make Moodle default to the server\'s operating system setting, but \"Server time\" in the user profile will make the user default to this timezone setting. Cronjobs that depend on a time of day to run will use this timezone.'; $string['configunzip'] = 'Indicate the location of your unzip program (Unix only, optional). If specified, this will be used to unpack zip archives on the server. If you leave this blank, then Moodle will use internal routines.'; +$string['configuseexternalyui'] = 'Instead of using local files, use online files available on Yahoo‘s servers.'; $string['configusetags'] = 'Should tags functionality across the site be enabled?'; $string['configvariables'] = 'Variables'; $string['configwarning'] = 'Be careful modifying these settings - strange values could cause problems.'; @@ -732,6 +733,7 @@ $string['upgradinglogs'] = 'Upgrading logs'; $string['uploaduserspreview'] = 'Upload users preview'; $string['uploadusersresult'] = 'Upload users results'; $string['upwards'] = 'upwards'; +$string['useexternalyui'] = 'Use online YUI libraries'; $string['usehtmleditor'] = 'Use HTML editor'; $string['useraccountupdated'] = 'User updated'; $string['userbulk'] = 'Bulk user actions'; diff --git a/lib/ajax/ajaxlib.php b/lib/ajax/ajaxlib.php index f7109f3dd0..0636b82e2a 100644 --- a/lib/ajax/ajaxlib.php +++ b/lib/ajax/ajaxlib.php @@ -12,6 +12,7 @@ function ajax_get_lib($libname) { global $CFG; $libpath = ''; + $external_yui = false; $translatelist = array( 'yui_yahoo' => '/lib/yui/yahoo/yahoo-min.js', @@ -58,14 +59,26 @@ function ajax_get_lib($libname) { ); if (array_key_exists($libname, $translatelist)) { - $libpath = $CFG->wwwroot . $translatelist[$libname]; + // If this is a YUI file and we are using external libraries + if (substr($libname, 0, 3) == 'yui' && $CFG->useexternalyui) { + $external_yui = true; + // Get current version + include($CFG->libdir.'/yui/version.php'); + $libpath = 'http://yui.yahooapis.com/'.$yuiversion.'/build/'.substr($translatelist[$libname], 9); + } else { + $libpath = $CFG->wwwroot . $translatelist[$libname]; + } + } else { $libpath = $libname; } - $testpath = str_replace($CFG->wwwroot, $CFG->dirroot, $libpath); - if (!file_exists($testpath)) { - print_error('require_js: '.$libpath.' - file not found.'); + // Make sure the file exists if it is local. + if ($external_yui === false) { + $testpath = str_replace($CFG->wwwroot, $CFG->dirroot, $libpath); + if (!file_exists($testpath)) { + error('require_js: '.$libpath.' - file not found.'); + } } return $libpath; diff --git a/lib/yui/version.php b/lib/yui/version.php new file mode 100644 index 0000000000..3e962a2432 --- /dev/null +++ b/lib/yui/version.php @@ -0,0 +1,3 @@ + diff --git a/version.php b/version.php index 792ceb80fb..60227c57a3 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2008072401; // YYYYMMDD = date of the last version bump + $version = 2008072402; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20080724)'; // Human-friendly version name -- 2.39.5