示例#1
0
 /**
  * Instanciate the specified module
  */
 function &createInstanceOf($bundleId, $options = array(), $initArgs = array())
 {
     global $xoops;
     XOS::import('xoops_kernel_Module');
     // @TODO: This is lame and limited, whatever, should be arranged later
     if (!empty($bundleId)) {
         // Module ID specified: get its location from the registry
         if (!XOS::import($bundleId)) {
             trigger_error("Cannot instanciate unknown module " . $bundleId, E_USER_WARNING);
             return false;
         }
         $root = $xoops->path(XOS::classVar($bundleId, 'xoBundleRoot')) . '/';
     } else {
         $root = '';
     }
     $moduleInfo = @(include $root . 'xo-info.php');
     unset($moduleInfo['xoServices']);
     $options = array_merge($moduleInfo, $options);
     if (isset($moduleInfo['xoClassPath'])) {
         XOS::import($moduleInfo['xoBundleIdentifier']);
         $inst =& XOS::createInstanceOf($moduleInfo['xoBundleIdentifier'], $options);
     } else {
         $inst =& XOS::createInstanceOf('xoops_kernel_Module', $options);
     }
     $inst->xoBundleIdentifier = $moduleInfo['xoBundleIdentifier'];
     $inst->xoBundleRoot = XOS::classVar($inst->xoBundleIdentifier, 'xoBundleRoot');
     // If we are instanciating the "current" module, find the current location
     if ($inst && empty($bundleId)) {
         $moduleRoot = substr($inst->xoBundleRoot, 4);
         $scriptFile = substr(strstr($_SERVER['SCRIPT_NAME'], $moduleRoot), strlen($moduleRoot));
         $inst->currentLocation = $inst->findLocationName($scriptFile);
     }
     return $inst;
 }
示例#2
0
 /**
  * Instanciate the specified theme
  */
 function &createInstance($options = array(), $initArgs = array())
 {
     // Grab the theme folder from request vars if present
     if (@empty($options['folderName']) && ($req = @$_REQUEST['_xo_theme_name'])) {
         if ($this->isThemeAllowed($req)) {
             $options['folderName'] = $req;
             if (isset($_SESSION) && $this->allowUserSelection) {
                 $_SESSION[$this->xoBundleIdentifier]['defaultTheme'] = $req;
             }
         }
     } elseif (isset($_SESSION[$this->xoBundleIdentifier]['defaultTheme'])) {
         $options['folderName'] = $_SESSION[$this->xoBundleIdentifier]['defaultTheme'];
     } elseif (@empty($options['folderName']) || !$this->isThemeAllowed($options['folderName'])) {
         $options['folderName'] = $this->defaultTheme;
     }
     // Retrieve the desired content-type from the request
     if (@empty($options['contentType']) && !empty($_REQUEST['_xo_mime_type'])) {
         $options['contentType'] = $_REQUEST['_xo_mime_type'];
     }
     // Read the theme bundle info file
     global $xoops;
     $options['path'] = $xoops->path('/themes/' . $options['folderName']);
     if ($info = @(include $options['path'] . "/xo-info.php")) {
         $options = array_merge($info, $options);
     } else {
         $options['themeAPI'] = '2.0';
         $options['parentTheme'] = $options['folderName'] == 'xoops20' ? '' : 'xoops20';
     }
     $inst =& XOS::createInstanceOf('xoops_opal_Theme', $options);
     return $inst;
 }
示例#3
0
 /**
  * Instanciate the specified theme
  */
 function &createInstance($options = array(), $initArgs = array())
 {
     if (@empty($options['folderName'])) {
         $options['folderName'] = $this->defaultTheme;
     } elseif (!empty($this->allowedThemes) && !in_array($options['folderName'], $this->allowedThemes)) {
         $options['folderName'] = $this->defaultTheme;
     }
     $inst =& XOS::createInstanceOf("xoops_pyro_Theme", $options, $initArgs);
     return $inst;
 }
示例#4
0
 /**
  * Create an object instance
  * 
  * This function will delegate object instanciation to a local factory if one has been
  * specified. It is also able to handle singletons: when a singleton is requested
  * it will check if it has not been already created and return a reference to the already
  * existing instance if it has.
  */
 function &create($id, $options = null, $args = null)
 {
     $me =& $GLOBALS[EXXOS];
     $inst = false;
     if (is_array($id)) {
         @(list($id, $options, $initArgs) = $id);
     }
     if (isset($me->services[$id])) {
         return $me->services[$id];
     }
     XOS::import($id);
     if (isset($me->registry[$id])) {
         if (!isset($me->factories[$id]) && isset($me->registry[$id]['xoFactory'])) {
             $me->factories[$id] =& XOS::create($me->registry[$id]['xoFactory']);
             unset($me->registry[$id]['xoFactory']);
         }
         if (@is_object($me->factories[$id])) {
             if (method_exists($me->factories[$id], 'createInstanceOf')) {
                 $inst =& $me->factories[$id]->createInstanceOf($id, $options);
             } else {
                 $inst =& $me->factories[$id]->createInstance($options);
             }
         } else {
             $inst =& XOS::createInstanceOf($id, $options, $args);
         }
         if (is_object($inst)) {
             if (@$inst->xoSingleton) {
                 $me->services[$id] =& $inst;
                 if (!@empty($options['xoServiceName'])) {
                     $me->services[$options['xoServiceName']] =& $inst;
                 }
             }
         }
     }
     return $inst;
 }