ACC SHELL
<?php
//die('ekrk');
//print_R($_SERVER);
//(print_r($_GET));
//die();
//phpinfo();
class Kernel
{
var $page;
var $template;
var $db;
//var $db2;
var $httpRoot;
var $Root;
var $ftp;
var $languages;
var $language;
var $pagesLanguages; // informace o vsech strankach
var $childern;
var $menu;
var $pageBame; // nazev aktualni stranky
var $map;
var $mapById;
var $languageCode;
var $path_suffix;
var $langs; // jazykove mutace textu - pole ve formatu klic => preklad v dane jazykove verzi
function Kernel()
{
if (FALSE==$_GET['page_name'])
{
$_GET['page_name']='/';
}
include_once('inc/config.php');
include_once('inc/fce.php');
include_once('inc/db.php');
require_once('inc/admin/forms.php');
$this->db = new Db();
// $this->db2 = new Db(false);
$this->http_root = $http_root;
$this->Root = $root;
$this->ftp = $GLOBALS['ftp'];
$this->seo_title = $seo_title;
$this->seo_keywords = $seo_keywords;
$this->seo_description = $seo_description;
$this->seo_author = $seo_author;
$this->seo_robots = $seo_robots;
$this->seo_path_favicon = $seo_path_favicon;
$tmp=$this->db->select('*', 'sys_pages_languages');
for ($i=0; $i<count($tmp); $i++)
{
$this->pagesLanguages[$tmp[$i]['id_page']][$tmp[$i]['id_language']]=$tmp[$i];
}
$page_name=preg_replace('/^(.*)\.php$/', '\\1', $_GET['page_name']);
$path=explode('/', $page_name);
//print_R($path);
// jazyky
$this->languages=$this->db->select('*', 'languages', 'active=\'Y\'', '', 'list');
$this->language=array();
if (1<count($this->languages))
{
$language_code=array_shift($path);
if ($language_code=='nemovitost' or $language_code=='real-estates' or $language_code=='immobilien'){
$language_code2 = explode('/',$_GET["lang"]);
$language_code = $language_code2[2];
}
//die($language_code);
for ($i=0; $i<count($this->languages); $i++)
{
if ($language_code==$this->languages[$i]['code'])
{
//echo 'a';
$this->language=$this->languages[$i];
}
}
//die($this->language['code']);
/*
if ('cz'==$this->language['code']){
header('location: '.rtrim($http_root.'/'.$page_name.'/', '/').'/', TRUE, 301);
die();
}else*/if (FALSE==$this->language['code'])
{
$this->language=$this->languages[0];
//header('location: '.rtrim($http_root.$this->languages[0]['code'].'/'.$page_name.'/', '/').'/', TRUE, 301);
//header('location: '.rtrim($http_root), TRUE, 301);
//die();
}
}
else
{
$this->language=$this->languages[0];
}
// print_R($this->language);
// jazykove mutace kratkych statickych textu
@include_once('inc/langs.php');
$keys=@array_keys($languages);
for ($i=0; $i<count($keys); $i++)
{
$this->langs[$keys[$i]]=$languages[$keys[$i]][$this->language['code']];
}
// zjisteni startovaci stranky
$tmp=$this->db->select('id', 'sys_pages', 'start=\'Y\'', '1');
$start_page=$this->pagesLanguages[$tmp['id']][$this->language['id']]['path'];
if (FALSE==$start_page)
{
die('Chyba: neni definovana startovaci stranka.');
}
$page_name=preg_replace('/^'.$this->language['code'].'(\/*)(.*)$/', '\\1\\2', $_GET['page_name']);
//die($page_name);
if (FALSE==$page_name)
{
// die('a');
// header('location: '.str_replace('//', '/', $http_root.$language_code.$start_page), TRUE, 301);
// die();
}
if ('/'!=$page_name[0])
{
$page_name='/'.$page_name;
}
$page_name=rtrim($page_name, '/').'/';
$this->pageName='/';
// stranka
$tmp_path=explode('/', $page_name);
$this->pathSuffix=array();
$segment=array_shift($tmp_path);
$page_name=$segment.'/';
while (0<count($tmp_path))
{
$tmp=$this->db->select('pl.*, p.*', 'sys_pages AS p LEFT JOIN sys_pages_languages AS pl ON (p.id=pl.id_page)', 'pl.id_language='.(int)$this->language['id'].' AND p.active=\'Y\' AND path=\''.addslashes($page_name).'\'', '1');
if (0<count($tmp))
{
$this->page=$tmp;
$tmp=$this->db->select('c.css_file', 'sys_css_pages AS cp LEFT JOIN sys_csss AS c ON (c.id=cp.id_css)', 'cp.id_page='.(int)$this->page['id']);
$this->page['css']='';
for ($i=0; $i<count($tmp); $i++)
{
$this->page['css'].="<link href=\"".$this->http_root."css/".$tmp[$i]['css_file']."\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n";
}
$segment=array_shift($tmp_path);
$this->pathSuffix=array();
$this->pageName=$page_name;
$page_name.=$segment.'/';
$this->pageName=str_replace('//', '/', $this->pageName);
}
else
{
header('location:'.$this->http_root.'stranka-nenalezena/', true, 301);
$this->pathSuffix[]=$segment;
$page_name.=$segment;
$segment=array_shift($tmp_path);
}
}
//die();
// sablona
$this->template=$this->db->select('tl.*, t.*', 'sys_templates AS t LEFT JOIN sys_templates_languages AS tl ON (t.id=tl.id_template)', 'tl.id_language='.(int)$this->language['id'].' AND t.id='.(int)$this->page['id_template'], '1');
$tmp=$this->db->select('c.css_file', 'sys_css_templates AS cp LEFT JOIN sys_csss AS c ON (c.id=cp.id_css)', 'cp.id_template='.(int)$this->template['id']);
$this->template['css']='';
for ($i=0; $i<count($tmp); $i++)
{
$this->template['css'].="<link href=\"".$this->http_root."css/".$tmp[$i]['css_file']."\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n";
}
// jazyky
$this->template['languages']='';
if (1<count($this->languages))
{
for ($i=0; $i<count($this->languages); $i++)
{
$this->template['languages'].='<li><a href="'.$this->http_root.$this->languages[$i]['code'].$this->pagesLanguages[$this->page['id']][$this->languages[$i]['id']]['path'].'">'.$this->languages[$i]['code'].'</a></li>
';
if ($language_code==$this->languages[$i]['code'])
{
$this->language=$this->languages[$i];
}
}
if (TRUE==$this->teplate['language'])
{
$this->template['language']='
<hr class="no_css" />
<ul id="languages">
'.$this->template['languages'].' </ul>
';
}
}
// vytvoreni menu
$this->menu=array();
$this->map=array();
$this->mapById=array();
$tmp=$this->db->select('p.*, pl.name, pl.path', 'sys_pages AS p LEFT JOIN sys_pages_languages AS pl ON (p.id=pl.id_page)', 'pl.id_language='.(int)$this->language['id'].' AND p.active=\'Y\' AND pl.name != "" group by p.id', '', 'p.list');
for ($i=0; $i<count($tmp); $i++)
{
$this->childern[(int)$tmp[$i]['id_parent']][]=$tmp[$i];
}
$this->template['menu']='';
for ($i=0; $i<count($this->childern[0]); $i++)
{
$active=FALSE;
$this->menu[]=array(
'text'=>$this->childern[0][$i]['name'],
'href'=>str_replace('//', '/', $this->http_root.$this->language['code'].$this->childern[0][$i]['path'].'/'),
'submenu'=>array(),
);
if ($i==count($this->childern[0])-1)
{
$last=TRUE;
}
else
{
$last=FALSE;
}
if (0==$i)
{
$first=TRUE;
}
else
{
$first=FALSE;
}
$this->template['menu'].=$this->menu_node($this->childern[0][$i], $this->menu[count($this->menu)-1]['submenu'], $active, $first, $last, $this->map, $this->mapById);
}
if (TRUE==$this->template['menu'])
{
$this->template['menu']='
<ul id="menu">
'.$this->template['menu'].'
</ul>
';
}
$this->map=@array_reverse($this->map);
$this->mapById=@array_reverse($this->mapById);
//print($this->map);
$this->loadModules();
}
function menu_node($node, &$menu_node, &$active, $first=FALSE, $last=FALSE, &$map, &$mapById, $cssId = "menu")
{
if (TRUE==$first)
{
$class2.=' first';
}
if (TRUE==$last)
{
$class2.=' last';
}
if ($this->language['code']=='cz'){
$this->language['code']='';
}
if ($this->pageName==$node['path'])
{
$active=TRUE;
$map[]='<a class="'.trim($class).'" href="'.str_replace('//', '/', $this->http_root.$this->language['code'].$node['path'].'/').'">'.$node['name'].'</a>';
$mapById[]=$node['id'];
}
else
{
$active=FALSE;
}
$m=1;
$submenu_str='';
for ($i=0; $i<count($this->childern[$node['id']]); $i++)
{
$child_active=FALSE;
$menu_node[]=array(
'text'=>$this->childern[$node['id']][$i]['name'],
'href'=>str_replace('//', '/', $this->http_root.$this->language['code'].$this->childern[$node['id']][$i]['path'].'/'),
'submenu'=>array(),
);
if ($i==count($this->childern[$node['id']])-1)
{
$last=TRUE;
}
else
{
$last=FALSE;
}
if (0==$i)
{
$first=TRUE;
}
else
{
$first=FALSE;
}
$submenu_str.=$this->menu_node($this->childern[$node['id']][$i], $menu_node[count($menu_node)-1]['submenu'], $child_active, $first, $last, $map, $mapById);
$active=$active || $child_active;
}
$class='';
if (TRUE==$active)
{
$class.=' active';
}
if ('Y'==$node['in_menu'])
{
$result='<li class="m'.($node["id"]) .$class2.'"><a class="'.trim($class).'" href="'.str_replace('//', '/', $this->http_root.$this->language['code'].$node['path'].'/').'">'.$node['name'].'</a>';
$GLOBALS["k"]++;
}
if ( TRUE==$submenu_str )
{
if (FALSE==$active)
{
if ('Y'==$node['in_menu'])
{
$result.='
<ul class="no_css">
'.$submenu_str.'
</ul>
';
}
}
else
{
if ( (TRUE==$active) && ($this->pageName!=$node['path']) )
{
$map[]='<a class="'.trim($class).'" href="'.str_replace('//', '/', $this->http_root.$this->language['code'].$node['path'].'/').'">'.$node['name'].'</a>';
$mapById[]=$node['id'];
}
if ('Y'==$node['in_menu'])
{
$result.='
<ul id="submenu">
'.$submenu_str.'
</ul>
';
}
}
}
if ('Y'==$node['in_menu'])
{
$result.='</li>';
}
else
{
$result.=' ';
}
return str_replace('//', '/',$result);
}
function loadModules()
{
require_once('inc/module.php');
$tmp=$this->db->select('*', 'sys_modules');
$modules=array();
for ($i=0; $i<count($tmp); $i++)
{
if (TRUE==include_once('modules/'.$tmp[$i]['sys_name'].'/'.$tmp[$i]['sys_name'].'.php'))
{
$class_name=ucfirst(strtolower($tmp[$i]['sys_name']));
$this->$tmp[$i]['sys_name']=new $class_name('modules/');
}
}
}
function getHTML()
{
// $this->db = new Db();
$mod = $this->db->select(
'id_module',
'sys_pages',
'id = '.(int)$this->page['id'],
'1'
);
ob_start();
if (TRUE==@include('pages/'.$this->page['script_file']))
{
$this->page['content']=ob_get_contents();
// nacteni promenny stranky
$tmp=$this->db->select(
'v.name, vv.value',
'sys_vars AS v
LEFT JOIN sys_var_values AS vv ON (vv.id_var=v.id)
',
'vv.id_language='.(int)$this->language['id'].'
AND
vv.id_page='.(int)$this->page['id']
);
for ($i=0; $i<count($tmp); $i++)
{
$this->page['content']=str_replace('{|'.$tmp[$i]['name'].'|}', $tmp[$i]['value'], $this->page['content']);
}
}
elseif((int)$mod["id_module"]!=0)
{
$m = $this->db->select('sys_name', 'sys_modules', 'id='.(int)$mod['id_module'], '1');
include_once('modules/'.$m['sys_name'].'/'.$m['sys_name'].'.php');
$class_name=ucfirst(strtolower($m['sys_name']));
$module=new $class_name('modules/');
$this->page['content'] = $module->frontEnd($this, $this->page['id']);
}
else
{
$files=$this->db->select(
'f.*,
f.name AS filename
',
'
sys_pages_files AS sf
LEFT JOIN files AS f ON (sf.id_file=f.id)
',
'sf.id_sys_page='.(int)$this->page['id']
);
$files_str='';
$icons = $GLOBALS['icons'];
$image_types=array('image/jpeg', 'image/pjpeg', 'image/gif');
$images = '';
for ($i=0; $i<count($files); $i++)
{
if (in_array($files[$i]["type"], $image_types)==true){
$images .= '
<a class="gallery" href="'.$this->ftp['http_root'].'sys_page'.$this->page['id'].'/'.$files[$i]['path'].'" rel="lightbox[rel]" title="'.$files[$i]["filename"].'">
<img src="'.$this->ftp['http_root'].'sys_page'.$this->page['id'].'/user/'.$files[$i]['path'].'" class="" alt="'.$files[$i]["filename"].'" />
</a>
';
}else{
$files_str.='<img src="'.$this->http_root.'images/ico/'.$icons[$files[$i]['type']].'" alt="" class="nobackground img_left" />
<a target="_blank" class="files" href="'.$this->ftp['http_root'].'sys_page'.$this->page['id'].'/'.$files[$i]['path'].'">'.$files[$i]['filename'].'
</a>
<div class="clear_both"><!-- --></div>
';
}
}
if (TRUE==$files_str)
{
$files_str='<br />
<b>Soubory ke stažení:</b><br /><br />
'.$files_str.'
';
}
$this->page['content']=stripslashes($this->page['html']);
}
ob_end_clean();
$this->page['content']=str_replace('*http_root*', $this->http_root, $this->page['content']);
if (!empty($_GET['search'])){
require ('inc/search.php');
$this->page['content']=$obsah;
$this->page['name']="Výsledky vyhledávání: ". count($pole);
}
ob_start();
@include('templates/'.$this->template['script_file']);
$result=ob_get_contents();
// nacteni promenny stranky
$tmp=$this->db->select(
'v.name, vv.value',
'sys_vars AS v
LEFT JOIN sys_var_values AS vv ON (vv.id_var=v.id)
',
'vv.id_language='.(int)$this->language['id'].'
AND
vv.id_page='.(int)$this->page['id'].'
AND
v.id_template='.(int)$this->template['id']
);
//print_r($tmp);
for ($i=0; $i<count($tmp); $i++)
{
$result=str_replace('{|'.$tmp[$i]['name'].'|}', $tmp[$i]['value'], $result);
}
ob_end_clean();
echo $result;
return TRUE;
}
}
function getPageInfo($id)
{
$tmp=$db->select('*', 'sys_pages', 'id='.(int)$id, '1');
return $tmp;
}
$kernel=new Kernel();
//print_r($kernel -> db2);
$kernel->getHTML();
// print_r($GLOBALS);
//$kernel->db->createColumn('sys_pages_languages', 'html', 'medium text');
// die(print_r($kernel));
?>
ACC SHELL 2018