### 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] } } ### 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 FROM $tbl WHERE uri = '$uri' && lang = '$lang' && visible = '1' && parentInvisible != '1' }[ $.limit(1) ]] $langs[^sql:table{ SELECT id, pageTitle, uriTitle FROM $tbl WHERE parent_id = '$config.site.langs_id' && visible = '1' && type = 'l' ORDER BY order_id }] ^if(def $page.template){ ### CACHE $cacheKey[${request:uri}${cookie:[sort-$page.module]}${cookie:[results-$page.module]}${cookie:currency}] $cacheFile[/data/cache/$page.id/^math:md5[$cacheKey]] ^if( $env:REQUEST_METHOD eq 'POST' || $cookie:debug || $form:nameless eq 'nocache' ){ $cacheTime(0) }{ $cacheTime($config.site.cacheTime) } ^if($page.clearCache == 1){ ^cache[$cacheFile] ^sql:void{UPDATE $tbl SET clearCache = '' WHERE id = '$page.id' LIMIT 1} } ### TEMPLATE $jTemplateCode{ ^if($langs > 1 && !def $form:lang){ $response:status(301) $response:location[^langPrefix[^untaint{$request:uri}]] } ^if($langs > 1){ $translList[^getTranslList[]] } $markList[^getMarkList[]] $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(def $lang && $langs > 1 && def $uri){ $response:status(301) $response:location[http://$env:SERVER_NAME/$lang/] }{ $response:status(404) $404[^file::load[text;/404.html]] ^process{^untaint{$404.text}} } } ################# ### REDIRECTS ### ################# ### WWW REDIRECT ^if(^env:SERVER_NAME.left(4) eq 'www.'){ $response:status(301) $response:location[http://^env:SERVER_NAME.mid(4)$request:uri] } ### TRAILING SLASH REDIRECT ^if(^request:uri.right(1) ne '/' && !def ^file:justext[$request:uri] && !def $form:nameless && !def $form:search && !def $form:confirm){ $response:status(301) $response:location[http://${env:SERVER_NAME}$request:uri/] } ### PAGE=1 REDIRECT ^if($form.page eq '1'){ $response:status(301) $response:location[${form:uri}^formFields[ $.page[] ]] } ### DB REDIRECT $newUri[^sql:table{SELECT id, newUri AS value FROM ${tbl}_redirect WHERE oldUri = '$request:uri' && lang = '$lang'}[ $.limit(1) ]] ^if($newUri){ ^sql:void{UPDATE ${tbl}_redirect SET visitDate = '^date.sql-string[]' WHERE id = '$newUri.id' LIMIT 1} $response:status(301) $response:location[http://${env:SERVER_NAME}$newUri.value^if(def $form:param && ^request:uri.pos[/param/] < 0){param$form:param}] ^sql:delOld[redirect;visitDate;180] }