PageRenderTime 103ms CodeModel.GetById 61ms app.highlight 7ms RepoModel.GetById 33ms app.codeStats 0ms

/system/engine/engine_library/mvctools.enginelib.php

https://bitbucket.org/threetopia/thtech
PHP | 108 lines | 74 code | 2 blank | 32 comment | 9 complexity | 38742cb0b3ca571210ee1b5a5dcb0ba7 MD5 | raw file
  1<?php
  2/*
  3 * File name		: mvctools.enignelib.php
  4 * Author			: Tri Hartanto
  5 * Site				: trihartanto.com
  6 * Framework		: thtech
  7 * Library type		: Engine Library
  8 * Version			: 1.5
  9 * License			: GPL
 10 * Create Date		: 11 Dec 2013
 11 * Modified Date	: 04 Apr 2014
 12 * File Description	: This file contains MVC (Model View Controller) class to be used by the framework and CMS system.
 13 * 
 14 * For more license information please kindly open and read LICENSE.txt file
 15 */
 16class MVCTools_EngineLibrary extends Systems
 17{
 18	public $staging_mvc_view = NULL;
 19	public $returndata = array();
 20	
 21	public function mainprocess($data=NULL)
 22	{
 23		$output = '';
 24		$GetConfig = $this->_SysEngine->configtools->getconfig('mvctools');
 25		$ActiveProgram = (!empty($GetConfig['mvc_class']))?$GetConfig['mvc_class']:((!empty($this->_CurProgramData['uprgm_name']))?$this->_CurProgramData['uprgm_name']:$this->_CurProgramData['iprgm_name']);
 26		//$ActiveProgram = (!empty($this->_NavData[0]['nav_mvc_class']) and $this->_CurProgramData['iprgm_type']=='app')?$this->_NavData[0]['nav_mvc_class']:(!empty($this->_CurProgramData['uprgm_mvc_class']))?$this->_CurProgramData['uprgm_mvc_class']:((!empty($this->_CurProgramData['uprgm_name']))?$this->_CurProgramData['uprgm_name']:$this->_CurProgramData['iprgm_name']);
 27		/*
 28		 * Load Controller Class
 29		 */
 30		$ControllerProgram = $ActiveProgram.'_c';
 31		$autoload[] = array('sourcedir'=>$this->_CurSystemProgramDir.'/controller','file'=>$ControllerProgram.'.php','class'=>NULL,'alias'=>NULL,'loaderstate'=>NULL);
 32		/*
 33		 * Load Model Class
 34		 */
 35		$ModelProgram = $ActiveProgram.'_m';
 36		$autoload[] = array('sourcedir'=>$this->_CurSystemProgramDir.'/model','file'=>$ModelProgram.'.php','class'=>NULL,'alias'=>NULL,'loaderstate'=>NULL);	
 37		/*
 38		 * Load View Class
 39		 */
 40		$ViewProgram = $ActiveProgram.'_v';
 41		$autoload[] = array('sourcedir'=>$this->_CurSystemProgramDir.'/view','file'=>$ViewProgram.'.php','class'=>NULL,'alias'=>NULL,'loaderstate'=>NULL);	
 42		/*
 43		 * Class Loader
 44		 */
 45		$this->class_loader(array('sourcedir'=>NULL,'autoload'=>$autoload,'loaderstate'=>'dynamic'));
 46		/*
 47		 * Call predifined class in autoloader
 48		 */
 49		${$ControllerProgram} = (!is_null($this->$ControllerProgram))?$this->$ControllerProgram:new StdClass;
 50		${$ViewProgram} = (!is_null($this->$ViewProgram))?$this->$ViewProgram:new StdClass;
 51		if($this->_CurProgramData['iprgm_type']=='app')
 52		{
 53			$PageMethod = (!empty($GetConfig['mvc_method']) and method_exists(${$ControllerProgram},$GetConfig['mvc_method']))?$GetConfig['mvc_method']:((!empty($this->_NavData[0]['nav_name']) and method_exists(${$ControllerProgram},$this->_NavData[0]['nav_name']))?$this->_NavData[0]['nav_name']:((isset($this->_URLDecode['URLLink']) and method_exists(${$ControllerProgram},$this->_URLDecode['URLLink']))?$this->_URLDecode['URLLink']:((!isset($this->_URLDecode['URLLink']) and empty($this->_NavData[0]['nav_name']) and method_exists(${$ControllerProgram},'index'))?'index':'')));
 54			//$PageMethod = (!empty($this->_NavData[0]['nav_mvc_method']) and method_exists(${$ControllerProgram},$this->_NavData[0]['nav_mvc_method']))?$this->_NavData[0]['nav_mvc_method']:((!empty($this->_CurProgramData['uprgm_mvc_method']) and method_exists(${$ControllerProgram},$this->_CurProgramData['uprgm_mvc_method']))?$this->_CurProgramData['uprgm_mvc_method']:((!empty($this->_NavData[0]['nav_name']) and method_exists(${$ControllerProgram},$this->_NavData[0]['nav_name']))?$this->_NavData[0]['nav_name']:((isset($this->_URLDecode['URLLink']) and method_exists(${$ControllerProgram},$this->_URLDecode['URLLink']))?$this->_URLDecode['URLLink']:((!isset($this->_URLDecode['URLLink']) and empty($this->_NavData[0]['nav_name']) and method_exists(${$ControllerProgram},'index'))?'index':''))));
 55		}
 56		else
 57		{
 58			$PageMethod = (!empty($GetConfig['mvc_method']) and method_exists(${$ControllerProgram},$GetConfig['mvc_method']))?$GetConfig['mvc_method']:((!empty($this->_AppData[0]['uprgm_name']) and method_exists(${$ControllerProgram},$this->_AppData[0]['uprgm_name']))?$this->_AppData[0]['uprgm_name']:((method_exists(${$ControllerProgram},'index'))?'index':''));
 59			//$PageMethod = (!empty($this->_CurProgramData['uprgm_mvc_method']) and method_exists(${$ControllerProgram},$this->_CurProgramData['uprgm_mvc_method']))?$this->_CurProgramData['uprgm_mvc_method']:((!empty($this->_AppData[0]['uprgm_name']) and method_exists(${$ControllerProgram},$this->_AppData[0]['uprgm_name']))?$this->_AppData[0]['uprgm_name']:((method_exists(${$ControllerProgram},'index'))?'index':''));
 60		}
 61		if(!empty($PageMethod))
 62		{
 63			$func_get_args = func_get_args();
 64			$returndata = call_user_func_array(array(${$ControllerProgram},$PageMethod),$func_get_args);
 65			$this->returndata = (!empty($returndata))?$returndata:array();
 66			if(method_exists(${$ViewProgram},$PageMethod))
 67			{
 68				$output .= call_user_func_array(array(${$ViewProgram},$PageMethod),$this->returndata);
 69			}
 70			else if(file_exists($this->_CurSystemProgramDir.'/view/'.$ActiveProgram.'/'.$PageMethod.'.php'))
 71			{
 72				$output .= $this->viewprocess(array('file'=>''.$PageMethod.'.php','data'=>$this->returndata,'sourcedir'=>$this->_CurSystemProgramDir.'/view/'.$ActiveProgram.'/','grab'=>true));
 73			}
 74		}
 75		else if(empty($PageMethod) and $this->_CurProgramData['iprgm_type']=='app')
 76		{
 77			$this->_SysEngine->httptools->errorprocess(array('error'=>'404','message'=>'MVC tools can\'t found any match controller or method on Application to render the page.'));# 404 Page not found
 78		}
 79		$output .= $this->staging_mvc_view;
 80		$this->staging_mvc_view = NULL;
 81		return $output;
 82	}
 83	
 84	public function viewprocess($data=NULL)
 85	{
 86		$ViewFile = ((!empty($data['sourcedir']))?$data['sourcedir']:$this->_CurSystemProgramDir.'/view/').((!empty($data['file']))?$data['file']:'');
 87		$ViewData = (isset($data['data']))?$data['data']:NULL;
 88		$Grab = (isset($data['grab']))?$data['grab']:false;
 89		unset($data);
 90		if(file_exists($ViewFile))
 91		{
 92			(!empty($ViewData))?extract($ViewData):NULL;
 93			@ob_start();
 94			include($ViewFile);
 95			$output = ob_get_contents();
 96			@ob_end_clean();
 97			if($Grab===false)
 98			{
 99				$this->staging_mvc_view .= $output;
100			}
101			else
102			{
103				return $output;
104			}
105		}
106	}
107}
108?>