* @version 1.0 */ class CSS { // Include these style sheets. var $_css_files = array(); // Cache style sheets? var $_params = array( 'cache_css' => true, 'character_set' => 'ISO-8859-1', ); /** * Constructor. */ function __construct() { $this->_params['character_set'] = isset($CFG->character_set) ? $CFG->character_set : $this->_params['character_set']; } /** * Set (or overwrite existing) parameters by passing an array of new parameters. * * @access public * * @param array $params Array of parameters (key => val pairs). */ function setParam($params=null) { if (isset($params) && is_array($params)) { // Merge new parameters with old overriding only those passed. $this->_params = array_merge($this->_params, $params); } else { logMsg(sprintf('Supplied argument is not an array: %s', $params), LOG_WARNING, __FILE__, __LINE__); } } /** * Return the value of a parameter. * * @access public * * @param string $param The key of the parameter to return. * * @return mixed Parameter value. */ function getParam($param) { return $this->_params[$param]; } /** * Add a file-path to the array of files to include as CSS. * * @access public * * @param string Full path to css file. * * @return bool True on success, false on failure. */ function setFile($file) { if (file_exists($file)) { $this->_css_files[] = $file; return true; } else { logMsg(sprintf('CSS file non-existant: %s', $file), LOG_WARNING, __FILE__, __LINE__); return false; } } /** * Output headers for CSS. * * @access public * * @return bool False if no files have been set. */ function headers() { if (empty($this->_css_files)) { logMsg(sprintf('CSS::headers called without specifiying any files.', null), LOG_NOTICE, __FILE__, __LINE__); return false; } // Get time of latest modified file. $files_mtime = array_map('filemtime', array_merge($this->_css_files, array(__FILE__))); sort($files_mtime, SORT_NUMERIC); $mtime = array_pop($files_mtime); if ($this->_params['cache_css']) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $mtime) . ' GMT'); header('Cache-Control: public, max-age=86400'); } else { header('Expires: -1'); header('Pragma: no-cache'); header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); } header('Content-Type: text/css; charset=' . $this->_params['character_set']); } /** * Include CSS files specified by setFile(). * * @access public * * @return bool False if no files have been set. */ function output() { if (empty($this->_css_files)) { logMsg(sprintf('CSS::output called without specifiying any files.', null), LOG_NOTICE, __FILE__, __LINE__); return false; } foreach ($this->_css_files as $file) { include $file; } } } ?>