in response to
kabutar's
comment in my
s2layers post.
adds AJAX support.
adds quickreply comments to each comment.
adds timezone support.
uses linkbar function for comments.
function Comment::print_linkbar() {
var string link_seperator = "";
# initialize array/hashes
var string[] link_keyseq = [""];
var string{} link_url = {"" => ""};
var string{} link_caption = {"" => ""};
var string{} link_image = {"" => ""};
var string print = ""; # var for printing
var int keyseq_index = 0; # set index point for new link_keyseq array
# gather current linkbar
foreach var string link_key ($.link_keyseq) {
var Link link = $this->get_link($link_key);
$link_url{$link_key} = $link.url;
$link_caption{$link_key} = $link.caption;
$link_image{$link_key} = $link.icon.url;
$link_keyseq[$keyseq_index++] = $link_key; # add this to new link_keyseq array
}
#####################################################################################################################################
# by now, the above hashes should look something like: #
# #
# Delete Comment: #
# $link_url{"delete_comment"} =
http://www.livejournal.com/delcomment.bml?journal=exampleusername&id=256 #
# $link_caption{"delete_comment"} = Delete #
# $link_image{"delete_comment"} =
http://stat.livejournal.com/img/btn_del.gif #
# #
# If not frozen: #
# Freeze Comment: #
# $link_url{"freeze_thread"} =
http://www.livejournal.com/talkscreen.bml?mode=freeze&journal=exampleusername&talkid=256 #
# $link_caption{"freeze_thread"} = Freeze #
# $link_image{"freeze_thread"} =
http://stat.livejournal.com/img/btn_freeze.gif #
# #
# If frozen: #
# Unfreeze Comment: #
# $link_url{"unfreeze_thread"} =
http://www.livejournal.com/talkscreen.bml?mode=unfreeze&journal=exampleusername&talkid=256 #
# $link_caption{"unfreeze_thread"} = Unfreeze #
# $link_image{"unfreeze_thread"} =
http://stat.livejournal.com/img/btn_unfreeze.gif #
# #
# If not screened: #
# Screen Comment: #
# $link_url{"screen_comment"} =
http://www.livejournal.com/talkscreen.bml?mode=screen&journal=exampleusername&talkid=256 #
# $link_caption{"screen_comment"} = Screen #
# $link_image{"screen_comment"} =
http://stat.livejournal.com/img/btn_scr.gif #
# #
# If screened: #
# Unscreen Comment: #
# $link_url{"unscreen_comment"} =
http://www.livejournal.com/talkscreen.bml?mode=unfreeze&journal=exampleusername&talkid=256 #
# $link_caption{"unscreen_comment"} = Unscreen #
# $link_image{"unscreen_comment"} =
http://stat.livejournal.com/img/btn_unscr.gif #
#####################################################################################################################################
# replace images
$link_image{"delete_comment" } = $*delete;
$link_image{"freeze_thread" } = $*freeze;
$link_image{"unfreeze_thread" } = $*unfreeze;
$link_image{"screen_comment" } = $*screen;
$link_image{"unscreen_comment"} = $*unscreen;
$link_image{"watch_thread" } = $*track;
$link_image{"unwatch_thread" } = $*untrack;
$link_image{"watching_parent" } = $*tracking_parent;
var string id = "";
# loop thru linkbar and add links to print var
foreach var string link_key ($link_keyseq) {
# if we can do performed action, url will be present
if($link_url{$link_key} != "") {
$id = "";
# if we're freezing, add freeze handle to image
if($link_key->contains("freeze")) {
$id = "fuf_$.talkid";
}
# if we're screening, add screen handle to image
if($link_key->contains("screen")) {
$id = "sus_$.talkid";
}
if($id != "") {
$id = " id=\"$id\" name=\"$id\"";
}
$print = $print + """
""";
# if image url available, use it
if($link_image{$link_key} != "") {
$print = $print + """
""";
} else {
# else, just use text
$print = $print + "$link_caption{$link_key}";
}
# add a seperator
$print = $print + "$link_seperator";
}
}
# hack off last seperator
$print = $print->substr(0, $print->length() - $link_seperator->length());
# we're done! let's print it!
print $print;
}
# insert dom_id for each comment so quickreply and AJAX have something to hold onto
function EntryPage::print_comments (Comment[] cs) {
if (size $cs == 0) { return; }
foreach var Comment c ($cs) {
"
\n";
if ($c.full) {
$this->print_comment($c);
} else {
$this->print_comment_partial($c);
}
"";
$this->print_comments($c.replies);
}
}
function EntryPage::print_comment (Comment c) {
var int count = 0;
var int img_height = 0;
var int img_width = 0;
var int multiplier = 0;
var int sidewidth = 0;
var int entry_page_width = 0;
var int entry_half_width = 0;
var int subtract = 0;
var string reply = "";
var string parent = "";
var string thread = "";
var string img_alt = "";
var string img_url = "";
var string img_link = "";
var string ip = "";
var string poster = "";
var string sub_icon = "";
var string subject = "";
var string url = "";
var Color mybg;
$count = $c.depth / 7; # get how many times greater is the depth than our 8 color choices
$count = $count + (($count * 10 % 10 >= 5) ? 1 : 0); # round that number
$subtract = $count * 7; # figure out how many times we need to subtract 8 from the depth
$multiplier = (($c.depth - 1) - $subtract) * 15;
if($*nav_scale == "darker") {
$mybg = $*entry_bg;
} else {
$mybg = $*entry_bg;
}
if(defined $c.poster) {
$poster = $c.poster.name;
$url = $c.poster->base_url();
} else {
$poster = """$*text_poster_anonymous""";
}
if (defined $c.subject_icon) {
$sub_icon = $c.subject_icon->as_string();
}
if ($c.metadata{"poster_ip"}) {
$ip = " (" + $c.metadata{"poster_ip"} + ")";
}
$sidewidth = 137 + ($c.depth - 1) * 25;
$entry_page_width = $*page_width - $sidewidth;
$entry_half_width = $entry_page_width / 2;
$subject = $c.subject != "" ? $c.subject : """$*text_nosubject""";
"""
$c.poster.username""";
if(defined $c.userpic) {
"""
""";
}
if($c.journal) {
"""
$poster """;
} else {
"""
$poster
""";
}
"""
$sub_icon $ip
""";
# add timezone support
print $c->time_display($*my_date, "");
if ($this.multiform_on) {
$c->print_multiform_check();
}
"""
$subject
""";
# use print_text()
$c->print_text();
"""
""";
# build thread icon
if($c.thread_url != "") {
$img_alt = $*text_comment_thread;
$img_url = $*comment;
$img_link = $c.thread_url;
$img_width = 17;
$img_height = 21;
$thread = """
""";
}
# build parent icon
if($c.parent_url != "") {
$img_alt = $*text_comment_parent;
$img_url = $*parent;
$img_link = $c.parent_url;
$img_width = 20;
$img_height = 21;
$parent = """
""";
}
# if we're not frozen, print quickreply
if(not $c.frozen) {
$img_alt = $*text_comment_frozen;
$img_url = $*leave_comment;
$img_width = 20;
$img_height = 21;
print """""";
$c->print_reply_link({"img_url" => $img_url, "img_width" => $img_width + "", "img_height" => $img_height + "", "img_align" => "middle", "alt" => $img_alt, "title" => $img_alt});
print """""";
} else {
# else, just print image
$img_alt = $*text_comment_frozen;
$img_url = $*leave_comment;
$img_width = 20;
$img_height = 21;
$reply = """
""";
print $reply;
}
print "$thread$parent";
# use print_linkbar()
$c->print_linkbar();
"""
""";
# print reply container
$c->print_reply_container();
"""
""";
}