本文整理汇总了PHP中CSS::minify方法的典型用法代码示例。如果您正苦于以下问题:PHP CSS::minify方法的具体用法?PHP CSS::minify怎么用?PHP CSS::minify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSS
的用法示例。
在下文中一共展示了CSS::minify方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: styles
/**
* Styles output, if cache exsists will return cached file, else will cache then return cached file
*
* @param array
*
* return array
*/
public static function styles($todo)
{
if (!empty($todo)) {
$dir = self::get_page_cache_dir('styles');
if (!$dir) {
return $todo;
}
$enque_styles = array();
$fname = self::$is_footer ? 'footer' : 'header';
$cache_dir = self::create_scripts_dir('styles', $fname);
$file_path = self::get_cache_dir(true);
$file_path .= $dir . pathinfo($cache_dir, PATHINFO_BASENAME);
if (!self::$is_footer || is_file($cache_dir)) {
$enque_styles[] = 'themify_cache_' . $fname;
wp_enqueue_style('themify_cache_' . $fname, $file_path, array(), THEMIFY_VERSION);
}
if (is_file($cache_dir)) {
return $enque_styles;
}
global $wp_styles;
foreach ($todo as $handler) {
if (isset($wp_styles->registered[$handler]) && $wp_styles->registered[$handler]->src && !isset(self::$header_styles[$handler]) && !isset(self::$footer_styles[$handler])) {
if (!isset($wp_styles->registered[$handler]->extra['conditional']) || !$wp_styles->registered[$handler]->extra['conditional'] || !$wp_styles->registered[$handler]['args'] || $wp_styles->registered[$handler]['args'] == 'screen' || $wp_styles->registered[$handler]['args'] == 'all') {
if (self::$is_footer || $wp_styles->groups[$handler] == 1) {
self::$footer_styles[$handler]['src'] = $wp_styles->registered[$handler]->src;
} else {
self::$header_styles[$handler]['src'] = $wp_styles->registered[$handler]->src;
}
} else {
$enque_styles[] = $handler;
}
}
}
$styles = self::$is_footer ? self::$footer_styles : self::$header_styles;
$minifier = new CSS();
foreach ($styles as $value) {
if (self::is_remote($value['src'])) {
if (strpos($value['src'], '//') === 0) {
$value['src'] = 'http:' . $value['src'];
}
$response = wp_remote_get($value['src'], array('timeout' => 4, 'sslverify' => false));
if (is_array($response)) {
$minifier->add($response['body']);
}
} else {
$path = self::get_full_path($value['src']);
if (!file_exists($path)) {
$response = wp_remote_get($value['src'], array('timeout' => 4, 'sslverify' => false));
if (is_array($response)) {
$minifier->add($response['body']);
}
} else {
$minifier->add($path);
}
}
}
if (self::$is_footer) {
$temp_dir = pathinfo($cache_dir);
$cache_dir = $temp_dir['dirname'] . '/' . $temp_dir['filename'] . '-tmp.css';
$content = $minifier->minify();
self::$footer_file['css'] = array('dir' => $cache_dir, 'path' => $file_path);
if (file_put_contents($cache_dir, $content, FILE_APPEND)) {
return $enque_styles;
}
} else {
$minifier->minify($cache_dir);
return $enque_styles;
}
}
return $todo;
}