/** * Application management screen. */ public function Applications($Filter = '', $TransientKey = '') { $Session = Gdn::Session(); $ApplicationName = $Session->ValidateTransientKey($TransientKey) ? $Filter : ''; if (!in_array($Filter, array('enabled', 'disabled'))) { $Filter = ''; } $this->Filter = $Filter; $this->Permission('Garden.Applications.Manage'); $this->AddSideMenu('garden/settings/applications'); $this->AddJsFile('applications.js'); $this->Title(Translate('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 = Format::Unserialize(Gdn::Config('Garden.RequiredUpdates', '')); if (is_array($RequiredUpdates)) { foreach ($RequiredUpdates as $UpdateInfo) { if (is_object($UpdateInfo)) { $UpdateInfo = 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 != '') { if (array_key_exists($ApplicationName, $this->EnabledApplications) === TRUE) { try { $ApplicationManager->DisableApplication($ApplicationName); } 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); if ($ApplicationManager->ApplicationHasSetup($ApplicationName)) { $ApplicationManager->ApplicationSetup($ApplicationName, $this->ControllerName, $Validation); } } $this->Form->SetValidationResults($Validation->Results()); } if ($this->Form->ErrorCount() == 0) { Redirect('settings/applications'); } } $this->Render(); }
/** * Application management screen. */ public function Applications($Action = '', $ApplicationName = '', $TransientKey = '') { $this->Permission('Garden.Applications.Manage'); $this->AddSideMenu('garden/settings/applications'); if ($this->Head) { $this->Head->AddScript('/applications/garden/js/applications.js'); } $Session = Gdn::Session(); $AuthenticatedPostBack = $this->Form->AuthenticatedPostBack(); // Todd: Is this part necessary? if (!$Session->ValidateTransientKey($TransientKey)) { // if(!$AuthenticatedPostBack) { $Action = ''; $ApplicationName = ''; } else { $AuthenticatedPostBack = TRUE; } $FinalRedirect = FALSE; $SetupRender = FALSE; $ApplicationManager = new Gdn_ApplicationManager(); $this->AvailableApplications = $ApplicationManager->AvailableApplications(); // Check the update server for updates to these applications $this->UpdateManager = new Gdn_UpdateManager(); // TODO: FIX UP THE PHONE-HOME CODE - AJAX, PERHAPS? // $this->CurrentVersions = $this->UpdateManager->Check(ADDON_TYPE_APPLICATION, array_keys($this->AvailableApplications)); if ($AuthenticatedPostBack) { $ApplicationName = $this->Form->GetValue('ApplicationName', $ApplicationName); if ($ApplicationName != '') { if (array_key_exists($ApplicationName, $this->EnabledApplications) === TRUE) { try { $ApplicationManager->DisableApplication($ApplicationName); } catch (Exception $e) { $this->Form->AddError(strip_tags($e->getMessage())); } $FinalRedirect = TRUE; } else { if ($Action == '') { // 1. Make sure that the application's requirements are met try { $ApplicationManager->CheckRequirements($ApplicationName); } catch (Exception $e) { $this->Form->AddError(strip_tags($e->getMessage())); } if ($this->Form->ErrorCount() == 0) { // 2. Register any specified permissions $Validation = new Gdn_Validation(); $ApplicationManager->RegisterPermissions($ApplicationName, $Validation); if (count($Validation->Results()) == 0) { if (!$ApplicationManager->ApplicationSetup($ApplicationName, $this, $Validation, TRUE)) { $SetupUrl = '/garden/settings/applications/setup/' . $ApplicationName . '/' . $Session->TransientKey(); if ($this->_DeliveryType === DELIVERY_TYPE_ALL) { Redirect($SetupUrl); } else { $this->SetJson('Go', Url($SetupUrl)); // <---- THIS IS WHAT MAKES IT GET PICKED UP BY THE POPUP $this->Database->CloseConnection(); exit(json_encode($this->GetJson())); } } else { $FinalRedirect = TRUE; } } } $this->Form->SetValidationResults($Validation->Results()); } elseif ($Action == 'setup') { // 3. Run the setup method of the application $SetupRender = TRUE; $Validation = new Gdn_Validation(); if ($ApplicationManager->ApplicationSetup($ApplicationName, $this, $Validation)) { $SetupRender = FALSE; $FinalRedirect = TRUE; } } } if ($FinalRedirect && $this->Form->ErrorCount() == 0) { $this->StatusMessage = Gdn::Translate('Finalizing changes...'); $this->RedirectUrl = Url('/garden/settings/applications/'); } } } if (!$SetupRender) { $this->Render(); } }