Advertisement
scriptz-team

Untitled

Jan 29th, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.35 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. *
  5. * _____ _____ _ _____ _____ _____ _____ _____ _____
  6. * ___| | __ |_| _ |_ _|___ ___|_ _| __| _ | |
  7. * |_ -| --| -| | __| | | |- _|___| | | | __| | | | |
  8. * |___|_____|__|__|_|__| |_| |___| |_| |_____|__|__|_|_|_|
  9. * |s C R i P T z - T E A M . i N F O|
  10. *
  11. * This file was created by sCRiPTz-TEAM.iNFO [DEiONCUBE TEAM]
  12. * @ IonCube & Zend & NuSphere DeCoder
  13. *
  14. * @ Version : 1.0.0.3
  15. * @ Author : sCRiPTz-TEAM.iNFO
  16. * @ Released : 26-December-2011
  17. * @ Official site : http://sCRiPTz-TEAM.iNFO
  18. *
  19. */
  20.  
  21. class ModuleManager implements IApplicationContextAware
  22. {
  23.  
  24. private $appContext = NULL;
  25. public $modules = array( );
  26. public $call_stack = array( );
  27. public $prev_requests = array( );
  28. private $objectMotherCreated = false;
  29. private $pathManager = null;
  30.  
  31. public function setAppContext( $appContext )
  32. {
  33. $this->appContext = $appContext;
  34. }
  35.  
  36. public function setPathManager( $manager )
  37. {
  38. $this->pathManager = $manager;
  39. }
  40.  
  41. public function init( )
  42. {
  43. $this->readModuleConfigs( );
  44. }
  45.  
  46. public function getFunctionAccessSystem( $module_name, $function_name )
  47. {
  48. if ( isset( $this->modules[$module_name]['functions'][$function_name] ) )
  49. {
  50. if ( isset( $this->modules[$module_name]['functions'][$function_name]['system'] ) )
  51. {
  52. return $this->modules[$module_name]['functions'][$function_name]['system'];
  53. }
  54. return false;
  55. }
  56. }
  57.  
  58. public function getModuleOfCommand( $command )
  59. {
  60. foreach ( $this->modules as $module_name => $module )
  61. {
  62. if ( isset( $module['commands'] ) )
  63. {
  64. foreach ( $module['commands'] as $command_name => $command_info )
  65. {
  66. if ( !( strtolower( $command ) == strtolower( $command_name ) ) )
  67. {
  68. continue;
  69. }
  70. return $module_name;
  71. }
  72. }
  73. }
  74. }
  75.  
  76. public function doesModuleExists( $module_name )
  77. {
  78. return isset( $this->modules[$module_name] );
  79. }
  80.  
  81. public function doesFunctionExist( $module, $function )
  82. {
  83. return isset( $this->modules[$module]['functions'][$function] );
  84. }
  85.  
  86. public function old_scripts_compatible_require_function( $filename, &$template_processor, &$page_title )
  87. {
  88. require( $filename );
  89. }
  90.  
  91. public function getModuleInfo( $module_name = "" )
  92. {
  93. if ( empty( $module_name ) )
  94. {
  95. return $this->modules;
  96. }
  97. return isset( $this->modules[$module_name] ) ? $this->modules[$module_name] : false;
  98. }
  99.  
  100. public function getFunctionType( $module_name, $function_name )
  101. {
  102. if ( isset( $this->modules[$module_name]['functions'][$function_name] ) )
  103. {
  104. return $this->modules[$module_name]['functions'][$function_name]['type'];
  105. }
  106. }
  107.  
  108. public function getModuleClassesDir( $module_name )
  109. {
  110. return $this->modules[$module_name]['classes'];
  111. }
  112.  
  113. public function executeFunction( $module_name, $function_name, $parameters_override = array( ) )
  114. {
  115. if ( !$this->objectMotherCreated )
  116. {
  117. $this->appContext->createSingletonServiceByClassName( "ObjectMother" );
  118. $this->objectMotherCreated = true;
  119. }
  120. ob_start( );
  121. if ( $this->doesFunctionExist( $module_name, $function_name ) )
  122. {
  123. $script_filename = $this->getFunctionScriptFilename( $module_name, $function_name );
  124. if ( $script_filename != null && is_readable( $script_filename ) )
  125. {
  126. $this->prepareFunctionEnvironment( $parameters_override );
  127. $this->pushExecutionStack( $module_name, $function_name );
  128. require_once( $script_filename );
  129. $scriptClassName = $this->getFunctionScriptClassName( $module_name, $function_name );
  130. $script = $this->appContext->createContextAwareObjectOfClass( $scriptClassName );
  131. $script->respond( );
  132. $this->popExecutionStack( );
  133. $this->restoreEnvironment( );
  134. }
  135. else
  136. {
  137. return "<!-- Either wrong module/function or function script file does not exist for {$module_name}, {$function_name} -->";
  138. }
  139. }
  140. else
  141. {
  142. return "<!-- No such function or function is not accessible for {$module_name}, {$function_name} -->";
  143. }
  144. $content = ob_get_contents( );
  145. ob_end_clean( );
  146. return $content;
  147. }
  148.  
  149. public function getFunctionScriptClassName( $module_name, $function_name )
  150. {
  151. if ( isset( $this->modules[$module_name]['functions'][$function_name] ) )
  152. {
  153. return $this->modules[$module_name]['functions'][$function_name]['class'];
  154. }
  155. return null;
  156. }
  157.  
  158. public function getFunctionScriptFilename( $module_name, $function_name )
  159. {
  160. if ( isset( $this->modules[$module_name]['functions'][$function_name] ) )
  161. {
  162. $script_path = $this->modules[$module_name]['functions'][$function_name]['class'].".php";
  163. return $this->pathManager->getAbsoluteFunctionScriptPath( $module_name, $script_path );
  164. }
  165. return null;
  166. }
  167.  
  168. public function prepareFunctionEnvironment( $parameters )
  169. {
  170. array_push( $this->prev_requests, $_REQUEST );
  171. if ( is_array( $parameters ) )
  172. {
  173. foreach ( $parameters as $key => $value )
  174. {
  175. $_REQUEST[$key] = $value;
  176. }
  177. }
  178. }
  179.  
  180. public function getCurrentModuleAndFunction( )
  181. {
  182. return $this->getCurrentFunction( );
  183. }
  184.  
  185. public function restoreEnvironment( )
  186. {
  187. $c = count( $this->prev_requests );
  188. if ( 0 < $c )
  189. {
  190. $_REQUEST = array_pop( $this->prev_requests );
  191. }
  192. }
  193.  
  194. public function pushExecutionStack( $module_name, $function_name )
  195. {
  196. array_push( $this->call_stack, array(
  197. $module_name,
  198. $function_name
  199. ) );
  200. }
  201.  
  202. public function popExecutionStack( )
  203. {
  204. array_pop( $this->call_stack );
  205. }
  206.  
  207. public function getCurrentFunction( )
  208. {
  209. $c = count( $this->call_stack );
  210. if ( 0 < $c )
  211. {
  212. return $this->call_stack[$c - 1];
  213. }
  214. return null;
  215. }
  216.  
  217. public function setPageTitleOnce( $page_title )
  218. {
  219. if ( !isset( $GLOBALS['PAGE_TITLE'] ) && !empty( $page_title ) )
  220. {
  221. $GLOBALS['PAGE_TITLE'] = $page_title;
  222. }
  223. }
  224.  
  225. public function readModuleConfigs( )
  226. {
  227. if ( function_exists( "startupModules" ) )
  228. {
  229. startupModules( $this, $this->appContext );
  230. }
  231. if ( $dh = opendir( $this->pathManager->getAbsoluteModulesPath( ) ) )
  232. {
  233. while ( ( $module_name = readdir( $dh ) ) !== false )
  234. {
  235. $this->includeModule( $module_name );
  236. }
  237. closedir( $dh );
  238. }
  239. }
  240.  
  241. public function executeStartupScript( $module_name )
  242. {
  243. $module_startup_scripts = $this->getModuleSetting( $module_name, "startup_script" );
  244. if ( isset( $module_startup_scripts[$this->appContext->getSystemSettings( "SYSTEM_ACCESS_TYPE" )] ) )
  245. {
  246. $module_startup_script = $module_startup_scripts[$this->appContext->getSystemSettings( "SYSTEM_ACCESS_TYPE" )];
  247. }
  248. else
  249. {
  250. $module_startup_script = null;
  251. }
  252. if ( $module_startup_script != null )
  253. {
  254. $this->executeFunction( $module_name, $module_startup_script );
  255. }
  256. }
  257.  
  258. public function getModuleSetting( $module, $setting )
  259. {
  260. if ( isset( $this->modules[$module][$setting] ) )
  261. {
  262. return $this->modules[$module][$setting];
  263. }
  264. return null;
  265. }
  266.  
  267. public function doesFunctionHaveRawOutput( $module, $function )
  268. {
  269. if ( isset( $this->modules[$module], $this->modules[$module]['functions'][$function] ) )
  270. {
  271. if ( isset( $this->modules[$module]['functions'][$function]['raw_output'] ) )
  272. {
  273. return $this->modules[$module]['functions'][$function]['raw_output'];
  274. }
  275. return false;
  276. }
  277. return null;
  278. }
  279.  
  280. public function includeModule( $module_name )
  281. {
  282. if ( is_dir( $this->pathManager->getAbsoluteModulePath( $module_name ) ) && $module_name != "." && $module_name != ".." && is_readable( $this->pathManager->getAbsoluteModulePath( $module_name )."config.php" ) )
  283. {
  284. $this->module[$module_name] = require( $this->pathManager->getAbsoluteModulePath( $module_name )."config.php" );
  285. }
  286. }
  287.  
  288. public function getCommandScriptAbsolutePath( $module, $command )
  289. {
  290. $script_name = $this->_getCommandScriptName( $module, $command );
  291. if ( $script_name )
  292. {
  293. return $this->pathManager->getAbsoluteCommandsPath( $module ).$script_name;
  294. }
  295. }
  296.  
  297. public function startupModules( )
  298. {
  299. $this->modules =& $this->module;
  300. }
  301.  
  302. public function executeModulesStartupFunctions( )
  303. {
  304. foreach ( $this->modules as $module => $parameters )
  305. {
  306. $this->executeStartupScript( $module );
  307. }
  308. }
  309.  
  310. public function getModulesList( )
  311. {
  312. return array_keys( $this->modules );
  313. }
  314.  
  315. public function getFunctionsList( $module, $accessType )
  316. {
  317. $functionsList = array( );
  318. foreach ( $this->modules[$module]['functions'] as $functionName => $functionData )
  319. {
  320. if ( !isset( $functionData['type'] ) || $functionData['type'] == $accessType )
  321. {
  322. $functionsList[$functionName] = $functionData;
  323. }
  324. }
  325. return array_keys( $functionsList );
  326. }
  327.  
  328. public function getParamsList( $module, $function )
  329. {
  330. if ( isset( $this->modules[$module]['functions'][$function]['params'] ) )
  331. {
  332. return $this->modules[$module]['functions'][$function]['params'];
  333. }
  334. }
  335.  
  336. public function getRegisteredCommands( )
  337. {
  338. $commands = array( );
  339. foreach ( $this->modules as $module_name => $module )
  340. {
  341. if ( isset( $module['commands'] ) )
  342. {
  343. $commands = array_merge( $commands, $module['commands'] );
  344. }
  345. }
  346. return $commands;
  347. }
  348.  
  349. public function _getCommandScriptName( $module, $command )
  350. {
  351. if ( isset( $this->modules[$module]['commands'] ) )
  352. {
  353. foreach ( $this->modules[$module]['commands'] as $command_name => $command_info )
  354. {
  355. if ( !( strtolower( $command_name ) == strtolower( $command ) ) )
  356. {
  357. continue;
  358. }
  359. return $command_info['script'];
  360. }
  361. }
  362. return null;
  363. }
  364.  
  365. }
  366.  
  367. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement