Exemplo n.º 1
0
 public function __construct($config = array())
 {
     mimport('framework.error.profiler');
     // Set the view name.
     $this->_name = $this->getName();
     // Only set the clientId if available.
     if (isset($config['clientId'])) {
         $this->_clientId = $config['clientId'];
     } else {
         if (defined('DOING_AJAX')) {
             if (isset($_GET['client']) and $_GET['client'] == 'admin') {
                 $this->_clientId = 1;
             } else {
                 $this->_clientId = 0;
             }
             return;
         }
         if (is_admin()) {
             $this->_clientId = 1;
         } else {
             $this->_clientId = 0;
         }
     }
     // Enable sessions by default.
     if (!isset($config['session'])) {
         $config['session'] = true;
     }
     // Create the input object
     if (class_exists('MRequest')) {
         $this->input = new MRequest();
     }
     // Set the session default name.
     if (!isset($config['session_name'])) {
         $config['session_name'] = $this->_name;
     }
     // Set the default configuration file.
     if (!isset($config['config_file'])) {
         $config['config_file'] = 'config.php';
     }
     // Create the configuration object.
     if (file_exists(MPATH_CONFIGURATION . '/' . $config['config_file'])) {
         $this->_createConfiguration(MPATH_CONFIGURATION . '/' . $config['config_file']);
     }
     // Create the session if a session name is passed.
     // todo:: use php session
     if ($config['session'] !== false) {
         $this->_createSession(self::getHash($config['session_name']));
     }
     $this->requestTime = gmdate('Y-m-d H:i');
     // Used by task system to ensure that the system doesn't go over time.
     $this->startTime = MProfiler::getmicrotime();
 }
Exemplo n.º 2
0
 public static function renderModule($module, $attribs = array())
 {
     static $chrome;
     if (constant('MDEBUG')) {
         MProfiler::getInstance('Application')->mark('beforeRenderModule ' . $module->module . ' (' . $module->title . ')');
     }
     $app = MFactory::getApplication();
     // Record the scope.
     $scope = $app->scope;
     // Set scope to component name
     $app->scope = $module->module;
     // Get module parameters
     $params = new MRegistry();
     $params->loadString($module->params);
     // Get module path
     $module->module = preg_replace('/[^A-Z0-9_\\.-]/i', '', $module->module);
     $path = MPATH_MODULES . '/' . $module->module . '/' . $module->module . '.php';
     // Load the module
     // $module->user is a check for 1.0 custom modules and is deprecated refactoring
     if (empty($module->user) && file_exists($path)) {
         $lang = MFactory::getLanguage();
         // 1.5 or Core then 1.6 3PD
         $lang->load($module->module, MPATH_BASE, null, false, true) || $lang->load($module->module, dirname($path), null, false, true);
         $content = '';
         ob_start();
         include $path;
         $module->content = ob_get_contents() . $content;
         ob_end_clean();
     }
     // Load the module chrome functions
     if (!$chrome) {
         $chrome = array();
     }
     include_once MPATH_MODULES . '/modules.php';
     $chromePath = MPATH_THEMES . '/' . $app->getTemplate() . '/html/modules.php';
     if (!isset($chrome[$chromePath])) {
         if (file_exists($chromePath)) {
             include_once $chromePath;
         }
         $chrome[$chromePath] = true;
     }
     // Make sure a style is set
     if (!isset($attribs['style'])) {
         $attribs['style'] = 'none';
     }
     foreach (explode(' ', $attribs['style']) as $style) {
         $chromeMethod = 'modChrome_' . $style;
         // Apply chrome and render module
         if (function_exists($chromeMethod)) {
             $module->style = $attribs['style'];
             ob_start();
             $chromeMethod($module, $params, $attribs);
             $module->content = ob_get_contents();
             ob_end_clean();
         }
     }
     //revert the scope
     $app->scope = $scope;
     if (constant('MDEBUG')) {
         MProfiler::getInstance('Application')->mark('afterRenderModule ' . $module->module . ' (' . $module->title . ')');
     }
     return $module->content;
 }