/** * Get comment options. * * @since 2.1 * @param DataSet $Comment . * @return array $Options Each element must include keys 'Label' and 'Url'. */ function getCommentOptions($Comment) { $Options = array(); if (!is_numeric(val('CommentID', $Comment))) { return $Options; } $Sender = Gdn::controller(); $Session = Gdn::session(); $Discussion = Gdn::controller()->data('Discussion'); $CategoryID = val('CategoryID', $Discussion); $PermissionCategoryID = val('PermissionCategoryID', $Discussion); // Determine if we still have time to edit $EditContentTimeout = c('Garden.EditContentTimeout', -1); $CanEdit = $EditContentTimeout == -1 || strtotime($Comment->DateInserted) + $EditContentTimeout > time(); $TimeLeft = ''; $canEditDiscussions = $Session->checkPermission('Vanilla.Discussions.Edit', true, 'Category', $PermissionCategoryID); if ($CanEdit && $EditContentTimeout > 0 && !$canEditDiscussions) { $TimeLeft = strtotime($Comment->DateInserted) + $EditContentTimeout - time(); $TimeLeft = $TimeLeft > 0 ? ' (' . Gdn_Format::seconds($TimeLeft) . ')' : ''; } // Can the user edit the comment? $canEditComments = $Session->checkPermission('Vanilla.Comments.Edit', true, 'Category', $PermissionCategoryID); if ($CanEdit && $Session->UserID == $Comment->InsertUserID || $canEditComments) { $Options['EditComment'] = ['Label' => t('Edit') . $TimeLeft, 'Url' => '/post/editcomment/' . $Comment->CommentID, 'EditComment']; } // Can the user delete the comment? $SelfDeleting = $CanEdit && $Session->UserID == $Comment->InsertUserID && c('Vanilla.Comments.AllowSelfDelete'); if ($SelfDeleting || $Session->checkPermission('Vanilla.Comments.Delete', true, 'Category', $PermissionCategoryID)) { $Options['DeleteComment'] = ['Label' => t('Delete'), 'Url' => '/discussion/deletecomment/' . $Comment->CommentID . '/' . $Session->transientKey() . '/?Target=' . urlencode("/discussion/{$Comment->DiscussionID}/x"), 'Class' => 'DeleteComment']; } // DEPRECATED (as of 2.1) $Sender->EventArguments['Type'] = 'Comment'; // Allow plugins to add options $Sender->EventArguments['CommentOptions'] =& $Options; $Sender->EventArguments['Comment'] = $Comment; $Sender->fireEvent('CommentOptions'); return $Options; }