ident)] = $row->value; } } // DEFAULT FUNCTIONS --------------------------------------------------------- function echo404 ($type = 0) { header("HTTP/1.0 404 Page Not Found"); if (DEBUG == 'true') $GLOBALS[DEBUG]["HTTP 404"] = 'true'; if (!$type) { @ob_get_clean(); echo ' Page Not Exists (Error 404)

Page Not Exists (Error 404)

Try this link: '.$_SERVER['HTTP_HOST'].'

Copyright © '.date('Y').' WEB CMS

'; exit; } } function e404() { # zobrazuje 404 $q = "select * from ws_cms_mod_pages where id='{$GLOBALS[DOMAIN]->error_404}' and display='Y' limit 1"; if (nr($q)) { echo404('header'); $content_page = row($q); } else { echo404(); } if ($GLOBALS[CONTENT]) { # ak sa uz generuje nejaka stranka if ($content_page) { # a ak mame nejaku 404 na zobrazenie tak presmerujeme na 404 if ($GLOBALS[STRUCTURE]->multi_language == 'Y') { $url = $content_page->lang.'/'.$content_page->url; } else { $url = $content_page->url; } $url = "http://".$GLOBALS[DOMAIN]->domain.'/'.BASE_DIR.$url; header("Location: $url"); exit; } } return $content_page; } # spracovanie stranky function content($ws_cms_load_page = 0) { # vytvorime globals pre smarty if (!is_array($GLOBALS['SMARTY'])) $GLOBALS['SMARTY'] = array(); if (!is_array($GLOBALS['SMARTY_HISTORY_PAGE'])) $GLOBALS['SMARTY_HISTORY_PAGE'] = array(); # ak vlozime ID nacitame si data stranky if (is_numeric($ws_cms_load_page) && intval($ws_cms_load_page) > 0) { $ws_cms_load_page = row("select * from ws_cms_mod_pages where id='$ws_cms_load_page' and display='Y' limit 1"); } # uz mame data stranky a generujeme stranku if ($ws_cms_load_page) { # hladame cash stranky if ($ws_cms_load_page->cash && !count($_POST)) { $get_hash = $_GET; if (count($_SESSION)) $get_hash = array_merge($get_hash,$_SESSION); $get_hash = md5(serialize($get_hash)); $q = "select * from `ws_cms_mod_pages_cash` where `page_id`='$ws_cms_load_page->id' and `get_hash`='$get_hash' and `t_expire`>'".date("Y-m-d H:i:s")."' limit 1"; if (nr($q)) { $cashed_page = row($q); if (DEBUG == 'true') { $GLOBALS[DEBUG]["Cash action [$ws_cms_load_page->lang/$ws_cms_load_page->url]"] = "Read"; } # refresh z cache $array = unserialize($cashed_page->globals); # obnovime globals a session $GLOBALS = $array['GLOBALS']['GLOBALS']; $_SESSION = unserialize($cashed_page->session); return $cashed_page->content; } } # vytvorime smarty pole pre generovanu stranku $GLOBALS['SMARTY'][$ws_cms_load_page->id] = array(); $GLOBALS['SMARTY_ACTUAL_PAGE'] = $ws_cms_load_page; $GLOBALS['SMARTY_HISTORY_PAGE'][] = $GLOBALS['SMARTY_ACTUAL_PAGE']; if (!$ws_cms_load_page->cash) { if (DEBUG == 'true') $GLOBALS[DEBUG]["Cash action [$ws_cms_load_page->lang/$ws_cms_load_page->url]"] = "Cash no set"; } # koniec hladania cash # zaciatok generovania stranky if (DEBUG == 'true') $GLOBALS[DEBUG]["Start generate [$ws_cms_load_page->lang/$ws_cms_load_page->url]"] = "content/$ws_cms_load_page->content_script.php"; if (DEBUG == 'true') $GLOBALS[DEBUG]["Start generate TPL [$ws_cms_load_page->lang/$ws_cms_load_page->url]"] = "content/$ws_cms_load_page->content_template.tpl"; # nadefinujeme parametre $q = "select * from ws_cms_mod_pages_data where page_id='$ws_cms_load_page->id'"; $ws_cms_load_page_res = mq($q); while ($ws_cms_load_page_res_row = fo($ws_cms_load_page_res)) { eval("\$$ws_cms_load_page_res_row->system_name = \$ws_cms_load_page_res_row->content; "); eval("\$GLOBALS['SMARTY']['{$ws_cms_load_page->id}']['{$ws_cms_load_page_res_row->system_name}'] = \$ws_cms_load_page_res_row->content; "); if (DEBUG == 'true') $GLOBALS[DEBUG]["Set param [$ws_cms_load_page->lang/$ws_cms_load_page->url => $ws_cms_load_page_res_row->system_name]"] = $ws_cms_load_page_res_row->system_name; } # zistime ci spustime kod controlleru $includeControllerScript = true; $controllerClass = $ws_cms_load_page->content_script; $controllerClass = array_pop(explode("/", $controllerClass)); if (class_exists($controllerClass)) { $controllerInterfaces = array_keys(class_implements($controllerClass)); $controllerParents = array_keys(class_parents($controllerClass)); if (in_array('frontendController',$controllerParents) && in_array('iFrontendController',$controllerInterfaces)) { if (method_exists($controllerClass, 'cInitialize')) { $includeControllerScript = false; } } } # spustime kod stranky ob_start(); if ($ws_cms_load_page->content_script && $includeControllerScript) include "content/$ws_cms_load_page->content_script.php"; # spustime initialize metodu v kontroleri $controllerClass = $ws_cms_load_page->content_script; $controllerClass = array_pop(explode("/", $controllerClass)); if (class_exists($controllerClass)) { $controllerInterfaces = array_keys(class_implements($controllerClass)); $controllerParents = array_keys(class_parents($controllerClass)); if (in_array('frontendController',$controllerParents) && in_array('iFrontendController',$controllerInterfaces)) { if (method_exists($controllerClass, 'cInitialize')) { $pgController = new $controllerClass; $pgController->cInitialize(); } } } # ak mame smarty if ($ws_cms_load_page->content_template) { ob_get_clean(); ob_start(); $ws_cms_smarty = new Smarty(); foreach ($GLOBALS['SMARTY'][$ws_cms_load_page->id] as $ws_cms_smarty_k => $ws_cms_smarty_v) { $ws_cms_smarty->assign($ws_cms_smarty_k,$ws_cms_smarty_v); } $ws_cms_smarty->display("content/$ws_cms_load_page->content_template.tpl"); } $out = ob_get_clean(); # ulozime cache ak je potreba if ($ws_cms_load_page->cash && !$ws_cms_no_write_cash && !count($_POST)) { $time = time() + $ws_cms_load_page->cash*60; $time = date('Y-m-d H:i:s',$time); $out_write = addslashes($out); $get_hash = $_GET; if (count($_SESSION)) $get_hash = array_merge($get_hash,$_SESSION); $get_hash = md5(serialize($get_hash)); $globals = addslashes(serialize($GLOBALS)); $session = addslashes(serialize($_SESSION)); $q = "insert into `ws_cms_mod_pages_cash` (`page_id`,`t_expire`,`get_hash`,`content`,`globals`,`session`) values ('$ws_cms_load_page->id','$time','$get_hash','$out_write','$globals','$session')"; mq($q); if (DEBUG == 'true') $GLOBALS[DEBUG]["Cash action [$ws_cms_load_page->lang/$ws_cms_load_page->url]"] = "Create"; } # vratime actual smarty pre generovanu stranku / aby fungovalo vnorenie array_pop($GLOBALS['SMARTY_HISTORY_PAGE']); $GLOBALS['SMARTY_ACTUAL_PAGE'] = $GLOBALS['SMARTY_HISTORY_PAGE'][count($GLOBALS['SMARTY_HISTORY_PAGE'])-1]; # vratime obsah stranky return $out; } } // DEFAULT FUNCTIONS --------------------------------------------------------- // TEST FOR index.php request ------------------------------------------------ if (substr($_SERVER['REQUEST_URI'],0,10) == '/index.php') { # presmerujeme header("Location: /"); header( "HTTP/1.1 301 Moved Permanently"); exit; } // TEST FOR HOST NAME -------------------------------------------------------- $domCheck = $_SERVER[HTTP_HOST]; $q = "select * from ws_cms_mod_pages_domains"; $res = mq($q); while ($row = fo($res)) { if ($row->domain == $domCheck) { $domain = $row; break; } if ($row->domain{0} == '*') { $row->domain = substr($row->domain, 1,strlen($row->domain)-1); if (array_pop(explode($row->domain,$domCheck.'-')) == '-') { $row->domain = $domCheck; $domain = $row; break; } } } if (!$domain) { echo404(); } $GLOBALS[DOMAIN] = $domain; if (DEBUG == 'true') $GLOBALS[DEBUG]["DOMAIN [$domain->id]"] = $domain->domain; // TEST FOR HOST NAME -------------------------------------------------------- // SEARCH DOMAIN STRUCTURE --------------------------------------------------- $q = "select * from ws_cms_mod_pages_structures "; $res = mq($q); while ($row = fo($res)) { $domains = explode(",",$row->domains); if (in_array($domain->id,$domains)) { if ($structure) { echo404(); } $structure = $row; } } if (!$structure) echo404(); $GLOBALS[STRUCTURE] = $structure; if (DEBUG == 'true') $GLOBALS[DEBUG]["STRUCTURE [$structure->id]"] = $structure->name; // SEARCH DOMAIN STRUCTURE --------------------------------------------------- // SEARCH PAGE IN STRUCTURE -------------------------------------------------- $url = $_GET[request_url]; if (!$url) { // vstupna stranka domeny $q = "select * from ws_cms_mod_pages where id='$domain->input_page' and display='Y' limit 1"; } else { // nieje vstupna stranka if ($structure->multi_language == 'Y') { // ak je struktura priradena domene multijazycna $url = explode("/",$url); $searchLang = array_shift($url); $url = implode("/",$url); } else { // nie multijazycna struktura $searchLang = $structure->languages; } # ak stranka nema na konci lomitko if (substr($url,strlen($url)-1,1) != '/' && $url) { # doplnime lomitko if ($url) { $url = "/$url/"; } else { $url = '/'; } # doplnime jazyk if ($structure->multi_language == 'Y') { $url = "/".$searchLang.$url; } # doplnime get parametre $pos = strpos($_SERVER['REQUEST_URI'],"?"); $params = substr($_SERVER['REQUEST_URI'], $pos,10000); if ($params && $pos) { $url .= $params; } # presmerujeme header("Location: $url"); header( "HTTP/1.1 301 Moved Permanently"); exit; } // select danej stranky $q = "select * from ws_cms_mod_pages where lang='$searchLang' and url='$url' and structure_id='$structure->id' and display='Y' limit 1"; } if (nr($q)) { // ak mame najdenu stranku $content_page = row($q); // testneme ci stranka nahodou nieje zadana ako 404 ak ano dame 404header if ($GLOBALS[DOMAIN]->error_404 == $content_page->id) { echo404('header'); } # ak je stranka specifikovana len pre jednu domenu a nachadzame sa na inej, dame 404 if ($content_page->domain && $content_page->domain != $GLOBALS[DOMAIN]->id) { $content_page = e404(); #exit; } # testneme ci neni homepage a presmerujeme if ($GLOBALS['DOMAIN']->input_page == $content_page->id && $url) { header("Location: ".getlink($content_page->id)); exit; } } else { // skusime este ci neexistuje nejaky rewrite -------------------------- $povodna_url = $url; while ($url != '/') { $url = removeEmptyValues(explode("/",$url)); array_pop($url); $url = implode("/",$url).'/'; $q = "select * from ws_cms_mod_pages where lang='$searchLang' and url='$url' and structure_id='$structure->id' and display='Y' and rewrite='Y' limit 1"; if (nr($q)) { // nasli sme rewrite stranku ---------------------------- $content_page = row($q); $rozdiel = substr($povodna_url,strlen($url),strlen($povodna_url)); $rozdiel = removeEmptyValues(explode("/",$rozdiel)); $content_page->rewrite_data = $rozdiel; } } // ak sa stranka nenasla dame 404 z domeny, ak domena nema 404page dame klasicky error if (!$content_page) { $content_page = e404(); } } // select layoutu pre zobrazenu stranku if ($content_page->layout) { $q = "select * from ws_cms_mod_pages where id='$content_page->layout' and display='Y' limit 1"; if (nr($q)) { $layout_page = row($q); } } // SEARCH PAGE IN STRUCTURE -------------------------------------------------- // SAVE GLOBALS PARAMETERS --------------------------------------------------- $GLOBALS[CONTENT] = $content_page; $GLOBALS[LAYOUT] = $layout_page; $GLOBALS[LANGUAGE] = $content_page->lang; $GLOBALS[STRUCTURE] = $GLOBALS[STRUCTURE]; $GLOBALS[DOMAIN] = $GLOBALS[DOMAIN]; $GLOBALS[REWRITE] = $content_page->rewrite_data; // SAVE GLOBALS PARAMETERS --------------------------------------------------- unset( $domain, $q, $structure, $url, $searchLang, $content_page, $layout_page ); # autoinclude public PHP if (file_exists("content/public.php")) { ob_start(); require_once "content/public.php"; ob_get_clean(); } # read structure setings page if ($GLOBALS[STRUCTURE]->setings_page) { $ssp = row("select * from `ws_cms_mod_pages` where `id`='{$GLOBALS[STRUCTURE]->setings_page}' limit 1"); if ($ssp) { $q = "select * from `ws_cms_mod_pages` where `id` in ($ssp->similar_pages) and `lang`='{$GLOBALS['LANGUAGE']}' limit 1"; $ssp = row($q); if ($ssp) { content($ssp); } } unset($ssp); } # generating source page $content = content($GLOBALS[CONTENT]); $layout = content($GLOBALS[LAYOUT]); # vnorenie stranky do layoutu a echo stranky if (count(explode("{|CONTENT|}",$layout)) > 1) { echo str_replace("{|CONTENT|}",$content,$layout); } elseif (count(explode("[|CONTENT|]",$layout)) > 1) { echo str_replace("[|CONTENT|]",$content,$layout); } else { echo $content; } # uzatvorenie mysql spojenia @mysql_close(); # ak mame hodnotu DEBUG zobrazime list --------------------------------------- if (DEBUG == 'true') { $end = microtime(); list ($start_sec,$start_mic) = explode(" ",$start); $start = $start_sec + $start_mic; list ($end_sec,$end_mic) = explode(" ",$end); $end = $end_sec + $end_mic; $GLOBALS[DEBUG]['Generate time'] = ($end - $start); # display debug echo ""; foreach (array_keys($GLOBALS[DEBUG]) as $key) { echo "'; } echo "
Close debug report
$key".$GLOBALS[DEBUG][$key].'
"; } # end display DEBUG list ----------------------------------------------------- ?>