Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- *
- * _____ _____ _ _____ _____ _____ _____ _____ _____
- * ___| | __ |_| _ |_ _|___ ___|_ _| __| _ | |
- * |_ -| --| -| | __| | | |- _|___| | | | __| | | | |
- * |___|_____|__|__|_|__| |_| |___| |_| |_____|__|__|_|_|_|
- * |s C R i P T z - T E A M . i N F O|
- *
- * This file was created by sCRiPTz-TEAM.iNFO [DEiONCUBE TEAM]
- * @ IonCube & Zend & NuSphere DeCoder
- *
- * @ Version : 1.0.0.3
- * @ Author : sCRiPTz-TEAM.iNFO
- * @ Released : 26-December-2011
- * @ Official site : http://sCRiPTz-TEAM.iNFO
- *
- */
- class ModuleManager implements IApplicationContextAware
- {
- private $appContext = NULL;
- public $modules = array( );
- public $call_stack = array( );
- public $prev_requests = array( );
- private $objectMotherCreated = false;
- private $pathManager = null;
- public function setAppContext( $appContext )
- {
- $this->appContext = $appContext;
- }
- public function setPathManager( $manager )
- {
- $this->pathManager = $manager;
- }
- public function init( )
- {
- $this->readModuleConfigs( );
- }
- public function getFunctionAccessSystem( $module_name, $function_name )
- {
- if ( isset( $this->modules[$module_name]['functions'][$function_name] ) )
- {
- if ( isset( $this->modules[$module_name]['functions'][$function_name]['system'] ) )
- {
- return $this->modules[$module_name]['functions'][$function_name]['system'];
- }
- return false;
- }
- }
- public function getModuleOfCommand( $command )
- {
- foreach ( $this->modules as $module_name => $module )
- {
- if ( isset( $module['commands'] ) )
- {
- foreach ( $module['commands'] as $command_name => $command_info )
- {
- if ( !( strtolower( $command ) == strtolower( $command_name ) ) )
- {
- continue;
- }
- return $module_name;
- }
- }
- }
- }
- public function doesModuleExists( $module_name )
- {
- return isset( $this->modules[$module_name] );
- }
- public function doesFunctionExist( $module, $function )
- {
- return isset( $this->modules[$module]['functions'][$function] );
- }
- public function old_scripts_compatible_require_function( $filename, &$template_processor, &$page_title )
- {
- require( $filename );
- }
- public function getModuleInfo( $module_name = "" )
- {
- if ( empty( $module_name ) )
- {
- return $this->modules;
- }
- return isset( $this->modules[$module_name] ) ? $this->modules[$module_name] : false;
- }
- public function getFunctionType( $module_name, $function_name )
- {
- if ( isset( $this->modules[$module_name]['functions'][$function_name] ) )
- {
- return $this->modules[$module_name]['functions'][$function_name]['type'];
- }
- }
- public function getModuleClassesDir( $module_name )
- {
- return $this->modules[$module_name]['classes'];
- }
- public function executeFunction( $module_name, $function_name, $parameters_override = array( ) )
- {
- if ( !$this->objectMotherCreated )
- {
- $this->appContext->createSingletonServiceByClassName( "ObjectMother" );
- $this->objectMotherCreated = true;
- }
- ob_start( );
- if ( $this->doesFunctionExist( $module_name, $function_name ) )
- {
- $script_filename = $this->getFunctionScriptFilename( $module_name, $function_name );
- if ( $script_filename != null && is_readable( $script_filename ) )
- {
- $this->prepareFunctionEnvironment( $parameters_override );
- $this->pushExecutionStack( $module_name, $function_name );
- require_once( $script_filename );
- $scriptClassName = $this->getFunctionScriptClassName( $module_name, $function_name );
- $script = $this->appContext->createContextAwareObjectOfClass( $scriptClassName );
- $script->respond( );
- $this->popExecutionStack( );
- $this->restoreEnvironment( );
- }
- else
- {
- return "<!-- Either wrong module/function or function script file does not exist for {$module_name}, {$function_name} -->";
- }
- }
- else
- {
- return "<!-- No such function or function is not accessible for {$module_name}, {$function_name} -->";
- }
- $content = ob_get_contents( );
- ob_end_clean( );
- return $content;
- }
- public function getFunctionScriptClassName( $module_name, $function_name )
- {
- if ( isset( $this->modules[$module_name]['functions'][$function_name] ) )
- {
- return $this->modules[$module_name]['functions'][$function_name]['class'];
- }
- return null;
- }
- public function getFunctionScriptFilename( $module_name, $function_name )
- {
- if ( isset( $this->modules[$module_name]['functions'][$function_name] ) )
- {
- $script_path = $this->modules[$module_name]['functions'][$function_name]['class'].".php";
- return $this->pathManager->getAbsoluteFunctionScriptPath( $module_name, $script_path );
- }
- return null;
- }
- public function prepareFunctionEnvironment( $parameters )
- {
- array_push( $this->prev_requests, $_REQUEST );
- if ( is_array( $parameters ) )
- {
- foreach ( $parameters as $key => $value )
- {
- $_REQUEST[$key] = $value;
- }
- }
- }
- public function getCurrentModuleAndFunction( )
- {
- return $this->getCurrentFunction( );
- }
- public function restoreEnvironment( )
- {
- $c = count( $this->prev_requests );
- if ( 0 < $c )
- {
- $_REQUEST = array_pop( $this->prev_requests );
- }
- }
- public function pushExecutionStack( $module_name, $function_name )
- {
- array_push( $this->call_stack, array(
- $module_name,
- $function_name
- ) );
- }
- public function popExecutionStack( )
- {
- array_pop( $this->call_stack );
- }
- public function getCurrentFunction( )
- {
- $c = count( $this->call_stack );
- if ( 0 < $c )
- {
- return $this->call_stack[$c - 1];
- }
- return null;
- }
- public function setPageTitleOnce( $page_title )
- {
- if ( !isset( $GLOBALS['PAGE_TITLE'] ) && !empty( $page_title ) )
- {
- $GLOBALS['PAGE_TITLE'] = $page_title;
- }
- }
- public function readModuleConfigs( )
- {
- if ( function_exists( "startupModules" ) )
- {
- startupModules( $this, $this->appContext );
- }
- if ( $dh = opendir( $this->pathManager->getAbsoluteModulesPath( ) ) )
- {
- while ( ( $module_name = readdir( $dh ) ) !== false )
- {
- $this->includeModule( $module_name );
- }
- closedir( $dh );
- }
- }
- public function executeStartupScript( $module_name )
- {
- $module_startup_scripts = $this->getModuleSetting( $module_name, "startup_script" );
- if ( isset( $module_startup_scripts[$this->appContext->getSystemSettings( "SYSTEM_ACCESS_TYPE" )] ) )
- {
- $module_startup_script = $module_startup_scripts[$this->appContext->getSystemSettings( "SYSTEM_ACCESS_TYPE" )];
- }
- else
- {
- $module_startup_script = null;
- }
- if ( $module_startup_script != null )
- {
- $this->executeFunction( $module_name, $module_startup_script );
- }
- }
- public function getModuleSetting( $module, $setting )
- {
- if ( isset( $this->modules[$module][$setting] ) )
- {
- return $this->modules[$module][$setting];
- }
- return null;
- }
- public function doesFunctionHaveRawOutput( $module, $function )
- {
- if ( isset( $this->modules[$module], $this->modules[$module]['functions'][$function] ) )
- {
- if ( isset( $this->modules[$module]['functions'][$function]['raw_output'] ) )
- {
- return $this->modules[$module]['functions'][$function]['raw_output'];
- }
- return false;
- }
- return null;
- }
- public function includeModule( $module_name )
- {
- if ( is_dir( $this->pathManager->getAbsoluteModulePath( $module_name ) ) && $module_name != "." && $module_name != ".." && is_readable( $this->pathManager->getAbsoluteModulePath( $module_name )."config.php" ) )
- {
- $this->module[$module_name] = require( $this->pathManager->getAbsoluteModulePath( $module_name )."config.php" );
- }
- }
- public function getCommandScriptAbsolutePath( $module, $command )
- {
- $script_name = $this->_getCommandScriptName( $module, $command );
- if ( $script_name )
- {
- return $this->pathManager->getAbsoluteCommandsPath( $module ).$script_name;
- }
- }
- public function startupModules( )
- {
- $this->modules =& $this->module;
- }
- public function executeModulesStartupFunctions( )
- {
- foreach ( $this->modules as $module => $parameters )
- {
- $this->executeStartupScript( $module );
- }
- }
- public function getModulesList( )
- {
- return array_keys( $this->modules );
- }
- public function getFunctionsList( $module, $accessType )
- {
- $functionsList = array( );
- foreach ( $this->modules[$module]['functions'] as $functionName => $functionData )
- {
- if ( !isset( $functionData['type'] ) || $functionData['type'] == $accessType )
- {
- $functionsList[$functionName] = $functionData;
- }
- }
- return array_keys( $functionsList );
- }
- public function getParamsList( $module, $function )
- {
- if ( isset( $this->modules[$module]['functions'][$function]['params'] ) )
- {
- return $this->modules[$module]['functions'][$function]['params'];
- }
- }
- public function getRegisteredCommands( )
- {
- $commands = array( );
- foreach ( $this->modules as $module_name => $module )
- {
- if ( isset( $module['commands'] ) )
- {
- $commands = array_merge( $commands, $module['commands'] );
- }
- }
- return $commands;
- }
- public function _getCommandScriptName( $module, $command )
- {
- if ( isset( $this->modules[$module]['commands'] ) )
- {
- foreach ( $this->modules[$module]['commands'] as $command_name => $command_info )
- {
- if ( !( strtolower( $command_name ) == strtolower( $command ) ) )
- {
- continue;
- }
- return $command_info['script'];
- }
- }
- return null;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement