$userIP[^if(def $env:HTTP_X_FORWARDED_FOR){$env:HTTP_X_FORWARDED_FOR}{$env:REMOTE_ADDR}] ^try{ $xml[^xdoc::load[http://ipgeobase.ru:7020/geo?ip=$userIP]] ^if($xml){ $country[^xml.selectSingle[/ip-answer/ip/country]] $detectedLang[$country.firstChild.nodeValue] } }{ $exception.handled(1) } ^if(^request:uri.right(1) ne '/' && !def ^file:justext[$request:uri] && !def $form:nameless && !def $form:search && !def $form:confirm && ^form:uri.pos[liqpay] < 0 && ^form:uri.pos[moneyua] < 0){ $response:status(301) $response:location[http://${env:SERVER_NAME}$request:uri/] } ### FORM PARAMS HASH ### $sParam[^form:param.trim[both;/]] $form[ $.tables[^hash::create[]] ] $tParam[^sParam.split[/]] ^if(def $tParam.piece){ ^tParam.menu{ $pair[^tParam.piece.split[-]] $param[$pair.piece] ^pair.offset(1) $value[$pair.piece] ^if($form.tables.[$param] is table){ ^rem{ #do nothing } }{ $form.tables.[$param][^table::create{field^#0A$form.[$param]}] } ^form.tables.[$param].append{$value} $form.[$param][$value] } } ^if($form.page eq '1'){ $response:status(301) $response:location[${form:uri}^formFields[ $.page[] ]] } ### DEBUG SWITCH ### ^if($form:nameless eq 'debug'){ ^if($cookie:debug){ $cookie:debug[] }{ $cookie:debug(1) } $response:location[./] } ^if($cookie:debug){ } ### CURRENT PAGE ### $uri[^if(def $form:uri){$form:uri}{/}] $lang[^if(def $form:lang){$form:lang}{$config.site.defaultLang}] $page[^sql:table{ SELECT id, parent_id, pageTitle, IF(windowTitle != '',windowTitle,pageTitle) AS windowTitle, module, method, results, template, keywords, description, text, clearCache, showSub, comments, visible FROM $tbl WHERE uri = '$uri' && lang = '$lang' }[ $.limit(1) ]] ^if(!$page.visible){ $response:location[http://$env:SERVER_NAME] } ^if(def $page.template){ ### CACHE PARAMS ### $cacheFile[/data/cache/$page.id/^math:md5[$request:uri]${cookie:[sort-$page.module]}$cookie:[results-$page.module]] ^if($env:REQUEST_METHOD eq 'POST' || $cookie:debug || $form:nameless eq 'nocache' || $env:REMOTE_ADDR eq '127.0.0.1'){ $cacheTime(0) }{ $cacheTime($config.site.cacheTime) } ^if($page.clearCache == 1){ ^cache[$cacheFile] ^sql:void{UPDATE $tbl SET clearCache = '' WHERE id = '$page.id'} } ### TEMPLATE ### $jTemplateCode{ $markList[^getMarkList[]] $langs[^sql:table{SELECT id,pageTitle,uriTitle FROM $tbl WHERE parent_id = '$config.site.langs_id' && visible = '1' && type = 'l' ORDER BY order_id}] $path[^getPath[$page.parent_id]] ^use[/include/templates/$page.template/template.p] ^template:show[] } ^try{ ^cache[$cacheFile]($cacheTime){ $jTemplateCode } }{ ^if(^exception.comment.pos[cache_put failed] >=0){ $exception.handled(1) $jTemplateCode } } ### VISIT COUNTER ### ^use[/include/classes/counter.p] ^file:lock[/include/counter.lock]{ ^counter:setHits[$page.id] ^counter:setHosts[] } }{ # ^if(^request:uri.right(1) ne '/' && !def ^file:justext[$request:uri]){ # $response:status(301) # $response:location[http://${env:SERVER_NAME}$request:uri/] # }{ $langsCount(^sql:int{SELECT COUNT(id) FROM $tbl WHERE parent_id = '$config.site.langs_id' && visible = '1' && type = 'l'}) ^if($langsCount > 1 && def $form:lang){ $response:status(301) $response:location[http://$env:SERVER_NAME/$form:lang/] }{ $response:status(404) $404[^file::load[text;/404.html]] ^process{^untaint{$404.text}} } ### REDIRECT $newUri[^sql:table{SELECT id,newUri AS value FROM ${tbl}_redirect WHERE oldUri = '$uri'}] ^if($newUri){ ^sql:void{UPDATE ${tbl}_redirect SET visitDate = '^date.sql-string[]' WHERE id = '$newUri.id'} $response:status(301) $response:location[http://${env:SERVER_NAME}$newUri.value^if(def $form:param){param$form:param}] } ^sql:delOld[redirect;visitDate;180] # } }