/**
* Outputs a formatted comment.
*
* Prior to 2.1, this also output the discussion ("FirstComment") to the browser.
* That has moved to the discussion.php view.
*
* @param DataSet $Comment .
* @param Gdn_Controller $Sender .
* @param Gdn_Session $Session .
* @param int $CurrentOffet How many comments into the discussion we are (for anchors).
*/
function writeComment($Comment, $Sender, $Session, $CurrentOffset)
{
// Whether to order the name & photo with the latter first.
static $UserPhotoFirst = null;
if ($UserPhotoFirst === null) {
$UserPhotoFirst = c('Vanilla.Comment.UserPhotoFirst', true);
}
$Author = Gdn::userModel()->getID($Comment->InsertUserID);
//UserBuilder($Comment, 'Insert');
$Permalink = val('Url', $Comment, '/discussion/comment/' . $Comment->CommentID . '/#Comment_' . $Comment->CommentID);
// Set CanEditComments (whether to show checkboxes)
if (!property_exists($Sender, 'CanEditComments')) {
$Sender->CanEditComments = $Session->checkPermission('Vanilla.Comments.Edit', true, 'Category', 'any') && c('Vanilla.AdminCheckboxes.Use');
}
// Prep event args
$CssClass = cssClass($Comment, $CurrentOffset);
$Sender->EventArguments['Comment'] =& $Comment;
$Sender->EventArguments['Author'] =& $Author;
$Sender->EventArguments['CssClass'] =& $CssClass;
$Sender->EventArguments['CurrentOffset'] = $CurrentOffset;
$Sender->EventArguments['Permalink'] = $Permalink;
// Needed in writeCommentOptions()
if ($Sender->data('Discussion', null) === null) {
$discussionModel = new DiscussionModel();
$discussion = $discussionModel->getID($Comment->DiscussionID);
$Sender->setData('Discussion', $discussion);
}
// DEPRECATED ARGUMENTS (as of 2.1)
$Sender->EventArguments['Object'] =& $Comment;
$Sender->EventArguments['Type'] = 'Comment';
// First comment template event
$Sender->fireEvent('BeforeCommentDisplay');
?>
<li class="<?php
echo $CssClass;
?>
" id="<?php
echo 'Comment_' . $Comment->CommentID;
?>
">
<div class="Comment">
<?php
// Write a stub for the latest comment so it's easy to link to it from outside.
if ($CurrentOffset == Gdn::controller()->data('_LatestItem')) {
echo '<span id="latest"></span>';
}
?>
<div class="Options">
<?php
writeCommentOptions($Comment);
?>
</div>
<?php
$Sender->fireEvent('BeforeCommentMeta');
?>
<div class="Item-Header CommentHeader">
<div class="AuthorWrap">
<span class="Author">
<?php
if ($UserPhotoFirst) {
echo userPhoto($Author);
echo userAnchor($Author, 'Username');
} else {
echo userAnchor($Author, 'Username');
echo userPhoto($Author);
}
echo FormatMeAction($Comment);
$Sender->fireEvent('AuthorPhoto');
?>
</span>
<span class="AuthorInfo">
<?php
echo ' ' . wrapIf(htmlspecialchars(val('Title', $Author)), 'span', array('class' => 'MItem AuthorTitle'));
echo ' ' . wrapIf(htmlspecialchars(val('Location', $Author)), 'span', array('class' => 'MItem AuthorLocation'));
$Sender->fireEvent('AuthorInfo');
?>
</span>
</div>
<div class="Meta CommentMeta CommentInfo">
<span class="MItem DateCreated">
<?php
echo anchor(Gdn_Format::date($Comment->DateInserted, 'html'), $Permalink, 'Permalink', array('name' => 'Item_' . $CurrentOffset, 'rel' => 'nofollow'));
?>
</span>
<?php
echo DateUpdated($Comment, array('<span class="MItem">', '</span>'));
?>
<?php
// Include source if one was set
if ($Source = val('Source', $Comment)) {
echo wrap(sprintf(t('via %s'), t($Source . ' Source', $Source)), 'span', array('class' => 'MItem Source'));
}
// Include IP Address if we have permission
if ($Session->checkPermission('Garden.PersonalInfo.View')) {
echo wrap(ipAnchor($Comment->InsertIPAddress), 'span', array('class' => 'MItem IPAddress'));
}
$Sender->fireEvent('CommentInfo');
$Sender->fireEvent('InsideCommentMeta');
// DEPRECATED
$Sender->fireEvent('AfterCommentMeta');
// DEPRECATED
?>
</div>
</div>
<div class="Item-BodyWrap">
<div class="Item-Body">
<div class="Message">
<?php
echo formatBody($Comment);
?>
</div>
<?php
$Sender->fireEvent('AfterCommentBody');
writeReactions($Comment);
if (val('Attachments', $Comment)) {
writeAttachments($Comment->Attachments);
}
?>
</div>
</div>
</div>
</li>
<?php
$Sender->fireEvent('AfterComment');
}