function json_decode($arg, $assoc = FALSE) { global $services_json; if (!isset($services_json)) { $services_json = new Services_JSON(); } $obj = $services_json->decode($arg); if ($assoc) { return Format::ObjectAsArray($obj); } else { return $obj; } }
/** * Assign a set of data to be displayed in the form elements. * * @param Ressource $Data A result resource or associative array containing data to be filled in */ public function SetData($Data) { if (is_object($Data) === TRUE) { // If this is a result object (/garden/library/database/class.dataset.php) // retrieve it's values as arrays if ($Data instanceof DataSet) { $ResultSet = $Data->ResultArray(); if (count($ResultSet) > 0) { $this->_DataArray = $ResultSet[0]; } } else { // Otherwise assume it is an object representation of a data row. $this->_DataArray = Format::ObjectAsArray($Data); } } else { if (is_array($Data)) { $this->_DataArray = $Data; } } }
public function UpdateResponse() { // Get the message, response, and transientkey $Messages = GetIncomingValue('Messages', ''); $Response = GetIncomingValue('Response', ''); $TransientKey = GetIncomingValue('TransientKey', ''); // If the key validates $Session = Gdn::Session(); if ($Session->ValidateTransientKey($TransientKey)) { // If messages wasn't empty if ($Messages != '') { // Unserialize them & save them if necessary $Messages = Format::Unserialize($Messages); if (is_array($Messages)) { $MessageModel = new Gdn_MessageModel(); foreach ($Messages as $Message) { // Check to see if it already exists, and if not, add it. if (is_object($Message)) { $Message = Format::ObjectAsArray($Message); } $Content = ArrayValue('Content', $Message, ''); if ($Content != '') { $Data = $MessageModel->GetWhere(array('Content' => $Content)); if ($Data->NumRows() == 0) { $MessageModel->Save(array('Content' => $Content, 'AllowDismiss' => ArrayValue('AllowDismiss', $Message, '1'), 'Enabled' => ArrayValue('Enabled', $Message, '1'), 'Application' => ArrayValue('Application', $Message, 'Garden'), 'Controller' => ArrayValue('Controller', $Message, 'Settings'), 'Method' => ArrayValue('Method', $Message, ''), 'AssetTarget' => ArrayValue('AssetTarget', $Message, 'Content'), 'CssClass' => ArrayValue('CssClass', $Message, ''))); } } } } } // Load the config file so we can save some info in it $Config = Gdn::Factory(Gdn::AliasConfig); $Config->Load(PATH_CONF . DS . 'config.php', 'Save'); // If the response wasn't empty, save it in the config if ($Response != '') { $Config->Set('Garden.RequiredUpdates', $Response); } // Record the current update check time in the config. $Config->Set('Garden.UpdateCheckDate', time()); $Config->Save(); } }
function CleanErrorArguments(&$Var, $BlackList = array('configuration', 'config', 'database', 'password')) { if (is_array($Var)) { foreach ($Var as $Key => $Value) { if (in_array(strtolower($Key), $BlackList)) { $Var[$Key] = 'SECURITY'; } else { if (is_object($Value)) { $Value = Format::ObjectAsArray($Value); $Var[$Key] = $Value; } if (is_array($Value)) { CleanErrorArguments($Var[$Key], $BlackList); } } } } }
/** * Theme management screen. */ public function Themes($ThemeFolder = '', $TransientKey = '') { $this->Title(Translate('Themes')); $this->Permission('Garden.Themes.Manage'); $this->AddSideMenu('garden/settings/themes'); $Session = Gdn::Session(); $ThemeManager = new Gdn_ThemeManager(); $this->AvailableThemes = $ThemeManager->AvailableThemes(); $this->EnabledThemeFolder = $ThemeManager->EnabledTheme(); $this->EnabledTheme = $ThemeManager->EnabledThemeInfo(); $Name = array_keys($this->EnabledTheme); $Name = ArrayValue(0, $Name, 'undefined'); $this->EnabledTheme = ArrayValue($Name, $this->EnabledTheme); $this->EnabledThemeName = ArrayValue('Name', $this->EnabledTheme, $Name); // Loop through all of the available themes and mark them if they have an update available // Retrieve the list of themes 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->AvailableThemes as $Theme => $Info) { $CurrentName = ArrayValue('Name', $Info, $Theme); if ($CurrentName == $Name && $Type == 'Theme') { $Info['NewVersion'] = $NewVersion; $this->AvailableThemes[$Theme] = $Info; } } } } if ($Session->ValidateTransientKey($TransientKey) && $ThemeFolder != '') { try { foreach ($this->AvailableThemes as $ThemeName => $ThemeInfo) { if ($ThemeInfo['Folder'] == $ThemeFolder) { $Session->SetPreference('PreviewTheme', ''); // Clear out the preview $ThemeManager->EnableTheme($ThemeName); } } } catch (Exception $e) { $this->Form->AddError(strip_tags($e->getMessage())); } if ($this->Form->ErrorCount() == 0) { Redirect('/settings/themes'); } } $this->Render(); }
/** * Adds values to the $this->_Sets collection. Allows for the inserting * and updating of values to the db. * * @param mixed $Field The name of the field to save value as. Alternately this can be an array * of $FieldName => $Value pairs, or even an object of $DataSet->Field * properties containing one rowset. * @param string $Value The value to be set in $Field. Ignored if $Field was an array or object. * @param boolean $EscapeString A boolean value indicating if the $Value(s) should be escaped or not. * @param boolean $CreateNewNamedParameter A boolean value indicating that if (a) a named parameter is being * created, and (b) that name already exists in $this->_NamedParameters * collection, then a new one should be created rather than overwriting the * existing one. */ public function Set($Field, $Value = '', $EscapeString = TRUE, $CreateNewNamedParameter = TRUE) { $Field = Format::ObjectAsArray($Field); if (!is_array($Field)) { $Field = array($Field => $Value); } foreach ($Field as $f => $v) { if (!is_object($v)) { if (!is_array($v)) { $v = array($v); } foreach ($v as $FunctionName => $Val) { if ($EscapeString === FALSE) { if (is_string($FunctionName) !== FALSE) { $this->_Sets[$this->EscapeIdentifier($f)] = $FunctionName . '(' . $Val . ')'; } else { $this->_Sets[$this->EscapeIdentifier($f)] = $Val; } } else { $NamedParameter = $this->NamedParameter($f, $CreateNewNamedParameter); $this->_NamedParameters[$NamedParameter] = $Val; $this->_Sets[$this->EscapeIdentifier($f)] = is_string($FunctionName) !== FALSE ? $FunctionName . '(' . $NamedParameter . ')' : $NamedParameter; } } } } return $this; }
/** * Returns an array of associative arrays containing the ResultSet data. * * @param string $FormatType The type of formatting to use on each of the result fields. Defaults to none. */ public function ResultArray($FormatType = '') { if ($this->_PDOStatementFetched === TRUE) { if ($this->_ResultArrayFetched === FALSE) { foreach ($this->_ResultObject as $Object) { $this->_ResultArray[] = Format::ObjectAsArray($Object); } } } else { $this->FetchAllRows(DATASET_TYPE_ARRAY); } $this->_ResultArrayFetched = TRUE; return Format::To($this->_ResultArray, $FormatType); }