summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2010-03-01 07:18:28 +0000
committerdeva <deva>2010-03-01 07:18:28 +0000
commit9d6e3ab0be248bde75ed5b70dbab5f24d2bfeac5 (patch)
treefb42c13d9b9930a0abcccc6d38c9d6bf28742951
parent7dce03dc61c4bb8a1e48856a27221b083826490b (diff)
Make images in css file preload automatically.
-rw-r--r--htdocs/index.php12
-rw-r--r--utils/preload.php25
2 files changed, 29 insertions, 8 deletions
diff --git a/htdocs/index.php b/htdocs/index.php
index 1a9e5af..25f5ad1 100644
--- a/htdocs/index.php
+++ b/htdocs/index.php
@@ -89,18 +89,14 @@ if($config->value('splash') == "true") {
</script>
</head>
<body><?php
+
+ include_once($UTIL_DIR."/preload.php");
+preload("design/mors/style.css");
+
if($page == "admin") {
include($UTIL_DIR."/admin.php");
}
?>
-<div style="display: none;">
-<?php
-$_ps = $config->value('preload');
-foreach($_ps as $_p) {
- echo " <img alt=\"preload\" src=\"".$_p."\"/>\n";
-}
-?>
-</div>
<div class="page">
<div class="menu">
<?php
diff --git a/utils/preload.php b/utils/preload.php
new file mode 100644
index 0000000..9e26956
--- /dev/null
+++ b/utils/preload.php
@@ -0,0 +1,25 @@
+<?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+function preload($cssfile)
+{
+ $css = file_get_contents($cssfile);
+
+ // TODO: Check for @import and do recursive parsing
+?>
+
+ <div style="display: none;">
+<?php
+ preg_match_all("|url\((.+)\)|U", $css, $urls);
+ // print_r($urls);
+ $path = dirname($cssfile);
+ $imgs = array_unique($urls[1]);
+
+foreach($imgs as $_p) {
+ echo " <img alt=\"preload\" src=\"".$path . "/" . $_p."\"/>\n";
+}
+?>
+</div>
+<?php
+}
+
+?> \ No newline at end of file