00001 <?php
00028 global $request;
00034 class zigController extends zCore{
00041 var $request;
00048 var $load;
00055 var $prjName;
00062 var $className;
00069 var $methodName;
00076 var $layoutName = null;
00083 var $layoutPath = null;
00090 var $paramsPath = null;
00097 var $paramsName = null;
00104 var $viewQueue = array();
00111 var $ormList = array();
00118 var $params = array();
00125 var $multiLayout = false;
00132 var $loadedOrms = array();
00139 var $db;
00146 var $noAutoViewRender = false;
00153 var $cacheConfig = array();
00160 var $cacheDict = array();
00167 var $cache;
00174 var $noLayout = false;
00181 var $postPeer;
00188 var $getPeer;
00189
00190 function zigController(){
00191 $this->__construct();
00192 }
00193 function __construct(){
00194 global $app_data;
00195 global $request;
00196 global $load;
00197 $this->db = new stdClass();
00198 $this->prjName = $app_data['prj'];
00199 $this->className = $app_data['class'];
00200 $this->methodName = $app_data['method'];
00201 $this->request =& $request;
00202 $this->postPeer =& $request->post;
00203 $this->getPeer =& $request->get;
00204 $this->load =& $load;
00205 if(!defined('Z_CACHE_FULL'))define('Z_CACHE_FULL', 'f');
00206 if(!defined('Z_CACHE_CONTROLLER'))define('Z_CACHE_CONTROLLER', 'c');
00207 if(!defined('Z_CACHE_RENDERED_VIEW'))define('Z_CACHE_RENDERED_VIEW', 'rv');
00208 if(!defined('Z_CACHE_LOADED_VIEW'))define('Z_CACHE_LOADED_VIEW', 'lv');
00209 if(!defined('Z_CACHE_RENDERED_SHARED_VIEW'))define('Z_CACHE_RENDERED_SHARED_VIEW', 'rsv');
00210 if(!defined('Z_CACHE_LOADED_SHARED_VIEW'))define('Z_CACHE_LOADED_SHARED_VIEW', 'lsv');
00211
00212 parent::__construct();
00213 }
00227 function retViewPath($viewName){
00238 $place = array('class' => $this->className, 'method' => $this->methodName, 'view' => $viewName);
00239 switch(strchr_occurrences($viewName, '.')){
00240 case 0:
00241 break;
00242 case 1:
00243 $data = explode('.', $viewName);
00244 $place['method'] = $data[0];
00245 $place['view'] = $data[1];
00246 break;
00247 case 2:
00248 $data = explode('.', $viewName);
00249 $place['class'] = $data[0];
00250 $place['method'] = $data[1];
00251 $place['view'] = $data[2];
00252 break;
00253 default:
00254 perror('<code>ZigMoyd.mvc.view</code><br />Invalid View '.$viewName);
00255 return false;
00256 }
00257
00258 $baseSharedPath = ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.fstab_getProjectDirByName($this->prjName).DRS.Z_VIEW_DIR_NAME.DRS;
00259 $commonBasePath = ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.fstab_getProjectDirByName($this->prjName).DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_VIEW.DRS;
00260 $viewPath = $commonBasePath.$place['class'].DRS.$place['method'].DRS.$place['view'].'.view.php';
00261 if($this->layoutName){
00262 $layoutPath = $baseSharedPath.$this->layoutName.'.layout.php';
00263 }else{
00264 if($this->multiLayout){
00265
00266 $layoutPath = $commonBasePath.$place['class'].DRS.$place['method'].DRS.$place['method'].'.layout.php';
00267 }else{
00268 $layoutPath = $commonBasePath.$place['class'].DRS.$place['class'].'.layout.php';
00269 }
00270 }
00271 if($this->paramsName){
00272 $paramsPath = $baseSharedPath.$this->paramsName.'.params.php';
00273 }else{
00274 if($this->multiLayout){
00275
00276 $paramsPath = $commonBasePath.$place['class'].DRS.$place['method'].DRS.$place['method'].'.params.php';
00277 }else{
00278 $paramsPath = $commonBasePath.$place['class'].DRS.$place['class'].'.params.php';
00279 }
00280 }
00281
00282 return array($viewPath, $layoutPath, $paramsPath);
00283 }
00289 function commitViews(){
00290 if(strlen($this->layoutPath) > 1 && strlen($this->paramsPath)){
00291
00292 if(!file_exists($this->layoutPath)){
00293 exit(zTemplate::sysNumeric('l404', $this->layoutPath, getcwd()));
00294 }else{
00295
00296 if(!file_exists($this->paramsPath)){
00297 exit(zTemplate::sysNumeric('pr404', $this->paramsPath, getcwd()));
00298 }else{
00299 if(!include_once($this->paramsPath)){
00300 perror("<code>zigmoyd.apps.mvc</code><br />Failed to Include $this->paramsPath");
00301 exit;
00302 }
00303 }
00304
00305
00306 if(isset($this->cacheDict[Z_CACHE_CONTROLLER]["$this->className.$this->methodName"]))$this->params['content'] = $this->cacheDict[Z_CACHE_CONTROLLER]["$this->className.$this->methodName"];
00307
00308 foreach($params as $var => $val){
00309 if(!isset($this->params[$var])){
00310 $this->params[$var] = $val;
00311 }
00312 }
00313
00314
00315 ob_start();
00316 if(!include_once($this->layoutPath)){
00317 perror("<code>zigmoyd.apps.mvc</code><br />Failed to include $this->layoutPath");
00318 exit;
00319 }
00320
00321 if(isset($this->cacheConfig[Z_CACHE_FULL][Z_CACHE_FULL]) && is_array($this->cacheConfig[Z_CACHE_FULL][Z_CACHE_FULL])){
00322 zLogger::debug("Creating Full Page Cache ["."$this->className.$this->methodName.".$this->cacheConfig[Z_CACHE_FULL][Z_CACHE_FULL]['lifeTime'].'.php'."]", "cache.full");
00323 file_put_contents(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_CACHE_MVC.DRS."full".DRS."$this->className.$this->methodName.cache", ob_get_contents());
00324 }
00325
00326 if(isset($this->cacheConfig[Z_CACHE_CONTROLLER]["$this->className.$this->methodName"]) && is_array($this->cacheConfig[Z_CACHE_CONTROLLER]["$this->className.$this->methodName"])){
00327 zLogger::debug("Creating Controller Level Cache [$this->className.$this->methodName] with a Lifetime of ".($this->cacheConfig[Z_CACHE_CONTROLLER]["$this->className.$this->methodName"]['lifeTime']-time())." Seconds from Now", "cache.controller");
00328 $this->doCache("$this->className.$this->methodName", Z_CACHE_CONTROLLER, ($this->cacheConfig[Z_CACHE_CONTROLLER]["$this->className.$this->methodName"]['lifeTime']), $this->params['content']);
00329 }
00330 ob_end_flush();
00331
00332
00333 }
00334
00335 }else{
00336 if(!$this->noLayout){
00337 perror("zigmoyd mvc Engine Serving Without any layout But You need to explecitely Decleare that you really dont want a layout<br />e.g. its a Layout less application else zigmoyd will fire this error as it thinks that you did this wrongly<br />To Explecitely Decleare no Layout Application use <br />\$this->noLayout();");
00338 return false;
00339 }else{
00340
00341
00342
00343 if(isset($this->params['content']))echo $this->params['content'];
00344
00345
00346
00347
00348
00349 }
00350 }
00351 }
00364 function renderView($viewName, $return=false){
00365 list($viewPath, $layoutPath, $paramsPath) = $this->retViewPath($viewName);
00366 $this->paramsPath = $paramsPath;
00367 $this->layoutPath = $layoutPath;
00368 if(!file_exists($viewPath)){
00369
00370 exit(zTemplate::sysNumeric('v404', $viewName, $viewPath));
00371
00372 }else{
00373
00374
00375 if(!isset($this->cacheDict[Z_CACHE_RENDERED_VIEW][$viewName])){
00376 foreach($this as $var => $val){
00377 ${$var} = $val;
00378 }
00379 }
00380
00381 ob_start();
00382
00383 if(!isset($this->cacheDict[Z_CACHE_RENDERED_VIEW][$viewName]) && !include($viewPath)){
00384 perror("<code>zigmoyd.apps.mvc</code><br />failed to include view on $viewPath");exit;
00385 }
00386
00387 $viewContent = (!isset($this->cacheDict[Z_CACHE_RENDERED_VIEW][$viewName])) ? ob_get_contents() : $this->cacheDict[Z_CACHE_RENDERED_VIEW][$viewName];
00388 if($return)return $viewContent;
00389 if(!isset($this->params['content']) || !strlen($this->params['content']) > 0){
00390 $this->params['content'] = $viewContent;
00391 }else{
00392 $this->params['content'] .= $viewContent;
00393 }
00394
00395 ob_end_clean();
00396
00397 if(isset($this->cacheConfig[Z_CACHE_RENDERED_VIEW][$viewName]) && is_array($this->cacheConfig[Z_CACHE_RENDERED_VIEW][$viewName])){
00398 zLogger::debug("Creating View(Rendered) Level Cache [$viewName] with a Lifetime of ".($this->cacheConfig[Z_CACHE_RENDERED_VIEW][$viewName]['lifeTime']-time())." Seconds from Now", "cache.view.rendered");
00399 $this->doCache($viewName, Z_CACHE_RENDERED_VIEW, $this->cacheConfig[Z_CACHE_RENDERED_VIEW][$viewName]['lifeTime'], $viewContent);
00400 }
00401
00402
00403 }
00404 }
00411 function queueAutoView($viewName){
00412 $this->viewQueue[] = $viewName;
00413 }
00418 function renderAutoView(){
00419 foreach($this->viewQueue as $view){
00420 $this->renderView($view);
00421 }
00422 }
00431 function renderSharedView($viewName, $projectName=null, $return=false){
00432 list($nullDummy, $this->layoutPath, $this->paramsPath) = $this->retViewPath($viewName);
00433 if(is_null($projectName))$projectName = $this->prjName;
00434 $viewPath = ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.fstab_getProjectDirByName($projectName).DRS.Z_VIEW_DIR_NAME.DRS.$viewName.'.view.php';
00435 if(!file_exists($viewPath)){
00436
00437 perror("Failed to render Shared View $viewName as no such file exists $viewPath");
00438
00439 }else{
00440
00441
00442 if(!isset($this->cacheDict[Z_CACHE_RENDERED_SHARED_VIEW][$viewName])){
00443 foreach($this as $var => $val){
00444 ${$var} = $val;
00445 }
00446 }
00447
00448 ob_start();
00449
00450 if(!isset($this->cacheDict[Z_CACHE_RENDERED_SHARED_VIEW][$viewName]) && !include($viewPath)){
00451 perror("failed to include view on $viewPath");
00452 }
00453
00454
00455 $viewContent = (!isset($this->cacheDict[Z_CACHE_RENDERED_SHARED_VIEW][$viewName])) ? ob_get_contents() : $this->cacheDict[Z_CACHE_RENDERED_SHARED_VIEW][$viewName];
00456 if($return)return $viewContent;
00457 if(!isset($this->params['content']) || !strlen($this->params['content']) > 0){
00458 $this->params['content'] = $viewContent;
00459 }else{
00460 $this->params['content'] .= $viewContent;
00461 }
00462
00463 ob_end_clean();
00464 if(isset($this->cacheConfig[Z_CACHE_RENDERED_SHARED_VIEW][$viewName]) && is_array($this->cacheConfig[Z_CACHE_RENDERED_SHARED_VIEW][$viewName])){
00465 zLogger::debug("Creating Shared View(Rendered) Level Cache [$viewName] with a Lifetime of ".($this->cacheConfig[Z_CACHE_RENDERED_SHARED_VIEW][$viewName]['lifeTime']-time())." Seconds from Now", "cache.view.rendered.shared");
00466 $this->doCache($viewName, Z_CACHE_RENDERED_SHARED_VIEW, $this->cacheConfig[Z_CACHE_RENDERED_SHARED_VIEW][$viewName]['lifeTime'], $viewContent);
00467 }
00468
00469
00470 }
00471 }
00481 function loadView($viewName, $varList, $return=false){
00482 list($viewPath, $layoutPath, $paramsPath) = $this->retViewPath($viewName);
00483 $this->paramsPath = $paramsPath;
00484 $this->layoutPath = $layoutPath;
00485 if(!file_exists($viewPath)){
00486
00487 perror("Failed to Load View $viewName as no such file exists $viewPath");
00488
00489 }else{
00490
00491
00492 if(!isset($this->cacheDict[Z_CACHE_LOADED_VIEW][$viewName])){
00493 foreach($varList as $var => $val){
00494 ${$var} = $val;
00495 }
00496 }
00497
00498 ob_start();
00499
00500 if(!isset($this->cacheDict[Z_CACHE_LOADED_VIEW][$viewName]) && !include($viewPath)){
00501 perror("<code>zigmoyd.apps.mvc</code><br />failed to include view on $viewPath");exit;
00502 }
00503
00504 $viewContent = (!isset($this->cacheDict[Z_CACHE_LOADED_VIEW][$viewName])) ? ob_get_contents() : $this->cacheDict[Z_CACHE_LOADED_VIEW][$viewName];
00505 if($return)return $viewContent;
00506 if(!isset($this->params['content']) || !strlen($this->params['content']) > 0){
00507 $this->params['content'] = $viewContent;
00508 }else{
00509 $this->params['content'] .= $viewContent;
00510 }
00511 ob_end_clean();
00512 if(isset($this->cacheConfig[Z_CACHE_LOADED_VIEW][$viewName]) && is_array($this->cacheConfig[Z_CACHE_LOADED_VIEW][$viewName])){
00513 zLogger::debug("Creating Shared View(Loaded) Level Cache [$viewName] with a Lifetime of ".($this->cacheConfig[Z_CACHE_LOADED_VIEW][$viewName]['lifeTime']-time())." Seconds from Now", "cache.view.loaded");
00514 $this->doCache($viewName, Z_CACHE_LOADED_VIEW, $this->cacheConfig[Z_CACHE_LOADED_VIEW][$viewName]['lifeTime'], $viewContent);
00515 }
00516
00517 }
00518 }
00530 function loadSharedView($viewName, $varList, $projectName=null, $return=false){
00531 list($nullDummy, $this->layoutPath, $this->paramsPath) = $this->retViewPath($viewName);
00532 if(is_null($projectName))$projectName = $this->prjName;
00533 $viewPath = ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.fstab_getProjectDirByName($projectName).DRS.Z_VIEW_DIR_NAME.DRS.$viewName.'.view.php';
00534 if(!file_exists($viewPath)){
00535
00536 perror("Failed to Load Shared View $viewName as no such file exists $viewPath");
00537 return false;
00538
00539 }else{
00540
00541
00542 if(!isset($this->cacheDict[Z_CACHE_LOADED_SHARED_VIEW][$viewName])){
00543 foreach($varList as $var => $val){
00544 ${$var} = $val;
00545 }
00546 }
00547
00548 ob_start();
00549
00550 if(!isset($this->cacheDict[Z_CACHE_LOADED_SHARED_VIEW][$viewName]) && !include($viewPath)){
00551 perror("<code>zigmoyd.apps.mvc</code><br />failed to include view on $viewPath");
00552 exit;
00553 }
00554
00555 $viewContent = (!isset($this->cacheDict[Z_CACHE_LOADED_SHARED_VIEW][$viewName])) ? ob_get_contents() : $this->cacheDict[Z_CACHE_LOADED_SHARED_VIEW][$viewName];
00556 if($return)return $viewContent;
00557 if(!isset($this->params['content']) || !strlen($this->params['content']) > 0){
00558 $this->params['content'] = $viewContent;
00559 }else{
00560 $this->params['content'] .= $viewContent;
00561 }
00562 ob_end_clean();
00563 if(isset($this->cacheConfig[Z_CACHE_LOADED_SHARED_VIEW][$viewName]) && is_array($this->cacheConfig[Z_CACHE_LOADED_SHARED_VIEW][$viewName])){
00564 zLogger::debug("Creating Shared View(Loaded) Level Cache [$viewName] with a Lifetime of ".($this->cacheConfig[Z_CACHE_LOADED_SHARED_VIEW][$viewName]['lifeTime']-time())." Seconds from Now", "cache.view.rendered");
00565 $this->doCache($viewName, Z_CACHE_LOADED_SHARED_VIEW, $this->cacheConfig[Z_CACHE_LOADED_SHARED_VIEW][$viewName]['lifeTime'], $viewContent);
00566 }
00567
00568
00569 }
00570 return true;
00571 }
00578 function switchLayout($layoutName){
00579 $this->layoutName = $layoutName;
00580 }
00587 function switchLayoutParams($layoutParamsFile){
00588 $this->paramsName = $layoutParamsFile;
00589 }
00597 function getLayoutParams($var = null){
00598 if(!is_null($var)){
00599 if(isset($this->params[$var])){
00600 return $this->params[$var];
00601 }else{
00602 return false;
00603 }
00604 }else{
00605 return $this->params;
00606 }
00607 }
00614 function setLayoutParams($var, $value){
00615 $this->params[$var] = $value;
00616 }
00622 function setLayoutMeta($metaTagStr){
00623 $this->params['meta'][] = $metaTagStr;
00624 }
00631 function multiLayout($flag=true){
00632 $this->multiLayout = $flag;
00633 }
00639 function noAutoViewRender($flag=true){
00640 $this->noAutoViewRender = $flag;
00641 }
00647 function noLayout($flag=true){
00648 $this->noLayout = $flag;
00649 }
00650
00657 function attachModel($modelName, $projectName=null){
00658
00659 if(is_null($projectName))$projectName = $this->prjName;
00660 $modelPath = ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.fstab_getProjectDirByName($projectName).DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_MODEL.DRS.$modelName.'.php';
00661 if(!file_exists($modelPath)){
00662 exit(zTemplate::sysNumeric('m404', $modelPath, $modelName, $projectName));
00663 }elseif(!is_readable($modelPath)){
00664 exit(zTemplate::sysNumeric('m403', $modelPath));
00665 }
00666 if(!include_once($modelPath)){
00667 perror("Failed to include model on $modelPath");
00668 return false;
00669 }
00670 if(!class_exists($modelName.'Model')){
00671 exit(zTemplate::sysNumeric('m500', $modelName, $modelPath));
00672 }else{
00673 $className = $modelName.'Model';
00674 $dummy = new $className();
00675 $dummy->attachOrmMap();
00676 foreach($dummy->ormList as $ormName){
00677 $this->ormList[$ormName] = array();
00678 $this->loadOrm($ormName);
00679 }
00680 unset($dummy);
00681 }
00682 }
00683
00690 function flash($msg, $exitFlag=false){
00691 $this->noAutoViewRender();
00692 $this->noLayout();
00693 $this->loadSharedView('zig.flash', array('msg' => $msg));
00694 $this->noAutoViewRender(false);
00695 $this->noLayout(false);
00696 if($exitFlag)exit;
00697 }
00705 function redirect($msg, $location, $timer=0){
00706 $this->loadSharedView('zig.flash', array('msg' => $msg));
00707 $this->setLayoutMeta("<meta http-equiv=\"refresh\" content=\"$timer;url=$location\">");
00708 }
00714 function headerRedirect($path){
00715 header("Location: $path");
00716 }
00722 function forward($httpErrorCode){
00723
00724 if(zTemplate::exists($httpErrorCode, true)){
00725 echo zTemplate::sysNumeric($httpErrorCode, '/'.implode('/', url_segment(ZIG_URL_SEGMENT_PATH)));
00726 }else{
00727 perror("<code>zigmoyd.template</code><br />System Template for $httpErrorCode doesn't exists");
00728 }
00729 exit;
00730 }
00737 function setHeader($str){
00738 return header($str);
00739 }
00746 function setContentType($mimeType){
00747 return $this->setHeader('Content-Type: '.$mimeType);
00748 }
00754 function getHeaders(){
00755 return headers_list();
00756 }
00762 function getSentHeaders(){
00763 return headers_sent();
00764 }
00765
00771 function validateForm($validationMapName){
00772 if($this->isPostRequest())$this->request->post->initValidator($validationMapName);
00773 }
00779 function validateGet($validationMapName){
00780 if($this->isGetRequest())$this->request->get->initValidator($validationMapName);
00781 }
00782
00789 function loadOrm($ormMapName, $projectName=null){
00790 global $__ZigOrm;
00813 if(is_null($projectName))$projectName = $this->prjName;
00814 foreach(load_orm_map($ormMapName, $projectName) as $ormClassName){
00815 if(class_exists($ormClassName)){
00816 $this->db->$ormClassName = new $ormClassName();
00817 $this->loadedOrms[$ormMapName][] = $ormClassName;
00818 }else{
00819 perror("<code>zigmoyd.mvc.model.orm</code><br /> Failed to Instantiate orm Class `$ormClassName` as no such Class exists");
00820 }
00821 }
00822 }
00828 function unloadTable($ormClassName){
00829 if(!isset($this->db->$ormClassName)){perror("<code>zigmoyd.mvc.orm.unload.table</code><br />Failed to unload Table Alias <code style=\"background-color: #FFFFFF;font-weight: normal;\">$ormClassName</code> as Its instance not found on <code style=\"background-color: #FFFFFF;font-weight: normal;\">\$this->db</code>");return false;}
00830 if(!class_exists($ormClassName)){perror("<code>zigmoyd.mvc.orm.unload.table</code><br />Failed to unload Table Alias <code style=\"background-color: #FFFFFF;font-weight: normal;\">$ormClassName</code> as Its class not found");return false;}
00831 unset($this->db->$ormClassName);
00832 }
00838 function getLoadedOrm(){
00839 return $this->loadedOrms;
00840 }
00847 function getLoadedTables($ormMapName = null){
00853 global $__ZigOrm;
00854 $tableDictFlip = array_flip($__ZigOrm->dataDict->tables);
00855 $ret = array();
00856 $tablesList = $this->getLoadedTableAlias($ormMapName);
00857 if(is_bool($tablesList) && !$tablesList){
00858 perror("<code>zigmoyd.mvc.orm.unload.table</code><br />Unable to fetch the orm Map <code style=\"background-color: #FFFFFF;font-weight: normal;\">$ormMapName</code>");
00859 }
00860 if(is_array($tablesList)){
00861 foreach($this->getLoadedTableAlias($ormMapName) as $tableAliasName){
00862 array_push($ret, $tableDictFlip[$tableAliasName]);
00863 }
00864 }
00865 return $ret;
00866 }
00873 function getLoadedTableAlias($ormMapName = null){
00874 $ret = array();
00875 if(is_null($ormMapName)){
00876 $src =& $this->loadedOrms;
00877 }else{
00878 $src =& $this->loadedOrms[$ormMapName];
00879 }
00880 foreach($src as $mapName => $classList){
00881 if(is_array($classList)){
00882 foreach($classList as $className){
00883 if(isset($this->db->$className)){
00884 array_push($ret, $className);
00885 }
00886 }
00887 }else{
00888 if(isset($this->db->$classList))array_push($ret, $classList);
00889 }
00890 }
00891 return $ret;
00892 }
00893
00902 function isPostRequest(){
00903 return (isset($_POST) && count($_POST) > 0);
00904 }
00910 function isPurePost(){
00911 return ($this->isPostRequest() && !$this->isUploadRequest());
00912 }
00918 function isGetRequest(){
00926 if($this->isBlankGetRequest()){
00927 return true;
00928 }else{
00929 return (isset($_GET) && count($_GET) > 0);
00930 }
00931 }
00938 function isBlankGetRequest(){
00939 return (!isset($_GET) || count($_GET) <= 0 && !isset($_POST) || count($_POST) <= 0);
00940 }
00946 function isUploadRequest(){
00947 return (isset($_FILES) && count($_FILES) > 0);
00948 }
00954 function getRequestParams(){
00955
00956 }
00957
00963 function getUrlRoot(){
00964 return pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME);
00965 }
00974 function getCurrentUrl($bindGet = false){
00975 if(!$bindGet)
00976 return $this->getUrlRoot().'/'.implode('/', url_segment(ZIG_URL_SEGMENT_PATH));
00977 else{
00978 $base = $this->getUrlRoot().'/'.implode('/', url_segment(ZIG_URL_SEGMENT_PATH));
00979 if(is_array($this->request->get->items) && count($this->request->get->items) >= 1){
00980 $base .= "?";
00981 foreach($this->request->get->items as $key => $val){
00982 $base .= "$key=$val";
00983 }
00984 }
00985 return $base;
00986 }
00987 }
00994 function importStylesheet($styleSheetName, $rewriteEngine = false){
00995 if(strpos($styleSheetName, '.') === false)$styleSheetName .= '.css';
00996 if(!isset($this->params['css']) || !is_array($this->params['css']))$this->params['css'] = array();
00997 switch(true){
00998 case eregi(".+://.+", $styleSheetName):
00999 $this->params['css'][] = $styleSheetName;
01000 break;
01001 case eregi("^/", $styleSheetName):
01002 $this->params['css'][] = $this->getUrlRoot().$styleSheetName;
01003 break;
01004 default:
01005
01006 if($rewriteEngine){
01007 $this->params['css'][] = $this->getUrlRoot()."/r/$this->prjName/c/$styleSheetName";
01008 }else{
01009 $this->params['css'][] = $this->getUrlRoot()."/rt.php/$this->prjName/c/$styleSheetName";
01010 }
01011
01012 }
01013 }
01020 function importJavaScript($javaScriptsName, $rewriteEngine = false){
01021 if(strpos($javaScriptsName, '.') === false)$javaScriptsName .= '.js';
01022 if(!isset($this->params['js']) || !is_array($this->params['js']))$this->params['js'] = array();
01023 switch(true){
01024 case eregi(".+://.+", $javaScriptsName):
01025 $this->params['js'][] = $javaScriptsName;
01026 break;
01027 case eregi("^/", $javaScriptsName):
01028 $this->params['js'][] = $this->getUrlRoot().$javaScriptsName;
01029 break;
01030 default:
01031
01032 if($rewriteEngine){
01033 $this->params['js'][] = $this->getUrlRoot()."/r/$this->prjName/j/$javaScriptsName";
01034 }else{
01035 $this->params['js'][] = $this->getUrlRoot()."/rt.php/$this->prjName/j/$javaScriptsName";
01036 }
01037
01038 }
01039 }
01040
01048 function registerCache($name, $type, $lifeTime=30){
01049 if(in_array($type, array(Z_CACHE_FULL, Z_CACHE_CONTROLLER))){
01050 $name = array_search($type, array(Z_CACHE_FULL => Z_CACHE_FULL, "$this->className.$this->methodName" => Z_CACHE_CONTROLLER));
01051 }
01052
01053 $this->cacheConfig[$type] = array($name => array('lifeTime' => (time()+$lifeTime)));
01054
01055 }
01065 function doCache($name, $type, $lifeTime, &$content){
01066 foreach(glob(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_CACHE_MVC.DRS."$name.$type.*.cache") as $cacheFileName)unlink($cacheFileName);
01067 return file_put_contents(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_CACHE_MVC.DRS."$name.$type.$lifeTime.cache", $content);
01068 }
01076 function cacheExists($name, $type){
01077 foreach(glob(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_CACHE_MVC.DRS."$name.$type.*.cache") as $cacheFileName){
01078 if(preg_match("~$name\.$type\.(\d+)\.cache~", pathinfo($cacheFileName, PATHINFO_BASENAME), $m)){
01079 if($m[1] >= time()){
01080
01081 if(!isset($ret)){
01082 zLogger::debug("Cache $name exists", 'cache.exists');
01083 $ret = true;
01084 }else{
01085
01086 unlink($cacheFileName);
01087 }
01088 }else{
01089
01090 if(!isset($ret)){
01091 zLogger::debug("Cache $name expired", 'cache.exists');
01092 $ret = false;
01093 }else{
01094
01095 unlink($cacheFileName);
01096 }
01097 }
01098 }else{
01099
01100 $ret = false;
01101 }
01102 }
01103 if(!isset($ret))$ret = false;
01104 return $ret;
01105 }
01113 function deleteCache($name, $type){
01114 if($this->cacheExists($name, $type)){
01115 foreach(glob(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_CACHE_MVC.DRS."$name.$type.*.cache") as $cacheFileName){
01116 return unlink($cacheFileName);
01117 }
01118 }
01119 }
01126 function execCache($name, $type){
01127 if($this->cacheExists($name, $type)){
01128 foreach(glob(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_CACHE_MVC.DRS."$name.$type.*.cache") as $cacheFileName){
01129 zLogger::debug("Executing Cache $name", 'cache.exec');
01130 $this->cacheDict[$type][$name] = file_get_contents($cacheFileName);
01131 }
01132 }
01133 }
01139 function uSess($sessId){
01140 $this->noAutoViewRender();
01141 $this->load->module('unitTestReader');
01142 $this->importStylesheet('unit/unitTest');
01143 $this->importJavaScript('unit/unitTest');
01144 $test = new unitTestReader($sessId);
01145 $len = $test->length();
01146 if(!$this->loadSharedView('unit/header', array('uSessId' => $sessId, 'totalPassed' => $test->totalPassed(), 'len' => $len))){
01147 perror("<code>zigmoyd.unitTest.reader</code><br />This project is not Prepared for Unit test Reading Plese execute unit.prepare Command to Prapare it");
01148 }
01149 while($test->hasNext()){
01150 $testObj = $test->current();
01151 $testObj['title'] = "(".($test->currentIndex()+1)."/$len) Test ".((trim($testObj['ExpFlag']) == 1) ? "Passed" : "Failed");
01152 (trim($testObj['ExpFlag']) == 1) ? $this->loadSharedView('unit/test_success', &$testObj) : $this->loadSharedView('unit/test_fail', &$testObj);
01153 $test->next();
01154 }
01155 }
01156
01162 function registerFullCache(){
01163 return $this->registerCache($this->className.".".$this->methodName, Z_CACHE_FULL);
01164 }
01171 function registerControllerCache($lifeTime=30){
01172 return $this->registerCache($this->className.".".$this->methodName, Z_CACHE_CONTROLLER);
01173 }
01181 function registerRenderedViewCache($viewName, $lifeTime=30){
01182 return $this->registerCache($viewName, Z_CACHE_RENDERED_VIEW, $lifeTime);
01183 }
01191 function registerLoadedViewCache($viewName, $lifeTime=30){
01192 return $this->registerCache($viewName, Z_CACHE_LOADED_VIEW, $lifeTime);
01193 }
01201 function registerRenderedSharedViewCache($viewName, $lifeTime=30){
01202 return $this->registerCache($viewName, Z_CACHE_RENDERED_SHARED_VIEW, $lifeTime);
01203 }
01211 function registerLoadedSharedViewCache($viewName, $lifeTime=30){
01212 return $this->registerCache($viewName, Z_CACHE_LOADED_SHARED_VIEW, $lifeTime);
01213 }
01219 function existsFullCache(){
01220 return $this->cacheExists($this->className.".".$this->methodName, Z_CACHE_FULL);
01221 }
01227 function existsControllerCache(){
01228 return $this->cacheExists($this->className.".".$this->methodName, Z_CACHE_CONTROLLER);
01229 }
01236 function existsRenderedViewCache($viewName){
01237 return $this->cacheExists($viewName, Z_CACHE_RENDERED_VIEW);
01238 }
01245 function existsLoadedViewCache($viewName){
01246 return $this->cacheExists($viewName, Z_CACHE_LOADED_VIEW);
01247 }
01254 function existsRenderedSharedViewCache($viewName){
01255 return $this->cacheExists($viewName, Z_CACHE_RENDERED_SHARED_VIEW);
01256 }
01263 function existsLoadedSharedViewCache($viewName){
01264 return $this->cacheExists($viewName, Z_CACHE_LOADED_SHARED_VIEW);
01265 }
01271 function execFullCache(){
01272 return $this->execCache($this->className.".".$this->methodName, Z_CACHE_FULL);
01273 }
01280 function execControllerCache($lifeTime=30){
01281 return $this->execCache($this->className.".".$this->methodName, Z_CACHE_CONTROLLER);
01282 }
01290 function execRenderedViewCache($viewName, $lifeTime=30){
01291 return $this->execCache($viewName, Z_CACHE_RENDERED_VIEW, $lifeTime);
01292 }
01300 function execLoadedViewCache($viewName, $lifeTime=30){
01301 return $this->execCache($viewName, Z_CACHE_LOADED_VIEW, $lifeTime);
01302 }
01310 function execRenderedSharedViewCache($viewName, $lifeTime=30){
01311 return $this->execCache($viewName, Z_CACHE_RENDERED_SHARED_VIEW, $lifeTime);
01312 }
01320 function execLoadedSharedViewCache($viewName, $lifeTime=30){
01321 return $this->execCache($viewName, Z_CACHE_LOADED_SHARED_VIEW, $lifeTime);
01322 }
01328 function deleteFullCache(){
01329 return $this->deleteCache($this->className.".".$this->methodName, Z_CACHE_FULL);
01330 }
01337 function deleteControllerCache($lifeTime=30){
01338 return $this->deleteCache($this->className.".".$this->methodName, Z_CACHE_CONTROLLER);
01339 }
01347 function deleteRenderedViewCache($viewName, $lifeTime=30){
01348 return $this->deleteCache($viewName, Z_CACHE_RENDERED_VIEW, $lifeTime);
01349 }
01357 function deleteLoadedViewCache($viewName, $lifeTime=30){
01358 return $this->deleteCache($viewName, Z_CACHE_LOADED_VIEW, $lifeTime);
01359 }
01367 function deleteRenderedSharedViewCache($viewName, $lifeTime=30){
01368 return $this->deleteCache($viewName, Z_CACHE_RENDERED_SHARED_VIEW, $lifeTime);
01369 }
01377 function deleteLoadedSharedViewCache($viewName, $lifeTime=30){
01378 return $this->deleteCache($viewName, Z_CACHE_LOADED_SHARED_VIEW, $lifeTime);
01379 }
01380 }
01388 function triggeredErr($fieldName, &$handle){
01389 if(!$handle->is_submited)return false;
01390 if(!isset($handle->{$fieldName})){
01391 perror("<code>zigmoyd.rom.triggeredErr()</code><br />Field $fieldName doesnt exists on your HTML or not found on your Validation Map");
01392 return false;
01393 }
01394 if(!$handle->{$fieldName}->isValid){
01395 return $handle->{$fieldName}->err_msg;
01396 }
01397 }
01398 include_once(ZIGROOT.DRS.MOD_KEY_NAME_EXPLICIT.DRS."app".DRS."viewEmbeder.php");
01400 ?>