本文整理汇总了PHP中csstidy::load_template方法的典型用法代码示例。如果您正苦于以下问题:PHP csstidy::load_template方法的具体用法?PHP csstidy::load_template怎么用?PHP csstidy::load_template使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类csstidy
的用法示例。
在下文中一共展示了csstidy::load_template方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: minify
public static function minify($css, $options = array())
{
$options = array_merge(array('remove_bslash' => true, 'compress_colors' => true, 'compress_font-weight' => true, 'lowercase_s' => false, 'optimise_shorthands' => 1, 'remove_last_;' => false, 'case_properties' => 1, 'sort_properties' => false, 'sort_selectors' => false, 'merge_selectors' => 2, 'discard_invalid_properties' => false, 'css_level' => 'CSS2.1', 'preserve_css' => false, 'timestamp' => false, 'template' => 'default'), $options);
set_include_path(get_include_path() . PATH_SEPARATOR . W3TC_LIB_CSSTIDY_DIR);
require_once 'class.csstidy.php';
$csstidy = new csstidy();
foreach ($options as $option => $value) {
$csstidy->set_cfg($option, $value);
}
$csstidy->load_template($options['template']);
$csstidy->parse($css);
$css = $csstidy->print->plain();
if (isset($options['currentDir']) || isset($options['prependRelativePath'])) {
require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS/UriRewriter.php';
$browsercache_id = isset($options['browserCacheId']) ? $options['browserCacheId'] : 0;
$browsercache_extensions = isset($options['browserCacheExtensions']) ? $options['browserCacheExtensions'] : array();
if (isset($options['currentDir'])) {
$document_root = isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'];
$symlinks = isset($options['symlinks']) ? $options['symlinks'] : array();
return Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $document_root, $symlinks, $browsercache_id, $browsercache_extensions);
} else {
return Minify_CSS_UriRewriter::prepend($css, $options['prependRelativePath'], $browsercache_id, $browsercache_extensions);
}
}
return $css;
}
示例2: minify_css
/**
* 压缩css文件
*
* @param mixed $sourceFile
* @param mixed $targetFile
* @return void
*/
function minify_css($sourceFile, $targetFile)
{
$css = new csstidy();
$css->load_template('highest_compression');
/* $css->set_cfg('remove_bslash',false);
$css->set_cfg('compress_colors',false);
$css->set_cfg('compress_font-weight',false);
$css->set_cfg('lowercase_s',true);
$css->set_cfg('optimise_shorthands',$_REQUEST['optimise_shorthands']);
$css->set_cfg('remove_last_;',true);
$css->set_cfg('case_properties',$_REQUEST['case_properties']);
$css->set_cfg('sort_properties',true);
$css->set_cfg('sort_selectors',true);
$css->set_cfg('merge_selectors', $_REQUEST['merge_selectors']);
$css->set_cfg('discard_invalid_properties',true);
$css->set_cfg('preserve_css',true);
$css->set_cfg('timestamp',true);
*/
$strSourceCSS = file_get_contents($sourceFile);
$strResult = $css->parse($strSourceCSS);
$handle = fopen($targetFile, 'w');
if ($handle) {
if (fwrite($handle, $css->print->plain())) {
$file_ok = true;
}
}
fclose($handle);
}
示例3: compress
function compress($Media)
{
$Tidy = new csstidy();
$Tidy->load_template($this->_template);
$Tidy->parse($Media->contents['raw']);
if ($compressed = $Tidy->print->plain()) {
$Media->content['raw'] = $compressed;
return true;
}
return false;
}
示例4: minify
public static function minify($css, $options = array())
{
$options = array_merge(array('remove_bslash' => true, 'compress_colors' => true, 'compress_font-weight' => true, 'lowercase_s' => false, 'optimise_shorthands' => 1, 'remove_last_;' => false, 'case_properties' => 1, 'sort_properties' => false, 'sort_selectors' => false, 'merge_selectors' => 2, 'discard_invalid_properties' => false, 'css_level' => 'CSS2.1', 'preserve_css' => false, 'timestamp' => false, 'template' => 'default'), $options);
set_include_path(get_include_path() . PATH_SEPARATOR . W3TC_LIB_DIR . '/CSSTidy');
require_once 'class.csstidy.php';
$csstidy = new csstidy();
foreach ($options as $option => $value) {
$csstidy->set_cfg($option, $value);
}
$csstidy->load_template($options['template']);
$csstidy->parse($css);
$css = $csstidy->print->plain();
$css = Minify_CSS_UriRewriter::rewrite($css, $options);
return $css;
}
示例5: post_format
/**
* @access public
* @param $source
* @return string
*/
public function post_format($source, $scaffold)
{
$css = new csstidy();
$css->set_cfg('case_properties', false);
$css->set_cfg('lowercase_s', true);
$css->set_cfg('compress_colors', false);
$css->set_cfg('compress_font-weight', false);
$css->set_cfg('merge_selectors', true);
$css->set_cfg('optimise_shorthands', true);
$css->set_cfg('remove_bslash', false);
$css->set_cfg('preserve_css', true);
$css->set_cfg('sort_selectors', true);
$css->set_cfg('sort_properties', true);
$css->set_cfg('remove_last_;', true);
$css->set_cfg('discard_invalid_properties', true);
$css->set_cfg('css_level', '2.1');
$css->set_cfg('timestamp', false);
$css->load_template('highest_compression');
$result = $css->parse($source->contents);
$output = $css->print->plain();
$source->contents = $output;
}
示例6: isset
</label><br />
</fieldset>
<input type="hidden" name="post" />
</div>
</div>
</form>
<?php
$file_ok = false;
$result = false;
$url = isset($_REQUEST['url']) && !empty($_REQUEST['url']) ? $_REQUEST['url'] : false;
if (isset($_REQUEST['template'])) {
switch ($_REQUEST['template']) {
case 4:
if ($is_custom) {
$css->load_template($_REQUEST['custom'], false);
}
break;
case 3:
$css->load_template('highest_compression');
break;
case 2:
$css->load_template('high_compression');
break;
case 0:
$css->load_template('low_compression');
break;
}
}
if ($url) {
if (substr($_REQUEST['url'], 0, 7) !== 'http://') {
示例7: getWorkspacePath
error_reporting(0);
switch ($_GET['action']) {
/**
* Compress a css file.
*
* @param {string} path The path of the file to compress
* @param {string} advanced Either advanced or standard_compression
*/
case 'compressCSS':
if (isset($_GET['path']) && isset($_POST['advanced'])) {
$path = getWorkspacePath($_GET['path']);
$css_code = file_get_contents($path);
$css = new csstidy();
$css->parse($css_code);
if ($_POST['compression'] != "standard_compression") {
$css->load_template($_POST['compression']);
}
if ($_POST['advanced']) {
$css->set_cfg('compress_colors', $_POST['color']);
$css->set_cfg('compress_font-weight', $_POST['fontw']);
$css->set_cfg('remove_last_;', $_POST['bslash']);
$css->set_cfg('remove_bslash', $_POST['last']);
}
$code = $css->print->plain();
$nFile = substr($path, 0, strrpos($path, ".css"));
$nFile = $nFile . ".min.css";
file_put_contents($nFile, $code);
echo '{"status":"success","message":"CSS tidied!"}';
} else {
echo '{"status":"error","message":"Missing Parameter!"}';
}
示例8: minifyCss
/**
* Yii-ified version of CSS.php of the Minify packages with fixed options
*
* @param <type> $css
*/
private function minifyCss($css)
{
Yii::import('application.extensions.csstidy.*');
require_once('class.csstidy.php');
$cssTidy = new csstidy();
$cssTidy->load_template($this->cssTidyTemplate);
foreach($this->cssTidyConfig as $k => $v)
$cssTidy->set_cfg($k, $v);
$cssTidy->parse($css);
return $cssTidy->print->plain();
}
示例9: array
// Get scripts from servlet
$json = file_get_contents($getScripts);
$scripts = json_decode($json, true);
//print_r($scripts);
//$css_core = array();
$core_files = array();
$errors = array();
$warnings = array();
$completed = array();
$script_hash = array();
$script_size = array();
$full_script_size = array();
// Load, concat and minify css
foreach ($scripts['css'] as $core_name => $core_group) {
$cssTidy = new csstidy();
$cssTidy->load_template('highest_compression');
$cssTidy->settings['merge_selectors'] = 2;
$core_files[$core_name] = "";
$script_hash[$core_name] = getFileHash($pathToCore . "/{$core_name}");
$script_size[$core_name] = getFileSize($pathToCore . "/{$core_name}");
$full_script_size[$core_name] = 0;
foreach ($core_group as $script) {
$filePath = $pathToRoot . $script;
if (file_exists($filePath)) {
/*
$core_files[$core_name] .= Minify_CSS::minify(file_get_contents($filePath), array(
'currentDir' => dirname($filePath)
));
*/
//echo "Proccessing: $filePath<br />\n";
$full_script_size[$core_name] += getFileSize($filePath);
示例10: dirname
#!/usr/bin/php
<?php
# Uses the CSS Tidy package <http://csstidy.sourceforge.net/index.php>, licensed under the GPL
include dirname(__FILE__) . '/../../SharedSupport/csstidy/class.csstidy.php';
$input = file_get_contents('php://stdin');
# might need to add some options to the css tidy
# class.
$css = new csstidy();
$css->parse($input);
$css->load_template('low_compression');
echo $css->print->plain();
示例11: array
header('Content-Type: text/css');
$cache_dir = "/cache/csscache";
if (!file_exists($cache_dir)) {
$status = @mkdir($cache_dir, 0755);
}
$cssdata = file_get_contents($css_file);
$cssmd5 = md5($cssdata);
$cache_file = $cache_dir . "/" . base64_encode($_SERVER['SERVER_NAME'] . "/" . $css_file);
$data = array();
if (file_exists($cache_file)) {
$data = unserialize(file_get_contents($cache_file));
}
if (!isset($data['md5']) || $cssmd5 != $data['md5']) {
require_once 'external/csstidy/class.csstidy.php';
$css = new csstidy();
$css->load_template('high_compression');
$result = $css->parse($cssdata);
$css->set_cfg('optimise_shorthands', 1);
$css->set_cfg('merge_selectors', 2);
$css->set_cfg('compress_colors', true);
$css->set_cfg('compress_font-weight', true);
$css->set_cfg('remove_bslash', true);
$output = $css->print->plain();
$fp = @fopen($cache_file, 'w');
$data['md5'] = $cssmd5;
$data['css'] = $output;
@fwrite($fp, serialize($data));
@fclose($fp);
}
if (!isset($data['css'])) {
$data['css'] = $cssdata;
示例12: InitCssCompressor
/**
* Создает css-компрессор и инициализирует его конфигурацию
*
* @return bool
*/
protected function InitCssCompressor()
{
/**
* Получаем параметры из конфигурации
*/
$aParams = Config::Get('compress.css');
$this->oCssCompressor = $aParams['use'] ? new csstidy() : null;
/**
* Если компрессор не создан, завершаем работу инициализатора
*/
if (!$this->oCssCompressor) {
return false;
}
/**
* Устанавливаем параметры
*/
$this->oCssCompressor->set_cfg('case_properties', $aParams['case_properties']);
$this->oCssCompressor->set_cfg('merge_selectors', $aParams['merge_selectors']);
$this->oCssCompressor->set_cfg('optimise_shorthands', $aParams['optimise_shorthands']);
$this->oCssCompressor->set_cfg('remove_last_;', $aParams['remove_last_;']);
$this->oCssCompressor->set_cfg('css_level', $aParams['css_level']);
$this->oCssCompressor->load_template($aParams['template']);
return true;
}
示例13: dirname
<?php
include('class.csstidy.php');
$css_file = dirname(__FILE__). "/tmp_csstidy_code.css";
$f = fopen($css_file, "r");
$css_code = fread($f, filesize($css_file));
fclose($f);
$css = new csstidy();
$css->load_template("highest_compression");
$css->set_cfg('remove_last_;',TRUE);
$css->parse($css_code);
print $css->print->plain();
?>
示例14: csstidy
<?php
require_once 'csstidy/csstidy.class.php';
require_once 'csstidy.config.php';
$config = parse_ini_file("./simpleconfig.ini", true);
$config['csstidy']['vendor_prefix'] = '-moz-';
$csstidy = new csstidy($csstidy_config, $config['csstidy']);
$csstidy->load_template('no_compression');
$file = file_get_contents("./qutim.pure.css");
$csstidy->parse($file);
//var_dump($csstidy);
echo $csstidy->return_plain_output_css();
//print_r($csstidy->get_log());
foreach ($csstidy->get_log() as $l => $m) {
foreach ($m as $me => $t) {
echo $t['t'] . ": " . $t['m'] . "\n";
}
}
$csstidy->get_diff();
示例15: process
function process($type, $data)
{
switch ($type) {
case 'js':
$path = JS;
break;
case 'css':
$path = CSS;
break;
}
$folder = new Folder();
//make sure the cache folder exists
if ($folder->create($path . $this->cachePath, "777")) {
/* trigger_error('Could not create ' . $path . $this->cachePath
. '. Please create it manually with 777 permissions', E_USER_WARNING);*/
}
//check if the cached file exists
$names = Set::extract($data, '{n}.name');
$folder->cd($path . $this->cachePath);
$fileName = $folder->find($this->__generateFileName($names) . '_([0-9]{10}).' . $type);
if ($fileName) {
//take the first file...really should only be one.
$fileName = $fileName[0];
}
//make sure all the pieces that went into the packed script
//are OLDER then the packed version
if ($this->checkTS && $fileName) {
$packed_ts = filemtime($path . $this->cachePath . $fileName);
$latest_ts = 0;
$scripts = Set::extract($data, '{n}.script');
foreach ($scripts as $script) {
$latest_ts = max($latest_ts, filemtime($path . $script . '.' . $type));
}
//an original file is newer. need to rebuild
if ($latest_ts > $packed_ts) {
unlink($path . $this->cachePath . $fileName);
$fileName = null;
}
}
//file doesn't exist. create it.
if (!$fileName) {
$ts = time();
//merge the script
$scriptBuffer = '';
$scripts = Set::extract($data, '{n}.script');
foreach ($scripts as $script) {
$buffer = file_get_contents($path . $script . '.' . $type);
switch ($type) {
case 'js':
//jsmin only works with PHP5
if (PHP5) {
App::import('Vendor', 'jsmin/jsmin');
$buffer = trim(JSMin::minify($buffer));
}
break;
case 'css':
vendor('csstidy/class.csstidy');
$tidy = new csstidy();
$tidy->load_template($this->cssCompression);
$tidy->parse($buffer);
$buffer = $tidy->print->plain();
break;
}
$scriptBuffer .= "\n/* {$script}.{$type} */\n" . $buffer;
}
//write the file
$fileName = $this->__generateFileName($names) . '_' . $ts . '.' . $type;
$file = new File($path . $this->cachePath . $fileName);
$file->write(trim($scriptBuffer));
}
if ($type == 'css') {
//$html->css doesn't check if the file already has
//the .css extension and adds it automatically, so we need to remove it.
$fileName = str_replace('.css', '', $fileName);
}
return $fileName;
}