function onAfterRender() { $isDebug=false; $css=$this->param('css'); $javascript=$this->param('javascript'); if(!$css&&!$javascript){ return true; } // Only render for the front site $app =& JFactory::getApplication(); if($app->getName() != 'site') { return true; } $document =& JFactory::getDocument(); $doctype = $document->getType(); // Only render for HTML output if ( $doctype != 'html' ) { return; } //excludeComponents $excludeComponents=$this->param('excludeComponents'); if(isset($excludeComponents)&&$excludeComponents){ $components=@explode(',',$excludeComponents); $option=JRequest::getVar('option'); if(isset($option)&&in_array($option,$components)){ return true; } } //gzip checking $isGZ=$this->param('gzip'); if($isGZ){ $encoding = JResponse::_clientEncoding(); if (!$encoding){ $isGZ=false; } if (!extension_loaded('zlib') || ini_get('zlib.output_compression')) { $isGZ=false; } } $body = JResponse::getBody(); $isok=true; $compressor=new jsCssCompressor(); $baseUrl=JURI::base(true).'/'; if($javascript){ $scriptRegex="/<script [^>]+(\/>|><\/script>)/i"; $jsRegex="/([^\"\'=]+\.(js))[\"\']/i"; preg_match_all($scriptRegex, $body, $matches); $scripts=@implode('',$matches[0]); preg_match_all($jsRegex,$scripts,$matches); $scriptFiles= array(); foreach($matches[1] as $script){ if(isInternal($script)){ //if $baseurl=='/'; may need specail handle $parts=@explode( JURI::base(),$script); if(count($parts)>1&&endwith($parts[1],'.js')){ $script=JPATH_ROOT.DS.$parts[1]; $script=replaceSperator($script); $scriptFiles[]=$script; }else if(endwith($script,'.js')){ $script=$_SERVER['DOCUMENT_ROOT'].DS.$script; $script=replaceSperator($script); if(file_exists($script)){ $scriptFiles[]=$script; }else{ $script=JPATH_ROOT.DS.$script; $script=replaceSperator($script); if(file_exists($script)){ $scriptFiles[]=$script; } } } } } $scriptFiles=array_unique($scriptFiles); $customOrder=$this->param('customOrder'); $jqueryNoConflict=$this->param('jqueryNoConflict'); $jquery=$this->param('jquery'); $exclude=$this->param('excludeJs'); $excludeJs=array(); if(isset($exclude)&&$exclude){ $excludeJs=@explode(',',$exclude); } $predefinedExcludeJs=array('xajax.js','script.js','tiny_mce.js','com_community/assets/toolbar.js'); $excludeJs=@array_merge($excludeJs,$predefinedExcludeJs); $mappedScripts=array(); foreach($scriptFiles as $sf){ $file=strrchr($sf,DS); if(isset($file)){ $file=substr($file,1); $mappedScripts[trim($file)]=$sf; } } $firstScripts=explode(',',$customOrder); $orderedScripts=array(); foreach($firstScripts as $fs){ $fs=trim($fs); if(array_key_exists($fs,$mappedScripts)){ $orderedScripts[]=$mappedScripts[$fs]; } } //append all js, ignore customorded files foreach($scriptFiles as $sf){ if(!in_array($sf,$orderedScripts)){ $orderedScripts[]=$sf; } } if(isset($jquery)&&isset($mappedScripts[$jquery])){
function sendHeaders() { // Don't compress something if the server is going todo it anyway. Waste of time. $this->doCompression = $this->sitemap->compress_xml && !ini_get('zlib.output_compression') && ini_get('output_handler') != 'ob_gzhandler'; @ob_end_clean(); if ($this->doCompression) { $encoding = JResponse::_clientEncoding(); header('Content-Encoding: ' . $encoding); header('X-Content-Encoded-By: Joomla! 1.5'); ob_start(); } header('Content-type: application/xml; charset=utf-8'); }
/** * Compress the data * * Checks the accept encoding of the browser and compresses the data before * sending it to the client. * * @access public * @param string data * @return string compressed data */ function _compress($data) { $encoding = JResponse::_clientEncoding(); if (!$encoding) { return $data; } if (!extension_loaded('zlib') || ini_get('zlib.output_compression')) { return $data; } if (headers_sent()) { return $data; } if (connection_status() !== 0) { return $data; } $level = 4; //ideal level /* $size = strlen($data); $crc = crc32($data); $gzdata = "\x1f\x8b\x08\x00\x00\x00\x00\x00"; $gzdata .= gzcompress($data, $level); $gzdata = substr($gzdata, 0, strlen($gzdata) - 4); $gzdata .= pack("V",$crc) . pack("V", $size); */ $gzdata = gzencode($data, $level); JResponse::setHeader('Content-Encoding', $encoding); JResponse::setHeader('X-Content-Encoded-By', 'Joomla! 1.5'); return $gzdata; }
function startOutput(&$menus, &$config) { $live_site = substr_replace(JURI::root(), "", -1, 1); $this->isNews = JRequest::getInt('news', 0); // Don't compress something if the server is going todo it anyway. Waste of time. $this->doCompression = $this->sitemap->compress_xml && !ini_get('zlib.output_compression') && ini_get('output_handler') != 'ob_gzhandler'; @ob_end_clean(); if ($this->doCompression) { $encoding = JResponse::_clientEncoding(); header('Content-Encoding: ' . $encoding); header('X-Content-Encoded-By: Joomla! 1.5'); ob_start(); } header('Content-type: application/xml; charset=utf-8'); echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; if (!$config->exclude_xsl && !$this->isNews) { $user =& JFactory::getUser(); if ($user->get('gid') == "25") { echo '<?xml-stylesheet type="text/xsl" href="' . $live_site . '/index2.php?option=com_xmap&view=xsladminfile&tmpl=component"?>' . "\n"; } else { echo '<?xml-stylesheet type="text/xsl" href="' . $live_site . '/index2.php?option=com_xmap&view=xslfile&tmpl=component"?>' . "\n"; } } echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' . 'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 ' . 'http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" ' . 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" ' . 'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"' . ($this->isNews ? ' xmlns:n="http://www.google.com/schemas/sitemap-news/0.9"' : '') . ">\n"; }