Skip to content

Commit

Permalink
MDL-21188 removing support for yui pix folders in themes because it i…
Browse files Browse the repository at this point in the history
…s not compatible with autoloading in YUI3 and also loading of any YUI from external sites through combo scripts
  • Loading branch information
skodak committed Dec 25, 2009
1 parent 4c90714 commit 9b2735f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 48 deletions.
4 changes: 3 additions & 1 deletion lib/ajax/ajaxlib.php
Expand Up @@ -133,6 +133,8 @@ public function __construct() {

// This file helps to minimise number of http requests
//$this->yui3loader->comboBase = $CFG->httpswwwroot . '/theme/yuicomboloader.php?';

$this->yui3loader->load('cssreset', 'cssbase', 'cssfonts', 'cssgrids');
}

/**
Expand Down Expand Up @@ -463,7 +465,7 @@ protected function get_javascript_code($when, $indent = '') {
* @return string
*/
protected function get_yui3lib_code() {
return $this->yui3loader->script();
return $this->yui3loader->css().$this->yui3loader->script();
}

/**
Expand Down
52 changes: 10 additions & 42 deletions lib/outputlib.php
Expand Up @@ -591,7 +591,7 @@ public function css_urls() {
$css = $this->css_content();
$url = $CFG->httpswwwroot.'/theme/styles_debug.php';
$urls = array();
$urls[] = new moodle_url($url, array('theme'=>$this->name,'type'=>'yui'));
$urls[] = new moodle_url($url, array('theme'=>$this->name,'type'=>'yui2'));
foreach ($css['plugins'] as $plugin=>$unused) {
$urls[] = new moodle_url($url, array('theme'=>$this->name,'type'=>'plugin', 'subtype'=>$plugin));
}
Expand All @@ -614,16 +614,10 @@ public function css_urls() {
public function css_content() {
global $CFG;

$css = array('yui'=>array(), 'plugins'=>array(), 'parents'=>array(), 'theme'=>array());
$css = array('yui2'=>array(), 'plugins'=>array(), 'parents'=>array(), 'theme'=>array());

//YUI sheets
$yui_sheets = "/*** YUI3 reset sheets and grids ***/\n\n";
$yui_sheets .= file_get_contents("$CFG->libdir/yui/$CFG->yui3version/cssreset/reset-min.css");
$yui_sheets .= file_get_contents("$CFG->libdir/yui/$CFG->yui3version/cssbase/base-min.css");
$yui_sheets .= file_get_contents("$CFG->libdir/yui/$CFG->yui3version/cssfonts/fonts-min.css");
$yui_sheets .= file_get_contents("$CFG->libdir/yui/$CFG->yui3version/cssgrids/grids-min.css");

$yui_sheets .= "\n\n/*** Standard YUI2 sheets ***/\n\n";
// legacy YUI2 stylesheets, YUI3 stylesheets are loaded on the fly
$yui2_sheets = "\n\n/*** Standard YUI2 sheets ***/\n\n";
$items = new DirectoryIterator("$CFG->libdir/yui/$CFG->yui2version/assets/skins/sam");
foreach ($items as $item) {
if ($item->isDot() or !$item->isFile()) {
Expand All @@ -633,28 +627,13 @@ public function css_content() {
if (substr($filename, -4) !== '.css') {
continue;
}
$yui_sheets .= file_get_contents("$CFG->libdir/yui/$CFG->yui2version/assets/skins/sam/$filename");
$yui2_sheets .= file_get_contents("$CFG->libdir/yui/$CFG->yui2version/assets/skins/sam/$filename");
}
unset($item);
unset($items);

$yui_sheets .= "\n\n/*** Standard YUI3 sheets ***/\n\n";
$items = new DirectoryIterator("$CFG->libdir/yui/$CFG->yui3version/assets/skins/sam");
foreach ($items as $item) {
if ($item->isDot() or !$item->isFile()) {
continue;
}
$filename = $item->getFilename();
if (substr($filename, -4) !== '.css') {
continue;
}
$yui_sheets .= file_get_contents("$CFG->libdir/yui/$CFG->yui3version/assets/skins/sam/$filename");
}
unset($item);
unset($items);

$yui_sheets = preg_replace('/([a-z-]+)\.(png|gif)/', '[[pix:yui|$1]]', $yui_sheets);
$css['yui'][] = $this->post_process($yui_sheets);
$yui2_sheets = preg_replace('/([a-z-]+)\.(png|gif)/', '[[pix:yui2|$1]]', $yui2_sheets);
$css['yui2'][] = $this->post_process($yui2_sheets);

// get all plugin sheets
$excludes = null;
Expand Down Expand Up @@ -898,20 +877,9 @@ public function resolve_image_location($image, $component) {
}
return null;

} else if ($component === 'yui') {
// yui CSS files are parsed automatically and altered on the fly
if ($imagefile = $this->image_exists("$this->dir/pix_yui/$image")) {
return $imagefile;
}
foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last
if ($imagefile = $this->image_exists("$parent_config->dir/pix_yui/$image")) {
return $imagefile;
}
}
if ($imagefile = $this->image_exists("$CFG->libdir/yui/$CFG->yui3version/assets/skins/sam/$image")) {
// YUI3 takes precedence
return $imagefile;
}
} else if ($component === 'yui2') {
// YUI2 is here for legacy reasons only, YUI3 images are not handled here
// yui images need to be overriden with CSS using proper selectors
if ($imagefile = $this->image_exists("$CFG->libdir/yui/$CFG->yui2version/assets/skins/sam/$image")) {
return $imagefile;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/outputrenderers.php
Expand Up @@ -362,7 +362,7 @@ public function standard_head_html() {
// any other custom CSS can not be overridden via themes and is highly discouraged
$urls = $this->page->theme->css_urls();
foreach ($urls as $url) {
$output .= '<link rel="stylesheet" type="text/css" href="' . $url->out() . '" />' . "\n";
$this->page->requires->css($url->out(), true);
}

// Get the theme javascript
Expand Down
4 changes: 2 additions & 2 deletions theme/styles.php
Expand Up @@ -32,7 +32,7 @@
$type = min_optional_param('type', 'all', 'SAFEDIR');
$rev = min_optional_param('rev', 0, 'INT');

if (!in_array($type, array('all', 'ie', 'editor', 'yui', 'plugins', 'parents', 'theme'))) {
if (!in_array($type, array('all', 'ie', 'editor', 'yui2', 'plugins', 'parents', 'theme'))) {
header('HTTP/1.0 404 not found');
die('Theme was not found, sorry.');
}
Expand Down Expand Up @@ -116,7 +116,7 @@ function send_ie_css($themename, $rev) {

$css = <<<EOF
/** Unfortunately IE6/7 does not support more than 4096 selectors in one CSS file, which means we have to use some ugly hacks :-( **/
@import url(styles.php?theme=$themename&rev=$rev&type=yui);
@import url(styles.php?theme=$themename&rev=$rev&type=yui2);
@import url(styles.php?theme=$themename&rev=$rev&type=plugins);
@import url(styles.php?theme=$themename&rev=$rev&type=parents);
@import url(styles.php?theme=$themename&rev=$rev&type=theme);
Expand Down
4 changes: 2 additions & 2 deletions theme/styles_debug.php
Expand Up @@ -56,8 +56,8 @@

$css = $theme->css_content();

if ($type === 'yui') {
send_uncached_css(reset($css['yui']));
if ($type === 'yui2') {
send_uncached_css(reset($css['yui2']));

} else if ($type === 'plugin') {
if (isset($css['plugins'][$subtype])) {
Expand Down

0 comments on commit 9b2735f

Please sign in to comment.