From d1f582d99c50e8d5622329c76716ab46a54109ef Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Wed, 29 Feb 2012 08:44:34 +0100 Subject: [PATCH] MDL-31079 detect js and css minimisation failures --- lib/csslib.php | 31 +++++++++++++++++++++++++++++-- lib/javascript.php | 25 +++++++++++++++++++++++-- theme/javascript.php | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 82 insertions(+), 6 deletions(-) diff --git a/lib/csslib.php b/lib/csslib.php index 379ce16bd70..0995948714d 100644 --- a/lib/csslib.php +++ b/lib/csslib.php @@ -198,6 +198,10 @@ function css_send_css_not_found() { function css_minify_css($files) { global $CFG; + if (empty($files)) { + return ''; + } + set_include_path($CFG->libdir . '/minify/lib' . PATH_SEPARATOR . get_include_path()); require_once('Minify.php'); @@ -220,8 +224,31 @@ function css_minify_css($files) { // This returns the CSS rather than echoing it for display 'quiet' => true ); - $result = Minify::serve('Files', $options); - return $result['content']; + + $error = 'unknown'; + try { + $result = Minify::serve('Files', $options); + if ($result['success']) { + return $result['content']; + } + } catch (Exception $e) { + $error = $e->getMessage(); + $error = str_replace("\r", ' ', $error); + $error = str_replace("\n", ' ', $error); + } + + // minification failed - try to inform the theme developer and include the non-minified version + $css = << $files ); - Minify::serve('Files', $options); - die(); + try { + Minify::serve('Files', $options); + die(); + } catch (Exception $e) { + $error = $e->getMessage(); + $error = str_replace("\r", ' ', $error); + $error = str_replace("\n", ' ', $error); + } + + // minification failed - try to inform the developer and include the non-minified version + $js = << true ); - $result = Minify::serve('Files', $options); - return $result['content']; + $error = 'unknown'; + try { + $result = Minify::serve('Files', $options); + if ($result['success']) { + return $result['content']; + } + } catch (Exception $e) { + $error = $e->getMessage(); + $error = str_replace("\r", ' ', $error); + $error = str_replace("\n", ' ', $error); + } + + // minification failed - try to inform the theme developer and include the non-minified version + $js = <<