connect(redisServer)) die('cannot rape the database ...');
if(isset($_GET['deleteCache']))
{ $cache = $redis->keys(redisPrefix.':designCache:*');
foreach($cache as $c) $redis->delete($c);
}
function setInfo($langage,$upath)
{ global $currentLangage,$canonicalurl,$urlpath;$currentLangage=$langage;$urlpath=$upath;
if($langage!=defaultLangage)
{ $canonicalurl=site_full_url.$langage.'/';
if($upath != '') $canonicalurl.=$upath.'/';
}
else
{ $canonicalurl=site_full_url;
if($upath != '') $canonicalurl.=$upath.'/';
}
}
function getlang(){global $currentLangage;return $currentLangage;}
function getUrlPath(){global $urlpath;return $urlpath;}
define ('site_full_path',dirname(__FILE__));
define ('site_path',site_full_path.'/files');
define ('common_path','common');
define ('module_path','plugins');
define ('design_path','constants.ini');
$nofollow=0;$nodesigncache=0;$norendercache=0;$renderInclude=array();$global_current_file='';$fnc=array();$designPath='';$commonDesignPath='';
/* additionnal keywords for render */
function addToRender($word,$txt) { global $renderInclude,$currentDesign; $renderInclude[$word] .= $txt; setDesignCache($currentDesign.'/'.$word,$txt); }
function setRender($word,$txt) { global $renderInclude,$currentDesign; $renderInclude[$word] = $txt; setDesignCache($currentDesign.'/'.$word,$txt); }
function extendRenderWord($word) { if(!isset($renderWords[$word])) array_push($renderWords,$word); }
global $renderWords; $renderWords = array('head','js','jquery','title','meta','style','keywords','description');
function addToHead($t){addToRender('head',$t);}function setHead($t){setRender('head',$t);}$renderInclude['head']='';function addToJs($t){addToRender('js',$t);}function setJs($t){setRender('js',$t);}$renderInclude['js']='';function addToJquery($t){addToRender('jquery',$t);}function setJquery($t){setRender('jquery',$t);}$renderInclude['jquery']='';function addToTitle($t){addToRender('title',$t);}function setTitle($t){setRender('title',$t);}$renderInclude['title']='';function addToMeta($t){addToRender('meta',$t);}function setMeta($t){setRender('meta',$t);}$renderInclude['meta']='';function addToStyle($t){addToRender('style',$t);}function setStyle($t){setRender('style',$t);}$renderInclude['style']='';function addToKeywords($t){addToRender('keywords',$t);}function setKeywords($t){setRender('keywords',$t);}$renderInclude['keywords']='';function addToDescription($t){addToRender('description',$t);}function setDescription($t){setRender('description',$t);}$renderInclude['description']='';
//foreach($renderWords as $word){ print('function addTo'.ucfirst($word).'($t){addToRender(\''.$word.'\',$t);}function set'.ucfirst($word).'($t){setRender(\''.$word.'\',$t);}$renderInclude[\''.$word.'\']=\'\';'); } die();
function renderPage($url,$page)
{ global $renderInclude, $design_cache, $canonicalurl,$currentLangage;
if(empty($renderInclude['title'])) $renderInclude['title'] = $design_cache['ini:title'];
if(empty($renderInclude['keywords'])) $renderInclude['keywords'] = $design_cache['ini:keywords'];
if(empty($renderInclude['description'])) $renderInclude['description'] = $design_cache['ini:description'];
if(empty($renderInclude['meta'])) $renderInclude['meta'] = $design_cache['ini:meta'];
$renderInclude['meta'] .= '';
return str_replace(array('[head]','[js]','[jquery]','[meta]','[style]','[keywords]','[description]','[title]','[url]','[lang]'),array($renderInclude['head'],$renderInclude['js'],$renderInclude['jquery'],$renderInclude['meta'],$renderInclude['style'],$renderInclude['keywords'],$renderInclude['description'],$renderInclude['title'],site_url,$currentLangage),$page);
}
function get_include_contents($filename)
{ if(is_file($filename))
{ ob_start(); include ($filename); $contents = ob_get_contents(); ob_end_clean(); return $contents;
} return false;
}
function showPage($key,$seed=1)
{ global $fnc,$global_current_file,$need_fix_name,$designPath,$commonDesignPath,$redis;
if($seed){ $designPath=$key; $commonDesignPath=''; }
$dpath = $designPath; $cdpath = $commonDesignPath;
$out = '';
if($seed)
{ global $seedPath,$seedKey,$design_cache,$currentLangage,$urlpath; $seedPath=$urlpath.'/'.$key; $seedKey=$key;
$design_cache = $redis->hgetall(redisPrefix.':designCache:'.$currentLangage.':'.$seedPath);
if(!isset($design_cache['ini:loaded'])) // redis page info not set
{ //print '
loading ini';
$page_opt = array('loaded'=>1);
$path = template.'/'.$key.'/'.$key.'.ini';
if(is_file($path)) $page_opt = array_merge(parse_ini_file($path),$page_opt);
$outarray = array(); foreach($page_opt as $name=>$value) $outarray['ini:'.$name] = $value;
$design_cache = array_merge($design_cache,$outarray);
$redis->hMset(redisPrefix.':designCache:'.$currentLangage.':'.$seedPath,$outarray);
}
if(!isset($design_cache['ini:skeleton'])) $design_cache['ini:skeleton'] = 'normal';
if(!isset($design_cache['ini:title'])) $design_cache['ini:title'] = defaultTitle;
if(!isset($design_cache['ini:keywords'])) $design_cache['ini:keywords'] = defaultKeywords;
if(!isset($design_cache['ini:description'])) $design_cache['ini:description'] = defaultDescription;
if(!isset($design_cache['ini:meta'])) $design_cache['ini:meta'] = defaultMeta;
if(!isset($design_cache['ini:sk']))
{ //print '
loading skeleton';
$path = template.'/'.common_path.'/skeleton/'.$design_cache['ini:skeleton'].'.html';
if(is_file($path))
{ $out = file_get_contents($path); $redis->hset(redisPrefix.':designCache:'.$currentLangage.':'.$seedKey,'ini:sk',$out);
} else $out = '
';print_r($constants);print ''; // page specific constants $path = template.'/'.$seedKey.'/'.design_path; if(is_file($path)) $constants = array_merge_recursive($constants,parse_ini_file($path,true)); if(isset($constants)) { //print '
';print_r($constants);print ''; foreach($constants as $name=>$sub) { if($name == $currentLangage || $name == 'common') foreach($sub as $cnt=>$val) $global_constants[$cnt] = $val; } } //$redis->hmset(redisPrefix.':designCache:'.$currentLangage.':'.$seedPath.':constant',$global_constants); //print '
';print_r($global_constants);print ''; } } if(isset($global_constants[$design])){$d=$global_constants[$design];setDesignCache($design,$d);return $d;} } else { $mdl = explode('|',$design); if(isset($mdl[0])) { $mdl = $mdl[0]; $mdlargs = getArgs($design,$mdl.'|','|'); if($mdlargs[0] > 0) { $fn = 'fn_'.$mdl; ob_start(); if(function_exists($fn)) $fn($mdlargs); else { $path = module_path.'/'.$mdl.'/'.$mdl.'.php'; if(is_file($path)) { //print ' load module '.$mdl.' '; include($path); $fn($mdlargs); }// else { print '
';print_r($keywords);print ''; $out = ''; if($callback !== false) { $n=0; if(is_array($callback)) { foreach($data as $dta) { $d = $design; foreach($keywords as $word) { if(isset($callback[$word])) // specific word callback exist ! { if(isset($dta[$word])) $d = str_replace('$'.$word.'$', $callback[$word]($dta[$word],$n), $d); // data contain this word, callback receive the word else $d = str_replace('$'.$word.'$', $callback[$word]($dta,$n), $d); // data not get the word, callback receive all the data } else $d = str_replace('$'.$word.'$','', $d); // else, fill blank } $out .= $d; $n++; } } else { // callback is a generic function, who get word and complete data foreach($data as $dta) { $d = $design; foreach($keywords as $word) $d = str_replace('$'.$word.'$', $callback($word,$dta,$n++), $d); $out .= $d; } } } else { foreach($data as $dta) { $d = $design; foreach($keywords as $word => $size) { // no callback, just replace specific word with data, or fill blank if word data not set if(isset($dta[$word])) $d = str_replace('$'.$word.'$', $dta[$word]); else $d = str_replace('$'.$word.'$','', $d); } $out .= $d; } } return $out; } function lredisHashFill($listkey, $design, $callback=false, $kprefix='', $ksuffix='', $start=0, $end=-1, &$size=0) { global $redis; list($keys,$size) = $redis->multi(Redis::PIPELINE)->lRange($listkey,$start,$end)->lSize($listkey)->exec(); $redis->multi(Redis::PIPELINE); foreach($keys as $k) $redis->hgetall($kprefix.$k.$ksuffix); $data = $redis->exec(); //print '
';print_r($data);print ''; return fillDesign($data,$design,$callback); } function sredisHashFill($setkey, $design, $callback=false, $kprefix='', $ksuffix='') { global $redis; $keys = $redis->smembers($setkey); $redis->multi(Redis::PIPELINE); foreach($keys as $k) $redis->hgetall($kprefix.$k.$ksuffix); $data = $redis->exec(); //print '
';print_r($data);print ''; return fillDesign($data,$design,$callback); } function redisHashFill($hashkey, $design, $callback=false) { global $redis; return fillDesign(array($redis->hgetall($hashkey)), $design, $callback); } function isUserPrivilege($prv) { return ( isset($_SESSION['user']) && (( isset($_SESSION['user']['right:all']) && !isset($_SESSION['user']['right:'.$prv]) ) || ( isset($_SESSION['user']['right:'.$prv]) && $_SESSION['user']['right:'.$prv] ))); } ?>