protected function Build() { $DiscussionModel = new DiscussionModel(); $Offset = 0; $Limit = 1000; while ($Discussions = $DiscussionModel->Get($Offset, $Limit)) { if (!$Discussions->NumRows()) { break; } $Offset += $Discussions->NumRows(); $Day = 24 * 3600; $Week = 7 * $Day; $Month = 4 * $Week; $Year = 12 * $Month; $PriorityMatrix = array('hourly' => 1, 'daily' => 0.8, 'weekly' => 0.6, 'monthly' => 0.4, 'yearly' => 0.2); while ($Discussion = $Discussions->NextRow()) { $ChangeFreq = 'hourly'; $DiffDate = time() - strtotime($Discussion->DateLastComment); $Priority = 1; if ($DiffDate < $Day) { $ChangeFreq = 'hourly'; } elseif ($DiffDate < $Week) { $ChangeFreq = 'daily'; } elseif ($DiffDate < $Month) { $ChangeFreq = 'weekly'; } elseif ($DiffDate < $Year) { $ChangeFreq = 'monthly'; } else { $ChangeFreq = 'yearly'; } $this->MapItem(DiscussionLink($Discussion, FALSE), date('Y-m-d', strtotime($Discussion->DateLastComment)), $ChangeFreq, $PriorityMatrix[$ChangeFreq]); } } $this->WriteIndex(); }
public function GetData($Limit = 10) { $this->Data = FALSE; if (Gdn::Session()->IsValid() && C('Vanilla.Modules.ShowBookmarkedModule', TRUE)) { $BookmarkIDs = Gdn::SQL() ->Select('DiscussionID') ->From('UserDiscussion') ->Where('UserID', Gdn::Session()->UserID) ->Where('Bookmarked', 1) ->Get()->ResultArray(); $BookmarkIDs = ConsolidateArrayValuesByKey($BookmarkIDs, 'DiscussionID'); if (count($BookmarkIDs)) { $DiscussionModel = new DiscussionModel(); DiscussionModel::CategoryPermissions(); $DiscussionModel->SQL->WhereIn('d.DiscussionID', $BookmarkIDs); $this->Data = $DiscussionModel->Get( 0, $Limit ); } else { $this->Data = FALSE; } } }
public function DiscussionsController_Participated_Create(&$Sender, $Args) { $Sender->Permission('Garden.SignIn.Allow'); $Page = GetValue(0, $Args); $Limit = GetValue(1, $Args); list($Offset, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30)); // Get Discussions $DiscussionModel = new DiscussionModel(); $Sender->DiscussionData = $DiscussionModel->GetParticipated(Gdn::Session()->UserID, $Offset, $Limit); $Sender->SetData('Discussions', $Sender->DiscussionData); $CountDiscussions = $DiscussionModel->GetCountParticipated(Gdn::Session()->UserID); $Sender->SetData('CountDiscussions', $CountDiscussions); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $Sender->EventArguments['PagerType'] = 'Pager'; $Sender->FireEvent('BeforeBuildPager'); $Sender->Pager = $PagerFactory->GetPager($Sender->EventArguments['PagerType'], $Sender); $Sender->Pager->ClientID = 'Pager'; $Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/participated/%1$s'); $Sender->FireEvent('AfterBuildPager'); // Deliver JSON data if necessary if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) { $Sender->SetJson('LessRow', $Sender->Pager->ToString('less')); $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more')); $Sender->View = 'discussions'; } // Add modules $Sender->AddModule('NewDiscussionModule'); $Sender->AddModule('CategoriesModule'); $BookmarkedModule = new BookmarkedModule($Sender); $BookmarkedModule->GetData(); $Sender->AddModule($BookmarkedModule); $Sender->Render($this->GetView('participated.php')); }
public function pluginController_quoteMention_create($sender, $discussionID, $commentID, $username) { $sender->deliveryMethod(DELIVERY_METHOD_JSON); $user = Gdn::userModel()->getByUsername($username); $discussionModel = new DiscussionModel(); $discussion = $discussionModel->getID($discussionID); if (!$user || !$discussion) { throw notFoundException(); } // Make sure this endpoint can't be used to snoop around. $sender->permission('Vanilla.Discussions.View', true, 'Category', $discussion->PermissionCategoryID); // Find the previous comment of the mentioned user in this discussion. $item = Gdn::sql()->getWhere('Comment', ['DiscussionID' => $discussion->DiscussionID, 'InsertUserID' => $user->UserID, 'CommentID <' => $commentID], 'CommentID', 'desc', 1)->firstRow(); // The items ID in the DOM used for highlighting. if ($item) { $target = '#Comment_' . $item->CommentID; // The mentioned user might be the discussion creator. } elseif ($discussion->InsertUserID == $user->UserID) { $item = $discussion; $target = '#Discussion_' . $item->DiscussionID; } if (!$item) { // A success response code always means that a comment was found. $sender->statusCode(404); } $sender->renderData($item ? ['html' => nl2br(sliceString(Gdn_Format::plainText($item->Body, $item->Format), c('QuoteMention.MaxLength', 400))), 'target' => $target] : []); }
public function GetData($Limit = 10) { $Session = Gdn::Session(); if ($Session->IsValid()) { $DiscussionModel = new DiscussionModel(); $this->_DiscussionData = $DiscussionModel->Get(0, $Limit, array('w.Bookmarked' => '1', 'w.UserID' => $Session->UserID)); } }
public function GetData($Limit = FALSE) { if (!$Limit) { $Limit = $this->Limit; } $DiscussionModel = new DiscussionModel(); $this->SetData('Discussions', $DiscussionModel->Get(0, $Limit, array('Announce' => 'all'))); }
/** * Advanced settings. * * Allows setting configuration values via form elements. * * @since 2.0.0 * @access public */ public function Advanced() { // Check permission $this->Permission('Vanilla.Settings.Manage'); // Load up config options we'll be setting $Validation = new Gdn_Validation(); $ConfigurationModel = new Gdn_ConfigurationModel($Validation); $ConfigurationModel->SetField(array( 'Vanilla.Discussions.PerPage', 'Vanilla.Comments.AutoRefresh', 'Vanilla.Comments.PerPage', 'Vanilla.Archive.Date', 'Vanilla.Archive.Exclude', 'Garden.EditContentTimeout' )); // Set the model on the form. $this->Form->SetModel($ConfigurationModel); // If seeing the form for the first time... if ($this->Form->AuthenticatedPostBack() === FALSE) { // Apply the config settings to the form. $this->Form->SetData($ConfigurationModel->Data); } else { // Define some validation rules for the fields being saved $ConfigurationModel->Validation->ApplyRule('Vanilla.Discussions.PerPage', 'Required'); $ConfigurationModel->Validation->ApplyRule('Vanilla.Discussions.PerPage', 'Integer'); $ConfigurationModel->Validation->ApplyRule('Vanilla.Comments.AutoRefresh', 'Integer'); $ConfigurationModel->Validation->ApplyRule('Vanilla.Comments.PerPage', 'Required'); $ConfigurationModel->Validation->ApplyRule('Vanilla.Comments.PerPage', 'Integer'); $ConfigurationModel->Validation->ApplyRule('Vanilla.Archive.Date', 'Date'); $ConfigurationModel->Validation->ApplyRule('Garden.EditContentTimeout', 'Integer'); // Grab old config values to check for an update. $ArchiveDateBak = Gdn::Config('Vanilla.Archive.Date'); $ArchiveExcludeBak = (bool)Gdn::Config('Vanilla.Archive.Exclude'); // Save new settings $Saved = $this->Form->Save(); if($Saved) { $ArchiveDate = Gdn::Config('Vanilla.Archive.Date'); $ArchiveExclude = (bool)Gdn::Config('Vanilla.Archive.Exclude'); if($ArchiveExclude != $ArchiveExcludeBak || ($ArchiveExclude && $ArchiveDate != $ArchiveDateBak)) { $DiscussionModel = new DiscussionModel(); $DiscussionModel->UpdateDiscussionCount('All'); } $this->InformMessage(T("Your changes have been saved.")); } } $this->AddSideMenu('vanilla/settings/advanced'); $this->AddJsFile('settings.js'); $this->Title(T('Advanced Forum Settings')); // Render default view (settings/advanced.php) $this->Render(); }
/** * Load discussions for a specific tag. */ public function DiscussionsController_Tagged_Create($Sender) { $Offset = GetValue('1', $Sender->RequestArgs, 'p1'); list($Offset, $Limit) = OffsetLimit($Offset, Gdn::Config('Vanilla.Discussions.PerPage', 30)); $Sender->Tag = GetValue('0', $Sender->RequestArgs, ''); $Sender->Title(T('Tagged with ') . $Sender->Tag); $Sender->Head->Title($Sender->Head->Title()); $Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged/' . $Sender->Tag, PageNumber($Offset, $Limit, TRUE)), TRUE)); if ($Sender->Head) { $Sender->AddJsFile('discussions.js'); $Sender->AddJsFile('bookmark.js'); $Sender->AddJsFile('js/library/jquery.menu.js'); $Sender->AddJsFile('options.js'); $Sender->Head->AddRss($Sender->SelfUrl . '/feed.rss', $Sender->Head->Title()); } if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } // Add Modules $Sender->AddModule('NewDiscussionModule'); $BookmarkedModule = new BookmarkedModule($Sender); $BookmarkedModule->GetData(); $Sender->AddModule($BookmarkedModule); $Sender->SetData('Category', FALSE, TRUE); $DiscussionModel = new DiscussionModel(); $Tag = $DiscussionModel->SQL->Select()->From('Tag')->Where('Name', $Sender->Tag)->Get()->FirstRow(); $TagID = $Tag ? $Tag->TagID : 0; $CountDiscussions = $Tag ? $Tag->CountDiscussions : 0; $Sender->SetData('CountDiscussions', $CountDiscussions); $Sender->AnnounceData = FALSE; $Sender->SetData('Announcements', array(), TRUE); $DiscussionModel->FilterToTagID = $TagID; $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit); $Sender->SetData('Discussions', $Sender->DiscussionData, TRUE); $Sender->SetJson('Loading', $Offset . ' to ' . $Limit); // Build a pager. $PagerFactory = new Gdn_PagerFactory(); $Sender->Pager = $PagerFactory->GetPager('Pager', $Sender); $Sender->Pager->ClientID = 'Pager'; $Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/tagged/' . $Sender->Tag . '/%1$s'); // Deliver json data if necessary if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) { $Sender->SetJson('LessRow', $Sender->Pager->ToString('less')); $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more')); $Sender->View = 'discussions'; } // Set a definition of the user's current timezone from the db. jQuery // will pick this up, compare to the browser, and update the user's // timezone if necessary. $CurrentUser = Gdn::Session()->User; if (is_object($CurrentUser)) { $ClientHour = $CurrentUser->HourOffset + date('G', time()); $Sender->AddDefinition('SetClientHour', $ClientHour); } // Render the controller $Sender->Render(PATH_PLUGINS . '/Tagging/views/taggeddiscussions.php'); }
/** * Use 404 handler to look for a SimplePage. */ public function gdn_dispatcher_notFound_handler($dispatcher, $args) { $requestUri = Gdn::Request()->Path(); $discussionModel = new DiscussionModel(); $result = $discussionModel->GetWhere(array('Type' => 'SimplePage', 'ForeignID' => $requestUri))->FirstRow(DATASET_TYPE_ARRAY); // Page exists with requested slug, so dispatch; no redirect. if ($discussionID = val('DiscussionID', $result)) { SaveToConfig('SimplePage.Found', true, false); Gdn::Dispatcher()->Dispatch('/discussion/' . $discussionID); exit; } }
public function CategoriesController_RefreshCounts_Create($Sender) { $Sender->Permission('Vanilla.Categories.Manage'); $DiscussionModel = new DiscussionModel(); $CategoryModel = $Sender->CategoryModel; $Categories = $CategoryModel->GetAll(); foreach ($Categories as $Category) { $CategoryID = $Category->CategoryID; $DiscussionModel->UpdateDiscussionCount($CategoryID); } // stash the inform message for later Gdn::Session()->Stash('RefreshCountsMessage', T('RefreshCounts.CatComplete')); Redirect('/vanilla/settings/managecategories'); }
/** * Get the data for the module. * * @param int|bool $limit Override the number of discussions to display. */ public function getData($limit = false) { if (!$limit) { $limit = $this->Limit; } $discussionModel = new DiscussionModel(); $categoryIDs = $this->getCategoryIDs(); $where = array('Announce' => 'all'); if ($categoryIDs) { $where['d.CategoryID'] = CategoryModel::filterCategoryPermissions($categoryIDs); } else { $discussionModel->Watching = true; } $this->setData('Discussions', $discussionModel->get(0, $limit, $where)); }
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; } }
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)); }
/** * 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); // decho($Stub); // die(); // 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'); }
public function getData() { if (Gdn::session()->isValid()) { $BookmarkIDs = Gdn::sql()->select('DiscussionID')->from('UserDiscussion')->where('UserID', Gdn::session()->UserID)->where('Bookmarked', 1)->get()->resultArray(); $BookmarkIDs = consolidateArrayValuesByKey($BookmarkIDs, 'DiscussionID'); if (count($BookmarkIDs)) { $DiscussionModel = new DiscussionModel(); DiscussionModel::CategoryPermissions(); $DiscussionModel->SQL->whereIn('d.DiscussionID', $BookmarkIDs); $Bookmarks = $DiscussionModel->get(0, $this->Limit, array('w.Bookmarked' => '1')); $this->setData('Bookmarks', $Bookmarks); } else { $this->setData('Bookmarks', new Gdn_DataSet()); } } }
/** * 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->isAuthenticatedPostBack(true)) { 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 = valr('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'); }
public function Get($Begin, $End, $Offset = '0', $Limit = '') { // Validate parameters, set today as default $BeginDate = strtotime($Begin); if ($BeginDate <= 0) { $BeginDate = date('Y-m-d'); } else { $BeginDate = date('Y-m-d', $BeginDate); } $EndDate = strtotime($End); if ($EndDate <= 0) { $EndDate = date('Y-m-d'); } else { $EndDate = date('Y-m-d', $EndDate); } if (!is_numeric($Offset)) { $Offset = 0; } if (!is_numeric($Limit)) { $Limit = ''; } $Sql = GDN::SQL(); $Sql->Select('d.Name, d.Body, d.Format')->Select('d.InsertUserID', '', 'UserID')->Select('DAY FROM d.EventCalendarDate', 'EXTRACT', 'EventCalendarDay')->From('Discussion d')->Where('d.EventCalendarDate >=', $BeginDate)->Where('d.EventCalendarDate <=', $EndDate)->OrderBy('d.EventCalendarDate')->Limit($Limit, $Offset); // add permission restrictions if necessary $Perms = DiscussionModel::CategoryPermissions(); if ($Perms !== TRUE) { $Sql->WhereIn('d.CategoryID', $Perms); } // return $Sql->GetSelect(); return $Sql->Get()->ResultArray(); }
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 (val('Notified', $Discussion) != ActivityModel::SENT_PENDING) { die('Not pending'); } // Mark the notification as in progress. $this->DiscussionModel->setField($DiscussionID, 'Notified', ActivityModel::SENT_INPROGRESS); $discussionType = val('Type', $Discussion); if ($discussionType) { $Code = "HeadlineFormat.Discussion.{$discussionType}"; } else { $Code = 'HeadlineFormat.Discussion'; } $HeadlineFormat = t($Code, '{ActivityUserID,user} started a new discussion: <a href="{Url,html}">{Data.Name,text}</a>'); $Category = CategoryModel::categories(val('CategoryID', $Discussion)); $Activity = array('ActivityType' => 'Discussion', 'ActivityUserID' => $Discussion->InsertUserID, 'HeadlineFormat' => $HeadlineFormat, 'RecordType' => 'Discussion', 'RecordID' => $DiscussionID, 'Route' => DiscussionUrl($Discussion), 'Data' => array('Name' => $Discussion->Name, 'Category' => val('Name', $Category))); $ActivityModel = new ActivityModel(); $this->DiscussionModel->NotifyNewDiscussion($Discussion, $ActivityModel, $Activity); $ActivityModel->SaveQueue(); $this->DiscussionModel->setField($DiscussionID, 'Notified', ActivityModel::SENT_OK); die('OK'); }
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; }
public function Index() { $Session = Gdn::Session(); $categories = array(); $discussionsPerCategory = 4; $DiscussionModel = new DiscussionModel(); $this->CategoryData = $this->CategoryModel->GetFull(); $this->CategoryDiscussionData = array(); foreach ($this->CategoryData->Result() as $Category) { $this->Category = $Category; if ($Session->CheckPermission('Vanilla.Discussions.View', $this->Category->CategoryID)) { //TODO be nice if options could be passed to filter // discussions that are closed, sunk, etc etc... $this->DiscussionData = $DiscussionModel->Get(0, $discussionsPerCategory, array('d.CategoryID' => $Category->CategoryID)); $category = array(); foreach ($Category as $key => $value) { $category[$key] = $value; } #$category["CategoryURL"] = Gdn::Config('Garden.Domain')."/categories/".$Category->UrlCode; $category["CategoryURL"] = Gdn::Request()->Domain() . "/categories/" . $Category->UrlCode; if ($this->DiscussionData->NumRows() > 0) { $count = 0; $discussion = array(); $category["discussions"] = array(); foreach ($this->DiscussionData->Result() as $Discussion) { foreach ($Discussion as $key => $value) { $discussion[$key] = $value; } //$discussion["DiscussionURL"] = Gdn::Config('Garden.Domain').'/discussion/'.$Discussion->DiscussionID.'/'.Gdn_Format::Url($Discussion->Name); $discussion["DiscussionURL"] = Gdn::Request()->Domain() . '/discussion/' . $Discussion->DiscussionID . '/' . Gdn_Format::Url($Discussion->Name); if ($count++ < $discussionsPerCategory) { $category["discussions"][] = $discussion; } else { break; } } } $categories[] = $category; } } $this->SetJSON("categories", $categories); $this->Render(); }
public function ProfileController_Discussions_Create(&$Sender) { $UserReference = ArrayValue(0, $Sender->EventArguments, ''); $Offset = ArrayValue(1, $Sender->EventArguments, 0); // Tell the ProfileController what tab to load $Sender->SetTabView($UserReference, 'Discussions', 'Profile', 'Discussions', 'Vanilla'); // Load the data for the requested tab. if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30); $DiscussionModel = new DiscussionModel(); $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit, array('d.InsertUserID' => $Sender->User->UserID)); $CountDiscussions = $Offset + $Sender->DiscussionData->NumRows(); if ($Sender->DiscussionData->NumRows() == $Limit) { $CountDiscussions = $Offset + $Limit + 1; } // Build a pager $PagerFactory = new PagerFactory(); $Sender->Pager = $PagerFactory->GetPager('MorePager', $Sender); $Sender->Pager->MoreCode = 'More Discussions'; $Sender->Pager->LessCode = 'Newer Discussions'; $Sender->Pager->ClientID = 'Pager'; $Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'profile/discussions/' . urlencode($Sender->User->Name) . '/%1$s/'); // Deliver json data if necessary if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL && $Offset > 0) { $Sender->SetJson('LessRow', $Sender->Pager->ToString('less')); $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more')); $Sender->View = 'discussions'; } // Set the handlertype back to normal on the profilecontroller so that it fetches it's own views $Sender->HandlerType = HANDLER_TYPE_NORMAL; // Do not show discussion options $Sender->ShowOptions = FALSE; // Render the ProfileController $Sender->Render(); }
/** * Add new filters to the discussion model * * @param DiscussionModel $sender Sending controller instance. * @param array $args Event arguments. */ public function discussionModel_initStatic_handler($sender, $args) { DiscussionModel::addFilterSet('prefix', 'Prefixes'); DiscussionModel::addFilter('has-prefix', 'Has prefix', ['d.Prefix IS NOT NULL' => null], 'base-filter', 'prefix'); DiscussionModel::addFilter('no-prefix', 'No prefix', ['d.Prefix IS NULL' => null], 'base-filter', 'prefix'); $currentPrefixes = PrefixDiscussionPlugin::getPrefixes(); unset($currentPrefixes['-']); $usedPrefixesResult = Gdn::sql()->select('Prefix')->from('Discussion')->where('Prefix IS NOT NULL')->get()->resultArray(); foreach ($usedPrefixesResult as $row) { $prefix = $row['Prefix']; if (!isset($currentPrefixes[$prefix])) { $currentPrefixes[$prefix] = $prefix; } } natsort($currentPrefixes); foreach ($currentPrefixes as $prefix) { DiscussionModel::addFilter('prefix-' . $this->stringToSlug($prefix), $prefix, ['d.Prefix' => $prefix], 'prefix-filter', 'prefix'); } }
/** * @param PostController $Sender * @param array $Args * @return mixed */ public function PostController_Comment_Create($Sender, $Args = array()) { if ($Sender->Form->AuthenticatedPostBack()) { $Sender->Form->SetModel($Sender->CommentModel); // Grab the discussion for use later. $DiscussionID = $Sender->Form->GetFormValue('DiscussionID'); $DiscussionModel = new DiscussionModel(); $Discussion = $DiscussionModel->GetID($DiscussionID); // Check to see if the discussion is supposed to be in private... $WhisperConversationID = GetValueR('Attributes.WhisperConversationID', $Discussion); if ($WhisperConversationID === TRUE) { // There isn't a conversation so we want to create one. $Sender->Form->SetFormValue('Whisper', TRUE); $WhisperUserIDs = GetValueR('Attributes.WhisperUserIDs', $Discussion); $Sender->Form->SetFormValue('RecipientUserID', $WhisperUserIDs); } elseif ($WhisperConversationID) { // There is already a conversation. $Sender->Form->SetFormValue('Whisper', TRUE); $Sender->Form->SetFormValue('ConversationID', $WhisperConversationID); } $Whisper = $Sender->Form->GetFormValue('Whisper') && GetIncomingValue('Type') != 'Draft'; $WhisperTo = trim($Sender->Form->GetFormValue('To')); $ConversationID = $Sender->Form->GetFormValue('ConversationID'); // If this isn't a whisper then post as normal. if (!$Whisper) { return call_user_func_array(array($Sender, 'Comment'), $Args); } $ConversationModel = new ConversationModel(); $ConversationMessageModel = new ConversationMessageModel(); if ($ConversationID > 0) { $Sender->Form->SetModel($ConversationMessageModel); } else { // We have to remove the blank conversation ID or else the model won't validate. $FormValues = $Sender->Form->FormValues(); unset($FormValues['ConversationID']); $FormValues['Subject'] = GetValue('Name', $Discussion); $Sender->Form->FormValues($FormValues); $Sender->Form->SetModel($ConversationModel); $ConversationModel->Validation->ApplyRule('DiscussionID', 'Required'); } $ID = $Sender->Form->Save($ConversationMessageModel); if ($Sender->Form->ErrorCount() > 0) { $Sender->ErrorMessage($Sender->Form->Errors()); } else { if ($WhisperConversationID === TRUE) { $Discussion->Attributes['WhisperConversationID'] = $ID; $DiscussionModel->SetProperty($DiscussionID, 'Attributes', serialize($Discussion->Attributes)); } $LastCommentID = GetValue('LastCommentID', $Discussion); $MessageID = GetValue('LastMessageID', $ConversationMessageModel, FALSE); // Randomize the querystring to force the browser to refresh. $Rand = mt_rand(10000, 99999); if ($LastCommentID) { // Link to the last comment. $HashID = $MessageID ? 'w' . $MessageID : $LastCommentID; $Sender->RedirectUrl = Url("discussion/comment/{$LastCommentID}?rand={$Rand}#Comment_{$HashID}", TRUE); } else { // Link to the discussion. $Hash = $MessageID ? "Comment_w{$MessageID}" : 'Item_1'; $Name = rawurlencode(GetValue('Name', $Discussion, 'x')); $Sender->RedirectUrl = Url("discussion/{$DiscussionID}/{$Name}?rand={$Rand}#{$Hash}", TRUE); } } $Sender->Render(); } else { return call_user_func_array(array($Sender, 'Comment'), $Args); } }
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); }
/** * Handle flagging process in a discussion. */ public function DiscussionController_Flag_Create($Sender) { if (!C('Plugins.Flagging.Enabled')) { return; } // Signed in users only. if (!($UserID = Gdn::Session()->UserID)) { return; } $UserName = Gdn::Session()->User->Name; $Arguments = $Sender->RequestArgs; if (sizeof($Arguments) != 5) { return; } list($Context, $ElementID, $ElementAuthorID, $ElementAuthor, $EncodedURL) = $Arguments; $URL = base64_decode(str_replace('-', '=', $EncodedURL)); $Sender->SetData('Plugin.Flagging.Data', array('Context' => $Context, 'ElementID' => $ElementID, 'ElementAuthorID' => $ElementAuthorID, 'ElementAuthor' => $ElementAuthor, 'URL' => $URL, 'UserID' => $UserID, 'UserName' => $UserName)); if ($Sender->Form->AuthenticatedPostBack()) { $SQL = Gdn::SQL(); $Comment = $Sender->Form->GetValue('Plugin.Flagging.Reason'); $Sender->SetData('Plugin.Flagging.Reason', $Comment); $CreateDiscussion = C('Plugins.Flagging.UseDiscussions'); if ($CreateDiscussion) { // Category $CategoryID = C('Plugins.Flagging.CategoryID'); // New discussion name if ($Context == 'comment') { $Result = $SQL->Select('d.Name')->Select('c.Body')->From('Comment c')->Join('Discussion d', 'd.DiscussionID = c.DiscussionID', 'left')->Where('c.CommentID', $ElementID)->Get()->FirstRow(); } elseif ($Context == 'discussion') { $DiscussionModel = new DiscussionModel(); $Result = $DiscussionModel->GetID($ElementID); } $DiscussionName = GetValue('Name', $Result); $PrefixedDiscussionName = T('FlagPrefix', 'FLAG: ') . $DiscussionName; // Prep data for the template $Sender->SetData('Plugin.Flagging.Report', array('DiscussionName' => $DiscussionName, 'FlaggedContent' => GetValue('Body', $Result))); // Assume no discussion exists $this->DiscussionID = NULL; // Get discussion ID if already flagged $FlagResult = Gdn::SQL()->Select('DiscussionID')->From('Flag fl')->Where('ForeignType', $Context)->Where('ForeignID', $ElementID)->Get()->FirstRow(); if ($FlagResult) { // New comment in existing discussion $DiscussionID = $FlagResult->DiscussionID; $ReportBody = $Sender->FetchView($this->GetView('reportcomment.php')); $SQL->Insert('Comment', array('DiscussionID' => $DiscussionID, 'InsertUserID' => $UserID, 'Body' => $ReportBody, 'Format' => 'Html', 'DateInserted' => date('Y-m-d H:i:s'))); $CommentModel = new CommentModel(); $CommentModel->UpdateCommentCount($DiscussionID); } else { // New discussion body $ReportBody = $Sender->FetchView($this->GetView('report.php')); $DiscussionID = $SQL->Insert('Discussion', array('InsertUserID' => $UserID, 'UpdateUserID' => $UserID, 'CategoryID' => $CategoryID, 'Name' => $PrefixedDiscussionName, 'Body' => $ReportBody, 'Format' => 'Html', 'CountComments' => 1, 'DateInserted' => date('Y-m-d H:i:s'), 'DateUpdated' => date('Y-m-d H:i:s'), 'DateLastComment' => date('Y-m-d H:i:s'))); // Update discussion count $DiscussionModel = new DiscussionModel(); $DiscussionModel->UpdateDiscussionCount($CategoryID); } } try { // Insert the flag $SQL->Insert('Flag', array('DiscussionID' => $DiscussionID, 'InsertUserID' => $UserID, 'InsertName' => $UserName, 'AuthorID' => $ElementAuthorID, 'AuthorName' => $ElementAuthor, 'ForeignURL' => $URL, 'ForeignID' => $ElementID, 'ForeignType' => $Context, 'Comment' => $Comment, 'DateInserted' => date('Y-m-d H:i:s'))); } catch (Exception $e) { } // Notify users with permission who've chosen to be notified if (!$FlagResult) { // Only send if this is first time it's being flagged. $Sender->SetData('Plugin.Flagging.DiscussionID', $DiscussionID); $Subject = isset($PrefixedDiscussionName) ? $PrefixedDiscussionName : T('FlagDiscussion', 'A discussion was flagged'); $EmailBody = $Sender->FetchView($this->GetView('reportemail.php')); $NotifyUsers = C('Plugins.Flagging.NotifyUsers', array()); // Send emails $UserModel = new UserModel(); foreach ($NotifyUsers as $UserID) { $User = $UserModel->GetID($UserID); $Email = new Gdn_Email(); $Email->To($User->Email)->Subject(sprintf(T('[%1$s] %2$s'), Gdn::Config('Garden.Title'), $Subject))->Message($EmailBody)->Send(); } } $Sender->InformMessage(T('FlagSent', "Your complaint has been registered.")); } $Sender->Render($this->GetView('flag.php')); }
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(); } }
/** * 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 = val('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 (Gdn::controller()->deliveryType() === DELIVERY_TYPE_ALL && $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($Fields['InsertUserID'], $IncUser && $Insert); // Mark the user as participated. $this->SQL->replace('UserDiscussion', array('Participated' => 1), array('DiscussionID' => $DiscussionID, 'UserID' => val('InsertUserID', $Fields))); if ($Insert) { // UPDATE COUNT AND LAST COMMENT ON CATEGORY TABLE if ($Discussion->CategoryID > 0) { $Category = CategoryModel::categories($Discussion->CategoryID); if ($Category) { $CountComments = val('CountComments', $Category, 0) + 1; if ($CountComments < self::COMMENT_THRESHOLD_SMALL || $CountComments < self::COMMENT_THRESHOLD_LARGE && $CountComments % self::COUNT_RECALC_MOD == 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. $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' => val('Name', $Category))); // Allow simple fulltext notifications if (c('Vanilla.Activity.ShowCommentBody', false)) { $Activity['Story'] = val('Body', $Fields); $Activity['Format'] = val('Format', $Fields); } // Pass generic activity to events. $this->EventArguments['Activity'] = $Activity; // 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; $Activity['Data']['Reason'] = 'bookmark'; $ActivityModel->Queue($Activity, 'BookmarkComment', array('CheckRecord' => true)); } // Notify users who have participated in the discussion. $ParticipatedData = $DiscussionModel->GetParticipatedUsers($DiscussionID); foreach ($ParticipatedData->result() as $UserRow) { if (!$UserModel->GetCategoryViewPermission($UserRow->UserID, $Discussion->CategoryID)) { continue; } $Activity['NotifyUserID'] = $UserRow->UserID; $Activity['Data']['Reason'] = 'participated'; $ActivityModel->Queue($Activity, 'ParticipateComment', array('CheckRecord' => true)); } // Record user-comment activity. if ($Discussion != false) { $InsertUserID = val('InsertUserID', $Discussion); // Check user can still see the discussion. if ($UserModel->GetCategoryViewPermission($InsertUserID, $Discussion->CategoryID)) { $Activity['NotifyUserID'] = $InsertUserID; $Activity['Data']['Reason'] = 'mine'; $ActivityModel->Queue($Activity, 'DiscussionComment'); } } // Record advanced notifications. if ($Discussion !== false) { $Activity['Data']['Reason'] = 'advanced'; $this->RecordAdvancedNotications($ActivityModel, $Activity, $Discussion); } // Notify any users who were mentioned in the comment. $Usernames = GetMentions($Fields['Body']); 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; $Activity['Data']['Reason'] = 'mention'; $ActivityModel->Queue($Activity, 'Mention'); $Activity['HeadlineFormat'] = $HeadlineFormatBak; } unset($Activity['Data']['Reason']); // 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'); // Send all notifications. $ActivityModel->SaveQueue(); } }
/** * * * @param $Type * @param $ID * @param $QuoteData * @param bool $Format */ protected function formatQuote($Type, $ID, &$QuoteData, $Format = false) { // Temporarily disable Emoji parsing (prevent double-parsing to HTML) $emojiEnabled = Emoji::instance()->enabled; Emoji::instance()->enabled = 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, false); } elseif ($QuoteFormat == 'Text' && $NewFormat == 'BBCode') { $NewBody = Gdn_Format::text($NewBody, false); } 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) . "\n"; 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)); } // Undo Emoji disable. Emoji::instance()->enabled = $emojiEnabled; }
/** * Get full data for a single category by its URL slug. Respects permissions. * * @since 2.0.0 * @access public * * @param string $UrlCode Unique category slug from URL. * @return object SQL results. */ public function GetFullByUrlCode($UrlCode) { $Data = (object) self::Categories($UrlCode); // Check to see if the user has permission for this category. // Get the category IDs. $CategoryIDs = DiscussionModel::CategoryPermissions(); if (is_array($CategoryIDs) && !in_array(GetValue('CategoryID', $Data), $CategoryIDs)) { $Data = FALSE; } return $Data; }
public function Gdn_Statistics_Tick_Handler($Sender, $Args) { $Path = Gdn::Request()->Post('Path'); $Args = Gdn::Request()->Post('Args'); parse_str($Args, $Args); $ResolvedPath = trim(Gdn::Request()->Post('ResolvedPath'), '/'); $ResolvedArgs = @json_decode(Gdn::Request()->Post('ResolvedArgs')); $DiscussionID = NULL; $DiscussionModel = new DiscussionModel(); // Gdn::Controller()->SetData('Path', $Path); // Gdn::Controller()->SetData('Args', $Args); // Gdn::Controller()->SetData('ResolvedPath', $ResolvedPath); // Gdn::Controller()->SetData('ResolvedArgs', $ResolvedArgs); // Comment permalink if ($ResolvedPath == 'vanilla/discussion/comment') { $CommentID = GetValue('CommentID', $ResolvedArgs); $CommentModel = new CommentModel(); $Comment = $CommentModel->GetID($CommentID); $DiscussionID = GetValue('DiscussionID', $Comment); } elseif ($ResolvedPath == 'vanilla/discussion/index') { $DiscussionID = GetValue('DiscussionID', $ResolvedArgs, NULL); } elseif ($ResolvedPath == 'vanilla/discussion/embed') { $ForeignID = GetValue('vanilla_identifier', $Args); if ($ForeignID) { // This will be hit a lot so let's try caching it... $Key = "DiscussionID.ForeignID.page.{$ForeignID}"; $DiscussionID = Gdn::Cache()->Get($Key); if (!$DiscussionID) { $Discussion = $DiscussionModel->GetForeignID($ForeignID, 'page'); $DiscussionID = GetValue('DiscussionID', $Discussion); Gdn::Cache()->Store($Key, $DiscussionID, array(Gdn_Cache::FEATURE_EXPIRY, 1800)); } } } if ($DiscussionID) { $DiscussionModel->AddView($DiscussionID); } }