本文整理汇总了PHP中gpOutput::ParseLess方法的典型用法代码示例。如果您正苦于以下问题:PHP gpOutput::ParseLess方法的具体用法?PHP gpOutput::ParseLess怎么用?PHP gpOutput::ParseLess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gpOutput
的用法示例。
在下文中一共展示了gpOutput::ParseLess方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PreviewCSS
/**
* Preview changes to the custom css/less
*
*/
function PreviewCSS()
{
global $page, $langmessage;
$layout_info = common::LayoutInfo($this->curr_layout, false);
$theme_colors = $this->GetThemeColors($layout_info['dir']);
$color = $layout_info['theme_color'];
// which color option
if (array_key_exists('color', $_REQUEST)) {
if (!isset($theme_colors[$color])) {
message($langmessage['OOPS'] . ' (Invalid Color)');
return false;
}
$color = $_REQUEST['color'];
}
$page->theme_color = $color;
$page->theme_rel = dirname($page->theme_rel) . '/' . $color;
$page->theme_path = dirname($page->theme_path) . '/' . $color;
// which css files
$less = array();
if (file_exists($page->theme_dir . '/' . $page->theme_color . '/style.css')) {
$page->css_user[] = rawurldecode($page->theme_path) . '/style.css';
} else {
$less[] = $page->theme_dir . '/' . $page->theme_color . '/style.less';
}
// variables.less
$var_file = $page->theme_dir . '/' . $page->theme_color . '/variables.less';
if (file_exists($var_file)) {
$less[] = $var_file;
}
$temp = trim($_REQUEST['css']);
if (!empty($temp)) {
$less[] = $_REQUEST['css'] . "\n";
//make sure this is seen as code and not a filename
}
if (count($less)) {
$compiled = gpOutput::ParseLess($less);
if (!$compiled) {
message($langmessage['OOPS'] . ' (Invalid LESS)');
return false;
}
$page->head .= '<style>' . $compiled . '</style>';
}
$page->get_theme_css = false;
}
示例2: CacheLess
/**
* Convert a .less file to .css and include it in the page
* @param mixed $less_files A strin or array of less filesThe absolute or relative path of the .less file
*
*/
static function CacheLess($less_files)
{
global $dataDir;
//generage the name of the css file from the modified times and content length of each imported less file
$files_hash = common::ArrayHash($less_files);
$list_file = $dataDir . '/data/_cache/less_' . $files_hash . '.list';
if (file_exists($list_file)) {
$list = explode("\n", file_get_contents($list_file));
//pop the etag
$etag = array_pop($list);
if (!ctype_alnum($etag)) {
$list[] = $etag;
$etag = false;
}
// generate an etag if needed or if logged in
if (!$etag || common::LoggedIn()) {
$etag = common::FilesEtag($list);
}
$compiled_name = 'less_' . $files_hash . '_' . $etag . '.css';
$compiled_file = '/data/_cache/' . $compiled_name;
if (file_exists($dataDir . $compiled_file)) {
//msg('not using cache');
return $compiled_file;
}
}
$less_files = (array) $less_files;
$compiled = gpOutput::ParseLess($less_files, $files_hash);
if (!$compiled) {
return false;
}
// generate the file name
$etag = common::FilesEtag($less_files);
$compiled_name = 'less_' . $files_hash . '_' . $etag . '.css';
$compiled_file = '/data/_cache/' . $compiled_name;
// save the cache
// use the last line for the etag
$less_files[] = $etag;
$cache = implode("\n", $less_files);
if (!gpFiles::Save($list_file, $cache)) {
return false;
}
//save the css
if (file_put_contents($dataDir . $compiled_file, $compiled)) {
return $compiled_file;
}
return false;
}