Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Profile Addon - Deleting Avatar Comments Help

Hey,

I'm developing an addon which allows users to delete avatar comments on their wall only.

The controller I found which renders the comments is ProfileController_BeforeActivity_Handler. Though I don't think there's a way to render the delete button without overriding some methods. I'm wondering if there's a better way to do this.

Comments

  • R_JR_J Admin

    The ActivityComments list is rendered here:

       <?php
        $Comments = val('Comments', $Activity, array());
        if (count($Comments) > 0) {
            echo '<ul class="DataList ActivityComments">';
            foreach ($Comments as $Comment) {
                WriteActivityComment($Comment, $Activity);
            }
        } else {
            echo '<ul class="DataList ActivityComments Hidden">';
        }
    

    Each single comment is written with the writeActivityComment function:

    if (!function_exists('WriteActivityComment')):
        function writeActivityComment($Comment, $Activity) {
            $Session = Gdn::session();
            $Author = UserBuilder($Comment, 'Insert');
            $PhotoAnchor = userPhoto($Author, 'Photo');
            $CssClass = 'Item ActivityComment ActivityComment';
            if ($PhotoAnchor != '')
                $CssClass .= ' HasPhoto';
            ?>
            <li id="ActivityComment_<?php echo $Comment['ActivityCommentID']; ?>" class="<?php echo $CssClass; ?>">
                <?php if ($PhotoAnchor != '') { ?>
    ...
    

    A delete button should look like that: <div class="Options"><a href="/dashboard/activity/delete/XYZ/transientKey?Target=profile%2Fusername" class="Delete">&times;</a></div>

    You would have to add it right after the li.ActivityComment element. Sadly, there is no event fired which could help you.

    I see only one obvious option, but there might be a second way to do so:

    1. Copy the writeActivityComment function below your plugin and change it so that it will display the option if needed/allowed.
    2. Use JavaScript. An activity has the activity type in the css class. So you could write a selector like that: .Activity-PictureChange > .ActivityComments > .ActivityComment. The transientKey is available in your JavaScript with this var transientKey = gdn.definition('TransientKey');

    Although normally I'd prefer PHP solutions, the JavaScript way would be less invasive here and I would use it in this case.

  • Thank you so much! I'll probably go with the JS solution. :)

Sign In or Register to comment.