Inheritance: extends Gdn_Pluggable
 public function FormatConfiguration($Data)
 {
     $Old = $Data;
     $New = $Data['_New'];
     unset($Old['_New']);
     $Old = Gdn_Configuration::Format($Old);
     $New = Gdn_Configuration::Format($New);
     $Diffs = $this->FormatDiff($Old, $New, 'raw');
     $Result = array();
     foreach ($Diffs as $Diff) {
         if (is_array($Diff)) {
             if (!empty($Diff['del'])) {
                 $Result[] = '<del>' . implode("<br />\n", $Diff['del']) . '</del>';
             }
             if (!empty($Diff['ins'])) {
                 $Result[] = '<ins>' . implode("<br />\n", $Diff['ins']) . '</ins>';
             }
         }
     }
     $Result = implode("<br />\n", $Result);
     if ($Result) {
         return $Result;
     } else {
         return T('No Change');
     }
 }
Exemple #2
0
 /**
  * Get all known core
  */
 public function GetDeveloperDefinitions()
 {
     if (!$this->DeveloperMode) {
         return FALSE;
     }
     return $this->DeveloperContainer->Get('.');
 }
 public function Configuration()
 {
     $this->Permission('Garden.Settings.Manage');
     $this->DeliveryMethod(DELIVERY_METHOD_JSON);
     $this->DeliveryType(DELIVERY_TYPE_DATA);
     $ConfigData = array('Title' => C('Garden.Title'), 'Domain' => C('Garden.Domain'), 'Cookie' => C('Garden.Cookie'), 'Theme' => C('Garden.Theme'), 'Analytics' => array('InstallationID' => C('Garden.InstallationID'), 'InstallationSecret' => C('Garden.InstallationSecret')));
     $Config = Gdn_Configuration::Format($ConfigData, array('FormatStyle' => 'Dotted', 'WrapPHP' => FALSE, 'SafePHP' => FALSE, 'Headings' => FALSE, 'ByLine' => FALSE));
     $Configuration = array();
     eval($Config);
     $this->SetData('Configuration', $Configuration);
     $this->Render();
 }
Exemple #4
0
 /**
  *
  *
  * @return bool|null
  * @throws Exception
  */
 public function save()
 {
     if (!$this->Dirty) {
         return null;
     }
     $this->EventArguments['ConfigDirty'] =& $this->Dirty;
     $this->EventArguments['ConfigNoSave'] = false;
     $this->EventArguments['ConfigType'] = $this->Type;
     $this->EventArguments['ConfigSource'] = $this->Source;
     $this->EventArguments['ConfigData'] = $this->Settings;
     $this->fireEvent('BeforeSave');
     if ($this->EventArguments['ConfigNoSave']) {
         $this->Dirty = false;
         return true;
     }
     // Check for and fire callback if one exists
     if ($this->Callback && is_callable($this->Callback)) {
         $CallbackOptions = array();
         if (!is_array($this->CallbackOptions)) {
             $this->CallbackOptions = array();
         }
         $CallbackOptions = array_merge($CallbackOptions, $this->CallbackOptions, array('ConfigDirty' => $this->Dirty, 'ConfigType' => $this->Type, 'ConfigSource' => $this->Source, 'ConfigData' => $this->Settings, 'SourceObject' => $this));
         $ConfigSaved = call_user_func($this->Callback, $CallbackOptions);
         if ($ConfigSaved) {
             $this->Dirty = false;
             return true;
         }
     }
     switch ($this->Type) {
         case 'file':
             if (empty($this->Source)) {
                 trigger_error(errorMessage('You must specify a file path to be saved.', 'Configuration', 'Save'), E_USER_ERROR);
             }
             $CheckWrite = $this->Source;
             if (!file_exists($CheckWrite)) {
                 $CheckWrite = dirname($CheckWrite);
             }
             if (!is_writable($CheckWrite)) {
                 throw new Exception(sprintf(t("Unable to write to config file '%s' when saving."), $this->Source));
             }
             $Group = $this->Group;
             $Data =& $this->Settings;
             ksort($Data);
             // Check for the case when the configuration is the group.
             if (is_array($Data) && count($Data) == 1 && array_key_exists($Group, $Data)) {
                 $Data = $Data[$Group];
             }
             // Do a sanity check on the config save.
             if ($this->Source == Gdn::config()->defaultPath()) {
                 // Log root config changes
                 try {
                     $LogData = $this->Initial;
                     $LogData['_New'] = $this->Settings;
                     LogModel::insert('Edit', 'Configuration', $LogData);
                 } catch (Exception $Ex) {
                 }
                 if (!isset($Data['Database'])) {
                     if ($Pm = Gdn::pluginManager()) {
                         $Pm->EventArguments['Data'] = $Data;
                         $Pm->EventArguments['Backtrace'] = debug_backtrace();
                         $Pm->fireEvent('ConfigError');
                     }
                     return false;
                 }
             }
             // Write config data to string format, ready for saving
             $FileContents = Gdn_Configuration::format($Data, array('VariableName' => $Group, 'WrapPHP' => true, 'ByLine' => true));
             if ($FileContents === false) {
                 trigger_error(errorMessage('Failed to define configuration file contents.', 'Configuration', 'Save'), E_USER_ERROR);
             }
             // Save to cache if we're into that sort of thing
             $FileKey = sprintf(Gdn_Configuration::CONFIG_FILE_CACHE_KEY, $this->Source);
             if ($this->Configuration && $this->Configuration->caching() && Gdn::cache()->type() == Gdn_Cache::CACHE_TYPE_MEMORY && Gdn::cache()->activeEnabled()) {
                 $CachedConfigData = Gdn::cache()->store($FileKey, $Data, array(Gdn_Cache::FEATURE_NOPREFIX => true, Gdn_Cache::FEATURE_EXPIRY => 3600));
             }
             $TmpFile = tempnam(PATH_CONF, 'config');
             $Result = false;
             if (file_put_contents($TmpFile, $FileContents) !== false) {
                 chmod($TmpFile, 0775);
                 $Result = rename($TmpFile, $this->Source);
             }
             if ($Result) {
                 if (function_exists('apc_delete_file')) {
                     // This fixes a bug with some configurations of apc.
                     @apc_delete_file($this->Source);
                 } elseif (function_exists('opcache_invalidate')) {
                     @opcache_invalidate($this->Source);
                 }
             }
             $this->Dirty = false;
             return $Result;
             break;
         case 'json':
         case 'array':
         case 'string':
             /**
              * How would these even save? String config data must be handled by
              * an event hook or callback, if at all.
              */
             $this->Dirty = false;
             return false;
             break;
     }
 }