本文整理汇总了PHP中Minify_HTML类的典型用法代码示例。如果您正苦于以下问题:PHP Minify_HTML类的具体用法?PHP Minify_HTML怎么用?PHP Minify_HTML使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Minify_HTML类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compresshtml
function compresshtml($data)
{
/* remove comments */
$data = preg_replace('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '', $data);
/* remove tabs, spaces, new lines, etc. */
$data = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), ' ', $data);
$compress = new Minify_HTML($data);
$data = $compress->minify($data);
return $data;
}
示例2: output
public function output()
{
if ($this->output) {
if (defined('JOURNAL_INSTALLED')) {
global $registry;
$is_ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
$is_get = !empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) === 'get';
$ignored_routes = array('journal2/assets/css', 'journal2/assets/js', 'feed/google_sitemap');
$request = $registry->get('request');
$current_route = isset($request->get['route']) ? $request->get['route'] : null;
$ignored_route = $current_route !== null && in_array($current_route, $ignored_routes);
$journal2 = $registry->get('journal2');
if (!$ignored_route && !$is_ajax && $is_get && !$journal2->settings->get('config_system_settings.developer_mode') && $journal2->settings->get('config_system_settings.minify_html')) {
$this->output = Minify_HTML::minify($this->output, array('xhtml' => false, 'jsMinifier' => 'j2_js_minify'));
if (Journal2Cache::$page_cache_file) {
file_put_contents(Journal2Cache::$page_cache_file, $this->output);
}
}
}
if ($this->level) {
$output = $this->compress($this->output, $this->level);
} else {
$output = $this->output;
}
if (!headers_sent()) {
foreach ($this->headers as $header) {
header($header, true);
}
}
echo $output;
}
}
示例3: minimize_html
function minimize_html($html)
{
$options = array('xhtml' => true);
$html = Minify_HTML::minify($html, $options);
$html = str_replace('<a
', '<a ', $html);
$html = str_replace('<ul
', '<ul ', $html);
$html = str_replace('<li
', '<li ', $html);
$html = str_replace('<div
', '<div ', $html);
$html = str_replace('<body
', '<body ', $html);
$html = str_replace('<header
', '<header ', $html);
$html = str_replace('<footer
', '<footer ', $html);
$html = str_replace('<link
', '<link ', $html);
$html = str_replace('<article
', '<article ', $html);
$html = str_replace('<span
', '<span ', $html);
$html = str_replace('<p
', '<p ', $html);
$html = str_replace('
itemprop="', ' itemprop="', $html);
return $html;
}
示例4: minifyHTML
public static function minifyHTML($html_content)
{
if (strlen($html_content) > 0) {
//set an alphabetical order for args
$html_content = preg_replace_callback('/(<[a-zA-Z0-9]+)((\\s?[a-zA-Z0-9]+=[\\"\\\'][^\\"\\\']*[\\"\\\']\\s?)*)>/', array('Media', 'minifyHTMLpregCallback'), $html_content);
require_once _PS_TOOL_DIR_ . 'minify_html/minify_html.class.php';
$html_content = str_replace(chr(194) . chr(160), ' ', $html_content);
$html_content = Minify_HTML::minify($html_content, array('xhtml', 'cssMinifier', 'jsMinifier'));
if (Configuration::get('PS_HIGH_HTML_THEME_COMPRESSION')) {
//$html_content = preg_replace('/"([^\>\s"]*)"/i', '$1', $html_content);//FIXME create a js bug
$html_content = preg_replace('/<!DOCTYPE \\w[^\\>]*dtd\\">/is', '', $html_content);
$html_content = preg_replace('/\\s\\>/is', '>', $html_content);
$html_content = str_replace('</li>', '', $html_content);
$html_content = str_replace('</dt>', '', $html_content);
$html_content = str_replace('</dd>', '', $html_content);
$html_content = str_replace('</head>', '', $html_content);
$html_content = str_replace('<head>', '', $html_content);
$html_content = str_replace('</html>', '', $html_content);
$html_content = str_replace('</body>', '', $html_content);
//$html_content = str_replace('</p>', '', $html_content);//FIXME doesnt work...
$html_content = str_replace("</option>\n", '', $html_content);
//TODO with bellow
$html_content = str_replace('</option>', '', $html_content);
$html_content = str_replace('<script type=text/javascript>', '<script>', $html_content);
//Do a better expreg
$html_content = str_replace("<script>\n", '<script>', $html_content);
//Do a better expreg
}
return $html_content;
}
return false;
}
示例5: test_HTML
function test_HTML()
{
global $thisDir;
$src = file_get_contents($thisDir . '/_test_files/html/before.html');
$minExpected = file_get_contents($thisDir . '/_test_files/html/before.min.html');
$time = microtime(true);
$minOutput = Minify_HTML::minify($src, array('cssMinifier' => array('Minify_CSS', 'minify'), 'jsMinifier' => array('JSMin', 'minify')));
$time = microtime(true) - $time;
$passed = assertTrue($minExpected === $minOutput, 'Minify_HTML');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
if ($passed) {
echo "\n---Source: ", countBytes($src), " bytes\n", "---Output: ", countBytes($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n\n";
} else {
echo "\n---Output: ", countBytes($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n", "---Expected: ", countBytes($minExpected), " bytes\n\n{$minExpected}\n\n", "---Source: ", countBytes($src), " bytes\n\n{$src}\n\n\n";
}
}
$src = file_get_contents($thisDir . '/_test_files/html/before2.html');
$minExpected = file_get_contents($thisDir . '/_test_files/html/before2.min.html');
$time = microtime(true);
$minOutput = Minify_HTML::minify($src, array('cssMinifier' => array('Minify_CSS', 'minify'), 'jsMinifier' => array('JSMin', 'minify')));
$time = microtime(true) - $time;
$passed = assertTrue($minExpected === $minOutput, 'Minify_HTML');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
if ($passed) {
echo "\n---Source: ", countBytes($src), " bytes\n", "---Output: ", countBytes($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n\n";
} else {
echo "\n---Output: ", countBytes($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n", "---Expected: ", countBytes($minExpected), " bytes\n\n{$minExpected}\n\n", "---Source: ", countBytes($src), " bytes\n\n{$src}\n\n\n";
}
}
}
示例6: template_post_parse
/**
* Hook for processing template output.
* @param string $template_string The template markup
* @param bool $is_embed Is the template an embed?
* @param int $site_id Site ID
* @return string The final template string
*/
public function template_post_parse($template_string, $is_embed, $site_id)
{
$final_string = $template_string;
// AutoMin model
$this->EE->load->model('automin_model');
// Prior output?
if (isset($this->EE->extensions->last_call) && $this->EE->extensions->last_call) {
$final_string = $this->EE->extensions->last_call;
}
// Is HTML minifcation disabled?
if (!$this->EE->automin_model->should_compress_markup()) {
return $final_string;
}
// Minify
if (!$is_embed) {
// Minify
$data_length_before = strlen($final_string) / 1024;
require_once 'libraries/class.html.min.php';
$final_string = Minify_HTML::minify($final_string);
$data_length_after = strlen($final_string) / 1024;
// Log results
$data_savings_kb = $data_length_before - $data_length_after;
$data_savings_percent = $data_savings_kb / $data_length_before;
$data_savings_message = sprintf('AutoMin Module HTML Compression: Before: %1.0fkb / After: %1.0fkb / Data reduced by %1.2fkb or %1.2f%%', $data_length_before, $data_length_after, $data_savings_kb, $data_savings_percent);
$this->EE->TMPL->log_item($data_savings_message);
}
return $final_string;
}
示例7: htmlMin
public function htmlMin($htmlText = "")
{
if ($this->shouldMinify) {
$htmlText = \Minify_HTML::minify($htmlText);
}
return $htmlText;
}
示例8: minify
/**
* Minifies the passed HTML source.
*/
public function minify($pageContent)
{
Loader::library("3rdparty/minify-2.1.5/min/lib/Minify/HTML", "mainio_minco");
Loader::library("3rdparty/minify-2.1.5/min/lib/Minify/CSS", "mainio_minco");
Loader::library("3rdparty/minify-2.1.5/min/lib/JSMin", "mainio_minco");
$opts = array('cssMinifier' => "Minify_CSS::minify", 'jsMinifier' => "JSMin::minify");
return Minify_HTML::minify($pageContent, $opts);
}
示例9: initial_output
function initial_output($buffer)
{
require_once 'Minify/HTML.php';
require_once 'Minify/CSS.php';
require_once 'JSMin.php';
$buffer = Minify_HTML::minify($buffer, array('cssMinifier' => array('Minify_CSS', 'minify'), 'jsMinifier' => array('JSMin', 'minify')));
return $buffer;
}
示例10: dispatchLoopShutdown
public function dispatchLoopShutdown()
{
$response = $this->getResponse();
if ($response->isException() || $response->isRedirect() || !$response->getBody()) {
return;
}
require_once APPLICATION_PATH . '/../library/Garp/3rdParty/minify/lib/Minify/HTML.php';
$response->setBody(Minify_HTML::minify($response->getBody()));
}
示例11: onKernelResponse
/**
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if ($this->enableListener) {
$response = $event->getResponse();
$content = \Minify_HTML::minify($response->getContent(), array('cssMinifier' => array('Minify_CSS', 'minify'), 'jsMinifier' => array('JSMinPlus', 'minify'), 'xhtml' => false));
$response->setContent($content);
}
return;
}
示例12: index
public function index($setting)
{
if (!defined('JOURNAL_INSTALLED')) {
return;
}
Journal2::startTimer(get_class($this));
/* get module data from db */
$module_data = $this->model_journal2_module->getModule($setting['module_id']);
if (!$module_data || !isset($module_data['module_data']) || !$module_data['module_data']) {
return;
}
if (Journal2Utils::getProperty($module_data, 'module_data.disable_mobile') && (Journal2Cache::$mobile_detect->isMobile() && !Journal2Cache::$mobile_detect->isTablet())) {
return;
}
$cache_property = "module_journal_fullscreen_slider_{$setting['module_id']}_{$setting['layout_id']}_{$setting['position']}";
$cache = $this->journal2->cache->get($cache_property);
if ($cache === null || self::$CACHEABLE !== true) {
$module = mt_rand();
$this->data['module'] = $module;
$this->data['transition'] = Journal2Utils::getProperty($module_data, 'module_data.transition', 'fade');
$this->data['transition_speed'] = Journal2Utils::getProperty($module_data, 'module_data.transition_speed', '700');
$this->data['transition_delay'] = Journal2Utils::getProperty($module_data, 'module_data.transition_delay', '3000');
if (Journal2Utils::getProperty($module_data, 'module_data.transparent_overlay', '')) {
$this->data['transparent_overlay'] = Journal2Utils::resizeImage($this->model_tool_image, Journal2Utils::getProperty($module_data, 'module_data.transparent_overlay', ''));
} else {
$this->data['transparent_overlay'] = '';
}
$this->data['images'] = array();
$images = Journal2Utils::getProperty($module_data, 'module_data.images', array());
$images = Journal2Utils::sortArray($images);
foreach ($images as $image) {
if (!$image['status']) {
continue;
}
$image = Journal2Utils::getProperty($image, 'image');
if (is_array($image)) {
$image = Journal2Utils::getProperty($image, $this->config->get('config_language_id'));
}
$this->data['images'][] = array('image' => Journal2Utils::resizeImage($this->model_tool_image, $image), 'title' => '');
}
$this->template = $this->config->get('config_template') . '/template/journal2/module/fullscreen_slider.tpl';
if (self::$CACHEABLE === true) {
$html = Minify_HTML::minify($this->render(), array('xhtml' => false, 'jsMinifier' => 'j2_js_minify'));
$this->journal2->cache->set($cache_property, $html);
}
} else {
$this->template = $this->config->get('config_template') . '/template/journal2/cache/cache.tpl';
$this->data['cache'] = $cache;
}
$this->document->addStyle('catalog/view/theme/journal2/lib/supersized/css/supersized.css');
$this->document->addScript('catalog/view/theme/journal2/lib/supersized/js/jquery.easing.min.js');
$this->document->addScript('catalog/view/theme/journal2/lib/supersized/js/supersized.3.2.7.min.js');
$output = $this->render();
Journal2::stopTimer(get_class($this));
return $output;
}
示例13: process
/**
* Remove whitespaces from HTML code
*
* @param string $html
* @param boolean $compress_all Compress embedded css and js code
*
* @return string
*/
public static function process($html, array $settings = array())
{
require_once dirname(__FILE__) . '/min-html.php';
$settings = self::$_settings = $settings + array('compress_all' => true, 'css' => array(), 'js' => array(), 'markers' => array('<?'), 'external_services' => true);
if ($settings['compress_all']) {
return Minify_HTML::minify($html, array('cssMinifier' => array(__CLASS__, '_compress_inline_css'), 'jsMinifier' => array(__CLASS__, '_compress_inline_js')));
} else {
return Minify_HTML::minify($html);
}
}
示例14: filter_final_output
public function filter_final_output($buffer)
{
set_include_path(dirname(__FILE__) . '/min/lib' . PATH_SEPARATOR . get_include_path());
require_once 'Minify/Source.php';
require_once 'Minify/HTML.php';
require_once 'Minify/CSS.php';
require_once 'Minify/HTML.php';
require_once 'Minify.php';
require_once 'Minify/Cache/File.php';
return Minify_HTML::minify($buffer);
}
示例15: dispatchLoopShutdown
public function dispatchLoopShutdown()
{
if (!Pimcore_Tool::isHtmlResponse($this->getResponse())) {
return;
}
if ($this->enabled) {
$body = $this->getResponse()->getBody();
$body = Minify_HTML::minify($body);
$this->getResponse()->setBody($body);
}
}