Exemplo n.º 1
0
 /**
  * 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');
 }
 /**
  * Default all discussions view: chronological by most recent comment.
  * 
  * @since 2.0.0
  * @access public
  * 
  * @param int $Page Multiplied by PerPage option to determine offset.
  */
 public function Index($Page = '0')
 {
     // Determine offset from $Page
     list($Page, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30));
     $this->CanonicalUrl(Url(ConcatSep('/', 'discussions', PageNumber($Page, $Limit, TRUE)), TRUE));
     // Validate $Page
     if (!is_numeric($Page) || $Page < 0) {
         $Page = 0;
     }
     // Setup head
     $this->Title(T('All Discussions'));
     if ($this->Head) {
         $this->Head->AddRss(Url('/discussions/feed.rss', TRUE), $this->Head->Title());
     }
     // Add modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     // Set criteria & get discussions data
     $this->SetData('Category', FALSE, TRUE);
     $DiscussionModel = new DiscussionModel();
     $CountDiscussions = $DiscussionModel->GetCount();
     $this->SetData('CountDiscussions', $CountDiscussions);
     $this->AnnounceData = $Page == 0 ? $DiscussionModel->GetAnnouncements() : FALSE;
     $this->SetData('Announcements', $this->AnnounceData !== FALSE ? $this->AnnounceData : array(), TRUE);
     $this->DiscussionData = $DiscussionModel->Get($Page, $Limit);
     $this->SetData('Discussions', $this->DiscussionData, TRUE);
     $this->SetJson('Loading', $Page . ' to ' . $Limit);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->EventArguments['PagerType'] = 'Pager';
     $this->FireEvent('BeforeBuildPager');
     $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($Page, $Limit, $CountDiscussions, 'discussions/%1$s');
     $this->FireEvent('AfterBuildPager');
     // Deliver JSON data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->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());
         $this->AddDefinition('SetClientHour', $ClientHour);
     }
     // Render default view (discussions/index.php)
     $this->Render();
 }
Exemplo n.º 3
0
 public function Index($Offset = '0')
 {
     list($Offset, $Limit) = OffsetLimit($Offset, Gdn::Config('Vanilla.Discussions.PerPage', 30));
     $this->CanonicalUrl(Url(ConcatSep('/', 'discussions', PageNumber($Offset, $Limit, TRUE)), TRUE));
     $this->Title(T('All Discussions'));
     if ($this->Head) {
         $this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
     }
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     // Add Modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     $this->SetData('Category', FALSE, TRUE);
     $DiscussionModel = new DiscussionModel();
     $CountDiscussions = $DiscussionModel->GetCount();
     $this->SetData('CountDiscussions', $CountDiscussions);
     $this->AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements() : FALSE;
     $this->SetData('Announcements', $this->AnnounceData !== FALSE ? $this->AnnounceData : array(), TRUE);
     $this->DiscussionData = $DiscussionModel->Get($Offset, $Limit);
     $this->SetData('Discussions', $this->DiscussionData, TRUE);
     $this->SetJson('Loading', $Offset . ' to ' . $Limit);
     // Build a pager.
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('Pager', $this);
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/%1$s');
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->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());
         $this->AddDefinition('SetClientHour', $ClientHour);
     }
     // Render the controller
     $this->Render();
 }
Exemplo n.º 4
0
 /**
  * Create a comment.
  *
  * @param int The DiscussionID to add the comment to. If blank, this method will throw an error.
  */
 public function Comment($DiscussionID = '')
 {
     if ($DiscussionID == '' && sizeof($this->RequestArgs)) {
         if (is_numeric($this->RequestArgs[0])) {
             $DiscussionID = $this->RequestArgs[0];
         }
     }
     $this->AddJsFile('jquery.autogrow.js');
     $this->AddJsFile('post.js');
     $this->AddJsFile('autosave.js');
     $Session = Gdn::Session();
     $this->Form->SetModel($this->CommentModel);
     $CommentID = isset($this->Comment) && property_exists($this->Comment, 'CommentID') ? $this->Comment->CommentID : '';
     $DraftID = isset($this->Comment) && property_exists($this->Comment, 'DraftID') ? $this->Comment->DraftID : '';
     $this->EventArguments['CommentID'] = $CommentID;
     $Editing = $CommentID > 0 || $DraftID > 0;
     $this->EventArguments['Editing'] = $Editing;
     $DiscussionID = is_numeric($DiscussionID) ? $DiscussionID : $this->Form->GetFormValue('DiscussionID', 0);
     $this->Form->AddHidden('DiscussionID', $DiscussionID);
     $this->Form->AddHidden('CommentID', $CommentID);
     $this->Form->AddHidden('DraftID', $DraftID, TRUE);
     $this->DiscussionID = $DiscussionID;
     $this->Discussion = $Discussion = $this->DiscussionModel->GetID($DiscussionID);
     if ($Editing) {
         if ($this->Comment->InsertUserID != $Session->UserID) {
             $this->Permission('Vanilla.Comments.Edit', TRUE, 'Category', $Discussion->CategoryID);
         }
         // Make sure that content can (still) be edited.
         $EditContentTimeout = C('Garden.EditContentTimeout', -1);
         $CanEdit = $EditContentTimeout == -1 || strtotime($this->Comment->DateInserted) + $EditContentTimeout > time();
         if (!$CanEdit) {
             $this->Permission('Vanilla.Comments.Edit', TRUE, 'Category', $Discussion->CategoryID);
         }
     } else {
         $this->Permission('Vanilla.Comments.Add', TRUE, 'Category', $Discussion->CategoryID);
     }
     if ($this->Form->AuthenticatedPostBack() === FALSE) {
         if (isset($this->Comment)) {
             $this->Form->SetData($this->Comment);
         }
     } else {
         // Save as a draft?
         $FormValues = $this->Form->FormValues();
         if ($DraftID == 0) {
             $DraftID = $this->Form->GetFormValue('DraftID', 0);
         }
         $Type = GetIncomingValue('Type');
         $Draft = $Type == 'Draft';
         $this->EventArguments['Draft'] = $Draft;
         $Preview = $Type == 'Preview';
         if ($Draft) {
             $DraftID = $this->DraftModel->Save($FormValues);
             $this->Form->AddHidden('DraftID', $DraftID, TRUE);
             $this->Form->SetValidationResults($this->DraftModel->ValidationResults());
         } else {
             if (!$Preview) {
                 $Inserted = !$CommentID;
                 $CommentID = $this->CommentModel->Save($FormValues);
                 // The comment is now half-saved.
                 if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
                     $this->Comment2($CommentID, $Inserted);
                 } else {
                     $this->JsonTarget('', Url("/vanilla/post/comment2/{$CommentID}/{$Inserted}"), 'Ajax');
                 }
                 // $Discussion = $this->DiscussionModel->GetID($DiscussionID);
                 $Comment = $this->CommentModel->GetID($CommentID);
                 $this->EventArguments['Discussion'] = $Discussion;
                 $this->EventArguments['Comment'] = $Comment;
                 $this->FireEvent('AfterCommentSave');
                 $this->Form->SetValidationResults($this->CommentModel->ValidationResults());
                 if ($CommentID > 0 && $DraftID > 0) {
                     $this->DraftModel->Delete($DraftID);
                 }
             }
         }
         // Handle non-ajax requests first:
         if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
             if ($this->Form->ErrorCount() == 0) {
                 // Make sure that this form knows what comment we are editing.
                 if ($CommentID > 0) {
                     $this->Form->AddHidden('CommentID', $CommentID);
                 }
                 // If the comment was not a draft
                 if (!$Draft) {
                     // Redirect to the new comment
                     // $Discussion = $this->DiscussionModel->GetID($DiscussionID);
                     Redirect("discussion/comment/{$CommentID}/#Comment_{$CommentID}");
                 } elseif ($Preview) {
                     // If this was a preview click, create a comment shell with the values for this comment
                     $this->Comment = new stdClass();
                     $this->Comment->InsertUserID = $Session->User->UserID;
                     $this->Comment->InsertName = $Session->User->Name;
                     $this->Comment->InsertPhoto = $Session->User->Photo;
                     $this->Comment->DateInserted = Gdn_Format::Date();
                     $this->Comment->Body = ArrayValue('Body', $FormValues, '');
                     $this->AddAsset('Content', $this->FetchView('preview'));
                 } else {
                     // If this was a draft save, notify the user about the save
                     $this->StatusMessage = sprintf(T('Draft saved at %s'), Gdn_Format::Date());
                 }
             }
         } else {
             // Handle ajax-based requests
             if ($this->Form->ErrorCount() > 0) {
                 // Return the form errors
                 $this->StatusMessage = $this->Form->Errors();
             } else {
                 // Make sure that the ajax request form knows about the newly created comment or draft id
                 $this->SetJson('CommentID', $CommentID);
                 $this->SetJson('DraftID', $DraftID);
                 if ($Preview) {
                     // If this was a preview click, create a comment shell with the values for this comment
                     $this->Comment = new stdClass();
                     $this->Comment->InsertUserID = $Session->User->UserID;
                     $this->Comment->InsertName = $Session->User->Name;
                     $this->Comment->InsertPhoto = $Session->User->Photo;
                     $this->Comment->DateInserted = Gdn_Format::Date();
                     $this->Comment->Body = ArrayValue('Body', $FormValues, '');
                     $this->View = 'preview';
                 } elseif (!$Draft) {
                     // If the comment was not a draft
                     // If Editing a comment
                     if ($Editing) {
                         // Just reload the comment in question
                         $this->Offset = 1;
                         $this->SetData('CommentData', $this->CommentModel->GetIDData($CommentID), TRUE);
                         // Load the discussion
                         $this->ControllerName = 'discussion';
                         $this->View = 'comments';
                         // Also define the discussion url in case this request came from the post screen and needs to be redirected to the discussion
                         $this->SetJson('DiscussionUrl', Url('/discussion/' . $DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name) . '/#Comment_' . $CommentID));
                     } else {
                         // If the comment model isn't sorted by DateInserted or CommentID then we can't do any fancy loading of comments.
                         $OrderBy = GetValueR('0.0', $this->CommentModel->OrderBy());
                         $Redirect = !in_array($OrderBy, array('c.DateInserted', 'c.CommentID'));
                         if (!$Redirect) {
                             // Otherwise load all new comments that the user hasn't seen yet
                             $LastCommentID = $this->Form->GetFormValue('LastCommentID');
                             if (!is_numeric($LastCommentID)) {
                                 $LastCommentID = $CommentID - 1;
                             }
                             // Failsafe back to this new comment if the lastcommentid was not defined properly
                             // Don't reload the first comment if this new comment is the first one.
                             $this->Offset = $LastCommentID == 0 ? 1 : $this->CommentModel->GetOffset($LastCommentID);
                             // Do not load more than a single page of data...
                             $Limit = C('Vanilla.Comments.PerPage', 50);
                             // Redirect if the new new comment isn't on the same page.
                             $Redirect |= PageNumber($this->Offset, $Limit) != PageNumber($Discussion->CountComments - 1, $Limit);
                         }
                         if ($Redirect) {
                             // The user posted a comment on a page other than the last one, so just redirect to the last page.
                             $this->RedirectUrl = Gdn::Request()->Url("discussion/comment/{$CommentID}/#Comment_{$CommentID}", TRUE);
                             $this->CommentData = NULL;
                         } else {
                             // Make sure to load all new comments since the page was last loaded by this user
                             $this->SetData('CommentData', $this->CommentModel->GetNew($DiscussionID, $LastCommentID), TRUE);
                             $this->SetData('NewComments', TRUE);
                             $this->ControllerName = 'discussion';
                             $this->View = 'comments';
                         }
                         // Make sure to set the user's discussion watch records
                         $CountComments = $this->CommentModel->GetCount($DiscussionID);
                         $Limit = is_object($this->CommentData) ? $this->CommentData->NumRows() : $Discussion->CountComments;
                         $Offset = $CountComments - $Limit;
                         $this->CommentModel->SetWatch($this->Discussion, $Limit, $Offset, $CountComments);
                     }
                 } else {
                     // If this was a draft save, notify the user about the save
                     $this->StatusMessage = sprintf(T('Draft saved at %s'), Gdn_Format::Date());
                 }
                 // And update the draft count
                 $UserModel = Gdn::UserModel();
                 $CountDrafts = $UserModel->GetAttribute($Session->UserID, 'CountDrafts', 0);
                 $this->SetJson('MyDrafts', T('My Drafts'));
                 $this->SetJson('CountDrafts', $CountDrafts);
             }
         }
     }
     if (property_exists($this, 'Discussion')) {
         $this->EventArguments['Discussion'] = $this->Discussion;
     }
     if (property_exists($this, 'Comment')) {
         $this->EventArguments['Comment'] = $this->Comment;
     }
     $this->FireEvent('BeforeCommentRender');
     $this->Render();
 }
        $numrows = $pro->num_rows();
        $pro->get_products($list_id, true, false, $sort_fld, $direction, $first, $max_rows);
        if ($pro->num_rows() == 0) {
            $curpage = 1;
            $pro->get_products($list_id, true, false, $sort_fld, $direction, 0, $max_rows);
        }
        $page = PageNumber($numrows, $max_rows, 5, $curpage, "index.php?list_id={$list_id}&sort_fld={$sort_fld}&direction={$direction}", $st, $cmdPrevious, $cmdNext);
    } else {
        $pro->get_products(-1, false, true, $sort_fld, $direction);
        $numrows = $pro->num_rows();
        $pro->get_products(-1, false, true, $sort_fld, $direction, $first, $max_rows);
        if ($pro->num_rows() == 0) {
            $curpage = 1;
            $pro->get_products(-1, false, true, $sort_fld, $direction, 0, $max_rows);
        }
        $page = PageNumber($numrows, $max_rows, 5, $curpage, "index.php?list_id={$list_id}&sort_fld={$sort_fld}&direction={$direction}", $st, $cmdPrevious, $cmdNext);
    }
    $task = 'edit';
}
while ($pro->next_record()) {
    $id = $pro->f('product_id');
    $name = $pro->f('product_name');
    $cate = $pro->f('category_name');
    if (empty($cate)) {
        $cate = $pro->f('attach_cate');
    }
    $click_del = "javascript:click_del(document.frmProList, {$id} , \"{$name}\" , \"" . sprintf($sc_ConfirmDeleteProduct, $name) . "\")";
    ?>
  
  <tr>
  	<td width="1"><input type="checkbox" name="buy_id[]" value="<?php 
Exemplo n.º 6
0
 public function Index($DiscussionID = '', $DiscussionStub = '', $Offset = '', $Limit = '')
 {
     $this->AddCssFile('vanilla.css');
     $Session = Gdn::Session();
     $this->AddJsFile('jquery.resizable.js');
     $this->AddJsFile('jquery.ui.packed.js');
     $this->AddJsFile('jquery.autogrow.js');
     //      $this->AddJsFile('jquery.gardenmorepager.js');
     $this->AddJsFile('options.js');
     $this->AddJsFile('bookmark.js');
     $this->AddJsFile('discussion.js');
     $this->AddJsFile('autosave.js');
     // Load the discussion record
     $DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0;
     $this->SetData('Discussion', $this->DiscussionModel->GetID($DiscussionID), TRUE);
     if (!is_object($this->Discussion)) {
         return Gdn::Dispatcher()->Dispatch('Default404');
     }
     // Check Permissions
     $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $this->Discussion->CategoryID);
     $this->SetData('CategoryID', $this->CategoryID = $this->Discussion->CategoryID, TRUE);
     // Setup
     $this->Title($this->Discussion->Name);
     // Actual number of comments, excluding the discussion itself
     $ActualResponses = $this->Discussion->CountComments - 1;
     // Define the query offset & limit
     if (!is_numeric($Limit) || $Limit < 0) {
         $Limit = C('Vanilla.Comments.PerPage', 50);
     }
     $OffsetProvided = $Offset != '';
     list($Offset, $Limit) = OffsetLimit($Offset, $Limit);
     // If $Offset isn't defined, assume that the user has not clicked to
     // view a next or previous page, and this is a "view" to be counted.
     if ($Offset == '') {
         $this->DiscussionModel->AddView($DiscussionID);
     }
     $this->Offset = $Offset;
     if (C('Vanilla.Comments.AutoOffset')) {
         if (!is_numeric($this->Offset) || $this->Offset < 0 || !$OffsetProvided) {
             // Round down to the appropriate offset based on the user's read comments & comments per page
             $CountCommentWatch = $this->Discussion->CountCommentWatch > 0 ? $this->Discussion->CountCommentWatch : 0;
             if ($CountCommentWatch > $ActualResponses) {
                 $CountCommentWatch = $ActualResponses;
             }
             // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
             $this->Offset = floor($CountCommentWatch / $Limit) * $Limit;
         }
         if ($ActualResponses <= $Limit) {
             $this->Offset = 0;
         }
         if ($this->Offset == $ActualResponses) {
             $this->Offset -= $Limit;
         }
     } else {
         if ($this->Offset == '') {
             $this->Offset = 0;
         }
     }
     if ($this->Offset < 0) {
         $this->Offset = 0;
     }
     // Set the canonical url to have the proper page title.
     $this->CanonicalUrl(Url(ConcatSep('/', 'discussion/' . $this->Discussion->DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name), PageNumber($this->Offset, $Limit, TRUE)), TRUE));
     // Make sure to set the user's discussion watch records
     $this->CommentModel->SetWatch($this->Discussion, $Limit, $this->Offset, $this->Discussion->CountComments);
     // Load the comments
     $this->SetData('CommentData', $this->CommentModel->Get($DiscussionID, $Limit, $this->Offset), TRUE);
     $this->SetData('Comments', $this->CommentData);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('Pager', $this);
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($this->Offset, $Limit, $ActualResponses, 'discussion/' . $DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name) . '/%1$s');
     //      $this->Pager->MoreCode = '%1$s more comments';
     //      $this->Pager->LessCode = '%1$s older comments';
     //      $this->Pager->ClientID = 'Pager';
     //      $this->Pager->Configure(
     //         $this->Offset,
     //         $Limit,
     //         $ActualResponses,
     //         'discussion/'.$DiscussionID.'/'.Gdn_Format::Url($this->Discussion->Name).'/%1$s/%2$s/'
     //      );
     // Define the form for the comment input
     $this->Form = Gdn::Factory('Form', 'Comment');
     $this->Form->Action = Url('/vanilla/post/comment/');
     $this->DiscussionID = $this->Discussion->DiscussionID;
     $this->Form->AddHidden('DiscussionID', $this->DiscussionID);
     $this->Form->AddHidden('CommentID', '');
     // Retrieve & apply the draft if there is one:
     $DraftModel = new DraftModel();
     $Draft = $DraftModel->Get($Session->UserID, 0, 1, $this->Discussion->DiscussionID)->FirstRow();
     $this->Form->AddHidden('DraftID', $Draft ? $Draft->DraftID : '');
     if ($Draft) {
         $this->Form->SetFormValue('Body', $Draft->Body);
     }
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'comments';
     }
     // Add Modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     $this->FireEvent('BeforeDiscussionRender');
     $this->Render();
 }
 public function Comment($CommentID)
 {
     // Get the discussionID
     $Comment = $this->CommentModel->GetID($CommentID);
     if (!$Comment) {
         Redirect('dashboard/home/filenotfound');
     }
     $DiscussionID = $Comment->DiscussionID;
     // Figure out how many comments are before this one
     $Offset = $this->CommentModel->GetOffset($Comment);
     $Limit = Gdn::Config('Vanilla.Comments.PerPage', 50);
     // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
     //$Offset = floor($Offset / $Limit) * $Limit;
     $PageNumber = PageNumber($Offset, $Limit, TRUE);
     $this->View = 'index';
     $this->Index($DiscussionID, 'x', $PageNumber);
 }
Exemplo n.º 8
0
 public function RemovePageCache($DiscussionID, $From = 1)
 {
     if (!Gdn::Cache()->ActiveEnabled()) {
         return;
     }
     $CountComments = $this->SQL->GetWhere('Discussion', array('DiscussionID' => $DiscussionID))->Value('CountComments');
     $PageCount = PageNumber($CountComments - 1, C('Vanilla.Comments.PerPage', 30));
     for ($Page = $From; $Page <= $PageCount; $Page++) {
         $CacheKey = "Comment.Page.{$DiscussionID}.{$Page}";
         Gdn::Cache()->Remove($CacheKey);
     }
 }
Exemplo n.º 9
0
 /**
  *
  *
  * @param string $Type
  * @return string
  */
 public function toStringPrevNext($Type = 'more')
 {
     $this->CssClass = ConcatSep(' ', $this->CssClass, 'PrevNextPager');
     $CurrentPage = PageNumber($this->Offset, $this->Limit);
     $Pager = '';
     if ($CurrentPage > 1) {
         $PageParam = 'p' . ($CurrentPage - 1);
         $Pager .= anchor(t('Previous'), $this->PageUrl($CurrentPage - 1), 'Previous', array('rel' => 'prev'));
     }
     $HasNext = true;
     if ($this->CurrentRecords !== false && $this->CurrentRecords < $this->Limit) {
         $HasNext = false;
     }
     if ($HasNext) {
         $PageParam = 'p' . ($CurrentPage + 1);
         $Pager = ConcatSep(' ', $Pager, anchor(t('Next'), $this->PageUrl($CurrentPage + 1), 'Next', array('rel' => 'next')));
     }
     $ClientID = $this->ClientID;
     $ClientID = $Type == 'more' ? $ClientID . 'After' : $ClientID . 'Before';
     if (isset($this->HtmlBefore)) {
         $Pager = $this->HtmlBefore . $Pager;
     }
     return $Pager == '' ? '' : sprintf($this->Wrapper, Attribute(array('id' => $ClientID, 'class' => $this->CssClass)), $Pager);
 }
    /**
     * Alternate version of Index that uses the embed master view.
     *
     * @param int $DiscussionID Unique identifier, if discussion has been created.
     * @param string $DiscussionStub Deprecated.
     * @param int $Offset
     * @param int $Limit
     */
    public function Embed($DiscussionID = '', $DiscussionStub = '', $Offset = '', $Limit = '')
    {
        $this->Title(T('Comments'));
        // Add theme data
        $this->Theme = C('Garden.CommentsTheme', $this->Theme);
        Gdn_Theme::Section('Comments');
        // Force view options
        $this->MasterView = 'empty';
        $this->CanEditComments = FALSE;
        // Don't show the comment checkboxes on the embed comments page
        // Add some css to help with the transparent bg on embedded comments
        if ($this->Head) {
            $this->Head->AddString('<style type="text/css">
body { background: transparent !important; }
</style>');
        }
        // Javascript files & options
        $this->AddJsFile('jquery.gardenmorepager.js');
        $this->AddJsFile('jquery.autogrow.js');
        $this->RemoveJsFile('autosave.js');
        $this->AddJsFile('discussion.js');
        $this->AddDefinition('DoInform', '0');
        // Suppress inform messages on embedded page.
        $this->AddDefinition('SelfUrl', Gdn::Request()->PathAndQuery());
        $this->AddDefinition('Embedded', TRUE);
        // Define incoming variables (prefer querystring parameters over method parameters)
        $DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0;
        $DiscussionID = GetIncomingValue('vanilla_discussion_id', $DiscussionID);
        $Offset = GetIncomingValue('Offset', $Offset);
        $Limit = GetIncomingValue('Limit', $Limit);
        $vanilla_identifier = GetIncomingValue('vanilla_identifier', '');
        // Only allow vanilla identifiers of 32 chars or less - md5 if larger
        if (strlen($vanilla_identifier) > 32) {
            $vanilla_identifier = md5($vanilla_identifier);
        }
        $vanilla_type = GetIncomingValue('vanilla_type', 'page');
        $vanilla_url = GetIncomingValue('vanilla_url', '');
        $vanilla_category_id = GetIncomingValue('vanilla_category_id', '');
        $ForeignSource = array('vanilla_identifier' => $vanilla_identifier, 'vanilla_type' => $vanilla_type, 'vanilla_url' => $vanilla_url, 'vanilla_category_id' => $vanilla_category_id);
        $this->SetData('ForeignSource', $ForeignSource);
        // Set comment sorting
        $SortComments = C('Garden.Embed.SortComments') == 'desc' ? 'desc' : 'asc';
        $this->SetData('SortComments', $SortComments);
        // Retrieve the discussion record
        $Discussion = FALSE;
        if ($DiscussionID > 0) {
            $Discussion = $this->DiscussionModel->GetID($DiscussionID);
        } else {
            if ($vanilla_identifier != '' && $vanilla_type != '') {
                $Discussion = $this->DiscussionModel->GetForeignID($vanilla_identifier, $vanilla_type);
            }
        }
        // Set discussion data if we have one for this page
        if ($Discussion) {
            $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $Discussion->PermissionCategoryID);
            $this->SetData('Discussion', $Discussion, TRUE);
            $this->SetData('DiscussionID', $Discussion->DiscussionID, TRUE);
            $this->Title($Discussion->Name);
            // Actual number of comments, excluding the discussion itself
            $ActualResponses = $Discussion->CountComments;
            // Define the query offset & limit
            if (!is_numeric($Limit) || $Limit < 0) {
                $Limit = C('Garden.Embed.CommentsPerPage', 30);
            }
            $OffsetProvided = $Offset != '';
            list($Offset, $Limit) = OffsetLimit($Offset, $Limit);
            $this->Offset = $Offset;
            if (C('Vanilla.Comments.AutoOffset')) {
                if ($ActualResponses <= $Limit) {
                    $this->Offset = 0;
                }
                if ($this->Offset == $ActualResponses) {
                    $this->Offset -= $Limit;
                }
            } else {
                if ($this->Offset == '') {
                    $this->Offset = 0;
                }
            }
            if ($this->Offset < 0) {
                $this->Offset = 0;
            }
            // Set the canonical url to have the proper page title.
            $this->CanonicalUrl(DiscussionUrl($Discussion, PageNumber($this->Offset, $Limit)));
            // Load the comments.
            $CurrentOrderBy = $this->CommentModel->OrderBy();
            if (StringBeginsWith(GetValueR('0.0', $CurrentOrderBy), 'c.DateInserted')) {
                $this->CommentModel->OrderBy('c.DateInserted ' . $SortComments);
            }
            // allow custom sort
            $this->SetData('Comments', $this->CommentModel->Get($Discussion->DiscussionID, $Limit, $this->Offset), TRUE);
            if (count($this->CommentModel->Where()) > 0) {
                $ActualResponses = FALSE;
            }
            $this->SetData('_Count', $ActualResponses);
            // Build a pager
            $PagerFactory = new Gdn_PagerFactory();
            $this->EventArguments['PagerType'] = 'MorePager';
            $this->FireEvent('BeforeBuildPager');
            $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
            $this->Pager->ClientID = 'Pager';
            $this->Pager->MoreCode = 'More Comments';
            $this->Pager->Configure($this->Offset, $Limit, $ActualResponses, 'discussion/embed/' . $Discussion->DiscussionID . '/' . Gdn_Format::Url($Discussion->Name) . '/%1$s');
            $this->Pager->CurrentRecords = $this->Comments->NumRows();
            $this->FireEvent('AfterBuildPager');
        }
        // Define the form for the comment input
        $this->Form = Gdn::Factory('Form', 'Comment');
        $this->Form->Action = Url('/vanilla/post/comment/');
        $this->Form->AddHidden('CommentID', '');
        $this->Form->AddHidden('Embedded', 'true');
        // Tell the post controller that this is an embedded page (in case there are custom views it needs to pick up from a theme).
        $this->Form->AddHidden('DisplayNewCommentOnly', 'true');
        // Only load/display the new comment after posting (don't load all new comments since the page last loaded).
        // Grab the page title
        if ($this->Request->Get('title')) {
            $this->Form->SetValue('Name', $this->Request->Get('title'));
        }
        // Set existing DiscussionID for comment form
        if ($Discussion) {
            $this->Form->AddHidden('DiscussionID', $Discussion->DiscussionID);
        }
        foreach ($ForeignSource as $Key => $Val) {
            // Drop the foreign source information into the form so it can be used if creating a discussion
            $this->Form->AddHidden($Key, $Val);
            // Also drop it into the definitions so it can be picked up for stashing comments
            $this->AddDefinition($Key, $Val);
        }
        // Retrieve & apply the draft if there is one:
        $Draft = FALSE;
        if (Gdn::Session()->UserID && $Discussion) {
            $DraftModel = new DraftModel();
            $Draft = $DraftModel->Get(Gdn::Session()->UserID, 0, 1, $Discussion->DiscussionID)->FirstRow();
            $this->Form->AddHidden('DraftID', $Draft ? $Draft->DraftID : '');
        }
        if ($Draft) {
            $this->Form->SetFormValue('Body', $Draft->Body);
        } else {
            // Look in the session stash for a comment
            $StashComment = Gdn::Session()->Stash('CommentForForeignID_' . $ForeignSource['vanilla_identifier'], '', FALSE);
            if ($StashComment) {
                $this->Form->SetValue('Body', $StashComment);
                $this->Form->SetFormValue('Body', $StashComment);
            }
        }
        // Deliver JSON data if necessary
        if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
            if ($this->Discussion) {
                $this->SetJson('LessRow', $this->Pager->ToString('less'));
                $this->SetJson('MoreRow', $this->Pager->ToString('more'));
            }
            $this->View = 'comments';
        }
        // Ordering note for JS
        if ($SortComments == 'desc') {
            $this->AddDefinition('PrependNewComments', '1');
        }
        // Report the discussion id so js can use it.
        if ($Discussion) {
            $this->AddDefinition('DiscussionID', $Discussion->DiscussionID);
        }
        $this->FireEvent('BeforeDiscussionRender');
        $this->Render();
    }
Exemplo n.º 11
0
 public function ToStringPrevNext($Type = 'more')
 {
     $this->CssClass = ConcatSep(' ', $this->CssClass, 'PrevNextPager');
     $CurrentPage = PageNumber($this->Offset, $this->Limit);
     $Pager = '';
     if ($CurrentPage > 1) {
         $PageParam = 'p' . ($CurrentPage - 1);
         $Pager .= Anchor(T('Previous'), self::FormatUrl($this->Url, $PageParam), 'Previous');
     }
     $HasNext = TRUE;
     if ($this->CurrentRecords !== FALSE && $this->CurrentRecords < $this->Limit) {
         $HasNext = FALSE;
     }
     if ($HasNext) {
         $PageParam = 'p' . ($CurrentPage + 1);
         $Pager = ConcatSep(' ', $Pager, Anchor('Next', self::FormatUrl($this->Url, $PageParam), 'Next'));
     }
     $ClientID = $this->ClientID;
     $ClientID = $Type == 'more' ? $ClientID . 'After' : $ClientID . 'Before';
     if (isset($this->HtmlBefore)) {
         $Pager = $this->HtmlBefore . $Pager;
     }
     return $Pager == '' ? '' : sprintf($this->Wrapper, Attribute(array('id' => $ClientID, 'class' => $this->CssClass)), $Pager);
 }
Exemplo n.º 12
0
 /**
  * Return the page number from the given variables that may have an offset or a page.
  *
  * @param array $Vars The variables that should contain an Offset or Page key.
  * @param int|string $PageSize The pagesize or the config key of the pagesize.
  * @return int
  */
 public static function PageNumber($Vars, $PageSize)
 {
     if (isset($Vars['Page'])) {
         return $Vars['Page'];
     }
     if (isset($Vars['Offset'])) {
         if (is_numeric($PageSize)) {
             return PageNumber($Vars['Offset'], $PageSize, FALSE, Gdn::Session()->IsValid());
         } else {
             return PageNumber($Vars['Offset'], C($PageSize, 30), FALSE, Gdn::Session()->IsValid());
         }
     }
     return 1;
 }
Exemplo n.º 13
0
 /**
  * Load popular discussions.
  */
 public function DiscussionsController_Popular_Create($Sender)
 {
     $Sender->Title(T('Popular'));
     // Get rid of announcements from this view
     if ($Sender->Head) {
         $Sender->AddJsFile('discussions.js');
         $Sender->Head->AddRss($Sender->SelfUrl . '/feed.rss', $Sender->Head->Title());
     }
     // Add Modules
     $Sender->AddModule('DiscussionFilterModule');
     $Sender->AddModule('NewDiscussionModule');
     $Sender->AddModule('CategoriesModule');
     $Sender->AddModule('BookmarkedModule');
     // Determine offset from $Page
     $Page = GetValue('0', $Sender->RequestArgs, 'p1');
     list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     $Page = PageNumber($Offset, $Limit);
     $Sender->SetData('Category', FALSE, TRUE);
     $Limit = C('Vanilla.Discussions.PerPage', 30);
     $DiscussionModel = new DiscussionModel();
     $CountDiscussions = $DiscussionModel->GetCount();
     $Sender->SetData('CountDiscussions', $CountDiscussions);
     $Sender->AnnounceData = FALSE;
     $Sender->SetData('Announcements', array(), TRUE);
     $DiscussionModel->SQL->OrderBy('d.Score', 'desc');
     $DiscussionModel->SQL->OrderBy('d.CountViews', 'desc');
     $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/popular/%1$s');
     if (!$Sender->Data('_PagerUrl')) {
         $Sender->SetData('_PagerUrl', 'discussions/popular/{Page}');
     }
     $Sender->SetData('_Page', $Page);
     $Sender->SetData('_Limit', $Limit);
     // 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';
     }
     // Render the controller
     $Sender->View = 'index';
     $Sender->Render();
 }
Exemplo n.º 14
0
 /**
  * Load discussions for a specific tag.
  */
 public function DiscussionsController_Tagged_Create($Sender)
 {
     Gdn_Theme::Section('DiscussionList');
     if ($Sender->Request->Get('Tag')) {
         $Tag = $Sender->Request->Get('Tag');
         $Page = GetValue('0', $Sender->RequestArgs, 'p1');
     } else {
         $Tag = urldecode(GetValue('0', $Sender->RequestArgs, ''));
         $Page = GetValue('1', $Sender->RequestArgs, 'p1');
     }
     if ($Sender->Request->Get('Page')) {
         $Page = $Sender->Request->Get('Page');
     }
     $Tag = StringEndsWith($Tag, '.rss', TRUE, TRUE);
     list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
     $Sender->SetData('Tag', $Tag, TRUE);
     $Sender->Title(T('Tagged with ') . htmlspecialchars($Tag));
     $Sender->Head->Title($Sender->Head->Title());
     $UrlTag = rawurlencode($Tag);
     if (urlencode($Tag) == $Tag) {
         $Sender->CanonicalUrl(Url(ConcatSep('/', "/discussions/tagged/{$UrlTag}", PageNumber($Offset, $Limit, TRUE)), TRUE));
         $FeedUrl = Url(ConcatSep('/', "/discussions/tagged/{$UrlTag}/feed.rss", PageNumber($Offset, $Limit, TRUE, FALSE)), '//');
     } else {
         $Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE)) . '?Tag=' . $UrlTag, TRUE));
         $FeedUrl = Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE, FALSE), 'feed.rss') . '?Tag=' . $UrlTag, '//');
     }
     if ($Sender->Head) {
         $Sender->AddJsFile('discussions.js');
         $Sender->Head->AddRss($FeedUrl, $Sender->Head->Title());
     }
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     // Add Modules
     $Sender->AddModule('NewDiscussionModule');
     $Sender->AddModule('DiscussionFilterModule');
     $BookmarkedModule = new BookmarkedModule($Sender);
     $BookmarkedModule->GetData();
     $Sender->AddModule($BookmarkedModule);
     $Sender->SetData('Category', FALSE, TRUE);
     $Sender->SetData('CountDiscussions', FALSE);
     $Sender->AnnounceData = FALSE;
     $Sender->SetData('Announcements', array(), TRUE);
     $DiscussionModel = new DiscussionModel();
     $this->_SetTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Sender->Request->Get('op', 'or'));
     $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit, array('Announce' => 'all'));
     $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';
     if (urlencode($Sender->Tag) == $Sender->Tag) {
         $PageUrlFormat = "discussions/tagged/{$Sender->Tag}/{Page}";
     } else {
         $PageUrlFormat = 'discussions/tagged/{Page}?Tag=' . urlencode($Sender->Tag);
     }
     $Sender->Pager->Configure($Offset, $Limit, FALSE, $PageUrlFormat);
     // 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';
     }
     // Render the controller
     $Sender->Render('TaggedDiscussions', '', 'plugins/Tagging');
 }
Exemplo n.º 15
0
 /**
  * Load discussions for a specific tag.
  *
  * @param DiscussionsController $Sender Sending controller instance
  * @param array $Args Event's arguments
  * @throws Exception
  */
 public function discussionsController_tagged_create($Sender, $Args)
 {
     Gdn_Theme::section('DiscussionList');
     $Args = $Sender->RequestArgs;
     $Get = array_change_key_case($Sender->Request->get());
     if ($UseCategories = c('Plugins.Tagging.UseCategories')) {
         // The url is in the form /category/tag/p1
         $CategoryCode = val(0, $Args);
         $Tag = val(1, $Args);
         $Page = val(2, $Args);
     } else {
         // The url is in the form /tag/p1
         $CategoryCode = '';
         $Tag = val(0, $Args);
         $Page = val(1, $Args);
     }
     // Look for explcit values.
     $CategoryCode = val('category', $Get, $CategoryCode);
     $Tag = val('tag', $Get, $Tag);
     $Page = val('page', $Get, $Page);
     $Category = CategoryModel::categories($CategoryCode);
     $Tag = stringEndsWith($Tag, '.rss', true, true);
     list($Offset, $Limit) = offsetLimit($Page, c('Vanilla.Discussions.PerPage', 30));
     $MultipleTags = strpos($Tag, ',') !== false;
     $Sender->setData('Tag', $Tag, true);
     $TagModel = TagModel::instance();
     $RecordCount = false;
     if (!$MultipleTags) {
         $Tags = $TagModel->getWhere(array('Name' => $Tag))->resultArray();
         if (count($Tags) == 0) {
             throw notFoundException('Page');
         }
         if (count($Tags) > 1) {
             foreach ($Tags as $TagRow) {
                 if ($TagRow['CategoryID'] == val('CategoryID', $Category)) {
                     break;
                 }
             }
         } else {
             $TagRow = array_pop($Tags);
         }
         $Tags = $TagModel->getRelatedTags($TagRow);
         $RecordCount = $TagRow['CountDiscussions'];
         $Sender->setData('CountDiscussions', $RecordCount);
         $Sender->setData('Tags', $Tags);
         $Sender->setData('Tag', $TagRow);
         $ChildTags = $TagModel->getChildTags($TagRow['TagID']);
         $Sender->setData('ChildTags', $ChildTags);
     }
     $Sender->title(htmlspecialchars($TagRow['FullName']));
     $UrlTag = empty($CategoryCode) ? rawurlencode($Tag) : rawurlencode($CategoryCode) . '/' . rawurlencode($Tag);
     if (urlencode($Tag) == $Tag) {
         $Sender->canonicalUrl(url(ConcatSep('/', "/discussions/tagged/{$UrlTag}", PageNumber($Offset, $Limit, true)), true));
         $FeedUrl = url(ConcatSep('/', "/discussions/tagged/{$UrlTag}/feed.rss", PageNumber($Offset, $Limit, true, false)), '//');
     } else {
         $Sender->canonicalUrl(url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, true)) . '?Tag=' . $UrlTag, true));
         $FeedUrl = url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, true, false), 'feed.rss') . '?Tag=' . $UrlTag, '//');
     }
     if ($Sender->Head) {
         $Sender->addJsFile('discussions.js');
         $Sender->Head->addRss($FeedUrl, $Sender->Head->title());
     }
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     // Add Modules
     $Sender->addModule('NewDiscussionModule');
     $Sender->addModule('DiscussionFilterModule');
     $Sender->addModule('BookmarkedModule');
     $Sender->setData('Category', false, true);
     $Sender->AnnounceData = false;
     $Sender->setData('Announcements', array(), true);
     $DiscussionModel = new DiscussionModel();
     $TagModel->setTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Sender->Request->get('op', 'or'));
     $Sender->DiscussionData = $DiscussionModel->get($Offset, $Limit, array('Announce' => 'all'));
     $Sender->setData('Discussions', $Sender->DiscussionData, true);
     $Sender->setJson('Loading', $Offset . ' to ' . $Limit);
     // Build a pager.
     $PagerFactory = new Gdn_PagerFactory();
     $Sender->EventArguments['PagerType'] = 'Pager';
     $Sender->fireEvent('BeforeBuildPager');
     if (!$Sender->data('_PagerUrl')) {
         $Sender->setData('_PagerUrl', "/discussions/tagged/{$UrlTag}/{Page}");
     }
     $Sender->Pager = $PagerFactory->GetPager($Sender->EventArguments['PagerType'], $Sender);
     $Sender->Pager->ClientID = 'Pager';
     $Sender->Pager->configure($Offset, $Limit, $RecordCount, $Sender->data('_PagerUrl'));
     $Sender->setData('_Page', $Page);
     $Sender->setData('_Limit', $Limit);
     $Sender->fireEvent('AfterBuildPager');
     $Sender->View = c('Vanilla.Discussions.Layout');
     // Render the controller.
     $this->View = c('Vanilla.Discussions.Layout') == 'table' && $Sender->SyndicationMethod == SYNDICATION_NONE ? 'table' : 'index';
     $Sender->render($this->View, 'discussions', 'vanilla');
 }
 /**
  * Show all discussions in a particular category.
  *
  * @since 2.0.0
  * @access public
  *
  * @param string $CategoryIdentifier Unique category slug or ID.
  * @param int $Offset Number of discussions to skip.
  */
 public function index($CategoryIdentifier = '', $Page = '0')
 {
     // Figure out which category layout to choose (Defined on "Homepage" settings page).
     $Layout = c('Vanilla.Categories.Layout');
     if ($CategoryIdentifier == '') {
         switch ($Layout) {
             case 'mixed':
                 $this->View = 'discussions';
                 $this->Discussions();
                 break;
             case 'table':
                 $this->table();
                 break;
             default:
                 $this->View = 'all';
                 $this->All();
                 break;
         }
         return;
     } else {
         $Category = CategoryModel::categories($CategoryIdentifier);
         if (empty($Category)) {
             // Try lowercasing before outright failing
             $LowerCategoryIdentifier = strtolower($CategoryIdentifier);
             if ($LowerCategoryIdentifier != $CategoryIdentifier) {
                 $Category = CategoryModel::categories($LowerCategoryIdentifier);
                 if ($Category) {
                     redirect("/categories/{$LowerCategoryIdentifier}", 301);
                 }
             }
             throw notFoundException();
         }
         $Category = (object) $Category;
         Gdn_Theme::section($Category->CssClass);
         // Load the breadcrumbs.
         $this->setData('Breadcrumbs', CategoryModel::GetAncestors(val('CategoryID', $Category)));
         $this->setData('Category', $Category, true);
         $this->title(htmlspecialchars(val('Name', $Category, '')));
         $this->Description(val('Description', $Category), true);
         if ($Category->DisplayAs == 'Categories') {
             if (val('Depth', $Category) > c('Vanilla.Categories.NavDepth', 0)) {
                 // Headings don't make sense if we've cascaded down one level.
                 saveToConfig('Vanilla.Categories.DoHeadings', false, false);
             }
             trace($this->deliveryMethod(), 'delivery method');
             trace($this->deliveryType(), 'delivery type');
             trace($this->SyndicationMethod, 'syndication');
             if ($this->SyndicationMethod != SYNDICATION_NONE) {
                 // RSS can't show a category list so just tell it to expand all categories.
                 saveToConfig('Vanilla.ExpandCategories', true, false);
             } else {
                 // This category is an overview style category and displays as a category list.
                 switch ($Layout) {
                     case 'mixed':
                         $this->View = 'discussions';
                         $this->Discussions($CategoryIdentifier);
                         break;
                     case 'table':
                         $this->table($CategoryIdentifier);
                         break;
                     default:
                         $this->View = 'all';
                         $this->All($CategoryIdentifier);
                         break;
                 }
                 return;
             }
         }
         Gdn_Theme::section('DiscussionList');
         // Figure out which discussions layout to choose (Defined on "Homepage" settings page).
         $Layout = c('Vanilla.Discussions.Layout');
         switch ($Layout) {
             case 'table':
                 if ($this->SyndicationMethod == SYNDICATION_NONE) {
                     $this->View = 'table';
                 }
                 break;
             default:
                 // $this->View = 'index';
                 break;
         }
         // Load the subtree.
         $Categories = CategoryModel::GetSubtree($CategoryIdentifier, false);
         $this->setData('Categories', $Categories);
         // Setup head
         $this->Menu->highlightRoute('/discussions');
         if ($this->Head) {
             $this->addJsFile('discussions.js');
             $this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->title());
         }
         // Set CategoryID
         $CategoryID = val('CategoryID', $Category);
         $this->setData('CategoryID', $CategoryID, true);
         // Add modules
         $this->addModule('NewDiscussionModule');
         $this->addModule('DiscussionFilterModule');
         $this->addModule('CategoriesModule');
         $this->addModule('BookmarkedModule');
         // Get a DiscussionModel
         $DiscussionModel = new DiscussionModel();
         $CategoryIDs = array($CategoryID);
         if (c('Vanilla.ExpandCategories')) {
             $CategoryIDs = array_merge($CategoryIDs, array_column($this->data('Categories'), 'CategoryID'));
         }
         $Wheres = array('d.CategoryID' => $CategoryIDs);
         $this->setData('_ShowCategoryLink', count($CategoryIDs) > 1);
         // Check permission
         $this->permission('Vanilla.Discussions.View', true, 'Category', val('PermissionCategoryID', $Category));
         // Set discussion meta data.
         $this->EventArguments['PerPage'] = c('Vanilla.Discussions.PerPage', 30);
         $this->fireEvent('BeforeGetDiscussions');
         list($Offset, $Limit) = offsetLimit($Page, $this->EventArguments['PerPage']);
         if (!is_numeric($Offset) || $Offset < 0) {
             $Offset = 0;
         }
         $Page = PageNumber($Offset, $Limit);
         // Allow page manipulation
         $this->EventArguments['Page'] =& $Page;
         $this->EventArguments['Offset'] =& $Offset;
         $this->EventArguments['Limit'] =& $Limit;
         $this->fireEvent('AfterPageCalculation');
         // We want to limit the number of pages on large databases because requesting a super-high page can kill the db.
         $MaxPages = c('Vanilla.Categories.MaxPages');
         if ($MaxPages && $Page > $MaxPages) {
             throw notFoundException();
         }
         $CountDiscussions = $DiscussionModel->getCount($Wheres);
         if ($MaxPages && $MaxPages * $Limit < $CountDiscussions) {
             $CountDiscussions = $MaxPages * $Limit;
         }
         $this->setData('CountDiscussions', $CountDiscussions);
         $this->setData('_Limit', $Limit);
         // We don't wan't child categories in announcements.
         $Wheres['d.CategoryID'] = $CategoryID;
         $AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet();
         $this->setData('AnnounceData', $AnnounceData, true);
         $Wheres['d.CategoryID'] = $CategoryIDs;
         $this->DiscussionData = $this->setData('Discussions', $DiscussionModel->getWhere($Wheres, $Offset, $Limit));
         // Build a pager
         $PagerFactory = new Gdn_PagerFactory();
         $this->EventArguments['PagerType'] = 'Pager';
         $this->fireEvent('BeforeBuildPager');
         $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
         $this->Pager->ClientID = 'Pager';
         $this->Pager->configure($Offset, $Limit, $CountDiscussions, array('CategoryUrl'));
         $this->Pager->Record = $Category;
         PagerModule::Current($this->Pager);
         $this->setData('_Page', $Page);
         $this->setData('_Limit', $Limit);
         $this->fireEvent('AfterBuildPager');
         // Set the canonical Url.
         $this->canonicalUrl(CategoryUrl($Category, PageNumber($Offset, $Limit)));
         // Change the controller name so that it knows to grab the discussion views
         $this->ControllerName = 'DiscussionsController';
         // Pick up the discussions class
         $this->CssClass = 'Discussions Category-' . GetValue('UrlCode', $Category);
         // Deliver JSON data if necessary
         if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
             $this->setJson('LessRow', $this->Pager->toString('less'));
             $this->setJson('MoreRow', $this->Pager->toString('more'));
             $this->View = 'discussions';
         }
         // Render default view.
         $this->fireEvent('BeforeCategoriesRender');
         $this->render();
     }
 }
 /**
  * Show all discussions in a particular category.
  * 
  * @since 2.0.0
  * @access public
  * 
  * @param string $CategoryIdentifier Unique category slug or ID.
  * @param int $Offset Number of discussions to skip.
  */
 public function Index($CategoryIdentifier = '', $Page = '0')
 {
     if ($CategoryIdentifier == '') {
         // Figure out which category layout to choose (Defined on "Homepage" settings page).
         $Layout = C('Vanilla.Categories.Layout');
         switch ($Layout) {
             case 'mixed':
                 $this->View = 'discussions';
                 $this->Discussions();
                 break;
             case 'table':
                 $this->Table();
                 break;
             default:
                 $this->View = 'all';
                 $this->All();
                 break;
         }
         return;
     } else {
         Gdn_Theme::Section('DiscussionList');
         // Figure out which discussions layout to choose (Defined on "Homepage" settings page).
         $Layout = C('Vanilla.Discussions.Layout');
         switch ($Layout) {
             case 'table':
                 if ($this->SyndicationMethod == SYNDICATION_NONE) {
                     $this->View = 'table';
                 }
                 break;
             default:
                 // $this->View = 'index';
                 break;
         }
         $Category = CategoryModel::Categories($CategoryIdentifier);
         if (empty($Category)) {
             if ($CategoryIdentifier) {
                 throw NotFoundException();
             }
         }
         $Category = (object) $Category;
         Gdn_Theme::Section($Category->CssClass);
         // Load the breadcrumbs.
         $this->SetData('Breadcrumbs', CategoryModel::GetAncestors(GetValue('CategoryID', $Category)));
         $this->SetData('Category', $Category, TRUE);
         // Load the subtree.
         if (C('Vanilla.ExpandCategories')) {
             $Categories = CategoryModel::GetSubtree($CategoryIdentifier);
         } else {
             $Categories = array($Category);
         }
         $this->SetData('Categories', $Categories);
         // Setup head
         $this->AddCssFile('vanilla.css');
         $this->Menu->HighlightRoute('/discussions');
         if ($this->Head) {
             $this->AddJsFile('discussions.js');
             $this->AddJsFile('bookmark.js');
             $this->AddJsFile('options.js');
             $this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
         }
         $this->Title(GetValue('Name', $Category, ''));
         $this->Description(GetValue('Description', $Category), TRUE);
         // Set CategoryID
         $CategoryID = GetValue('CategoryID', $Category);
         $this->SetData('CategoryID', $CategoryID, TRUE);
         // Add modules
         $this->AddModule('NewDiscussionModule');
         $this->AddModule('DiscussionFilterModule');
         $this->AddModule('CategoriesModule');
         $this->AddModule('BookmarkedModule');
         // Get a DiscussionModel
         $DiscussionModel = new DiscussionModel();
         $CategoryIDs = ConsolidateArrayValuesByKey($this->Data('Categories'), 'CategoryID');
         $Wheres = array('d.CategoryID' => $CategoryIDs);
         $this->SetData('_ShowCategoryLink', count($CategoryIDs) > 1);
         // Check permission
         $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', GetValue('PermissionCategoryID', $Category));
         // Set discussion meta data.
         $this->EventArguments['PerPage'] = C('Vanilla.Discussions.PerPage', 30);
         $this->FireEvent('BeforeGetDiscussions');
         list($Offset, $Limit) = OffsetLimit($Page, $this->EventArguments['PerPage']);
         if (!is_numeric($Offset) || $Offset < 0) {
             $Offset = 0;
         }
         $CountDiscussions = $DiscussionModel->GetCount($Wheres);
         $this->SetData('CountDiscussions', $CountDiscussions);
         $this->SetData('_Limit', $Limit);
         // We don't wan't child categories in announcements.
         $Wheres['d.CategoryID'] = $CategoryID;
         $AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet();
         $this->SetData('AnnounceData', $AnnounceData, TRUE);
         $Wheres['d.CategoryID'] = $CategoryIDs;
         $this->DiscussionData = $this->SetData('Discussions', $DiscussionModel->GetWhere($Wheres, $Offset, $Limit));
         // Build a pager
         $PagerFactory = new Gdn_PagerFactory();
         $this->Pager = $PagerFactory->GetPager('Pager', $this);
         $this->Pager->ClientID = 'Pager';
         $this->Pager->Configure($Offset, $Limit, $CountDiscussions, array('CategoryUrl'));
         $this->Pager->Record = $Category;
         PagerModule::Current($this->Pager);
         $this->SetData('_Page', $Page);
         // Set the canonical Url.
         $this->CanonicalUrl(CategoryUrl($Category, PageNumber($Offset, $Limit)));
         // Change the controller name so that it knows to grab the discussion views
         $this->ControllerName = 'DiscussionsController';
         // Pick up the discussions class
         $this->CssClass = 'Discussions';
         // Deliver JSON data if necessary
         if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
             $this->SetJson('LessRow', $this->Pager->ToString('less'));
             $this->SetJson('MoreRow', $this->Pager->ToString('more'));
             $this->View = 'discussions';
         }
         // Render default view.
         $this->FireEvent('BeforeCategoriesRender');
         $this->Render();
     }
 }
Exemplo n.º 18
0
 /**
  * Show all discussions in a particular category.
  *
  * @since 2.0.0
  * @access public
  *
  * @param string $CategoryIdentifier Unique category slug or ID.
  * @param int $Offset Number of discussions to skip.
  */
 public function index($CategoryIdentifier = '', $Page = '0')
 {
     // Figure out which category layout to choose (Defined on "Homepage" settings page).
     $Layout = c('Vanilla.Categories.Layout');
     if ($CategoryIdentifier == '') {
         switch ($Layout) {
             case 'mixed':
                 $this->View = 'discussions';
                 $this->discussions();
                 break;
             case 'table':
                 $this->table();
                 break;
             default:
                 $this->View = 'all';
                 $this->all('', CategoryModel::getRootDisplayAs());
                 break;
         }
         return;
     } else {
         $Category = CategoryModel::categories($CategoryIdentifier);
         if (empty($Category)) {
             throw notFoundException();
         }
         $Category = (object) $Category;
         Gdn_Theme::section($Category->CssClass);
         // Load the breadcrumbs.
         $this->setData('Breadcrumbs', CategoryModel::getAncestors(val('CategoryID', $Category)));
         $this->setData('Category', $Category, true);
         $this->title(htmlspecialchars(val('Name', $Category, '')));
         $this->description(val('Description', $Category), true);
         switch ($Category->DisplayAs) {
             case 'Flat':
             case 'Heading':
             case 'Categories':
                 $stopHeadings = val('Depth', $Category) > CategoryModel::instance()->getNavDepth();
                 CategoryModel::instance()->setStopHeadingsCalculation($stopHeadings);
                 if ($this->SyndicationMethod != SYNDICATION_NONE) {
                     // RSS can't show a category list so just tell it to expand all categories.
                     saveToConfig('Vanilla.ExpandCategories', true, false);
                 } else {
                     // This category is an overview style category and displays as a category list.
                     switch ($Layout) {
                         case 'mixed':
                             $this->View = 'discussions';
                             $this->discussions($CategoryIdentifier);
                             break;
                         case 'table':
                             $this->table($CategoryIdentifier, $Category->DisplayAs);
                             break;
                         default:
                             $this->View = 'all';
                             $this->All($CategoryIdentifier, $Category->DisplayAs);
                             break;
                     }
                     return;
                 }
                 break;
         }
         Gdn_Theme::section('DiscussionList');
         // Figure out which discussions layout to choose (Defined on "Homepage" settings page).
         $Layout = c('Vanilla.Discussions.Layout');
         switch ($Layout) {
             case 'table':
                 if ($this->SyndicationMethod == SYNDICATION_NONE) {
                     $this->View = 'table';
                 }
                 break;
             default:
                 // $this->View = 'index';
                 break;
         }
         $this->setData('CategoryTree', $this->getCategoryTree($CategoryIdentifier, val('DisplayAs', $Category)));
         // Add a backwards-compatibility shim for the old categories.
         $this->categoriesCompatibilityCallback = function () use($CategoryIdentifier) {
             $categories = CategoryModel::getSubtree($CategoryIdentifier, false);
             return $categories;
         };
         // Setup head
         $this->Menu->highlightRoute('/discussions');
         if ($this->Head) {
             $this->addJsFile('discussions.js');
             $this->Head->addRss(categoryUrl($Category) . '/feed.rss', $this->Head->title());
         }
         // Set CategoryID
         $CategoryID = val('CategoryID', $Category);
         $this->setData('CategoryID', $CategoryID, true);
         // Add modules
         $this->addModule('NewDiscussionModule');
         $this->addModule('DiscussionFilterModule');
         $this->addModule('CategoriesModule');
         $this->addModule('BookmarkedModule');
         // Get a DiscussionModel
         $DiscussionModel = new DiscussionModel();
         $DiscussionModel->setSort(Gdn::request()->get());
         $DiscussionModel->setFilters(Gdn::request()->get());
         $this->setData('Sort', $DiscussionModel->getSort());
         $this->setData('Filters', $DiscussionModel->getFilters());
         $CategoryIDs = array($CategoryID);
         if (c('Vanilla.ExpandCategories')) {
             $CategoryIDs = array_merge($CategoryIDs, array_column($this->data('Categories'), 'CategoryID'));
         }
         $Wheres = array('d.CategoryID' => $CategoryIDs);
         $this->setData('_ShowCategoryLink', count($CategoryIDs) > 1);
         // Check permission
         $this->permission('Vanilla.Discussions.View', true, 'Category', val('PermissionCategoryID', $Category));
         // Set discussion meta data.
         $this->EventArguments['PerPage'] = c('Vanilla.Discussions.PerPage', 30);
         $this->fireEvent('BeforeGetDiscussions');
         list($Offset, $Limit) = offsetLimit($Page, $this->EventArguments['PerPage']);
         if (!is_numeric($Offset) || $Offset < 0) {
             $Offset = 0;
         }
         $Page = PageNumber($Offset, $Limit);
         // Allow page manipulation
         $this->EventArguments['Page'] =& $Page;
         $this->EventArguments['Offset'] =& $Offset;
         $this->EventArguments['Limit'] =& $Limit;
         $this->fireEvent('AfterPageCalculation');
         // We want to limit the number of pages on large databases because requesting a super-high page can kill the db.
         $MaxPages = c('Vanilla.Categories.MaxPages');
         if ($MaxPages && $Page > $MaxPages) {
             throw notFoundException();
         }
         $CountDiscussions = $DiscussionModel->getCount($Wheres);
         if ($MaxPages && $MaxPages * $Limit < $CountDiscussions) {
             $CountDiscussions = $MaxPages * $Limit;
         }
         $this->setData('CountDiscussions', $CountDiscussions);
         $this->setData('_Limit', $Limit);
         // We don't wan't child categories in announcements.
         $Wheres['d.CategoryID'] = $CategoryID;
         $AnnounceData = $DiscussionModel->getAnnouncements($Wheres, $Offset, $Limit);
         $this->AnnounceData = $this->setData('Announcements', $AnnounceData);
         $Wheres['d.CategoryID'] = $CategoryIDs;
         // RSS should include announcements.
         if ($this->SyndicationMethod !== SYNDICATION_NONE) {
             $Wheres['Announce'] = 'all';
         }
         $this->DiscussionData = $this->setData('Discussions', $DiscussionModel->getWhereRecent($Wheres, $Limit, $Offset));
         // Build a pager
         $PagerFactory = new Gdn_PagerFactory();
         $url = CategoryUrl($CategoryIdentifier);
         $this->EventArguments['PagerType'] = 'Pager';
         $this->fireEvent('BeforeBuildPager');
         if (!$this->data('_PagerUrl')) {
             $this->setData('_PagerUrl', $url . '/{Page}');
         }
         $queryString = DiscussionModel::getSortFilterQueryString($DiscussionModel->getSort(), $DiscussionModel->getFilters());
         $this->setData('_PagerUrl', $this->data('_PagerUrl') . $queryString);
         $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
         $this->Pager->ClientID = 'Pager';
         $this->Pager->configure($Offset, $Limit, $CountDiscussions, $this->data('_PagerUrl'));
         $this->Pager->Record = $Category;
         PagerModule::current($this->Pager);
         $this->setData('_Page', $Page);
         $this->setData('_Limit', $Limit);
         $this->fireEvent('AfterBuildPager');
         // Set the canonical Url.
         $this->canonicalUrl(categoryUrl($Category, pageNumber($Offset, $Limit)));
         // Change the controller name so that it knows to grab the discussion views
         $this->ControllerName = 'DiscussionsController';
         // Pick up the discussions class
         $this->CssClass = 'Discussions Category-' . val('UrlCode', $Category);
         // Deliver JSON data if necessary
         if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
             $this->setJson('LessRow', $this->Pager->toString('less'));
             $this->setJson('MoreRow', $this->Pager->toString('more'));
             $this->View = 'discussions';
         }
         // Render default view.
         $this->fireEvent('BeforeCategoriesRender');
         $this->render();
     }
 }
 /**
  * Default single discussion display.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $DiscussionID Unique discussion ID
  * @param string $DiscussionStub URL-safe title slug
  * @param int $Page The current page of comments
  */
 public function index($DiscussionID = '', $DiscussionStub = '', $Page = '')
 {
     // Setup head
     $Session = Gdn::session();
     $this->addJsFile('jquery.autosize.min.js');
     $this->addJsFile('autosave.js');
     $this->addJsFile('discussion.js');
     Gdn_Theme::section('Discussion');
     // Load the discussion record
     $DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0;
     if (!array_key_exists('Discussion', $this->Data)) {
         $this->setData('Discussion', $this->DiscussionModel->getID($DiscussionID), true);
     }
     if (!is_object($this->Discussion)) {
         $this->EventArguments['DiscussionID'] = $DiscussionID;
         $this->fireEvent('DiscussionNotFound');
         throw notFoundException('Discussion');
     }
     // Define the query offset & limit.
     $Limit = c('Vanilla.Comments.PerPage', 30);
     $OffsetProvided = $Page != '';
     list($Offset, $Limit) = offsetLimit($Page, $Limit);
     // Check permissions
     $this->permission('Vanilla.Discussions.View', true, 'Category', $this->Discussion->PermissionCategoryID);
     $this->setData('CategoryID', $this->CategoryID = $this->Discussion->CategoryID, true);
     if (strcasecmp(val('Type', $this->Discussion), 'redirect') === 0) {
         $this->redirectDiscussion($this->Discussion);
     }
     $Category = CategoryModel::categories($this->Discussion->CategoryID);
     $this->setData('Category', $Category);
     if ($CategoryCssClass = val('CssClass', $Category)) {
         Gdn_Theme::section($CategoryCssClass);
     }
     $this->setData('Breadcrumbs', CategoryModel::getAncestors($this->CategoryID));
     // Setup
     $this->title($this->Discussion->Name);
     // Actual number of comments, excluding the discussion itself.
     $ActualResponses = $this->Discussion->CountComments;
     $this->Offset = $Offset;
     if (c('Vanilla.Comments.AutoOffset')) {
         //         if ($this->Discussion->CountCommentWatch > 1 && $OffsetProvided == '')
         //            $this->addDefinition('ScrollTo', 'a[name=Item_'.$this->Discussion->CountCommentWatch.']');
         if (!is_numeric($this->Offset) || $this->Offset < 0 || !$OffsetProvided) {
             // Round down to the appropriate offset based on the user's read comments & comments per page
             $CountCommentWatch = $this->Discussion->CountCommentWatch > 0 ? $this->Discussion->CountCommentWatch : 0;
             if ($CountCommentWatch > $ActualResponses) {
                 $CountCommentWatch = $ActualResponses;
             }
             // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
             $this->Offset = floor($CountCommentWatch / $Limit) * $Limit;
         }
         if ($ActualResponses <= $Limit) {
             $this->Offset = 0;
         }
         if ($this->Offset == $ActualResponses) {
             $this->Offset -= $Limit;
         }
     } else {
         if ($this->Offset == '') {
             $this->Offset = 0;
         }
     }
     if ($this->Offset < 0) {
         $this->Offset = 0;
     }
     $LatestItem = $this->Discussion->CountCommentWatch;
     if ($LatestItem === null) {
         $LatestItem = 0;
     } elseif ($LatestItem < $this->Discussion->CountComments) {
         $LatestItem += 1;
     }
     $this->setData('_LatestItem', $LatestItem);
     // Set the canonical url to have the proper page title.
     $this->canonicalUrl(discussionUrl($this->Discussion, pageNumber($this->Offset, $Limit, 0, false)));
     //      url(ConcatSep('/', 'discussion/'.$this->Discussion->DiscussionID.'/'. Gdn_Format::url($this->Discussion->Name), PageNumber($this->Offset, $Limit, TRUE, Gdn::session()->UserID != 0)), true), Gdn::session()->UserID == 0);
     // Load the comments
     $this->setData('Comments', $this->CommentModel->get($DiscussionID, $Limit, $this->Offset));
     $PageNumber = PageNumber($this->Offset, $Limit);
     $this->setData('Page', $PageNumber);
     $this->_SetOpenGraph();
     include_once PATH_LIBRARY . '/vendors/simplehtmldom/simple_html_dom.php';
     if ($PageNumber == 1) {
         $this->description(sliceParagraph(Gdn_Format::plainText($this->Discussion->Body, $this->Discussion->Format), 160));
         // Add images to head for open graph
         $Dom = str_get_html(Gdn_Format::to($this->Discussion->Body, $this->Discussion->Format));
     } else {
         $this->Data['Title'] .= sprintf(t(' - Page %s'), PageNumber($this->Offset, $Limit));
         $FirstComment = $this->data('Comments')->firstRow();
         $FirstBody = val('Body', $FirstComment);
         $FirstFormat = val('Format', $FirstComment);
         $this->description(sliceParagraph(Gdn_Format::plainText($FirstBody, $FirstFormat), 160));
         // Add images to head for open graph
         $Dom = str_get_html(Gdn_Format::to($FirstBody, $FirstFormat));
     }
     if ($Dom) {
         foreach ($Dom->find('img') as $img) {
             if (isset($img->src)) {
                 $this->image($img->src);
             }
         }
     }
     // Queue notification.
     if ($this->Request->get('new') && c('Vanilla.QueueNotifications')) {
         $this->addDefinition('NotifyNewDiscussion', 1);
     }
     // Make sure to set the user's discussion watch records if this is not an API request.
     if ($this->deliveryType() !== DELIVERY_TYPE_DATA) {
         $this->CommentModel->SetWatch($this->Discussion, $Limit, $this->Offset, $this->Discussion->CountComments);
     }
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->EventArguments['PagerType'] = 'Pager';
     $this->fireEvent('BeforeBuildPager');
     $this->Pager = $PagerFactory->getPager($this->EventArguments['PagerType'], $this);
     $this->Pager->ClientID = 'Pager';
     $this->Pager->configure($this->Offset, $Limit, $ActualResponses, array('DiscussionUrl'));
     $this->Pager->Record = $this->Discussion;
     PagerModule::current($this->Pager);
     $this->fireEvent('AfterBuildPager');
     // Define the form for the comment input
     $this->Form = Gdn::Factory('Form', 'Comment');
     $this->Form->Action = url('/post/comment/');
     $this->DiscussionID = $this->Discussion->DiscussionID;
     $this->Form->addHidden('DiscussionID', $this->DiscussionID);
     $this->Form->addHidden('CommentID', '');
     // Look in the session stash for a comment
     $StashComment = $Session->getPublicStash('CommentForDiscussionID_' . $this->Discussion->DiscussionID);
     if ($StashComment) {
         $this->Form->setValue('Body', $StashComment);
         $this->Form->setFormValue('Body', $StashComment);
     }
     // Retrieve & apply the draft if there is one:
     if (Gdn::session()->UserID) {
         $DraftModel = new DraftModel();
         $Draft = $DraftModel->get($Session->UserID, 0, 1, $this->Discussion->DiscussionID)->firstRow();
         $this->Form->addHidden('DraftID', $Draft ? $Draft->DraftID : '');
         if ($Draft && !$this->Form->isPostBack()) {
             $this->Form->setValue('Body', $Draft->Body);
             $this->Form->setValue('Format', $Draft->Format);
         }
     }
     // Deliver JSON data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->setJson('LessRow', $this->Pager->toString('less'));
         $this->setJson('MoreRow', $this->Pager->toString('more'));
         $this->View = 'comments';
     }
     // Inform moderator of checked comments in this discussion
     $CheckedComments = $Session->getAttribute('CheckedComments', array());
     if (count($CheckedComments) > 0) {
         ModerationController::informCheckedComments($this);
     }
     // Add modules
     $this->addModule('DiscussionFilterModule');
     $this->addModule('NewDiscussionModule');
     $this->addModule('CategoriesModule');
     $this->addModule('BookmarkedModule');
     $this->CanEditComments = Gdn::session()->checkPermission('Vanilla.Comments.Edit', true, 'Category', 'any') && c('Vanilla.AdminCheckboxes.Use');
     // Report the discussion id so js can use it.
     $this->addDefinition('DiscussionID', $DiscussionID);
     $this->addDefinition('Category', $this->data('Category.Name'));
     $this->fireEvent('BeforeDiscussionRender');
     $AttachmentModel = AttachmentModel::instance();
     if (AttachmentModel::enabled()) {
         $AttachmentModel->joinAttachments($this->Data['Discussion'], $this->Data['Comments']);
         $this->fireEvent('FetchAttachmentViews');
         if ($this->deliveryMethod() === DELIVERY_METHOD_XHTML) {
             require_once $this->fetchViewLocation('attachment', 'attachments', 'dashboard');
         }
     }
     $this->render();
 }
Exemplo n.º 20
0
 /**
  * Show all discussions in a particular category.
  * 
  * @since 2.0.0
  * @access public
  * 
  * @param string $CategoryIdentifier Unique category slug or ID.
  * @param int $Offset Number of discussions to skip.
  */
 public function Index($CategoryIdentifier = '', $Page = '0')
 {
     $Category = CategoryModel::Categories($CategoryIdentifier);
     if (empty($Category)) {
         if ($CategoryIdentifier) {
             throw NotFoundException();
         }
     }
     $Category = (object) $Category;
     // Load the breadcrumbs.
     $this->SetData('Breadcrumbs', CategoryModel::GetAncestors(GetValue('CategoryID', $Category)));
     $this->SetData('Category', $Category, TRUE);
     // Setup head
     $this->AddCssFile('vanilla.css');
     $this->Menu->HighlightRoute('/discussions');
     if ($this->Head) {
         $this->Head->Title(GetValue('Name', $Category, ''));
         $this->AddJsFile('discussions.js');
         $this->AddJsFile('bookmark.js');
         $this->AddJsFile('options.js');
         $this->AddJsFile('jquery.gardenmorepager.js');
         $this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
     }
     // Set CategoryID
     $this->SetData('CategoryID', GetValue('CategoryID', $Category), TRUE);
     // Add modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $this->AddModule('BookmarkedModule');
     // Get a DiscussionModel
     $DiscussionModel = new DiscussionModel();
     $Wheres = array('d.CategoryID' => $this->CategoryID);
     // Check permission
     $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', GetValue('PermissionCategoryID', $Category));
     // Set discussion meta data.
     $this->EventArguments['PerPage'] = C('Vanilla.Discussions.PerPage', 30);
     $this->FireEvent('BeforeGetDiscussions');
     list($Offset, $Limit) = OffsetLimit($Page, $this->EventArguments['PerPage']);
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     $CountDiscussions = $DiscussionModel->GetCount($Wheres);
     $this->SetData('CountDiscussions', $CountDiscussions);
     $this->SetData('_Limit', $Limit);
     $AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet();
     $this->SetData('AnnounceData', $AnnounceData, TRUE);
     $this->DiscussionData = $this->SetData('Discussions', $DiscussionModel->Get($Offset, $Limit, $Wheres));
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('Pager', $this);
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'categories/' . $CategoryIdentifier . '/%1$s');
     $this->SetData('_PagerUrl', 'categories/' . rawurlencode($CategoryIdentifier) . '/{Page}');
     $this->SetData('_Page', $Page);
     // Set the canonical Url.
     $this->CanonicalUrl(Url(ConcatSep('/', 'categories/' . GetValue('UrlCode', $Category, $CategoryIdentifier), PageNumber($Offset, $Limit, TRUE, FALSE)), TRUE));
     // Change the controller name so that it knows to grab the discussion views
     $this->ControllerName = 'DiscussionsController';
     // Pick up the discussions class
     $this->CssClass = 'Discussions';
     // Deliver JSON data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'discussions';
     }
     // Render default view
     $this->Render();
 }
Exemplo n.º 21
0
 /**
  * Load discussions for a specific tag.
  * @param DiscussionsController $Sender
  */
 public function DiscussionsController_Tagged_Create($Sender)
 {
     Gdn_Theme::Section('DiscussionList');
     $Args = $Sender->RequestArgs;
     $Get = array_change_key_case($Sender->Request->Get());
     if ($UseCategories = C('Plugins.Tagging.UseCategories')) {
         // The url is in the form /category/tag/p1
         $CategoryCode = GetValue(0, $Args);
         $Tag = GetValue(1, $Args);
         $Page = GetValue(2, $Args);
     } else {
         // The url is in the form /tag/p1
         $CategoryCode = '';
         $Tag = GetValue(0, $Args);
         $Page = GetValue(1, $Args);
     }
     // Look for explcit values.
     $CategoryCode = GetValue('category', $Get, $CategoryCode);
     $Tag = GetValue('tag', $Get, $Tag);
     $Page = GetValue('page', $Get, $Page);
     $Category = CategoryModel::Categories($CategoryCode);
     $Tag = StringEndsWith($Tag, '.rss', TRUE, TRUE);
     list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
     $MultipleTags = strpos($Tag, ',') !== FALSE;
     $Sender->SetData('Tag', $Tag, TRUE);
     $TagModel = TagModel::instance();
     $RecordCount = FALSE;
     if (!$MultipleTags) {
         $Tags = $TagModel->GetWhere(array('Name' => $Tag))->ResultArray();
         if (count($Tags) == 0) {
             throw NotFoundException('Page');
         }
         if (count($Tags) > 1) {
             foreach ($Tags as $TagRow) {
                 if ($TagRow['CategoryID'] == GetValue('CategoryID', $Category)) {
                     break;
                 }
             }
         } else {
             $TagRow = array_pop($Tags);
         }
         $Tags = $TagModel->getRelatedTags($TagRow);
         $RecordCount = $TagRow['CountDiscussions'];
         $Sender->SetData('CountDiscussions', $RecordCount);
         $Sender->SetData('Tags', $Tags);
         $Sender->SetData('Tag', $TagRow);
         $ChildTags = $TagModel->getChildTags($TagRow['TagID']);
         $Sender->SetData('ChildTags', $ChildTags);
     }
     $Sender->Title(htmlspecialchars($TagRow['FullName']));
     $UrlTag = rawurlencode($Tag);
     if (urlencode($Tag) == $Tag) {
         $Sender->CanonicalUrl(Url(ConcatSep('/', "/discussions/tagged/{$UrlTag}", PageNumber($Offset, $Limit, TRUE)), TRUE));
         $FeedUrl = Url(ConcatSep('/', "/discussions/tagged/{$UrlTag}/feed.rss", PageNumber($Offset, $Limit, TRUE, FALSE)), '//');
     } else {
         $Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE)) . '?Tag=' . $UrlTag, TRUE));
         $FeedUrl = Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE, FALSE), 'feed.rss') . '?Tag=' . $UrlTag, '//');
     }
     if ($Sender->Head) {
         $Sender->AddJsFile('discussions.js');
         $Sender->Head->AddRss($FeedUrl, $Sender->Head->Title());
     }
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     // Add Modules
     $Sender->AddModule('NewDiscussionModule');
     $Sender->AddModule('DiscussionFilterModule');
     $Sender->AddModule('BookmarkedModule');
     $Sender->SetData('Category', FALSE, TRUE);
     $Sender->AnnounceData = FALSE;
     $Sender->SetData('Announcements', array(), TRUE);
     $DiscussionModel = new DiscussionModel();
     $TagModel->SetTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Sender->Request->Get('op', 'or'));
     $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit, array('Announce' => 'all'));
     $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, $RecordCount, '');
     $Sender->View = C('Vanilla.Discussions.Layout');
     /*
           // If these don't equal, then there is a category that should be inserted.
           if ($UseCategories && $Category && $TagRow['FullName'] != GetValue('Name', $Category)) {
              $Sender->Data['Breadcrumbs'][] = array('Name' => $Category['Name'], 'Url' => TagUrl($TagRow));
           }
           $Sender->Data['Breadcrumbs'][] = array('Name' => $TagRow['FullName'], 'Url' => '');
     */
     // Render the controller.
     $this->View = C('Vanilla.Discussions.Layout') == 'table' ? 'table' : 'index';
     $Sender->Render($this->View, 'discussions', 'vanilla');
 }
Exemplo n.º 22
0
    /**
     * Alternate version of Index that uses the embed master view.
     */
    public function Embed($DiscussionID = '', $DiscussionStub = '', $Offset = '', $Limit = '')
    {
        $this->CanEditComments = FALSE;
        // Don't show the comment checkboxes on the embed comments page
        $this->Theme = 'default';
        // Force the default theme on embedded comments
        // Add some css to help with the transparent bg on embedded comments
        if ($this->Head) {
            $this->Head->AddString('<style type="text/css">
body { background: transparent !important; }
ul.MessageList li.Item { background: #fff; }
ul.MessageList li.Item.Mine { background: #E3F4FF; }
</style>');
        }
        $Session = Gdn::Session();
        $this->AddJsFile('jquery.ui.packed.js');
        $this->AddJsFile('jquery.gardenmorepager.js');
        $this->AddJsFile('jquery.autogrow.js');
        $this->AddJsFile('options.js');
        $this->AddJsFile('discussion.js');
        $this->MasterView = 'empty';
        // Define incoming variables (prefer querystring parameters over method parameters)
        $DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0;
        $DiscussionID = GetIncomingValue('vanilla_discussion_id', $DiscussionID);
        $Offset = GetIncomingValue('Offset', $Offset);
        $Limit = GetIncomingValue('Limit', $Limit);
        $ForeignID = GetIncomingValue('vanilla_identifier', '');
        $ForeignType = GetIncomingValue('vanilla_type', '');
        $ForeignName = GetIncomingValue('vanilla_name', '');
        $ForeignUrl = GetIncomingValue('vanilla_url', '');
        $this->SetData('ForeignUrl', $ForeignUrl);
        $this->AddDefinition('ForeignUrl', $ForeignUrl);
        $ForeignBody = GetIncomingValue('vanilla_body', '');
        $CategoryID = GetIncomingValue('vanilla_category_id', '');
        // Retrieve the discussion record.
        $Discussion = FALSE;
        if ($DiscussionID > 0) {
            $Discussion = $this->DiscussionModel->GetID($DiscussionID);
        } else {
            if ($ForeignID != '' && $ForeignType != '') {
                $Discussion = $this->DiscussionModel->GetForeignID($ForeignID, $ForeignType);
            }
        }
        // If no discussion record was found, but foreign id was provided, create it now
        if (!$Discussion && $ForeignID != '' && $ForeignType != '') {
            if ($ForeignName == '' || $ForeignBody == '') {
                $PageInfo = FetchPageInfo($ForeignUrl);
                if (!$PageInfo['Exception']) {
                    $ForeignName = $PageInfo['Title'];
                    $ForeignBody = Wrap(Anchor($ForeignName, $ForeignUrl), 'strong') . "\n" . '<br />' . Wrap(Anchor($ForeignUrl, $ForeignUrl), 'small') . "\n" . Wrap($PageInfo['Description'], 'p');
                    if (count($PageInfo['Images']) > 0) {
                        $ForeignBody = Anchor(Img($PageInfo['Images'][0], array('alt' => $ForeignName, 'class' => 'Thumbnail')), $ForeignUrl) . "\n" . $ForeignBody;
                    }
                }
            }
            $Body = $ForeignBody;
            if ($Body == '' && $ForeignUrl != '') {
                $Body = $ForeignUrl;
            }
            if ($Body == '') {
                $Body = T('This discussion is related to an undefined foriegn content source.');
            }
            // Validate the CategoryID for inserting
            if (!is_numeric($CategoryID)) {
                $CategoryID = C('Vanilla.Embed.DefaultCategoryID', 0);
                if ($CategoryID <= 0) {
                    // No default category defined, so grab the first non-root category and use that.
                    try {
                        $CategoryID = $this->DiscussionModel->SQL->Select('CategoryID')->From('Category')->Where('CategoryID >', 0)->Get()->FirstRow()->CategoryID;
                    } catch (Exception $ex) {
                        // No categories in the db? default to 0
                        $CategoryID = 0;
                    }
                }
            }
            $SystemUserID = Gdn::UserModel()->GetSystemUserID();
            $DiscussionID = $this->DiscussionModel->SQL->Insert('Discussion', array('InsertUserID' => $SystemUserID, 'DateInserted' => Gdn_Format::ToDateTime(), 'UpdateUserID' => $SystemUserID, 'DateUpdated' => Gdn_Format::ToDateTime(), 'CategoryID' => $CategoryID == '' ? NULL : $CategoryID, 'ForeignID' => $ForeignID, 'Type' => $ForeignType, 'Name' => $ForeignName == '' ? T('Undefined foreign content') : $ForeignName, 'Body' => $Body, 'Attributes' => serialize(array('ForeignUrl' => $ForeignUrl))));
            $ValidationResults = $this->DiscussionModel->ValidationResults();
            if (count($ValidationResults) == 0 && $DiscussionID > 0) {
                $Discussion = $this->DiscussionModel->GetID($DiscussionID);
                // Update the category discussion count
                if ($CategoryID > 0) {
                    $this->DiscussionModel->UpdateDiscussionCount($CategoryID, $DiscussionID);
                }
            }
        }
        // If no discussion was found, 404
        if (!$Discussion) {
            $this->Render('FileNotFound', 'HomeController', 'Dashboard');
            return;
        }
        $this->SetData('Discussion', $Discussion, TRUE);
        $this->SetData('DiscussionID', $Discussion->DiscussionID, TRUE);
        $this->Title($this->Discussion->Name);
        // Actual number of comments, excluding the discussion itself
        $ActualResponses = $this->Discussion->CountComments - 1;
        // Define the query offset & limit
        if (!is_numeric($Limit) || $Limit < 0) {
            $Limit = C('Vanilla.Comments.PerPage', 30);
        }
        $OffsetProvided = $Offset != '';
        list($Offset, $Limit) = OffsetLimit($Offset, $Limit);
        $this->Offset = $Offset;
        if (C('Vanilla.Comments.AutoOffset')) {
            if ($ActualResponses <= $Limit) {
                $this->Offset = 0;
            }
            if ($this->Offset == $ActualResponses) {
                $this->Offset -= $Limit;
            }
        } else {
            if ($this->Offset == '') {
                $this->Offset = 0;
            }
        }
        if ($this->Offset < 0) {
            $this->Offset = 0;
        }
        // Set the canonical url to have the proper page title.
        $this->CanonicalUrl(Url(ConcatSep('/', 'discussion/' . $this->Discussion->DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name), PageNumber($this->Offset, $Limit, TRUE)), TRUE));
        // Load the comments
        $this->CommentModel->OrderBy('c.DateInserted desc');
        // allow custom sort
        $this->SetData('CommentData', $this->CommentModel->Get($this->Discussion->DiscussionID, $Limit, $this->Offset), TRUE);
        // Build a pager
        $PagerFactory = new Gdn_PagerFactory();
        $this->EventArguments['PagerType'] = 'MorePager';
        $this->FireEvent('BeforeBuildPager');
        $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
        $this->Pager->ClientID = 'Pager';
        $this->Pager->MoreCode = 'More Comments';
        $this->Pager->Configure($this->Offset, $Limit, $ActualResponses, 'discussion/embed/' . $this->Discussion->DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name) . '/%1$s');
        $this->FireEvent('AfterBuildPager');
        // Define the form for the comment input
        $this->Form = Gdn::Factory('Form', 'Comment');
        $this->Form->Action = Url('/vanilla/post/comment/');
        $this->Form->AddHidden('DiscussionID', $this->Discussion->DiscussionID);
        $this->Form->AddHidden('CommentID', '');
        $this->Form->AddHidden('DisplayNewCommentOnly', 'true');
        // Only load/display the new comment after posting (don't load all new comments since the page last loaded).
        // Retrieve & apply the draft if there is one:
        $Draft = FALSE;
        if (Gdn::Session()->UserID) {
            $DraftModel = new DraftModel();
            $Draft = $DraftModel->Get($Session->UserID, 0, 1, $this->Discussion->DiscussionID)->FirstRow();
            $this->Form->AddHidden('DraftID', $Draft ? $Draft->DraftID : '');
        }
        if ($Draft) {
            $this->Form->SetFormValue('Body', $Draft->Body);
        } else {
            // Look in the session stash for a comment
            $StashComment = $Session->Stash('CommentForDiscussionID_' . $this->Discussion->DiscussionID, '', FALSE);
            if ($StashComment) {
                $this->Form->SetFormValue('Body', $StashComment);
            }
        }
        // Deliver JSON data if necessary
        if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
            $this->SetJson('LessRow', $this->Pager->ToString('less'));
            $this->SetJson('MoreRow', $this->Pager->ToString('more'));
            $this->View = 'comments';
        }
        $this->AddDefinition('PrependNewComments', '1');
        $this->AddDefinition('DiscussionID', $Discussion->DiscussionID);
        // Report the discussion id so js can use it.
        $this->FireEvent('BeforeDiscussionRender');
        $this->Render();
    }
 /**
  * Display discussions the user has bookmarked.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $Offset Number of discussions to skip.
  */
 public function Bookmarked($Page = '0')
 {
     $this->Permission('Garden.SignIn.Allow');
     Gdn_Theme::Section('DiscussionList');
     // Figure out which discussions layout to choose (Defined on "Homepage" settings page).
     $Layout = C('Vanilla.Discussions.Layout');
     switch ($Layout) {
         case 'table':
             if ($this->SyndicationMethod == SYNDICATION_NONE) {
                 $this->View = 'table';
             }
             break;
         default:
             $this->View = 'index';
             break;
     }
     // Determine offset from $Page
     list($Page, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
     $this->CanonicalUrl(Url(ConcatSep('/', 'discussions', 'bookmarked', PageNumber($Page, $Limit, TRUE, FALSE)), TRUE));
     // Validate $Page
     if (!is_numeric($Page) || $Page < 0) {
         $Page = 0;
     }
     $DiscussionModel = new DiscussionModel();
     $Wheres = array('w.Bookmarked' => '1', 'w.UserID' => Gdn::Session()->UserID);
     $this->DiscussionData = $DiscussionModel->Get($Page, $Limit, $Wheres);
     $this->SetData('Discussions', $this->DiscussionData);
     $CountDiscussions = $DiscussionModel->GetCount($Wheres);
     $this->SetData('CountDiscussions', $CountDiscussions);
     $this->Category = FALSE;
     $this->SetJson('Loading', $Page . ' to ' . $Limit);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->EventArguments['PagerType'] = 'Pager';
     $this->FireEvent('BeforeBuildBookmarkedPager');
     $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($Page, $Limit, $CountDiscussions, 'discussions/bookmarked/%1$s');
     if (!$this->Data('_PagerUrl')) {
         $this->SetData('_PagerUrl', 'discussions/bookmarked/{Page}');
     }
     $this->SetData('_Page', $Page);
     $this->SetData('_Limit', $Limit);
     $this->FireEvent('AfterBuildBookmarkedPager');
     // Deliver JSON data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'discussions';
     }
     // Add modules
     $this->AddModule('DiscussionFilterModule');
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     // Render default view (discussions/bookmarked.php)
     $this->SetData('Title', T('My Bookmarks'));
     $this->SetData('Breadcrumbs', array(array('Name' => T('My Bookmarks'), 'Url' => '/discussions/bookmarked')));
     $this->Render();
 }
 /**
  * Show all discussions in a particular category.
  * 
  * @since 2.0.0
  * @access public
  * 
  * @param string $CategoryIdentifier Unique category slug or ID.
  * @param int $Offset Number of discussions to skip.
  */
 public function Index($CategoryIdentifier = '', $Offset = '0')
 {
     list($Offset, $Limit) = OffsetLimit($Offset, C('Vanilla.Discussions.PerPage', 30));
     if (!is_numeric($CategoryIdentifier)) {
         $Category = $this->CategoryModel->GetFullByUrlCode(urlencode($CategoryIdentifier));
     } else {
         $Category = $this->CategoryModel->GetFull($CategoryIdentifier);
     }
     if ($Category === FALSE) {
         return $this->All();
     }
     $this->SetData('Category', $Category, TRUE);
     // Setup head
     $this->AddCssFile('vanilla.css');
     $this->Menu->HighlightRoute('/discussions');
     if ($this->Head) {
         $this->Head->Title($Category->Name);
         $this->AddJsFile('discussions.js');
         $this->AddJsFile('bookmark.js');
         $this->AddJsFile('jquery.menu.js');
         $this->AddJsFile('options.js');
         $this->AddJsFile('jquery.gardenmorepager.js');
         $this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
     }
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     // Set CategoryID
     $this->SetData('CategoryID', $this->Category->CategoryID, TRUE);
     // Add modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     // Get a DiscussionModel
     $DiscussionModel = new DiscussionModel();
     $Wheres = array('d.CategoryID' => $this->CategoryID);
     // Check permission
     $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $this->CategoryID);
     // Set discussion meta data
     $CountDiscussions = $DiscussionModel->GetCount($Wheres);
     $this->SetData('CountDiscussions', $CountDiscussions);
     $AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet();
     $this->SetData('AnnounceData', $AnnounceData, TRUE);
     $this->SetData('DiscussionData', $DiscussionModel->Get($Offset, $Limit, $Wheres), TRUE);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('Pager', $this);
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'categories/' . $CategoryIdentifier . '/%1$s');
     // Set the canonical Url.
     $this->CanonicalUrl(Url(ConcatSep('/', 'categories/' . GetValue('UrlCode', $Category, $CategoryIdentifier), PageNumber($Offset, $Limit, TRUE)), TRUE));
     // Change the controller name so that it knows to grab the discussion views
     $this->ControllerName = 'DiscussionsController';
     // Pick up the discussions class
     $this->CssClass = 'Discussions';
     // Deliver JSON data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'discussions';
     }
     // Render default view
     $this->Render();
 }
Exemplo n.º 25
0
 /**
  *
  *
  * @param $Url
  * @param $Offset
  * @param string $Limit
  * @return mixed|string
  */
 public static function formatUrl($Url, $Offset, $Limit = '')
 {
     // Check for new style page.
     if (strpos($Url, '{Page}') !== false || strpos($Url, '{Offset}') !== false) {
         $Page = PageNumber($Offset, $Limit, true);
         return str_replace(array('{Offset}', '{Page}', '{Size}'), array($Offset, $Page, $Limit), $Url);
     } else {
         return self::FormatUrl($Url, $Page, $Limit);
     }
 }
Exemplo n.º 26
0
 /**
  * Load discussions for a specific tag.
  */
 public function DiscussionsController_Tagged_Create($Sender)
 {
     if ($Sender->Request->Get('Tag')) {
         $Tag = $Sender->Request->Get('Tag');
         $Page = GetValue('0', $Sender->RequestArgs, 'p1');
     } else {
         $Tag = urldecode(GetValue('0', $Sender->RequestArgs, ''));
         $Page = GetValue('1', $Sender->RequestArgs, 'p1');
     }
     if ($Sender->Request->Get('Page')) {
         $Page = $Sender->Request->Get('Page');
     }
     $Tag = StringEndsWith($Tag, '.rss', TRUE, TRUE);
     list($Offset, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30));
     $Sender->SetData('Tag', $Tag, TRUE);
     $Sender->Title(T('Tagged with ') . htmlspecialchars($Tag));
     $Sender->Head->Title($Sender->Head->Title());
     if (urlencode($Tag) == $Tag) {
         $Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged/' . urlencode($Tag), PageNumber($Offset, $Limit, TRUE)), TRUE));
     } else {
         $Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE)) . '?Tag=' . urlencode($Tag), 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);
     $Sender->SetData('CountDiscussions', FALSE);
     $Sender->AnnounceData = FALSE;
     $Sender->SetData('Announcements', array(), TRUE);
     $DiscussionModel = new DiscussionModel();
     $this->_SetTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Sender->Request->Get('op', 'or'));
     $Sender->DiscussionData = $DiscussionModel->Get(FALSE);
     $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';
     if (urlencode($Sender->Tag) == $Sender->Tag) {
         $PageUrlFormat = "discussions/tagged/{$Sender->Tag}/{Page}";
     } else {
         $PageUrlFormat = 'discussions/tagged/{Page}?Tag=' . urlencode($Sender->Tag);
     }
     $Sender->Pager->Configure($Offset, $Limit, FALSE, $PageUrlFormat);
     // 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('TaggedDiscussions', '', 'plugins/Tagging');
 }
Exemplo n.º 27
0
 public function removePageCache($DiscussionID, $From = 1)
 {
     if (!$this->pageCache) {
         return;
     }
     $CountComments = $this->SQL->getWhere('Discussion', array('DiscussionID' => $DiscussionID))->value('CountComments');
     $Limit = c('Vanilla.Comments.PerPage', 30);
     $PageCount = PageNumber($CountComments, $Limit) + 1;
     for ($Page = $From; $Page <= $PageCount; $Page++) {
         $CacheKey = "Comment.Page.{$Limit}.{$DiscussionID}.{$Page}";
         Gdn::cache()->Remove($CacheKey);
     }
 }
   /**
    * Alternate version of Index that uses the embed master view.
    */
   public function Embed($DiscussionID = '', $DiscussionStub = '', $Offset = '', $Limit = '') {
      $Session = Gdn::Session();
      $this->AddJsFile('jquery.ui.packed.js');
      $this->AddJsFile('jquery.gardenmorepager.js');
      $this->AddJsFile('jquery.autogrow.js');
      $this->AddJsFile('options.js');
      $this->AddJsFile('discussion.js');
      $this->MasterView = 'empty';
      
      // Define incoming variables (prefer querystring parameters over method parameters)
      $DiscussionID = (is_numeric($DiscussionID) && $DiscussionID > 0) ? $DiscussionID : 0;
      $DiscussionID = GetIncomingValue('vanilla_discussion_id', $DiscussionID);
      $Offset = GetIncomingValue('Offset', $Offset);
      $Limit = GetIncomingValue('Limit', $Limit);
      $ForeignID = GetIncomingValue('vanilla_identifier', '');
      $ForeignType = GetIncomingValue('vanilla_type', '');
      $ForeignName = GetIncomingValue('vanilla_name', '');
      $ForeignUrl = GetIncomingValue('vanilla_url', '');
      $ForeignBody = GetIncomingValue('vanilla_body', '');
      $CategoryID = GetIncomingValue('vanilla_category_id', '');
      
      // Retrieve the discussion record.
      $Discussion = FALSE;
      if ($DiscussionID > 0)
         $Discussion = $this->DiscussionModel->GetID($DiscussionID);
      else if ($ForeignID != '' && $ForeignType != '')
         $Discussion = $this->DiscussionModel->GetForeignID($ForeignID, $ForeignType);
      
      // If no discussion record was found, but foreign id was provided, create it now
      if (!$Discussion && $ForeignID != '' && $ForeignType != '') {
         $Body = $ForeignBody;
         if ($Body == '' && $ForeignUrl != '')
            $Body = $ForeignUrl;
         if ($Body == '')
            $Body = T('This discussion is related to an undefined foriegn content source.');
            
         // Validate the CategoryID for inserting
         if (!is_numeric($CategoryID)) {
            $CategoryID = C('Vanilla.Embed.DefaultCategoryID', 0);
            if ($CategoryID <= 0) {
               // No default category defined, so grab the first non-root category and use that.
               try {
                  $CategoryID = $this->DiscussionModel
                     ->SQL
                     ->Select('CategoryID')
                     ->From('Category')
                     ->Where('CategoryID >', 0)
                     ->Get()
                     ->FirstRow()
                     ->CategoryID;
               } catch (Exception $ex) {
                  // No categories in the db? default to 0
                  $CategoryID = 0;
               }
            }
         }

         $DiscussionID = $this->DiscussionModel->Save(
            array(
               'CategoryID' => $CategoryID == '' ? NULL : $CategoryID,
               'ForeignID' => $ForeignID,
               'Type' => $ForeignType,
               'Name' => $ForeignName == '' ? T('Undefined foreign content') : $ForeignName,
               'Body' => $Body,
               'Attributes' => serialize(array('ForeignUrl' => $ForeignUrl))
            )
         );
         $ValidationResults = $this->DiscussionModel->ValidationResults();
         if (count($ValidationResults) == 0 && $DiscussionID > 0)
            $Discussion = $this->DiscussionModel->GetID($DiscussionID);
      }
      
      // If no discussion was found, 404
      if (!$Discussion) {
         $this->Render('FileNotFound', 'HomeController', 'Dashboard');
         return;
      } 
      $this->SetData('Discussion', $Discussion, TRUE);
      $this->SetData('DiscussionID', $Discussion->DiscussionID, TRUE);
      $this->Title($this->Discussion->Name);

      // Actual number of comments, excluding the discussion itself
      $ActualResponses = $this->Discussion->CountComments - 1;
      // Define the query offset & limit
      if (!is_numeric($Limit) || $Limit < 0)
         $Limit = C('Vanilla.Comments.PerPage', 50);

      $OffsetProvided = $Offset != '';
      list($Offset, $Limit) = OffsetLimit($Offset, $Limit);
      $this->Offset = $Offset;
      if (C('Vanilla.Comments.AutoOffset')) {
         if ($ActualResponses <= $Limit)
            $this->Offset = 0;

         if ($this->Offset == $ActualResponses)
            $this->Offset -= $Limit;
      } else if ($this->Offset == '')
         $this->Offset = 0;

      if ($this->Offset < 0)
         $this->Offset = 0;

      // Set the canonical url to have the proper page title.
      $this->CanonicalUrl(Url(ConcatSep('/', 'discussion/'.$this->Discussion->DiscussionID.'/'. Gdn_Format::Url($this->Discussion->Name), PageNumber($this->Offset, $Limit, TRUE)), TRUE));

      // Load the comments
      $this->CommentModel->OrderBy('c.DateInserted desc'); // allow custom sort
      $this->SetData('CommentData', $this->CommentModel->Get($this->Discussion->DiscussionID, $Limit, $this->Offset), TRUE);
      
      // Build a pager
      $PagerFactory = new Gdn_PagerFactory();
		$this->EventArguments['PagerType'] = 'MorePager';
		$this->FireEvent('BeforeBuildPager');
      $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
      $this->Pager->ClientID = 'Pager';
      $this->Pager->MoreCode = 'More Comments';
      $this->Pager->Configure(
         $this->Offset,
         $Limit,
         $ActualResponses,
         'discussion/embed/'.$this->Discussion->DiscussionID.'/'.Gdn_Format::Url($this->Discussion->Name).'/%1$s'
      );
      $this->FireEvent('AfterBuildPager');
      
      // Define the form for the comment input
      $this->Form = Gdn::Factory('Form', 'Comment');
      $this->Form->Action = Url('/vanilla/post/comment/');
      $this->Form->AddHidden('DiscussionID', $this->Discussion->DiscussionID);
      $this->Form->AddHidden('CommentID', '');
      $this->Form->AddHidden('DisplayNewCommentOnly', 'true'); // Only load/display the new comment after posting (don't load all new comments since the page last loaded).

      // Retrieve & apply the draft if there is one:
      $DraftModel = new DraftModel();
      $Draft = $DraftModel->Get($Session->UserID, 0, 1, $this->Discussion->DiscussionID)->FirstRow();
      $this->Form->AddHidden('DraftID', $Draft ? $Draft->DraftID : '');
      if ($Draft)
         $this->Form->SetFormValue('Body', $Draft->Body);
      else {
         // Look in the session stash for a comment
         $StashComment = $Session->Stash('CommentForDiscussionID_'.$this->Discussion->DiscussionID, '', FALSE);
         if ($StashComment)
            $this->Form->SetFormValue('Body', $StashComment);
      }
      
      // Deliver JSON data if necessary
      if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'comments';
      }
      
      $this->AddDefinition('PrependNewComments', '1');
      $this->AddDefinition('DiscussionID', $Discussion->DiscussionID);
      
      // Report the discussion id so js can use it.      
      $this->FireEvent('BeforeDiscussionRender');
      $this->Render();
   }