_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 = ""; $type = ''; if (preg_match('#type="([^"]+)"#i', $m[2], $matches)) { $type = strtolower($matches[1]); } // whitespace surrounding? preserve at least one space $ws1 = ($m[1] === '') ? '' : ' '; $ws2 = ($m[4] === '') ? '' : ' '; // remove HTML comments (and ending "//" if present) if ($this->_jsCleanComments) { $js = preg_replace('/(?:^\\s*\\s*$)/', '', $js); } // minify $minifier = $this->_jsMinifier ? $this->_jsMinifier : 'trim'; if (in_array($type, array('text/template', 'text/x-handlebars-template'))) { $minifier = ''; } $minifier = apply_filters('w3tc_minify_html_script_minifier', $minifier, $type, $script_tag); if (empty($minifier)) { $needsCdata = false; } else { // remove CDATA section markers $js_old = $js; $js = $this->_removeCdata($js); $needsCdata = ( $js_old != $js ); $js = call_user_func($minifier, $js); } return $this->_reservePlace($needsCdata && $this->_needsCdata($js) ? "{$ws1}{$openScript}/**/{$ws2}" : "{$ws1}{$openScript}{$js}{$ws2}" ); } protected function _removeCdata($str) { if (false !== strpos($str, '', '', $str); $str = preg_replace('~/\*\s*\]\]>\s*\*/~', '', $str); $str = str_replace(']]>', '', $str); } return $str; } protected function _removeComment($m) { return $this->_reservePlace($m[1]); } protected function _needsCdata($str) { return ($this->_isXhtml && preg_match('/(?:[<&]|\\-\\-|\\]\\]>)/', $str)); } protected function _removeAttributeQuotes($m) { // whatsapp/fb bots dont read meta tags without quotes well if (strtolower($m[2]) != 'meta') { $m[3] = preg_replace_callback( '~([a-z0-9\\-])=(?[\'"])([^"\'\\s=]*)\k(\\s|>|/>)~i', array( $this, '_removeAttributeQuotesCallback'), $m[3] ); } return $m[1] . $m[3]; } public function _removeAttributeQuotesCallback( $m ) { // empty tag values like to hi is sometimes (XHTML? HTML5 specs doesnt allow that) // parsed as hi by browsers // avoid that by turning it to hi // 2. auto-closing tags without space at the end e.g. // should have space after value // otherwise some browsers assume data-value="aa/" if ( /* 1 */ $m[4] == '/>' || /* 2 */ ( $m[4] == '>' && substr( $m[3], -1, 1 ) == '/' ) ) { return $m[1] . '=' . $m[3] . ' ' . $m[4]; } return $m[1] . '=' . $m[3] . $m[4]; } }
[\'"])([^"\'\\s=]*)\k(\\s|>|/>)~i', array( $this, '_removeAttributeQuotesCallback'), $m[3] ); } return $m[1] . $m[3]; } public function _removeAttributeQuotesCallback( $m ) { // empty tag values like to hi is sometimes (XHTML? HTML5 specs doesnt allow that) // parsed as hi by browsers // avoid that by turning it to hi // 2. auto-closing tags without space at the end e.g. // should have space after value // otherwise some browsers assume data-value="aa/" if ( /* 1 */ $m[4] == '/>' || /* 2 */ ( $m[4] == '>' && substr( $m[3], -1, 1 ) == '/' ) ) { return $m[1] . '=' . $m[3] . ' ' . $m[4]; } return $m[1] . '=' . $m[3] . $m[4]; } }
(\\s|>|/>)~i', array( $this, '_removeAttributeQuotesCallback'), $m[3] ); } return $m[1] . $m[3]; } public function _removeAttributeQuotesCallback( $m ) { // empty tag values like to hi is sometimes (XHTML? HTML5 specs doesnt allow that) // parsed as hi by browsers // avoid that by turning it to hi // 2. auto-closing tags without space at the end e.g. // should have space after value // otherwise some browsers assume data-value="aa/" if ( /* 1 */ $m[4] == '/>' || /* 2 */ ( $m[4] == '>' && substr( $m[3], -1, 1 ) == '/' ) ) { return $m[1] . '=' . $m[3] . ' ' . $m[4]; } return $m[1] . '=' . $m[3] . $m[4]; } }