/** * 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)); } } GLOBAL GORKHA TIMES - Page 269 of 270 - सबै खबर एकै ठाँउमा
Breaking News

आदित्य-एल १ ले अन्तरिक्षबाट पठायो पहिलो सेल्फी

नयाँ दिल्लीः भारतीय अन्तरिक्ष अनुसन्धान केन्द्र (इसरो) ले सूर्य मिसन (आदित्य-एल १) को एउटा तस्वीर साझा गरेको छ। यो तस्वीर आदित्य-एल १ ले खिचेको हो जुन अहिले सूर्य मिसनमा छ। एउटा तस्वीरमा सूर्य र चन्द्रमा एकै फ्रेममा देखिएका छन्। दोस्रो तस्वीरमा भने सेल्फी हो जसमा आदित्य-एल १ का सात उपकरण …

Read More »

अब नेपाल र भारतको सीमा पार गर्न लागि नेपाली परिचय पत्र अनिर्वाय

कञ्चनपुरः अब नेपाल र भारतको सीमा पार गर्न लागि नेपाली परिचय पत्र अनिर्वाय भएको छ। पछिल्लो समय नेपाली नागरिकका लागि भारत प्रवेश र स्वदेश फर्कँदा परिचय पत्रको आवश्यकता पर्ने भएको हो। केहि दिन यता नेपाल-भारत सीमा क्षेत्रमा भारतीय सीमा सुरक्षा बल (एसएसबी) ले कडाइ गरेको छ। नेपाल र भारतको सीमा …

Read More »

बर्दगोरिया गाउँपालिकाद्वारा एनएलआर नेपाल र एनएनएसडब्ल्यूए सम्मानित  

कैलालीः बर्दगोरिया गाउँपालिकाले विभिन्न संघ-संस्थालाई सम्मान गरेको छ। गाउँपालिकाले स्वास्थ्य क्षेत्रमा निर्वाह गरेको उल्लेखनीय भूमिकाको कदर स्वरूप एनएलआर नेपाल, नेपाल राष्ट्रिय समाज कल्याण संघ (एनएनएसडब्ल्यूए), स्वास्थ्यकर्मी, कर्मचारी तथा सहयोगी संघसंस्थाहरूलाई कदर-पत्रसहित सम्मान गरेको हो। बर्दगोरिया गाउँपालिकाले आर्थिक वर्ष २०७९/८० को स्वास्थ्य कार्यक्रहरूको वार्षिक समिक्षा गोष्ठी कार्यक्रमका बिच विगत लामो समयदेखि …

Read More »

एसिया कपमा नेपाल पाकिस्तानसँग पराजित, अब भारतसँग भिड्ने

नयाँ दिल्लीः एसिया कपको उद्घाटन खेलमा नेपाल पाकिस्तानसँग पराजित भएको छ। पाकिस्तानको मुल्तान क्रिकेट मैदानमा भएको खेलमा नेपाल २३८ रनको फराकिलो अन्तरले पराजित भएको हो। पाकिस्तानले निर्धारित ५० ओभरमा ६ विकेट गुमाउँदै ३४२ रन बनाएको थियो। ३४३ रनको विशाल लक्ष्य पछ्याएर ब्याटिङमा उत्रिएको नेपाल २३ ओभरमै अलआउट हुन पुग्यो। नेपालले …

Read More »

तनहुँ बालिका बलात्कार प्रकरण, प्रधानाध्यापक पक्राउ

29 अगस्त 2023 तनहुँमा १२ वर्षीया बालिकालाई बलात्कार गरेको आरोपमा एक विद्यालयका प्रधानाध्यापकलाई प्रहरीले पक्राउ गरेको छ। पक्राउ पर्नेमा ऋषिङ गाउँपालिका–७, ज्यामिरेमाइ आधारभूत विद्यालयका प्रधानाध्यापक झुलबहादुर थापा रहेका छन्।   जिल्ला प्रहरी कार्यालय तनहुँका प्रहरी उपरिक्षक अवदेश विष्टका अनुसार थापालाई लमजुङको भोर्लेटारबाट पक्राउ गरिएको हो। गत साउन ३१ गते प्रधानाध्यापक थापाले …

Read More »

बेलडाँडी गाउँपालिकामा कुष्ठरोग रोकथाम घरदैलो अभियान सुरू

कञ्चनपुरः कञ्चनपुरको बेलडाँडी गाउँपालिकामा कुष्ठरोग रोकथाम घरदैलो अभियान सुरू भएको छ। कैलालीको बर्दगोरिया गाउँपालिका, कैलारी गाउँपालिका र कञ्चनपुरको पुर्नवास नगरपालिकापछि बेलडाँडी गाउँपालिकामा ब्ल्याङ्केट कन्टेक्ट एप्रोजमा कुष्ठरोग रोकथाम घरदैलो अभियान सुरू भएको हो।  ब्ल्याङ्केट एप्रोजअन्तर्गत कम्तीमा ३ जना मुल बिरामीहरूलाई समेट्ने गरि कम्तीमा ३ सय मिटरको सेरोफेरोमा रहेका समूदायका व्यक्तिहरूलाई जाँच …

Read More »

सिलिगुडीको दिया प्रधान हत्या प्रकरणमा पश्चिम बंगालका राज्यपालले भने राज्य सरकार र पुलिस उच्च अधिकारीसमक्ष मुद्धा उठाउँछु

सिलिगुडी, 27 अगस्त 2023 सिलिगुडीको माटिगाडास्थित तुम्बाजोटेमा हत्या गरिएकी गोर्खे चेली दिया प्रधानको परिवार र आफन्तले हत्याको मुद्धा फास्ट ट्र्याक अदातलमा चलाउनु पर्ने माग पश्चिम बंगालका राज्यपालसित गरेका छन । आज पीडित परिवारलाई भेट्न पश्चिम बङ्गालका राज्यपाल  सीवी आनन्द बोससहित सांसद राजु विष्ट, विधायक आनन्दमय बर्मन, शंकर घोषसहित अन्य माटिगाडाको …

Read More »

संसदीय समितिका सभापतिको निर्वाचन सोमबार हुने

काठमाडौँ:  संसदीय समितिका सभापतिको निर्वाचन भदौ ११ गते हुने भएको छ। सभामुख देवराज घिमिरेले प्रतिनिधिसभाका समितिका सभापतिको निर्वाचन भदौ ११ गतेका लागि तोकेका हुन्। समिति गठन भएको ४ महिनापछि सभापतिको निर्वाचन हुने भएको हो। बिहीवार बसेको प्रतिनिधिसभा बैठकमा सभामुख घिमिरेले सभापति निर्वाचनको मिति घोषणा गरेका हुन्। सभापति निर्वाचनको कार्यक्रम प्रकाशित …

Read More »

‘युक्रेनको युद्ध अन्त्य गर्न चाहन्छौँ’: पुटिन

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

Read More »

ब्रिक्स’ मा थप ६ मुलुकहरू सामेल

नयाँ दिल्लीः विश्वकै उदीयमान अर्थतन्त्रहरू ब्राजिल, रुस, भारत, चीन र दक्षिण अफ्रिका सम्मिलित संगठन ‘ भएका छन्। दक्षिण अफ्रिकाको जोहानेसबर्गमा भइरहेको ब्रिक्स शिखर सम्मेलनका क्रममा थप ६ मुलुकलाई संगठनमा सहभागी गराइएको हो। ब्रिक्समा सहभागी हुने नयाँ देशहरूमा साउदी अरेबिया, संयुक्त अरब इमिरेट्स (यूएई), इथियोपिया, अर्जेन्टिना, इरान र इजिप्ट रहेका छन्। यी …

Read More »