本文整理汇总了PHP中Gdn_Format::ObjectAsArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Format::ObjectAsArray方法的具体用法?PHP Gdn_Format::ObjectAsArray怎么用?PHP Gdn_Format::ObjectAsArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Format
的用法示例。
在下文中一共展示了Gdn_Format::ObjectAsArray方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: TableDataValues
/**
* Undocumented
*
*/
function TableDataValues($Data, $TableName, $Options = False)
{
static $Cache;
if (!isset($Cache[$TableName])) {
$SQL = Gdn::SQL();
$Cache[$TableName] = $SQL->FetchTableSchema($TableName);
}
//$CoerceString = GetValue('CoerceString', $Options);
$Columns = $Cache[$TableName];
$Result = array();
$Data = Gdn_Format::ObjectAsArray($Data);
foreach ($Data as $Name => $Value) {
if (is_object($Value) || is_array($Value)) {
continue;
}
// TODO: WE CAN PUT THIS INTO CACHE
$ColumnKeys = array_keys($Columns);
$ColumnKeys = array_combine(array_map('strtolower', $ColumnKeys), $ColumnKeys);
$NameLowered = strtolower($Name);
if (array_key_exists($NameLowered, $ColumnKeys)) {
$Name = $ColumnKeys[$NameLowered];
$Field = $Columns[$Name];
$Float = array('float', 'double');
$Int = array('int', 'tinyint', 'smallint', 'mediumint', 'bigint');
if (in_array($Field->Type, $Int)) {
$Value = intval($Value);
} else {
if (in_array($Field->Type, $Float)) {
$Value = floatval($Value);
}
}
if (!is_null($Value)) {
$Value = strval($Value);
}
$Result[$Name] = $Value;
}
}
return $Result;
}
示例2: SetData
/**
* 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 = Gdn_Format::ObjectAsArray($Data);
}
} else {
if (is_array($Data)) {
$this->_DataArray = $Data;
}
}
}
示例3: Set
/**
* 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 = Gdn_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;
}
示例4: UpdateResponse
public function UpdateResponse() {
// Get the message, response, and transientkey
$Messages = TrueStripSlashes(GetValue('Messages', $_POST));
$Response = TrueStripSlashes(GetValue('Response', $_POST));
$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 = Gdn_Format::Unserialize($Messages);
if (is_array($Messages)) {
$MessageModel = new MessageModel();
foreach ($Messages as $Message) {
// Check to see if it already exists, and if not, add it.
if (is_object($Message))
$Message = Gdn_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, 'Dashboard'),
'Controller' => ArrayValue('Controller', $Message, 'Settings'),
'Method' => ArrayValue('Method', $Message, ''),
'AssetTarget' => ArrayValue('AssetTarget', $Message, 'Content'),
'CssClass' => ArrayValue('CssClass', $Message, '')
));
}
}
}
}
}
// Save some info to the configuration file
$Save = array();
// If the response wasn't empty, save it in the config
if ($Response != '')
$Save['Garden.RequiredUpdates'] = Gdn_Format::Unserialize($Response);
// Record the current update check time in the config.
$Save['Garden.UpdateCheckDate'] = time();
SaveToConfig($Save);
}
}
示例5: Themes
/**
* Theme management screen.
*/
public function Themes($ThemeFolder = '', $TransientKey = '')
{
$this->AddJsFile('addons.js');
$this->SetData('Title', T('Themes'));
$this->Permission('Garden.Themes.Manage');
$this->AddSideMenu('dashboard/settings/themes');
$Session = Gdn::Session();
$ThemeManager = new Gdn_ThemeManager();
$AvailableThemes = $ThemeManager->AvailableThemes();
$this->SetData('EnabledThemeFolder', $ThemeManager->EnabledTheme());
$this->SetData('EnabledTheme', $ThemeManager->EnabledThemeInfo());
$this->SetData('EnabledThemeName', $this->Data('EnabledTheme.Name', $this->Data('EnabledTheme.Folder')));
// 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 = Gdn_Format::Unserialize(Gdn::Config('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 ($AvailableThemes as $Theme => $Info) {
$CurrentName = ArrayValue('Name', $Info, $Theme);
if ($CurrentName == $Name && $Type == 'Theme') {
$Info['NewVersion'] = $NewVersion;
$AvailableThemes[$Theme] = $Info;
}
}
}
}
$this->SetData('AvailableThemes', $AvailableThemes);
if ($Session->ValidateTransientKey($TransientKey) && $ThemeFolder != '') {
try {
foreach ($this->Data('AvailableThemes') as $ThemeName => $ThemeInfo) {
if ($ThemeInfo['Folder'] == $ThemeFolder) {
$Session->SetPreference(array('PreviewThemeName' => '', 'PreviewThemeFolder' => ''));
// Clear out the preview
$ThemeManager->EnableTheme($ThemeName);
$this->EventArguments['ThemeName'] = $ThemeName;
$this->EventArguments['ThemeInfo'] = $ThemeInfo;
$this->FireEvent('AfterEnableTheme');
}
}
} catch (Exception $Ex) {
$this->Form->AddError($Ex);
}
if ($this->Form->ErrorCount() == 0) {
Redirect('/settings/themes');
}
}
$this->Render();
}
示例6: CleanErrorArguments
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 = Gdn_Format::ObjectAsArray($Value);
$Var[$Key] = $Value;
}
if (is_array($Value)) {
CleanErrorArguments($Var[$Key], $BlackList);
}
}
}
}
}
示例7: Themes
/**
* Themes management screen.
*
* @since 2.0.0
* @access public
* @param string $ThemeName Unique ID.
* @param string $TransientKey Security token.
*/
public function Themes($ThemeName = '', $TransientKey = '')
{
$this->AddJsFile('addons.js');
$this->SetData('Title', T('Themes'));
$this->Permission('Garden.Settings.Manage');
$this->AddSideMenu('dashboard/settings/themes');
$ThemeInfo = Gdn::ThemeManager()->EnabledThemeInfo(TRUE);
$this->SetData('EnabledThemeFolder', GetValue('Folder', $ThemeInfo));
$this->SetData('EnabledTheme', Gdn::ThemeManager()->EnabledThemeInfo());
$this->SetData('EnabledThemeName', GetValue('Name', $ThemeInfo, GetValue('Index', $ThemeInfo)));
// 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 = Gdn_Format::Unserialize(Gdn::Config('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 (Gdn::ThemeManager()->AvailableThemes() as $Theme => $Info) {
$CurrentName = ArrayValue('Name', $Info, $Theme);
if ($CurrentName == $Name && $Type == 'Theme') {
$Info['NewVersion'] = $NewVersion;
$AvailableThemes[$Theme] = $Info;
}
}
}
}
$Themes = Gdn::ThemeManager()->AvailableThemes();
uasort($Themes, array('SettingsController', '_NameSort'));
// Remove themes that are archived
$Remove = array();
foreach ($Themes as $Index => $Theme) {
$Archived = GetValue('Archived', $Theme);
if ($Archived) {
$Remove[] = $Index;
}
}
foreach ($Remove as $Index) {
unset($Themes[$Index]);
}
$this->SetData('AvailableThemes', $Themes);
if (Gdn::Session()->ValidateTransientKey($TransientKey) && $ThemeName != '') {
try {
$ThemeInfo = Gdn::ThemeManager()->GetThemeInfo($ThemeName);
if ($ThemeInfo === FALSE) {
throw new Exception(sprintf(T("Could not find a theme identified by '%s'"), $ThemeName));
}
Gdn::Session()->SetPreference(array('PreviewThemeName' => '', 'PreviewThemeFolder' => ''));
// Clear out the preview
Gdn::ThemeManager()->EnableTheme($ThemeName);
$this->EventArguments['ThemeName'] = $ThemeName;
$this->EventArguments['ThemeInfo'] = $ThemeInfo;
$this->FireEvent('AfterEnableTheme');
} catch (Exception $Ex) {
$this->Form->AddError($Ex);
}
if ($this->Form->ErrorCount() == 0) {
Redirect('/settings/themes');
}
}
$this->Render();
}
示例8: FlashHtml
function FlashHtml($Movie, $Attributes = array(), $Params = array(), $FlashVars = False)
{
static $DefaultAttributes = array('width' => 400, 'height' => 300, 'type' => 'application/x-shockwave-flash');
static $DefaultParams = array('allowfullscreen' => 'true', 'allowscriptaccess' => 'always', 'quality' => 'best', 'menu' => 'false');
// BUG: 'wmode' => 'transparent'
$ScriptRender = GetValue('ScriptRender', $Attributes, False, True);
if (!is_array($Params)) {
$Params = array();
}
$Params = array_merge($DefaultParams, $Params);
$Movie = Asset($Movie, True);
// check size
if (!array_key_exists('width', $Attributes) || !array_key_exists('height', $Attributes)) {
$ImageInfo = GetImageSize($Movie);
if ($ImageInfo != False) {
$Attributes['width'] = $ImageInfo[0];
$Attributes['height'] = $ImageInfo[1];
}
}
$Attributes = array_merge($DefaultAttributes, $Attributes);
$FlashVars = GetValue('FlashVars', $Attributes, $FlashVars, True);
if ($FlashVars != False) {
$FlashVars = Gdn_Format::ObjectAsArray($FlashVars);
$Vars = array();
foreach ($FlashVars as $Name => $Value) {
$Vars[] = $Name . '=' . $Value;
}
// encodeuricomponent
$Params['flashvars'] = implode('&', $Vars);
}
$MSIE = strpos(ArrayValue('HTTP_USER_AGENT', $_SERVER), 'MSIE') > 0;
if ($MSIE != False) {
$Mode = GetValue('wmode', $Attributes, False, True);
if ($Mode !== False) {
$Params['wmode'] = $Mode;
}
$Params['movie'] = $Movie;
$ObjectParams = '';
foreach ($Params as $Name => $Value) {
$ObjectParams .= '<param name="' . $Name . '" value="' . $Value . '" />';
}
// TODO: ADD CLASSID FOR IE
$Result = '<object' . Attribute($Attributes) . '>' . $ObjectParams . '</object>';
} else {
$Attributes['src'] = $Movie;
$Attributes = array_merge($Attributes, $Params);
$Result = '<embed' . Attribute($Attributes) . ' />';
}
if ($ScriptRender) {
$Result = JavaScript($Result, True);
}
// detect flash version you should manually
return $Result;
}
示例9: CamelizeResult
function CamelizeResult($Data, $bRemoveUnderscoreKeys = True)
{
$Data = Gdn_Format::ObjectAsArray($Data);
$Keys = array_keys($Data);
$CamelizedKeys = array_map('Camelize', $Keys);
$Keys = array_combine($Keys, $CamelizedKeys);
foreach ($Keys as $Key => $CamelizedKey) {
$Data[$CamelizedKey] = $Data[$Key];
if ($bRemoveUnderscoreKeys) {
unset($Data[$Key]);
}
}
$Data = Gdn_Format::ArrayAsObject($Data);
return $Data;
}
示例10: Themes
/**
* Theme management screen.
*/
public function Themes($ThemeFolder = '', $TransientKey = '')
{
$this->Title(T('Themes'));
$this->Permission('Garden.Themes.Manage');
$this->AddSideMenu('dashboard/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 = Gdn_Format::Unserialize(Gdn::Config('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->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
$Test = ProxyRequest(Url('/dashboard/settings/testaddon/Theme/' . $ThemeName . '/' . $Session->TransientKey() . '?DeliveryType=JSON', TRUE));
if ($Test != 'Success') {
$this->Form->AddError(sprintf(T('The theme could not be enabled because it generated a fatal error: <pre>%s</pre>'), strip_tags($Test)));
} else {
$ThemeManager->EnableTheme($ThemeName);
}
}
}
} catch (Exception $e) {
$this->Form->AddError(strip_tags($e->getMessage()));
}
if ($this->Form->ErrorCount() == 0) {
Redirect('/settings/themes');
}
}
$this->Render();
}
示例11: Set
/**
* 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.
* @return Gdn_SQLDriver $this Returns this for fluent calls
* @throws \Exception Throws an exception if an invalid type is passed for {@link $Value}.
*/
public function Set($Field, $Value = '', $EscapeString = TRUE, $CreateNewNamedParameter = TRUE)
{
$Field = Gdn_Format::ObjectAsArray($Field);
if (!is_array($Field)) {
$Field = array($Field => $Value);
}
foreach ($Field as $f => $v) {
if (is_array($v) || is_object($v)) {
throw new Exception('Invalid value type (' . gettype($v) . ') in INSERT/UPDATE statement.', 500);
} else {
if ($EscapeString) {
$NamedParameter = $this->NamedParameter($f, $CreateNewNamedParameter);
$this->_NamedParameters[$NamedParameter] = $v;
$this->_Sets[$this->EscapeIdentifier($f)] = $NamedParameter;
} else {
$this->_Sets[$this->EscapeIdentifier($f)] = $v;
}
}
}
return $this;
}