public function Check($Type = '', $Name = '') { if ($Type != '' && $Name != '') { $this->AddItem($Type, $Name); } if (count($this->_Items) > 0) { // TODO: Use garden update check url instead of this: $UpdateUrl = Url('/lussumo/update', TRUE, TRUE); $Host = Gdn_Url::Host(); $Path = CombinePaths(array(Gdn_Url::WebRoot(), 'lussumo', 'update'), '/'); $Port = 80; /* $UpdateUrl = Gdn::Config('Garden.UpdateCheckUrl', ''); $UpdateUrl = parse_url($UpdateUrl); $Host = ArrayValue('host', $UpdateUrl, 'www.lussumo.com'); $Path = ArrayValue('path', $UpdateUrl, '/'); $Port = ArrayValue('port', $UpdateUrl, '80'); */ $Path .= '?Check=' . urlencode(Format::Serialize($this->_Items)); $Locale = Gdn::Config('Garden.Locale', 'Undefined'); $Referer = Gdn_Url::WebRoot(TRUE); if ($Referer === FALSE) { $Referer = 'Undefined'; } $Timeout = 10; $Response = ''; // Connect to the update server. $Pointer = @fsockopen($Host, '80', $ErrorNumber, $Error, $Timeout); if (!$Pointer) { throw new Exception(sprintf(Gdn::Translate('Encountered an error when attempting to connect to the update server (%1$s): [%2$s] %3$s'), $UpdateUrl, $ErrorNumber, $Error)); } else { // send the necessary headers to get the file fputs($Pointer, "GET {$Path} HTTP/1.0\r\n" . "Host: {$Host}\r\n" . "User-Agent: Lussumo Garden/1.0\r\n" . "Accept: */*\r\n" . "Accept-Language: " . $Locale . "\r\n" . "Accept-Charset: utf-8;\r\n" . "Keep-Alive: 300\r\n" . "Connection: keep-alive\r\n" . "Referer: {$Referer}\r\n\r\n"); // Retrieve the response from the remote server while ($Line = fread($Pointer, 4096)) { $Response .= $Line; } fclose($Pointer); // Remove response headers $Response = substr($Response, strpos($Response, "\r\n\r\n") + 4); } $Result = Format::Unserialize($Response); // print_r($Result); if (is_array($Result)) { $this->_Items = $Result; } else { $Result = FALSE; } return $Result; } }
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(); } }
public function GetAttribute($UserID, $Attribute, $DefaultValue = FALSE) { $Data = $this->SQL->Select('Attributes')->From('User')->Where('UserID', $UserID)->Get()->FirstRow(); if ($Data !== FALSE) { $Attributes = Format::Unserialize($Data->Attributes); if (is_array($Attributes)) { return ArrayValue($Attribute, $Attributes, $DefaultValue); } } return $DefaultValue; }
/** * 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(); }
/** * Gets a setting from the configuration array. Returns $DefaultValue if the value isn't found. * * @param string $Name The name of the configuration setting to get. If the setting is contained * within an associative array, use dot denomination to get the setting. ie. * <code>$this->Get('Database.Host')</code> would retrieve <code>$Configuration[$Group]['Database']['Host']</code>. * @param mixed $DefaultValue If the parameter is not found in the group, this value will be returned. * @return mixed The configuration value. */ public function Get($Name, $DefaultValue = FALSE) { $Path = explode('.', $Name); $Value = $this->_Data; $Count = count($Path); for ($i = 0; $i < $Count; ++$i) { if (is_array($Value) && array_key_exists($Path[$i], $Value)) { $Value = $Value[$Path[$i]]; } else { return $DefaultValue; } } if (is_string($Value)) { $Result = Format::Unserialize($Value); } else { $Result = $Value; } return $Result; }
/** * Authenticates the user with the provided Authenticator class. * * @param Gdn_IAuthenticator $Authenticator The authenticator used to identify the user making the request. */ function Start($Authenticator) { // Retrieve the authenticated UserID from the Authenticator module. $UserModel = Gdn::UserModel(); $this->UserID = $Authenticator->GetIdentity(); $this->User = FALSE; // Now retrieve user information if ($this->UserID > 0) { // Instantiate a UserModel to get session info $this->User = $UserModel->GetSession($this->UserID); $UserModel->EventArguments['User'] =& $this->User; $UserModel->FireEvent('AfterGetSession'); if ($this->User) { $this->_Permissions = Format::Unserialize($this->User->Permissions); $this->_Preferences = Format::Unserialize($this->User->Preferences); $this->_Attributes = Format::Unserialize($this->User->Attributes); $this->_TransientKey = is_array($this->_Attributes) ? ArrayValue('TransientKey', $this->_Attributes) : FALSE; if ($this->_TransientKey === FALSE) { $this->_TransientKey = $UserModel->SetTransientKey($this->UserID); } // If the user hasn't been active in the session-time, update their date last active $SessionLength = Gdn::Config('Garden.Session.Length', '15 minutes'); if (Format::ToTimestamp($this->User->DateLastActive) < strtotime($SessionLength . ' ago')) { $UserModel->Save(array('UserID' => $this->UserID, 'DateLastActive' => Format::ToDateTime())); } } else { $this->UserID = 0; $this->User = FALSE; $Authenticator->DeAuthenticate(); } } // Load guest permissions if necessary if ($this->UserID == 0) { $this->_Permissions = Format::Unserialize($UserModel->DefinePermissions(0)); } }
public function SendNotification($ActivityID, $Story = '') { $Activity = $this->GetID($ActivityID); if (!is_object($Activity)) { return; } $Story = Format::Text($Story == '' ? $Activity->Story : $Story); // If this is a comment on another activity, fudge the activity a bit so that everything appears properly. if (is_null($Activity->RegardingUserID) && $Activity->CommentActivityID > 0) { $CommentActivity = $this->GetID($Activity->CommentActivityID); $Activity->RegardingUserID = $CommentActivity->RegardingUserID; $Activity->Route = '/profile/' . $CommentActivity->RegardingUserID . '/' . Format::Url($CommentActivity->RegardingName) . '/#Activity_' . $Activity->CommentActivityID; } $User = $this->SQL->Select('Name, Email, Preferences')->From('User')->Where('UserID', $Activity->RegardingUserID)->Get()->FirstRow(); if ($User) { $Preferences = Format::Unserialize($User->Preferences); $Preference = ArrayValue('Email.' . $Activity->ActivityType, $Preferences, Gdn::Config('Preferences.Email.' . $Activity->ActivityType)); if ($Preference) { $ActivityHeadline = Format::Text(Format::ActivityHeadline($Activity, $Activity->ActivityUserID, $Activity->RegardingUserID)); $Email = new Gdn_Email(); $Email->Subject(sprintf(T('[%1$s] %2$s'), Gdn::Config('Garden.Title'), $ActivityHeadline)); $Email->To($User->Email, $User->Name); $Email->From(Gdn::Config('Garden.SupportEmail'), Gdn::Config('Garden.SupportName')); $Email->Message(sprintf(T($Story == '' ? 'EmailNotification' : 'EmailStoryNotification'), $ActivityHeadline, Url($Activity->Route == '' ? '/' : $Activity->Route, TRUE), $Story)); try { $Email->Send(); } catch (Exception $ex) { // Don't do anything with the exception. } } } }
public function Preferences($UserReference = '') { $Session = Gdn::Session(); $this->Permission('Garden.SignIn.Allow'); $this->GetUserInfo($UserReference); $UserPrefs = Format::Unserialize($this->User->Preferences); if (!is_array($UserPrefs)) { $UserPrefs = array(); } // Define the preferences to be managed $this->Preferences = array('Email Notifications' => array('Email.WallComment' => Gdn::Translate('Notify me when people write on my wall.'), 'Email.ActivityComment' => Gdn::Translate('Notify me when people reply to my wall comments.'))); $this->FireEvent('AfterPreferencesDefined'); if ($this->User->UserID != $Session->UserID) { $this->Permission('Garden.Users.Edit'); } if ($this->Form->AuthenticatedPostBack() === FALSE) { // Loop the preferences, setting defaults from the configuration $Defaults = array(); foreach ($this->Preferences as $PrefGroup => $Prefs) { foreach ($Prefs as $Pref => $Desc) { $Defaults[$Pref] = ArrayValue($Pref, $UserPrefs, Gdn::Config('Preferences.' . $Pref, '0')); } } $this->Form->SetData($Defaults); } else { // Get, assign, and save the preferences foreach ($this->Preferences as $PrefGroup => $Prefs) { foreach ($Prefs as $Pref => $Desc) { $UserPrefs[$Pref] = $this->Form->GetValue($Pref, '0'); } } $this->UserModel->SavePreference($this->User->UserID, $UserPrefs); $this->StatusMessage = Translate("Your preferences have been saved."); } $this->Render(); }
public function SaveToSerializedColumn($Column, $RowID, $Name, $Value = '') { if (!isset($this->Schema)) { $this->DefineSchema(); } // TODO: need to be sure that $this->PrimaryKey is only one primary key $FieldName = $this->PrimaryKey; // Load the existing values $Row = $this->SQL->Select($Column)->From($this->Name)->Where($FieldName, $RowID)->Get()->FirstRow(); if (!$Row) { throw new Exception(Gdn::Translate('ErrorRecordNotFound')); } $Values = Format::Unserialize($Row->{$Column}); if (is_string($Values) && $Values != '') { throw new Exception(Gdn::Translate('Serialized column failed to be unserialized.')); } if (!is_array($Values)) { $Values = array(); } if (!is_array($Name)) { $Name = array($Name => $Value); } // Assign the new value(s) $Values = Format::Serialize(array_merge($Values, $Name)); // Save the values back to the db return $this->SQL->From($this->Name)->Where($FieldName, $RowID)->Set($Column, $Values)->Put(); }