/** * Compress HTML * * 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. * * @package Minify * @author Stephen Clay */ namespace LiteSpeed\Lib ; defined( 'WPINC' ) || exit ; class HTML_MIN { /** * @var string */ protected $_html = ''; /** * @var boolean */ protected $_jsCleanComments = true; protected $_skipComments = array(); /** * "Minify" an HTML page * * @param string $html * * @param array $options * * '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 */ public static function minify($html, $options = array()) { $min = new self($html, $options); return $min->process(); } /** * Create a minifier object * * @param string $html * * @param array $options * * '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. * * 'jsCleanComments' : (optional) whether to remove HTML comments beginning and end of script block * * 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If * unset, minify will sniff for an XHTML doctype. */ public function __construct($html, $options = array()) { $this->_html = str_replace("\r\n", "\n", trim($html)); if (isset($options['xhtml'])) { $this->_isXhtml = (bool)$options['xhtml']; } if (isset($options['cssMinifier'])) { $this->_cssMinifier = $options['cssMinifier']; } if (isset($options['jsMinifier'])) { $this->_jsMinifier = $options['jsMinifier']; } if (isset($options['jsCleanComments'])) { $this->_jsCleanComments = (bool)$options['jsCleanComments']; } if (isset($options['skipComments'])) { $this->_skipComments = $options['skipComments']; } } /** * Minify the markeup given in the constructor * * @return string */ public function process() { if ($this->_isXhtml === null) { $this->_isXhtml = (false !== strpos($this->_html, '_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']); $this->_placeholders = array(); // replace SCRIPTs (and minify) with placeholders $this->_html = preg_replace_callback( '/(\\s*)]*?>)([\\s\\S]*?)<\\/script>(\\s*)/i' ,array($this, '_removeScriptCB') ,$this->_html); // replace STYLEs (and minify) with placeholders $this->_html = preg_replace_callback( '/\\s*]*>)([\\s\\S]*?)<\\/style>\\s*/i' ,array($this, '_removeStyleCB') ,$this->_html); // remove HTML comments (not containing IE conditional comments). $this->_html = preg_replace_callback( '//' ,array($this, '_commentCB') ,$this->_html); // replace PREs with placeholders $this->_html = preg_replace_callback('/\\s*]*?>[\\s\\S]*?<\\/pre>)\\s*/i' ,array($this, '_removePreCB') ,$this->_html); // replace TEXTAREAs with placeholders $this->_html = preg_replace_callback( '/\\s*]*?>[\\s\\S]*?<\\/textarea>)\\s*/i' ,array($this, '_removeTextareaCB') ,$this->_html); // trim each line. // @todo take into account attribute values that span multiple lines. $this->_html = preg_replace('/^\\s+|\\s+$/m', '', $this->_html); // remove ws around block/undisplayed elements $this->_html = preg_replace('/\\s+(<\\/?(?:area|article|aside|base(?:font)?|blockquote|body' .'|canvas|caption|center|col(?:group)?|dd|dir|div|dl|dt|fieldset|figcaption|figure|footer|form' .'|frame(?:set)?|h[1-6]|head|header|hgroup|hr|html|legend|li|link|main|map|menu|meta|nav' .'|ol|opt(?:group|ion)|output|p|param|section|t(?:able|body|head|d|h||r|foot|itle)' .'|ul|video)\\b[^>]*>)/i', '$1', $this->_html); // remove ws outside of all elements $this->_html = preg_replace( '/>(\\s(?:\\s*))?([^<]+)(\\s(?:\s*))?$1$2$3<' ,$this->_html); // use newlines before 1st attribute in open tags (to limit line lengths) // $this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html); // fill placeholders $this->_html = str_replace( array_keys($this->_placeholders) ,array_values($this->_placeholders) ,$this->_html ); // issue 229: multi-pass to catch scripts that didn't get replaced in textareas $this->_html = str_replace( array_keys($this->_placeholders) ,array_values($this->_placeholders) ,$this->_html ); return $this->_html; } /** * From LSCWP 6.2: Changed the function to test for special comments that will be skipped. See: https://github.com/litespeedtech/lscache_wp/pull/622 */ protected function _commentCB($m) { // If is IE conditional comment return it. if(0 === strpos($m[1], '[') || false !== strpos($m[1], ' HTML Settings -> HTML Keep comments if(count($this->_skipComments) > 0){ foreach ($this->_skipComments as $comment) { if ($comment && strpos($m[1], $comment) !== false) { return $m[0]; } } } // Comment can be removed. return ''; } protected function _reservePlace($content) { $placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%'; $this->_placeholders[$placeholder] = $content; return $placeholder; } protected $_isXhtml = null; protected $_replacementHash = null; protected $_placeholders = array(); protected $_cssMinifier = null; protected $_jsMinifier = null; protected function _removePreCB($m) { return $this->_reservePlace("_reservePlace("\\s*$)/', '', $css); // remove CDATA section markers $css = $this->_removeCdata($css); // minify $minifier = $this->_cssMinifier ? $this->_cssMinifier : 'trim'; $css = call_user_func($minifier, $css); return $this->_reservePlace($this->_needsCdata($css) ? "{$openStyle}/**/" : "{$openStyle}{$css}" ); } protected function _removeScriptCB($m) { $openScript = "_jsCleanComments) { $js = preg_replace('/(?:^\\s*\\s*$)/', '', $js); } // remove CDATA section markers $js = $this->_removeCdata($js); // minify /** * Added 2nd param by LiteSpeed * * @since 2.2.3 */ if ( $this->_jsMinifier ) { $js = call_user_func( $this->_jsMinifier, $js, trim( $m[ 2 ] ) ) ; } else { $js = trim( $js ) ; } return $this->_reservePlace($this->_needsCdata($js) ? "{$ws1}{$openScript}/**/{$ws2}" : "{$ws1}{$openScript}{$js}{$ws2}" ); } protected function _removeCdata($str) { return (false !== strpos($str, ''), '', $str) : $str; } protected function _needsCdata($str) { return ($this->_isXhtml && preg_match('/(?:[<&]|\\-\\-|\\]\\]>)/', $str)); } } Blog Archives - GLOBAL GORKHA TIMES
Breaking News

Blog

Your blog category

The Best Bitcoin Online Casinos that Approve Bitcoins

Bitcoin has revolutionized the globe of on the internet betting, supplying gamers a protected, anonymous, and practical means to appreciate their favorite casino site games. With the rise in popularity of cryptocurrencies, increasingly more on-line casinos are currently accepting Bitcoin as a form of settlement. In this write-up, we will …

Read More »

Best Neteller Gambling Enterprises Online: A Comprehensive Overview

Welcome to our extensive overview on the very best Neteller online casinos online. Neteller is a popular e-wallet service that permits individuals to make safe and secure online deals, including deposits and withdrawals at on the internet casinos. In this write-up, we will explore the world of Neteller online casinos …

Read More »

दिल्लीमा समाजसेवी टंकनाथ पौडेल जम्बूद्वीप पद्मश्री अवार्डले सम्मानित

नयाँदिल्ली/24 अक्टोबर,2024, भारतको राजधानी दिल्लीमा संयुक्त राष्ट्र स्थापना दिवसको अवसरमा नेपालसहित कयौं देशका प्रतिनिधिहरुलाई जम्बूद्वीप पद्मश्री अवार्ड एंव सेवाश्री अवार्डले सम्मानित गरिएको छ । संयुक्त राष्ट्रका 192 सदस्य राष्ट्रध्वजाका नागरिक सम्मान कार्यक्रम अन्तर्गत देवघाट क्षेत्र विकास समितिका पूर्व अध्यक्ष तथा मैया देवी कन्या कलेज भरतपुर, चितवनका अध्यक्ष टंकनाथ पौडेललाई धार्मिक …

Read More »

नागरिकको गुनासो तथा सुझाव संकलनका लागि दोधारामा प्रहरीको “नागरिक सुनुवाई” कार्यक्रम

कञ्चनपुरः नागरिकको गुनासो र सुझाव संकलन गर्ने उद्देश्यले जिल्ला प्रहरी कार्यालय कञ्चनपुरले “नागरिक सुनुवाई” कार्यक्रम गरेको छ। कञ्चनपुरको दोधारा चाँदनी नगरपालिकामा जिल्ला प्रहरी कार्यालय कञ्चनपुरले सामुदायिक साँझेदारी कार्यक्रमअन्तर्गत नागरिक सुनुवाई कार्यक्रम सम्पन्न गरेको हो। गुनासो व्यवस्थापनका लागि कञ्चनपुरले प्रदान गर्दै आएको सेवा र चाडपर्व नजिकिएसँगै प्रहरीले खेल्नुपर्ने भूमिका साथै जनताले …

Read More »

एनएनएसडब्ल्यूएद्वारा गर्भवती तथा सुत्केरी महिला साथै अपाङ्गता भएका व्यक्तिलाई सहयोग

कञ्चनपुरः कञ्चनपुरको भीमदत्त नगरपालिकामा बाढीबाट प्रभावित गर्भवती, सुत्केरी महिला साथै आपाङ्गता भएका व्यक्तिहरूलाई स्वास्थ्य तथा सरसफाई सामग्री सहयोग गरिएको छ। नेपाल राष्ट्रिय समाज कल्याण संघ (एनएनएसडब्ल्यूए) र सेभ द चिल्ड्रनको सहयोगमा भीमदत्त नगरपालिकाका वडा नम्बर ९, १०, ११, १२ र १३ का ६५ जना गर्भवती, सुत्केरी महिला साथै अपाङ्गता भएका व्यक्तिहरूलाई …

Read More »

अखिल भारत नेपाली एकता मंचद्वारा बाढीपहिरोको घटनाप्रति दुख प्रकट

नयाँ दिल्ली, 2 अक्टोबर 2024 अखिल भारत नेपाली एकता मंच केन्द्रिय समिती भारतले नेपालमा हालै वर्षा अनि बाढी पहिरो जन्य घटनाले भएको धनजनको क्षतिप्रति गहिरो दु:ख व्यक्त गरेको छ। घटनामा ज्यान गुमाउनेहरुप्रति श्रद्धाञ्जली अर्पण गर्दै एंव शोकाकुल परिवारजनप्रति समवेदना प्रकट गरेको छ। यस दुखको घडिमा एकता मंचले सिंगो देश र …

Read More »

एनएनएसडब्ल्यूएद्वारा बाढीबाट प्रभावित गर्भवती, सुत्केरी र अपाङ्गता भएका व्यक्तिलाई सामग्री हस्तान्तरण

कञ्चनपुरः कञ्चनपुरको दोधारा चाँदनी नगरपालिकामा बाढीबाट प्रभावित गर्भवती तथा सुत्केरी महिला साथै आपाङ्गता भएका व्यक्तिहरूलाई स्वास्थ्य तथा सरसफाई सामग्री हस्तान्तरण गरिएको छ। नेपाल राष्ट्रिय समाज कल्याण संघ (एनएनएसडब्ल्यूए) र सेभ द चिल्ड्रनको सहयोग तथा दोधारा चाँदनी नगरपालिकाको समन्वयमा दोधारा चाँदनी नगरपालिकाका दश वटै वडामा रहेका १ सय ३० जना गर्भवती …

Read More »

पुनर्वासमा पूर्वानुमानमा आधारित पूर्वकार्यका लागि आईएमई मार्फत नगद सहयोग

कञ्चनपुरः कञ्चनपुरको पुनर्वास नगरपालिकामा पूर्वानुमानमा आधारित पूर्वकार्यका लागि बाढीको उच्च जोखिममा रहेका घरधूरीहरूलाई आईएमई मार्फत नगद सहयोग गरिएको छ। नेपाल राष्ट्रिय समाज कल्याण संघ (एनएनएसडब्ल्यूए) र मर्सिकोर नेपालको साँझेदारीमा सञ्चालित आर्थिक विकास मार्फत विपद् जोखिम व्यवस्थापन (एमरेड) परियोजनाले बाढीको उच्च जोखिममा रहेका सिमरी, रातोताल, दशरथबस्ति र विकासबस्तिका गरि १७२ घरधुरीहरूलाई …

Read More »

कञ्चनपुरमा ‘सातौँ आदर्श क्रिकेट कप-२०८१’ टी-२० क्रिकेट प्रतियोगिता हुने

कञ्चनपुरः कञ्चनपुरमा ‘सातौँ आदर्श क्रिकेट कप-२०८१’ टी-२० क्रिकेट प्रतियोगिता हुने भएको छ। जिल्लाको बेदकोट नगरपालिका वडा नम्बर–१ मा असोज २० गतेदेखि प्रतियोगिता हुन् लागेको हो। दशैँ तथा तिहारको अवसरमा आदर्श युवा समाज हात्तिथलाको आयोजनामा प्रतियोगिता हुनेछ। आदर्श युवा समाजका अध्यक्ष ज्ञानेश्वर प्रसाद जोशीले खेलाडीहरूको खेल प्रतिभालाई प्रस्फुटन गर्ने उद्देश्यले प्रतियोगिताको …

Read More »

कुतियाकवरका बाढी प्रभावितहरूका लागि आश्रय बन्दै ‘सुरक्षित आवास’

दोधाराः कञ्चनपुरको दोधारा चाँदनी नगरपालिकास्थित कुतियाकवर बस्तीमा नगरपालिका, नेपाल राष्ट्रिय समाज कल्याण संघ (एनएनएसडब्ल्यूए) र निड्स नेपालद्वारा निमार्ण गरिएको सुरक्षित आवास कुतियाकवरका बाढी पीडितहरूका लागि महत्वपूर्ण आश्रयस्थल बनेको छ। दोधारा चाँदनी नगरपालिका-१० स्थित कुतियाकवर बस्तीमा बाढीबाट प्रभावित भएका स्थानिय बासिन्दाहरुका लागि दोधारा चाँदनी नगरपालिका, निड्स नेपाल, नेपाल राष्ट्रिय समाज कल्याण …

Read More »