<?php
 if(!$_GET['showError'] AND $_SERVER['HTTP_HOST']!='dev') { ini_set('display_errors', '0'); } 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','32M'); Mizu::startScripttime(); $GP = $_POST+$_GET; 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', '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($GP['mizu']=='login' OR $_SESSION['mizu'][$_SERVER['SCRIPT_NAME']] OR $_SESSION['mizu']) { $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) { $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->decodeUrl($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($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(); } 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 '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() { foreach($this->Conf['lngs'] as $k => $v) { if($v['attr'] AND $v['attr']['offline']) { continue; } $R[] =$k; } return $R; } function getLangIfUndefined() { $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) { 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) { $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->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"); } } 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 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); $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']++; } $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); } } return $Nav; } 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 parseHtmlTextField($v) { if(!$v OR !is_string($v)) return $v; $cacheid = md5($v); if(!$this->parseHtmlTextFieldCache[$cacheid]) { $s = '<img((.*)(src="([^"]*)")([^>]*))/>'; preg_match_all('!'.$s.'!imsU',$v,$M); if(is_array($M)) { $toChange = array(); foreach($M[4] as $i => $url) { if(strpos($url,$this->_Url->BaseHref)===false ) continue; $str = $M[1][$i]; $Get = array('height','src','width','style'); $Attr = array(); foreach($Get as $f) { preg_match('!'.$f.'="(.*)"!imsU',$str,$R); if($f=='src' AND substr($R[1],0,4)=='http') { $R[1] = substr($R[1],strlen($this->_Url->BaseHref)); } $Attr[$f] = $R[1]; } $Attr['size'] = @getimagesize($Attr['src']); if($Attr['style']) { foreach($Get as $f) { preg_match('!'.$f.':(.*)px;!imsU',$Attr['style'],$R2); if($R2[1]) { $Attr[$f] = trim($R2[1]); } } } if($Attr['size'][0]>$Attr['width']) { $nUrl = $this->getImgUrl($Attr['src'],$Attr['width'].'!',$Attr['height'].'!'); } else { $nUrl = $Attr['src']; } $nStr = strtr($M[0][$i],array($url=>$nUrl)); $toChange[$M[0][$i]] = $nStr; } } $s = '{getUrl:([^}]*)}'; preg_match_all('!'.$s.'!imsU',$v,$M); if($M[1]) { foreach($M[0] as $i => $x) { $url = ''; $T = explode(':',$M[1][$i]); $id = $T[0]; $L = $T[1]; if(is_numeric($id)) { $url = $this->getUrl($id,$L); } $toChange[$x] = $url; } } $s = '{getImg:([^}]*)}'; preg_match_all('!'.$s.'!imsU',$v,$M); if($M[1]) { foreach($M[0] as $i => $x) { $toChange[$x] = '<img src="'.$M[1][$i].'"/>'; } } $this->parseHtmlTextFieldCache[$cacheid] = strtr($v,$toChange); } 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(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,'{'))) { $c = $this->parseHtmlTextField($c); } if($c) { break; } } return $c; } function getEditButton() {} function getEB() {} function getEditRel() {} function getER() {} function setJQuery($f) { $f = 'http://ajax.googleapis.com/ajax/libs/jquery/'.$f.'/jquery.min.js'; $this->JsIncjQuery = true; $this->JsIncLib[$f] = 'jquery'; } 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 getCssInc($f,$media='screen') { if($this->CssInc[$f]) return false; $this->CssInc[$f][$media] = 1; if(!$this->Conf['plugins']['cssUnify']) { if($media) { $s = 'media="'.$media.'"'; } return '<link href="'.$f.'" rel="stylesheet" type="text/css" '.$s.'/>'; } } function setCssInc($f,$media='screen') { if($this->CssIncLib[$f]) return false; $this->CssIncLib[$f][$media] = 1; } function _($f,$lng=false) { if(!$lng) { $lng = $this->GP['L']; } return $this->LngStr[$lng][$f]; } function parseLngFile($f,$lng=false) { if(!$lng) { $lng = $this->GP['L']; } if($this->LngStrFiles[$f][$lng]) { return $this->LngStr; } $LT = $this->_Helper->getAfX(simplexml_load_file($f)); $toC = array( '[b]' => '<b>', '[/b]' => '</b>', '[br]' => '<br/>', ); if(is_array($LT[$lng]['label'])) { foreach($LT[$lng]['label'] as $v) { $value = strtr($v['attr']['value'],$toC); if($v['txt']) { $value = $v['txt']; } $this->LngStr[$lng][$v['attr']['index']] = $value; } } $this->LngStrFiles[$f][$lng] = true; 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 $k => $v) { if($k=='id' OR $k=='TplConf') continue; global ${$k}; } 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 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->project['conf']['noHeaderContentType']) { $c.= '<meta http-equiv="Content-Type" content="text/html;charset='.$this->Conf['Encoding'].'"/>'; } if(isset($this->GP['getLogin']) AND !$this->isAdmin) { $c.= MizuAdmin::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,$m); } } } 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'])) { $c.= $this->getJsInc($this->_Url->getMizuIncUrl('code.js')); } $this->Header = $c; $this->_Conf->execHook('Mizu.getHeader.return'); return $this->Header; } function MizuInit() { if(!$this->project['conf']['noHeaderContentType']) { header("Content-Type: text/html; charset=".$this->Conf['Encoding']); } $this->cacheInit(); if($this->Conf['Singleton']) return false; ob_start(); } function MizuClose() { $this->cnt = ob_get_contents(); ob_end_clean(); if($this->GP['fe-mizu']=='showHooks') { print_rf($this->Hooks); } if($this->Conf['plugins']['cssUnify'] AND is_array($this->CssInc)) { $c = ''; foreach($this->_File->getUnifyInc($this->CssInc,'css') as $t => $f) { $s = ''; if($t) { $s = 'media="'.$t.'"'; } $c.= '<link href="'.$f.'" rel="stylesheet" type="text/css" '.$s.'/>'; } $this->cnt = strtr($this->cnt,array('</head>'=>$c.'</head>')); } if($this->Conf['plugins']['jsUnify'] AND is_array($this->JsInc)) { $c = ''; foreach($this->_File->getUnifyInc($this->JsInc,'js') as $f) { $c.= '<script type="text/javascript" src="'.$f.'"></script>'; } $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) { echo '<div style="background:#ddd;border-radius:0 0 0 10px;z-index:200;color:#000;position:fixed;top:0px;right:0px;padding:10px;">'.$this->showScripttime().'</div>'; } $this->cacheSet(); } 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); echo $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); } } 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; } $cnt = $this->CachFileInit.$this->CachSep.mktime().$this->CachSep; $cnt.= $this->cnt; 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']).$this->addCacheID; $this->cacheFile = 'cache/tpl-'.$this->cacheID.'.php'; if($this->cacheCheck()) { $cnt = $this->cacheGetContent($this->cacheFile,'cnt'); if(strpos($cnt,'</html>')) { 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], ); } 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'); $tables = $this->_DB->getRows("SHOW TABLE STATUS FROM ".$this->_DB->Conf['db']['db'],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 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() {} } ?>