Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.
Help keep Vanilla free:<?php
include("appg/settings.php");
include("appg/init_vanilla.php");
$Context->Session->UserID = 4;
$DiscussionID = 312;
// Load the selected user
$UserManager = $Context->ObjectFactory->NewContextObject($Context, "UserManager");
$Context->Session->User = $UserManager->GetUserByID($Context->Session->UserID);
// Ensure the user is allowed to view this page
$Context->Session->Check($Context);
// Create the discussion and comment objects
$NewComment = $Context->ObjectFactory->NewContextObject($Context, 'Comment');
$Discussion = $Context->ObjectFactory->NewContextObject($Context, 'Discussion');
$cm = $Context->ObjectFactory->NewContextObject($Context, 'CommentManager');
$dm = $Context->ObjectFactory->NewContextObject($Context, 'DiscussionManager');
// Set up the new comment
$NewComment->Clear();
$NewComment->DiscussionID = $DiscussionID;
$NewComment->Body = time();
$NewComment->UserCommentCount = $Context->Session->User->CountComments;
// Get the selected discussion
$Discussion = $dm->GetDiscussionById($NewComment->DiscussionID);
if ($Discussion->Closed && !$Context->Session->User->Permission('PERMISSION_CLOSE_DISCUSSIONS')) {
$ResultComment = false;
$Context->WarningCollector->Add($Context->GetDefinition('ErrPermissionInsufficient'));
} else {
$ResultComment = $cm->SaveComment($NewComment);
}
if ($ResultComment) {
echo "Comment added successfully\n";
}
else
echo "Failed to save comment.\n";
?>
1 to 2 of 2