/** * Callback function used to remove urls of css and js files in head tags * * @param array $aMatches Array of all matches * @return string Returns the url if excluded, empty string otherwise */ protected function replaceScripts($aMatches) { if ((!isset($aMatches[1]) || trim($aMatches[1]) == '') && (!isset($aMatches[3]) || trim($aMatches[3]) == '')) { return $aMatches[0]; } $sType = $this->aCallbackArgs['type']; $sEditor = JchOptimizeHelper::getEditorName(); $sUrl = $aMatches[1]; $sFile = isset($aMatches[2]) ? $aMatches[2] : ''; $sDeclaration = isset($aMatches[3]) ? $aMatches[3] : ''; $aExcludes = array(); $sPath = ''; //global $_PROFILER; if (isset($this->aCallbackArgs['excludes'])) { $aExcludes = $this->aCallbackArgs['excludes']; } $aExcludes['script'] = array_map(function ($sScript) { return stripslashes($sScript); }, $aExcludes['script']); $aExcludes['script'] = array_merge($aExcludes['script'], array('document.write', 'var mapconfig90')); $aExcludes['js'] = array_merge($aExcludes['js'], array('.com/maps/api/js', '.com/jsapi', '.com/uds', 'plugin_googlemap3', '.com/recaptcha/api')); if ($sUrl != '') { $sPath .= JchOptimizeHelper::getFilePath($sUrl); } $sMedia = ''; if ($sType == 'css' && preg_match('#media=(?(?=["\'])(?:["\']([^"\']+))|(\\w+))#i', $aMatches[0], $aMediaTypes) > 0) { $sMedia .= $aMediaTypes[1] ? $aMediaTypes[1] : $aMediaTypes[2]; } //JCH_DEBUG ? $_PROFILER->mark('beforeReplaceScript - ' . $sFile . ' plgSystem (JCH Optimize)') : null; switch (TRUE) { case isset($aExcludes['if']) && in_array($aMatches[0], $aExcludes['if']): case $sUrl != '' && !empty($aExcludes[$sType]) && JchOptimizeHelper::findExcludes($aExcludes[$sType], $sUrl): case $sEditor == 'artofeditor' && $sFile == 'ckeditor.js': case $sType == 'js' && $sUrl != '' && $this->isEditorsExcluded($sUrl): case $sUrl != '' && $this->isUrlFopenAllowed($sUrl): case $sUrl != '' && preg_match('#^https#', $sUrl) && !extension_loaded('openssl'): case $sUrl != '' && preg_match('#^data:#', $sUrl): case $sDeclaration != '' && JchOptimizeHelper::findExcludes($aExcludes['script'], $sDeclaration, TRUE): //JCH_DEBUG ? $_PROFILER->mark('afterReplaceScript - ' . $sFile . ' plgSystem (JCH Optimize)') : null; return $aMatches[0]; case $sUrl == '' && trim($sDeclaration) != '': $content = str_replace(array('<!--', '-->'), '', $sDeclaration); $this->aLinks[$sType][] = array('content' => $content, 'match' => $aMatches[0]); //JCH_DEBUG ? $_PROFILER->mark('afterReplaceScript - ' . $sFile . ' plgSystem (JCH Optimize)') : null; return ''; case $this->aCallbackArgs['type'] == 'js': $this->aCallbackArgs['counter']++; $this->aLinks[$sType][] = array('url' => $sUrl, 'file' => $sFile, 'match' => $aMatches[0], 'path' => $sPath); //JCH_DEBUG ? $_PROFILER->mark('afterReplaceScript - ' . $sFile . ' plgSystem (JCH Optimize)') : null; return '<JCH_SCRIPT>'; case $this->aCallbackArgs['type'] == 'css': $this->aLinks[$sType][] = array('url' => $sUrl, 'file' => $sFile, 'media' => $sMedia, 'match' => $aMatches[0], 'path' => $sPath); //JCH_DEBUG ? $_PROFILER->mark('afterReplaceScript - ' . $sFile . ' plgSystem (JCH Optimize)') : null; return ''; default: JchOptimizeLogger::log(JText::_('Unknown match type')); return $aMatches[0]; } }