public function Structure($AppName = 'all', $CaptureOnly = '1', $Drop = '0', $Explicit = '0') { $this->Permission('Garden.AdminUser.Only'); $Files = array(); $AppName = $AppName == '' ? 'all' : $AppName; if ($AppName == 'all') { // Load all application structure files. $ApplicationManager = new Gdn_ApplicationManager(); $Apps = $ApplicationManager->EnabledApplications(); $AppNames = ConsolidateArrayValuesByKey($Apps, 'Folder'); foreach ($AppNames as $AppName) { $Files[] = CombinePaths(array(PATH_APPLICATIONS, $AppName, 'settings', 'structure.php'), DS); } $AppName = 'all'; } else { // Load that specific application structure file. $Files[] = CombinePaths(array(PATH_APPLICATIONS, $AppName, 'settings', 'structure.php'), DS); } $Validation = new Gdn_Validation(); $Database = Gdn::Database(); $Drop = $Drop == '0' ? FALSE : TRUE; $Explicit = $Explicit == '0' ? FALSE : TRUE; $CaptureOnly = !($CaptureOnly == '0'); $Structure = Gdn::Structure(); $Structure->CaptureOnly = $CaptureOnly; $SQL = Gdn::SQL(); $SQL->CaptureModifications = $CaptureOnly; $this->SetData('CaptureOnly', $Structure->CaptureOnly); $this->SetData('Drop', $Drop); $this->SetData('Explicit', $Explicit); $this->SetData('ApplicationName', $AppName); $this->SetData('Status', ''); $FoundStructureFile = FALSE; foreach ($Files as $File) { if (file_exists($File)) { $FoundStructureFile = TRUE; try { include $File; } catch (Exception $Ex) { $this->Form->AddError($Ex); } } if (property_exists($Structure->Database, 'CapturedSql')) { $this->SetData('CapturedSql', (array) $Structure->Database->CapturedSql); } else { $this->SetData('CapturedSql', array()); } } if ($this->Form->ErrorCount() == 0 && !$CaptureOnly && $FoundStructureFile) { $this->SetData('Status', 'The structure was successfully executed.'); } $this->AddSideMenu('dashboard/settings/configure'); $this->AddCssFile('admin.css'); $this->SetData('Title', T('Database Structure Upgrades')); $this->Render(); }
public function EnableTheme($ThemeName) { // 1. Make sure that the theme's requirements are met $ApplicationManager = new Gdn_ApplicationManager(); $EnabledApplications = $ApplicationManager->EnabledApplications(); $AvailableThemes = $this->AvailableThemes(); $NewThemeInfo = ArrayValue($ThemeName, $AvailableThemes, array()); $RequiredApplications = ArrayValue('RequiredApplications', $NewThemeInfo, FALSE); CheckRequirements($ThemeName, $RequiredApplications, $EnabledApplications, 'application'); // Applications // 5. Set the theme $ThemeFolder = ArrayValue('Folder', $NewThemeInfo, ''); if ($ThemeFolder == '') { throw new Exception(Gdn::Translate('The theme folder was not properly defined.')); } else { SaveToConfig('Garden.Theme', $ThemeFolder); } return TRUE; }
/** * * * @param null $AddonCode * @param bool $Explicit * @param bool $Drop * @throws Exception */ public function runStructure($AddonCode = null, $Explicit = false, $Drop = false) { // Get the structure files for all of the enabled applications. $ApplicationManager = new Gdn_ApplicationManager(); $Apps = $ApplicationManager->EnabledApplications(); $AppNames = consolidateArrayValuesByKey($Apps, 'Folder'); $Paths = array(); foreach ($Apps as $Key => $AppInfo) { $Path = PATH_APPLICATIONS . "/{$AppInfo['Folder']}/settings/structure.php"; if (file_exists($Path)) { $Paths[] = $Path; } Gdn::ApplicationManager()->RegisterPermissions($Key, $this->Validation); } // Execute the structures. $Database = Gdn::database(); $SQL = Gdn::sql(); $Structure = Gdn::structure(); foreach ($Paths as $Path) { include $Path; } // Execute the structures for all of the plugins. $PluginManager = Gdn::pluginManager(); $Registered = $PluginManager->RegisteredPlugins(); foreach ($Registered as $ClassName => $Enabled) { if (!$Enabled) { continue; } try { $Plugin = $PluginManager->GetPluginInstance($ClassName, Gdn_PluginManager::ACCESS_CLASSNAME); if (method_exists($Plugin, 'Structure')) { trace("{$ClassName}->Structure()"); $Plugin->Structure(); } } catch (Exception $Ex) { // Do nothing, plugin wouldn't load/structure. if (Debug()) { throw $Ex; } } } $this->fireEvent('AfterStructure'); }
public function TestTheme($ThemeName) { // Get some info about the currently enabled theme. $EnabledTheme = $this->EnabledThemeInfo(); $EnabledThemeFolder = GetValue('Folder', $EnabledTheme, ''); $OldClassName = $EnabledThemeFolder . 'ThemeHooks'; // Make sure that the theme's requirements are met $ApplicationManager = new Gdn_ApplicationManager(); $EnabledApplications = $ApplicationManager->EnabledApplications(); $NewThemeInfo = $this->GetThemeInfo($ThemeName); $ThemeName = GetValue('Index', $NewThemeInfo, $ThemeName); $RequiredApplications = ArrayValue('RequiredApplications', $NewThemeInfo, FALSE); $ThemeFolder = ArrayValue('Folder', $NewThemeInfo, ''); CheckRequirements($ThemeName, $RequiredApplications, $EnabledApplications, 'application'); // Applications // If there is a hooks file, include it and run the setup method. $ClassName = "{$ThemeFolder}ThemeHooks"; $HooksFile = GetValue("HooksFile", $NewThemeInfo, NULL); if (!is_null($HooksFile) && file_exists($HooksFile)) { include_once $HooksFile; if (class_exists($ClassName)) { $ThemeHooks = new $ClassName(); $ThemeHooks->Setup(); } } // If there is a hooks in the old theme, include it and run the ondisable method. if (class_exists($OldClassName)) { $ThemeHooks = new $OldClassName(); if (method_exists($ThemeHooks, 'OnDisable')) { $ThemeHooks->OnDisable(); } } return TRUE; }
public function RunStructure($AddonCode = NULL, $Explicit = FALSE, $Drop = FALSE) { // Get the structure files for all of the enabled applications. $ApplicationManager = new Gdn_ApplicationManager(); $Apps = $ApplicationManager->EnabledApplications(); $AppNames = ConsolidateArrayValuesByKey($Apps, 'Folder'); $Paths = array(); foreach ($Apps as $AppInfo) { $Path = PATH_APPLICATIONS . "/{$AppInfo['Folder']}/settings/structure.php"; if (file_exists($Path)) { $Paths[] = $Path; } } // Execute the structures. $Database = Gdn::Database(); $SQL = Gdn::SQL(); $Structure = Gdn::Structure(); foreach ($Paths as $Path) { include $Path; } // Execute the structures for all of the plugins. $PluginManager = Gdn::PluginManager(); $Registered = $PluginManager->RegisteredPlugins(); foreach ($Registered as $ClassName => $Enabled) { if (!$Enabled) { continue; } try { $Plugin = $PluginManager->GetPluginInstance($ClassName, Gdn_PluginManager::ACCESS_CLASSNAME); if (method_exists($Plugin, 'Structure')) { Trace("{$ClassName}->Structure()"); $Plugin->Structure(); } } catch (Exception $Ex) { // Do nothing, plugin wouldn't load/structure. } } }
public function RunStructure($AddonCode = NULL, $Explicit = FALSE, $Drop = FALSE) { // Get the structure files for all of the enabled applications. $ApplicationManager = new Gdn_ApplicationManager(); $Apps = $ApplicationManager->EnabledApplications(); $AppNames = ConsolidateArrayValuesByKey($Apps, 'Folder'); $Paths = array(); foreach ($Apps as $AppInfo) { $Path = PATH_APPLICATIONS . "/{$AppInfo['Folder']}/settings/structure.php"; if (file_exists($Path)) { $Paths[] = $Path; } } // Execute the structures. $Database = Gdn::Database(); $SQL = Gdn::SQL(); $Structure = Gdn::Structure(); foreach ($Paths as $Path) { include $Path; } // Execute the structures for all of the plugins. $PluginManager = Gdn::PluginManager(); $Plugins = $PluginManager->EnabledPlugins(); foreach ($Plugins as $Key => $PluginInfo) { $PluginName = GetValue('Index', $PluginInfo); $Plugin = $PluginManager->GetPluginInstance($PluginName, Gdn_PluginManager::ACCESS_PLUGINNAME); if (method_exists($Plugin, 'Structure')) { $Plugin->Structure(); } } }
/** * Returns a complete list of all enabled applications & plugins. This list * can act as a namespace list for permissions. * @return array */ public function GetAllowedPermissionNamespaces() { $ApplicationManager = new Gdn_ApplicationManager(); $EnabledApplications = $ApplicationManager->EnabledApplications(); $PluginNamespaces = array(); foreach (Gdn::PluginManager()->EnabledPlugins() as $Plugin) { if (!array_key_exists('RegisterPermissions', $Plugin) || !is_array($Plugin['RegisterPermissions'])) { continue; } foreach ($Plugin['RegisterPermissions'] as $Index => $PermissionName) { if (is_string($Index)) { $PermissionName = $Index; } $Namespace = substr($PermissionName, 0, strrpos($PermissionName, '.')); $PluginNamespaces[$Namespace] = TRUE; } } $Result = array_merge(array_keys($EnabledApplications), array_keys($PluginNamespaces)); if (in_array('Dashboard', $Result)) { $Result[] = 'Garden'; } return $Result; }
/** * Test to see if a plugin throws fatal errors. */ public function TestPlugin($PluginName, &$Validation, $Setup = FALSE) { // Make sure that the plugin's requirements are met // Required Plugins $AvailablePlugins = $this->AvailablePlugins(); $RequiredPlugins = ArrayValue('RequiredPlugins', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredPlugins, $this->EnabledPlugins, 'plugin'); // Required Themes $ThemeManager = new Gdn_ThemeManager(); $EnabledThemes = $ThemeManager->EnabledThemeInfo(TRUE); $RequiredThemes = ArrayValue('RequiredTheme', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredThemes, $EnabledThemes, 'theme'); // Required Applications $ApplicationManager = new Gdn_ApplicationManager(); $EnabledApplications = $ApplicationManager->EnabledApplications(); $RequiredApplications = ArrayValue('RequiredApplications', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredApplications, $EnabledApplications, 'application'); // Include the plugin, instantiate it, and call its setup method $PluginInfo = ArrayValue($PluginName, $AvailablePlugins, FALSE); $PluginClassName = ArrayValue('ClassName', $PluginInfo, FALSE); $PluginFolder = ArrayValue('Folder', $PluginInfo, FALSE); if ($PluginFolder == '') { throw new Exception(T('The plugin folder was not properly defined.')); } $this->_PluginHook($PluginName, self::ACTION_ENABLE, $Setup); // If setup succeeded, register any specified permissions $PermissionName = ArrayValue('RegisterPermissions', $PluginInfo, FALSE); if ($PermissionName != FALSE) { $PermissionModel = Gdn::PermissionModel(); $PermissionModel->Define($PermissionName); } return TRUE; }
public function EnablePlugin($PluginName, $Validation, $Setup = FALSE) { // 1. Make sure that the plugin's requirements are met // Required Plugins $AvailablePlugins = $this->AvailablePlugins(); $RequiredPlugins = ArrayValue('RequiredPlugins', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredPlugins, $this->EnabledPlugins, 'plugin'); // Required Themes $ThemeManager = new Gdn_ThemeManager(); $EnabledThemes = $ThemeManager->EnabledThemeInfo(); $RequiredThemes = ArrayValue('RequiredTheme', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredThemes, $EnabledThemes, 'theme'); // Required Applications $ApplicationManager = new Gdn_ApplicationManager(); $EnabledApplications = $ApplicationManager->EnabledApplications(); $RequiredApplications = ArrayValue('RequiredApplications', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredApplications, $EnabledApplications, 'application'); // 2. Include the plugin, instantiate it, and call its setup method $PluginInfo = ArrayValue($PluginName, $AvailablePlugins, FALSE); $PluginFolder = ArrayValue('Folder', $PluginInfo, FALSE); if ($PluginFolder == '') { throw new Exception(Gdn::Translate('The plugin folder was not properly defined.')); } $this->_PluginHook($PluginName, self::ACTION_ENABLE, $Setup); // 3. If setup succeeded, register any specified permissions $PermissionName = ArrayValue('RegisterPermissions', $PluginInfo, FALSE); if ($PermissionName != FALSE) { $PermissionModel = Gdn::PermissionModel(); $PermissionModel->Define($PermissionName); } if (is_object($Validation) && count($Validation->Results()) > 0) { return FALSE; } // 4. If everything succeeded, add the plugin to the // $EnabledPlugins array in conf/plugins.php // $EnabledPlugins['PluginClassName'] = 'Plugin Folder Name'; SaveToConfig('EnabledPlugins' . '.' . $PluginName, $PluginFolder); $ApplicationManager = new Gdn_ApplicationManager(); $Locale = Gdn::Locale(); $Locale->Set($Locale->Current(), $ApplicationManager->EnabledApplicationFolders(), $this->EnabledPluginFolders(), TRUE); return TRUE; }
public function TestTheme($ThemeName) { // Get some info about the currently enabled theme. $EnabledTheme = $this->EnabledThemeInfo(); $EnabledThemeFolder = GetValue('Folder', $EnabledTheme, ''); $OldClassName = $EnabledThemeFolder . 'ThemeHooks'; // Make sure that the theme's requirements are met $ApplicationManager = new Gdn_ApplicationManager(); $EnabledApplications = $ApplicationManager->EnabledApplications(); $AvailableThemes = $this->AvailableThemes(); $NewThemeInfo = ArrayValue($ThemeName, $AvailableThemes, array()); $RequiredApplications = ArrayValue('RequiredApplications', $NewThemeInfo, FALSE); $ThemeFolder = ArrayValue('Folder', $NewThemeInfo, ''); CheckRequirements($ThemeName, $RequiredApplications, $EnabledApplications, 'application'); // Applications // If there is a hooks file, include it and run the setup method. $ClassName = $ThemeFolder . 'ThemeHooks'; $HooksFile = PATH_THEMES . DS . $ThemeFolder . DS . 'class.' . strtolower($ClassName) . '.php'; if (file_exists($HooksFile)) { include $HooksFile; if (class_exists($ClassName)) { $ThemeHooks = new $ClassName(); $ThemeHooks->Setup(); } } // If there is a hooks in the old theme, include it and run the ondisable method. if (class_exists($OldClassName)) { $ThemeHooks = new $OldClassName(); $ThemeHooks->OnDisable(); } return TRUE; }
function GetApplicationMenus(&$Menu) { $ApplicationManager = new Gdn_ApplicationManager(); $EnabledApplications = $ApplicationManager->EnabledApplications(); // Get all settings pages from the specified applications: foreach ($EnabledApplications as $ApplicationName => $ApplicationFolder) { $AppController = $ApplicationName . 'Controller'; // Attempt to include the app controller if it isn't already loaded $ControllerPath = PATH_APPLICATIONS . DS . $ApplicationFolder . DS . 'controllers' . DS . 'appcontroller.php'; if (!class_exists($AppController) && file_exists($ControllerPath)) { include_once $ControllerPath; } // Attempt to instantiate the app controller to get the settings pages if (class_exists($AppController)) { $AppController = new $AppController(); if (method_exists($AppController, 'GetSettingsPages')) { $AppController->GetSettingsPages($Menu); } } } // Get all settings pages from plugins $Plugins = array(); $PluginManager = Gdn::Factory('PluginManager'); $PluginMenuAdded = FALSE; foreach ($PluginManager->EnabledPlugins as $PluginName => $PluginInfo) { if (array_key_exists('SettingsUrl', $PluginInfo)) { if (!$PluginMenuAdded) { $Menu->AddItem('Plugins', 'Plugins'); $PluginMenuAdded = TRUE; } // TODO: DOES A PERMISSION NEED TO APPLY TO THE PLUGIN SETTINGS URL? $Menu->AddLink('Plugins', $PluginName, ArrayValue('SettingsUrl', $PluginInfo, '')); } } }
public function GetAddons($Enabled = FALSE) { $Addons = array(); // Get the core. self::_AddAddon(array('AddonKey' => 'vanilla', 'AddonType' => 'core', 'Version' => APPLICATION_VERSION, 'Folder' => '/'), $Addons); // Get a list of all of the applications. $ApplicationManager = new Gdn_ApplicationManager(); if ($Enabled) { $Applications = $ApplicationManager->AvailableApplications(); } else { $Applications = $ApplicationManager->EnabledApplications(); } foreach ($Applications as $Key => $Info) { // Exclude core applications. if (in_array(strtolower($Key), array('conversations', 'dashboard', 'skeleton', 'vanilla'))) { continue; } $Addon = array('AddonKey' => $Key, 'AddonType' => 'application', 'Version' => GetValue('Version', $Info, '0.0'), 'Folder' => '/applications/' . GetValue('Folder', $Info, strtolower($Key))); self::_AddAddon($Addon, $Addons); } // Get a list of all of the plugins. $PluginManager = Gdn::PluginManager(); if ($Enabled) { $Plugins = $PluginManager->EnabledPlugins(); } else { $Plugins = $PluginManager->AvailablePlugins(); } foreach ($Plugins as $Key => $Info) { // Exclude core plugins. if (in_array(strtolower($Key), array())) { continue; } $Addon = array('AddonKey' => $Key, 'AddonType' => 'plugin', 'Version' => GetValue('Version', $Info, '0.0'), 'Folder' => '/applications/' . GetValue('Folder', $Info, $Key)); self::_AddAddon($Addon, $Addons); } // Get a list of all the themes. $ThemeManager = new Gdn_ThemeManager(); if ($Enabled) { $Themes = $ThemeManager->EnabledThemeInfo(TRUE); } else { $Themes = $ThemeManager->AvailableThemes(); } foreach ($Themes as $Key => $Info) { // Exclude core themes. if (in_array(strtolower($Key), array('default'))) { continue; } $Addon = array('AddonKey' => $Key, 'AddonType' => 'theme', 'Version' => GetValue('Version', $Info, '0.0'), 'Folder' => '/themes/' . GetValue('Folder', $Info, $Key)); self::_AddAddon($Addon, $Addons); } // Get a list of all locales. $LocaleModel = new LocaleModel(); if ($Enabled) { $Locales = $LocaleModel->EnabledLocalePacks(TRUE); } else { $Locales = $LocaleModel->AvailableLocalePacks(); } foreach ($Locales as $Key => $Info) { // Exclude core themes. if (in_array(strtolower($Key), array('skeleton'))) { continue; } $Addon = array('AddonKey' => $Key, 'AddonType' => 'locale', 'Version' => GetValue('Version', $Info, '0.0'), 'Folder' => '/locales/' . GetValue('Folder', $Info, $Key)); self::_AddAddon($Addon, $Addons); } return $Addons; }
/** * Returns a complete list of all enabled applications & plugins. This list * can act as a namespace list for permissions. * @return array */ public function GetAllowedPermissionNamespaces() { $ApplicationManager = new Gdn_ApplicationManager(); $EnabledApplications = $ApplicationManager->EnabledApplications(); $PluginManager = Gdn::Factory('PluginManager'); $PluginNamespaces = array(); foreach ($PluginManager->EnabledPlugins as $Plugin) { if (!array_key_exists('RegisterPermissions', $Plugin) || !is_array($Plugin['RegisterPermissions'])) { continue; } foreach ($Plugin['RegisterPermissions'] as $PermissionName) { $Namespace = substr($PermissionName, 0, strrpos($PermissionName, '.')); $PluginNamespaces[$Namespace] = TRUE; } } return array_merge(array_keys($EnabledApplications), array_keys($PluginNamespaces)); }
public function EnablePlugin($PluginName, $Validation, $Setup = FALSE) { // 1. Make sure that the plugin's requirements are met // Required Plugins $AvailablePlugins = $this->AvailablePlugins(); $RequiredPlugins = ArrayValue('RequiredPlugins', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredPlugins, $this->EnabledPlugins, 'plugin'); // Required Themes $ThemeManager = new Gdn_ThemeManager(); $EnabledThemes = $ThemeManager->EnabledThemeInfo(); $RequiredThemes = ArrayValue('RequiredTheme', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredThemes, $EnabledThemes, 'theme'); // Required Applications $ApplicationManager = new Gdn_ApplicationManager(); $EnabledApplications = $ApplicationManager->EnabledApplications(); $RequiredApplications = ArrayValue('RequiredApplications', ArrayValue($PluginName, $AvailablePlugins, array()), FALSE); CheckRequirements($PluginName, $RequiredApplications, $EnabledApplications, 'application'); // 2. Include the plugin, instantiate it, and call it's setup method $PluginInfo = ArrayValue($PluginName, $AvailablePlugins, FALSE); $PluginFolder = ArrayValue('Folder', $PluginInfo, FALSE); if ($PluginFolder == '') { throw new Exception(Gdn::Translate('The plugin folder was not properly defined.')); } $PluginClassName = ArrayValue('ClassName', $PluginInfo, FALSE); if ($PluginFolder !== FALSE && $PluginClassName !== FALSE && class_exists($PluginClassName) === FALSE) { $this->IncludePlugins(array($PluginName => $PluginFolder)); if (class_exists($PluginClassName)) { $Plugin = new $PluginClassName(); $Plugin->Setup(); } } elseif (class_exists($PluginClassName, FALSE) !== FALSE && $Setup === TRUE) { $Plugin = new $PluginClassName(); $Plugin->Setup(); } // 3. If setup succeeded, register any specified permissions $PermissionName = ArrayValue('RegisterPermissions', $PluginInfo, FALSE); if ($PermissionName != FALSE) { $PermissionModel = Gdn::PermissionModel(); $PermissionModel->Define($PermissionName); } if (is_object($Validation) && count($Validation->Results()) > 0) { return FALSE; } // 4. If everything succeeded, add the plugin to the // $EnabledPlugins array in conf/plugins.php // $EnabledPlugins['PluginClassName'] = 'Plugin Folder Name'; $Config = Gdn::Factory(Gdn::AliasConfig); $Config->Load(PATH_CONF . DS . 'config.php', 'Save'); $Config->Set('EnabledPlugins' . '.' . $PluginName, $PluginFolder); $Config->Save(); $ApplicationManager = new Gdn_ApplicationManager(); $Locale = Gdn::Locale(); $Locale->Set($Locale->Current(), $ApplicationManager->EnabledApplicationFolders(), $this->EnabledPluginFolders(), TRUE); return TRUE; }