<?php
 if(!isset($_GET['showError']) AND $_SERVER['HTTP_HOST']!='dev' AND $_SERVER['HTTP_HOST']!='devm') { @ini_set('display_errors', '0'); error_reporting(0); } if($_GET['showError']) { ini_set('display_errors', '1'); error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT); } if(substr($_SERVER['REQUEST_URI'],-strlen('favicon.ico'))=='favicon.ico') exit; if(isset($_POST['PHPSESSID'])) session_id(trim($_POST['PHPSESSID'])); session_start(); if(!$_SESSION['mizu'][$_SERVER['SCRIPT_NAME']] AND $_COOKIE['MizuAuto'] AND $_COOKIE['MizuAuto']!='-1') { $_SESSION['mizu'][$_SERVER['SCRIPT_NAME']] = unserialize(base64_decode($_COOKIE['MizuAuto'])); } header('X-UA-Compatible: Chrome=1', true); if(phpversion()>=5.1) { @date_default_timezone_set('Europe/Rome'); } class Mizu { function getInstance($lng=false,$addConf=array()) { global $_GET,$_POST; ini_set( 'memory_limit','64M'); Mizu::startScripttime(); $GP = Mizu::checkSecurity(); if($lng) { $GP['L'] = $lng; } $Incs = array( '../lib/php/legacy/php4.php', 'DB.class.php', 'MizuAdmin.class.php', 'MizuAdminLegacy.class.php', 'Url.class.php', 'Helper.class.php', 'Media.class.php', 'Tpl.class.php', 'File.class.php', 'MizuSingleton.class.php', 'File.class.php', 'Conf.class.php', '../lib/php/helper/Html.class.php', ); foreach($Incs as $f) { $v = dirname(__FILE__).'/'.$f; if(file_exists($v)) { require_once($v); } } if($GP['mizu']=='installDB') { $R = new Mizu; $R->addConf = $addConf; $R->GP = $GP; $R->_Conf = $R->getClass('Conf'); $R->_DB = $R->getClass('DB'); $R->install(); exit; } $isAdmin = false; if(($addConf['isAdmin'] OR $GP['mizu']=='login' OR ($_SESSION['mizu'] AND $_SESSION['mizu'][$_SERVER['SCRIPT_NAME']] AND $_SESSION['mizu'][$_SERVER['SCRIPT_NAME']]['user']) )) { $M = new MizuAdmin; $M->addConf = $addConf; $M->GP = $GP; $M->isAdmin = true; $M->_Conf = $M->getClass('Conf'); if(!$M->_Media) { $M->_Media = $M->getClass('Media'); } $M->_DB = $M->getClass('DB'); $M->_Url = $M->getClass('Url'); $M->_Helper = $M->getClass('Helper'); $M->checkAuth(); if($M->isAdmin()) { $isAdmin = true; } } if($isAdmin OR $addConf['isAdmin']) { $R = $M; } else { $R = new Mizu; $R->addConf = $addConf; $R->GP = $GP; } if(!$R->Conf) { $R->_Conf = $R->getClass('Conf'); if(!$R->_Media) { $R->_Media = $R->getClass('Media'); } $R->_DB = $R->getClass('DB'); $R->_Helper = $R->getClass('Helper'); } $R->MizuInit(); $R->_Tpl = $R->getClass('Tpl'); $R->_File = $R->getClass('File'); $R->_Url = $R->getClass('Url'); if(!$GP['mizu'] AND !$R->Conf['Singleton']) { $R->_Url->Mizu = $R; $R->GP = $R->_Url->decodeUrlMain($GP); } else { $R->GP = $GP; } $R->setLng($R->GP['L']); $R->_Url->lng = $R->lng; $R->_DB->lng = $R->lng; if($isAdmin) { $R->_Tpl->startInit(); } global $Mizu; $Mizu = $R; $Mizu->init(); if($Mizu->devMode) { } $Mizu->checkAction(); return $Mizu; } function getClass($c,$P=array(),$f=false) { if(is_string($P)) { $f = $P; unset($P); } if($GLOBALS['MizuClass'][$c]) { return $GLOBALS['MizuClass'][$c]; } if(!$f AND $this->Conf['regClass'][$c]) { $f = $this->Conf['regClass'][$c]; } if($f AND file_exists($f)) { require_once($f); } if(!class_exists($c)) return false; if($P) { $R = new $c($P); } else{ $R = new $c(); } $R->Mizu = &$this; if(method_exists($R,'init')) { $R->init(); } if($R instanceof MizuSingleton) { $GLOBALS['MizuClass'][$c] = $R; } return $R; } function getHelperClass($c) { $f = dirname(__FILE__).'/../lib/php/helper/'.$c.'.class.php'; return $this->getClass($c,array(),$f); } function showScripttime() { global $scriptTimeStart; $scriptTimeEnd = Mizu::getCurrentTime(); $scriptTimeDiv = intval(($scriptTimeEnd - $scriptTimeStart)*1000)/1000; return $scriptTimeDiv; } function getCurrentTime() { $time = explode(" ",microtime()); return ($time[0]+$time[1]); } function startScripttime() { global $scriptTimeStart; $scriptTimeStart = Mizu::getCurrentTime(); } function install() { if($this->GP['pass']=='hund1' AND $this->GP['action']!='update') { $A = "
					CREATE TABLE IF NOT EXISTS `%content%` (
					  `id` int(255) NOT NULL auto_increment,
					  `pid` int(255) NOT NULL,
					  `cid` int(255) NOT NULL,
					  `t` int(5) NOT NULL,
					  `lng` varchar(3) NOT NULL,
					  `k` varchar(255) NOT NULL,
					  `v` text NOT NULL,
					  PRIMARY KEY  (`id`),
					  KEY `pid` (`pid`,`t`,`k`),
					  KEY `lng` (`lng`),
					  KEY `cid` (`cid`)
					);
					
					CREATE TABLE IF NOT EXISTS `%pages%` (
					  `id` int(255) NOT NULL auto_increment,
					  `pid` int(255) NOT NULL,
					  `deleted` int(1) NOT NULL,
					  PRIMARY KEY  (`id`),
					  KEY `pid` (`pid`),
					  KEY `deleted` (`deleted`)
					);
					
					INSERT INTO `%pages%` (`id`, `pid`, `deleted`) VALUES
					(1, 0, 0);
				"; $A = "
					CREATE TABLE IF NOT EXISTS `%content%` (
					  `id` int(255) NOT NULL auto_increment,
					  `pid` int(255) NOT NULL,
					  `cid` int(255) NOT NULL,
					  `t` int(5) NOT NULL,
					  `lng` varchar(3) NOT NULL,
					  `k` varchar(255) NOT NULL,
					  `v` text NOT NULL,
					  PRIMARY KEY  (`id`),
					  KEY `pid` (`pid`,`t`,`k`),
					  KEY `lng` (`lng`),
					  KEY `cid` (`cid`)
					);
					
					CREATE TABLE IF NOT EXISTS `%pages%` (
					  `id` int(255) NOT NULL auto_increment,
					  `pid` int(255) NOT NULL,
					  `deleted` int(1) NOT NULL,
					  PRIMARY KEY  (`id`),
					  KEY `pid` (`pid`),
					  KEY `deleted` (`deleted`)
					);
					
					INSERT INTO `%pages%` (`id`, `pid`, `deleted`) VALUES
					(1, 0, 0);
				"; $B = explode(';',$A); foreach($B as $v) { if(!trim($v)) continue; $this->_DB->query($v); } echo 'install ok'; } else { $c = '<form method="post"/>'; $c.='<table>'; $c.='<tr>'; $c.= '<td>Pass:</td>'; $c.= '<td><input type="password" name="pass" /></td>'; $c.='</tr>'; $c.='<tr>'; $c.= '<td></td>'; $c.= '<td>Install</td>'; $c.='</tr>'; $c.='<tr>'; $c.= '<td></td>'; $c.= '<td><input type="submit" value="Send" /></td>'; $c.='</tr>'; $c.='</table>'; $c.='<form>'; echo $c; } exit; } function checkAction() { switch($this->GP['mizu']) { case 'encodeDecodeHtml' : $this->GP = $this->_Url->decodeUrl($GP); $v= $this->_Helper->getTestHtml(); print_Rf(htmlentities($v),'Html'); $v = $this->_Helper->encodeHtml($v); print_Rf(htmlentities($v),'encodeHtml 1'); $v = $this->_Helper->decodeHtml($v,array('forAdmin'=>true)); print_Rf(htmlentities($v),'decodeHtml for Admin 1'); $v = $this->_Helper->encodeHtml($v); print_Rf(htmlentities($v),'encodeHtml 2'); $v.= $this->_Helper->getTestHtml(); $v = $this->_Helper->decodeHtml($v,array('forAdmin'=>true)); print_Rf(htmlentities($v),'decodeHtml 2 with Legacy'); $v = $this->_Helper->encodeHtml($v); print_Rf(htmlentities($v),'encodeHtml 3'); $v = $this->_Helper->decodeHtml($v); print_Rf(htmlentities($v),'decodeHtml FINAL'); exit; break; case 'checkSession' : $R = array(); $R['ok'] = $this->isAdmin; $this->sendJson($R); break; case 'saveSession' : $this->sendJson(array('ok'=>true)); break; case 'getImg' : $path = explode("?",$this->GP['path']); if(!file_exists($path[0])) { $this->pageNotExists(); exit; } header('Location:'.$this->_Url->BaseHref.$this->_Url->getImgUrl($this->GP['path'],$this->GP['w'],$this->GP['h'],$this->GP['c'])); exit; break; } } function debugRequest() { $file = 'request.txt'; $TXT.='SERVER --------------'."\n"; foreach($_SERVER as $k => $v) { $TXT.= $k.":\t".$v."\n"; } $TXT.='GET --------------'."\n"; foreach($_GET as $k => $v) { $TXT.= $k.":\t".$v."\n"; } $TXT.='POST --------------'."\n"; foreach($_POST as $k => $v) { $TXT.= $k.":\t".$v."\n"; } $TXT.='SESSION --------------'."\n"; foreach($_SESSION as $k => $v) { $TXT.= $k.":\t".$v."\n"; } if(file_exists($file)) { $TXT = file_get_contents($file)."\n\n\n".$TXT; } file_put_contents($file,$TXT); } function getAllowLng() { $R = array(); if($this->Conf['lng']) { $R[] = $this->Conf['lng']; } else { foreach($this->Conf['lngs'] as $k => $v) { if($v AND $v['attr'] AND $v['attr']['offline']) { continue; } $R[] =$k; } } return $R; } function getLangIfUndefined() { if($this->Conf['lng']) { return $this->Conf['lng']; } $lng = strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2)); foreach($this->Conf['lngs'] as $l => $v) { if($v['attr'] AND $v['attr']['force']) { $lng = $l; break; } } return $lng; } function setLng($lng) { $this->allowLngs = $this->getAllowLng(); if(!$lng) { $lng = $this->getLangIfUndefined(); } if(is_array($this->allowLngs) AND !in_array($lng,$this->allowLngs)) { $lng = 'de'; } $this->GP['L'] = $lng; $this->_Url->lng = $lng; $this->_DB->lng = $lng; $this->lng = $lng; } function buildPages($pid=0) { foreach($this->_DB->getChildren($pid,'pages') as $id => $v) { $R = $this->_DB->getPage($v['id']); $R['sub'] = $this->buildPages($R['id']); if($this->GP['id']==$R['id']) { $this->project['current'] = $R; } $Pages[$R['id']] = $R; $this->project['pages'][$R['id']] = $R; } return $Pages; } function init($a=false) { $this->_Less = $this->getClass('lessc',dirname(__FILE__).'/../lib/php/lessphp/lessc.inc.php'); if($this->Conf['Singleton']) return false; $this->project = array(); $this->project['conf'] = $this->Conf; if($a) return false; if(!$this->GP['id']) { $this->pageNotExists(); } else { $B = $this->_DB->getRow('SELECT deleted FROM %pages% WHERE id = "'.$this->GP['id'].'"'); if($B['deleted']) { $this->pageNotExists(); } } if(!$this->isAdmin) { $Ls = $this->getAllowLng(); if(is_array($Ls) AND !in_array($this->GP['L'],$Ls)) { header('Location:'.$this->_Url->getUrl($this->project['conf']['startpage'],$Ls[0])); exit; } } $this->setPage($this->GP['id']); if($this->CurrentPage['cnt']['offline'] AND !$this->isAdmin(true)) { $this->pageNotExists(); } $this->project['path'] = $this->buildPath($this->GP['id']); $this->setPage($this->GP['id']); $this->_Conf->execHook('Mizu.init.return'); } function pageNotExists() { if($this->GP['id']==$this->Conf['startpage']) { return false; } if($this->Conf['Singleton']) { return false; } $this->GP['id'] = $this->project['conf']['notFoundPage']; if(!$this->GP['L']) { $this->GP['L'] = $this->lng; } if(!isset($this->GP['getLogin']) AND !isset($this->GP['mizu'])) { header("HTTP/1.0 404 Not Found"); $this->HeaderStatus = 404; $this->Conf['plugins']['pageCache'] = 0; } } function buildPath($id=false) { return $this->_DB->buildPagePath($id); } function isAct($id) { if(!$this->project['path'] AND $id==$this->project['conf']['startpage']) { return true; } if(@in_array($id,$this->project['path'])) { return true; } } function getPageChildrenIds($id=false,$sort=false,$admin=false,$showHidden=false) { if(!$id) { $id = $this->GP['id']; } return $this->_DB->getPageChildrenIds($id,$sort,$admin,$showHidden); } function getCurrentPage() { return $this->CurrentPage; } function setPage($id) { $this->CurrentPage = $this->_DB->getPage($id); } function getPage($id=false) { if(!$id) { $id = $this->CurrentPage['id']; } return $this->_DB->getPage($id); } function getRegUrl($reg,$P=array()) { return $this->getUrl(false,false,array('regurl'=>$reg)+$P); } function getUrl($id=false,$lng=false,$p=array(),$np=array()) { $conf = $this->getDefaultPageConf($id,$lng); return $this->_Url->getUrl($conf['id'],$conf['lng'],$p,$np); } function getImgUrl($path,$width=false,$height=false,$conf=false) { return $this->_Url->getImgUrl($path,$width,$height,$conf); } function getImg($path,$width=false,$height=false,$conf=array()) { if(is_array($conf)) { if(!$conf['alt']) { $conf['alt'] = ''; } $ext = ''; foreach($conf as $k => $v) { $ext.=' '.$k.'="'.$v.'"'; } } $url = $this->getImgUrl($path,$width,$height,$conf); $S = @getimagesize($url); return '<img src="'.$url.'" width="'.$S[0].'" height="'.$S[1].'"  '.$ext.'/>'; } function getNav($id=false,$opt=array()) { if(!$id) { $id = 0; } if(!is_array($opt) AND $opt) { $opt = array(); $opt['showAll'] = true; } if(!$opt['curLevel']) { $opt['curLevel'] = 1; } else { $opt['curLevel']++; } $cacheid = $id.md5(serialize($opt)); if(!$this->getNavCache[$cacheid]) { $Nav = array(); $Pages = $this->_DB->getPageChildrenIds($id,'sort'); if(!$Pages) return array(); foreach($Pages as $k => $v) { $Nav[$v['id']] = array( 'url' => $this->_Url->getUrl($v['id']), 'name' => $v['nav'], 'id' => $v['id'] ); if(($opt['showAll'] AND (!$opt['maxLevel'] OR $opt['curLevel']<$opt['maxLevel']) ) OR ($this->isAct($v['id']))) { $Nav[$v['id']]['sub'] = $this->getNav($v['id'],$opt); } } $this->getNavCache[$cacheid] = $Nav; } return $this->getNavCache[$cacheid]; } function getDefaultPageConf($id=false,$lng=false) { if(!$lng) { $lng = $this->lng; } if($id===false) { if($this->CurrentPage) { $id = $this->CurrentPage['id']; } else { $id = $this->GP['id']; } } return array('id' => $id,'lng' => $lng); } function decodeHtml($v,$widgets=array()) { return $this->parseHtmlTextField($v,$widgets); } function parseHtmlTextField($v,$widgets=array()) { if(!$v OR !is_string($v)) return $v; $cacheid = md5($v); if(!$this->parseHtmlTextFieldCache[$cacheid]) { $this->parseHtmlTextFieldCache[$cacheid] = $this->_Helper->decodeHtml($v,array('forAdmin'=>$this->isAdminEdit,'widgets'=>$widgets)); } return $this->parseHtmlTextFieldCache[$cacheid]; } function getDefaultElementConf($f,$id=false,$lng=false,$cid=false) { $conf = $this->getDefaultPageConf($id,$lng); $R = $conf; if($f) { $fA = explode('/',$f); if($fA[0]=='editor') { $R['editor'] = true; $R['group'] = $fA[1]; if(isset($fA[2])) { $R['tab'] = $fA[2]; } } if(count($fA)<2) { $f = 'lng/'.$f; } $R['field'] = $fA[count($fA)-1]; $R['rf'] = $fA[count($fA)-2].'/'.$fA[count($fA)-1]; $R['pfield'] = $fA[count($fA)-3]; $R['pt'] = $fA[count($fA)-4]; if($fA[count($fA)-2]=='cnt') { $t = 'cnt'; } else { $t = 'lng'; } } $R['f'] = $f; $R['t'] = $t; $R['cid'] = $cid; if($R['t']=='cnt') { unset($R['lng']); } return $R; } function insertList($f,$A,$id=false,$lng=false) { $conf = $this->getDefaultElementConf($f,$id,$lng); return $this->_DB->insertList($A,$conf['id'],$conf['t'],$conf['field'],$conf['lng']); } function countList($f,$opt=array(),$id=false,$lng=false,$cid=false) { $conf = $this->getDefaultElementConf($f,$id,$lng,$cid); $opt['opt'] = array('returnRows'=>true); return count($this->_DB->getList($conf['id'],$conf['t'],$conf['field'],$conf['lng'],$opt['where'],$opt['order'],$opt['limit'],$opt['opt'],$opt['join'])); } function getList($f,$opt=array(),$id=false,$lng=false,$cid=false) { $conf = $this->getDefaultElementConf($f,$id,$lng,$cid); if(!$opt['order'] AND $this->_Tpl) { $orderBy = array(); $Page = $this->getPage($conf['id']); $tpl = $this->_Tpl->getById($conf['id']); $addConf = Helper::getAbyPath($tpl,$conf['f']);; if($addConf['lng']) { foreach($addConf['lng'] as $y => $z) { if($z['attr']['orderBy']) { $orderBy[$y] = $z['attr']['orderBy']; } } } if($addConf['cnt']) { foreach($addConf['cnt'] as $y => $z) { if($z['attr'] AND $z['attr']['orderBy']) { $orderBy[$y] = $z['attr']['orderBy']; } } } if($orderBy) { $opt['order'] = $orderBy; } } $opt['opt'] = $opt; return $this->_DB->getList($conf['id'],$conf['t'],$conf['field'],$conf['lng'],$opt['where'],$opt['order'],$opt['limit'],$opt['opt'],$opt['join']); } function getLBeta($f,$id=false,$lng=false,$cid=false,$opt=array()) { foreach(array('id','lng','cid') as $k => $v) { if(is_array(${$v})) { $opt = ${$v}; ${$v} = false; break; } } $conf = $this->getDefaultElementConf($f,$id,$lng,$cid); return $this->_DB->getList($conf['id'],$conf['t'],$conf['field'],$conf['lng'],false,false,false,$opt,false); } function getE($f,$id=false,$lng=false,$cid=false) { return $this->get($f,$id,$lng,$cid); } function get($f,$id=false,$lng=false,$cid=false) { $F = explode(';',$f); foreach($F as $f) { $conf = $this->getDefaultElementConf($f,$id,$lng,$cid); $c = $this->_DB->getContent($conf['id'],$conf['t'],$conf['field'],$conf['lng'],$conf['cid']); if(is_string($c) AND (strpos($c,'<img') OR strpos($c,'{') OR strpos($c,'#'))) { $c = $this->parseHtmlTextField($c); } if($c) { break; } } return $c; } function getEditButton() {} function getEB() {} function getEditRel() {} function getER() {} function setJQuery($f) { if($f!='none') { $f = 'http://ajax.googleapis.com/ajax/libs/jquery/'.$f.'/jquery.min.js'; $this->JsIncLib[$f] = 'jquery'; } $this->JsIncjQuery = true; } function getJs($f) { $this->JsInc[] = $f; if(!$this->Conf['plugins']['jsUnify']) { return '<script type="text/javascript">'.$f.'</script>'; } } function getJsInc($f) { if($this->JsInc[$f]) return false; $this->JsInc[$f] = 1; if(!$this->Conf['plugins']['jsUnify']) { return '<script type="text/javascript" src="'.$f.'"></script>'; } } function setJsInc($f) { if($this->JsIncLib[$f]) return false; $this->JsIncLib[$f] = 1; } function setLessVars($v=array()) { $this->_Less->setVariables($v); if(!$this->_Less->regVars) { $this->_Less->regVars = array(); } $this->_Less->regVars = array_merge($this->_Less->regVars,$v); if($this->isAdmin AND $this->Conf['plugins']['writeLessVarsFile']) { $file = 'inc/less-vars.less'; if(!file_exists($file)) { $cnt = array(); foreach($this->_Less->regVars as $f => $value) { $cnt[]= '@'.$f.' : '.$value.';'; } file_put_contents($file,implode("\n",$cnt)); } } } function checkLess($f) { if(substr($f,-5)=='.less') { $in = $f; $add = ''; if($this->_Less->regVars) { $add.='.'.md5(serialize($this->_Less->regVars)); } if($this->Conf['addCssToFile'][$in]) { $add.='.'.md5(serialize($this->Conf['addCssToFile'][$in])); } $out = 'cache/css-less-'.strtr($in,array('/'=>'-')).$add.'.css'; $reWrite = false; $md5Check = false; if($this->Mizu->devMode AND substr($in,-11)=='screen.less') { } if($this->_File->isDirty($in,$out,$md5Check)) { $reWrite = true; } if(!$reWrite OR $md5Check) { preg_match_all('|@import(.*)"(.*)"|iUs',file_get_contents($in),$M); if($M) { foreach($M[2] as $t) { if(!file_exists(dirname($in).'/'.$t)) { continue; } if($this->_File->isDirty(dirname($in).'/'.$t,$out,$md5Check)) { $reWrite = true; if(!$md5Check) { break; } } if($this->Mizu->devMode AND substr($t,-11)=='screen.less') { preg_match_all('|@import(.*)"(.*)"|iUs',file_get_contents(dirname($in).'/'.$t),$M2); if($M2) { foreach($M2[2] as $t2) { if($this->_File->isDirty(dirname($in).'/'.dirname($t).'/'.$t2,$out,$md5Check)) { $reWrite = true; if(!$md5Check) { break; } } } } } } } } if ($reWrite) { $css = $this->_Less->compileFile($in); $css = $this->_File->moveCss($css,$in); if($this->Conf['addCssToFile'][$in]) { $css.= $this->_Less->compile($this->Conf['addCssToFile'][$in]); } file_put_contents($out, $css); } $f = $out; } return $f; } function getCssInc($f,$opt=array()) { if(is_string($opt)) { $opt = array('media' => $opt); } if(!$opt['media']) { $opt['media'] = 'all'; } $this->CssIncRaw[$f] = 1; if($this->CssInc[$f]) return false; $f = $this->checkLess($f); $this->CssInc[$f][$opt['media']] = $opt; if(!$this->Conf['plugins']['cssUnify']) { if($opt['media'] AND !is_numeric($mmedia)) { $s = 'media="'.$opt['media'].'"'; } return '<link href="'.$f.'" rel="stylesheet" type="text/css" '.$s.'/>'; } } function setCssInc($f,$opt=array()) { if(is_string($opt)) { $opt = array('media' => $opt); } if(!$opt['media']) { $opt['media'] = 'all'; } $this->CssIncRaw[$f] = 1; $f = $this->checkLess($f); if($this->CssIncLib[$f]) return false; $this->CssIncLib[$f][$opt['media']] = $opt; } function _($f,$lng=false) { if(!$lng) { $lng = $this->GP['L']; } return $this->LngStr[$lng][$f]; } function parseLngFile($f,$lng=false,$opt=array()) { if(!$lng) { $lng = $this->GP['L']; } if($this->LngStrFiles[$f][$lng]) { return $this->LngStr; } $R = $this->parseLngStr(file_get_contents($f),$lng,$opt); $this->LngStrFiles[$f][$lng] = true; return $R; } function parseLngStr($str,$lng=false,$opt=array()) { if(!$lng) { $lng = $this->GP['L']; } $LT = $this->_Helper->getAfX(simplexml_load_string($str)); $toC = array( '[b]' => '<b>', '[/b]' => '</b>', '[br]' => '<br/>', ); if(is_array($LT[$lng]['label'])) { foreach(Helper::getArrayAsRows($LT[$lng]['label']) as $v) { if(!$v['attr']['index']) continue; $value = ''; if($v['attr']['value']) { $value = $v['attr']['value']; } elseif($v['txt']) { $value = $v['txt']; } elseif($v['sdata']) { $value = $v['sdata']; } $value = strtr($value,$toC); if($opt['noOverwrite'] AND $this->LngStr[$lng][$v['attr']['index']]) { } else { $this->LngStr[$lng][$v['attr']['index']] = $value; } } } return $this->LngStr[$lng]; } function getFileType($f) { $path = explode("?",$f); $f = $path[0]; $ext = strtolower(substr($f,strrpos($f,'.')+1)); foreach($this->_File->Types as $k => $t) { if(preg_match('/\.('.$t.')$/iU', $f)) { return $k; } } return 'doc'; } function checkFiles($A) { if(!$A OR !is_array($A)) return array(); $R = array(); foreach($A as $v) { $path = explode("?",$v['file']); if($path[0] AND is_file($path[0])) { $R[] = $v; } } return $R; } function truncate($string,$length,$etc='...', $break_words = false) { if ($length == 0) return ''; if (strlen($string) > $length) { $length -= strlen($etc); if (!$break_words) $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1)); return substr($string, 0, $length).$etc; } else return $string; } function getTpl($id=false,$TplConf=array(),$asReturn=false) { foreach($GLOBALS as $getTplk =>$getTplk) { if($getTplk=='id' OR $getTplk=='TplConf') continue; global ${$getTplk}; } global $Mizu; if(!$this->Mizu) { $this->Mizu = $Mizu; } $conf = $this->getDefaultPageConf($id); if(!$id) { if($TplConf['forceTpl']) return false; $id = $this->CurrentPage['cnt']['tpl']; } $tC = $TplConf; if($TplConf['forceTpl'] AND !file_exists('tpl/'.$id.'.php')) { return false; } if(!file_exists('tpl/'.$id.'.php')) { $id = 'default'; } if($TplConf['asReturn'] OR $asReturn) { ob_start(); include($this->_Tpl->getFile($id)); $cnt = ob_get_contents(); ob_end_clean(); return $cnt; } else { include($this->_Tpl->getFile($id)); } } function setHeader($v) { $this->HeaderStr.=$v; } function isAdmin($real=false) { if($this->isAdmin AND !$real) { return true; } if($real AND $this->User['ok']) { return true; } return false; } function getMizuVersion() { if(!$this->MizuVersion) { include(dirname(__FILE__).'/../version.php'); $this->MizuVersion = $MizuVersion; } return $this->MizuVersion; } function getHeader() { $c = $this->_Url->getHeader(); $c.= '<meta http-equiv="content-language" content="'.$this->GP['L'].'"/>'; if(!$this->Conf['noHeaderContentType']) { $c.= '<meta http-equiv="Content-Type" content="text/html;charset='.$this->Conf['Encoding'].'"/>'; } if(isset($this->GP['getLogin']) AND !$this->isAdmin) { $c.= $this->getExtJsBaseHeader(); $c.= $this->getJsInc($this->_Url->getMizuIncUrl('login.js')); } if($this->isAdmin) { $c.= $this->getAdminHeader();; } if(!$this->JsIncjQuery AND !$this->Conf['jQueryFeLoaded']) { $c.= $this->getJsInc('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'); if($this->JsLoadBeJquery) { $c.=$this->getJs('$ = jQuery.noConflict();'); } } if(is_array($this->CssIncLib)) { foreach($this->CssIncLib as $f => $x) { foreach($x as $m => $z) { $c.= $this->getCssInc($f,$z); } } } if(is_array($this->JsIncLib)) { foreach($this->JsIncLib as $f => $z) { $c.= $this->getJsInc($f); if($z=='jquery' AND $this->JsLoadBeJquery) { $c.=$this->getJs('$ = jQuery.noConflict();'); } } } if(!$this->isAdmin AND !isset($this->GP['getLogin']) AND !$this->Conf['noMizuLoginJs']) { $c.= $this->getJsInc($this->_Url->getMizuIncUrl('code.js')); } $this->Header = $c; $this->_Conf->execHook('Mizu.getHeader.return'); return $this->Header; } function MizuInit() { if(!$this->Conf['noHeaderContentType']) { header("Content-Type: text/html; charset=".$this->Conf['Encoding']); } $this->cacheInit(); if($this->Conf['Singleton']) return false; ob_start(); } function getExtJsBaseHeader() { $this->JsLoadBeJquery = true; $c = ''; $c.= $this->getJsInc('https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'); if($this->devMode) { $this->MizuBaseUrl = 'http://dev/00000_mizu/004_base.mizu.co/'; } else { $this->MizuBaseUrl = base64_decode('aHR0cDovL2Jhc2UubWl6dS5jby8='); if($_SERVER['REQUEST_SCHEME']=='https') { $this->MizuBaseUrl = base64_decode('aHR0cHM6Ly9iYXNlLm1penUuY28v'); } if(!$this->MizuBaseUrl) { $this->MizuBaseUrl = strrev('/oc.uzim.esab//:ptth');; } } $j = 'code'; if($this->Conf['brand']) { $j = $this->Conf['brand']; } $P = array( 'V' => $this->getMizuVersion(), ); if($this->BeUser['user']) { $P['user'] = $this->BeUser['user']; } $vStr = ''; foreacH($P as $k => $v) { $vStr.=$k.'/'.$v.'/'; } $vStr = substr($vStr,0,-1); $c.= $this->getJsInc($this->MizuBaseUrl.$vStr.'/'.$j.'.js'); $c.= $this->getJsInc($this->_Url->BaseHref.'mizu/lib/js/ckeditor/ckeditor.js'); $c.= $this->getJs('$m = jQuery.noConflict();'); if(file_exists($this->_Url->getMizuIncUrl('mizu.min.css'))) { $c.= $this->getJsInc($this->_Url->BaseHref.'mizu/mizu.min.js?'.$this->getMizuVersion()); $c.= $this->getCssInc($this->_Url->BaseHref.'mizu/mizu.min.css?'.$this->getMizuVersion()); $this->AdminUnifyVersion = true; } $this->extjsVersion = '5.1.1'; if(!$this->isAdmin) { $adminLng = 'de'; } else { $adminLng = $this->getAdminLng(); } if(!$this->AdminUnifyVersion) { $c.= $this->getCssInc($this->_Url->getMizuIncUrl('lib/css/font-awesome/css/font-awesome.min.css')); $c.= $this->getJsInc($this->_Url->getMizuIncUrl('lib/js/extjs/'.$this->extjsVersion.'/ext-all.js')); $theme = 'mizu'; $c.= $this->getCssInc($this->_Url->getMizuIncUrl('lib/js/extjs/'.$this->extjsVersion.'/theme/ext-theme-'.$theme.'/ext-theme-'.$theme.'-all.css')); $c.= $this->getJsInc($this->_Url->getMizuIncUrl('lib/js/extjs/'.$this->extjsVersion.'/theme/ext-theme-'.$theme.'/ext-theme-'.$theme.'.js')); $c.= $this->getCssInc($this->_Url->getMizuIncUrl('screen.less')); $c.= $this->getJsInc($this->_Url->getMizuIncUrl('lib/js/extjs/'.$this->extjsVersion.'/locale/ext-locale-'.$adminLng.'.js')); } else { if($adminLng!='de') { $c.= $this->getJsInc($this->_Url->getMizuIncUrl('lib/js/extjs/'.$this->extjsVersion.'/locale/ext-locale-'.$adminLng.'.js')); } } if(isset($this->GP['getLogin']) AND Helper::isMobile()) { $c.=' <meta name="viewport" content="width=300, height=170, minimum-scale=1, maximum-scale=1" />'; } if(Helper::isMobile()) { $c.=' <meta name="isMobile" content="1"/>'; $c.=' <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1" />'; } return $c; } function getCssUnifyIncCnt() { $c = ''; foreach($this->_File->getUnifyInc($this->CssInc,'css') as $t => $f) { if(substr($f,0,7)!='http://' AND $this->Conf['plugins']['absoluteIncFiles']) { $f = $this->Mizu->_Url->BaseHref.$f; } $s = ''; if($t AND !is_numeric($t)) { $s = 'media="'.$t.'"'; } $c.= '<link href="'.$f.'" rel="stylesheet" type="text/css" '.$s.'/>'; } return $c; } function getJsUnifyIncCnt() { $c = ''; foreach($this->_File->getUnifyInc($this->JsInc,'js') as $f) { if(substr($f,0,7)!='http://' AND $this->Conf['plugins']['absoluteIncFiles']) { $f = $this->Mizu->_Url->BaseHref.$f; } $c.= '<script type="text/javascript" src="'.$f.'"></script>'; } return $c; } function MizuClose() { $this->cnt = ob_get_contents(); ob_end_clean(); $this->_Conf->execHook('Mizu.MizuClose.init'); if($this->GP['fe-mizu']=='showHooks') { print_rf($this->Hooks); } if($this->Conf['plugins']['cssUnify'] AND is_array($this->CssInc)) { $c = $this->getCssUnifyIncCnt(); $this->cnt = strtr($this->cnt,array('</head>'=>$c.'</head>')); } if($this->Conf['plugins']['jsUnify'] AND is_array($this->JsInc)) { $c = $this->getJsUnifyIncCnt(); $this->cnt = strtr($this->cnt,array('</body>'=>$c.'</body>')); } if($this->HeaderStr) { $this->cnt = strtr($this->cnt,array('</head>'=>$this->HeaderStr.'</head>')); } if($this->Conf['plugins']['htmlMinify']) { require_once 'mizu/lib/php/min/lib/Minify/HTML.php'; $this->cnt = Minify_HTML::minify($this->cnt); $this->cnt = $this->_Helper->removeWhiteSpaces($this->cnt); } if($this->Conf['plugins']['gzencode'] AND strpos("gzip",$_SERVER["HTTP_ACCEPT_ENCODING"]) !== NULL) { $ccnt = gzencode($this->cnt, 6, FORCE_GZIP); header('Content-Encoding: gzip'); header('Content-Length: '.strlen($ccnt)); echo $ccnt; } else { echo $this->cnt; } if($this->devMode AND !$this->Conf['plugins']['disableShowTime']) { $this->showTime(); } $this->cacheSet(); } function showTime() { echo '<div style="background:#f2fae6;border:5px solid #83bc25;border-radius:5px 0 0 0;font-size:10px;z-index:30000;color:#000;position:fixed;bottom:-5px;right:-5px;padding:5px 10px;">'.Mizu::showScripttime().'</div>'; } function close() { $this->MizuClose(); } function isBrowser() { if($_SERVER['HTTP_X_REQUESTED_WITH']!='XMLHttpRequest' AND $_SERVER['HTTP_USER_AGENT']!='Shockwave Flash' AND substr($_SERVER['HTTP_USER_AGENT'],0,strlen('Adobe'))!='Adobe' AND !$this->GP['debug']) { return true; } return false; } function sendJson($A=array(),$forceJson=false) { if($this->isBrowser() AND !$forceJson) { if($this->GP['redirectId']) { $this->GP['id'] = $this->GP['redirectId']; } if(!$this->GP['id'] OR !$this->GP['L']) { $this->GP = $this->_Url->decodeUrl($this->GP); } $this->_DB->noCache = true; if($this->Conf['MizuLight']) { header('Location:'.$_SERVER['REQUEST_URI']); } else { header('Location:'.$this->_Url->getUrl($this->GP['id'],$this->GP['L'])); } exit; } ob_clean(); header('Content-type: application/json'); if($this->Conf['spcEncoding']) { $A = $this->_Helper->utf8EncodeArray($A); } if($this->GP['debug']) { if(function_exists('json_encode') ) { $t = 'phpjson'; } else { $t = 'myjson'; } $this->_Helper->print_rf($A,$t); if($_GET['callback']) { echo $_GET['callback']."(".$this->MyJsonEncode($A).");"; } else { echo $this->MyJsonEncode($A); } } else { header('Content-Type: application/json'); if($_GET['callback']) { echo $_GET['callback']."(".$this->MyJsonEncode($A).");"; } else { echo $this->MyJsonEncode($A); } } exit; } function MyJsonEncode($A=array()) { if(function_exists('json_encode') ) { return json_encode($A); } else { require_once(dirname(__FILE__).'/../lib/php/legacy/JSON.php'); return array_to_json($A); } } function MyJsonDecode($A=array()) { if(function_exists('json_decode') ) { return json_decode($A,true); } else { } } var $CachSep = '%%%%%%%%%%%%%%%%%%%%%%%%%%%%'; var $CachFileInit = '<?php exit; ?>'; function cacheSet() { global $_POST; $this->_Conf->execHook('Mizu.cacheSet.init'); if(!$this->Conf['plugins']['pageCache']) return false; if($_POST) { return false; } $A = $this->_DB->getRow('SELECT NOW() AS n'); $time = strtotime($A['n']); if($time) { $time=mktime(); } $cnt = $this->CachFileInit.$this->CachSep.$time.$this->CachSep; $cnt.= $this->cnt; if(is_array($this->CacheOpt)) { $cnt.= $this->CachSep.$this->MyJsonEncode($this->CacheOpt); } if(!$this->isAdmin) { file_put_contents($this->cacheFile,$cnt); } } function cacheInit() { $this->_Conf->execHook('Mizu.cacheInit.init'); if($this->Conf['Singleton']) return false; if(!$this->Conf['plugins']['pageCache']) return false; $this->cacheID = md5($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']).$_SERVER['HTTPS'].$this->addCacheID; $this->cacheFile = 'cache/tpl-'.$this->cacheID.'.php'; if($this->cacheCheck()) { $cnt = $this->cacheGetContent($this->cacheFile,'cnt'); if($cnt) { echo $cnt; exit; } } } function cacheGetContent($f,$r) { if(!$this->cacheContent[$f]) { $t = file_get_contents($f); $A = explode($this->CachSep,$t); $this->cacheContent[$f] = array( 'time' => $A[1], 'cnt' => $A[2], 'opt' => $this->MyJsonDecode($A[3]), ); } if($r) { return $this->cacheContent[$f][$r]; } return $this->cacheContent[$f]; } function cacheCheck() { global $_POST; if(!$this->Conf['plugins']['pageCache']) return false; if($this->isAdmin) { return false; } if($this->GP['no_cache']) { unset($this->GP['no_cache']); return false; } if($_POST) { return false; } if(file_exists($this->cacheFile)) { $fileTime = $this->cacheGetContent($this->cacheFile,'time'); $q = 'SHOW TABLE STATUS FROM '.$this->_DB->Conf['db']['db'].' WHERE Name LIKE "'.$this->_DB->Conf['db']['prefix'].'%"'; $tables = $this->_DB->getRows($q,true); if($this->Conf['plugins']['pageCache']!=1) { $onlyTables = explode(';',$this->Conf['plugins']['pageCache']); foreach($onlyTables as $i => $v) { $onlyTables[$i] = $this->Conf['db']['attr']['prefix'].$v; } } foreach($tables as $v) { if($onlyTables AND !in_array($v['Name'],$onlyTables)) { continue; } $A = explode(' ',$v['Update_time']); $B = explode('-',$A[0]); $C = explode(':',$A[1]); $dbTime = @mktime($C[0],$C[1],$C[2],$B[1],$B[2],$B[0]); if($dbTime>$fileTime) { return false; } } } else { return false; } return true; } function checkSecurity() { if($_SERVER['HTTP_HOST']!='dev') { return $_POST+$_GET;; } else{ require_once("print_rf.func.php"); } if(phpversion()>=5.2) { $_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_MAGIC_QUOTES); $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_MAGIC_QUOTES); } if(!$_POST) { $_POST = array(); } if(!$_GET) { $_GET = array(); } $GP = $_POST+$_GET; $Vars = array( 'id' => FILTER_SANITIZE_ENCODED, 'L' => FILTER_SANITIZE_ENCODED, 'mizu' => FILTER_SANITIZE_ENCODED, ); foreach($Vars as $k => $v) { if($GP[$k]) { $GP[$k] = filter_var($GP[$k],$v); } } $Sec['NotAllowedMethods'] = array('connect' => 1,'debug' => 1,'delete' => 1,'move' => 1,'put' => 1,'trace' => 1,'track' => 1); if($Sec['NotAllowedMethods'] AND $Sec['NotAllowedMethods'][strtolower($_SERVER['REQUEST_METHOD'])]) { return false; } return $GP; } function getLEditButton() {} function getLEditRel() {} function getLE($f,$id=false,$lng=false) { return $this->getE('lng/'.$f,$id,$lng); } function getL($f,$id=false,$lng=false) { return $this->get('lng/'.$f,$id,$lng); } function getC($f,$id=false,$lng=false) { $conf = $this->getDefaultElementConf('cnt/'.$f,$id,$lng); return $this->get($conf['f'],$conf['id'],$conf['lng']); } function getCE($f,$id=false,$lng=false) { $conf = $this->getDefaultElementConf('cnt/'.$f,$id,$lng); return $this->getE($conf['f'],$conf['id'],$conf['lng']); } function getCEditButton() {} function getCEditRel() {} } 