This is a heavy regex-based removal of whitespace, unnecessary comments and tokens. IE conditional comments are preserved. There are also options to have STYLE and SCRIPT blocks compressed by callback functions. A test suite is available.
Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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;
     }
 }
Exemplo n.º 3
0
    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;
    }
Exemplo n.º 4
0
 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), '&nbsp;', $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;
 }
Exemplo n.º 5
0
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";
        }
    }
}
Exemplo n.º 6
0
 /**
  * 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;
 }
Exemplo n.º 7
0
 public function htmlMin($htmlText = "")
 {
     if ($this->shouldMinify) {
         $htmlText = \Minify_HTML::minify($htmlText);
     }
     return $htmlText;
 }
Exemplo n.º 8
0
 /**
  * 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);
 }
Exemplo n.º 9
0
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;
}
Exemplo n.º 10
0
 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()));
 }
 /**
  * @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;
 }
 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;
 }
Exemplo n.º 13
0
 /**
  * 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);
     }
 }
Exemplo n.º 14
0
 /**
  * Minification des commentaires
  * 
  * Le cas <!--extra--> doit être conservé dans les commentaires,
  * tout comme <!--keepme: xxx -->
  *
  * @param array $m    Matches du preg_match d'un commentaire HTML
  * @return string     Contenu minifié
  */
 protected function _commentCB($m)
 {
     if ($m[1] === 'extra') {
         return $m[0];
     }
     if ($m[1] and $m[1][0] === 'k' and substr($m[1], 0, 7) === 'keepme:') {
         return $m[0];
     }
     return parent::_commentCB($m);
 }
Exemplo n.º 15
0
 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);
 }
Exemplo n.º 16
0
 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);
     }
 }
Exemplo n.º 17
0
 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), '&nbsp;', $html_content);
         $html_content = Minify_HTML::minify($html_content, array('xhtml', 'cssMinifier', 'jsMinifier'));
         return $html_content;
     }
     return false;
 }
Exemplo n.º 18
0
function htmlia_js_css_compress($html)
{
    /** 
     * some minify codes here ...
     */
    require_once 'min/lib/Minify/Loader.php';
    // Reuired to minify CSS
    require_once 'min/lib/Minify/HTML.php';
    require_once 'min/lib/Minify/CSS.php';
    require_once 'min/lib/JSMin.php';
    // return Minify_HTML::minify( $html );
    Minify_Loader::register();
    // Requeired by CSS
    return Minify_HTML::minify($html, array('jsMinifier' => array('JSMin', 'minify'), 'cssMinifier' => array('Minify_CSS', 'minify')));
}
Exemplo n.º 19
0
 public function minify()
 {
     if (class_exists('Minify_HTML')) {
         // noptimize me
         $this->content = $this->hide_noptimize($this->content);
         // Minify html
         $options = array('keepComments' => $this->keepcomments);
         $this->content = Minify_HTML::minify($this->content, $options);
         // restore noptimize
         $this->content = $this->restore_noptimize($this->content);
         return true;
     }
     //Didn't minify :(
     return false;
 }
Exemplo n.º 20
0
 public function save($content)
 {
     if (!$this->enable) {
         return;
     }
     $identify = $this->getIdentify();
     $file = $this->root_dir . 'cache/' . $identify;
     if (!is_dir(dirname($file))) {
         mkdir(dirname($file));
     }
     if (file_exists($file)) {
         unlink($file);
     }
     $content = Minify_HTML::minify($content);
     file_put_contents($file, $content);
 }
Exemplo n.º 21
0
 /**
  * Minify HTML
  *
  * @param string $htmlContent
  *
  * @return bool|mixed|string
  */
 public static function minifyHTML($htmlContent)
 {
     if (strlen($htmlContent) > 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,
         // Media::getBackTrackLimit());
         $htmlContent = str_replace(chr(194) . chr(160), '&nbsp;', $htmlContent);
         if (trim($minified_content = \Minify_HTML::minify($htmlContent, array('cssMinifier', 'jsMinifier'))) != '') {
             $htmlContent = $minified_content;
         }
         return $htmlContent;
     }
     return false;
 }
Exemplo n.º 22
0
 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,
         			Media::getBackTrackLimit());*/
         require_once _PS_TOOL_DIR_ . 'minify_html/minify_html.class.php';
         $html_content = str_replace(chr(194) . chr(160), '&nbsp;', $html_content);
         if (trim($minified_content = Minify_HTML::minify($html_content, array('xhtml', 'cssMinifier', 'jsMinifier'))) != '') {
             $html_content = $minified_content;
         }
         return $html_content;
     }
     return false;
 }
 public function index($setting)
 {
     if (!defined('JOURNAL_INSTALLED')) {
         return;
     }
     if (!$this->model_journal2_blog->isEnabled()) {
         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 (Journal2Cache::$mobile_detect->isMobile() && !Journal2Cache::$mobile_detect->isTablet() && $this->journal2->settings->get('responsive_design')) {
         return;
     }
     $hash = isset($this->request->server['REQUEST_URI']) ? md5($this->request->server['REQUEST_URI']) : null;
     $cache_property = "module_journal_blog_comments_{$setting['module_id']}_{$setting['layout_id']}_{$setting['position']}_{$hash}";
     $cache = $this->journal2->cache->get($cache_property);
     if ($cache === null || self::$CACHEABLE !== true || $hash === null) {
         $module = mt_rand();
         $this->data['module'] = $module;
         $this->data['heading_title'] = Journal2Utils::getProperty($module_data, 'module_data.title.value.' . $this->config->get('config_language_id'), 'Not Translated');
         $this->data['default_author_image'] = $this->model_tool_image->resize('data/journal2/misc/avatar.png', 75, 75);
         $this->data['comments'] = array();
         $comments = $this->model_journal2_blog->getLatestComments(Journal2Utils::getProperty($module_data, 'module_data.limit', 5));
         $char_limit = Journal2Utils::getProperty($module_data, 'module_data.char_limit', 50);
         foreach ($comments as $comment) {
             $this->data['comments'][] = array('email' => $comment['email'], 'name' => $comment['name'], 'comment' => utf8_substr(strip_tags(html_entity_decode($comment['comment'], ENT_QUOTES, 'UTF-8')), 0, $char_limit) . '...', 'post' => $comment['post'], 'href' => $this->url->link('journal2/blog/post', 'journal_blog_post_id=' . $comment['post_id']) . '#c' . $comment['comment_id']);
         }
         $this->template = $this->config->get('config_template') . '/template/journal2/module/blog_comments.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;
     }
     $output = $this->render();
     Journal2::stopTimer(get_class($this));
     return $output;
 }
 public function index($setting)
 {
     if (!defined('JOURNAL_INSTALLED')) {
         return;
     }
     if (!$this->model_journal2_blog->isEnabled()) {
         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 (Journal2Cache::$mobile_detect->isMobile() && !Journal2Cache::$mobile_detect->isTablet() && $this->journal2->settings->get('responsive_design')) {
         return;
     }
     $hash = isset($this->request->server['REQUEST_URI']) ? md5($this->request->server['REQUEST_URI']) : null;
     $cache_property = "module_journal_blog_search_{$setting['module_id']}_{$setting['layout_id']}_{$setting['position']}_{$hash}";
     $cache = $this->journal2->cache->get($cache_property);
     if ($cache === null || self::$CACHEABLE !== true || $hash === null) {
         $module = mt_rand();
         $this->data['module'] = $module;
         $this->data['heading_title'] = Journal2Utils::getProperty($module_data, 'module_data.title.value.' . $this->config->get('config_language_id'));
         $this->data['placeholder'] = Journal2Utils::getProperty($module_data, 'module_data.placeholder.value.' . $this->config->get('config_language_id'), 'Blog Search');
         $this->data['search_url'] = str_replace('&amp;', '&', $this->url->link('journal2/blog', 'journal_blog_search='));
         if (isset($this->request->get['journal_blog_search'])) {
             $this->data['search'] = trim($this->request->get['journal_blog_search']);
         } else {
             $this->data['search'] = '';
         }
         $this->template = $this->config->get('config_template') . '/template/journal2/module/blog_search.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;
     }
     $output = $this->render();
     Journal2::stopTimer(get_class($this));
     return $output;
 }
Exemplo n.º 25
0
 public function minify()
 {
     $noptimizeHTML = apply_filters('autoptimize_filter_html_noptimize', false, $this->content);
     if ($noptimizeHTML) {
         return false;
     }
     if (class_exists('Minify_HTML')) {
         // wrap the to-be-excluded strings in noptimize tags
         foreach ($this->exclude as $exclString) {
             if (strpos($this->content, $exclString) !== false) {
                 $replString = "<!--noptimize-->" . $exclString . "<!--/noptimize-->";
                 $this->content = str_replace($exclString, $replString, $this->content);
             }
         }
         // noptimize me
         $this->content = $this->hide_noptimize($this->content);
         // Minify html
         $options = array('keepComments' => $this->keepcomments);
         if ($this->forcexhtml) {
             $options['xhtml'] = true;
         }
         if (@is_callable(array(new Minify_HTML(), "minify"))) {
             $tmp_content = Minify_HTML::minify($this->content, $options);
             if (!empty($tmp_content)) {
                 $this->content = $tmp_content;
                 unset($tmp_content);
             }
         }
         // restore noptimize
         $this->content = $this->restore_noptimize($this->content);
         // remove the noptimize-wrapper from around the excluded strings
         foreach ($this->exclude as $exclString) {
             $replString = "<!--noptimize-->" . $exclString . "<!--/noptimize-->";
             if (strpos($this->content, $replString) !== false) {
                 $this->content = str_replace($replString, $exclString, $this->content);
             }
         }
         return true;
     }
     // Didn't minify :(
     return false;
 }
Exemplo n.º 26
0
 public function minify()
 {
     if (class_exists('Minify_HTML')) {
         // noptimize me
         $this->content = $this->hide_noptimize($this->content);
         // Minify html
         $options = array('keepComments' => $this->keepcomments);
         if (@is_callable(array(new Minify_HTML(), "minify"))) {
             $tmp_content = Minify_HTML::minify($this->content, $options);
             if (!empty($tmp_content)) {
                 $this->content = $tmp_content;
                 unset($tmp_content);
             }
         }
         // restore noptimize
         $this->content = $this->restore_noptimize($this->content);
         return true;
     }
     //Didn't minify :(
     return false;
 }
Exemplo n.º 27
0
 /**
  * 
  * Minify the HTML code and rewrite the code for 
  * including CSS and JS files to make it redirect to /bin/min/index.php?f
  * @param string $html
  * @return string $html
  */
 public static function MinifyOutput($html)
 {
     $minifyURL = OPENBIZ_APP_URL . "/bin/min/index.php";
     $headEnd = "</head>";
     //fetch js requests
     preg_match_all("/\\<script.*?src\\s?\\=\\s?[\"|\\'](.*?\\.js)[\"|\\']/i", $html, $matches);
     $jsListStr = implode(array_unique($matches[1]), ',');
     $jsURL = $minifyURL . '?f=' . $jsListStr;
     $jsCode = "<script type=\"text/javascript\" src=\"{$jsURL}\"></script>";
     //remove old js include
     $html = preg_replace("/\\<script.*?src\\s?\\=\\s?[\"|\\'].*?\\.js[\"|\\'].*?\\<\\/script\\>/i", "", $html);
     //add new js include
     $html = str_replace($headEnd, $jsCode . "\n" . $headEnd, $html);
     preg_match_all("/\\<link.*?href\\s?\\=\\s?\"(.*?\\.css)\"/i", $html, $matches);
     $cssListStr = implode(array_unique($matches[1]), ',');
     $cssURL = $minifyURL . '?f=' . $cssListStr;
     $cssCode = "<link rel=\"stylesheet\" href=\"{$cssURL}\" type=\"text/css\">";
     $html = preg_replace("/\\<link.*?href\\s?\\=\\s?\"(.*?\\.css)\".*?\\>/i", "", $html);
     $html = str_replace($headEnd, $cssCode . "\n" . $headEnd, $html);
     require_once OPENBIZ_APP_PATH . '/bin/min/lib/Minify/HTML.php';
     $html = Minify_HTML::minify($html);
     return $html;
 }
Exemplo n.º 28
0
 public static function minify($html, $options = array())
 {
     if (isset($options['cssMinifier'])) {
         self::$_cssMinifier = $options['cssMinifier'];
     }
     if (isset($options['jsMinifier'])) {
         self::$_jsMinifier = $options['jsMinifier'];
     }
     $html = str_replace("\r\n", "\n", trim($html));
     self::$_isXhtml = isset($options['xhtml']) ? (bool) $options['xhtml'] : false !== strpos($html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML');
     self::$_replacementHash = 'MINIFYHTML' . md5(time());
     self::$_placeholders = array();
     // replace SCRIPTs (and minify) with placeholders
     $html = preg_replace_callback('/\\s*(<script\\b[^>]*?>)([\\s\\S]*?)<\\/script>\\s*/i', array(self::$className, '_removeScriptCB'), $html);
     // replace STYLEs (and minify) with placeholders
     $html = preg_replace_callback('/\\s*(<style\\b[^>]*?>)([\\s\\S]*?)<\\/style>\\s*/i', array(self::$className, '_removeStyleCB'), $html);
     // remove HTML comments (not containing IE conditional comments).
     $html = preg_replace_callback('/<!--([\\s\\S]*?)-->/', array(self::$className, '_commentCB'), $html);
     // replace PREs with placeholders
     $html = preg_replace_callback('/\\s*(<pre\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i', array(self::$className, '_removePreCB'), $html);
     // replace TEXTAREAs with placeholders
     $html = preg_replace_callback('/\\s*(<textarea\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i', array(self::$className, '_removeTaCB'), $html);
     // trim each line.
     // @todo take into account attribute values that span multiple lines.
     $html = preg_replace('/^\\s+|\\s+$/m', '', $html);
     // remove ws around block/undisplayed elements
     $html = preg_replace('/\\s+(<\\/?(?:area|base(?:font)?|blockquote|body' . '|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form' . '|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta' . '|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h||r|foot|itle)' . '|ul)\\b[^>]*>)/i', '$1', $html);
     // remove ws outside of all elements
     $html = preg_replace_callback('/>([^<]+)</', array(self::$className, '_outsideTagCB'), $html);
     // use newlines before 1st attribute in open tags (to limit line lengths)
     $html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "\$1\n\$2", $html);
     // fill placeholders
     $html = str_replace(array_keys(self::$_placeholders), array_values(self::$_placeholders), $html);
     self::$_placeholders = array();
     self::$_cssMinifier = self::$_jsMinifier = null;
     return $html;
 }
Exemplo n.º 29
0
 /**
  * Will check in the Cache Service if there is something for this partial, then retrieve it,
  * otherwise, will give the PHPRenderer the responsability to execute the view.
  *
  * @param string|\Zend\View\Model\ModelInterface $nameOrModel
  * @param null                                   $values
  *
  * @return mixed|string
  */
 public function render($nameOrModel, $values = null)
 {
     $config = $this->getOptions()->getConfig();
     if (is_string($nameOrModel)) {
         $template = $nameOrModel;
     } elseif ($nameOrModel instanceof PartialViewModel) {
         if (true === $nameOrModel->getIsCached()) {
             return $nameOrModel->getCacheContent();
         }
     } elseif ($nameOrModel instanceof ViewModel) {
         $template = $nameOrModel->getTemplate();
     }
     if (!in_array($template, $config)) {
         return $this->getPhpRenderer()->render($nameOrModel, $values);
     }
     $success = false;
     $html = $this->getCacheManager()->getItem($template, $success);
     if ($success !== true) {
         $html = $this->getPhpRenderer()->render($nameOrModel, $values);
         $html = \Minify_HTML::minify($html);
         $this->getCacheManager()->setItem($template, $html);
     }
     return $html;
 }
Exemplo n.º 30
0
	};
	
	
	
	$(document).ready(function() {
		<? if(!$is_admin_mode) { ?>
		if(!window.opener) {
			alert('잘못된 접근입니다.');
			window.location.href = wiki_url;
			return;
		}
		<? } ?>
		mm.init();
		window.focus();
	});	
</script>

<? include_once "tail.php"; ?>

<?
if($use_minify) {
	$content = ob_get_contents();
	ob_end_clean();
	
	include_once WIKI_PATH."/lib/Minifier/htmlmin.php";
	include_once WIKI_PATH."/lib/Minifier/jsmin.php";
	include_once WIKI_PATH."/lib/Minifier/cssmin.php";
	echo Minify_HTML::minify($content, $options=array("jsMinifier"=>"JSMin::minify", "cssMinifier"=>"CssMin::minify"));
}
?>