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


PHP Gdn::session方法代码示例

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


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

示例1: informNotifications

 /**
  * Grabs all new notifications and adds them to the sender's inform queue.
  *
  * This method gets called by dashboard's hooks file to display new
  * notifications on every pageload.
  *
  * @since 2.0.18
  * @access public
  *
  * @param Gdn_Controller $Sender The object calling this method.
  */
 public static function informNotifications($Sender)
 {
     $Session = Gdn::session();
     if (!$Session->isValid()) {
         return;
     }
     $ActivityModel = new ActivityModel();
     // Get five pending notifications.
     $Where = array('NotifyUserID' => Gdn::session()->UserID, 'Notified' => ActivityModel::SENT_PENDING);
     // If we're in the middle of a visit only get very recent notifications.
     $Where['DateUpdated >'] = Gdn_Format::toDateTime(strtotime('-5 minutes'));
     $Activities = $ActivityModel->getWhere($Where, 0, 5)->resultArray();
     $ActivityIDs = array_column($Activities, 'ActivityID');
     $ActivityModel->setNotified($ActivityIDs);
     $Sender->EventArguments['Activities'] =& $Activities;
     $Sender->fireEvent('InformNotifications');
     foreach ($Activities as $Activity) {
         if ($Activity['Photo']) {
             $UserPhoto = anchor(img($Activity['Photo'], array('class' => 'ProfilePhotoMedium')), $Activity['Url'], 'Icon');
         } else {
             $UserPhoto = '';
         }
         $Excerpt = Gdn_Format::plainText($Activity['Story']);
         $ActivityClass = ' Activity-' . $Activity['ActivityType'];
         $Sender->informMessage($UserPhoto . Wrap($Activity['Headline'], 'div', array('class' => 'Title')) . Wrap($Excerpt, 'div', array('class' => 'Excerpt')), 'Dismissable AutoDismiss' . $ActivityClass . ($UserPhoto == '' ? '' : ' HasIcon'));
     }
 }
开发者ID:austins,项目名称:vanilla,代码行数:38,代码来源:class.notificationscontroller.php

示例2: smarty_function_signin_link

/**
 *
 *
 * @param array $Params
 * @param object $Smarty
 * @return string
 */
function smarty_function_signin_link($Params, &$Smarty)
{
    if (!Gdn::session()->isValid()) {
        $Wrap = val('wrap', $Params, 'li');
        return Gdn_Theme::link('signinout', val('text', $Params, ''), val('format', $Params, wrap('<a href="%url" rel="nofollow" class="%class">%text</a>', $Wrap)), $Params);
    }
}
开发者ID:sitexa,项目名称:vanilla,代码行数:14,代码来源:function.signin_link.php

示例3: delete

 /**
  * Delete a single draft.
  *
  * Redirects user back to Index unless DeliveryType is set.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $DraftID Unique ID of draft to be deleted.
  * @param string $TransientKey Single-use hash to prove intent.
  */
 public function delete($DraftID = '', $TransientKey = '')
 {
     $Form = Gdn::Factory('Form');
     $Session = Gdn::session();
     if (is_numeric($DraftID) && $DraftID > 0 && $Session->UserID > 0 && $Session->validateTransientKey($TransientKey)) {
         // Delete the draft
         $Draft = $this->DraftModel->getID($DraftID);
         if ($Draft && !$this->DraftModel->delete($DraftID)) {
             $Form->addError('Failed to delete discussion');
         }
     } else {
         // Log an error
         $Form->addError('ErrPermission');
     }
     // Redirect
     if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
         $Target = GetIncomingValue('Target', '/drafts');
         redirect($Target);
     }
     // Return any errors
     if ($Form->errorCount() > 0) {
         $this->setJson('ErrorMessage', $Form->errors());
     }
     // Render default view
     $this->render();
 }
开发者ID:karanjitsingh,项目名称:iecse-forum,代码行数:37,代码来源:class.draftscontroller.php

示例4: delete

 /**
  * Delete a single draft.
  *
  * Redirects user back to Index unless DeliveryType is set.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $DraftID Unique ID of draft to be deleted.
  * @param string $TransientKey Single-use hash to prove intent.
  */
 public function delete($DraftID = '', $TransientKey = '')
 {
     $Form = Gdn::factory('Form');
     $Session = Gdn::session();
     if (is_numeric($DraftID) && $DraftID > 0) {
         $Draft = $this->DraftModel->getID($DraftID);
     }
     if ($Draft) {
         if ($Session->validateTransientKey($TransientKey) && (val('InsertUserID', $Draft) == $Session->UserID || checkPermission('Garden.Community.Manage'))) {
             // Delete the draft
             if (!$this->DraftModel->deleteID($DraftID)) {
                 $Form->addError('Failed to delete draft');
             }
         } else {
             throw permissionException('Garden.Community.Manage');
         }
     } else {
         throw notFoundException('Draft');
     }
     // Redirect
     if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
         $Target = GetIncomingValue('Target', '/drafts');
         redirect($Target);
     }
     // Return any errors
     if ($Form->errorCount() > 0) {
         $this->setJson('ErrorMessage', $Form->errors());
     }
     // Render default view
     $this->render();
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:42,代码来源:class.draftscontroller.php

示例5: authenticateRequest

 /**
  * Token-based, per-request authentication
  *
  * This method takes the entire request string and turns the query into an
  * array of data. It then uses all the data to generate a signature the same
  * way it got generated on the client. If the server signature and client
  * token match, the client is considered legimate and the request is served.
  *
  * Based on initial work by Diego Zanella
  * @link http://careers.stackoverflow.com/diegozanella
  *
  * @since  0.1.0
  * @access public
  * @throws Exception
  * @return void
  * @static
  */
 public static function authenticateRequest()
 {
     $username = getIncomingValue("username");
     $email = getIncomingValue("email");
     if (!$username && !$email) {
         throw new Exception(t("API.Error.User.Missing"), 401);
     }
     if (!($userID = static::getUserID($username, $email))) {
         throw new Exception(t("API.Error.User.Invalid"), 401);
     }
     if (!($timestamp = getIncomingValue("timestamp"))) {
         throw new Exception(t("API.Error.Timestamp.Missing"), 401);
     }
     // Make sure that request is still valid
     if (abs($timestamp - time()) > c("API.Expiration")) {
         throw new Exception(t("API.Error.Timestamp.Invalid"), 401);
     }
     if (!($token = getIncomingValue("token"))) {
         throw new Exception(t("API.Error.Token.Missing"), 401);
     }
     $parsedUrl = parse_url(Gdn::request()->pathAndQuery());
     // Turn the request query data into an array to be used in the token
     // generation
     parse_str(val("query", $parsedUrl, []), $data);
     // Unset the values we don't want to include in the token generation
     unset($data["token"], $data["DeliveryType"], $data["DeliveryMethod"]);
     if ($token != ($signature = static::generateSignature($data))) {
         throw new Exception(t("API.Error.Token.Invalid"), 401);
     }
     // Now that the client has been thoroughly verified, start a session for
     // the duration of the request using the User ID specified earlier
     if ($token == $signature) {
         Gdn::session()->start(intval($userID), false);
     }
 }
开发者ID:hcxiong,项目名称:vanilla-api,代码行数:52,代码来源:class.apiauth.php

示例6: smarty_function_custom_menu

/**
 * A placeholder for future menu items.
 *
 * @param array $Params The parameters passed into the function.
 * @param Smarty $Smarty The smarty object rendering the template.
 * @return string
 */
function smarty_function_custom_menu($Params, &$Smarty)
{
    $Controller = $Smarty->Controller;
    if (is_object($Menu = val('Menu', $Controller))) {
        $Format = val('format', $Params, wrap('<a href="%url" class="%class">%text</a>', val('wrap', $Params, 'li')));
        $Result = '';
        foreach ($Menu->Items as $Group) {
            foreach ($Group as $Item) {
                // Make sure the item is a custom item.
                if (valr('Attributes.Standard', $Item)) {
                    continue;
                }
                // Make sure the user has permission for the item.
                if ($Permission = val('Permission', $Item)) {
                    if (!Gdn::session()->checkPermission($Permission)) {
                        continue;
                    }
                }
                if (($Url = val('Url', $Item)) && ($Text = val('Text', $Item))) {
                    $Attributes = val('Attributes', $Item);
                    $Result .= Gdn_Theme::link($Url, $Text, $Format, $Attributes) . "\r\n";
                }
            }
        }
        return $Result;
    }
    return '';
}
开发者ID:caidongyun,项目名称:vanilla,代码行数:35,代码来源:function.custom_menu.php

示例7: getOptions

 /**
  * Render options that the user has for this category.
  */
 function getOptions($Category)
 {
     if (!Gdn::session()->isValid()) {
         return;
     }
     $Sender = Gdn::controller();
     $Result = '';
     $Options = '';
     $CategoryID = val('CategoryID', $Category);
     $Result = '<div class="Options">';
     $TKey = urlencode(Gdn::session()->TransientKey());
     // Mark category read.
     $Options .= '<li rel="MarkRead">' . anchor(t('Mark Read'), "/category/markread?categoryid={$CategoryID}&tkey={$TKey}") . '</li>';
     // Follow/Unfollow category.
     if (!val('Following', $Category)) {
         $Options .= '<li rel="Hide">' . anchor(t('Unhide'), "/category/follow?categoryid={$CategoryID}&value=1&tkey={$TKey}") . '</li>';
     } else {
         $Options .= '<li rel="Hide">' . anchor(t('Hide'), "/category/follow?categoryid={$CategoryID}&value=0&tkey={$TKey}") . '</li>';
     }
     // Allow plugins to add options
     $Sender->EventArguments['Options'] =& $Options;
     $Sender->fireEvent('CategoryOptions');
     if ($Options != '') {
         $Result .= '<span class="ToggleFlyout OptionsMenu">';
         $Result .= '<span class="OptionsTitle">' . t('Options') . '</span>';
         $Result .= '<span class="SpFlyoutHandle"></span>';
         $Result .= '<ul class="Flyout MenuItems">' . $Options . '</ul>';
         $Result .= '</span>';
         $Result .= '</div>';
         return $Result;
     }
 }
开发者ID:caidongyun,项目名称:vanilla,代码行数:35,代码来源:helper_functions.php

示例8: discussionModel_beforeSaveDiscussion_handler

 /**
  * Do some validations before discussion is saved.
  *
  * @param object $sender DiscussionModel.
  * @param array $args EventArguments.
  * @return void.
  * @package TwitterBot
  * @since 0.1
  */
 public function discussionModel_beforeSaveDiscussion_handler($sender, $args)
 {
     // If "Publish on Twitter" is unchecked, no sanity checks must be done
     if (!$args['FormPostValues']['TwitterBot']) {
         return;
     }
     // Check if plugin is configured
     $consumerKey = Gdn::config('TwitterBot.ConsumerKey');
     $consumerSecret = Gdn::config('TwitterBot.ConsumerSecret');
     $oAuthAccessToken = Gdn::config('TwitterBot.OAuthAccessToken');
     $oAuthAccessTokenSecret = Gdn::config('TwitterBot.OAuthAccessTokenSecret');
     if (!$consumerKey || !$consumerSecret || !$oAuthAccessToken || !$oAuthAccessTokenSecret) {
         return;
     }
     // Check for role permissions
     $roleIds = array_keys(Gdn::userModel()->getRoles(Gdn::session()->UserID));
     if (array_intersect($roles, Gdn::config('TwitterBot.RoleIDs'))) {
         // Don't give feedback since this is only true on error or if
         // user has spoofed post data. Desired result is that discussion is
         // posted to forum without issues but not on Twitter.
         return;
     }
     // Check for allowed category
     $categoryID = $args['FormPostValues']['CategoryID'];
     if (!in_array($categoryID, Gdn::config('TwitterBot.CategoryIDs'))) {
         $sender->Validation->addValidationResult('CategoryID', 'Discussions in this category will not be published on Twitter. Please uncheck "Publish on Twitter" or choose a valid category.');
     }
     // Check for restriction to announcements
     if (Gdn::config('TwitterBot.AnnouncementsOnly') && !$args['FormPostValues']['Announce']) {
         $sender->Validation->addValidationResult('Publish on Twitter', 'Only Announcements will be published on Twitter. Either make this an Announcement or uncheck the "Publich on Twitter" checkbox.');
     }
 }
开发者ID:bhu1st,项目名称:TwitterBot,代码行数:41,代码来源:class.twitterbot.plugin.php

示例9: toString

 /**
  * Render.
  *
  * @return string
  */
 public function toString()
 {
     if (!Gdn::session()->isValid()) {
         return parent::ToString();
     }
     return '';
 }
开发者ID:caidongyun,项目名称:vanilla,代码行数:12,代码来源:class.guestmodule.php

示例10: toString

 public function toString()
 {
     $HasPermission = Gdn::session()->checkPermission('Vanilla.Discussions.Add', true, 'Category', 'any');
     if ($HasPermission) {
         echo anchor(t('Ask a Question'), '/post/discussion?Type=Question', 'Button BigButton NewQuestion');
     }
 }
开发者ID:vanilla,项目名称:addons,代码行数:7,代码来源:class.newquestionmodule.php

示例11: register

 /**
  * Register API endpoints
  *
  * @since  0.1.0
  * @access public
  * @param  array $data
  * @return void
  * @static
  */
 public static function register($data)
 {
     static::get("/", ["controller" => "Messages", "method" => "all", "authenticate" => true, "arguments" => ["Page" => val("Page", $data)]]);
     static::get("/[i:ConversationID]", ["controller" => "Messages", "authenticate" => true, "arguments" => ["Offset" => val("Offset", $data), "Limit" => val("Limit", $data)]]);
     static::post("/", ["controller" => "Messages", "method" => "add"]);
     static::post("/[i:ConversationID]/messages", ["controller" => "Messages", "method" => "addMessage"]);
     static::delete("/[i:ConversationID]", ["controller" => "Messages", "method" => "clear", "arguments" => ["TransientKey" => Gdn::session()->transientKey()]]);
 }
开发者ID:Nordic-T,项目名称:nt-vanilla,代码行数:17,代码来源:class.conversationsapi.php

示例12: base_afterBody_handler

 /**
  * Add Debugger info to every page.
  *
  * @param $Sender
  */
 public function base_afterBody_handler($Sender)
 {
     $Session = Gdn::session();
     if (!Debug() && !$Session->checkPermission('Plugins.Debugger.View')) {
         return;
     }
     require $Sender->fetchViewLocation('Debug', '', 'plugins/Debugger');
 }
开发者ID:oMadMartigaNo,项目名称:readjust-forum,代码行数:13,代码来源:default.php

示例13: getData

 public function getData($Limit = 20, $DiscussionID = '')
 {
     $Session = Gdn::session();
     if ($Session->isValid()) {
         $DraftModel = new DraftModel();
         $this->Data = $DraftModel->get($Session->UserID, 0, $Limit, $DiscussionID);
     }
     $this->Form = $this->_Sender->Form;
 }
开发者ID:karanjitsingh,项目名称:iecse-forum,代码行数:9,代码来源:class.draftsmodule.php

示例14: register

 /**
  * Register API endpoints
  *
  * @since  0.1.0
  * @access public
  * @param  array $data
  * @return void
  * @static
  */
 public static function register($data)
 {
     static::get("/", ["controller" => "Activity"]);
     static::get("/[i:ActivityID]", ["controller" => "Activity", "method" => "item"]);
     static::post("/", ["controller" => "Activity", "method" => "post", "arguments" => ["Notify" => val("Notify", $data)]]);
     static::post("/[i:ActivityID]/comments", ["controller" => "Activity", "method" => "comment"]);
     static::delete("/[i:ActivityID]", ["controller" => "Activity", "method" => "delete", "arguments" => ["TransientKey" => Gdn::session()->transientKey()]]);
     static::delete("/comments/[i:ID]", ["controller" => "Activity", "method" => "deleteComment", "arguments" => ["TK" => Gdn::session()->transientKey()]]);
 }
开发者ID:Nordic-T,项目名称:nt-vanilla,代码行数:18,代码来源:class.activitiesapi.php

示例15: base_afterRenderAsset_handler

 /**
  * Add Debugger info to dashboard after content asset.
  *
  * @param $sender
  * @param $args
  */
 public function base_afterRenderAsset_handler($sender, $args)
 {
     if (val('AssetName', $args) == 'Content' && $sender->MasterView == 'admin') {
         $session = Gdn::session();
         if (!Debug() || !$session->checkPermission('Plugins.Debugger.View')) {
             return;
         }
         require $sender->fetchViewLocation('Debug', '', 'plugins/Debugger');
     }
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:16,代码来源:default.php


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