Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Req: Post # in Permalink.
This discussion has been closed.
Comments
<?php /* Extension Name: Comment Links Extension Url: http://lussumo.com/docs/ Description: Adds a numbered link to every comment, which redirects to the proper discussion and page. Version: 1.0 beta Author: WallPhone Author Url: http://wallphone.com/ */ if ( 'comments.php' == $Context->SelfUrl ) { $CommentID = ForceIncomingInt('CommentID', 0); if ( $CommentID ) { function LocateComment(&$CommentGrid) { $cm = $CommentGrid->Context->ObjectFactory->NewContextObject($CommentGrid->Context, 'CommentManager'); $s = $CommentGrid->Context->ObjectFactory->NewContextObject($CommentGrid->Context, 'SqlBuilder'); $CommentID = ForceIncomingInt('CommentID', 0); $s->SetMainTable('Comment', 'm'); $s->AddSelect('DiscussionID', 'm'); $s->AddWhere('m', 'CommentID', '', $CommentID, '='); $result = $CommentGrid->Context->Database->Select($s, 'Extension:CommentLinks', 'LocateComment', 'An error occurred while attempting to retrieve the discussion ID.'); $result = $CommentGrid->Context->Database->GetRow($result); $DiscussionID = $result[0]; $CommentCount = $cm->GetCommentCount($DiscussionID); // If trying to focus on a particular comment, make sure to look at the correct page $PageCount = CalculateNumberOfPages($CommentCount, $CommentGrid->Context->Configuration['COMMENTS_PER_PAGE']); $CurrentPage = 0; $FoundComment = 0; while ($CurrentPage <= $PageCount && !$FoundComment) { $CommentData = $cm->GetCommentList($CommentGrid->Context->Configuration['COMMENTS_PER_PAGE'], $CurrentPage, $DiscussionID); $RowPosition = 0; $CurrentPage++; while ($Row = $CommentGrid->Context->Database->GetRow($CommentData)) { $RowPosition++; if (ForceInt($Row['CommentID'], 0) == $CommentID) { $FoundComment = 1; break; } } } // 302 to the comment's location if (2 >= $CurrentPage) { $url = GetUrl($CommentGrid->Context->Configuration, 'comments.php', '', 'DiscussionID', $DiscussionID) .'#Item_'. $RowPosition; } else { $url = GetUrl($CommentGrid->Context->Configuration, 'comments.php', '', 'DiscussionID', $DiscussionID, --$CurrentPage) .'#Item_'.$RowPosition; } header ('location: '. str_replace('&', '&', $url)); exit(); } $Context->AddToDelegate('CommentGrid', 'Constructor', 'LocateComment'); } else { function AddCommentLink(&$CommentGrid) { global $CountWhispers; $Page = ForceIncomingInt('page', 1); $Comment = &$CommentGrid->DelegateParameters['Comment']; $RowNumber = &$CommentGrid->DelegateParameters['RowNumber']; if ( (1 == $RowNumber) && (1 < $Page) ) { //TODO?: count the whispers on the prior page(s) } if ( $Comment->WhisperUserID ) { $CountWhispers++; } else { $CommentList = &$CommentGrid->DelegateParameters['CommentList']; $Number = $RowNumber - $CountWhispers + ($Page - 1) * $CommentGrid->Context->Configuration['COMMENTS_PER_PAGE']; $CommentList .= '<a href="'. GetUrl($Configuration, 'comments.php', '', 'CommentID', $Comment->CommentID) .'" id="CommentID_'. $Comment->CommentID .'"># '. $Number .'</a>'; } } $CountWhispers = 0; $Context->AddToDelegate('CommentGrid', 'PostCommentOptionsRender', 'AddCommentLink'); } } ?>
So this extension you're working on would be an improved permalinks basically?
$c = $cm->GetCommentByID($CommentID, $CommentGrid->Context->Session->UserID); if (!$c) Echo 'No matching comment by ID: '. $CommentID;
I think I will do a straight SQL select to get the DiscussionID from a known CommentID, rather than instantiate a CommentManager.This tires to accomodate all the requirements above--numbered comments, whispers not numbered, link directly to comment's ID which is resolved to a discussion and a page.