Changeset 26


Ignore:
Timestamp:
Dec 3, 2005 11:23:27 PM (18 years ago)
Author:
scdev
Message:

Updated CSS.inc.php to: 1. set different css files attached to an app with /css.php?app=name; 2. use file pointer from fopen() opening file from include path to get mtime.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/CSS.inc.php

    r25 r26  
    77 *
    88 * @author  Quinn Comendant <quinn@strangecode.com>
    9  * @version 1.1
    10  * TODO: set different css files attached to an app with /css.php?app=name
    11  * TODO:
     9 * @version 1.2
    1210 */
    1311class CSS {
    1412
    1513    // Include these style sheets.
    16     var $_css_files = array();
     14    var $_css_files = array('_default' => array());
    1715   
    1816    // Cache style sheets?
     
    6462     * @return  bool    True on success, false on failure.
    6563     */
    66     function setFile($file)
     64    function setFile($file, $app='_default')
    6765    {
    68         if (file_exists($file)) {
    69             $this->_css_files[] = $file;
     66        if ($fp = fopen($file, 'r', true)) {
     67            $this->_css_files[$app][] = $file;
     68            fclose($fp);
    7069            return true;
    7170        } else {
     
    8281     * @return  bool    False if no files have been set.
    8382     */
    84     function headers()
     83    function headers($app='_default')
    8584    {
    86         if (empty($this->_css_files)) {
     85        if (empty($this->_css_files[$app])) {
    8786            App::logMsg(sprintf('CSS::headers called without specifying any files.', null), LOG_WARNING, __FILE__, __LINE__);
    8887            return false;
    8988        }
    90        
     89
    9190        // Get time of latest modified file, including this class file.
    92         $files_mtime = array_map('filemtime', array_merge($this->_css_files, array(__FILE__)));
     91        $files_mtime = array();
     92        foreach (array_merge($this->_css_files[$app], array(__FILE__)) as $file) {
     93            $files_mtime[] = statIncludePath($file, 'mtime');
     94        }
    9395        sort($files_mtime, SORT_NUMERIC);
    94         $mtime = array_pop($files_mtime);
     96        $latest_mtime = array_pop($files_mtime);
    9597       
    9698        if ($this->_params['cache_css']) {
    97             header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $mtime) . ' GMT');
     99            header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $latest_mtime) . ' GMT');
    98100            header('Cache-Control: public, max-age=86400');
    99101        } else {
     
    112114     * @return  bool    False if no files have been set.
    113115     */
    114     function output()
     116    function output($app='_default')
    115117    {
    116         if (empty($this->_css_files)) {
     118        if (empty($this->_css_files[$app])) {
    117119            App::logMsg(sprintf('CSS::output called without specifying any files.', null), LOG_WARNING, __FILE__, __LINE__);
    118120            return false;
    119121        }
    120        
    121         foreach ($this->_css_files as $file) {
    122             include $file;
    123         }
    124122    }
     123   
    125124}
    126125?>
  • trunk/lib/Utilities.inc.php

    r25 r26  
    234234 
    235235    return sprintf($format, $size, $units[$i]);
     236}
     237
     238/**
     239 * Returns stats of a file from the include path.
     240 *
     241 * @param   string  $file   File in include path.
     242 * @return  mixed   Value of requested key from fstat(), or false on error.
     243 * @author  Quinn Comendant <quinn@strangecode.com>
     244 * @since   03 Dec 2005 14:23:26
     245 */
     246function statIncludePath($file, $stat)
     247{
     248    // Open file pointer read-only using include path.
     249    if ($fp = fopen($file, 'r', true)) {
     250        // File opend successfully, get stats.
     251        $stats = fstat($fp);
     252        fclose($fp);
     253        // Return specified stats.
     254        return $stats[$stat];
     255    } else {
     256        return false;
     257    }
    236258}
    237259
Note: See TracChangeset for help on using the changeset viewer.