Exemplo n.º 1
0
 /**
  * Add the appropriate view scripts directories for a given request.
  * This is pretty much the glue between the plugin broker and the
  * View object, since it uses data from the plugin broker to determine what
  * script paths will be available to the view.  
  * 
  * @param Zend_Controller_Request_Abstract $request Request object.
  * @return void
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     // Getting the module name from the request object is pretty much the main
     // reason why this needs to be in a controller plugin and can't be localized
     // to the view script.
     $moduleName = $request->getModuleName();
     $isPluginModule = !in_array($moduleName, array('default', null));
     $themeType = is_admin_theme() ? 'admin' : 'public';
     $pluginScriptDirs = $this->_pluginMvc->getViewScriptDirs($themeType);
     // Remove the current plugin, if any, from the set of "normal" plugin paths
     if ($isPluginModule && isset($pluginScriptDirs[$moduleName])) {
         $currentPluginScriptDirs = $pluginScriptDirs[$moduleName];
         unset($pluginScriptDirs[$moduleName]);
     }
     // Add all the "normal" plugin paths
     foreach ($pluginScriptDirs as $modulePaths) {
         $this->_addPathsToView($modulePaths);
     }
     // Add the theme and core paths
     $this->_addThemePaths($themeType);
     // Add plugin and theme-override paths for current plugin
     if ($isPluginModule) {
         if (isset($currentPluginScriptDirs)) {
             $this->_addPathsToView($currentPluginScriptDirs);
         }
         $this->_addOverridePathForPlugin($themeType, $moduleName);
     }
 }
Exemplo n.º 2
0
 /**
  * Add asset paths for a plugin.
  * 
  * @param string $pluginModuleName The module name for the plugin.
  * @param string $themeType The type of theme: 'admin' or 'public'.
  * @return void
  */
 protected function _addPluginPaths($themeType, $pluginModuleName = null)
 {
     // If we have chosen a specific module to add paths for.
     if ($pluginModuleName) {
         // We need to add the scripts in reverse order if how they will be found.
         // add the scripts from the other modules
         $otherPluginScriptDirs = $this->_pluginMvc->getModuleViewScriptDirs(null);
         foreach ($otherPluginScriptDirs as $otherPluginModuleName => $scriptPathSet) {
             if ($otherPluginModuleName != $pluginModuleName && isset($scriptPathSet[$themeType])) {
                 foreach ($scriptPathSet[$themeType] as $scriptPath) {
                     $this->_addPathToView($scriptPath);
                 }
             }
         }
         // add the scripts from the first module
         $pluginScriptDirs = $this->_pluginMvc->getModuleViewScriptDirs($pluginModuleName);
         if (isset($pluginScriptDirs[$themeType])) {
             foreach ($pluginScriptDirs[$themeType] as $scriptPath) {
                 $this->_addPathToView($scriptPath);
             }
         }
         // Adds plugin-specific scripts for themes (these take precedence over everything)
         $this->_addOverridePathForPlugin($themeType, $pluginModuleName);
     } else {
         // We have not chosen a specific module to add paths for, so just add
         // them all (for the specific theme type, 'admin' or 'public').
         $pluginScriptDirs = $this->_pluginMvc->getModuleViewScriptDirs(null);
         foreach ($pluginScriptDirs as $moduleName => $scriptPathSet) {
             if (array_key_exists($themeType, $scriptPathSet)) {
                 foreach ($scriptPathSet[$themeType] as $scriptPath) {
                     $this->_addPathToView($scriptPath);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Load a plugin (and make sure the plugin API is available).
  * 
  * To be loaded, the plugin must be installed, active, and not have a newer 
  * version. If loaded, the plugin will attempt to first load all plugins, 
  * both required and optional, that the plugin uses.  However, it will not 
  * load a plugin that it uses if that plugin is not installed and activated.
  * 
  * @param Plugin $plugin
  * @param boolean $force If true, throws exceptions if a plugin can't be 
  * loaded.
  * @param array $pluginsWaitingToLoad Plugins waiting to be loaded
  * @throws Omeka_Plugin_Loader_Exception
  * @return void
  */
 public function load(Plugin $plugin, $force = false, $pluginsWaitingToLoad = array())
 {
     $this->registerPlugin($plugin);
     $this->_iniReader->load($plugin);
     $pluginDirName = $plugin->getDirectoryName();
     if (!$this->_canLoad($plugin, $force)) {
         if ($force) {
             throw new Omeka_Plugin_Loader_Exception(__("The %s plugin could not be loaded.", $pluginDirName));
         } else {
             return;
         }
     }
     // If the current plugin is already on the waiting list, don't load it.
     if (array_key_exists(spl_object_hash($plugin), $pluginsWaitingToLoad)) {
         return;
     } else {
         // Otherwise add the current plugin to the waiting list.
         $pluginsWaitingToLoad[spl_object_hash($plugin)] = $plugin;
     }
     // Load the required plugins
     $requiredPluginDirNames = $plugin->getRequiredPlugins();
     foreach ($requiredPluginDirNames as $requiredPluginDirName) {
         if (!($requiredPlugin = $this->getPlugin($requiredPluginDirName))) {
             // If we can't find one of the required plugins, loading should
             // fail.
             if ($force) {
                 throw new Omeka_Plugin_Loader_Exception(__("The required plugin '%s' could not be found.", $requiredPluginDirName));
             } else {
                 return;
             }
         }
         // If the required plugin is already loaded, do not attempt to load
         // it a second time.
         if ($requiredPlugin->isLoaded()) {
             continue;
         }
         $this->load($requiredPlugin, $force, $pluginsWaitingToLoad);
         // make sure the required plugin is loaded.
         // if a required plugin of the plugin cannot be loaded,
         // then do not load the plugin
         if (!$requiredPlugin->isLoaded()) {
             return;
         }
     }
     // Load the optional plugins
     $optionalPluginDirNames = $plugin->getOptionalPlugins();
     foreach ($optionalPluginDirNames as $optionalPluginDirName) {
         if (!($optionalPlugin = $this->getPlugin($optionalPluginDirName))) {
             // If we can't find one of the optional plugins, it should skip it and try to load the next one.
             continue;
         }
         // If the optional plugin is already loaded, do not attempt to load
         // it a second time.
         if ($optionalPlugin->isLoaded()) {
             continue;
         }
         // If the optional plugin cannot load, then fail silently
         $this->load($optionalPlugin, false, $pluginsWaitingToLoad);
     }
     // add the plugin dir paths and require the plugin files
     $this->_mvc->addApplicationDirs($pluginDirName);
     $this->_loadPluginBootstrap($plugin);
     // This won't work unless the plugin has already been loaded.
     $plugin->setHasConfig((bool) $this->_broker->getHook($plugin->getDirectoryName(), 'config'));
     // remember that the plugin is loaded
     $plugin->setLoaded(true);
 }