Update of /cvsroot/thyapi/thyapi/thythemes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25920/thythemes
Added Files:
theme_loader.php
Log Message:
Commiting file additions and modification from SVN revision 1841 to 1842...
Changes made by vinicius on 2005-08-23 15:49:13 +0200 (Tue, 23 Aug 2005) corresponding to SVN revision 1842 with message:
License file included in thyapi
--- NEW FILE: theme_loader.php ---
<?php
/***************************************************************************\
* ThyAPI - Thyamad Javascript API - CSS inclusion parser *
* http://www.thyamad.com *
* *
* Copyright (C) 2005 - Raphael Derosso Pereira *
* Based on DynAPI v3.0b1 *
* ------------------------------------------------------------------------- *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation; either version 2.1 of the License, *
* or any later version. *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
\***************************************************************************/
/* Topic: Theme Loader
*
* To use this loader, just define GLOBALS['thyapi']['theme'] in the form:
*
* array( 'name' => <theme_name>, 'custom' => <dir> );
*
* <dir> can be a string or an array of strings
*
* Every css will be parsed and included on a single output, which will
* be cached by browser.
*
* The suggestion is to create a PHP file, with the needed definitions
* and include this file, placing a:
*
* <link href="<your_file>" type="text/css" />
*
* In your output to the browser.
*/
class thyapi_theme
{
var $custom;
function thyapi_theme()
{
if (!$GLOBALS['thyapi']['theme']) return;
if (!is_array($GLOBALS['thyapi']['theme']['custom']))
{
$this->custom = array( &$GLOBALS['thyapi']['theme']['custom'] );
}
else
{
$this->custom =& $GLOBALS['thyapi']['theme']['custom'];
}
$css = '';
if ($GLOBALS['thyapi']['theme']['dir'])
{
$css = $this->parse_css($GLOBALS['thyapi']['theme']['dir']);
}
foreach ($this->custom as $custom)
{
$css .= $this->parse_css($custom);
}
$this->compress_css($css);
// If using Apache compression AND HTTPS, do not compress this output! \\
if ($_SERVER['HTTPS'] == 'on')
{
apache_setenv('no-gzip', 1);
}
header('Expires: '.gmdate("D, d M Y H:i:s", time() + 86400).' GMT');
header('Cache-Control: max-age=86400, must-revalidate, public');
header('Pragma: ');
header('Content-type: text/css');
header('Content-length: '.strlen($css));
echo $css;
}
function parse_css($dir='.')
{
$css = '';
$files = array();
if (is_dir($dir))
{
$d = dir($dir);
while (($file = $d->read()) !== false)
{
if (eregi('css$',$file))
{
$files[$file] = file($dir . '/' . $file);
}
}
}
ksort($files);
foreach ($files as $file)
{
$css .= str_replace('{css_dir}',$dir,@implode($file));
}
return $css;
}
function compress_css(&$contents)
{
// Remove empty lines \\
$contents = preg_replace("/\n( |\t)*/",'',$contents);
$contents = preg_replace("/\n(\s*)\n/",'',$contents);
// Remove C-like comments \\
$contents = preg_replace('/\/\*(.(?!\*\/))*.\*\//s','',$contents);
// Remove double spaces \\
$contents = preg_replace('/\s{2,}/',' ',$contents);
}
}
$theme = new thyapi_theme();
|