From e9362d90feff482fa54b82b47a5d4ac8578081a8 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 29 Jul 2009 17:10:56 -0600 Subject: [PATCH] Move JS/CSS caching to Horde:: --- babel/templates/common-header.inc | 2 +- chora/templates/common-header.inc | 2 +- crumb/templates/common-header.inc | 2 +- fima/templates/common-header.inc | 2 +- folks/templates/common-header.inc | 2 +- gollem/templates/common-header.inc | 2 +- imp/compose-dimp.php | 2 +- imp/config/conf.xml | 49 ---- imp/docs/CHANGES | 1 + imp/index-dimp.php | 2 +- imp/lib/IMP.php | 317 ------------------------- imp/message-dimp.php | 2 +- imp/templates/common-header.inc | 17 +- ingo/templates/common-header.inc | 2 +- jeta/templates/common-header.inc | 2 +- kastalia/templates/common-header.inc | 2 +- koward/lib/Koward/View/shared/_header.html.php | 2 +- kronolith/index.php | 2 +- kronolith/lib/Kronolith.php | 222 +---------------- kronolith/templates/common-header.inc | 2 +- nag/templates/common-header.inc | 2 +- news/diff.php | 2 +- news/reads.php | 2 +- news/templates/common-header.inc | 2 +- skoli/templates/common-header.inc | 2 +- turba/templates/common-header.inc | 2 +- 26 files changed, 37 insertions(+), 611 deletions(-) diff --git a/babel/templates/common-header.inc b/babel/templates/common-header.inc index 93c47fcf4..d00e416a5 100644 --- a/babel/templates/common-header.inc +++ b/babel/templates/common-header.inc @@ -19,7 +19,7 @@ Horde::includeScriptFiles(); ?> <?php echo $page_title ?> - + > diff --git a/chora/templates/common-header.inc b/chora/templates/common-header.inc index 884cd39b3..558ebc11e 100644 --- a/chora/templates/common-header.inc +++ b/chora/templates/common-header.inc @@ -20,7 +20,7 @@ Horde::includeScriptFiles(); ?> <?php echo htmlspecialchars($page_title) ?> - + > diff --git a/crumb/templates/common-header.inc b/crumb/templates/common-header.inc index 481396ece..50147d49c 100644 --- a/crumb/templates/common-header.inc +++ b/crumb/templates/common-header.inc @@ -23,7 +23,7 @@ Horde::includeScriptFiles(); ?> <?php echo htmlspecialchars($page_title) ?> - + > diff --git a/fima/templates/common-header.inc b/fima/templates/common-header.inc index d6ecab05e..66c6440c6 100644 --- a/fima/templates/common-header.inc +++ b/fima/templates/common-header.inc @@ -23,7 +23,7 @@ Horde::includeScriptFiles(); ?> <?php echo htmlspecialchars($page_title) ?> - + > diff --git a/folks/templates/common-header.inc b/folks/templates/common-header.inc index d73782b55..bb8a9b147 100644 --- a/folks/templates/common-header.inc +++ b/folks/templates/common-header.inc @@ -27,7 +27,7 @@ Horde::includeScriptFiles(); " /> " /> - + > diff --git a/gollem/templates/common-header.inc b/gollem/templates/common-header.inc index b56950ff9..505922e0b 100644 --- a/gollem/templates/common-header.inc +++ b/gollem/templates/common-header.inc @@ -25,7 +25,7 @@ require GOLLEM_TEMPLATES . '/javascript_defs.php'; ?> <?php echo htmlspecialchars($page_title) ?> - + diff --git a/imp/compose-dimp.php b/imp/compose-dimp.php index b515ba185..558571c99 100644 --- a/imp/compose-dimp.php +++ b/imp/compose-dimp.php @@ -337,7 +337,7 @@ $scripts = array( DIMP::header(_("Message Composition"), $scripts); echo $t->fetch('compose.html'); -IMP::includeScriptFiles(); +Horde::includeScriptFiles(); Horde::outputInlineScript(); echo $compose_result['jsappend']; echo "\n"; diff --git a/imp/config/conf.xml b/imp/config/conf.xml index a4e636949..4675f6501 100644 --- a/imp/config/conf.xml +++ b/imp/config/conf.xml @@ -86,54 +86,6 @@ next login. If IMP will be the exclusive means of accessing the mail server, or you are not concerned about this behavior, this setting should be set to true.">true - none - - - - - - 86400 - - - - - <strong>Requires a configured Horde_Cache backend.</strong> - - - - 86400 - - - - none - - - - - - 86400 - - - - - <strong>Requires a configured Horde_Cache backend.</strong> - - - - 86400 - - - @@ -344,7 +296,6 @@ - Custom Hooks diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index c1ad3eede..ba4248607 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,7 @@ v5.0-git -------- +[mms] Move JS/CSS caching to Horde framework. [mms] Add simple search function to MIMP. [mms] DIMP now honors the 'mailbox_start' preference. [mms] Logins now handled by Horde login handler. diff --git a/imp/index-dimp.php b/imp/index-dimp.php index 90b55d30f..86e582d6a 100644 --- a/imp/index-dimp.php +++ b/imp/index-dimp.php @@ -62,7 +62,7 @@ foreach (DIMP::menuList() as $app) { echo "\n"; require IMP_TEMPLATES . '/index/index-dimp.inc'; -IMP::includeScriptFiles(); +Horde::includeScriptFiles(); Horde::outputInlineScript(); $notification->notify(array('listeners' => array('javascript'))); echo "\n"; diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 4684e9943..46546f03b 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -47,9 +47,6 @@ class IMP /* hideDeletedMsgs() cache. */ static private $_delhide = null; - /* filesystemGC() cache. */ - static private $_dirlist = array(); - /* Has init previously been called? */ static private $_init = false; @@ -1208,320 +1205,6 @@ class IMP } /** - * Outputs the necessary script tags, honoring local configuration - * choices as to script caching. - */ - static public function includeScriptFiles() - { - global $conf; - - $cache_type = @$conf['server']['cachejs']; - - if (empty($cache_type) || - $cache_type == 'none' || - (($cache_type == 'horde_cache') && - !($cache = self::getCache()))) { - Horde::includeScriptFiles(); - return; - } - - $js_tocache = $js_force = array(); - $mtime = array(0); - - $s_list = Horde::listScriptFiles(); - foreach ($s_list as $app => $files) { - foreach ($files as $file) { - if ($file['d'] && ($file['f'][0] != '/')) { - $js_tocache[$file['p'] . $file['f']] = false; - $mtime[] = filemtime($file['p'] . $file['f']); - } else { - $js_force[] = $file['u']; - } - } - } - - sort($s_list); - - require_once IMP_BASE . '/lib/version.php'; - $sig = hash('md5', serialize($s_list) . max($mtime) . IMP_VERSION); - - switch ($cache_type) { - case 'filesystem': - $js_filename = '/' . $sig . '.js'; - $js_path = $conf['server']['cachejsparams']['file_location'] . $js_filename; - $js_url = $conf['server']['cachejsparams']['file_url'] . $js_filename; - $exists = file_exists($js_path); - break; - - case 'horde_cache': - // Do lifetime checking here, not on cache display page. - $exists = $cache->exists($sig, empty($conf['server']['cachejsparams']['lifetime']) ? 0 : $conf['server']['cachejsparams']['lifetime']); - $js_url = Horde::getCacheUrl('js', array('cid' => $sig)); - break; - } - - if (!$exists) { - $out = ''; - foreach ($js_tocache as $key => $val) { - // Separate JS files with a newline since some compressors may - // strip trailing terminators. - if ($val) { - // Minify these files a bit by removing newlines and - // comments. - $out .= preg_replace(array('/\n+/', '/\/\*.*?\*\//'), array('', ''), file_get_contents($key)) . "\n"; - } else { - $out .= file_get_contents($key) . "\n"; - } - } - - switch ($cache_type) { - case 'filesystem': - register_shutdown_function(array('IMP', 'filesystemGC'), 'js'); - file_put_contents($js_path, $out); - break; - - case 'horde_cache': - $cache->set($sig, $out); - break; - } - } - - foreach (array_merge(array($js_url), $js_force) as $val) { - echo '\n"; - } - } - - /** - * Outputs the necessary style tags, honoring local configuration - * choices as to stylesheet caching. - * - * @param string $app The application to load ('dimp' or 'imp'). - */ - static public function includeStylesheetFiles($app = 'imp') - { - global $conf, $prefs, $registry; - - $theme = $prefs->getValue('theme'); - $themesfs = $registry->get('themesfs'); - $themesuri = $registry->get('themesuri'); - if ($app == 'imp') { - $css = Horde::getStylesheets('imp', $theme); - } else { - $css = self::_getDIMPStylesheets($theme); - } - $css_out = array(); - - if ($app == 'dimp') { - // Load custom stylesheets. - if (!empty($conf['dimp']['css_files'])) { - foreach ($conf['css_files'] as $css_file) { - $css[] = array('u' => $themesuri . '/' . $css_file, - 'f' => $themesfs . '/' . $css_file); - } - } - } - - $cache_type = @$conf['server']['cachecss']; - - if (empty($cache_type) || - $cache_type == 'none' || - (($cache_type == 'horde_cache') && - !($cache = self::getCache()))) { - $css_out = array_merge($css, $css_out); - } else { - $mtime = array(0); - $out = ''; - - foreach ($css as $file) { - $mtime[] = filemtime($file['f']); - } - - require_once IMP_BASE . '/lib/version.php'; - $sig = hash('md5', serialize($css) . max($mtime) . IMP_VERSION); - - switch ($cache_type) { - case 'filesystem': - $css_filename = '/' . $sig . '.css'; - $css_path = $conf['server']['cachecssparams']['file_location'] . $css_filename; - $css_url = $conf['server']['cachecssparams']['file_url'] . $css_filename; - $exists = file_exists($css_path); - break; - - case 'horde_cache': - // Do lifetime checking here, not on cache display page. - $exists = $cache->exists($sig, empty($GLOBALS['conf']['server']['cachecssparams']['lifetime']) ? 0 : $GLOBALS['conf']['server']['cachecssparams']['lifetime']); - $css_url = Horde::getCacheUrl('css', array('cid' => $sig)); - break; - } - - if (!$exists) { - $flags = defined('FILE_IGNORE_NEW_LINES') ? (FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : 0; - foreach ($css as $file) { - $path = substr($file['u'], 0, strrpos($file['u'], '/') + 1); - - // Fix relative URLs, convert graphics URLs to data URLs - // (if possible), remove multiple whitespaces, and strip - // comments. - $tmp = preg_replace(array('/(url\(["\']?)([^\/])/i', '/\s+/', '/\/\*.*?\*\//'), array('$1' . $path . '$2', ' ', ''), implode('', file($file['f'], $flags))); - if ($GLOBALS['browser']->hasFeature('dataurl')) { - $tmp = preg_replace_callback('/(background(?:-image)?:[^;}]*(?:url\(["\']?))(.*?)((?:["\']?\)))/i', array('IMP', 'stylesheetCallback'), $tmp); - } - $out .= $tmp; - } - - /* Use CSS tidy to clean up file. */ - try { - $out = Horde_Text_Filter::filter($out, 'csstidy'); - } catch (Horde_Exception $e) {} - - switch ($cache_type) { - case 'filesystem': - register_shutdown_function(array('IMP', 'filesystemGC'), 'css'); - file_put_contents($css_path, $out); - break; - - case 'horde_cache': - $cache->set($sig, $out); - break; - } - } - - $css_out = array_merge(array(array('u' => $css_url)), $css_out); - } - - foreach ($css_out as $file) { - echo '\n"; - } - } - - /** - * TODO - Move to Horde core - */ - public function stylesheetCallback($matches) - { - return $matches[1] . Horde::base64ImgData($matches[2]) . $matches[3]; - } - - /** - * TODO - Temporary DIMP fix/Merge to Horde core - */ - private function _getDIMPStylesheets($theme = '') - { - if ($theme === '' && isset($GLOBALS['prefs'])) { - $theme = $GLOBALS['prefs']->getValue('theme'); - } - - $css = array(); - $rtl = isset($GLOBALS['nls']['rtl'][$GLOBALS['language']]); - - /* Collect browser specific stylesheets if needed. */ - $browser_css = array(); - - switch ($GLOBALS['browser']->getBrowser()) { - case 'msie': - $ie_major = $GLOBALS['browser']->getMajor(); - // TODO: IE8 specific styling - if ($ie_major >= 7) { - $browser_css[] = 'ie7.css'; - $browser_css[] = 'ie7-dimp.css'; - } elseif ($ie_major < 7) { - $browser_css[] = 'ie6_or_less.css'; - $browser_css[] = 'ie6_or_less-dimp.css'; - if ($GLOBALS['browser']->getPlatform() == 'mac') { - $browser_css[] = 'ie5mac.css'; - } - } - break; - - case 'opera': - $browser_css[] = 'opera.css'; - break; - - case 'mozilla': - if ($GLOBALS['browser']->getMajor() >= 5 && - preg_match('/rv:(.*)\)/', $GLOBALS['browser']->getAgentString(), $revision) && - $revision[1] <= 1.4) { - $browser_css[] = 'moz14.css'; - } - break; - - case 'webkit': - $browser_css[] = 'webkit.css'; - } - - foreach (array('horde', 'imp') as $app) { - $themes_fs = $GLOBALS['registry']->get('themesfs', $app); - $themes_uri = Horde::url($GLOBALS['registry']->get('themesuri', $app), false, -1); - $css[] = array('u' => $themes_uri . '/screen.css', 'f' => $themes_fs . '/screen.css'); - if ($app == 'imp') { - $css[] = array('u' => $themes_uri . '/screen-dimp.css', 'f' => $themes_fs . '/screen-dimp.css'); - } - if (!empty($theme)) { - if (file_exists($themes_fs . '/' . $theme . '/screen.css')) { - $css[] = array('u' => $themes_uri . '/' . $theme . '/screen.css', 'f' => $themes_fs . '/' . $theme . '/screen.css'); - } - if (($app == 'imp') && - file_exists($themes_fs . '/' . $theme . '/screen-dimp.css')) { - $css[] = array('u' => $themes_uri . '/' . $theme . '/screen-dimp.css', 'f' => $themes_fs . '/' . $theme . '/screen-dimp.css'); - } - } - - if ($rtl) { - $css[] = array('u' => $themes_uri . '/rtl.css', 'f' => $themes_fs . '/rtl.css'); - if (!empty($theme) && - file_exists($themes_fs . '/' . $theme . '/rtl.css')) { - $css[] = array('u' => $themes_uri . '/' . $theme . '/rtl.css', 'f' => $themes_fs . '/' . $theme . '/rtl.css'); - } - } - foreach ($browser_css as $browser) { - if (file_exists($themes_fs . '/' . $browser)) { - $css[] = array('u' => $themes_uri . '/' . $browser, 'f' => $themes_fs . '/' . $browser); - } - if (!empty($theme) && - file_exists($themes_fs . '/' . $theme . '/' . $browser)) { - $css[] = array('u' => $themes_uri . '/' . $theme . '/' . $browser, 'f' => $themes_fs . '/' . $theme . '/' . $browser); - } - } - } - - return $css; - } - - /** - * Do garbage collection in the statically served file directory. - * - * @param string $type Either 'css' or 'js'. - */ - static public function filesystemGC($type) - { - $dir_list = &self::$_dirlist; - - $ptr = $GLOBALS['conf']['server'][(($type == 'css') ? 'cachecssparams' : 'cachejsparams')]; - $dir = $ptr['file_location']; - if (in_array($dir, $dir_list)) { - return; - } - - $c_time = time() - $ptr['lifetime']; - $d = dir($dir); - $dir_list[] = $dir; - - while (($entry = $d->read()) !== false) { - $path = $dir . '/' . $entry; - if (in_array($entry, array('.', '..'))) { - continue; - } - - if ($c_time > filemtime($path)) { - $old_error = error_reporting(0); - unlink($path); - error_reporting($old_error); - } - } - $d->close(); - } - - /** * Returns a Horde_Cache object (if configured) and handles any errors * associated with creating the object. * diff --git a/imp/message-dimp.php b/imp/message-dimp.php index 978b5a9e2..b1785a94f 100644 --- a/imp/message-dimp.php +++ b/imp/message-dimp.php @@ -83,7 +83,7 @@ Horde::addInlineScript(array(DIMP::notify()), 'dom'); DIMP::header($show_msg_result['subject'], $scripts); echo "\n"; require IMP_TEMPLATES . '/chunks/message.php'; -IMP::includeScriptFiles(); +Horde::includeScriptFiles(); Horde::outputInlineScript(); if (!$disable_compose) { echo $compose_result['jsappend']; diff --git a/imp/templates/common-header.inc b/imp/templates/common-header.inc index ea29eb9a1..91d19113f 100644 --- a/imp/templates/common-header.inc +++ b/imp/templates/common-header.inc @@ -16,13 +16,24 @@ $imp_view = Horde_Util::nonInputVar('imp_view'); switch ($imp_view) { case 'dimp': include IMP_TEMPLATES . '/javascript_defs_dimp.php'; - IMP::includeStylesheetFiles('dimp'); + + $css = array(); + if (!empty($GLOBALS['conf']['dimp']['css_files'])) { + foreach ($GLOBALS['conf']['css_files'] as $css_file) { + $css[] = array( + 'u' => $themesuri . '/' . $css_file, + 'f' => $themesfs . '/' . $css_file + ); + } + } + + Horde::includeStylesheetFiles(array('additional' => $css, 'sub' => 'dimp')); break; default: include IMP_TEMPLATES . '/javascript_defs.php'; - IMP::includeScriptFiles(); - IMP::includeStylesheetFiles(); + Horde::includeScriptFiles(); + Horde::includeStylesheetFiles(); break; } ?> diff --git a/ingo/templates/common-header.inc b/ingo/templates/common-header.inc index 3b67ad6a9..491d41cfd 100644 --- a/ingo/templates/common-header.inc +++ b/ingo/templates/common-header.inc @@ -17,7 +17,7 @@ if (!empty($title)) { <?php echo htmlspecialchars($page_title) ?> - + > diff --git a/jeta/templates/common-header.inc b/jeta/templates/common-header.inc index a9870df3b..501e08e31 100644 --- a/jeta/templates/common-header.inc +++ b/jeta/templates/common-header.inc @@ -9,7 +9,7 @@ if (isset($language)) { <?php echo htmlspecialchars($registry->get('name')) ?> - + diff --git a/kastalia/templates/common-header.inc b/kastalia/templates/common-header.inc index bfcf5a024..787fdffbe 100755 --- a/kastalia/templates/common-header.inc +++ b/kastalia/templates/common-header.inc @@ -26,7 +26,7 @@ Horde::includeScriptFiles(); ?> <?php echo htmlspecialchars($page_title) ?> - + > diff --git a/koward/lib/Koward/View/shared/_header.html.php b/koward/lib/Koward/View/shared/_header.html.php index 3d742b164..37b451c5a 100644 --- a/koward/lib/Koward/View/shared/_header.html.php +++ b/koward/lib/Koward/View/shared/_header.html.php @@ -29,7 +29,7 @@ Horde::includeScriptFiles(); <?php echo htmlspecialchars($page_title) ?> -print_view) ? $this->theme : 'print') ?> + diff --git a/kronolith/index.php b/kronolith/index.php index 2ca8c5f78..bdeec7467 100644 --- a/kronolith/index.php +++ b/kronolith/index.php @@ -62,7 +62,7 @@ $scripts = array( Kronolith::header('', $scripts); echo "\n"; require KRONOLITH_TEMPLATES . '/index/index.inc'; -Kronolith::includeScriptFiles(); +Horde::includeScriptFiles(); Horde::outputInlineScript(); $notification->notify(array('listeners' => array('javascript'))); $tac = Horde_Ajax_Imple::factory(array('kronolith', 'TagAutoCompleter'), array('triggerId' => 'kronolithEventTags', 'pretty' => true)); diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 02960397a..3500d8be3 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -111,7 +111,7 @@ class Kronolith '\n". Horde::wrapInlineScript(self::includeJSVars()); - self::includeStylesheetFiles(true); + Horde::includeStylesheetFiles(); echo "\n"; @@ -227,190 +227,6 @@ class Kronolith } /** - * Outputs the necessary script tags, honoring local configuration choices - * as to script caching. - */ - public static function includeScriptFiles() - { - global $conf; - - $cache_type = @$conf['server']['cachejs']; - - if (empty($cache_type) || - $cache_type == 'none' || - ($cache_type == 'horde_cache' && - $conf['cache']['driver'] == 'none')) { - Horde::includeScriptFiles(); - return; - } - - $js_tocache = $js_force = array(); - $mtime = array(0); - - $s_list = Horde::listScriptFiles(); - foreach ($s_list as $app => $files) { - foreach ($files as $file) { - if ($file['d'] && ($file['f'][0] != '/')) { - $js_tocache[$file['p'] . $file['f']] = false; - $mtime[] = filemtime($file['p'] . $file['f']); - } else { - $js_force[] = $file['u']; - } - } - } - - require_once KRONOLITH_BASE . '/lib/version.php'; - $sig = hash('md5', serialize($s_list) . max($mtime) . KRONOLITH_VERSION); - - switch ($cache_type) { - case 'filesystem': - $js_filename = '/' . $sig . '.js'; - $js_path = $conf['server']['cachejsparams']['file_location'] . $js_filename; - $js_url = $conf['server']['cachejsparams']['file_url'] . $js_filename; - $exists = file_exists($js_path); - break; - - case 'horde_cache': - $cache = &Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver'])); - $exists = $cache->exists($sig, empty($conf['server']['cachejsparams']['lifetime']) ? 0 : $conf['server']['cachejsparams']['lifetime']); - $js_url = self::getCacheURL('js', $sig); - break; - } - - if (!$exists) { - $out = ''; - foreach ($js_tocache as $key => $val) { - // Separate JS files with a newline since some compressors may - // strip trailing terminators. - if ($val) { - // Minify these files a bit by removing newlines and - // comments. - $out .= preg_replace(array('/\n+/', '/\/\*.*?\*\//'), array('', ''), file_get_contents($key)) . "\n"; - } else { - $out .= file_get_contents($key) . "\n"; - } - } - - switch ($cache_type) { - case 'filesystem': - register_shutdown_function(array('Kronolith', '_filesystemGC'), 'js'); - file_put_contents($js_path, $out); - break; - - case 'horde_cache': - $cache->set($sig, $out); - break; - } - } - - foreach (array_merge(array($js_url), $js_force) as $val) { - echo '' . "\n"; - } - } - - /** - * Outputs the necessary style tags, honoring local configuration choices - * as to stylesheet caching. - * - * @param boolean $print Include print CSS? - */ - public static function includeStylesheetFiles($print = false) - { - global $conf, $prefs, $registry; - - $theme = $prefs->getValue('theme'); - $themesfs = $registry->get('themesfs'); - $themesuri = $registry->get('themesuri'); - $css = Horde::getStylesheets('kronolith', $theme); - $css_out = array(); - - // Add print specific stylesheets. - if ($print) { - // Add Horde print stylesheet - $css_out[] = array('u' => $registry->get('themesuri', 'horde') . '/print/screen.css', - 'f' => $registry->get('themesfs', 'horde') . '/print/screen.css', - 'm' => 'print'); - $css_out[] = array('u' => $themesuri . '/print/screen.css', - 'f' => $themesfs . '/print/screen.css', - 'm' => 'print'); - if (file_exists($themesfs . '/' . $theme . '/print.css')) { - $css_out[] = array('u' => $themesuri . '/' . $theme . '/print.css', - 'f' => $themesfs . '/' . $theme . '/print.css', - 'm' => 'print'); - } - } - - // Load custom stylesheets. - if (!empty($conf['css_files'])) { - foreach ($conf['css_files'] as $css_file) { - $css[] = array('u' => $themesuri . '/' . $css_file, - 'f' => $themesfs . '/' . $css_file); - } - } - - $cache_type = @$conf['server']['cachecss']; - - if (empty($cache_type) || - $cache_type == 'none' || - ($cache_type == 'horde_cache' && - $conf['cache']['driver'] == 'none')) { - $css_out = array_merge($css, $css_out); - } else { - $mtime = array(0); - $out = ''; - - foreach ($css as $file) { - $mtime[] = filemtime($file['f']); - } - - require_once KRONOLITH_BASE . '/lib/version.php'; - $sig = hash('md5', serialize($css) . max($mtime) . KRONOLITH_VERSION); - - switch ($cache_type) { - case 'filesystem': - $css_filename = '/' . $sig . '.css'; - $css_path = $conf['server']['cachecssparams']['file_location'] . $css_filename; - $css_url = $conf['server']['cachecssparams']['file_url'] . $css_filename; - $exists = file_exists($css_path); - break; - - case 'horde_cache': - $cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); - $exists = $cache->exists($sig, empty($GLOBALS['conf']['server']['cachecssparams']['lifetime']) ? 0 : $GLOBALS['conf']['server']['cachecssparams']['lifetime']); - $css_url = self::getCacheURL('css', $sig); - break; - } - - if (!$exists) { - $flags = defined('FILE_IGNORE_NEW_LINES') ? (FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : 0; - foreach ($css as $file) { - $path = substr($file['u'], 0, strrpos($file['u'], '/') + 1); - // Fix relative URLs, remove multiple whitespaces, and - // strip comments. - $out .= preg_replace(array('/(url\(["\']?)([^\/])/i', '/\s+/', '/\/\*.*?\*\//'), array('$1' . $path . '$2', ' ', ''), implode('', file($file['f'], $flags))); - } - - switch ($cache_type) { - case 'filesystem': - register_shutdown_function(array('Kronolith', '_filesystemGC'), 'css'); - file_put_contents($css_path, $out); - break; - - case 'horde_cache': - $cache->set($sig, $out); - break; - } - } - - $css_out = array_merge(array(array('u' => $css_url)), $css_out); - } - - foreach ($css_out as $file) { - echo '' . "\n"; - } - } - - /** * Creates a URL for cached Kronolith data. * * @param string $type The cache type. @@ -430,42 +246,6 @@ class Kronolith } /** - * Do garbage collection in the statically served file directory. - * - * @access private - * - * @param string $type Either 'css' or 'js'. - */ - public static function _filesystemGC($type) - { - static $dir_list = array(); - - $ptr = $GLOBALS['conf']['server'][(($type == 'css') ? 'cachecssparams' : 'cachejsparams')]; - $dir = $ptr['file_location']; - if (in_array($dir, $dir_list)) { - return; - } - - $c_time = time() - $ptr['lifetime']; - $d = dir($dir); - $dir_list[] = $dir; - - while (($entry = $d->read()) !== false) { - $path = $dir . '/' . $entry; - if (in_array($entry, array('.', '..'))) { - continue; - } - - if ($c_time > filemtime($path)) { - $old_error = error_reporting(0); - unlink($path); - error_reporting($old_error); - } - } - $d->close(); - } - - /** * Returns all the alarms active on a specific date. * * @param Horde_Date $date The date to check for alarms. diff --git a/kronolith/templates/common-header.inc b/kronolith/templates/common-header.inc index 93dee4ca3..d556fb8fa 100644 --- a/kronolith/templates/common-header.inc +++ b/kronolith/templates/common-header.inc @@ -45,7 +45,7 @@ var kronolithPrintLink = ''; //]]> <?php echo htmlspecialchars($page_title) ?> - + diff --git a/nag/templates/common-header.inc b/nag/templates/common-header.inc index f2402a296..7ae491e1e 100644 --- a/nag/templates/common-header.inc +++ b/nag/templates/common-header.inc @@ -28,7 +28,7 @@ if ($prefs->getValue('show_panel')) { ?> <?php echo htmlspecialchars($page_title) ?> - + diff --git a/news/diff.php b/news/diff.php index 226d9d79c..cf1a54753 100644 --- a/news/diff.php +++ b/news/diff.php @@ -46,7 +46,7 @@ if ($version_data instanceof PEAR_Error) { $version_data = unserialize($version_data); -echo Horde::stylesheetLink('news'); +Horde::includeStylesheetFiles(); while (list($k, $v) = each($current_data)) { echo '
' . $nls['languages'][$k] . '
' . "\n"; diff --git a/news/reads.php b/news/reads.php index 859b8a6aa..e09bc8ec0 100644 --- a/news/reads.php +++ b/news/reads.php @@ -37,7 +37,7 @@ if ($result instanceof PEAR_Error) { Horde::addScriptFile('tables.js', 'horde', true); Horde::includeScriptFiles(); -echo Horde::stylesheetLink('news'); +Horde::includeStylesheetFiles(); // require_once NEWS_TEMPLATES . '/common-header.inc'; require_once NEWS_TEMPLATES . '/reads/header.inc'; diff --git a/news/templates/common-header.inc b/news/templates/common-header.inc index 6eb64594d..dcb2dd7d7 100644 --- a/news/templates/common-header.inc +++ b/news/templates/common-header.inc @@ -25,7 +25,7 @@ Horde::includeScriptFiles(); " href="" type="application/rss+xml" /> " href="" type="application/rss+xml" /> - + > diff --git a/skoli/templates/common-header.inc b/skoli/templates/common-header.inc index 85c2cb599..5772d5cd3 100644 --- a/skoli/templates/common-header.inc +++ b/skoli/templates/common-header.inc @@ -31,7 +31,7 @@ if ($prefs->getValue('show_panel')) { ?> <?php echo htmlspecialchars($page_title) ?> - + diff --git a/turba/templates/common-header.inc b/turba/templates/common-header.inc index 234db2bc0..fcf62d5cb 100644 --- a/turba/templates/common-header.inc +++ b/turba/templates/common-header.inc @@ -22,7 +22,7 @@ Horde::includeScriptFiles(); ?> <?php echo htmlspecialchars($page_title) ?> - + > -- 2.11.0