/** * @see PreFileFilter::__invoke() */ public static function __invoke($code, \Lohini\WebLoader\WebLoader $loader, $file = NULL) { if ($file === NULL || strtolower(pathinfo($file, PATHINFO_EXTENSION)) != 'xcss') { return $code; } $config = ['path_to_css_dir' => WWW_DIR . '/css', 'xCSS_files' => []]; define('XCSSCLASS', ''); $filter = new \xCSS($config); return $filter->compile(file_get_contents($file)); }
/** * The xCSS processor itself. * * @param sfWebRequest $request * * @return string */ public function execute($request) { // we do not care, whether this is a valid CSS file here $this->requestedCSSFile = $request->getParameter('file'); $targetFile = sfXCSSTools::getCacheOutputDirectory() . $this->requestedCSSFile; // because we cache the generated files, we check for an existing one if (file_exists($targetFile) === false) { $config = sfXCSSPluginConfiguration::getXCSSConfiguration(true); $config['xCSS_files'] = array($this->requestedCSSFile => $targetFile); $xCSS = new xCSS($config); $xCSS->compile(); } $this->xcss = file_get_contents($targetFile); chmod($targetFile, 0666); return sfView::SUCCESS; }
<?php /** * xCSS index file * * @author Anton Pawlik * @see http://xcss.antpaw.org/docs/ * @copyright (c) 2010 Anton Pawlik * @license http://xcss.antpaw.org/about/ */ define('XCSSCLASS', 'xcss-class.php'); file_exists(XCSSCLASS) ? include XCSSCLASS : die('alert("xCSS Parse error: Can\'t find the xCSS class file: \'' . XCSSCLASS . '\'.");'); define('XCSSCONFIG', 'config.php'); file_exists(XCSSCONFIG) ? include XCSSCONFIG : die('alert("xCSS Parse error: Can\'t find the xCSS config file: \'' . XCSSCONFIG . '\'.");'); $xCSS = new xCSS($config); $xCSS->compile();
/** * Build the css if necessary * */ function R3BuildCSS($force = false) { global $auth, $xcssConfig; $thema = 'orange'; $appCode = strtolower(APPLICATION_CODE); $path = R3_UPLOAD_DATA_DIR . strtolower(R3EcoGisHelper::getCurrentDomainName()) . "/style/"; $xcssConfig['master_filename'] = "{$path}{$appCode}_{$thema}.css"; $xcssConfig['xCSS_files']["{$thema}.xcss"] = "{$thema}.xcss"; if (file_exists("{$path}custom.css")) { $xcssConfig['xCSS_files']["{$path}custom.css"] = "custom.css"; } if (!$force) { $rebuild = !file_exists($xcssConfig['master_filename']); if (!$rebuild) { $compiledAge = filemtime($xcssConfig['master_filename']); $files = $xcssConfig['xCSS_files']; if (isset($xcssConfig['prepend'])) { foreach ($xcssConfig['prepend'] as $f) { $files[$f] = basename($f); } } foreach ($files as $srcFile => $dummy) { if (filemtime($srcFile[0] == '/' ? $srcFile : $xcssConfig['path_to_css_dir'] . $srcFile) > $compiledAge) { // Complie needed $rebuild = true; break; } } } } if ($force || $rebuild) { ezcLog::getInstance()->log("CSS rebuild for \"{$xcssConfig['master_filename']}\"", ezcLog::DEBUG); define('XCSSCLASS', 'xcss-class.php'); require_once R3_LIB_DIR . 'xcss-class.php'; checkPath(dirname($xcssConfig['master_filename']), true, true); $xCSS = new xCSS($xcssConfig); $xCSS->compile(); } }
<?php /** * xCSS string-compiler file * */ $xcss_string = '.selector { color: red; }'; define('XCSSCLASS', '../xcss-class.php'); include XCSSCLASS; define('XCSSCONFIG', '../config.php'); include XCSSCONFIG; $xCSS = new xCSS($config); echo '<script type="text/javascript">' . "\n"; $css_string = $xCSS->compile($xcss_string); unset($xCSS); echo '</script>' . "\n"; echo '<style type="text/css">' . "\n"; echo $css_string; echo '</style>' . "\n";