The {@link AddonManager} scans directories for addon folders and then maintains them in a catalogue. Addons can then be started which makes them available to the application. When an addon is started it can do the following: - Any classes the addon has declared are available via the {@link AddonManager::autoload()} method. - The addon can declare a class ending in "Plugin" and its events will be registered (TODO). - Any translations the addon has declared will be loaded for the currently enabled locale.
 /**
  * Define the permissions for an application.
  *
  * @param string $applicationName The name of the application.
  */
 public function registerPermissions($applicationName)
 {
     $addon = $this->addonManager->lookupAddon($applicationName);
     if ($permissions = $addon->getInfoValue('registerPermissions')) {
         Gdn::permissionModel()->define($permissions);
     }
 }
Example #2
0
 /**
  * Test a theme for dependencies and parse errors.
  *
  * @param string $themeName The case-sensitive theme name.
  * @return bool Returns
  * @throws Gdn_UserException Throws an exception when there was an issue testing the theme.
  */
 public function testTheme($themeName)
 {
     $addon = $this->addonManager->lookupTheme($themeName);
     if (!$addon) {
         throw notFoundException('Plugin');
     }
     try {
         $this->addonManager->checkRequirements($addon, true);
         $addon->test(true);
     } catch (\Exception $ex) {
         throw new Gdn_UserException($ex->getMessage(), $ex->getCode());
     }
     return true;
 }
Example #3
0
 /**
  * Enable an addon and do all the stuff that's entailed there.
  *
  * @param Addon $addon The addon to enable.
  * @param bool $setup Whether or not to set the plugin up.
  * @throws Exception Throws an exception if something goes bonkers during the process.
  */
 private function enableAddon(Addon $addon, $setup)
 {
     if ($setup) {
         $this->addonManager->startAddon($addon);
         $this->pluginHook($addon->getRawKey(), self::ACTION_ENABLE, true);
         // If setup succeeded, register any specified permissions
         $permissions = $addon->getInfoValue('registerPermissions');
         if (!empty($permissions)) {
             $PermissionModel = Gdn::permissionModel();
             $PermissionModel->define($permissions);
         }
         // Write enabled state to config.
         saveToConfig("EnabledPlugins." . $addon->getRawKey(), true);
         Logger::event('addon_enabled', Logger::INFO, 'The {addonName} plugin was enabled.', array('addonName' => $addon->getRawKey()));
     }
     $pluginClassName = $addon->getPluginClass();
     $this->registerPlugin($pluginClassName);
 }
Example #4
0
 /**
  * Returns the name of the enabled application based on $ApplicationFolder.
  *
  * @param string The application folder related to the application name you want to return.
  */
 public function enabledApplication($folder = '')
 {
     if ($folder == '') {
         $folder = $this->applicationFolder;
     }
     if (strpos($folder, 'plugins/') === 0) {
         $plugin = StringBeginsWith($folder, 'plugins/', false, true);
         if (array_key_exists($plugin, $this->addonManager->getEnabled())) {
             return $plugin;
         }
         return false;
     } else {
         $addon = $this->addonManager->lookupAddon($folder);
         if ($addon) {
             return $addon->getRawKey();
         }
     }
     return false;
 }
Example #5
0
 /**
  * Gets the locale sources for a given locale.
  *
  * @param string $locale The name of the locale.
  * @return array Returns an array of paths to the translations for the locale.
  * @deprecated Use the {@link AddonManager} for this.
  */
 public function getLocaleSources($locale)
 {
     deprecated('Gdn_PluginManager->getLocaleSources()', 'AddonManager->getEnabledLocaleSources()');
     $result = $this->addonManager->getEnabledTranslationPaths($locale);
     return $result;
 }