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


PHP DiscussionModel::GetID方法代码示例

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


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

示例1: RefetchPageInfo

 /**
  * Re-fetch a discussion's content based on its foreign url.
  * @param type $DiscussionID
  */
 public function RefetchPageInfo($DiscussionID)
 {
     // Make sure we are posting back.
     if (!$this->Request->IsPostBack()) {
         throw PermissionException('Javascript');
     }
     // Grab the discussion.
     $Discussion = $this->DiscussionModel->GetID($DiscussionID);
     if (!$Discussion) {
         throw NotFoundException('Discussion');
     }
     // Make sure the user has permission to edit this discussion.
     $this->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $Discussion->PermissionCategoryID);
     $ForeignUrl = GetValueR('Attributes.ForeignUrl', $Discussion);
     if (!$ForeignUrl) {
         throw new Gdn_UserException(T("This discussion isn't associated with a url."));
     }
     $Stub = $this->DiscussionModel->FetchPageInfo($ForeignUrl, TRUE);
     // Save the stub.
     $this->DiscussionModel->SetField($DiscussionID, (array) $Stub);
     // Send some of the stuff back.
     if (isset($Stub['Name'])) {
         $this->JsonTarget('.PageTitle h1', Gdn_Format::Text($Stub['Name']));
     }
     if (isset($Stub['Body'])) {
         $this->JsonTarget("#Discussion_{$DiscussionID} .Message", Gdn_Format::To($Stub['Body'], $Stub['Format']));
     }
     $this->InformMessage('The page was successfully fetched.');
     $this->Render('Blank', 'Utility', 'Dashboard');
 }
开发者ID:srikarrohit,项目名称:Vanillaforums-SSO,代码行数:34,代码来源:class.discussioncontroller.php

示例2: ModerationController_SplitComments_Create

 /**
  * Add a method to the ModerationController to handle splitting comments out to a new discussion.
  */
 public function ModerationController_SplitComments_Create($Sender)
 {
     $Session = Gdn::Session();
     $Sender->Form = new Gdn_Form();
     $Sender->Title(T('Split Comments'));
     $Sender->Category = FALSE;
     $DiscussionID = GetValue('0', $Sender->RequestArgs, '');
     if (!is_numeric($DiscussionID)) {
         return;
     }
     $DiscussionModel = new DiscussionModel();
     $Discussion = $DiscussionModel->GetID($DiscussionID);
     if (!$Discussion) {
         return;
     }
     // Verify that the user has permission to perform the split
     $Sender->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $Discussion->PermissionCategoryID);
     $CheckedComments = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedComments', array());
     if (!is_array($CheckedComments)) {
         $CheckedComments = array();
     }
     $CommentIDs = array();
     foreach ($CheckedComments as $DiscID => $Comments) {
         foreach ($Comments as $Comment) {
             if ($DiscID == $DiscussionID) {
                 $CommentIDs[] = str_replace('Comment_', '', $Comment);
             }
         }
     }
     // Load category data.
     $Sender->ShowCategorySelector = (bool) C('Vanilla.Categories.Use');
     $CountCheckedComments = count($CommentIDs);
     $Sender->SetData('CountCheckedComments', $CountCheckedComments);
     // Perform the split
     if ($Sender->Form->AuthenticatedPostBack()) {
         // Create a new discussion record
         $Data = $Sender->Form->FormValues();
         $Data['Body'] = sprintf(T('This discussion was created from comments split from: %s.'), Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/' . $Discussion->DiscussionID . '/' . Gdn_Format::Url($Discussion->Name) . '/'));
         $Data['Format'] = 'Html';
         $NewDiscussionID = $DiscussionModel->Save($Data);
         $Sender->Form->SetValidationResults($DiscussionModel->ValidationResults());
         if ($Sender->Form->ErrorCount() == 0 && $NewDiscussionID > 0) {
             // Re-assign the comments to the new discussion record
             $DiscussionModel->SQL->Update('Comment')->Set('DiscussionID', $NewDiscussionID)->WhereIn('CommentID', $CommentIDs)->Put();
             // Update counts on both discussions
             $CommentModel = new CommentModel();
             $CommentModel->UpdateCommentCount($DiscussionID);
             //            $CommentModel->UpdateUserCommentCounts($DiscussionID);
             $CommentModel->UpdateCommentCount($NewDiscussionID);
             // Clear selections
             unset($CheckedComments[$DiscussionID]);
             Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedComments', $CheckedComments);
             ModerationController::InformCheckedComments($Sender);
             $Sender->RedirectUrl = Url('discussion/' . $NewDiscussionID . '/' . Gdn_Format::Url($Data['Name']));
         }
     } else {
         $Sender->Form->SetValue('CategoryID', GetValue('CategoryID', $Discussion));
     }
     $Sender->Render($this->GetView('splitcomments.php'));
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:63,代码来源:class.splitmerge.plugin.php

示例3: NotifyNewDiscussion

 public function NotifyNewDiscussion($DiscussionID)
 {
     if (!C('Vanilla.QueueNotifications')) {
         throw ForbiddenException('NotifyNewDiscussion');
     }
     if (!$this->Request->IsPostBack()) {
         throw ForbiddenException('GET');
     }
     // Grab the discussion.
     $Discussion = $this->DiscussionModel->GetID($DiscussionID);
     if (!$Discussion) {
         throw NotFoundException('Discussion');
     }
     if (GetValue('Notified', $Discussion) != ActivityModel::SENT_PENDING) {
         die('Not pending');
     }
     // Mark the notification as in progress.
     $this->DiscussionModel->SetField($DiscussionID, 'Notified', ActivityModel::SENT_INPROGRESS);
     $HeadlineFormat = T($Code, '{ActivityUserID,user} started a new discussion: <a href="{Url,html}">{Data.Name,text}</a>');
     $Category = CategoryModel::Categories(GetValue('CategoryID', $Discussion));
     $Activity = array('ActivityType' => 'Discussion', 'ActivityUserID' => $Discussion->InsertUserID, 'HeadlineFormat' => $HeadlineFormat, 'RecordType' => 'Discussion', 'RecordID' => $DiscussionID, 'Route' => DiscussionUrl($Discussion), 'Data' => array('Name' => $Discussion->Name, 'Category' => GetValue('Name', $Category)));
     $ActivityModel = new ActivityModel();
     $this->DiscussionModel->NotifyNewDiscussion($Discussion, $ActivityModel, $Activity);
     $ActivityModel->SaveQueue();
     $this->DiscussionModel->SetField($DiscussionID, 'Notified', ActivityModel::SENT_OK);
     die('OK');
 }
开发者ID:embo-hd,项目名称:vanilla,代码行数:27,代码来源:class.postcontroller.php

示例4: Award

 public function Award($Sender, $User, $Criteria)
 {
     $NecroDate = strtotime($Criteria->Duration . ' ' . $Criteria->Period . ' ago');
     // Get the last comment date from the parent discussion
     $Args = $Sender->EventArguments;
     $DiscussionID = $Args['FormPostValues']['DiscussionID'];
     $DiscussionModel = new DiscussionModel();
     $Discussion = $DiscussionModel->GetID($DiscussionID);
     $LastCommentDate = strtotime($Discussion->DateLastComment);
     if ($LastCommentDate < $NecroDate) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
开发者ID:hxii,项目名称:Application-Yaga,代码行数:15,代码来源:class.necropost.php

示例5: DiscussionController_AutoExpire_Create

 public function DiscussionController_AutoExpire_Create($Sender, $Args)
 {
     $DiscussionID = intval($Args[0]);
     $DiscussionModel = new DiscussionModel();
     $Discussion = $DiscussionModel->GetID($DiscussionID);
     if (!Gdn::Session()->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $Discussion->PermissionCategoryID)) {
         throw PermissionException('Vanilla.Discussions.Close');
     }
     if (strtolower($Args[1]) == 'reset') {
         Gdn::SQL()->Put('Discussion', array('AutoExpire' => 1, 'Closed' => 0, 'DateReOpened' => Gdn_Format::ToDateTime()), array('DiscussionID' => $DiscussionID));
     } else {
         $Expire = strtolower($Args[1]) == 'on' ? 1 : 0;
         Gdn::SQL()->Put('Discussion', array('AutoExpire' => $Expire), array('DiscussionID' => $DiscussionID));
     }
     Redirect('discussion/' . $DiscussionID . '/' . Gdn_Format::Url($Discussion->Name));
 }
开发者ID:x00,项目名称:AutoExpireDiscussions-Vanilla-Plugin,代码行数:16,代码来源:default.php

示例6: AddReplyButton

    protected function AddReplyButton($Sender)
    {
        if (!Gdn::Session()->UserID) {
            return;
        }
        if (isset($Sender->EventArguments['Comment'])) {
            $Model = new CommentModel();
            $Data = $Model->GetID($Sender->EventArguments['Comment']->CommentID);
        } else {
            $Model = new DiscussionModel();
            $Data = $Model->GetID($Sender->Data['Discussion']->DiscussionID);
        }
        $ReplyURL = "#" . "{$Data->InsertName}";
        $ReplyText = T('Reply');
        echo <<<QUOTE
      <span class="CommentReply"><a href="{$ReplyURL}">{$ReplyText}</a></span>
QUOTE;
    }
开发者ID:edward-tsai,项目名称:vanilla4china,代码行数:18,代码来源:class.reply.plugin.php

示例7: Save

 public function Save($FormPostValues)
 {
     $Session = Gdn::Session();
     // Define the primary key in this model's table.
     $this->DefineSchema();
     // Add & apply any extra validation rules:
     $this->Validation->ApplyRule('Body', 'Required');
     $MaxCommentLength = Gdn::Config('Vanilla.Comment.MaxLength');
     if (is_numeric($MaxCommentLength) && $MaxCommentLength > 0) {
         $this->Validation->SetSchemaProperty('Body', 'Length', $MaxCommentLength);
         $this->Validation->ApplyRule('Body', 'Length');
     }
     $CommentID = ArrayValue('CommentID', $FormPostValues);
     $CommentID = is_numeric($CommentID) && $CommentID > 0 ? $CommentID : FALSE;
     $Insert = $CommentID === FALSE;
     if ($Insert) {
         $this->AddInsertFields($FormPostValues);
     } else {
         $this->AddUpdateFields($FormPostValues);
     }
     // Validate the form posted values
     if ($this->Validate($FormPostValues, $Insert)) {
         // If the post is new and it validates, check for spam
         if (!$Insert || !$this->CheckForSpam('Comment')) {
             $Fields = $this->Validation->SchemaValidationFields();
             $Fields = RemoveKeyFromArray($Fields, $this->PrimaryKey);
             $DiscussionModel = new DiscussionModel();
             $DiscussionID = ArrayValue('DiscussionID', $Fields);
             $Discussion = $DiscussionModel->GetID($DiscussionID);
             if ($Insert === FALSE) {
                 $this->SQL->Put($this->Name, $Fields, array('CommentID' => $CommentID));
             } else {
                 // Make sure that the comments get formatted in the method defined by Garden
                 $Fields['Format'] = Gdn::Config('Garden.InputFormatter', '');
                 $CommentID = $this->SQL->Insert($this->Name, $Fields);
                 $this->EventArguments['CommentID'] = $CommentID;
                 // IsNewDiscussion is passed when the first comment for new discussions are created.
                 $this->EventArguments['IsNewDiscussion'] = ArrayValue('IsNewDiscussion', $FormPostValues);
                 $this->FireEvent('AfterSaveComment');
                 // Notify any users who were mentioned in the comment
                 $Usernames = GetMentions($Fields['Body']);
                 $UserModel = Gdn::UserModel();
                 $Story = ArrayValue('Body', $Fields, '');
                 $NotifiedUsers = array();
                 foreach ($Usernames as $Username) {
                     $User = $UserModel->GetByUsername($Username);
                     if ($User && $User->UserID != $Session->UserID) {
                         $NotifiedUsers[] = $User->UserID;
                         $ActivityModel = new ActivityModel();
                         $ActivityID = $ActivityModel->Add($Session->UserID, 'CommentMention', Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID), $User->UserID, '', 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID, FALSE);
                         $ActivityModel->SendNotification($ActivityID, $Story);
                     }
                 }
                 // Notify users who have bookmarked the discussion
                 $BookmarkData = $DiscussionModel->GetBookmarkUsers($DiscussionID);
                 foreach ($BookmarkData->Result() as $Bookmark) {
                     if (!in_array($Bookmark->UserID, $NotifiedUsers) && $Bookmark->UserID != $Session->UserID) {
                         $NotifiedUsers[] = $Bookmark->UserID;
                         $ActivityModel = new ActivityModel();
                         $ActivityID = $ActivityModel->Add($Session->UserID, 'BookmarkComment', Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID), $Bookmark->UserID, '', 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID, FALSE);
                         $ActivityModel->SendNotification($ActivityID, $Story);
                     }
                 }
             }
             // Record user-comment activity
             if ($Insert === TRUE && $Discussion !== FALSE && !in_array($Session->UserID, $NotifiedUsers)) {
                 $this->RecordActivity($Discussion, $Session->UserID, $CommentID);
             }
             $this->UpdateCommentCount($DiscussionID);
             // Update the discussion author's CountUnreadDiscussions (ie.
             // the number of discussions created by the user that s/he has
             // unread messages in) if this comment was not added by the
             // discussion author.
             $Data = $this->SQL->Select('d.InsertUserID')->Select('d.DiscussionID', 'count', 'CountDiscussions')->From('Discussion d')->Join('Comment c', 'd.DiscussionID = c.DiscussionID')->Join('UserDiscussion w', 'd.DiscussionID = w.DiscussionID and w.UserID = d.InsertUserID')->Where('w.CountComments >', 0)->Where('c.InsertUserID', $Session->UserID)->Where('c.InsertUserID <>', 'd.InsertUserID', TRUE, FALSE)->GroupBy('d.InsertUserID')->Get();
             if ($Data->NumRows() > 0) {
                 $UserData = $Data->FirstRow();
                 $this->SQL->Update('User')->Set('CountUnreadDiscussions', $UserData->CountDiscussions)->Where('UserID', $UserData->InsertUserID)->Put();
             }
             $this->UpdateUser($Session->UserID);
         }
     }
     return $CommentID;
 }
开发者ID:sheldon,项目名称:Garden,代码行数:83,代码来源:class.commentmodel.php

示例8: CommentModel_AfterSaveComment_Handler

 public function CommentModel_AfterSaveComment_Handler($Sender, $Args)
 {
     if (!$this->SocialSharing()) {
         return;
     }
     if (!$this->AccessToken()) {
         return;
     }
     $Share = GetValueR('FormPostValues.ShareTwitter', $Args);
     if ($Share && $this->AccessToken()) {
         $Row = $Args['FormPostValues'];
         $DiscussionModel = new DiscussionModel();
         $Discussion = $DiscussionModel->GetID(GetValue('DiscussionID', $Row));
         if (!$Discussion) {
             return;
         }
         $Url = DiscussionUrl($Discussion, '', TRUE);
         $Message = SliceTwitter(Gdn_Format::PlainText($Row['Body'], $Row['Format'])) . ' ' . $Url;
         $R = $this->API('/statuses/update.json', array('status' => $Message), 'POST');
         //         decho($R);
         //         die();
         //      } else {
         //         die("$Share ".$this->AccessToken());
     }
 }
开发者ID:robhazkes,项目名称:Garden,代码行数:25,代码来源:class.twitter.plugin.php

示例9: _HideUser

 /**
  * Checks role permissions as well as category permissions
  * and changes InsertUserID to IncognitoUserID
  *
  * @param VanillaController $Sender    Either CommentController or DiscussionController
  *
  */
 private function _HideUser($Sender)
 {
     $Session = Gdn::Session();
     // return if checkbox not send or missing role permissions
     if ($Sender->EventArguments['FormPostValues']['Incognito'] !== '1' || !$Session->CheckPermission('Plugins.Incognito.Allow')) {
         return;
     }
     if (get_class($Sender) == 'CommentModel') {
         // get CategoryID of comment
         $DiscussionModel = new DiscussionModel();
         $DiscussionID = $Sender->EventArguments['FormPostValues']['DiscussionID'];
         $Discussion = $DiscussionModel->GetID($DiscussionID);
         $CategoryID = $Discussion->CategoryID;
         $PostType = 'Comments';
     } else {
         // ... or of discussion
         $CategoryID = $Sender->EventArguments['FormPostValues']['CategoryID'];
         $PostType = 'Discussions';
     }
     // get PermissionCategoryID of CategoryID
     $CategoryModel = new CategoryModel();
     $Category = $CategoryModel->GetID($CategoryID);
     $PermissionCategoryID = $Category->PermissionCategoryID;
     // check for permissions and change InsertUserID to IncognitoUserID...
     if ($Session->CheckPermission(array('Vanilla.Comments.Add', "Vanilla.{$PostType}.Incognito"), TRUE, 'Category', $PermissionCategoryID)) {
         $IncognitoUserID = C('Plugins.Incognito.UserID', Gdn::UserModel()->GetSystemUserID());
         $Sender->EventArguments['FormPostValues']['InsertUserID'] = $IncognitoUserID;
     } else {
         // ... or stop with error message if no permissions
         $Sender->Validation->AddValidationResult('CategoryID', 'You do not have permission to Post anonymously in this category');
     }
 }
开发者ID:audist,项目名称:ista-forum,代码行数:39,代码来源:class.incognito.plugin.php

示例10: Save2

 /**
  * Insert or update meta data about the comment.
  * 
  * Updates unread comment totals, bookmarks, and activity. Sends notifications.
  * 
  * @since 2.0.0
  * @access public
  *
  * @param array $CommentID Unique ID for this comment.
  * @param int $Insert Used as a boolean for whether this is a new comment.
  * @param bool $CheckExisting Not used.
  * @param bool $IncUser Whether or not to just increment the user's comment count rather than recalculate it.
  */
 public function Save2($CommentID, $Insert, $CheckExisting = TRUE, $IncUser = FALSE)
 {
     $Session = Gdn::Session();
     $UserModel = Gdn::UserModel();
     // Load comment data
     $Fields = $this->GetID($CommentID, DATASET_TYPE_ARRAY);
     // Clear any session stashes related to this discussion
     $DiscussionModel = new DiscussionModel();
     $DiscussionID = GetValue('DiscussionID', $Fields);
     $Discussion = $DiscussionModel->GetID($DiscussionID);
     $Session->Stash('CommentForForeignID_' . GetValue('ForeignID', $Discussion));
     // Make a quick check so that only the user making the comment can make the notification.
     // This check may be used in the future so should not be depended on later in the method.
     if ($Fields['InsertUserID'] != $Session->UserID) {
         return;
     }
     // Update the discussion author's CountUnreadDiscussions (ie.
     // the number of discussions created by the user that s/he has
     // unread messages in) if this comment was not added by the
     // discussion author.
     $this->UpdateUser($Session->UserID, $IncUser && $Insert);
     if ($Insert) {
         // UPDATE COUNT AND LAST COMMENT ON CATEGORY TABLE
         if ($Discussion->CategoryID > 0) {
             $CountComments = $this->SQL->Select('CountComments', 'sum', 'CountComments')->From('Discussion')->Where('CategoryID', $Discussion->CategoryID)->Get()->FirstRow()->CountComments;
             $CategoryModel = new CategoryModel();
             $CategoryModel->SetField($Discussion->CategoryID, array('LastDiscussionID' => $DiscussionID, 'LastCommentID' => $CommentID, 'CountComments' => $CountComments, 'LastDateInserted' => $Fields['DateInserted']));
             // Update the cache.
             if ($DiscussionID && Gdn::Cache()->ActiveEnabled()) {
                 $CategoryCache = array('LastTitle' => $Discussion->Name, 'LastUserID' => $Fields['InsertUserID'], 'LastUrl' => DiscussionUrl($Discussion) . '#latest');
                 CategoryModel::SetCache($Discussion->CategoryID, $CategoryCache);
             }
         }
         // Prepare the notification queue.
         $ActivityModel = new ActivityModel();
         $HeadlineFormat = T('HeadlineFormat.Comment', '{ActivityUserID,user} commented on <a href="{Url,html}">{Data.Name,text}</a>');
         $Category = CategoryModel::Categories($Discussion->CategoryID);
         $Activity = array('ActivityType' => 'Comment', 'ActivityUserID' => $Fields['InsertUserID'], 'HeadlineFormat' => $HeadlineFormat, 'RecordType' => 'Comment', 'RecordID' => $CommentID, 'Route' => "/discussion/comment/{$CommentID}#Comment_{$CommentID}", 'Data' => array('Name' => $Discussion->Name, 'Category' => GetValue('Name', $Category)));
         // Allow simple fulltext notifications
         if (C('Vanilla.Activity.ShowCommentBody', FALSE)) {
             $Activity['Story'] = GetValue('Body', $Fields);
         }
         // Notify users who have bookmarked the discussion.
         $BookmarkData = $DiscussionModel->GetBookmarkUsers($DiscussionID);
         foreach ($BookmarkData->Result() as $Bookmark) {
             // Check user can still see the discussion.
             if (!$UserModel->GetCategoryViewPermission($Bookmark->UserID, $Discussion->CategoryID)) {
                 continue;
             }
             $Activity['NotifyUserID'] = $Bookmark->UserID;
             $ActivityModel->Queue($Activity, 'BookmarkComment', array('CheckRecord' => TRUE));
         }
         // Record user-comment activity.
         if ($Discussion != FALSE) {
             $Activity['NotifyUserID'] = GetValue('InsertUserID', $Discussion);
             $ActivityModel->Queue($Activity, 'DiscussionComment');
         }
         // Record advanced notifications.
         if ($Discussion !== FALSE) {
             $this->RecordAdvancedNotications($ActivityModel, $Activity, $Discussion);
         }
         // Notify any users who were mentioned in the comment.
         $Usernames = GetMentions($Fields['Body']);
         $NotifiedUsers = array();
         foreach ($Usernames as $i => $Username) {
             $User = $UserModel->GetByUsername($Username);
             if (!$User) {
                 unset($Usernames[$i]);
                 continue;
             }
             // Check user can still see the discussion.
             if (!$UserModel->GetCategoryViewPermission($User->UserID, $Discussion->CategoryID)) {
                 continue;
             }
             $HeadlineFormatBak = $Activity['HeadlineFormat'];
             $Activity['HeadlineFormat'] = T('HeadlineFormat.Mention', '{ActivityUserID,user} mentioned you in <a href="{Url,html}">{Data.Name,text}</a>');
             $Activity['NotifyUserID'] = $User->UserID;
             $ActivityModel->Queue($Activity, 'Mention');
             $Activity['HeadlineFormat'] = $HeadlineFormatBak;
         }
         // Throw an event for users to add their own events.
         $this->EventArguments['Comment'] = $Fields;
         $this->EventArguments['Discussion'] = $Discussion;
         $this->EventArguments['NotifiedUsers'] = array_keys(ActivityModel::$Queue);
         $this->EventArguments['MentionedUsers'] = $Usernames;
         $this->EventArguments['ActivityModel'] = $ActivityModel;
         $this->FireEvent('BeforeNotification');
//.........这里部分代码省略.........
开发者ID:remobjects,项目名称:Garden,代码行数:101,代码来源:class.commentmodel.php

示例11: Gdn_Statistics_Tick_Handler

 public function Gdn_Statistics_Tick_Handler($Sender, $Args)
 {
     $Path = GetValue('Path', $Args);
     if (preg_match('`discussion\\/(\\d+)`i', $Path, $Matches)) {
         $DiscussionID = $Matches[1];
     } elseif (preg_match('`discussion\\/comment\\/(\\d+)`i', $Path, $Matches)) {
         $CommentID = $Matches[1];
         $CommentModel = new CommentModel();
         $Comment = $CommentModel->GetID($CommentID);
         $DiscussionID = GetValue('DiscussionID', $Comment);
     }
     if (isset($DiscussionID)) {
         $DiscussionModel = new DiscussionModel();
         $Discussion = $DiscussionModel->GetID($DiscussionID);
         $DiscussionModel->AddView($DiscussionID, GetValue('CountViews', $Discussion));
     }
 }
开发者ID:ru4,项目名称:arabbnota,代码行数:17,代码来源:class.hooks.php

示例12: FormatQuote

    protected function FormatQuote($Type, $ID, &$QuoteData, $Format = FALSE)
    {
        if (!$Format) {
            $Format = C('Garden.InputFormatter');
        }
        $Type = strtolower($Type);
        $Model = FALSE;
        switch ($Type) {
            case 'comment':
                $Model = new CommentModel();
                break;
            case 'discussion':
                $Model = new DiscussionModel();
                break;
            default:
                break;
        }
        //$QuoteData = array();
        if ($Model) {
            $Data = $Model->GetID($ID);
            $NewFormat = $Format;
            if ($NewFormat == 'Wysiwyg') {
                $NewFormat = 'Html';
            }
            $QuoteFormat = $Data->Format;
            if ($QuoteFormat == 'Wysiwyg') {
                $QuoteFormat = 'Html';
            }
            // Perform transcoding if possible
            $NewBody = $Data->Body;
            if ($QuoteFormat != $NewFormat) {
                if (in_array($NewFormat, array('Html', 'Wysiwyg'))) {
                    $NewBody = Gdn_Format::To($NewBody, $QuoteFormat);
                } elseif ($QuoteFormat == 'Html' && $NewFormat == 'BBCode') {
                    $NewBody = Gdn_Format::Text($NewBody);
                } elseif ($QuoteFormat == 'Text' && $NewFormat == 'BBCode') {
                    $NewBody = Gdn_Format::Text($NewBody);
                } else {
                    $NewBody = Gdn_Format::PlainText($NewBody, $QuoteFormat);
                }
                if (!in_array($NewFormat, array('Html', 'Wysiwyg'))) {
                    Gdn::Controller()->InformMessage(sprintf(T('The quote had to be converted from %s to %s.', 'The quote had to be converted from %s to %s. Some formatting may have been lost.'), htmlspecialchars($QuoteFormat), htmlspecialchars($NewFormat)));
                }
            }
            $Data->Body = $NewBody;
            // Format the quote according to the format.
            switch ($Format) {
                case 'Html':
                    // HTML
                    $Quote = '<blockquote class="Quote" rel="' . htmlspecialchars($Data->InsertName) . '">' . $Data->Body . '</blockquote>' . "\n";
                    break;
                case 'BBCode':
                    $Author = htmlspecialchars($Data->InsertName);
                    if ($ID) {
                        $IDString = ';' . htmlspecialchars($ID);
                    }
                    $QuoteBody = $Data->Body;
                    // TODO: Strip inner quotes...
                    //                  $QuoteBody = trim(preg_replace('`(\[quote.*/quote\])`si', '', $QuoteBody));
                    $Quote = <<<BQ
[quote="{$Author}{$IDString}"]{$QuoteBody}[/quote]

BQ;
                    break;
                case 'Markdown':
                case 'Display':
                case 'Text':
                    $QuoteBody = $Data->Body;
                    // Strip inner quotes and mentions...
                    $QuoteBody = self::_StripMarkdownQuotes($QuoteBody);
                    $QuoteBody = self::_StripMentions($QuoteBody);
                    $Quote = '> ' . sprintf(T('%s said:'), '@' . $Data->InsertName) . "\n" . '> ' . str_replace("\n", "\n> ", $QuoteBody);
                    break;
                case 'Wysiwyg':
                    $Attribution = sprintf(T('%s said:'), UserAnchor($Data, NULL, array('Px' => 'Insert')));
                    $QuoteBody = $Data->Body;
                    // TODO: Strip inner quotes...
                    //                  $QuoteBody = trim(preg_replace('`(<blockquote.*/blockquote>)`si', '', $QuoteBody));
                    $Quote = <<<BLOCKQUOTE
<blockquote class="Quote">
  <div class="QuoteAuthor">{$Attribution}</div>
  <div class="QuoteText">{$QuoteBody}</div>
</blockquote>

BLOCKQUOTE;
                    break;
            }
            $QuoteData = array_merge($QuoteData, array('status' => 'success', 'body' => $Quote, 'format' => $Format, 'authorid' => $Data->InsertUserID, 'authorname' => $Data->InsertName, 'type' => $Type, 'typeid' => $ID));
        }
    }
开发者ID:Nordic-T,项目名称:vanilla-plugins,代码行数:90,代码来源:class.quotes.plugin.php

示例13: GetRecord

 function GetRecord($RecordType, $ID, $ThrowError = FALSE)
 {
     $Row = FALSE;
     switch (strtolower($RecordType)) {
         case 'discussion':
             $Model = new DiscussionModel();
             $Row = $Model->GetID($ID);
             $Row->Url = DiscussionUrl($Row);
             $Row->ShareUrl = $Row->Url;
             if ($Row) {
                 return (array) $Row;
             }
             break;
         case 'comment':
             $Model = new CommentModel();
             $Row = $Model->GetID($ID, DATASET_TYPE_ARRAY);
             if ($Row) {
                 $Row['Url'] = Url("/discussion/comment/{$ID}#Comment_{$ID}", TRUE);
                 $Model = new DiscussionModel();
                 $Discussion = $Model->GetID($Row['DiscussionID']);
                 if ($Discussion) {
                     $Discussion->Url = DiscussionUrl($Discussion);
                     $Row['ShareUrl'] = $Discussion->Url;
                     $Row['Name'] = $Discussion->Name;
                     $Row['Discussion'] = (array) $Discussion;
                 }
                 return $Row;
             }
             break;
         case 'activity':
             $Model = new ActivityModel();
             $Row = $Model->GetID($ID, DATASET_TYPE_ARRAY);
             if ($Row) {
                 $Row['Name'] = FormatString($Row['HeadlineFormat'], $Row);
                 $Row['Body'] = $Row['Story'];
                 return $Row;
             }
         default:
             throw new Gdn_UserException(sprintf("I don't know what a %s is.", strtolower($RecordType)));
     }
     if ($ThrowError) {
         throw NotFoundException($RecordType);
     } else {
         return FALSE;
     }
 }
开发者ID:edward-tsai,项目名称:vanilla4china,代码行数:46,代码来源:functions.general.php

示例14: Controller_Delete

 public function Controller_Delete($Sender)
 {
     $Session = Gdn::Session();
     $DPModel = new DiscussionPollsModel();
     $DiscussionModel = new DiscussionModel();
     $Poll = $DPModel->Get($Sender->RequestArgs[1]);
     $Discussion = $DiscussionModel->GetID($Poll->DiscussionID);
     $PollOwnerID = $Discussion->InsertUserID;
     if ($Session->CheckPermission('Plugins.DiscussionPolls.Manage') || $PollOwnerID == $Session->UserID) {
         $DPModel = new DiscussionPollsModel();
         $DPModel->Delete($Sender->RequestArgs[1]);
         $Result = 'Removed poll with id ' . $Sender->RequestArgs[1];
         if ($Sender->DeliveryType() == DELIVERY_TYPE_VIEW) {
             $Data = array('html' => $Result);
             echo json_encode($Data);
         } else {
             $Sender->SetData('PollString', $Result);
             $Sender->Render($this->ThemView('poll'));
         }
     } else {
         // throw permission exception
         throw PermissionException();
     }
 }
开发者ID:Nordic-T,项目名称:vanilla-plugins,代码行数:24,代码来源:class.discussionpolls.plugin.php

示例15: Save2

 public function Save2($CommentID, $Insert, $CheckExisting = TRUE)
 {
     $Fields = $this->GetID($CommentID, DATASET_TYPE_ARRAY);
     $Session = Gdn::Session();
     // Make a quick check so that only the user making the comment can make the notification.
     // This check may be used in the future so should not be depended on later in the method.
     if ($Fields['InsertUserID'] != $Session->UserID) {
         return;
     }
     $DiscussionModel = new DiscussionModel();
     $DiscussionID = ArrayValue('DiscussionID', $Fields);
     $Discussion = $DiscussionModel->GetID($DiscussionID);
     if ($Insert) {
         // Notify any users who were mentioned in the comment
         $Usernames = GetMentions($Fields['Body']);
         $UserModel = Gdn::UserModel();
         $Story = ArrayValue('Body', $Fields, '');
         $NotifiedUsers = array();
         foreach ($Usernames as $Username) {
             $User = $UserModel->GetByUsername($Username);
             if ($User && $User->UserID != $Session->UserID) {
                 $NotifiedUsers[] = $User->UserID;
                 $ActivityModel = new ActivityModel();
                 $ActivityID = $ActivityModel->Add($Session->UserID, 'CommentMention', Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID), $User->UserID, '', 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID, FALSE);
                 $ActivityModel->SendNotification($ActivityID, $Story);
             }
         }
         // Notify users who have bookmarked the discussion
         $BookmarkData = $DiscussionModel->GetBookmarkUsers($DiscussionID);
         foreach ($BookmarkData->Result() as $Bookmark) {
             if (!in_array($Bookmark->UserID, $NotifiedUsers) && $Bookmark->UserID != $Session->UserID) {
                 $NotifiedUsers[] = $Bookmark->UserID;
                 $ActivityModel = new ActivityModel();
                 $ActivityID = $ActivityModel->Add($Session->UserID, 'BookmarkComment', Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID), $Bookmark->UserID, '', 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID, FALSE);
                 $ActivityModel->SendNotification($ActivityID, $Story);
             }
         }
         // Record user-comment activity
         if ($Discussion !== FALSE && !in_array($Session->UserID, $NotifiedUsers)) {
             $this->RecordActivity($Discussion, $Session->UserID, $CommentID, 'Only');
         }
     }
     $this->UpdateCommentCount($DiscussionID);
     // Mark the comment read (note: add 1 to $Discussion->CountComments because this comment has been added since $Discussion was loaded)
     $this->SetWatch($Discussion, $Discussion->CountComments, $Discussion->CountComments + 1, $Discussion->CountComments + 1);
     // Update the discussion author's CountUnreadDiscussions (ie.
     // the number of discussions created by the user that s/he has
     // unread messages in) if this comment was not added by the
     // discussion author.
     $Data = $this->SQL->Select('d.InsertUserID')->Select('d.DiscussionID', 'count', 'CountDiscussions')->From('Discussion d')->Join('Comment c', 'd.DiscussionID = c.DiscussionID')->Join('UserDiscussion w', 'd.DiscussionID = w.DiscussionID and w.UserID = d.InsertUserID')->Where('w.CountComments >', 0)->Where('c.InsertUserID', $Session->UserID)->Where('c.InsertUserID <>', 'd.InsertUserID', TRUE, FALSE)->GroupBy('d.InsertUserID')->Get();
     if ($Data->NumRows() > 0) {
         $UserData = $Data->FirstRow();
         $this->SQL->Update('User')->Set('CountUnreadDiscussions', $UserData->CountDiscussions)->Where('UserID', $UserData->InsertUserID)->Put();
     }
     $this->UpdateUser($Session->UserID);
 }
开发者ID:TiGR,项目名称:Garden,代码行数:56,代码来源:class.commentmodel.php


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