当前位置: 首页>>代码示例>>PHP>>正文


PHP Gdn_Format::serialize方法代码示例

本文整理汇总了PHP中Gdn_Format::serialize方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Format::serialize方法的具体用法?PHP Gdn_Format::serialize怎么用?PHP Gdn_Format::serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Gdn_Format的用法示例。


在下文中一共展示了Gdn_Format::serialize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveToSerializedColumn

 /**
  * Saves a name/value to the user's specified $Column.
  *
  * This method throws exceptions when errors are encountered. Use try ...
  * catch blocks to capture these exceptions.
  *
  * @param string The name of the serialized column to save to. At the time of this writing there are three serialized columns on the user table: Permissions, Preferences, and Attributes.
  * @param int The UserID to save.
  * @param mixed The name of the value being saved, or an associative array of name => value pairs to be saved. If this is an associative array, the $Value argument will be ignored.
  * @param mixed The value being saved.
  */
 public function saveToSerializedColumn($Column, $UserID, $Name, $Value = '')
 {
     // Load the existing values
     $UserData = $this->getID($UserID, DATASET_TYPE_OBJECT);
     if (!$UserData) {
         throw new Exception(sprintf('User %s not found.', $UserID));
     }
     $Values = val($Column, $UserData);
     if (!is_array($Values) && !is_object($Values)) {
         $Values = @unserialize($UserData->{$Column});
     }
     // Throw an exception if the field was not empty but is also not an object or array
     if (is_string($Values) && $Values != '') {
         throw new Exception(sprintf(t('Serialized column "%s" failed to be unserialized.'), $Column));
     }
     if (!is_array($Values)) {
         $Values = array();
     }
     // Hook for plugins
     $this->EventArguments['CurrentValues'] =& $Values;
     $this->EventArguments['Column'] =& $Column;
     $this->EventArguments['UserID'] =& $UserID;
     $this->EventArguments['Name'] =& $Name;
     $this->EventArguments['Value'] =& $Value;
     $this->fireEvent('BeforeSaveSerialized');
     // Assign the new value(s)
     if (!is_array($Name)) {
         $Name = array($Name => $Value);
     }
     $RawValues = array_merge($Values, $Name);
     $Values = array();
     foreach ($RawValues as $Key => $RawValue) {
         if (!is_null($RawValue)) {
             $Values[$Key] = $RawValue;
         }
     }
     $Values = Gdn_Format::serialize($Values);
     // Save the values back to the db
     $SaveResult = $this->SQL->put('User', array($Column => $Values), array('UserID' => $UserID));
     $this->clearCache($UserID, array('user'));
     return $SaveResult;
 }
开发者ID:RodSloan,项目名称:vanilla,代码行数:53,代码来源:class.usermodel.php

示例2: handshake

 /**
  * Create secure handshake with remote authenticator.
  *
  * @access public
  * @since 2.0.?
  * @author Tim Gunter
  *
  * @param string $AuthenticationSchemeAlias (default: 'default')
  */
 public function handshake($AuthenticationSchemeAlias = 'default')
 {
     try {
         // Don't show anything if handshaking not turned on by an authenticator
         if (!Gdn::authenticator()->canHandshake()) {
             throw new Exception();
         }
         // Try to load the authenticator
         $Authenticator = Gdn::authenticator()->authenticateWith($AuthenticationSchemeAlias);
         // Try to grab the authenticator data
         $Payload = $Authenticator->getHandshake();
         if ($Payload === false) {
             Gdn::request()->withURI('dashboard/entry/auth/password');
             return Gdn::dispatcher()->dispatch();
         }
     } catch (Exception $e) {
         Gdn::request()->WithURI('/entry/signin');
         return Gdn::dispatcher()->dispatch();
     }
     $UserInfo = array('UserKey' => $Authenticator->GetUserKeyFromHandshake($Payload), 'ConsumerKey' => $Authenticator->GetProviderKeyFromHandshake($Payload), 'TokenKey' => $Authenticator->GetTokenKeyFromHandshake($Payload), 'UserName' => $Authenticator->GetUserNameFromHandshake($Payload), 'UserEmail' => $Authenticator->GetUserEmailFromHandshake($Payload));
     if (method_exists($Authenticator, 'GetRolesFromHandshake')) {
         $RemoteRoles = $Authenticator->GetRolesFromHandshake($Payload);
         if (!empty($RemoteRoles)) {
             $UserInfo['Roles'] = $RemoteRoles;
         }
     }
     // Manual user sync is disabled. No hand holding will occur for users.
     $SyncScreen = c('Garden.Authenticator.SyncScreen', 'on');
     switch ($SyncScreen) {
         case 'on':
             // Authenticator events fired inside
             $this->syncScreen($Authenticator, $UserInfo, $Payload);
             break;
         case 'off':
         case 'smart':
             $UserID = $this->UserModel->synchronize($UserInfo['UserKey'], array('Name' => $UserInfo['UserName'], 'Email' => $UserInfo['UserEmail'], 'Roles' => val('Roles', $UserInfo)));
             if ($UserID > 0) {
                 // Account created successfully.
                 // Finalize the link between the forum user and the foreign userkey
                 $Authenticator->finalize($UserInfo['UserKey'], $UserID, $UserInfo['ConsumerKey'], $UserInfo['TokenKey'], $Payload);
                 $UserEventData = array_merge(array('UserID' => $UserID, 'Payload' => $Payload), $UserInfo);
                 Gdn::authenticator()->trigger(Gdn_Authenticator::AUTH_CREATED, $UserEventData);
                 /// ... and redirect them appropriately
                 $Route = $this->redirectTo();
                 if ($Route !== false) {
                     redirect($Route);
                 } else {
                     redirect('/');
                 }
             } else {
                 // Account not created.
                 if ($SyncScreen == 'smart') {
                     $this->informMessage(t('There is already an account in this forum using your email address. Please create a new account, or enter the credentials for the existing account.'));
                     $this->syncScreen($Authenticator, $UserInfo, $Payload);
                 } else {
                     // Set the memory cookie to allow signinloopback to shortcircuit remote query.
                     $CookiePayload = array('Sync' => 'Failed');
                     $SerializedCookiePayload = Gdn_Format::serialize($CookiePayload);
                     $Authenticator->remember($UserInfo['ConsumerKey'], $SerializedCookiePayload);
                     // This resets vanilla's internal "where am I" to the homepage. Needed.
                     Gdn::request()->withRoute('DefaultController');
                     $this->SelfUrl = url('');
                     //Gdn::request()->Path();
                     $this->View = 'syncfailed';
                     $this->ProviderSite = $Authenticator->getProviderUrl();
                     $this->render();
                 }
             }
             break;
     }
 }
开发者ID:korelstar,项目名称:vanilla,代码行数:80,代码来源:class.entrycontroller.php

示例3: addUpdateCheck

 /**
  * Adds information to the definition list that causes the app to "phone
  * home" and see if there are upgrades available.
  *
  * Currently added to the dashboard only. Nothing renders with this method.
  * It is public so it can be added by plugins.
  */
 public function addUpdateCheck()
 {
     if (c('Garden.NoUpdateCheck')) {
         return;
     }
     // Check to see if the application needs to phone-home for updates. Doing
     // this here because this method is always called when admin pages are
     // loaded regardless of the application loading them.
     $UpdateCheckDate = Gdn::config('Garden.UpdateCheckDate', '');
     if ($UpdateCheckDate == '' || !IsTimestamp($UpdateCheckDate) || $UpdateCheckDate < strtotime("-1 day")) {
         $UpdateData = array();
         // Grab all of the plugins & versions
         $Plugins = Gdn::pluginManager()->availablePlugins();
         foreach ($Plugins as $Plugin => $Info) {
             $Name = val('Name', $Info, $Plugin);
             $Version = val('Version', $Info, '');
             if ($Version != '') {
                 $UpdateData[] = array('Name' => $Name, 'Version' => $Version, 'Type' => 'Plugin');
             }
         }
         // Grab all of the applications & versions
         $ApplicationManager = Gdn::factory('ApplicationManager');
         $Applications = $ApplicationManager->availableApplications();
         foreach ($Applications as $Application => $Info) {
             $Name = val('Name', $Info, $Application);
             $Version = val('Version', $Info, '');
             if ($Version != '') {
                 $UpdateData[] = array('Name' => $Name, 'Version' => $Version, 'Type' => 'Application');
             }
         }
         // Grab all of the themes & versions
         $ThemeManager = new Gdn_ThemeManager();
         $Themes = $ThemeManager->availableThemes();
         foreach ($Themes as $Theme => $Info) {
             $Name = val('Name', $Info, $Theme);
             $Version = val('Version', $Info, '');
             if ($Version != '') {
                 $UpdateData[] = array('Name' => $Name, 'Version' => $Version, 'Type' => 'Theme');
             }
         }
         // Dump the entire set of information into the definition list (jQuery
         // will pick it up and ping the VanillaForums.org server with this info).
         $this->addDefinition('UpdateChecks', Gdn_Format::serialize($UpdateData));
     }
 }
开发者ID:mcnasby,项目名称:datto-vanilla,代码行数:52,代码来源:class.settingscontroller.php

示例4: definePermissions

 /**
  * Load and compile user permissions
  *
  * @param integer $UserID
  * @param boolean $Serialize
  * @return array
  */
 public function definePermissions($UserID, $Serialize = true)
 {
     if (Gdn::cache()->activeEnabled()) {
         $PermissionsIncrement = $this->GetPermissionsIncrement();
         $UserPermissionsKey = formatString(self::USERPERMISSIONS_KEY, array('UserID' => $UserID, 'PermissionsIncrement' => $PermissionsIncrement));
         $CachePermissions = Gdn::cache()->get($UserPermissionsKey);
         if ($CachePermissions !== Gdn_Cache::CACHEOP_FAILURE) {
             return $CachePermissions;
         }
     }
     $Data = Gdn::permissionModel()->CachePermissions($UserID);
     $Permissions = UserModel::CompilePermissions($Data);
     $PermissionsSerialized = null;
     if (Gdn::cache()->activeEnabled()) {
         Gdn::cache()->store($UserPermissionsKey, $Permissions);
     } else {
         // Save the permissions to the user table
         $PermissionsSerialized = Gdn_Format::Serialize($Permissions);
         if ($UserID > 0) {
             $this->SQL->put('User', array('Permissions' => $PermissionsSerialized), array('UserID' => $UserID));
         }
     }
     if ($Serialize && is_null($PermissionsSerialized)) {
         $PermissionsSerialized = Gdn_Format::serialize($Permissions);
     }
     return $Serialize ? $PermissionsSerialized : $Permissions;
 }
开发者ID:dimassrio,项目名称:vanilla,代码行数:34,代码来源:class.usermodel.php

示例5: array

<?php

if (!defined('APPLICATION')) {
    exit;
}
/**
 * Conversations stub content for a new site.
 *
 * Called by ConversationsHooks::Setup() to insert stub content upon enabling app.
 *
 * @copyright 2009-2015 Vanilla Forums Inc.
 * @license http://www.opensource.org/licenses/gpl-2.0.php GNU GPL v2
 * @package Conversations
 * @since 2.2
 */
// Only do this once, ever.
if (!$Drop) {
    return;
}
$SQL = Gdn::database()->sql();
// Prep default content
$ConversationBody = "Pssst. Hey. A conversation is a private chat between two or more members. No one can see it except the members added. You can delete this one since I&rsquo;m just a bot and know better than to talk back.";
$SystemUserID = Gdn::userModel()->getSystemUserID();
$TargetUserID = Gdn::session()->UserID;
$Now = Gdn_Format::toDateTime();
$Contributors = Gdn_Format::serialize(array($SystemUserID, $TargetUserID));
// Insert stub conversation
$ConversationID = $SQL->insert('Conversation', array('InsertUserID' => $SystemUserID, 'DateInserted' => $Now, 'Contributors' => $Contributors, 'CountMessages' => 1));
$MessageID = $SQL->insert('ConversationMessage', array('ConversationID' => $ConversationID, 'Body' => t('StubConversationBody', $ConversationBody), 'Format' => 'Html', 'InsertUserID' => $SystemUserID, 'DateInserted' => $Now));
$SQL->update('Conversation')->set('LastMessageID', $MessageID)->where('ConversationID', $ConversationID)->put();
$SQL->insert('UserConversation', array('ConversationID' => $ConversationID, 'UserID' => $TargetUserID, 'CountReadMessages' => 0, 'LastMessageID' => $MessageID, 'DateConversationUpdated' => $Now));
开发者ID:korelstar,项目名称:vanilla,代码行数:31,代码来源:stub.php

示例6: saveToSerializedColumn

 /**
  *
  *
  * @param string $Column
  * @param int $RowID
  * @param string $Name
  * @param string $Value
  * @return bool|Gdn_DataSet|object|string
  * @throws Exception
  */
 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(T('ErrorRecordNotFound'));
     }
     $Values = Gdn_Format::unserialize($Row->{$Column});
     if (is_string($Values) && $Values != '') {
         throw new Exception(T('Serialized column failed to be unserialized.'));
     }
     if (!is_array($Values)) {
         $Values = array();
     }
     if (!is_array($Name)) {
         // Assign the new value(s)
         $Name = array($Name => $Value);
     }
     $Values = Gdn_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();
 }
开发者ID:karanjitsingh,项目名称:iecse-forum,代码行数:37,代码来源:class.model.php


注:本文中的Gdn_Format::serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。