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

दोधारा चाँदनीमा सशस्त्र प्रहरीद्वारा निःशुल्क स्वास्थ्य शिविर

कञ्चनपुरः कञ्चनपुरको दोधारा चाँदनी नगरपालिकाको सीमा बस्तीमा सशस्त्र प्रहरीले निःशुल्क स्वास्थ्य शिविर सञ्चालन गरेको छ। सीमा ईलाकामा बसोवास गर्ने जनसमुदाय र सशस्त्र प्रहरी बल नेपाल बिचको सम्बन्ध सुमधुर बनाई सीमा सुरक्षा, सिमापार अपराध तथा अवैध गतिविधि नियन्त्रणमा प्रभावकारिता ल्याउने हेतुले “सीमाबासीसँग सशस्त्र प्रहरी कार्यक्रम” अन्तर्गत सीमामा सशस्त्र प्रहरीले दोधारा चाँदनी …

Read More »

उत्तराखण्ड राज्यको चमोलीमा 2 नेपालीको शव नदीमा फेला, एक जना बेपत्ता

उत्तराखण्ड, 11 Dec 2024 उत्तराखण्ड राज्यको चमोलीमा 2 नेपालीको शव नदीमा फेला परेको छ भने एक नेपाली बेपत्ता रहेको खबर प्राप्त भएको छ । चमौलीको ज्योतिर्मठ–मलारी राजमार्गमा रहेको गाणी पुलमुनि दुई नेपालीको शव नग्न अवस्थामा फेला परेको हो । मृतक नेपालीहरु सुर्खेतको बबई हातिखालका वासिन्दा तरावती पाण्डेका 24 वर्षका छोरा …

Read More »

कञ्चनपुरको लालझाडीमा “चौथो कञ्चनपुर सम्मेलन-२०८१” सम्पन्न

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

Read More »

नेपाल पत्रकार महासंघ निर्वाचन : अध्यक्षमा पाँच जनाको उम्मेदवारी

काठमाण्डौ, 6 डिसेम्बर 2024 नेपाल पत्रकार महासंघको आगामी नेतृत्व चयन गर्न शुक्रबार मनोनयन दर्ता भएको छ। महासंघको केन्द्रीय कार्यसमितिका पदाधिकारी तथा केन्द्रीय सदस्य चयन गर्न मनोनयन दर्ता भएको हो। महासंघको निर्वाचनमा नेपाल प्रेस युनियन र प्रेस चौतारीले गठबन्धन गरेर उम्मेदवारी दिएका छन्। प्रेस युनियन नेपाली कांग्रेसको शुभेच्छुक संस्था हो भने …

Read More »

पोखरा—लुम्बिनीको खेलमा बने एनपिएलका नयाँ रेकर्ड

6 Dec 2024, काठमाण्डौ सिद्धार्थ बैंक नेपाल प्रिमियर लिग (एनपिएल) मा पोखराले लुम्बिनी लायन्सलाई १० विकेटले हराएर पहिलो जित हात पार्दा केही रेकर्डहरू पनि बनेका छन् । एन्ड्रेस गाउस एनपिएलमा शतक प्रहार गर्ने पहिलो खेलाडी बनेका छन् । उनले ५४ बलमा १२ चौका र ५ छक्कासहित १०० रन बनाए । …

Read More »

दोधारामा किशोरीहरूलाई आत्मनिर्भर बनाउन सिलाई कटाई तालिम

कञ्चनपुरः कञ्चनपुरको दोधारा चाँदनी नगरपालिकामा किशोरीहरूलाई आत्मनिर्भर बनाउने उद्देश्यले सिलाई कटाई तालिम सुरू गरिएको छ। वडामा बसोवास गर्ने बेरोजगार किशोरीहरुका लागि सिलाई कटाई तालिमको समउद्धघाटन गरिएको छ। दोधारा चाँदनी नगरपालिका– ५ मा बसोबास गर्दै आएका बेरोजगार किशोरीहरुलाई आत्मनिर्भर बनाउने उद्देश्यले ३ महिने सिलाई कटाई तालिम सञ्चालन गरिएको दोधारा चाँदनी नगरपालिका– …

Read More »

आज ३३ औँ अन्तर्राष्ट्रिय अपाङ्गता दिवस, महेन्द्रनगरमा विविध कार्यक्रम गरि मनाइयो

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

Read More »

दोधारा र पर्शुराम नगरपालिकालाई ‘पूर्वानुमानमा आधारित पूर्वकार्य गर्नका लागि डिजिटल प्रणाली’ हस्तान्तरण

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

Read More »

प्रधानमन्त्रीलाई काम होइन सरकार ढल्दैन भनेर भाषण गर्नुपर्ने बाध्यता छः विप्लव

काठमाण्डौ, 23 नोभेम्बर 2024 नेपाल कम्युनिष्ट पार्टी (नेकपा) का महासचिव नेत्रविक्रम चन्द ‘विप्लव’ ले प्रधानमन्त्री केपी शर्मा ओलीको काम नै सरकार ढल्दैन भनेर भाषण गर्ने रहेको टिप्पणी गर्नुभएको छ । सरकार कुनैपनि बेला ढल्नसक्ने भएकाले प्रधानमन्त्री ओली बचाऊमा केन्द्रित हुनुपरेको उहाँको जिकिर थियो । शनिवार काठमाडौंमा आयोजित एक कार्यक्रममा बोल्दै …

Read More »

मधेस मुख्यमन्त्री कार्यालयअगाडि शहीद परिवारको आन्दोलन

जनकपुर, 22 नोभेम्बर, 2024 जनकपुरधामस्थित मुख्यमन्त्री तथा मन्त्रिपरिषद् कार्यालय अगाडि मधेस आन्दोलनका शहीद परिवारका सदस्यहरुले प्रदर्शन गरेका छन् । प्रदेश सरकारको पहिलो मन्त्रिपरिषद्को बैठकले शहीद परिवारका एक÷एक जनालाई रोजगार दिने निर्णय गरेपनि हालसम्म कार्यान्वयन नभएको भन्दै शहीद परिवारका सदस्यहरु आन्दोलित भएका हुन् । मुख्यमन्त्री कार्यालय अगाडि गरिएको प्रदर्शनमा प्रदेशका आठै …

Read More »