PageRenderTime 51ms CodeModel.GetById 27ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. */
  16. class MVCTools_EngineLibrary extends Systems
  17. {
  18. public $staging_mvc_view = NULL;
  19. public $returndata = array();
  20. public function mainprocess($data=NULL)
  21. {
  22. $output = '';
  23. $GetConfig = $this->_SysEngine->configtools->getconfig('mvctools');
  24. $ActiveProgram = (!empty($GetConfig['mvc_class']))?$GetConfig['mvc_class']:((!empty($this->_CurProgramData['uprgm_name']))?$this->_CurProgramData['uprgm_name']:$this->_CurProgramData['iprgm_name']);
  25. //$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']);
  26. /*
  27. * Load Controller Class
  28. */
  29. $ControllerProgram = $ActiveProgram.'_c';
  30. $autoload[] = array('sourcedir'=>$this->_CurSystemProgramDir.'/controller','file'=>$ControllerProgram.'.php','class'=>NULL,'alias'=>NULL,'loaderstate'=>NULL);
  31. /*
  32. * Load Model Class
  33. */
  34. $ModelProgram = $ActiveProgram.'_m';
  35. $autoload[] = array('sourcedir'=>$this->_CurSystemProgramDir.'/model','file'=>$ModelProgram.'.php','class'=>NULL,'alias'=>NULL,'loaderstate'=>NULL);
  36. /*
  37. * Load View Class
  38. */
  39. $ViewProgram = $ActiveProgram.'_v';
  40. $autoload[] = array('sourcedir'=>$this->_CurSystemProgramDir.'/view','file'=>$ViewProgram.'.php','class'=>NULL,'alias'=>NULL,'loaderstate'=>NULL);
  41. /*
  42. * Class Loader
  43. */
  44. $this->class_loader(array('sourcedir'=>NULL,'autoload'=>$autoload,'loaderstate'=>'dynamic'));
  45. /*
  46. * Call predifined class in autoloader
  47. */
  48. ${$ControllerProgram} = (!is_null($this->$ControllerProgram))?$this->$ControllerProgram:new StdClass;
  49. ${$ViewProgram} = (!is_null($this->$ViewProgram))?$this->$ViewProgram:new StdClass;
  50. if($this->_CurProgramData['iprgm_type']=='app')
  51. {
  52. $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':'')));
  53. //$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':''))));
  54. }
  55. else
  56. {
  57. $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':''));
  58. //$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':''));
  59. }
  60. if(!empty($PageMethod))
  61. {
  62. $func_get_args = func_get_args();
  63. $returndata = call_user_func_array(array(${$ControllerProgram},$PageMethod),$func_get_args);
  64. $this->returndata = (!empty($returndata))?$returndata:array();
  65. if(method_exists(${$ViewProgram},$PageMethod))
  66. {
  67. $output .= call_user_func_array(array(${$ViewProgram},$PageMethod),$this->returndata);
  68. }
  69. else if(file_exists($this->_CurSystemProgramDir.'/view/'.$ActiveProgram.'/'.$PageMethod.'.php'))
  70. {
  71. $output .= $this->viewprocess(array('file'=>''.$PageMethod.'.php','data'=>$this->returndata,'sourcedir'=>$this->_CurSystemProgramDir.'/view/'.$ActiveProgram.'/','grab'=>true));
  72. }
  73. }
  74. else if(empty($PageMethod) and $this->_CurProgramData['iprgm_type']=='app')
  75. {
  76. $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
  77. }
  78. $output .= $this->staging_mvc_view;
  79. $this->staging_mvc_view = NULL;
  80. return $output;
  81. }
  82. public function viewprocess($data=NULL)
  83. {
  84. $ViewFile = ((!empty($data['sourcedir']))?$data['sourcedir']:$this->_CurSystemProgramDir.'/view/').((!empty($data['file']))?$data['file']:'');
  85. $ViewData = (isset($data['data']))?$data['data']:NULL;
  86. $Grab = (isset($data['grab']))?$data['grab']:false;
  87. unset($data);
  88. if(file_exists($ViewFile))
  89. {
  90. (!empty($ViewData))?extract($ViewData):NULL;
  91. @ob_start();
  92. include($ViewFile);
  93. $output = ob_get_contents();
  94. @ob_end_clean();
  95. if($Grab===false)
  96. {
  97. $this->staging_mvc_view .= $output;
  98. }
  99. else
  100. {
  101. return $output;
  102. }
  103. }
  104. }
  105. }
  106. ?>