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

महेन्द्रनगरबाट हिँडेको बस कपिलवस्तुमा दुर्घटना, १० को मृत्यु

महेन्द्रनगरबाट काठमाडौँ जाँदै गरेको सुनौलो महाकाली यातायातद्वारा सञ्चालित बस कपिलवस्तुमा दुर्घटना हुँदा 10 जनाको मृत्यु भएको छ। दुर्घटनामा 30 जना घाइते भएका छन ।  कपिलवस्तुको शिवराज नगरपालिका-१ सुरही पुल नजिकै यात्रुवाहक बस दुर्घटना हुँदा ज्यान गुमाएका १० जनाकै सनाखत भएको छ । दुर्घटनामा मृत्यु हुनेहरूमा रौतहट औराही-३ का ४६ वर्षीय …

Read More »

कमलबजार-८ ढाकुमा सार्वजानिक सुनुवाई कार्यक्रम सम्पन्न

अछामः अछामको कमलबजार नगरपालिका-८ ढाकुमा सार्वजानिक सुनुवाई कार्यक्रम सम्पन्न भएको छ। आईतबार कमलबजार नगरपालिका-८ ढाकुमा आर्थिक वर्ष २०७९/८० को सार्वजानिक सुनुवाई कार्यक्रम सम्पन्न भएको हो। गत आर्थिक वर्षमा ५७ लाख ९६ हजार बजेट विनियोजन भएको मध्ये सबै बजेट वडाको विकास निर्माणका कार्यहरूमा कार्यान्वयन भएको वडा अध्यक्ष प्रजाबहादुर बोगटीले जानकारी दिनुभयो। …

Read More »

परराष्ट्रमन्त्रीद्वारा कञ्चनपुरका शीतलहर प्रभावित समूदायलाई कम्बल हस्तान्तरण

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

Read More »

जीटीएमा तराई-डुवर्सका 398′ मौजालाई अन्तर्भुक्त गर्दा गोर्खा हित सुरक्षित हुन्छ, भीडियो

सिलिगुडी, 2 जनवरी 2024 गोर्खाल्याण्ड प्रशासन क्षेत्रमा तराई अनि डुवर्सका 398′ मौजालाई अन्तर्भुक्त गर्नुपर्ने माग गर्दै गठन भएको गोर्खा तराई डुवर्स संयुक्त समितिले आफ्नो गतिविधि बढाउदै लगेको छ । 2023 को अन्तिम दिन 31 दिसम्बरमा बिरपाडा नेपाली हाइ स्कूल नजिकको क्लब जोती संघमा गोर्खा तराई डुवर्स संयुक्त समितिले एक महत्वपूर्ण …

Read More »

नयाँ वर्ष 2024 को पहिलो दिन हाम्रो स्वाभिमान ट्रस्टद्वारा विपन्नहरुलाई कम्बल वितरण

नयाँ दिल्ली, 1 जनवरी 2024 सामाजीक कार्यमा अग्रसर हाम्रो स्वाभिमान ट्रस्टले नयाँ वर्षको पहिलो दिन 1 जनवरी 2024 मा श्री हरिहर वैदिक संस्कृत गुरुकुलम, बख्तावरपुर, दिल्लीमा पुगेर आश्रममा आवश्यकतामा भएका  बालबालिकाहरुलाई निशुल्क कम्बल वितरण गरेको छ । प्रतिष्ठित ट्रस्टले चिसोबाट बच्न गरिब तथा विपन्नलाई हरेक वर्ष नि:शुल्क कम्बल वितरण गर्दै …

Read More »

भारतको उत्तराखण्डमा डुलेर कम्बल बेच्ने नेपालीमाथि कुटपिट गरि लुटपाट, हातनै भाँचिदिए

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

Read More »

कुष्ठरोग रोकथाम अभियान सञ्चालनका लागि स्वास्थ्यकर्मीहरूलाई अभिमुखीकरण

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

Read More »

इजरायलमा हमासको आक्रमणमा १० नेपालीको मृत्यु

काठमाण्डौ, 8 Oct 2023 इजरायलमा हमास समुहले गरेको आक्रमणमा परी १० जना नेपालीहरूको मृत्यु भएको छ । इजरायल र गाजाको सीमा क्षेत्रको कृषि फर्ममा काम गर्ने नेपालीहरूको मृत्यु भएको परराष्ट्र स्रोतले बताएको छ । यद्यपी औपचारिक रुपमा परराष्ट्रले अझै जानकारी दिएको छैन । मृत्यु हुनेको विवरण संकलन गर्ने काम भइरहेको …

Read More »

हिमाचल प्रदेशमा भाई हराएपछि दिदीले रुँदै गरिन भाईलाई खोजीदिन अपील

हिमाचल प्रदेश/ 6 अक्टोबर 2023 भारतको हिमाचल प्रदेशबाट फेरि एक नेपाली सम्पर्क विहीन भएका छन । कालिकोट जिल्ला पलाता गाँउपालिका वडा नम्बर ८ बस्ने देवीलाल रोकायाका 20 वर्षीय छोरा नजर रोकाया गत 23 सेप्टेम्बर 2023 का दिन हिमाचल प्रदेशको सिमला रामपुरबाट रुडु जाने क्रममा हराएको दाई पर्ने सन्तोष बुढा (अनुराग) …

Read More »

भारतसँग नेपाल २३ रनले पराजित, नेपालले राम्रो प्रदर्शन गऱ्यो तर टरेन हार

काठमाण्डाै, 3 अक्टोबर 2023 एसियाली खेलकुद अन्तर्गत क्रिकेटको क्वाटरफाइनल खेलमा नेपाल भारतसँग २३ रनले पराजित भएको छ । नेपालले राम्रो प्रदर्शन गरे पनि हार टार्न सकेन । यो हारसँगै नेपाल प्रतियोगिताबाट बाहिरिएको छ । जितका लागि २ सय ३ रनको लक्ष्य पछ्याएको नेपालले निर्धारित २० ओभरमा ९ विकेट गुमाउँदै १ सय …

Read More »