minify() public static method

"Minify" an HTML page
public static minify ( string $html, array $options = [] ) : string
$html string
$options array 'cssMinifier' : (optional) callback function to process content of STYLE elements. 'jsMinifier' : (optional) callback function to process content of SCRIPT elements. Note: the type attribute is ignored. 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If unset, minify will sniff for an XHTML doctype.
return string
Beispiel #1
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;
 }
Beispiel #2
0
 public function htmlMin($htmlText = "")
 {
     if ($this->shouldMinify) {
         $htmlText = \Minify_HTML::minify($htmlText);
     }
     return $htmlText;
 }
Beispiel #3
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;
 }
    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;
    }
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";
        }
    }
}
Beispiel #6
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;
     }
 }
Beispiel #7
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;
}
Beispiel #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);
 }
Beispiel #9
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;
 }
Beispiel #12
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;
 }
Beispiel #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);
     }
 }
 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);
     }
 }
 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);
 }
Beispiel #16
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;
 }
 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;
 }
Beispiel #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')));
}
Beispiel #19
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);
 }
Beispiel #20
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;
 }
Beispiel #21
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_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;
 }
 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 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;
 }
Beispiel #25
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;
 }
 /**
  * 
  * 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;
 }
Beispiel #27
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;
 }
Beispiel #28
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"));
}
?>
 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;
     }
     /* device detection */
     $this->data['disable_on_classes'] = array();
     if ($this->journal2->settings->get('responsive_design')) {
         $device = Journal2Utils::getDevice();
         if (Journal2Utils::getProperty($module_data, 'module_data.enable_on_phone', '1') == '0') {
             if ($device === 'phone') {
                 return;
             } else {
                 $this->data['disable_on_classes'][] = 'hide-on-phone';
             }
         }
         if (Journal2Utils::getProperty($module_data, 'module_data.enable_on_tablet', '1') == '0') {
             if ($device === 'tablet') {
                 return;
             } else {
                 $this->data['disable_on_classes'][] = 'hide-on-tablet';
             }
         }
         if (Journal2Utils::getProperty($module_data, 'module_data.enable_on_desktop', '1') == '0') {
             if ($device === 'desktop') {
                 return;
             } else {
                 $this->data['disable_on_classes'][] = 'hide-on-desktop';
             }
         }
     }
     $hash = isset($this->request->server['REQUEST_URI']) ? md5($this->request->server['REQUEST_URI']) : null;
     if (in_array($setting['position'], array('top', 'bottom'))) {
         $padding = $this->journal2->settings->get('module_margins', 20) . 'px';
         /* outer */
         $css = Journal2Utils::getBackgroundCssProperties(Journal2Utils::getProperty($module_data, 'module_data.background'));
         $css[] = 'padding-top: ' . Journal2Utils::getProperty($module_data, 'module_data.margin_top', 0) . 'px';
         $css[] = 'padding-bottom: ' . Journal2Utils::getProperty($module_data, 'module_data.margin_bottom', 0) . 'px';
         $this->journal2->settings->set('module_journal2_blog_posts_' . $setting['module_id'], implode('; ', $css));
         $this->journal2->settings->set('module_journal2_blog_posts_' . $setting['module_id'] . '_classes', implode(' ', $this->data['disable_on_classes']));
         /* inner css */
         $css = array();
         if (Journal2Utils::getProperty($module_data, 'module_data.fullwidth')) {
             $css[] = 'max-width: 100%';
             $css[] = 'padding-left: ' . $padding;
             $css[] = 'padding-right: ' . $padding;
         } else {
             $css[] = 'max-width: ' . $this->journal2->settings->get('site_width', 1024) . 'px';
             $css = array_merge($css, Journal2Utils::getBackgroundCssProperties(Journal2Utils::getProperty($module_data, 'module_data.module_background')));
             if (Journal2Utils::getProperty($module_data, 'module_data.module_padding')) {
                 $this->data['gutter_on_class'] = 'gutter-on';
                 $css[] = 'padding: 20px';
             }
         }
         $this->data['css'] = implode('; ', $css);
     }
     $cache_property = "module_journal_blog_posts_{$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['display'] = Journal2Utils::getProperty($module_data, 'module_data.display', 'grid');
         $this->data['content_align'] = Journal2Utils::getProperty($module_data, 'module_data.content_align', 'center');
         /* carousel */
         $this->data['carousel'] = Journal2Utils::getProperty($module_data, 'module_data.carousel');
         if ($this->data['carousel']) {
             $columns = in_array($setting['position'], array('top', 'bottom')) ? 0 : $this->journal2->settings->get('config_columns_count', 0);
             if ($this->data['display'] === 'list') {
                 $this->data['grid'] = array(array(0, 1), array(470, 1), array(760, 1), array(980, 1), array(1100, 1));
             } else {
                 $this->data['grid'] = Journal2Utils::getItemGrid(Journal2Utils::getProperty($module_data, 'module_data.items_per_row.value'), $this->journal2->settings->get('site_width', 1024), $columns);
                 $this->data['grid'] = array(array(0, (int) $this->data['grid']['xs']), array(470, (int) $this->data['grid']['sm']), array(760, (int) $this->data['grid']['md']), array(980, (int) $this->data['grid']['lg']), array(1100, (int) $this->data['grid']['xl']));
             }
             $this->data['arrows'] = Journal2Utils::getProperty($module_data, 'module_data.carousel_arrows');
             $this->data['bullets'] = Journal2Utils::getProperty($module_data, 'module_data.carousel_bullets');
             if (Journal2Utils::getProperty($module_data, 'module_data.autoplay')) {
                 $this->data['autoplay'] = Journal2Utils::getProperty($module_data, 'module_data.transition_delay', 3000);
             } else {
                 $this->data['autoplay'] = false;
             }
             $this->data['slide_speed'] = (int) Journal2Utils::getProperty($module_data, 'module_data.transition_speed', 400);
             $this->data['pause_on_hover'] = Journal2Utils::getProperty($module_data, 'module_data.pause_on_hover');
             $this->data['touch_drag'] = Journal2Utils::getProperty($module_data, 'module_data.touch_drag');
         }
         $module_type = Journal2Utils::getProperty($module_data, 'module_data.module_type', 'newest');
         $limit = Journal2Utils::getProperty($module_data, 'module_data.limit', 5);
         $posts = array();
         switch ($module_type) {
             case 'newest':
             case 'comments':
             case 'views':
                 $posts = $this->model_journal2_blog->getPosts(array('sort' => $module_type, 'start' => 0, 'limit' => $limit));
                 break;
             case 'related':
                 if (isset($this->request->get['route']) && $this->request->get['route'] === 'product/product' && isset($this->request->get['product_id'])) {
                     $posts = $this->model_journal2_blog->getRelatedPosts($this->request->get['product_id'], $limit);
                 }
                 break;
             case 'custom':
                 $custom_posts = Journal2Utils::getProperty($module_data, 'module_data.posts', array());
                 $custom_posts_ids = array();
                 foreach ($custom_posts as $custom_post) {
                     $post_id = (int) Journal2Utils::getProperty($custom_post, 'data.id', 0);
                     if ($post_id) {
                         $custom_posts_ids[$post_id] = $post_id;
                     }
                 }
                 if ($custom_posts_ids) {
                     $posts = $this->model_journal2_blog->getPosts(array('post_ids' => implode(',', $custom_posts_ids)));
                 }
                 break;
         }
         if (!$posts) {
             return;
         }
         if (in_array($setting['position'], array('column_left', 'column_right'))) {
             $this->data['is_column'] = true;
             $this->data['grid_classes'] = 'xs-100 sm-100 md-100 lg-100 xl-100';
         } else {
             $this->data['is_column'] = false;
             $columns = in_array($setting['position'], array('top', 'bottom')) ? 0 : $this->journal2->settings->get('config_columns_count', 0);
             $this->data['grid_classes'] = Journal2Utils::getProductGridClasses(Journal2Utils::getProperty($module_data, 'module_data.items_per_row.value'), $this->journal2->settings->get('site_width', 1024), $columns);
         }
         $this->data['image_width'] = Journal2Utils::getProperty($module_data, 'module_data.image_width', 50);
         $this->data['image_height'] = Journal2Utils::getProperty($module_data, 'module_data.image_height', 50);
         $this->data['image_resize_type'] = Journal2Utils::getProperty($module_data, 'module_data.image_type', 'fit');
         $this->data['show_description'] = Journal2Utils::getProperty($module_data, 'module_data.description', '1');
         $char_limit = Journal2Utils::getProperty($module_data, 'module_data.description_limit', 150);
         $this->data['posts'] = array();
         foreach ($posts as $post) {
             $this->data['posts'][] = array('name' => $post['name'], 'author' => $this->model_journal2_blog->getAuthorName($post), 'comments' => $post['comments'], 'description' => $this->data['show_description'] ? utf8_substr(strip_tags(html_entity_decode($post['description'], ENT_QUOTES, 'UTF-8')), 0, $char_limit) . '...' : false, 'date' => date($this->language->get('date_format_short'), strtotime($post['date'])), 'image' => Journal2Utils::resizeImage($this->model_tool_image, $post['image'] ? $post['image'] : 'data/journal2/no_image_large.jpg', $this->data['image_width'], $this->data['image_height'], $this->data['image_resize_type']), 'href' => $this->url->link('journal2/blog/post', 'journal_blog_post_id=' . $post['post_id']));
         }
         $this->template = $this->config->get('config_template') . '/template/journal2/module/blog_posts.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;
 }
 private function compress_content($content)
 {
     require_once QA_PLUGIN_DIR . 'q2a-caching/tools/minify/HTML.php';
     return Minify_HTML::minify($content);
 }