<?php
/* File: $Id: theme.css.php 170 2006-02-18 15:28:10Z l_a_toth $ */
/**
* Parse every css files in $theme/css
*
* @package YaCM Portal System
* @copyright (C) 2004,2005 László Attila Tóth <hide@address.com>
* @license GPL {@link http://www.gnu.org/licenses/gpl.html}
* @link http://panther.web.elte.hu/yacm/
*
* @subpackage themes
* @author László Attila Tóth <hide@address.com>
*/
header('Content-Type: text/css');
if (is_readable('../var/config.php')) {
require_once '../var/config.php';
$THEME_DIRECTORY = Config::web_directory;
} else {
$THEME_DIRECTORY = '.';
}
require_once '../functions.php';
cache_novalidate(300);
$theme = 'default';
if ( array_key_exists( 'PATH_INFO' ,$_SERVER) &&
preg_match('#^/[a-z0-9]+$#',$_SERVER['PATH_INFO'])
)
{
$theme = preg_replace('/^\//','', $_SERVER['PATH_INFO']);
}
if (!preg_match('/^[[:alnum:]]+$/',$theme)) exit;
// theme is now valid
$THEME_DIRECTORY .= '/themes/' . $theme . '/';
$from = array('/\{\$THEME_DIRECTORY\}/');
$to = array($THEME_DIRECTORY);
$from_ie = array('#/\*[^*]*\*/#' );
$to_ie = array('');
$from = array_merge($from_ie, $from );
$to = array_merge($to_ie, $to);
function PrintFile($file) {
global $from, $to;
$fh = fopen($file, 'r');
$buf = fread($fh, filesize($file));
fclose($fh);
echo preg_replace($from, $to,$buf);
}
function TraverseDir($dir) {
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file == '.' or $file == '..' ) continue;
$file = $dir . '/' . $file;
if (is_file( $file ) && preg_match( '/.css$/', $file ) ) {
PrintFile( $file);
} else if ( is_dir( $file) && ! is_link( $file ) ) {
TraverseDir( $file );
}
}
closedir($dh);
}
}
}
TraverseDir( $theme . '/css' );
?>