Ejemplo n.º 1
0
function WriteOptionList($Object, $Sender, $Session)
{
    $EditContentTimeout = C('Garden.EditContentTimeout', -1);
    $CanEdit = $EditContentTimeout == -1 || strtotime($Object->DateInserted) + $EditContentTimeout > time();
    $TimeLeft = '';
    if ($CanEdit && $EditContentTimeout > 0) {
        $TimeLeft = strtotime($Object->DateInserted) + $EditContentTimeout - time();
        $TimeLeft = $TimeLeft > 0 ? ' (' . Gdn_Format::Seconds($TimeLeft) . ')' : '';
    }
    $Sender->Options = '';
    $CategoryID = GetValue('CategoryID', $Object);
    if (!$CategoryID && property_exists($Sender, 'Discussion')) {
        $CategoryID = GetValue('CategoryID', $Sender->Discussion);
    }
    // Show discussion options if this is the discussion / first comment
    if ($Sender->EventArguments['Type'] == 'Discussion') {
        // Can the user edit the discussion?
        if ($CanEdit && $Session->UserID == $Object->InsertUserID || $Session->CheckPermission('Vanilla.Discussions.Edit', TRUE, 'Category', $CategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T('Edit'), '/vanilla/post/editdiscussion/' . $Object->DiscussionID, 'EditDiscussion') . $TimeLeft . '</span>';
        }
        // Can the user announce?
        if ($Session->CheckPermission('Vanilla.Discussions.Announce', TRUE, 'Category', $CategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T($Sender->Discussion->Announce == '1' ? 'Unannounce' : 'Announce'), 'vanilla/discussion/announce/' . $Object->DiscussionID . '/' . $Session->TransientKey(), 'AnnounceDiscussion') . '</span>';
        }
        // Can the user sink?
        if ($Session->CheckPermission('Vanilla.Discussions.Sink', TRUE, 'Category', $CategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T($Sender->Discussion->Sink == '1' ? 'Unsink' : 'Sink'), 'vanilla/discussion/sink/' . $Object->DiscussionID . '/' . $Session->TransientKey() . '?Target=' . urlencode($Sender->SelfUrl), 'SinkDiscussion') . '</span>';
        }
        // Can the user close?
        if ($Session->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $CategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T($Sender->Discussion->Closed == '1' ? 'Reopen' : 'Close'), 'vanilla/discussion/close/' . $Object->DiscussionID . '/' . $Session->TransientKey() . '?Target=' . urlencode($Sender->SelfUrl), 'CloseDiscussion') . '</span>';
        }
        // Can the user delete?
        if ($Session->CheckPermission('Vanilla.Discussions.Delete', TRUE, 'Category', $CategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T('Delete Discussion'), 'vanilla/discussion/delete/' . $Object->DiscussionID . '/' . $Session->TransientKey(), 'DeleteDiscussion') . '</span>';
        }
    } else {
        // And if this is just another comment in the discussion ...
        // Can the user edit the comment?
        if ($CanEdit && $Session->UserID == $Object->InsertUserID || $Session->CheckPermission('Vanilla.Comments.Edit', TRUE, 'Category', $Sender->Discussion->CategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T('Edit'), '/vanilla/post/editcomment/' . $Object->CommentID, 'EditComment') . $TimeLeft . '</span>';
        }
        // Can the user delete the comment?
        if ($Session->CheckPermission('Vanilla.Comments.Delete', TRUE, 'Category', $CategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T('Delete'), 'vanilla/discussion/deletecomment/' . $Object->CommentID . '/' . $Session->TransientKey() . '/?Target=' . urlencode($Sender->SelfUrl), 'DeleteComment') . '</span>';
        }
    }
    // Allow plugins to add options
    $Sender->FireEvent('CommentOptions');
    echo $Sender->Options;
}
Ejemplo n.º 2
0
 function GetCommentOptions($Comment)
 {
     $Options = array();
     if (!is_numeric(GetValue('CommentID', $Comment))) {
         return $Options;
     }
     $Sender = Gdn::Controller();
     $Session = Gdn::Session();
     $Discussion = Gdn::Controller()->Data('Discussion');
     $CategoryID = GetValue('CategoryID', $Discussion);
     $PermissionCategoryID = GetValue('PermissionCategoryID', $Discussion);
     // Determine if we still have time to edit
     $EditContentTimeout = C('Garden.EditContentTimeout', -1);
     $CanEdit = $EditContentTimeout == -1 || strtotime($Comment->DateInserted) + $EditContentTimeout > time();
     $TimeLeft = '';
     if ($CanEdit && $EditContentTimeout > 0 && !$Session->CheckPermission('Vanilla.Discussions.Edit', TRUE, 'Category', $PermissionCategoryID)) {
         $TimeLeft = strtotime($Comment->DateInserted) + $EditContentTimeout - time();
         $TimeLeft = $TimeLeft > 0 ? ' (' . Gdn_Format::Seconds($TimeLeft) . ')' : '';
     }
     // Can the user edit the comment?
     if ($CanEdit && $Session->UserID == $Comment->InsertUserID || $Session->CheckPermission('Vanilla.Comments.Edit', TRUE, 'Category', $PermissionCategoryID)) {
         $Options['EditComment'] = array('Label' => T('Edit') . ' ' . $TimeLeft, 'Url' => '/vanilla/post/editcomment/' . $Comment->CommentID, 'EditComment');
     }
     // Can the user delete the comment?
     // if (($CanEdit && $Session->UserID == $Comment->InsertUserID) || $Session->CheckPermission('Vanilla.Comments.Delete', TRUE, 'Category', $PermissionCategoryID))
     if ($Session->CheckPermission('Vanilla.Comments.Delete', TRUE, 'Category', $PermissionCategoryID)) {
         $Options['DeleteComment'] = array('Label' => T('Delete'), 'Url' => 'vanilla/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;
 }
Ejemplo n.º 3
0
function WriteOptionList($Object, $Sender, $Session)
{
    $EditContentTimeout = C('Garden.EditContentTimeout', -1);
    $CategoryID = GetValue('CategoryID', $Object);
    if (!$CategoryID && property_exists($Sender, 'Discussion')) {
        $CategoryID = GetValue('CategoryID', $Sender->Discussion);
    }
    $PermissionCategoryID = GetValue('PermissionCategoryID', $Object, GetValue('PermissionCategoryID', $Sender->Discussion));
    $CanEdit = $EditContentTimeout == -1 || strtotime($Object->DateInserted) + $EditContentTimeout > time();
    $TimeLeft = '';
    if ($CanEdit && $EditContentTimeout > 0 && !$Session->CheckPermission('Vanilla.Discussions.Edit', TRUE, 'Category', $PermissionCategoryID)) {
        $TimeLeft = strtotime($Object->DateInserted) + $EditContentTimeout - time();
        $TimeLeft = $TimeLeft > 0 ? ' (' . Gdn_Format::Seconds($TimeLeft) . ')' : '';
    }
    $Sender->Options = '';
    // Show discussion options if this is the discussion / first comment
    if ($Sender->EventArguments['Type'] == 'Discussion') {
        // Can the user edit the discussion?
        if ($CanEdit && $Session->UserID == $Object->InsertUserID || $Session->CheckPermission('Vanilla.Discussions.Edit', TRUE, 'Category', $PermissionCategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T('Edit'), '/post/editdiscussion/' . $Object->DiscussionID, 'EditDiscussion') . $TimeLeft . '</span>';
        }
        // Can the user announce?
        if ($Session->CheckPermission('Vanilla.Discussions.Announce', TRUE, 'Category', $PermissionCategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T($Sender->Discussion->Announce == '1' ? 'Unannounce' : 'Announce'), 'discussion/announce/' . $Object->DiscussionID . '/' . $Session->TransientKey() . '?Target=' . urlencode($Sender->SelfUrl), 'AnnounceDiscussion') . '</span>';
        }
        // Can the user sink?
        if ($Session->CheckPermission('Vanilla.Discussions.Sink', TRUE, 'Category', $PermissionCategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T($Sender->Discussion->Sink == '1' ? 'Unsink' : 'Sink'), 'discussion/sink/' . $Object->DiscussionID . '/' . $Session->TransientKey() . '?Target=' . urlencode($Sender->SelfUrl), 'SinkDiscussion') . '</span>';
        }
        // Can the user close?
        if ($Session->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $PermissionCategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T($Sender->Discussion->Closed == '1' ? 'Reopen' : 'Close'), 'discussion/close/' . $Object->DiscussionID . '/' . $Session->TransientKey() . '?Target=' . urlencode($Sender->SelfUrl), 'CloseDiscussion') . '</span>';
        }
        // Can the user delete?
        if ($Session->CheckPermission('Vanilla.Discussions.Delete', TRUE, 'Category', $PermissionCategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T('Delete Discussion'), 'discussion/delete/' . $Object->DiscussionID . '/' . $Session->TransientKey(), 'DeleteDiscussion') . '</span>';
        }
    } else {
        // And if this is just another comment in the discussion ...
        // Can the user edit the comment?
        if ($CanEdit && $Session->UserID == $Object->InsertUserID || $Session->CheckPermission('Vanilla.Comments.Edit', TRUE, 'Category', $PermissionCategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T('Edit'), '/post/editcomment/' . $Object->CommentID, 'EditComment') . $TimeLeft . '</span>';
        }
        // Can the user delete the comment?
        if ($Session->CheckPermission('Vanilla.Comments.Delete', TRUE, 'Category', $PermissionCategoryID)) {
            $Sender->Options .= '<span>' . Anchor(T('Delete'), 'discussion/deletecomment/' . $Object->CommentID . '/' . $Session->TransientKey() . '/?Target=' . urlencode("/discussion/{$Object->DiscussionID}/x"), 'DeleteComment') . '</span>';
        }
    }
    // Allow plugins to add options
    $Sender->FireEvent('CommentOptions');
    echo $Sender->Options;
    if ($Sender->CanEditComments) {
        if ($Sender->EventArguments['Type'] == 'Comment') {
            $Id = $Object->CommentID;
            echo '<div class="Options">';
            if (!property_exists($Sender, 'CheckedComments')) {
                $Sender->CheckedComments = $Session->GetAttribute('CheckedComments', array());
            }
            $ItemSelected = InSubArray($Id, $Sender->CheckedComments);
            echo '<span class="AdminCheck"><input type="checkbox" name="' . 'Comment' . 'ID[]" value="' . $Id . '"' . ($ItemSelected ? ' checked="checked"' : '') . ' /></span>';
            echo '</div>';
        } else {
            echo '<div class="Options">';
            echo '<div class="AdminCheck"><input type="checkbox" name="Toggle"></div>';
            echo '</div>';
        }
    }
}