kunzite (kunzite1) wrote in component_help,
kunzite
kunzite1
component_help

[theme] - [component] - [customizable comment headers + quick reply]

function Page::print_custom_head() {
"""
<style type="text/css">
/* let's add some margins to make it look prettier */
.quickreply_entry form, .quickreply_comment form {
  margin-top:    10px;
  margin-left:    5px;
  margin-bottom: 10px;
}
</style>
""";
}

function CommentInfo::print_postlink() {
  var string img_url    = "";
  var int    img_width  = 0;
  var int    img_height = 0;

  if($.show_postlink) {
    var Page   p    = get_page();
    var string url  = $.post_url;
    var string text = get_plural_phrase(0, "text_post_comment" + ($p.view == "friends" ? "_friends" : ""));
    if($.maxcomments) {
      $url  = "";
      $text = $*text_max_comments;
    }

    if($url != "") {
      """<a href="$url">""";
      if($img_url != "") {
        """<img src="$img_url" width="$img_width" height="$img_height" alt="$text" title="$text" border="0" />""";
      } else {
        print $text;
      }
      """</a>""";
    } else {
      print $text;
    }

  }
}

# Override the printing of a comment so that we can customise the way the header prints
function EntryPage::print_comment(Comment comment) {
  # define variables used for text layout.
  # If you want to change anything about the text in the layout, change what's in red.
  var bool   allpics_link            = false;                            # set to true to link userpic to allpics.bml
  var bool   show_picword            = false;                            # set to true to show userpic keyword
  var string comment_prefix          = "Comment by ";                    # how to start the title of the component box containing a single comment
  var string thread_prefix           = "Thread started by ";             # how to start the title of the component box containing a thread of comments
  var string anonymous_title         = "Anonymous";                      # what do display in place of a name on the component title when it's an anonymous post
  var string anonymous_header        = "<i>$*text_poster_anonymous</i>"; # what do display in place of a username in the comment header when it's an anonymous post
  var string ip_open_bracket         = "[";                              # opening bracket for around the IP address, placed after the username
  var string ip_close_bracket        = "]";                              # closing bracket for around the IP address
  var string link_open_bracket       = "(";                              # opening bracket for around the reply/parent/thread links
  var string link_close_bracket      = ")";                              # closing bracket for around the reply/parent/thread links
  var string link_seperator          = "&nbsp;";                         # space for between the reply/parent/thread links
  var string from                    = "$*text_comment_from";            # set from the core property, currently "From:"
  var string date                    = "$*text_comment_date";            # set from the core property, currently "Date:"
  var string select                  = "$*text_multiform_check";         # set from the core property, currently "Select:"
  var string ipaddr                  = "$*text_comment_ipaddr";          # set from the core property, currently "IP address:"
  var string parent                  = "$*text_comment_parent";          # set from the core property, currently "Parent"
  var string reply                   = "$*text_comment_reply";           # set from the core property, currently "Reply"
  var string thread                  = "$*text_comment_thread";          # set from the core property, currently "Thread"
  var Color  comments_frozen_bgcolor = "#aaaaff";                        # bgcolor for frozen comments

  # date formats, see http://www.livejournal.com/doc/s2/siteapi.core1.html#siteapi.core1.dateformats for more
  var string date_format             = "";                               # date format, leave blank for default
  var string time_format             = "";                               # time format, leave blank for default

  # var for header color based upon screened or not
  var string header_bgcolor          = ($comment.screened ? "$*comments_screened_bgcolor" : "$*comments_bgcolor");  # background color for the header section based on screened status

  # var for if we're going to print the reply link
  var bool   print_reply_link        = true;

  # if comment is frozen, change bgcolor, change link text, we're not printing a reply link
  if($comment.frozen             ) { $header_bgcolor = $comments_frozen_bgcolor; $print_reply_link = false; $reply = $*text_comment_frozen; }

  # if we've reached max comments for entry, change link text, we're not printing a reply link
  if($.entry.comments.maxcomments) { $reply = $*text_max_comments;               $print_reply_link = false;                                 }

  # place the anchor for the parent/thread links
  """<a name="$comment.anchor"></a> """;
 
  # if we are at a first level comment (ie. directly to an entry), we want to start the component box with the title.
  if ($comment.depth == 1) {
    print_entry_header((size $comment.replies > 0 ? $thread_prefix : $comment_prefix) + (defined $comment.poster ? $comment.poster.name : $anonymous_title));
    print_comment_top();
  }

  # start the box which contains the comment information. This takes care of the indentation.
  print_comment_content_top($comment);

  # start the header section
  """
  <div style="background-color: $header_bgcolor; color: $*entry_fgcolor; margin-top: 4px;">
    <table cellpadding="2" cellspacing="0" summary="0" width="100%" bgcolor="$header_bgcolor">""";

  # vars for seeing if we're going to print stuff
  var bool show_userpic = (defined $comment.userpic) and ($*comment_userpic_style != "off");
  var bool show_ip      = ($comment.metadata{"poster_ip"} != "");
  var bool show_subject = ($comment.subject != "" or defined $comment.subject_icon);
  # start the first row of the header
  """
      <tr valign="top">""";

  # place the userpic
  if ($show_userpic) {
    var string alttext = $comment.poster.name;
    var string title   = "";
    var string picword = $comment.metadata{"picture_keyword"};
    var Image  upi     = $comment.userpic;
    var int    width   = $upi.width;
    var int    height  = $upi.height;
    var string userpic = "";

    if($picword != "") {
      $alttext = $alttext + ": " + $picword;
    }

    if($show_picword) {
      $title = $alttext;
    }

    if($*comment_userpic_style == "small") {
      $width  = $width  / 2;
      $height = $height / 2;
    }

    $userpic = """<img src="$upi.url" width="$width" height="$height" alt="$alttext" title="$title" border="0" />""";

    if($allpics_link) {
      $userpic = """<a href="$*SITEROOT/allpics.bml?user=$comment.poster.username">$userpic</a>""";
    }

    """
        <td width="$width" align="center">$userpic</td>
        <td>
          <table cellpadding="2" cellspacing="0" summary="0" width="100%" bgcolor="$header_bgcolor">
            <tr>""";
  }

  # after the userpic place the user who posted the comment
  """
        <td align="left" width="100%" style="white-space: nowrap;">
          <strong>$from</strong>""";
  if (defined $comment.poster) {
    """$comment.poster""";
  } else {
    """ $anonymous_header""";
  }
  """
        </td>""";

  # after the poster, place the linkbar (delete button, screen/unscreen buttons)
  """
        <td align="right" style="white-space: nowrap">""";
  $comment->print_linkbar();
  """
        </td>""";

  # after the linkbar place the permanent link to the comment.
  """
        <td align="right">
          <strong>$link_open_bracket<a href="$comment.permalink_url">$*text_permalink</a>$link_close_bracket</strong>
        </td>
      </tr>""";

  # start the second row
  """
      <tr valign="top">""";

  # first place the date, spanning two columns (under the username and linkbar)
  """
        <td colspan="2" align="left" style="white-space: nowrap">
          <strong>$date</strong> """;
  print $comment->time_display($date_format, $time_format);
  """
        </td>""";

  # if multiform is on, place the select box for the multi action selector (delete/screen/unscreen)
  if ($.multiform_on) {
    """
        <td align="right" style="white-space: nowrap">
          <label for="ljcomsel_$comment.talkid">$select</label>""";
    $comment->print_multiform_check();
    """
        </td>""";
  }
  """
      </tr>""";

  if($show_ip) {
    # start the third row
    """
      <tr valign="top">""";

    # place the ip address
    """
        <td colspan="3" align="left" style="white-space: nowrap">
          <strong>$ipaddr</strong> $comment.metadata{"poster_ip"}""";
    """
        </td>
      </tr>""";
  }

  if($show_subject) {
    # start the third/fourth row
    """
      <tr valign="top">""";

    # place the subject line spanning all columns, with the subject icon before the actual subject
    """
        <td colspan="3" class="subject">""";
    if (defined $comment.subject_icon) {
      """$comment.subject_icon """;
    }
    if ($comment.subject != "") {
      """<strong>$comment.subject</strong>""";
    }
    """
        </td>
      </tr>""";
  }

  if($show_userpic) {
    """
          </table>
        </td>
      </tr>
    """;
  }

  # end the header section
  """
    </table>
  </div>""";

  # place the text 
  """
  <div style="margin-left: 5px">"""; $comment->print_text(); """</div>""";

  # place the Reply / Parent / Thread links 
  """
  <div class="small">
    $link_open_bracket""";
  if($print_reply_link) {
    # if we're printing the reply link, do it
    $comment->print_reply_link({"linktext" => $reply});
  } else {
    # else, print the appropriate text for why we're not printing the reply link
    print $reply;
  }
  """$link_close_bracket""";
  if ($comment.parent_url != "") {
    """$link_seperator$link_open_bracket<a href="$comment.parent_url">$parent</a>$link_close_bracket""";
  }
  if ($comment.thread_url != "") {
    """$link_seperator$link_open_bracket<a href="$comment.thread_url">$thread</a>$link_close_bracket""";
  }
  # if we're printing the reply link, we should also include the quickreply form
  if($print_reply_link) {
    $comment->print_reply_container({"class" => "quickreply_comment"});
  }
  """
  </div>""";

  # end the box containg the comment information
  print_comment_content_bottom();
}

function Comment::print_linkbar() {
  var string   link_separator = "&nbsp;";

  # 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

  # 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[size($link_keyseq)] = $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                                                  #
  #                                                                                                                                       #
  # If not watching:                                                                                                                      #
  #   Watch Thread:                                                                                                                       #
  #    $link_url{"watch_thread"}     = http://www.livejournal.com/manage/subscriptions/comments.bml?journal=exampleusername&dtalkid=256   #
  #    $link_caption{"watch_thread"} = Track This                                                                                         #
  #    $link_image{"watch_thread"}   = http://stat.livejournal.com/img/btn_track.gif                                                      #
  #                                                                                                                                       #
  # If watching:                                                                                                                          #
  #   Unwatch Thread:                                                                                                                     #
  #    $link_url{"unwatch_thread"}     = http://www.livejournal.com/manage/subscriptions/comments.bml?journal=exampleusername&dtalkid=256 #
  #    $link_caption{"unwatch_thread"} = Untrack This                                                                                     #
  #    $link_image{"unwatch_thread"}   = http://stat.livejournal.com/img/btn_tracking.gif                                                 #
  #########################################################################################################################################

  $link_image = {
                 "delete_comment"   => $*del_comment_img,
                 "edit_comment"     => $*edit_comment_img,
                 "screen_comment"   => $*scr_comment_img,
                 "unscreen_comment" => $*unscr_comment_img,
                 "freeze_thread"    => $*freeze_comment_img,
                 "unfreeze_thread"  => $*unfreeze_comment_img,
                 "watch_thread"     => $*track_comment_img,
                 "watching_parent"  => $*tracking_parent_img,
                 "unwatch_thread"   => $*untrack_comment_img,
                };


  # 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} != "") {
      $print = $print + """<a href="$link_url{$link_key}">""";
      # if image url available, use it
      if($link_image{$link_key} != "") {
        var string id = "";
        if($link_key->contains("screen")) {
          $id = "sus_";
        }
        if($link_key->contains("freeze")) {
          $id = "fuf_";
        }
        $id = "$id$.talkid";
        $print = $print + """<img id="$id" src="$link_image{$link_key}" alt="$link_caption{$link_key}" title="$link_caption{$link_key}" border="0" />""";
      } else {
        # else, just use text
        $print = $print + "$link_caption{$link_key}";
      }
      # add a separator
      $print = $print + "</a>$link_separator";
    }
  }

  # hack off last separator
  $print = $print->substr(0, $print->length() - $link_separator->length());

  # we're done! let's print it!
  print $print;
}
Tags: admin: deprecated, user: kunzite1
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 42 comments