The S2 HowTo Journal

Tips, Tricks, and Tutorials for Basic S2 Customization

Previous Entry Share Next Entry
[paidaccount] Hiding particular users' comments
howto_user wrote in s2howto
Paid Accounts Only
The following tutorial requires creating and editing a custom theme layer, which in turn requires a paid, permanent, or early adopter account. Please read What are the paid account benefits? and How do I buy a paid account? to learn about the paid account benefits and how to buy a paid account.

This tutorial requires the creation of a theme layer. If you already have a theme layer, you will need to edit it and add the code below. If you do not have a theme layer, you will need to create one by following the instructions in the Theme Layer tutorial.

This tutorial will add a Usenet-style "killfile" to comment pages, which will hide particular users' comments. To use this on other people's comment pages (e.g. communities), you will need to add "?style=mine" to the URL.

If your theme layer or layout already has code to print comments, modify it to include the code described below. Otherwise, you will need to copy the code from the layout layer to your theme layer and modify it as appropriate. We'll use Generator as an example here. From the list of public layers, select "Generator", then "Raw Source Code". Find the EntryPage::print_comment function, and copy it into your theme layer. It looks like this:

function EntryPage::print_comment (Comment c) {
    var Color background; var Color color;
    if ($c.screened) {
        $background = $*comment_bar_screened_bgcolor;
        $color = $*comment_bar_screened_fgcolor;
    } elseif ($c.depth % 2) {
        $background = $*comment_bar_one_bgcolor;
        $color = $*comment_bar_one_fgcolor;
    } else {
        $background = $*comment_bar_two_bgcolor;
        $color = $*comment_bar_two_fgcolor;
    }
    var string poster = defined $c.poster ? $c.poster->as_string() : "<i>(Anonymous)</i>";
    var string sub_icon;
    if (defined $c.subject_icon) {
        $sub_icon = $c.subject_icon->as_string();
    }
    "<a name='$c.anchor'></a><div id='cmtbar$c.talkid' style='background-color: $background; color: $color; margin-top: 10px; width: 100%;'>";
    "<table cellpadding='2' cellspacing='0' summary='0' style='width: 100%'><tr valign='top'>";
    if (defined $c.userpic and $*comment_userpic_style != "off") {
        var int w = $c.userpic.width;
        var int h = $c.userpic.height;
        # WARNING: this will later be done by the system (it'll be a
        # constructional property), so don't copy this hack into your
        # layout layers or you'll be messed up later.
        if ($*comment_userpic_style == "small") {
            $w = $w / 2;
            $h = $h / 2;
        }
        print "<td style='width: 102px'><img src='$c.userpic.url' width='$w' height='$h' alt='[User Picture]' /></td>";
    }

    "<td style='width: 100%'><table style='width: 100%'><tr>";

    ### From, date, etc
    "<td align='left' style='width: 50%'>";
      print "<table>";
      print "<tr><th align='right' style='white-space: nowrap'>From:</th><td style='white-space: nowrap'>$poster</td></tr>\n";
      print "<tr><th align='right' style='white-space: nowrap'>Date:</th><td style='white-space: nowrap'>";
        print $c.time->date_format("long") + " - " + $c.time->time_format() + "</td></tr>";
      if ($c.metadata{"poster_ip"}) { print "<tr><th align='right' style='white-space: nowrap'>IP Address:</th><td>(" + $c.metadata{"poster_ip"} + ")</td></tr>"; }
    "</table></td>";

    ### Gadgets
    "<td align='right' style='width: 50%'>";
    if ($this.multiform_on) {
        " <label for='ljcomsel_$c.talkid'>$*text_multiform_check</label>";
        $c->print_multiform_check();
    }
    $c->print_linkbar();
    "</td></tr>";

    ### Subject / icon
    print "<tr valign='top'><td style='width: 50%'>";
    print (defined $c.subject_icon or $c.subject != "") ? "<h3>$c.subject_icon $c.subject</h3>" : "";
    print "</td>";

    ### Permalink
    print "<td style='width: 50%' align='right'><strong>(<a href='$c.permalink_url'>Link</a>)</strong></td></tr>";

    print "</table></td></tr></table></div>";
    print "<div style='margin-left: 5px'>$c.text</div>";
    print "<div style='margin-top: 3px; font-size: smaller'>";

    "<span class='commentlinks'>";
    if ($c.frozen) {
        "(Replies frozen) ";
    } else {
        "(<a href='$c.reply_url'>Reply to this</a>) ";
    }
    "</span>";

    if ($c.parent_url != "") { "(<a href='$c.parent_url'>Parent</a>) "; }
    if ($c.thread_url != "") { "(<a href='$c.thread_url'>Thread</a>) "; }
    "</div>";
}

The key part here is "$c.text" (highlighted), which is the text of the comment. We want to modify this to say that the comment has been killfiled, if it has, rather than printing the text. So, change those 3 lines of code to look like this:

[ ... ]
    var string[] bad_people = [
        "exampleusername",
        "examplecomm",
    ];
    var string c_text = $c.text;
    foreach var string person ($bad_people) {
      if ($.args{"show_killed"} != "yes" and $person == $c.poster.username) {
         $c_text = """
<a href="?.show_killed=yes">
Killfiled.  Click to view.
</a>
""";
      }
    }

    print "</table></td></tr></table></div>";
    print "<div style='margin-left: 5px'>$c_text</div>";
    print "<div style='margin-top: 3px; font-size: smaller'>";
[ ... ]

Now, we print "$c_text" instead. If the comment was killed, we modify that to say so. Then simply add the usernames of the people whose comments you want to kill to the "bad_people" array.

Contributed by lithiana.


Comments Disabled:

Comments have been disabled for this post.

?

Log in

No account? Create an account