getCfg('enable_debug'); $microstart = explode(' ',microtime()); $cache_TTL = 0; $_start_time = $microstart[0] + $microstart[1]; if ( $is_debug == "1") { if ( $jrecache_config->getCfg('debug_ip') != cache_getip()) { $is_debug = false; } else { $is_debug = true; $debug_out = "cache debug information:"; } } if ($jrecache_config->getCfg('enable_cache') == "0" ){ $bypass_cache= true; if ( $is_debug ) { $debug_out = "
Cache is disabled"; } } else { $bypass_cache = false; $cache_TTL = $jrecache_config->getCfg('cache_TTL'); } if (isset ($_COOKIE["bypass_cache"])) { if ($_COOKIE["bypass_cache"] == "true") { $bypass_cache = true; } } /* * Bypass the posts, since submitting data can change the layout; * Adjustment made for the CB component. Make sure that the URL is comprofiler; */ if ( strpos( $_SERVER['REQUEST_URI'], "comprofiler")) { setcookie("bypass_cache", "true", time()+ $cache_TTL, "/"); if ( $is_debug ) { $debug_out = $debug_out . "
Bypassing cache because LOGIN POST"; } $bypass_cache = true; } if (isset($_POST) & $bypass_cache == false) { /* * Check if the post action is login or logout action; */ if ( isset($_POST['option'])) { if ( $_POST['option'] == "login" | $_POST['username'] != "") { $lifetime = time() + 365*24*60*60; setcookie("bypass_cache", "true", time()+ $cache_TTL,"/"); $bypass_cache = true; if ( $is_debug ) { $debug_out = $debug_out . "
Bypassing cache because LOGIN POST"; } } } if ( isset($_POST['option'])) { if ( $_POST['option'] == "logout") { $bypass_cache = true; $lifetime = time(); setcookie("bypass_cache", "false", time(), "/"); if ( $is_debug ) { $debug_out = $debug_out . "
Bypassing cache because LOGOUT POST"; } } } if ( ($jrecache_config->getCfg('enable_post_caching') == "0") & count($_POST) > 0 ) { $bypass_cache = true; if ( $is_debug ) { $debug_out = $debug_out . "
Bypassing cache because of POST"; } } } /* * Check if cookies are present that allows the page not to be cached; */ if ( trim($jrecache_config->getCfg('cookies_disable')) != "" & !$bypass_cache) { $cookies = explode( "|", trim($jrecache_config->getCfg('cookies_disable')) ) ; foreach ( $cookies as $cookie ) { $value = check_cookie ( $cookie ); if ( $value != "" ){ $cookie_string = $cookie_string . $cookie . ":" . $value . "|"; if ( $is_debug ) { $debug_out = $debug_out . "
Page not Cached due to cookie: $cookie value: $value "; } $bypass_cache = true; } } } /* * Reading the cookies and the value's */ $cookie_string = ""; # if ( trim($jrecache_config->getCfg('cookies')) != "" & !$bypass_cache) { $cookies = explode( "|", trim($jrecache_config->getCfg('cookies')) ) ; foreach ( $cookies as $cookie ) { $value = check_cookie ( $cookie ); if ($value != "") { $cookie_string = $cookie_string . $cookie . ":" . $value . "|"; if ( $is_debug ) { $debug_out = $debug_out . "
Cached cookie: $cookie value: $value "; } } } } // getting the cache directory, if not specified, read the global configuration file; $cache_dir = $jrecache_config->getCfg('cache_directory'); if ( $cache_dir == "") { $cache_dir = dirname(__FILE__) . '/cache'; } if ( !isset($_SERVER['REQUEST_URI']) ) { $REQUEST_URI = $_SERVER['SCRIPT_NAME']; if ($_SERVER['QUERY_STRING'] != '') { $REQUEST_URI .= '?'.$_SERVER['QUERY_STRING']; } $_SERVER['REQUEST_URI'] = $REQUEST_URI; } $url_to_store = $_SERVER['REQUEST_URI']; $hash = sha1($_SERVER['REQUEST_URI'] . '|G|' . serialize($_GET) . '|P|' . serialize($_POST) . '|C|' . $cookie_string); $file = $cache_dir . "/" . $hash; $use_cache = false; if ( $bypass_cache == false & file_exists($file) & $cache_TTL == 0) { $use_cache = true; } /* * Check if the cache must be cleaned up, automatic garbage collection; */ $cache_cleanup = false; if ( $jrecache_config->getCfg('garbage_collection') == "1") { $garbage_file = $cache_dir . "/garbage.cfg"; if (!file_exists($garbage_file) ) { _file_put_contents( $garbage_file, "don't remove this file", LOCK_EX); } else { if ((time() - @filemtime($garbage_file)) > $jrecache_config->getCfg('garbage_TTL') ){ $cache_cleanup = true; $bypass_cache = true; $use_cache = false; } } } if ( ($bypass_cache == false) & ((time() - @filemtime($file)) < $cache_TTL ) | $use_cache) { // We are done, just return the file and exit $enable_page_compression = $jrecache_config->getCfg('enable_page_compression'); if ($enable_page_compression == "1") { global $mosConfig_gzip; $mosConfig_gzip = 1; cache_initGzip(); } if ( !$jrecache_config->getCfg('enable_compressed_cache') ) { readfile($file); if ( $is_debug ) { $debug_out = $debug_out . "
Plain file read from cache: $file"; } } else { if ( $is_debug ) { $debug_out = $debug_out . "
Compressed file read from cache: $file"; } $handle = gzopen($file, 'r'); while (!gzeof($handle)) { $buffer = gzgets($handle, 4096); echo $buffer; } } if ( $is_debug ) { $microstop = explode(' ',microtime()); $_stop_time = $microstop[0] + $microstop[1]; $time_end = microtime() - $_start_time; $debug_out = $debug_out . "
File size: " . round(filesize($file)/1024,1) . " Kb" ; $debug_out = $debug_out . "
Generation time:" . round($_stop_time - $_start_time,7). " sec."; } if ($enable_page_compression == "1") { if ( $is_debug ) { $debug_out = $debug_out . "
Send out compressed HTML"; } if ( $is_debug ) { echo $debug_out; } cache_doGzip(); } else { if ( $is_debug ) { echo $debug_out; } } exit(); } else { // checks for configuration file, if none found loads installation page if (!file_exists( 'configuration.php' ) || filesize( 'configuration.php' ) < 10) { $self = rtrim( dirname( $_SERVER['PHP_SELF'] ), '/\\' ) . '/'; header("Location: http://" . $_SERVER['HTTP_HOST'] . $self . "installation/index.php" ); exit(); } require_once( 'configuration.php' ); // SSL check - $http_host returns : $http_host = explode(':', $_SERVER['HTTP_HOST'] ); if( (!empty( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] ) != 'off' || isset( $http_host[1] ) && $http_host[1] == 443) && substr( $mosConfig_live_site, 0, 8 ) != 'https://' ) { $mosConfig_live_site = 'https://'.substr( $mosConfig_live_site, 7 ); } require_once( 'includes/joomla.php' ); //Installation sub folder check, removed for work with SVN if (file_exists( 'installation/index.php' ) && $_VERSION->SVN == 0) { define( '_INSTALL_CHECK', 1 ); include ( $mosConfig_absolute_path .'/offline.php'); exit(); } // displays offline/maintanance page or bar if ($mosConfig_offline == 1) { require( $mosConfig_absolute_path .'/offline.php' ); } // load system bot group $_MAMBOTS->loadBotGroup( 'system' ); // trigger the onStart events $_MAMBOTS->trigger( 'onStart' ); if (file_exists( $mosConfig_absolute_path .'/components/com_sef/sef.php' )) { require_once( $mosConfig_absolute_path .'/components/com_sef/sef.php' ); } else { require_once( $mosConfig_absolute_path .'/includes/sef.php' ); } require_once( $mosConfig_absolute_path .'/includes/frontend.php' ); // retrieve some expected url (or form) arguments $option = strval( strtolower( mosGetParam( $_REQUEST, 'option' ) ) ); $Itemid = intval( mosGetParam( $_REQUEST, 'Itemid', null ) ); if ($option == '') { if ($Itemid) { $query = "SELECT id, link" . "\n FROM #__menu" . "\n WHERE menutype = 'mainmenu'" . "\n AND id = " . (int) $Itemid . "\n AND published = 1" ; $database->setQuery( $query ); } else { $query = "SELECT id, link" . "\n FROM #__menu" . "\n WHERE menutype = 'mainmenu'" . "\n AND published = 1" . "\n ORDER BY parent, ordering" ; $database->setQuery( $query, 0, 1 ); } $menu = new mosMenu( $database ); if ($database->loadObject( $menu )) { $Itemid = $menu->id; } $link = $menu->link; if (($pos = strpos( $link, '?' )) !== false) { $link = substr( $link, $pos+1 ). '&Itemid='.$Itemid; } parse_str( $link, $temp ); /** this is a patch, need to rework when globals are handled better */ foreach ($temp as $k=>$v) { $GLOBALS[$k] = $v; $_REQUEST[$k] = $v; if ($k == 'option') { $option = $v; } } } if ( !$Itemid ) { // when no Itemid give a default value $Itemid = 99999999; } // mainframe is an API workhorse, lots of 'core' interaction routines $mainframe = new mosMainFrame( $database, $option, '.' ); $mainframe->initSession(); // trigger the onAfterStart events $_MAMBOTS->trigger( 'onAfterStart' ); // checking if we can find the Itemid thru the content if ( $option == 'com_content' && $Itemid === 0 ) { $id = intval( mosGetParam( $_REQUEST, 'id', 0 ) ); $Itemid = $mainframe->getItemid( $id ); } /** do we have a valid Itemid yet?? */ if ( $Itemid === 0 ) { /** Nope, just use the homepage then. */ $query = "SELECT id" . "\n FROM #__menu" . "\n WHERE menutype = 'mainmenu'" . "\n AND published = 1" . "\n ORDER BY parent, ordering" ; $database->setQuery( $query, 0, 1 ); $Itemid = $database->loadResult(); } // patch to lessen the impact on templates if ($option == 'search') { $option = 'com_search'; } // loads english language file by default if ($mosConfig_lang=='') { $mosConfig_lang = 'english'; } include_once( $mosConfig_absolute_path .'/language/' . $mosConfig_lang . '.php' ); // frontend login & logout controls $return = strval( mosGetParam( $_REQUEST, 'return', NULL ) ); $message = intval( mosGetParam( $_POST, 'message', 0 ) ); if ($option == 'login') { $mainframe->login(); // JS Popup message if ( $message ) { ?> logout(); // JS Popup message if ( $message ) { ?> getUser(); // detect first visit $mainframe->detect(); // set for overlib check $mainframe->set( 'loadOverlib', false ); $gid = intval( $my->gid ); // gets template for page $cur_template = $mainframe->getTemplate(); /** temp fix - this feature is currently disabled */ /** @global A places to store information from processing of the component */ $_MOS_OPTION = array(); // precapture the output of the component require_once( $mosConfig_absolute_path . '/editor/editor.php' ); ob_start(); if ($path = $mainframe->getPath( 'front' )) { $task = strval( mosGetParam( $_REQUEST, 'task', '' ) ); $ret = mosMenuCheck( $Itemid, $option, $task, $gid ); if ($ret) { require_once( $path ); } else { mosNotAuth(); } } else { header( 'HTTP/1.0 404 Not Found' ); echo _NOT_EXIST; } $_MOS_OPTION['buffer'] = ob_get_contents(); ob_end_clean(); initGzip(); header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); header( 'Cache-Control: no-store, no-cache, must-revalidate' ); header( 'Cache-Control: post-check=0, pre-check=0', false ); header( 'Pragma: no-cache' ); // display the offline alert if an admin is logged in if (defined( '_ADMIN_OFFLINE' )) { include( $mosConfig_absolute_path .'/offlinebar.php' ); } // loads template file if ( !file_exists( $mosConfig_absolute_path .'/templates/'. $cur_template .'/index.php' ) ) { echo _TEMPLATE_WARN . $cur_template; } else { require_once( $mosConfig_absolute_path .'/templates/'. $cur_template .'/index.php' ); echo ''; } /* * cache implementation */ $usr_obj = $mainframe->getUser(); if ($usr_obj->name != "" ) { /* * Set the lifetime of the cookie, doesn't matter howlong, if logout the cookie is disabled */ $lifetime = time() + 365*24*60*60; setcookie("bypass_cache", "true", $lifetime, "/"); $bypass_cache = true; if ( $is_debug ) { $debug_out = $debug_out . "
Bypassing cache because LOGIN "; } } else { if (isset($_COOKIE["bypass_cache"]) == "true" ){ /* * Make the invalid if no-user is active */ setcookie("bypass_cache", "false", time(), "/"); if ( $is_debug ) { $debug_out = $debug_out . "
Bypassing cache because LOGOUT "; } } } if ( $bypass_cache == false ) { /* * Check if the URL may be cached; */ $generate = true; $cache_disallow = $jrecache_config->getCfg('cache_disallow_filter'); if ( $cache_disallow != "") { $lines = explode ( "\n", $cache_disallow ); foreach( $lines as $line ) { if ( $line != "") { if ( strstr ( $url_to_store, chop( $line)) ) { $generate = false; if ( $is_debug ) { $debug_out = $debug_out . "
File not generated due to cache disallow filter: " . $line; } } } } } if ( $generate ){ $output = ob_get_contents(); /* * Update the table #__jrecache_repository and check if the CACHE may be written; */ $url = $url_to_store; $sql = "SELECT is_may_cached, datetime, cache_file FROM #__jrecache_repository WHERE url='$url' AND cookie_info='$cookie_string'"; $database->setQuery( $sql ); $cache_obj = null; $cache_obj = $database->loadObjectList( $cache_obj); $may_write = true; $datetime = ""; if ( $cache_obj) { if ($cache_obj[0]->is_may_cached == "0") { $may_write = false; if ( $is_debug ) { $debug_out = $debug_out . "
File not generated due to cache disallow from cache repository database"; } } } if ( $may_write ) { $content_not_cached = $jrecache_config->getCfg('content_not_cached'); if ( preg_match ( $content_not_cached, $output ) ) { $page_valid = false; } else { $page_valid = true; } /* * final write the cache record */ if ( $page_valid) { if ( !$jrecache_config->getCfg('enable_compressed_cache') ) { if ( $is_debug ) { $debug_out = $debug_out . "
Generating plain cache file: $file "; } } else { $output = gzip($output, 9, $file); if ( $is_debug ) { $debug_out = $debug_out . "
Generating Compressed cache file: $file "; } } /* * final write the cache record */ $bytes = _file_put_contents($file, $output, LOCK_EX); $filesize = round($bytes/1024,1); $url = $url_to_store; $datetime = date( 'Y-m-d H:i:s', time() ); if ( $cache_obj ) { $sql = "UPDATE #__jrecache_repository SET datetime='$datetime', cache_size='$filesize', cache_file='$hash' WHERE url='$url' AND cookie_info='$cookie_string'"; } else { $sql = "INSERT INTO #__jrecache_repository ( url, cookie_info, cache_file, datetime, cache_size, is_may_cached ) values ( '$url', '$cookie_string','$hash', '$datetime', '$filesize', '1' )"; } $database->setQuery( $sql ); $database->query(); if ( $is_debug ) { $debug_out = $debug_out . "
File size: " . $filesize . " Kb" ; } } else { headers_sent($filename, $linenum); $debug_out = $debug_out . "
Page not included within cache due to content disallow filter" ; } } } } if ( $jrecache_config->getCfg('enable_cache') == "1" & $cache_cleanup ) { $debug_out = $debug_out . "
Executing the cache garbage cleanup: deleting outdated cache files"; $cache_directory = $jrecache_config->getCfg('cache_directory'); if ($dh = opendir($cache_directory)) { while (($file = readdir($dh)) !== false) { if ($file != "." && $file != ".." && $file != "index.html" && $file != "garbage.cfg") { $filename = $cache_directory . "/". $file; if ( $is_all) { @unlink ( $filename ); } else { if ( time() - @filemtime($filename) > $cache_TTL ) { @unlink ( $filename ); } } } } closedir($dh); } /* * Empty the table #_jrecache_repository */ $sql = "DELETE FROM #__jrecache_repository WHERE time_to_sec(now())-time_to_sec(datetime) > $cache_TTL and is_may_cached = '1'"; $database->setquery( $sql ); $database->query(); _file_put_contents( $garbage_file, "don't remove this file", LOCK_EX); } if ( $is_debug ) { $microstop = explode(' ',microtime()); $_stop_time = $microstop[0] + $microstop[1]; $debug_out = $debug_out . "
Generation time:" . round($_stop_time - $_start_time,7). " sec."; echo $debug_out; } } /* * end of the cache building */ // displays queries performed for page if ($mosConfig_debug) { echo $database->_ticker . ' queries executed'; echo '
';
 	foreach ($database->_log as $k=>$sql) {
 		echo $k+1 . "\n" . $sql . '
'; } echo '
'; } doGzip(); function gzip($data = "", $level = 6, $filename = "", $comments = "") { $flags = (empty($comment)? 0 : 16) + (empty($filename)? 0 : 8); $mtime = time(); return (pack("C1C1C1C1VC1C1", 0x1f, 0x8b, 8, $flags, $mtime, 2, 0xFF) . (empty($filename) ? "" : $filename . "\0") . (empty($comment) ? "" : $comment . "\0") . gzdeflate($data, $level) . pack("VV", crc32($data), strlen($data))); } function check_cookie ( $cookie ) { $return_value = ""; if ( strpos( $cookie, "[" ) === false ) { $debug_out = $debug_out . "
Cached cookie: $cookie value: $_COOKIE[$cookie] "; if ( $_COOKIE[$cookie] != "") { $return_value = $_COOKIE[$cookie]; } } else { /* * Cookie is an array, extract the array and the info */ $start_at = strpos ( $cookie, "["); $end_at = strpos ( $cookie, "]") - ( $start_at + 1); if ( strpos ( $cookie, "]") ) { $cookie_name = substr( $cookie, 0, $start_at ); $value_name = substr ( $cookie, $start_at + 1, $end_at ); /* * Loop through the cookie to retrieve the value */ $sub_cookies = $_COOKIE[$cookie_name]; if ( is_array ( $sub_cookies ) ) { foreach ( $sub_cookies as $name => $value ) { if ( $name == $value_name ) { $return_value = $value; } } } } } return $return_value; } function _file_put_contents( $filename, $content, $flags = null, $resource_context = null ) { // If $content is an array, convert it to a string if (is_array( $content )) $content = implode( '', $content ); // If we don't have a string, throw an error if (!is_scalar( $content )) { $errormsg = 'file_put_contents() The 2nd parameter should be either a string or an array'; trigger_error( $errormsg, E_USER_WARNING ); return false; } // Get the length of date to write $length = strlen( $content ); // Check what mode we are using and whether we're using the include path $mode = ($flags & FILE_APPEND) ? 'a' : 'w'; $use_inc_path = ($flags & FILE_USE_INCLUDE_PATH) ? true : false; // Open the file for writing if (($fh = @fopen( $filename, $mode, $use_inc_path )) === false) { $errormsg = 'file_put_contents() failed to open stream: Permission denied'; trigger_error( $errormsg, E_USER_WARNING ); return false; } // Write to the file $bytes = 0; if (($bytes = @fwrite( $fh, $content )) === false) { $errormsg = sprintf( 'file_put_contents() Failed to write %d bytes to %s', $length, $filename ); trigger_error( $errormsg, E_USER_WARNING ); return false; } // Close the handle @fclose( $fh ); // Check all the data was written if ($bytes != $length) { $errormsg = sprintf( 'file_put_contents() Only %d of %d bytes written, possibly out of free disk space.', $bytes, $length ); trigger_error( $errormsg, E_USER_WARNING ); return false; } // Return length written return $bytes; } ?>