/** * 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 266 of 270 - सबै खबर एकै ठाँउमा
Breaking News

नुवाकोटका आदित्यलाई खोज्न परिवारले गर्यो आग्रह

खिमराज चालिसे/ चंडिगढ (भारत)५ जुलाई २०२४ नुवाकोटको बिदुर नगरपालिका वार्ड नं १३, हर्कपुरका यादव भट्टका छोरा आदित्य भट्ट बर्ष १४ एक्कासी ०८ असार २०८१ को सम्पर्क विहिन भएका छन। छोरा सम्पर्क बिहिन भएपछि परिवारले मिडियालाई खोजी कार्यमा सहयोग गरिदिन अनुरोध गरेको छ। खोजी तलासीको क्रममा २०८१ असार ८ गते काठमाण्डौंको …

Read More »

कैलालीमा प्रहरी चौकी इन्चार्ज नै प्रहरी नियन्त्रणमा

30 जुन 2024/कैलाली कैलालीमा प्रहरी चौकी इन्चार्ज प्रहरी नियन्त्रणमा परेका छन्। टीकापुर नगरपालिका वडा नम्बर ९ खैरिपुर स्थित प्रहरी बिटमा सार्वजनिक स्थलमा अपशब्द प्रयोग गर्दै गालिगलौच गरिरहेका प्रहरी चौकी सत्तीका ईन्चार्ज प्रहरी नायब निरिक्षक असोक खड्कालाई शनिबार साँझ ईलाका प्रहरी कार्यालय टीकापुरले नियन्त्रणमा लिएको हो। सार्वजनिक स्थलमा जथाभावि हो–हल्ला गरेर …

Read More »

मुख्यमन्त्री प्रेम सिंह तामाङले केन्द्रिय बजेटमा सिक्किमको आपदाका लागि गरे विशेष अनुदानको माग

नयाँ दिल्ली, 22 जुन 2024 सिक्किमका मुख्यमन्त्री प्रेम सिंह तामाङ गोलेले केन्द्रीय वित्तमन्त्री निर्मला सीता रमणसँगको बैठकमा सिक्किममा प्राकृतिक आपदाले पुर्‍याएको क्षतिहरुका लागि विशेष अनुदान दिन ध्यानाकर्षण गराएका छन । नयाँ दिल्लीको भारत मण्डपममा आज बासेको बजेट पूर्व बैठकमा सहभागिता जनाइँदै मुख्यमन्त्री गोलेले वित्तमन्त्री सितारमणलाई दक्षिण ल्होनाक लेक फुटेर आएको …

Read More »

सिक्किमका मुख्यमन्त्री पीएस गोलेद्वारा दिल्लीमा केन्द्रीय मन्त्री मनोहरलाल खट्टरसित भेटघाट

21 जुन 2024/ नयाँ दिल्ली                                                    सिक्किमका मुख्यमन्त्री प्रेम सिंह तामाङले आज राजधानी दिल्लीमा केन्द्रीय आवास, शहरी मामिला एवं उर्जा मन्त्री मनोहरलाल खट्टरसित उनको सरकारी निवासमा …

Read More »

सिक्किमका मुख्यमन्त्री पीएस गोलेद्वारा दिल्लीमा केन्द्रीय मन्त्री मनोहरलाल खट्टरसित भेटघाट

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

Read More »

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

29 अप्रेल, 2024, कञ्चनपुरः नेपाल राष्ट्रिय समाज कल्याण संघ (एनएनएसडब्ल्यूए) ले अपाङ्ता भएका व्यक्तिहरूलाई सहायक सामग्री वितरण गरेको छ। एनएनएसडब्ल्यूएले भीमदत्त नगरपालिकासँगको सहकार्यमा पालिका भित्रका विभिन्न वडामा रहेका ४८ जना शारीरिक अपाङ्गता भएका व्यक्तिहरूलाई सहायता सामग्री वितरण गरेको हो। भीमदत्त नगरपालिकाका नगर प्रमुख पदम बोगटी, उप प्रमुख निलम लेखक, स्वास्थ्य …

Read More »

शैक्षिक सुधारका लागि कञ्चनपुरका ४७९ विद्यार्थीद्वारा प्रधानमन्त्रीलाई पत्र

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

Read More »

एनएनएसडब्ल्यूएद्वारा बाढी प्रभावित समुदायहरुमा उखु खेति प्रवर्धनका लागि कृषि औजार वितरण

कञ्चनपुरः कञ्चपुरमा बाढी प्रभावित समुदायहरूमा उखु खेति प्रवद्धनका लागि साना कृषि औजार वितरण गरिएको छ। नेपाल राष्ट्रिय समाज कल्याण संघ (एनएनएसडब्ल्यूए) कञ्चनपुर र मर्सिकोर नेपालको साझेदारिमा सञ्चालित आर्थिक विकासमार्फत विपद् जोखिम व्यवस्थापन (एमरेड) परियोजनाले बाढी प्रभावित समुदायहरुमा उखु खेति प्रवर्धनका लागि ४ लाख ९६ हजार बराबरको कृषि औजार वितरण गरेको …

Read More »

एनएनएसडब्ल्यूए-द्वारा नेतृत्व विकास, वक्तृत्व तथा सञ्चारसम्बन्धी तालिम सम्पन्न

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

Read More »

७ वर्षदेखि हराएका झापाका कुमार सुनारको खोजीको प्रयास

हिमाचल प्रदेश, 21 फरवरी 2024                                            भारतको हिमाचल प्रदेशमा रोजगारीका लागि गएका झापाका कुमार सुनारलाई खोजीदिन परिवारले आग्रह गरेको छ । कन्कई नगरी पालिका वडा ८ लक्ष्मीपुर प्रहरी चौकी भितामोड …

Read More »