Beispiel #1
0
 function DiscussionGrid_DiscussionPages($DiscussionGrid)
 {
     $Discussion =& $DiscussionGrid->DelegateParameters['Discussion'];
     $DiscussionList =& $DiscussionGrid->DelegateParameters['DiscussionList'];
     $CommentsPerPage = $DiscussionGrid->Context->Configuration['COMMENTS_PER_PAGE'];
     if ($Discussion->CountComments > $CommentsPerPage) {
         $PageList = '<font class="DiscussionPageNumbersContainer">';
         $PageList .= $Discussion->Context->GetDefinition('TextPrefix');
         $PageCount = CalculateNumberOfPages($Discussion->CountComments, $CommentsPerPage);
         if ($PageCount > 6) {
             $PageCountMinus2 = $PageCount - 2;
             $PageCountMinus1 = $PageCount - 1;
             $PageList .= ' <a href="' . GetUrl($Discussion->Context->Configuration, 'comments.php', '', 'DiscussionID', $Discussion->DiscussionID, 1) . '">1</a> ';
             $PageList .= ' <a href="' . GetUrl($Discussion->Context->Configuration, 'comments.php', '', 'DiscussionID', $Discussion->DiscussionID, 2) . '">2</a> ';
             $PageList .= ' <a href="' . GetUrl($Discussion->Context->Configuration, 'comments.php', '', 'DiscussionID', $Discussion->DiscussionID, 3) . '">3</a> ... ';
             $PageList .= ' <a href="' . GetUrl($Discussion->Context->Configuration, 'comments.php', '', 'DiscussionID', $Discussion->DiscussionID, $PageCountMinus2) . '">' . $PageCountMinus2 . '</a> ';
             $PageList .= ' <a href="' . GetUrl($Discussion->Context->Configuration, 'comments.php', '', 'DiscussionID', $Discussion->DiscussionID, $PageCountMinus1) . '">' . $PageCountMinus1 . '</a> ';
             $PageList .= ' <a href="' . GetUrl($Discussion->Context->Configuration, 'comments.php', '', 'DiscussionID', $Discussion->DiscussionID, $PageCount) . '">' . $PageCount . '</a> ';
         } else {
             for ($i = 1; $i <= $PageCount; $i++) {
                 $PageList .= ' <a href="' . GetUrl($Discussion->Context->Configuration, 'comments.php', '', 'DiscussionID', $Discussion->DiscussionID, $i) . '">' . $i . '</a> ';
             }
         }
         $PageList .= $Discussion->Context->GetDefinition('TextSuffix');
         $PageList .= "</font>";
         $DiscussionList = str_replace('class="DiscussionTopicName">' . $Discussion->Name . '</a>', 'class="DiscussionTopicName">' . $Discussion->Name . '</a> ' . $PageList, $DiscussionList);
     }
 }
 private function PrepareDiscussionList($Sender)
 {
     // Make the table view render just the inner content, similar to the modern view.
     if (C('Vanilla.Discussions.Layout') == 'table' && Gdn::Request()->Get('InnerList')) {
         $Sender->View = $this->GetView('inner_table.php');
     }
     $Page = (int) filter_var($Sender->Data('_Page'), FILTER_SANITIZE_NUMBER_INT);
     $Page = $Page > 1 ? $Page : 1;
     $CountDiscussions = $Sender->Data('CountDiscussions');
     $TotalPages = CalculateNumberOfPages($CountDiscussions, C('Vanilla.Discussions.PerPage', 30));
     $Sender->AddDefinition('InfiniteScroll.CountItems', $CountDiscussions);
     $Sender->AddDefinition('InfiniteScroll.Page', $Page);
     $Sender->AddDefinition('InfiniteScroll.TotalPages', $TotalPages);
     $Sender->AddDefinition('InfiniteScroll.PerPage', (int) C('Vanilla.Discussions.PerPage', 30));
     $this->BuildNavigation($Sender, $CountDiscussions, $TotalPages);
 }
function GetUnreadQuerystring($Discussion)
{
    $sReturn = "";
    $UnreadCommentCount = $Discussion->CountComments - $Discussion->NewComments + 1;
    $ReadCommentCount = $Discussion->CountComments - $Discussion->NewComments;
    $PageNumber = CalculateNumberOfPages($ReadCommentCount, agCOMMENTS_PER_PAGE);
    $JumpToItem = $ReadCommentCount - ($PageNumber - 1) * agCOMMENTS_PER_PAGE;
    if ($JumpToItem < 0) {
        $JumpToItem = 0;
    }
    if ($PageNumber > 0) {
        $sReturn = "&amp;page=" . $PageNumber;
    }
    $sReturn .= "#Item_" . $JumpToItem;
    return $sReturn;
}
function GetUnreadQuerystring(&$Discussion, &$Configuration, $CurrentUserJumpToLastCommentPref = '0')
{
    $Suffix = '';
    if ($Configuration['URL_BUILDING_METHOD'] == 'mod_rewrite') {
        $Suffix = CleanupString($Discussion->Name) . '/';
    }
    if ($CurrentUserJumpToLastCommentPref) {
        $UnreadCommentCount = $Discussion->CountComments - $Discussion->NewComments + 1;
        $ReadCommentCount = $Discussion->CountComments - $Discussion->NewComments;
        $PageNumber = CalculateNumberOfPages($ReadCommentCount, $Configuration['COMMENTS_PER_PAGE']);
        $JumpToItem = $ReadCommentCount - ($PageNumber - 1) * $Configuration['COMMENTS_PER_PAGE'];
        if ($JumpToItem < 0) {
            $JumpToItem = 0;
        }
        if ($PageNumber == 0) {
            $PageNumber = '';
        }
        return GetUrl($Configuration, 'comments.php', '', 'DiscussionID', $Discussion->DiscussionID, $PageNumber, '#Item_' . $JumpToItem, $Suffix);
    } else {
        return GetUrl($Configuration, 'comments.php', '', 'DiscussionID', $Discussion->DiscussionID, '', '', $Suffix);
    }
}
 function DefineProperties()
 {
     if (!$this->isPropertiesDefined) {
         if ($this->CurrentPage == 0) {
             $this->CurrentPage = ForceIncomingInt($this->PageParameterName, 1);
         }
         if ($this->Totalled) {
             $this->PageCount = CalculateNumberOfPages($this->TotalRecords, $this->RecordsPerPage);
             if ($this->CurrentPage > $this->PageCount) {
                 $this->CurrentPage = $this->PageCount;
             }
             if ($this->CurrentPage < 1) {
                 $this->CurrentPage = 1;
             }
             $this->FirstRecord = ($this->CurrentPage - 1) * $this->RecordsPerPage + 1;
             $this->LastRecord = $this->FirstRecord + $this->RecordsPerPage - 1;
             if ($this->LastRecord > $this->TotalRecords) {
                 $this->LastRecord = $this->TotalRecords;
             }
         } else {
             if ($this->CurrentPage < 1) {
                 $this->CurrentPage = 1;
             }
             $this->PageCount = $this->CurrentPage;
             if ($this->TotalRecords > $this->RecordsPerPage) {
                 $this->PageCount++;
             }
             $this->FirstRecord = ($this->CurrentPage - 1) * $this->RecordsPerPage + 1;
             $this->LastRecord = $this->FirstRecord + $this->TotalRecords - 1;
             if ($this->LastRecord < $this->FirstRecord) {
                 $this->LastRecord = $this->FirstRecord;
             }
             if ($this->PageCount > $this->CurrentPage) {
                 $this->LastRecord = $this->LastRecord - 1;
             }
         }
         $this->isPropertiesDefined = 1;
     }
 }
Beispiel #6
0
 function CommentLinks_LocateComment(&$Head)
 {
     $Context =& $Head->Context;
     $cm = $Context->ObjectFactory->NewContextObject($Context, 'CommentManager');
     $c = $Context->ObjectFactory->NewContextObject($Context, 'Comment');
     $c = $cm->GetCommentByID(ForceIncomingInt('CommentID', 0), $Context->Session->UserID);
     // Insufficient permissions & not logged in, go to the sign-in form
     if (!$Context->Session->UserID && $c) {
         if ($c->WhisperUserID || $c->DiscussionWhisperUserID) {
             CommentLinks_GoSignIn($Context);
         }
     }
     if ($c && $Context->WarningCollector->Iif()) {
         // A lot of overhead--might be better to just build my own query, but this is easier
         $dm = $Context->ObjectFactory->NewContextObject($Context, 'DiscussionManager');
         $d = $Context->ObjectFactory->NewContextObject($Context, 'Discussion');
         $d = $dm->GetDiscussionByID($c->DiscussionID);
         if ($d && $d->Active || $Context->Session->User->Permission('PERMISSION_VIEW_HIDDEN_DISCUSSIONS') && $Context->Session->User->Preference('ShowDeletedDiscussions')) {
             // Figure out which page the comment is on. A binary search would be more efficient for huge threads
             $PageCount = CalculateNumberOfPages($cm->GetCommentCount($c->DiscussionID), $Context->Configuration['COMMENTS_PER_PAGE']);
             $CurrentPage = 0;
             $FoundComment = 0;
             while ($CurrentPage <= $PageCount && !$FoundComment) {
                 $CommentData = $cm->GetCommentList($Context->Configuration['COMMENTS_PER_PAGE'], ++$CurrentPage, $c->DiscussionID);
                 $RowPosition = 0;
                 while ($Row = $Context->Database->GetRow($CommentData)) {
                     $RowPosition++;
                     if (ForceInt($Row['CommentID'], 0) == $c->CommentID) {
                         $FoundComment = 1;
                         break;
                     }
                 }
             }
             if (!$FoundComment) {
                 $Context->WarningCollector->Add($Context->GetDefinition('ErrCommentNotFound'));
             }
         } else {
             // Discussion is either missing or deleted. If deleted, say it can't be found.
             if (!$d->Active) {
                 $Context->WarningCollector->Add($Context->GetDefinition('ErrCommentNotFound'));
             }
         }
         // If all is well, 302 to the comment's location
         if ($Context->WarningCollector->Iif()) {
             $Suffix = $Context->Configuration['URL_BUILDING_METHOD'] == 'mod_rewrite' ? cleanupstring($d->Name) . '/' : '';
             $Anchor = CommentLinks_YELLOWFADE ? '#Comment_' . $c->CommentID : '#Item_' . $RowPosition;
             $Url = GetUrl($Context->Configuration, 'comments.php', '', 'DiscussionID', $d->DiscussionID, $CurrentPage, $Anchor, $Suffix);
             header('Location: ' . str_replace('&amp;', '&', $Url));
             $Context->unload();
             exit(0);
         }
     } else {
         //Comment probably belongs to a private category
         if (!$Context->Session->UserID && $c) {
             CommentLinks_GoSignIn($Context);
         }
     }
 }
 function GetPropertiesFromDataSet($DataSet)
 {
     $this->DiscussionID = ForceInt(@$DataSet["DiscussionID"], 0);
     $this->FirstCommentID = ForceInt(@$DataSet["FirstCommentID"], 0);
     $this->CategoryID = ForceInt(@$DataSet["CategoryID"], 0);
     $this->Category = ForceString(@$DataSet["Category"], "");
     $this->AuthUserID = ForceInt(@$DataSet["AuthUserID"], 0);
     $this->AuthFullName = ForceString(@$DataSet["AuthFullName"], "");
     $this->AuthUsername = ForceString(@$DataSet["AuthUsername"], "");
     $this->WhisperUserID = ForceInt(@$DataSet["WhisperUserID"], 0);
     $this->WhisperFullName = ForceString(@$DataSet["WhisperFullName"], "");
     $this->WhisperUsername = ForceString(@$DataSet["WhisperUsername"], "");
     $this->LastUserID = ForceInt(@$DataSet["LastUserID"], 0);
     $this->LastFullName = ForceString(@$DataSet["LastFullName"], "");
     $this->LastUsername = ForceString(@$DataSet["LastUsername"], "");
     $this->Active = ForceBool(@$DataSet["Active"], 0);
     $this->Closed = ForceBool(@$DataSet["Closed"], 0);
     $this->Sticky = ForceBool(@$DataSet["Sticky"], 0);
     $this->Bookmarked = ForceBool(@$DataSet["Bookmarked"], 0);
     $this->Name = ForceString(@$DataSet["Name"], "");
     $this->DateCreated = UnixTimestamp(@$DataSet["DateCreated"]);
     $this->DateLastActive = UnixTimestamp(@$DataSet["DateLastActive"]);
     $this->CountComments = ForceInt(@$DataSet["CountComments"], 0);
     $WhisperFromDateLastActive = UnixTimestamp(@$DataSet["WhisperFromDateLastActive"]);
     $WhisperFromLastUserID = ForceInt(@$DataSet["WhisperFromLastUserID"], 0);
     $WhisperFromLastFullName = ForceString(@$DataSet["WhisperFromLastFullName"], "");
     $WhisperFromLastUsername = ForceString(@$DataSet["WhisperFromLastUsername"], "");
     $this->CountWhispersFrom = ForceInt(@$DataSet["CountWhispersFrom"], 0);
     $WhisperToDateLastActive = UnixTimestamp(@$DataSet["WhisperToDateLastActive"]);
     $WhisperToLastUserID = ForceInt(@$DataSet["WhisperToLastUserID"], 0);
     $WhisperToLastFullName = ForceString(@$DataSet["WhisperToLastFullName"], "");
     $WhisperToLastUsername = ForceString(@$DataSet["WhisperToLastUsername"], "");
     $this->CountWhispersTo = ForceInt(@$DataSet["CountWhispersTo"], 0);
     $this->CountComments += $this->CountWhispersFrom;
     $this->CountComments += $this->CountWhispersTo;
     $this->CountReplies = $this->CountComments - 1;
     if ($this->CountReplies < 0) {
         $this->CountReplies = 0;
     }
     if ($WhisperFromDateLastActive != "") {
         if ($this->DateLastActive < $WhisperFromDateLastActive) {
             $this->DateLastActive = $WhisperFromDateLastActive;
             $this->LastUserID = $WhisperFromLastUserID;
             $this->LastFullName = $WhisperFromLastFullName;
             $this->LastUsername = $WhisperFromLastUsername;
         }
     }
     if ($WhisperToDateLastActive != "") {
         if ($this->DateLastActive < $WhisperToDateLastActive) {
             $this->DateLastActive = $WhisperToDateLastActive;
             $this->LastUserID = $WhisperToLastUserID;
             $this->LastFullName = $WhisperToLastFullName;
             $this->LastUsername = $WhisperToLastUsername;
         }
     }
     $this->LastViewed = UnixTimestamp(@$DataSet["LastViewed"]);
     $this->LastViewCountComments = ForceInt(@$DataSet["LastViewCountComments"], 0);
     if ($this->LastViewed != "") {
         $this->NewComments = $this->CountComments - $this->LastViewCountComments;
         if ($this->NewComments < 0) {
             $this->NewComments = 0;
         }
     } else {
         $this->NewComments = $this->CountComments;
     }
     $this->Status = $this->GetStatus();
     // Define the last page
     $this->LastPage = CalculateNumberOfPages($this->CountComments, agCOMMENTS_PER_PAGE);
 }
 function CommentGrid(&$Context, $DiscussionManager, $DiscussionID)
 {
     $this->Name = 'CommentGrid';
     $this->Control($Context);
     $this->CurrentPage = ForceIncomingInt('page', 1);
     // Load information about this discussion
     $RecordDiscussionView = 1;
     if ($this->Context->Session->UserID == 0) {
         $RecordDiscussionView = 0;
     }
     $this->Discussion = $DiscussionManager->GetDiscussionById($DiscussionID, $RecordDiscussionView);
     if ($this->Discussion) {
         $this->Discussion->FormatPropertiesForDisplay();
         if (!$this->Discussion->Active && !$this->Context->Session->User->Permission('PERMISSION_VIEW_HIDDEN_DISCUSSIONS')) {
             $this->Discussion = false;
             $this->Context->WarningCollector->Add($this->Context->GetDefinition('ErrDiscussionNotFound'));
         }
         if ($this->Context->WarningCollector->Count() > 0) {
             $this->CommentData = false;
             $this->CommentDataCount = 0;
         } else {
             // Load the data
             $CommentManager = $Context->ObjectFactory->NewContextObject($Context, 'CommentManager');
             $this->CommentDataCount = $CommentManager->GetCommentCount($DiscussionID);
             // If trying to focus on a particular comment, make sure to look at the correct page
             $Focus = ForceIncomingInt('Focus', 0);
             $PageCount = CalculateNumberOfPages($this->CommentDataCount, $this->Context->Configuration['COMMENTS_PER_PAGE']);
             if ($Focus > 0 && $PageCount > 1) {
                 $this->CurrentPage = 0;
                 $FoundComment = 0;
                 while ($this->CurrentPage <= $PageCount && !$FoundComment) {
                     $this->CurrentPage++;
                     $this->CommentData = $CommentManager->GetCommentList($this->Context->Configuration['COMMENTS_PER_PAGE'], $this->CurrentPage, $DiscussionID);
                     while ($Row = $this->Context->Database->GetRow($this->CommentData)) {
                         if (ForceInt($Row['CommentID'], 0) == $Focus) {
                             $FoundComment = 1;
                             break;
                         }
                     }
                 }
                 $this->Context->Database->RewindDataSet($this->CommentData);
             } else {
                 $this->CommentData = $CommentManager->GetCommentList($this->Context->Configuration['COMMENTS_PER_PAGE'], $this->CurrentPage, $DiscussionID);
             }
         }
         // Set up the pagelist
         $this->pl = $this->Context->ObjectFactory->NewContextObject($this->Context, 'PageList', 'DiscussionID', $this->Discussion->DiscussionID, CleanupString($this->Discussion->Name) . '/');
         $this->pl->NextText = $this->Context->GetDefinition('Next');
         $this->pl->PreviousText = $this->Context->GetDefinition('Previous');
         $this->pl->CssClass = 'PageList';
         $this->pl->TotalRecords = $this->CommentDataCount;
         $this->pl->CurrentPage = $this->CurrentPage;
         $this->pl->RecordsPerPage = $this->Context->Configuration['COMMENTS_PER_PAGE'];
         $this->pl->PagesToDisplay = 10;
         $this->pl->PageParameterName = 'page';
         $this->pl->DefineProperties();
         $this->pl->QueryStringParams->Remove('Focus');
         $CategoryManager = $Context->ObjectFactory->NewContextObject($this->Context, 'CategoryManager');
         $this->ShowForm = 0;
         if ($this->Context->Session->UserID > 0 && ($this->pl->PageCount == 1 || $this->pl->PageCount == $this->CurrentPage) && (!$this->Discussion->Closed && $this->Discussion->Active || $this->Context->Session->User->Permission('PERMISSION_ADD_COMMENTS_TO_CLOSED_DISCUSSION')) && $this->CommentData && $this->Context->Session->User->Permission('PERMISSION_ADD_COMMENTS') && !$CategoryManager->GetCategoryById($this->Discussion->CategoryID)->Blocked) {
             $this->ShowForm = 1;
         }
     }
     $this->CallDelegate('Constructor');
 }
Beispiel #9
0
 /**
  * Define all required parameters to create the Pageer and PageerDetails.
  */
 public function Configure($CurrentPage, $RecordsPerPage, $TotalRecords, $Url, $ForceConfigure = FALSE)
 {
     if ($this->_PropertiesDefined === FALSE || $ForceConfigure === TRUE) {
         $this->Url = $Url;
         $this->CurrentPage = is_numeric($CurrentPage) && $CurrentPage > 0 ? $CurrentPage : 1;
         $this->RecordsPerPage = is_numeric($RecordsPerPage) && $RecordsPerPage > 0 ? $RecordsPerPage : $this->RecordsPerPage;
         $this->TotalRecords = is_numeric($TotalRecords) ? $TotalRecords : 0;
         $this->_Totalled = $this->TotalRecords == $this->RecordsPerPage ? FALSE : TRUE;
         if ($this->_Totalled === TRUE) {
             $this->_PageCount = CalculateNumberOfPages($this->TotalRecords, $this->RecordsPerPage);
             if ($this->CurrentPage > $this->_PageCount && $this->_PageCount > 0) {
                 $this->CurrentPage = $this->_PageCount;
             }
             $this->_FirstRecord = ($this->CurrentPage - 1) * $this->RecordsPerPage + 1;
             $this->_LastRecord = $this->_FirstRecord + $this->RecordsPerPage - 1;
             if ($this->_LastRecord > $this->TotalRecords) {
                 $this->_LastRecord = $this->TotalRecords;
             }
         } else {
             $this->_PageCount = $this->CurrentPage;
             if ($this->TotalRecords >= $this->RecordsPerPage) {
                 ++$this->_PageCount;
             }
             $this->_FirstRecord = ($this->CurrentPage - 1) * $this->RecordsPerPage + 1;
             $this->_LastRecord = $this->_FirstRecord + $this->TotalRecords - 1;
             if ($this->_LastRecord < $this->_FirstRecord) {
                 $this->_LastRecord = $this->_FirstRecord;
             }
             if ($this->_PageCount > $this->CurrentPage) {
                 $this->_LastRecord = $this->_LastRecord - 1;
             }
         }
         $this->_PropertiesDefined = TRUE;
     }
 }