summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThilo Wawrzik2007-06-01 22:13:14 (GMT)
committer Thilo Wawrzik2007-06-01 22:13:14 (GMT)
commit74ec36fa7270ba46a9918cf80bc389364fb980a4 (patch)
tree7ee12d321c187bc12291690b71c8a150d2450390
parent4e843f55b2e5800fe034bc26f1a7b7cef8f9a336 (diff)
- bugfix: @import rules are incorrect (#148061)
-rw-r--r--gallery_base.inc40
1 files changed, 36 insertions, 4 deletions
diff --git a/gallery_base.inc b/gallery_base.inc
index d4f28ba..ff76ba2 100644
--- a/gallery_base.inc
+++ b/gallery_base.inc
@@ -277,11 +277,28 @@ function gallery_set_head($html, $settitle = FALSE) {
* Implementation of gallery_set_css
*/
function gallery_set_css($css) {
+ global $base_url;
+ static $css_memory = array();
+
if (count($css)) {
- $css = preg_replace('/<link(.*?)href="([^"]*)"([^\/]*)\/>/i', '${2}', $css);
+ $css = preg_replace('/<link(.*?)href="([^"]*)"(.*?)\/>/i', '${2}', $css);
+ $css = preg_replace(array('#^'. $base_url .'#', '#^'. base_path() .'#', '#^/#'), '', $css);
foreach ($css as $include) {
- // Gallery's CSS will always be added first, what allows overriding in the module(s)
- drupal_add_css(substr($include, strlen(base_path())), 'module', 'all', FALSE);
+ if (!in_array(($md5 = md5($include)), $css_memory)) {
+ $css_memory[] = $md5;
+ if (substr($include, 0, 6) == '<style') {
+ // drupal_add_css() does not support inline styles
+ drupal_set_html_head($include);
+ }
+ elseif (substr($include, 0, 4) == 'http') {
+ // drupal_add_css() does not support external paths
+ drupal_set_html_head('<style type="text/css" media="all">@import "'. $include .'";</style>' ."\n");
+ }
+ else {
+ // Gallery's css must always be added first to allow overriding from the module(s)
+ drupal_add_css($include, 'module', 'all', FALSE);
+ }
+ }
}
}
}
@@ -291,14 +308,29 @@ function gallery_set_css($css) {
* (druapl_add_js() ensures proper cascading of included G2 javascript)
*/
function gallery_set_javascript($javascript) {
+ global $base_url;
+ static $js_memory = array();
+
if (!empty($javascript)) {
$files = preg_grep('/<script(.*?)src=/i', $javascript);
+ // Inline Javascript
$inline = array_diff($javascript, $files);
$inline = preg_replace('/<script([^>]*)>([^<]*)<\/script>/i', '${2}', $inline);
drupal_add_js(implode("\n", $inline), 'inline');
+ // Javascript files
$files = preg_replace('/<script(.*?)src="([^"]*)"([^>]*)>(.*?)<\/script>/i', '${2}', $files);
+ $files = preg_replace(array('#^'. $base_url .'#', '#^'. base_path() .'#', '#^/#'), '', $files);
foreach ($files as $include) {
- drupal_add_js(substr($include, strlen(base_path())));
+ if (!in_array(($md5 = md5($include)), $js_memory)) {
+ $js_memory[] = $md5;
+ if (substr($include, 0, 4) == 'http') {
+ // drupal_add_js() does not support external paths
+ drupal_set_html_head('<script type="text/javascript" src="'. $include .'"></script>' ."\n");
+ }
+ else {
+ drupal_add_js($include);
+ }
+ }
}
}
}