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

एसियाली खेलकुदको क्रिकेटमा नेपाल क्वाटरफाइनलमा, फेरि भारत लगायतका देशसँग भीड्न सक्ने

नेपालले १९औँ एसियाली खेलकुदको क्रिकेटमा माल्दिभ्सलाई एक सय ३८ रनले हराएको छ । जितसँगै नेपाल क्वाटरफाइनलमा पुगेको छ । नेपाल समूह ‘ए’ मा अपराजित रहँदै क्वाटरफाइनलमा पुगेको हो । जितका लागि २ सय १३ रनको लक्ष्य पछ्याएको माल्दिभ्स १९ ओभर ४ बलमा ७४ रनमा अलआउट भयो । माल्दिभ्सका घानी अब्दुलले सर्वाधिक …

Read More »

नारायणी नदीमा नुहाउने क्रममा दुई भारतीय युवकहरु बेपत्ता

चितवन, 28 सेप्टेम्बर 2023 चितवनको पवित्र तिर्थस्थल देवघाटमा आएका दुई युवक बिहीवार बिहान करिब ७ बजेतिर नारायणी नदीमा नुहाउने क्रममा बेपत्ता भएका छन् । बेपत्ता हुनेमा भारत आसाम घर भई धनगढीस्थित लक्ष्मीनारायण मन्दिरमा संस्कृत विषय अध्ययनरत १९ वर्षे भोजराज अधिकारी र धनगढी उपमहानगरपालिका–३ मिलन चोक बस्ने वर्ष १७ को पंकज …

Read More »

अमेरिकी राष्ट्रपति जो बाईडेनसित प्रधानमन्त्री मोदीको भेटवार्ता, जी–२० शिखर सम्मेलनका लागि विदेशी पाहुनाको आगमन जारी

नयाँ दिल्ली, 8 सेप्टेम्बर 2023 दिल्लीमा हुने जी–२० शिखर सम्मेलनका लागि विदेशी पाहुनाको आगमन जारी छ । शुक्रबार अमेरिकी राष्ट्रपति जो बाइडेन पनि दिल्ली पुगेका छन् । केन्द्रीय मन्त्री जनरल वीके सिंहले अमेरिकी राष्ट्रपतिलाई विमानस्थलमा स्वागत गरे। जो बाइडेनले दिल्ली पुगेपछि प्रधानमन्त्री मोदीसँग द्विपक्षीय भेट गरेका छन। बैठक करिब ५० …

Read More »

बर्दियामा बाघकाे आक्रमणबाट एक महिलाको मृत्यू

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

Read More »

लुम्बिनी प्रदेशसभाबाट निजामती कर्मचारी विधेयक सर्वसम्मत पारित

नयाँ दिल्लीः लुम्बिनी प्रदेशसभाबाट निजामती कर्मचारी विधेयक सर्वसम्मत पारित भएको छ। प्रदेश निजामती सेवाको गठन, सञ्चालन र सेवाका सर्त सम्बन्धमा व्यवस्थापन गर्न बनेको विधेयक–२०८० शुक्रवारको प्रदेशसभा बैठकले पारित गरेको हो।  बैठकमा सरकारको तर्फबाट मुख्यमन्त्री डिल्लीबहादुर चौधरीले विधेयक निणयार्थ  गरियोस् भन्ने प्रस्ताव पेश गरेका थिए। सभामुख तुलाराम घर्तीले विधेयक पारित गरियोस …

Read More »

बलात्कार मुद्दामा अमेरिकी अभिनेता मास्टरसनलाई ३० वर्ष जेल

नयाँ दिल्लीः अमेरिकी अभिनेता ड्यानी मास्टरसनलाई बलात्कार गरेको आरोपमा ३० वर्षको जेल सजाय सुनाइएको छ। उनलाई दुई महिलालाई बलात्कार गरेको आरोपमा ३० वर्षको जेल सजाय सुनाइएको हो। मास्टरसनलाई सन् २००३ मा महिलालाई बलात्कार गरेको तीन वटा छुट्टाछुट्टै मुद्दामा अभियोग लगाइएको थियो। लस एन्जलिसको अदालतमा बुधबार भएको सुनुवाइमा न्यायाधीशले अभिनेतालाई दुई …

Read More »

आगामी तीन दिन मध्यम वर्षाको सम्भावना

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

Read More »

काेशीकाे मुख्यमन्त्रीमा एमालेका हिक्मत कार्की नियुक्त

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

Read More »

गृहका १० उपसचिवको सरूवा, चार जिल्लाका सीडीओ हेरफेर

काठमाण्डौँः गृह मन्त्रालयले १० उपसचिवको सरुवा गरेको छ। सरुवामा चार जिल्लाका प्रमुख जिल्ला अधिकारी (सीडीओ) फेरिएका छन्। उपसचिव चेतराज बराललाई ओखलढुंगा, अञ्जन न्यौपानेलाई डडेल्धुरा, भीमकान्त पौडेललाई बाजुरा तथा जनकराज पन्तलाई मुस्ताङको सीडीओ-मा खटाइएको छ। ओखलढुंगामा सीडीओ-मा कार्यरत प्रदर्शनी कुमारी र डडेल्धुराका विश्वराज न्यौपानेलाई गृह मन्त्रालय तथा मुस्ताङका अनुप केसीलाई रौतहटको …

Read More »

कञ्चनपुरमा डेंगीको संक्रमणबाट बालिकाको मृत्यु

कञ्चनपुरः कञ्चनपुरमा डेंगीको संक्रमणबाट एक बालिकाको मृत्यु भएको छ।  जिल्लाको भीमदत्त नगरपालिका वडा नम्बर ६ की १२ वर्षीया बालिका लक्ष्मी सेरालाको डेंगी संक्रमणबाट मृत्यु भएको हो। केही दिनअघि उनलाई महाकाली प्रादेशिक अस्पतालमा परीक्षण गर्दा डेंगी संक्रमण पुष्टि भएको थियो। त्यसपछि उनलाई त्यहाँबाट रेफर गरी धनगढीस्थित अस्पतालमा भर्ना गरिएकामा उपचारकै क्रममा …

Read More »