function _css_out() { global $_CONF, $_SYSTEM, $_VARS, $_USER, $_PLUGINS, $_TABLES; $css = ''; $file_content = ''; $files = array(); $outputHandle = outputHandler::getInstance(); if (!isset($_CONF['css_cache_filename'])) { $_CONF['css_cache_filename'] = 'style.cache'; } list($cacheFile, $cacheURL) = COM_getStyleCacheLocation(); // Let's look in the custom directory first... if (file_exists($_CONF['path_layout'] . 'custom/style.css')) { $files[] = $_CONF['path_layout'] . 'custom/style.css'; } else { $files[] = $_CONF['path_layout'] . 'style.css'; } if (file_exists($_CONF['path_layout'] . 'custom/style-colors.css')) { $files[] = $_CONF['path_layout'] . 'custom/style-colors.css'; } else { if (file_exists($_CONF['path_layout'] . 'style-color.css')) { $files[] = $_CONF['path_layout'] . 'style-colors.css'; } } // need to parse the outputhandler to see if there are any js scripts to load $headercss = $outputHandle->getCSSFiles(); foreach ($headercss as $s) { $files[] = $s; } /* * Check to see if there are any custom CSS files to include */ if (function_exists('CUSTOM_css')) { $customCSS = CUSTOM_css(); if (is_array($customCSS)) { foreach ($customCSS as $item => $file) { $files[] = $file; } } } if (is_array($_PLUGINS)) { foreach ($_PLUGINS as $pi_name) { if (function_exists('plugin_getheadercss_' . $pi_name)) { $function = 'plugin_getheadercss_' . $pi_name; $pHeader = array(); $pHeader = $function(); if (is_array($pHeader)) { foreach ($pHeader as $item => $file) { $files[] = $file; } } } } } // Custom CSS added by theme if it supports it... // if ( file_exists($_CONF['path_layout'] .'custom.css') ) { // $files[] = $_CONF['path_layout'] . 'custom.css'; // } // check cache age & handle conditional request if (css_cacheok($cacheFile, $files)) { return $cacheURL; } $cacheID = 'css_' . md5(time()); DB_query("REPLACE INTO {$_TABLES['vars']} (name, value) VALUES ('cacheid','" . $cacheID . "')"); $_VARS['cacheid'] = $cacheID; // load files if (is_array($files)) { foreach ($files as $file) { $file_content = @file_get_contents($file); if ($file_content === false) { COM_errorLog("ERROR: Unable to retrieve CSS file: " . $file); } else { $css .= $file_content; } $css .= LB; } } // compress whitespace and comments if ($_CONF['compress_css']) { $css = _css_compress($css); } // save cache file $rc = writeFile_lck($cacheFile, '', $css, 'glfusion_css.lck'); if ($rc === false) { writeFile_lck($cacheFile, '', $css, 'glfusion_css.lck'); } return $cacheURL; }
/** * Output all needed Styles * * @author Andreas Gohr <*****@*****.**> */ function css_out() { global $conf; global $lang; global $config_cascade; $mediatype = 'screen'; if (isset($_REQUEST['s']) && in_array($_REQUEST['s'], array('all', 'print', 'feed'))) { $mediatype = $_REQUEST['s']; } $tpl = trim(preg_replace('/[^\\w-]+/', '', $_REQUEST['t'])); if ($tpl) { $tplinc = DOKU_INC . 'lib/tpl/' . $tpl . '/'; $tpldir = DOKU_BASE . 'lib/tpl/' . $tpl . '/'; } else { $tplinc = DOKU_TPLINC; $tpldir = DOKU_TPL; } // The generated script depends on some dynamic options $cache = getCacheName('styles' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . DOKU_BASE . $tplinc . $mediatype, '.css'); // load template styles $tplstyles = array(); if (@file_exists($tplinc . 'style.ini')) { $ini = parse_ini_file($tplinc . 'style.ini', true); foreach ($ini['stylesheets'] as $file => $mode) { $tplstyles[$mode][$tplinc . $file] = $tpldir; } } // Array of needed files and their web locations, the latter ones // are needed to fix relative paths in the stylesheets $files = array(); // load core styles $files[DOKU_INC . 'lib/styles/' . $mediatype . '.css'] = DOKU_BASE . 'lib/styles/'; // load plugin styles $files = array_merge($files, css_pluginstyles($mediatype)); // load template styles if (isset($tplstyles[$mediatype])) { $files = array_merge($files, $tplstyles[$mediatype]); } // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility if (isset($config_cascade['userstyle']['default'])) { $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default']; } // load user styles if (isset($config_cascade['userstyle'][$mediatype])) { $files[$config_cascade['userstyle'][$mediatype]] = DOKU_BASE; } // load rtl styles // @todo: this currently adds the rtl styles only to the 'screen' media type // but 'print' and 'all' should also be supported if ($mediatype == 'screen') { if ($lang['direction'] == 'rtl') { if (isset($tplstyles['rtl'])) { $files = array_merge($files, $tplstyles['rtl']); } } } // check cache age & handle conditional request header('Cache-Control: public, max-age=3600'); header('Pragma: public'); if (css_cacheok($cache, array_keys($files), $tplinc)) { http_conditionalRequest(filemtime($cache)); if ($conf['allowdebug']) { header("X-CacheUsed: {$cache}"); } // finally send output if ($conf['gzip_output'] && http_gzip_valid($cache)) { header('Vary: Accept-Encoding'); header('Content-Encoding: gzip'); readfile($cache . ".gz"); } else { if (!http_sendfile($cache)) { readfile($cache); } } return; } else { http_conditionalRequest(time()); } // start output buffering and build the stylesheet ob_start(); // print the default classes for interwiki links and file downloads css_interwiki(); css_filetypes(); // load files foreach ($files as $file => $location) { print css_loadfile($file, $location); } // end output buffering and get contents $css = ob_get_contents(); ob_end_clean(); // apply style replacements $css = css_applystyle($css, $tplinc); // place all @import statements at the top of the file $css = css_moveimports($css); // compress whitespace and comments if ($conf['compress']) { $css = css_compress($css); } // save cache file io_saveFile($cache, $css); if (function_exists('gzopen')) { io_saveFile("{$cache}.gz", $css); } // finally send output if ($conf['gzip_output']) { header('Vary: Accept-Encoding'); header('Content-Encoding: gzip'); print gzencode($css, 9, FORCE_GZIP); } else { print $css; } }
/** * Output all needed Styles * * @author Andreas Gohr <*****@*****.**> */ function css_out() { global $conf; global $lang; switch ($_REQUEST['s']) { case 'all': case 'print': case 'feed': $style = $_REQUEST['s']; break; default: $style = ''; break; } $tpl = trim(preg_replace('/[^\\w-]+/', '', $_REQUEST['t'])); if ($tpl) { $tplinc = DOKU_INC . 'lib/tpl/' . $tpl . '/'; $tpldir = DOKU_BASE . 'lib/tpl/' . $tpl . '/'; } else { $tplinc = DOKU_TPLINC; $tpldir = DOKU_TPL; } // The generated script depends on some dynamic options $cache = getCacheName('styles' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . DOKU_BASE . $tplinc . $style, '.css'); // load template styles $tplstyles = array(); if (@file_exists($tplinc . 'style.ini')) { $ini = parse_ini_file($tplinc . 'style.ini', true); foreach ($ini['stylesheets'] as $file => $mode) { $tplstyles[$mode][$tplinc . $file] = $tpldir; } } // Array of needed files and their web locations, the latter ones // are needed to fix relative paths in the stylesheets $files = array(); //if (isset($tplstyles['all'])) $files = array_merge($files, $tplstyles['all']); if (!empty($style)) { $files[DOKU_INC . 'lib/styles/' . $style . '.css'] = DOKU_BASE . 'lib/styles/'; // load plugin, template, user styles $files = array_merge($files, css_pluginstyles($style)); if (isset($tplstyles[$style])) { $files = array_merge($files, $tplstyles[$style]); } $files[DOKU_CONF . 'user' . $style . '.css'] = DOKU_BASE; } else { $files[DOKU_INC . 'lib/styles/style.css'] = DOKU_BASE . 'lib/styles/'; if ($conf['spellchecker']) { $files[DOKU_INC . 'lib/styles/spellcheck.css'] = DOKU_BASE . 'lib/styles/'; } // load plugin, template, user styles $files = array_merge($files, css_pluginstyles('screen')); if (isset($tplstyles['screen'])) { $files = array_merge($files, $tplstyles['screen']); } if ($lang['direction'] == 'rtl') { if (isset($tplstyles['rtl'])) { $files = array_merge($files, $tplstyles['rtl']); } } $files[DOKU_CONF . 'userstyle.css'] = DOKU_BASE; } // check cache age & handle conditional request header('Cache-Control: public, max-age=3600'); header('Pragma: public'); if (css_cacheok($cache, array_keys($files), $tplinc)) { http_conditionalRequest(filemtime($cache)); if ($conf['allowdebug']) { header("X-CacheUsed: {$cache}"); } // finally send output if ($conf['gzip_output'] && http_gzip_valid($cache)) { header('Vary: Accept-Encoding'); header('Content-Encoding: gzip'); readfile($cache . ".gz"); } else { if (!http_sendfile($cache)) { readfile($cache); } } return; } else { http_conditionalRequest(time()); } // start output buffering and build the stylesheet ob_start(); // print the default classes for interwiki links and file downloads css_interwiki(); css_filetypes(); // load files foreach ($files as $file => $location) { print css_loadfile($file, $location); } // end output buffering and get contents $css = ob_get_contents(); ob_end_clean(); // apply style replacements $css = css_applystyle($css, $tplinc); // compress whitespace and comments if ($conf['compress']) { $css = css_compress($css); } // save cache file io_saveFile($cache, $css); copy($cache, "compress.zlib://{$cache}.gz"); // finally send output if ($conf['gzip_output']) { header('Vary: Accept-Encoding'); header('Content-Encoding: gzip'); print gzencode($css, 9, FORCE_GZIP); } else { print $css; } }