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();
 }
 /**
  * Application management screen.
  *
  * @since 2.0.0
  * @access public
  * @param string $Filter 'enabled', 'disabled', or 'all' (default)
  * @param string $ApplicationName Unique ID of app to be modified.
  * @param string $TransientKey Security token.
  */
 public function applications($Filter = '', $ApplicationName = '', $TransientKey = '')
 {
     $this->permission('Garden.Settings.Manage');
     // Page setup
     $this->addJsFile('addons.js');
     $this->addJsFile('applications.js');
     $this->title(t('Applications'));
     $this->addSideMenu('dashboard/settings/applications');
     // Validate & set parameters
     $Session = Gdn::session();
     if ($ApplicationName && !$Session->validateTransientKey($TransientKey)) {
         $ApplicationName = '';
     }
     if (!in_array($Filter, array('enabled', 'disabled'))) {
         $Filter = 'all';
     }
     $this->Filter = $Filter;
     $ApplicationManager = new Gdn_ApplicationManager();
     $this->AvailableApplications = $ApplicationManager->availableVisibleApplications();
     $this->EnabledApplications = $ApplicationManager->enabledVisibleApplications();
     if ($ApplicationName != '') {
         $this->EventArguments['ApplicationName'] = $ApplicationName;
         if (array_key_exists($ApplicationName, $this->EnabledApplications) === true) {
             try {
                 $ApplicationManager->disableApplication($ApplicationName);
                 Gdn_LibraryMap::clearCache();
                 $this->fireEvent('AfterDisableApplication');
             } catch (Exception $e) {
                 $this->Form->addError(strip_tags($e->getMessage()));
             }
         } else {
             try {
                 $ApplicationManager->checkRequirements($ApplicationName);
             } catch (Exception $e) {
                 $this->Form->addError(strip_tags($e->getMessage()));
             }
             if ($this->Form->errorCount() == 0) {
                 $Validation = new Gdn_Validation();
                 $ApplicationManager->registerPermissions($ApplicationName, $Validation);
                 $ApplicationManager->enableApplication($ApplicationName, $Validation);
                 Gdn_LibraryMap::clearCache();
                 $this->Form->setValidationResults($Validation->results());
                 $this->EventArguments['Validation'] = $Validation;
                 $this->fireEvent('AfterEnableApplication');
             }
         }
         if ($this->Form->errorCount() == 0) {
             redirect('settings/applications/' . $this->Filter);
         }
     }
     $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;
 }
 /**
  * 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));
 }
 /**
  * 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;
 }
 public function DisablePlugin($PluginName)
 {
     // 1. Check to make sure that no other enabled plugins rely on this one
     // Get all available plugins and compile their requirements
     foreach ($this->EnabledPlugins as $CheckingName => $CheckingInfo) {
         $RequiredPlugins = ArrayValue('RequiredPlugins', $CheckingInfo, FALSE);
         if (is_array($RequiredPlugins) && array_key_exists($PluginName, $RequiredPlugins) === TRUE) {
             throw new Exception(sprintf(T('You cannot disable the %1$s plugin because the %2$s plugin requires it in order to function.'), $PluginName, $CheckingName));
         }
     }
     // 2. Perform necessary hook action
     $this->_PluginHook($PluginName, self::ACTION_DISABLE, TRUE);
     // 3. Disable it
     RemoveFromConfig('EnabledPlugins' . '.' . $PluginName);
     unset($this->EnabledPlugins[$PluginName]);
     // Redefine the locale manager's settings $Locale->Set($CurrentLocale, $EnabledApps, $EnabledPlugins, TRUE);
     $ApplicationManager = new Gdn_ApplicationManager();
     $Locale = Gdn::Locale();
     $Locale->Set($Locale->Current(), $ApplicationManager->EnabledApplicationFolders(), $this->EnabledPluginFolders(), TRUE);
 }
 /**
  * Enable applications and create permisisions for roles.
  *
  * @return void
  */
 protected function enableApplications()
 {
     $ApplicationManager = new Gdn_ApplicationManager();
     $AppNames = c('Garden.Install.Applications', ['Conversations', 'Vanilla']);
     foreach ($AppNames as $AppName) {
         $Validation = new Gdn_Validation();
         $ApplicationManager->RegisterPermissions($AppName, $Validation);
         $ApplicationManager->EnableApplication($AppName, $Validation);
     }
     Gdn::pluginManager()->start(true);
     // Flag the application as installed
     saveToConfig('Garden.Installed', true);
     // Setup default permissions for all roles
     PermissionModel::ResetAllRoles();
 }
 /**
  *
  *
  * @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');
 }
Exemple #9
0
?>
</div>
<h1><?php 
echo T('Homepage');
?>
</h1>
<div class="Info">
   <?php 
printf(T('Use the content at this url as your homepage.', 'Choose the page people should see when they visit: <strong style="white-space: nowrap;">%s</strong>'), Url('/', TRUE));
?>
</div>
<div class="Homepage">
   <div class="HomeOptions">
      <?php 
// Only show the vanilla pages if Vanilla is enabled
$ApplicationManager = new Gdn_ApplicationManager();
$EnabledApplications = $ApplicationManager->EnabledVisibleApplications();
$CurrentTarget = $this->Data('CurrentTarget');
if (array_key_exists('Vanilla', $EnabledApplications)) {
    echo WriteHomepageOption('Discussions', 'discussions', 'SpDiscussions', $CurrentTarget);
    echo WriteHomepageOption('Categories', 'categories', 'SpCategories', $CurrentTarget);
    // echo WriteHomepageOption('Categories &amp; Discussions', 'categories/discussions', 'categoriesdiscussions', $CurrentTarget);
}
echo WriteHomepageOption('Activity', 'activity', 'SpActivity', $CurrentTarget);
?>
   </div>
   <?php 
if (array_key_exists('Vanilla', $EnabledApplications)) {
    ?>
   <div class="LayoutOptions DiscussionsLayout">
      <p>
Exemple #10
0
 /**
  * Garden management screen.
  */
 public function Configure()
 {
     $this->Permission('Garden.Settings.Manage');
     $this->AddSideMenu('garden/settings/configure');
     $this->AddJsFile('email.js');
     $this->Title(Translate('General Settings'));
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->SetField(array('Garden.Locale', 'Garden.Title', 'Garden.RewriteUrls', 'Garden.Email.SupportName', 'Garden.Email.SupportAddress', 'Garden.Email.UseSmtp', 'Garden.Email.SmtpHost', 'Garden.Email.SmtpUser', 'Garden.Email.SmtpPassword', 'Garden.Email.SmtpPort'));
     // Set the model on the form.
     $this->Form->SetModel($ConfigurationModel);
     // Load the locales for the locale dropdown
     $Locale = Gdn::Locale();
     $AvailableLocales = $Locale->GetAvailableLocaleSources();
     $this->LocaleData = ArrayCombine($AvailableLocales, $AvailableLocales);
     // Check to see if mod_rewrit is enabled.
     if (function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules())) {
         $this->SetData('HasModRewrite', TRUE);
     } else {
         $this->SetData('HasModRewrite', FALSE);
     }
     // If seeing the form for the first time...
     if ($this->Form->AuthenticatedPostBack() === FALSE) {
         // Apply the config settings to the form.
         $this->Form->SetData($ConfigurationModel->Data);
     } else {
         // Define some validation rules for the fields being saved
         $ConfigurationModel->Validation->ApplyRule('Garden.Locale', 'Required');
         $ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
         $ConfigurationModel->Validation->ApplyRule('Garden.RewriteUrls', 'Boolean');
         $ConfigurationModel->Validation->ApplyRule('Garden.Email.SupportName', 'Required');
         $ConfigurationModel->Validation->ApplyRule('Garden.Email.SupportAddress', 'Required');
         $ConfigurationModel->Validation->ApplyRule('Garden.Email.SupportAddress', 'Email');
         // If changing locale, redefine locale sources:
         $NewLocale = $this->Form->GetFormValue('Garden.Locale', FALSE);
         if ($NewLocale !== FALSE && Gdn::Config('Garden.Locale') != $NewLocale) {
             $ApplicationManager = new Gdn_ApplicationManager();
             $PluginManager = Gdn::Factory('PluginManager');
             $Locale = Gdn::Locale();
             $Locale->Set($NewLocale, $ApplicationManager->EnabledApplicationFolders(), $PluginManager->EnabledPluginFolders(), TRUE);
         }
         if ($this->Form->Save() !== FALSE) {
             $this->StatusMessage = Translate("Your settings have been saved.");
         }
     }
     $this->Render();
 }
Exemple #11
0
 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.
         }
     }
 }
Exemple #12
0
 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;
 }
 public function EnablePlugin($PluginName, $Validation, $Setup = FALSE, $EnabledPluginValueIndex = 'Folder')
 {
     // Check that the plugin is in AvailablePlugins...
     $Plugin = $this->GetPluginInfo($PluginName, self::ACCESS_PLUGINNAME);
     // If not, we're dealing with a special case. Enabling with a classname...
     if (!$Plugin) {
         $ClassName = $PluginName;
         $PluginFile = Gdn_LibraryMap::GetCache('plugin', $ClassName);
         if ($PluginFile) {
             $Plugin = $this->PluginAvailable($PluginFile);
             $PluginName = $Plugin['Index'];
         }
     }
     // Couldn't load the plugin info.
     if (!$Plugin) {
         return;
     }
     $PluginName = $Plugin['Index'];
     $this->TestPlugin($PluginName, $Validation, $Setup);
     if (is_object($Validation) && count($Validation->Results()) > 0) {
         return FALSE;
     }
     // If everything succeeded, add the plugin to the $EnabledPlugins array in conf/config.php
     // $EnabledPlugins['PluginClassName'] = 'Plugin Folder Name';
     // $PluginInfo = ArrayValue($PluginName, $this->AvailablePlugins(), FALSE);
     $PluginInfo = $this->GetPluginInfo($PluginName);
     $PluginFolder = ArrayValue('Folder', $PluginInfo);
     $PluginEnabledValue = ArrayValue($EnabledPluginValueIndex, $PluginInfo, $PluginFolder);
     SaveToConfig('EnabledPlugins.' . $PluginName, $PluginEnabledValue);
     $this->EnabledPlugins[$PluginName] = $PluginInfo;
     $this->RegisterPlugin($PluginInfo['ClassName'], $PluginInfo);
     $ApplicationManager = new Gdn_ApplicationManager();
     $Locale = Gdn::Locale();
     $Locale->Set($Locale->Current(), $ApplicationManager->EnabledApplicationFolders(), $this->EnabledPluginFolders(), TRUE);
     return TRUE;
 }
Exemple #14
0
 public function DisablePlugin($PluginName)
 {
     // 1. Check to make sure that no other enabled plugins rely on this one
     // Get all available plugins and compile their requirements
     foreach ($this->EnabledPlugins as $CheckingName => $CheckingInfo) {
         $RequiredPlugins = ArrayValue('RequiredPlugins', $CheckingInfo, FALSE);
         if (is_array($RequiredPlugins) && array_key_exists($PluginName, $RequiredPlugins) === TRUE) {
             throw new Exception(sprintf(Gdn::Translate('You cannot disable the %1$s plugin because the %2$s plugin requires it in order to function.'), $PluginName, $CheckingName));
         }
     }
     // 2. Disable it
     $Config = Gdn::Factory(Gdn::AliasConfig);
     $Config->Load(PATH_CONF . DS . 'config.php', 'Save');
     $Config->Remove('EnabledPlugins' . '.' . $PluginName);
     $Config->Save();
     unset($this->EnabledPlugins[$PluginName]);
     // Redefine the locale manager's settings $Locale->Set($CurrentLocale, $EnabledApps, $EnabledPlugins, TRUE);
     $ApplicationManager = new Gdn_ApplicationManager();
     $Locale = Gdn::Locale();
     $Locale->Set($Locale->Current(), $ApplicationManager->EnabledApplicationFolders(), $this->EnabledPluginFolders(), 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();
     $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();
         }
     }
 }
 /**
  * Allows the configuration of basic setup information in Garden. This
  * should not be functional after the application has been set up.
  *
  * @since 2.0.0
  * @access public
  * @param string $RedirectUrl Where to send user afterward.
  */
 private function configure($RedirectUrl = '')
 {
     // Create a model to save configuration settings
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->setField(array('Garden.Locale', 'Garden.Title', 'Garden.WebRoot', 'Garden.Cookie.Salt', 'Garden.Cookie.Domain', 'Database.Name', 'Database.Host', 'Database.User', 'Database.Password', 'Garden.Registration.ConfirmEmail', 'Garden.Email.SupportName'));
     // Set the models on the forms.
     $this->Form->setModel($ConfigurationModel);
     // Load the locales for the locale dropdown
     // $Locale = Gdn::locale();
     // $AvailableLocales = $Locale->GetAvailableLocaleSources();
     // $this->LocaleData = array_combine($AvailableLocales, $AvailableLocales);
     // If seeing the form for the first time...
     if (!$this->Form->isPostback()) {
         // Force the webroot using our best guesstimates
         $ConfigurationModel->Data['Database.Host'] = 'localhost';
         $this->Form->setData($ConfigurationModel->Data);
     } else {
         // Define some validation rules for the fields being saved
         $ConfigurationModel->Validation->applyRule('Database.Name', 'Required', 'You must specify the name of the database in which you want to set up Vanilla.');
         // Let's make some user-friendly custom errors for database problems
         $DatabaseHost = $this->Form->getFormValue('Database.Host', '~~Invalid~~');
         $DatabaseName = $this->Form->getFormValue('Database.Name', '~~Invalid~~');
         $DatabaseUser = $this->Form->getFormValue('Database.User', '~~Invalid~~');
         $DatabasePassword = $this->Form->getFormValue('Database.Password', '~~Invalid~~');
         $ConnectionString = GetConnectionString($DatabaseName, $DatabaseHost);
         try {
             $Connection = new PDO($ConnectionString, $DatabaseUser, $DatabasePassword);
         } catch (PDOException $Exception) {
             switch ($Exception->getCode()) {
                 case 1044:
                     $this->Form->addError(t('The database user you specified does not have permission to access the database. Have you created the database yet? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
                     break;
                 case 1045:
                     $this->Form->addError(t('Failed to connect to the database with the username and password you entered. Did you mistype them? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
                     break;
                 case 1049:
                     $this->Form->addError(t('It appears as though the database you specified does not exist yet. Have you created it yet? Did you mistype the name? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
                     break;
                 case 2005:
                     $this->Form->addError(t("Are you sure you've entered the correct database host name? Maybe you mistyped it? The database reported: <code>%s</code>"), strip_tags($Exception->getMessage()));
                     break;
                 default:
                     $this->Form->addError(sprintf(t('ValidateConnection'), strip_tags($Exception->getMessage())));
                     break;
             }
         }
         $ConfigurationModel->Validation->applyRule('Garden.Title', 'Required');
         $ConfigurationFormValues = $this->Form->formValues();
         if ($ConfigurationModel->validate($ConfigurationFormValues) !== true || $this->Form->errorCount() > 0) {
             // Apply the validation results to the form(s)
             $this->Form->setValidationResults($ConfigurationModel->validationResults());
         } else {
             $Host = array_shift(explode(':', Gdn::request()->requestHost()));
             $Domain = Gdn::request()->domain();
             // Set up cookies now so that the user can be signed in.
             $ExistingSalt = c('Garden.Cookie.Salt', false);
             $ConfigurationFormValues['Garden.Cookie.Salt'] = $ExistingSalt ? $ExistingSalt : betterRandomString(16, 'Aa0');
             $ConfigurationFormValues['Garden.Cookie.Domain'] = '';
             // Don't set this to anything by default. # Tim - 2010-06-23
             // Additional default setup values.
             $ConfigurationFormValues['Garden.Registration.ConfirmEmail'] = true;
             $ConfigurationFormValues['Garden.Email.SupportName'] = $ConfigurationFormValues['Garden.Title'];
             $ConfigurationModel->save($ConfigurationFormValues, true);
             // If changing locale, redefine locale sources:
             $NewLocale = 'en-CA';
             // $this->Form->getFormValue('Garden.Locale', false);
             if ($NewLocale !== false && Gdn::config('Garden.Locale') != $NewLocale) {
                 $ApplicationManager = new Gdn_ApplicationManager();
                 $Locale = Gdn::locale();
                 $Locale->set($NewLocale, $ApplicationManager->enabledApplicationFolders(), Gdn::pluginManager()->enabledPluginFolders(), true);
             }
             // Install db structure & basic data.
             $Database = Gdn::database();
             $Database->init();
             $Drop = false;
             $Explicit = false;
             try {
                 include PATH_APPLICATIONS . DS . 'dashboard' . DS . 'settings' . DS . 'structure.php';
             } catch (Exception $ex) {
                 $this->Form->addError($ex);
             }
             if ($this->Form->errorCount() > 0) {
                 return false;
             }
             // Create the administrative user
             $UserModel = Gdn::userModel();
             $UserModel->defineSchema();
             $UsernameError = t('UsernameError', 'Username can only contain letters, numbers, underscores, and must be between 3 and 20 characters long.');
             $UserModel->Validation->applyRule('Name', 'Username', $UsernameError);
             $UserModel->Validation->applyRule('Name', 'Required', t('You must specify an admin username.'));
             $UserModel->Validation->applyRule('Password', 'Required', t('You must specify an admin password.'));
             $UserModel->Validation->applyRule('Password', 'Match');
             $UserModel->Validation->applyRule('Email', 'Email');
             if (!($AdminUserID = $UserModel->SaveAdminUser($ConfigurationFormValues))) {
                 $this->Form->setValidationResults($UserModel->validationResults());
             } else {
                 // The user has been created successfully, so sign in now.
                 saveToConfig('Garden.Installed', true, array('Save' => false));
                 Gdn::session()->start($AdminUserID, true);
                 saveToConfig('Garden.Installed', false, array('Save' => false));
             }
             if ($this->Form->errorCount() > 0) {
                 return false;
             }
             // Assign some extra settings to the configuration file if everything succeeded.
             $ApplicationInfo = array();
             include CombinePaths(array(PATH_APPLICATIONS . DS . 'dashboard' . DS . 'settings' . DS . 'about.php'));
             // Detect Internet connection for CDNs
             $Disconnected = !(bool) @fsockopen('ajax.googleapis.com', 80);
             saveToConfig(array('Garden.Version' => val('Version', val('Dashboard', $ApplicationInfo, array()), 'Undefined'), 'Garden.Cdns.Disable' => $Disconnected, 'Garden.CanProcessImages' => function_exists('gd_info'), 'EnabledPlugins.GettingStarted' => 'GettingStarted', 'EnabledPlugins.HtmLawed' => 'HtmLawed'));
         }
     }
     return $this->Form->errorCount() == 0 ? true : false;
 }
 /**
  * Update database structure based on current definitions in each app's structure.php file.
  *
  * @since 2.0.?
  * @access public
  * @param string $AppName Unique app name or 'all' (default).
  * @param int $CaptureOnly Whether to list changes rather than execture (0 or 1).
  * @param int $Drop Whether to drop first (0 or 1).
  * @param int $Explicit Whether to force to only columns currently listed (0 or 1).
  */
 public function structure($AppName = 'all', $CaptureOnly = '1', $Drop = '0', $Explicit = '0')
 {
     $this->permission('Garden.Settings.Manage');
     $Files = array();
     $AppName = $AppName == '' ? 'all' : $AppName;
     if ($AppName == 'all') {
         // Load all application structure files.
         $ApplicationManager = new Gdn_ApplicationManager();
         $Apps = $ApplicationManager->enabledApplications();
         $AppNames = array_column($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);
             }
         }
     }
     // Run the structure of all of the plugins.
     $Plugins = Gdn::pluginManager()->enabledPlugins();
     foreach ($Plugins as $PluginKey => $Plugin) {
         $PluginInstance = Gdn::pluginManager()->getPluginInstance($PluginKey, Gdn_PluginManager::ACCESS_PLUGINNAME);
         if (method_exists($PluginInstance, 'Structure')) {
             $PluginInstance->structure();
         }
     }
     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();
 }
 /**
  * Run the database structure or /utility/structure.
  *
  * Note: Keep this method protected!
  *
  * @param string $appName Unique app name or 'all' (default).
  * @param bool $captureOnly Whether to list changes rather than execute (0 or 1).
  * @throws Exception
  */
 protected function runStructure($appName = 'all', $captureOnly = true)
 {
     // This permission is run again to be sure someone doesn't accidentally call this method incorrectly.
     $this->permission('Garden.Settings.Manage');
     $Files = array();
     $appName = $appName == '' ? 'all' : $appName;
     if ($appName == 'all') {
         // Load all application structure files.
         $ApplicationManager = new Gdn_ApplicationManager();
         $Apps = $ApplicationManager->enabledApplications();
         $AppNames = array_column($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);
     }
     $Drop = false;
     $Explicit = false;
     $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);
             }
         }
     }
     // Run the structure of all of the plugins.
     $Plugins = Gdn::pluginManager()->enabledPlugins();
     foreach ($Plugins as $PluginKey => $Plugin) {
         $PluginInstance = Gdn::pluginManager()->getPluginInstance($PluginKey, Gdn_PluginManager::ACCESS_PLUGINNAME);
         if (method_exists($PluginInstance, 'Structure')) {
             $PluginInstance->structure();
         }
     }
     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.');
     }
 }
Exemple #19
0
 /**
  * Allows the configuration of basic setup information in Garden. This
  * should not be functional after the application has been set up.
  */
 public function Configure($RedirectUrl = '')
 {
     $Config = Gdn::Factory(Gdn::AliasConfig);
     $ConfigFile = PATH_CONF . DS . 'config.php';
     // Create a model to save configuration settings
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel('Configuration', $ConfigFile, $Validation);
     $ConfigurationModel->SetField(array('Garden.Locale', 'Garden.Title', 'Garden.RewriteUrls', 'Garden.WebRoot', 'Garden.Cookie.Salt', 'Garden.Cookie.Domain', 'Database.Name', 'Database.Host', 'Database.User', 'Database.Password'));
     // Set the models on the forms.
     $this->Form->SetModel($ConfigurationModel);
     // Load the locales for the locale dropdown
     // $Locale = Gdn::Locale();
     // $AvailableLocales = $Locale->GetAvailableLocaleSources();
     // $this->LocaleData = array_combine($AvailableLocales, $AvailableLocales);
     // If seeing the form for the first time...
     if (!$this->Form->IsPostback()) {
         // Force the webroot using our best guesstimates
         $ConfigurationModel->Data['Database.Host'] = 'localhost';
         $this->Form->SetData($ConfigurationModel->Data);
     } else {
         // Define some validation rules for the fields being saved
         $ConfigurationModel->Validation->AddRule('Connection', 'function:ValidateConnection');
         $ConfigurationModel->Validation->ApplyRule('Database.Name', 'Connection');
         $ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
         $ConfigurationFormValues = $this->Form->FormValues();
         if ($ConfigurationModel->Validate($ConfigurationFormValues) !== TRUE) {
             // Apply the validation results to the form(s)
             $this->Form->SetValidationResults($ConfigurationModel->ValidationResults());
         } else {
             $Host = Gdn_Url::Host();
             $Domain = Gdn_Url::Domain();
             // Set up cookies now so that the user can be signed in.
             $ConfigurationFormValues['Garden.Cookie.Salt'] = RandomString(10);
             $ConfigurationFormValues['Garden.Cookie.Domain'] = strpos($Host, '.') === FALSE ? '' : $Host;
             // Don't assign the domain if it is a non .com domain as that will break cookies.
             $ConfigurationModel->Save($ConfigurationFormValues);
             // If changing locale, redefine locale sources:
             $NewLocale = 'en-CA';
             // $this->Form->GetFormValue('Garden.Locale', FALSE);
             if ($NewLocale !== FALSE && Gdn::Config('Garden.Locale') != $NewLocale) {
                 $ApplicationManager = new Gdn_ApplicationManager();
                 $PluginManager = Gdn::Factory('PluginManager');
                 $Locale = Gdn::Locale();
                 $Locale->Set($NewLocale, $ApplicationManager->EnabledApplicationFolders(), $PluginManager->EnabledPluginFolders(), TRUE);
             }
             // Set the instantiated config object's db params and make the database use them (otherwise it will use the default values from conf/config-defaults.php).
             $Config->Set('Database.Host', $ConfigurationFormValues['Database.Host']);
             $Config->Set('Database.Name', $ConfigurationFormValues['Database.Name']);
             $Config->Set('Database.User', $ConfigurationFormValues['Database.User']);
             $Config->Set('Database.Password', $ConfigurationFormValues['Database.Password']);
             $Config->ClearSaveData();
             Gdn::FactoryInstall(Gdn::AliasDatabase, 'Gdn_Database', PATH_LIBRARY . DS . 'database' . DS . 'class.database.php', Gdn::FactorySingleton, array(Gdn::Config('Database')));
             // Install db structure & basic data.
             $Database = Gdn::Database();
             $Drop = FALSE;
             // Gdn::Config('Garden.Version') === FALSE ? TRUE : FALSE;
             $Explicit = FALSE;
             try {
                 include PATH_APPLICATIONS . DS . 'garden' . DS . 'settings' . DS . 'structure.php';
             } catch (Exception $ex) {
                 $this->Form->AddError(strip_tags($ex->getMessage()));
             }
             if ($this->Form->ErrorCount() > 0) {
                 return FALSE;
             }
             // Create the administrative user
             $UserModel = Gdn::UserModel();
             $UserModel->DefineSchema();
             $UserModel->Validation->ApplyRule('Name', 'Username', 'Admin username can only contain letters, numbers, and underscores.');
             $UserModel->Validation->ApplyRule('Password', 'Required');
             $UserModel->Validation->ApplyRule('Password', 'Match');
             if (!$UserModel->SaveAdminUser($ConfigurationFormValues)) {
                 $this->Form->SetValidationResults($UserModel->ValidationResults());
             } else {
                 // The user has been created successfully, so sign in now
                 $Authenticator = Gdn::Authenticator();
                 $AuthUserID = $Authenticator->Authenticate(array('Name' => $this->Form->GetValue('Name'), 'Password' => $this->Form->GetValue('Password'), 'RememberMe' => TRUE));
             }
             if ($this->Form->ErrorCount() > 0) {
                 return FALSE;
             }
             // Assign some extra settings to the configuration file if everything succeeded.
             $ApplicationInfo = array();
             include CombinePaths(array(PATH_APPLICATIONS . DS . 'garden' . DS . 'settings' . DS . 'about.php'));
             $Config->Load($ConfigFile, 'Save');
             $Config->Set('Garden.Version', ArrayValue('Version', ArrayValue('Garden', $ApplicationInfo, array()), 'Undefined'));
             $Config->Set('Garden.WebRoot', Gdn_Url::WebRoot());
             $Config->Set('Garden.RewriteUrls', function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules()) ? TRUE : FALSE);
             $Config->Set('Garden.Domain', $Domain);
             $Config->Set('Garden.CanProcessImages', function_exists('gd_info'));
             $Config->Set('Garden.Messages.Cache', 'arr:["Garden\\/Settings\\/Index"]');
             // Make sure that the "welcome" message is cached for viewing
             $Config->Set('EnabledPlugins.HTMLPurifier', 'HtmlPurifier');
             // Make sure html purifier is enabled so html has a default way of being safely parsed
             $Config->Save();
         }
     }
     return $this->Form->ErrorCount() == 0 ? TRUE : FALSE;
 }
 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;
 }
Exemple #21
0
 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, ''));
         }
     }
 }
 /**
  * Allows the configuration of basic setup information in Garden. This
  * should not be functional after the application has been set up.
  *
  * @since 2.0.0
  * @access public
  * @param string $RedirectUrl Where to send user afterward.
  */
 public function Configure($RedirectUrl = '')
 {
     // Create a model to save configuration settings
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->SetField(array('Garden.Locale', 'Garden.Title', 'Garden.RewriteUrls', 'Garden.WebRoot', 'Garden.Cookie.Salt', 'Garden.Cookie.Domain', 'Database.Name', 'Database.Host', 'Database.User', 'Database.Password', 'Garden.Registration.ConfirmEmail', 'Garden.Email.SupportName'));
     // Set the models on the forms.
     $this->Form->SetModel($ConfigurationModel);
     // Load the locales for the locale dropdown
     // $Locale = Gdn::Locale();
     // $AvailableLocales = $Locale->GetAvailableLocaleSources();
     // $this->LocaleData = array_combine($AvailableLocales, $AvailableLocales);
     // If seeing the form for the first time...
     if (!$this->Form->IsPostback()) {
         // Force the webroot using our best guesstimates
         $ConfigurationModel->Data['Database.Host'] = 'localhost';
         $this->Form->SetData($ConfigurationModel->Data);
     } else {
         // Define some validation rules for the fields being saved
         $ConfigurationModel->Validation->ApplyRule('Database.Name', 'Required', 'You must specify the name of the database in which you want to set up Vanilla.');
         // Let's make some user-friendly custom errors for database problems
         $DatabaseHost = $this->Form->GetFormValue('Database.Host', '~~Invalid~~');
         $DatabaseName = $this->Form->GetFormValue('Database.Name', '~~Invalid~~');
         $DatabaseUser = $this->Form->GetFormValue('Database.User', '~~Invalid~~');
         $DatabasePassword = $this->Form->GetFormValue('Database.Password', '~~Invalid~~');
         $ConnectionString = GetConnectionString($DatabaseName, $DatabaseHost);
         try {
             $Connection = new PDO($ConnectionString, $DatabaseUser, $DatabasePassword);
         } catch (PDOException $Exception) {
             switch ($Exception->getCode()) {
                 case 1044:
                     $this->Form->AddError(T('The database user you specified does not have permission to access the database. Have you created the database yet? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
                     break;
                 case 1045:
                     $this->Form->AddError(T('Failed to connect to the database with the username and password you entered. Did you mistype them? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
                     break;
                 case 1049:
                     $this->Form->AddError(T('It appears as though the database you specified does not exist yet. Have you created it yet? Did you mistype the name? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
                     break;
                 case 2005:
                     $this->Form->AddError(T("Are you sure you've entered the correct database host name? Maybe you mistyped it? The database reported: <code>%s</code>"), strip_tags($Exception->getMessage()));
                     break;
                 default:
                     $this->Form->AddError(sprintf(T('ValidateConnection'), strip_tags($Exception->getMessage())));
                     break;
             }
         }
         $ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
         $ConfigurationFormValues = $this->Form->FormValues();
         if ($ConfigurationModel->Validate($ConfigurationFormValues) !== TRUE || $this->Form->ErrorCount() > 0) {
             // Apply the validation results to the form(s)
             $this->Form->SetValidationResults($ConfigurationModel->ValidationResults());
         } else {
             $Host = array_shift(explode(':', Gdn::Request()->RequestHost()));
             $Domain = Gdn::Request()->Domain();
             // Set up cookies now so that the user can be signed in.
             $ExistingSalt = C('Garden.Cookie.Salt', FALSE);
             $ConfigurationFormValues['Garden.Cookie.Salt'] = $ExistingSalt ? $ExistingSalt : RandomString(10);
             $ConfigurationFormValues['Garden.Cookie.Domain'] = '';
             // Don't set this to anything by default. # Tim - 2010-06-23
             // Additional default setup values.
             $ConfigurationFormValues['Garden.Registration.ConfirmEmail'] = TRUE;
             $ConfigurationFormValues['Garden.Email.SupportName'] = $ConfigurationFormValues['Garden.Title'];
             $ConfigurationModel->Save($ConfigurationFormValues, TRUE);
             // If changing locale, redefine locale sources:
             $NewLocale = 'en-CA';
             // $this->Form->GetFormValue('Garden.Locale', FALSE);
             if ($NewLocale !== FALSE && Gdn::Config('Garden.Locale') != $NewLocale) {
                 $ApplicationManager = new Gdn_ApplicationManager();
                 $Locale = Gdn::Locale();
                 $Locale->Set($NewLocale, $ApplicationManager->EnabledApplicationFolders(), Gdn::PluginManager()->EnabledPluginFolders(), TRUE);
             }
             // Install db structure & basic data.
             $Database = Gdn::Database();
             $Database->Init();
             $Drop = FALSE;
             // Gdn::Config('Garden.Version') === FALSE ? TRUE : FALSE;
             $Explicit = FALSE;
             try {
                 include PATH_APPLICATIONS . DS . 'dashboard' . DS . 'settings' . DS . 'structure.php';
             } catch (Exception $ex) {
                 $this->Form->AddError($ex);
             }
             if ($this->Form->ErrorCount() > 0) {
                 return FALSE;
             }
             // Create the administrative user
             $UserModel = Gdn::UserModel();
             $UserModel->DefineSchema();
             $UsernameError = T('UsernameError', 'Username can only contain letters, numbers, underscores, and must be between 3 and 20 characters long.');
             $UserModel->Validation->ApplyRule('Name', 'Username', $UsernameError);
             $UserModel->Validation->ApplyRule('Name', 'Required', T('You must specify an admin username.'));
             $UserModel->Validation->ApplyRule('Password', 'Required', T('You must specify an admin password.'));
             $UserModel->Validation->ApplyRule('Password', 'Match');
             $UserModel->Validation->ApplyRule('Email', 'Email');
             if (!($AdminUserID = $UserModel->SaveAdminUser($ConfigurationFormValues))) {
                 $this->Form->SetValidationResults($UserModel->ValidationResults());
             } else {
                 // The user has been created successfully, so sign in now.
                 SaveToConfig('Garden.Installed', TRUE, array('Save' => FALSE));
                 Gdn::Session()->Start($AdminUserID, TRUE);
                 SaveToConfig('Garden.Installed', FALSE, array('Save' => FALSE));
             }
             if ($this->Form->ErrorCount() > 0) {
                 return FALSE;
             }
             // Assign some extra settings to the configuration file if everything succeeded.
             $ApplicationInfo = array();
             include CombinePaths(array(PATH_APPLICATIONS . DS . 'dashboard' . DS . 'settings' . DS . 'about.php'));
             // Detect rewrite abilities
             try {
                 $Query = ConcatSep('/', Gdn::Request()->Domain(), Gdn::Request()->WebRoot(), 'dashboard/setup');
                 $Results = ProxyHead($Query, array(), 3);
                 $CanRewrite = FALSE;
                 if (in_array(ArrayValue('StatusCode', $Results, 404), array(200, 302)) && ArrayValue('X-Garden-Version', $Results, 'None') != 'None') {
                     $CanRewrite = TRUE;
                 }
             } catch (Exception $e) {
                 // cURL and fsockopen arent supported... guess?
                 $CanRewrite = function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules()) ? TRUE : FALSE;
             }
             SaveToConfig(array('Garden.Version' => ArrayValue('Version', GetValue('Dashboard', $ApplicationInfo, array()), 'Undefined'), 'Garden.RewriteUrls' => $CanRewrite, 'Garden.CanProcessImages' => function_exists('gd_info'), 'EnabledPlugins.GettingStarted' => 'GettingStarted', 'EnabledPlugins.HtmLawed' => 'HtmLawed'));
         }
     }
     return $this->Form->ErrorCount() == 0 ? TRUE : FALSE;
 }
Exemple #23
0
 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;
 }
 /**
  * Application management screen.
  */
 public function Applications($Filter = '', $ApplicationName = '', $TransientKey = '')
 {
     $this->AddJsFile('addons.js');
     $Session = Gdn::Session();
     $ApplicationName = $Session->ValidateTransientKey($TransientKey) ? $ApplicationName : '';
     if (!in_array($Filter, array('enabled', 'disabled'))) {
         $Filter = 'all';
     }
     $this->Filter = $Filter;
     $this->Permission('Garden.Applications.Manage');
     $this->AddSideMenu('dashboard/settings/applications');
     $this->AddJsFile('applications.js');
     $this->Title(T('Applications'));
     $AuthenticatedPostBack = $this->Form->AuthenticatedPostBack();
     $ApplicationManager = new Gdn_ApplicationManager();
     $this->AvailableApplications = $ApplicationManager->AvailableVisibleApplications();
     $this->EnabledApplications = $ApplicationManager->EnabledVisibleApplications();
     // Loop through all of the available visible apps and mark them if they have an update available
     // Retrieve the list of apps that require updates from the config file
     $RequiredUpdates = Gdn_Format::Unserialize(C('Garden.RequiredUpdates', ''));
     if (is_array($RequiredUpdates)) {
         foreach ($RequiredUpdates as $UpdateInfo) {
             if (is_object($UpdateInfo)) {
                 $UpdateInfo = Gdn_Format::ObjectAsArray($UpdateInfo);
             }
             $NewVersion = ArrayValue('Version', $UpdateInfo, '');
             $Name = ArrayValue('Name', $UpdateInfo, '');
             $Type = ArrayValue('Type', $UpdateInfo, '');
             foreach ($this->AvailableApplications as $App => $Info) {
                 $CurrentName = ArrayValue('Name', $Info, $App);
                 if ($CurrentName == $Name && $Type == 'Application') {
                     $Info['NewVersion'] = $NewVersion;
                     $this->AvailableApplications[$App] = $Info;
                 }
             }
         }
     }
     if ($ApplicationName != '') {
         $this->EventArguments['ApplicationName'] = $ApplicationName;
         if (array_key_exists($ApplicationName, $this->EnabledApplications) === TRUE) {
             try {
                 $ApplicationManager->DisableApplication($ApplicationName);
                 $this->FireEvent('AfterDisableApplication');
             } catch (Exception $e) {
                 $this->Form->AddError(strip_tags($e->getMessage()));
             }
         } else {
             try {
                 $ApplicationManager->CheckRequirements($ApplicationName);
             } catch (Exception $e) {
                 $this->Form->AddError(strip_tags($e->getMessage()));
             }
             if ($this->Form->ErrorCount() == 0) {
                 $Validation = new Gdn_Validation();
                 $ApplicationManager->RegisterPermissions($ApplicationName, $Validation);
                 $ApplicationManager->EnableApplication($ApplicationName, $Validation);
                 $this->Form->SetValidationResults($Validation->Results());
                 $this->EventArguments['Validation'] = $Validation;
                 $this->FireEvent('AfterEnableApplication');
             }
         }
         if ($this->Form->ErrorCount() == 0) {
             Redirect('settings/applications/' . $this->Filter);
         }
     }
     $this->Render();
 }
Exemple #25
0
 /**
  * Garden management screen.
  */
 public function Configure()
 {
     $this->Permission('Garden.Settings.Manage');
     $this->AddSideMenu('garden/settings/configure');
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel('Configuration', PATH_CONF . DS . 'config.php', $Validation);
     $ConfigurationModel->SetField(array('Garden.Locale', 'Garden.Title', 'Garden.RewriteUrls'));
     // Set the model on the form.
     $this->Form->SetModel($ConfigurationModel);
     // Load the locales for the locale dropdown
     $Locale = Gdn::Locale();
     $AvailableLocales = $Locale->GetAvailableLocaleSources();
     $this->LocaleData = ArrayCombine($AvailableLocales, $AvailableLocales);
     // If seeing the form for the first time...
     if ($this->Form->AuthenticatedPostBack() === FALSE) {
         // Apply the config settings to the form.
         $this->Form->SetData($ConfigurationModel->Data);
     } else {
         // Define some validation rules for the fields being saved
         $ConfigurationModel->Validation->ApplyRule('Garden.Locale', 'Required');
         $ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
         $ConfigurationModel->Validation->ApplyRule('Garden.RewriteUrls', 'Boolean');
         // If changing locale, redefine locale sources:
         $NewLocale = $this->Form->GetFormValue('Garden.Locale', FALSE);
         if ($NewLocale !== FALSE && Gdn::Config('Garden.Locale') != $NewLocale) {
             $ApplicationManager = new Gdn_ApplicationManager();
             $PluginManager = Gdn::Factory('PluginManager');
             $Locale = Gdn::Locale();
             $Locale->Set($NewLocale, $ApplicationManager->EnabledApplicationFolders(), $PluginManager->EnabledPluginFolders(), TRUE);
         }
         if ($this->Form->Save() !== FALSE) {
             $this->StatusMessage = Translate("Your settings have been saved.");
         }
     }
     $this->Render();
 }