info('site', PageCache::globalKeyArray(), AA::$site_id.":$post2shtml_id:$all_ids:$add_disc:$disc_type:$sh_itm:$parent_id", $ids, $sel_ids, $disc_ids); // store nocache to the variable (since it should be set for some view and we // do not want to have it set for whole site. // temporary solution - should be solved on view level (not global nocache) - TODO $site_nocache = $_REQUEST['nocache']; if ($cacheentry = $GLOBALS['pagecache']->getPage($cache_key,$site_nocache)) { $cacheentry->processPage(); if ( $_REQUEST['debug'] OR $_REQUEST['debugtime']) { echo '

Site cache hit!!!'; echo '
Page generation time: '. (microtime(true) - $timestart); echo '
Dababase instances: '. DB_AA::$_instances_no; echo '
(spareDBs): '. count($spareDBs); AA::$dbg->duration_stat(); } exit; } // -- /CACHE ------------------------------------------------------------------ require_once AA_INC_PATH."util.php3"; function IsInDomain( $domain ) { return (($_SERVER['HTTP_HOST'] == $domain) || ($_SERVER['HTTP_HOST'] == 'www.'.$domain)); } function StripslashesDeep($value) { return is_array($value) ? array_map('StripslashesDeep', $value) : stripslashes($value); } // ----------------- function definition end ----------------------------------- // change the state add_vars(); // get variables pased to stm page if ( get_magic_quotes_gpc() ) { $_POST = StripslashesDeep($_POST); $_GET = StripslashesDeep($_GET); $_REQUEST = StripslashesDeep($_REQUEST); $_COOKIE = StripslashesDeep($_COOKIE); } require_once AA_BASE_PATH."modules/site/router.class.php"; // we tried to remove all global $db, so let's try to comment out following global object // honza 2015-12-30 // is_object( $db ) || ($db = getDB()); $err["Init"] = ""; // error array (Init - just for initializing variable $host = ltrim($_SERVER['HTTP_HOST'],'w.'); AA::$site_id = $_REQUEST['site_id'] ?: unpack_id(DB_AA::select1("SELECT id FROM `module`", 'id', array(array('type','W'),array('slice_url',array("http://$host/", "https://$host/","http://www.$host/","https://www.$host/"))))); if ( !($module = AA_Module_Site::getModule(AA::$site_id)) ) { echo "
Error: no 'site_id' or 'site_id' is invalid"; exit; } $lang_file = $module->getProperty('lang_file'); AA::$encoding = $module->getCharset(); // @deprecated - use AA_Router_Seo instead // There are two possibilities, how to control the apc_state variable. It could // be se in ./modules/site/sites/site_...php control file. The control file // could be managed only by people, who have the access to the AA sources on the // server. If we want to permit control of the site to extenal people, which do // not have access to AA scripts directory, then it is possible to them to not // fill "site control file" in site configuration dialog and then call this // script from their own file, where the new $apc_state, $slices4cache and // $site_id will be defined and passed by GET method. Just like this: // // $url = 'http://example.org/apc-aa/modules/site/site.php3?'; // $url .= http_build_query( array( 'apc_state' => $apc_state, // 'slices4cache' => $slices4cache, // 'site_id' => 'ae54378beac7c7e8a998e7de8a998e7a' // )); // readfile($url); // /@deprecated - use AA_Router_Seo instead $hit_lid = null; if ($module->getProperty('flag') == 1) { // 1 - Use AA_Router_Seo $seo_slices = $module->getRelatedSlices(); //$lang_file = AA_Modules::getModuleProperty(AA::$site_id, 'lang_file'); // home can contain some logic like: {ifin:{server:SERVER_NAME}:czechweb.cz:/cz/home:/en/home} $home = AA_Stringexpand::unalias(trim($module->getProperty('state_file'))) ?: '/' .substr($lang_file,0,2). '/'; $router = AA_Router::singleton('AA_Router_Seo', $seo_slices, $home); // use REDIRECT_URL for homepage redirects: // RewriteRule ^/?$ /en/home [QSA] // RewriteRule ^/?en /apc-aa/modules/site/site.php3?site_id=439ee0af030d6b2598763de404aa5e34 [QSA,L,PT] // or (I think better) // RewriteEngine on // RewriteRule ^/?$ /apc-aa/modules/site/site.php3?site_id=439ee0af030d6b2598763de404aa5e34 [QSA,L,PT] // RewriteRule ^/?en /apc-aa/modules/site/site.php3?site_id=439ee0af030d6b2598763de404aa5e34 [QSA,L,PT] $uri = (strlen($_SERVER['REQUEST_URI']) > 1) ? $_SERVER['REQUEST_URI'] : $_SERVER['REDIRECT_URL']; $apc_state = $router->parse($uri); $lang_file = substr_replace($lang_file, $apc_state['xlang'], 0, 2); // count hit for current page - deffered after the page is sent to user $hit_lid = $router->xid(); } elseif ( $module->getProperty('state_file') ) { // in the following file we should define apc_state variable require_once AA_BASE_PATH."modules/site/sites/site_".$module->getProperty('state_file'); $apc_state['4cacheQS'] = shtml_query_string(); $_REQUEST['nocache'] = $_REQUEST['nocache'] ?: $nocache; } if ( !isset($apc_state) ) { echo "
Error: no 'state_file' nor 'apc_state' variable defined"; exit; } require_once AA_BASE_PATH."modules/site/util.php3"; // module specific utils require_once AA_BASE_PATH."modules/site/sitetree.php3"; require_once AA_INC_PATH."searchlib.php3"; require_once AA_INC_PATH."easy_scroller.php3"; require_once AA_INC_PATH."view.php3"; require_once AA_INC_PATH."discussion.php3"; require_once AA_INC_PATH."item.php3"; if ($lang_file) { mgettext_bind(GetLang($lang_file), 'output'); AA::$lang = strtolower(substr($lang_file,0,2)); // actual language - two letter shortcut cz / es / en AA::$langnum = array(AA_Content::getLangNumber(AA::$lang)); // array of prefered languages in priority order. } $page_content = $module->getSite( $apc_state ); // AJAX check if((AA::$headers['encoding'] != 'utf-8') && (AA::$encoding != 'utf-8') && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $page_content = ConvertCharset::singleton()->Convert($page_content, AA::$encoding, 'utf-8'); AA::$headers['encoding'] = 'utf-8'; } $cacheentry = new AA_Cacheentry($page_content, AA::getHeaders(), $hit_lid); $cacheentry->processPage(); // changed the way, how to get $slices4cache - now we ask for module ids realy // used during page generation. Honza 2015-12-29 $slices4cache = AA_Module::getUsedModules(); if (empty($slices4cache)) { // can't be combined empty() and assignment = for php 5.3 // probably not necessary $slices4cache = array(AA::$site_id); } AA::$debug && AA::$dbg->warn(__FILE__."-".__LINE__); if (!$site_nocache) { $str2find = new CacheStr2find($slices4cache, 'slice_id'); $GLOBALS['pagecache']->storePage($cache_key, $cacheentry, $str2find); } AA::$debug && AA::$dbg->warn(__FILE__."-".__LINE__); if ($debugtime) { echo '

Site cache MIS!!!'; echo '
Page generation time: '. (microtime(true) - $timestart); echo '
Dababase instances: '. DB_AA::$_instances_no; echo '
(spareDBs): '. count($spareDBs); echo '
UsedModules:
- '. join('
- ', array_map(function($mid) {return AA_Module::getModuleName($mid);}, $slices4cache)); AA::$dbg->duration_stat(); } // ----------------- process status end --------------------------------------- function ModW_StoreIDs($spot_id, $depth) { $GLOBALS['show_ids'][] = $spot_id; } // id = an item id, unpacked or short // short_ids = boolean indicating type of $ids (default is false => unpacked) function ModW_id2item($id,$use_short_ids="false") { return AA_Items::getItem(new zids($id, $use_short_ids ? 's' : 'l')); } /** Convert a state string into an array, based on the variable names and * regular expression supplied, if str is not present or doesn't match * the regular expression then use $strdef * e.g. ModW_str2arr("tpmi",$apc,"--h-", "^([-p])([-]|[0-9]+)([hbsfcCt])([-]|[0-9]+)"; */ function ModW_str2arr($varnames, $str, $strdef, $reg) { if (!$str) { $str = $strdef; } $varout = array(); $reg = '`'.str_replace('`','\`',$reg).'`'; if (!(preg_match($reg, $str, $vars))) { if (!(preg_match($reg, $strdef, $vars))) { print("Error initial string $strdef doesn't match regexp $reg\n
"); } } for ($i=0, $ino=min(strlen($varnames),count($vars)-1); $i<$ino; ++$i) { $varout[substr($varnames,$i,1)] = $vars[$i+1]; } AA::$debug && AA::$dbg->info('State=',$varout); return $varout; } /** Convert an array into a state string, in the order from $varnames * This is fairly simplistic, just concatennating state, a more * sophisticated sprint version might be needed */ function ModW_arr2str($varnames, $arr) { $strout = ""; for ($i=0, $ino=strlen($varnames); $i<$ino; ++$i) { $strout .= $arr[substr($varnames,$i,1)]; } return $strout; } // do not remove this exit - we do not want to allow users // to include this script (honzam) exit; ?>