kunzite (kunzite1) wrote in component_help,
kunzite
kunzite1
component_help

customizing the entries v3.0 / custom security icons

###################################
# CUSTOMIZING THE ENTRIES  (V3.0) #
# kunzite1, component_help/869795 #
# overrides:                      #
#  Entry::print_metadata()        #
#  CommentInfo::print()           #
#  Entry::print_linkbar()         #
#  print_entry()                  #
###################################

# activate tags
set tags_aware      = true;

# add colons to text because i didn't like them being hard-coded inside print_metadata()
set text_meta_mood  = "Current Mood:";
set text_meta_music = "Current Music:";

function Entry::print_metadata() {
  var string   tags_header          = "Current Tags"; # text header for tags in metadata
  var string   tags_joiner          = ":";            # text to come after tags header
  var string   tags_seperator       = ", ";           # text for seperating tags in tag list

  # get Entry handle
  var Entry e = $this;

  var string metadata = "";

  var Link edit_tags = $e->get_link("edit_tags");
  if ((size $e.metadata > 0) or ((size $e.tags > 0) and ($*tags_aware))){
    foreach var string k ($e.metadata){
      var string text = $k;
      var string val  = $e.metadata{$k};
      if ($k == "mood"){
        $text = $*text_meta_mood;
      } 
      elseif ($k == "music") {
        $text = $*text_meta_music;
      }
      if ($k == "mood" and defined $e.mood_icon){
        var Image i = $e.mood_icon;
        $val = """<img src="$i.url" width="$i.width" height="$i.height" align="middle" alt="" /> $val""";
      }
      $metadata = $metadata + """<strong>$text</strong> $val<br />""";
    }
    if ((size $e.tags > 0) and $*tags_aware) {
      var int    tcount               = 0;
      if($edit_tags.url != "") {
        $tags_header = """<a href="$edit_tags.url">$tags_header</a>""";
      }
      $metadata = $metadata + """<strong>$tags_header$tags_joiner</strong> """;
      foreach var Tag t ($e.tags) {
        $metadata = $metadata + """<a rel="tag" href="$t.url">$t.name</a>""";
        $tcount++;
        if ($tcount != size $e.tags) { $metadata = $metadata + $tags_seperator; }
      }
    }
  }
  print $metadata;
}

function CommentInfo::print() {
  # get Page handle
  var Page p = get_page();

  var string comments = "";
  if($.enabled) {
    if($.count > 0 or $.screened) {
      $comments = $comments + """<a href="$.read_url">""" + get_plural_phrase($.count, "text_read_comments" + (($p.view == "friends") ? "_friends" : "")) + "</a> $*comment_divider ";
    }
    if($.maxcomments) {
      $comments = $comments + $*text_max_comments;
    } else {
      $comments = $comments + """<a href="$.post_url">""" + get_plural_phrase(0, "text_post_comment" + (($p.view == "friends") ? "_friends" : "")) + """</a>""";
    }
  }
  print $comments;
}

function Entry::print_linkbar() {
  var string   linkbar_seperator    = " "; # seperator for links in linkbar (edit/mem/tags)
  var string{} linkbar_captions     = {    # linkbar captions
                                       "edit_entry"  => "Edit Entry",
                                       "edit_tags"   => "Edit Tags",
                                       "mem_add"     => "Add to Memories",
                                       "nav_prev"    => "Previous Entry",
                                       "nav_next"    => "Next Entry",
                                       "tell_friend" => "Tell a Friend",
                                      };
  var string{} linkbar_images       = {     # linkbar images;
                                       "edit_entry"  => "$*edit_img",
                                       "edit_tags"   => "$*tags_img",
                                       "mem_add"     => "$*mem_img",
                                       "nav_prev"    => "$*backarrow2",
                                       "nav_next"    => "$*forwardarrow2",
                                       "tell_friend" => "$*tellfriend_img",
                                      };
  # get Page handle
  var Page p = get_page();

  # get Entry handle
  var Entry e = $this;

  # initialize array/hashes
  var string[] link_keyseq    = [""];
  var string{} link_url       = {"" => ""};
  var string{} link_caption   = {"" => ""};
  var string{} link_image     = {"" => ""};
  $link_caption = $linkbar_captions;
  $link_image   = $linkbar_images;

  var string linkbar         = "";                                         # var for printing
  var bool   show_interentry = ($p.view == "entry" or $p.view == "reply"); # if entry/reply view, show interentry
  var int    keyseq_index    = 0;                                          # set index point for new link_keyseq array

  if($show_interentry) {
    # if show interentry, put previous entry link first
    $link_keyseq[$keyseq_index++] = "nav_prev";

    # get previous entry link information
    var Link prev             = $e->get_link("nav_prev");
    $link_url{"nav_prev"}     = $prev.url;

    # get next entry link information
    var Link next             = $e->get_link("nav_next");
    $link_url{"nav_next"}     = $next.url;
  }

  # gather current linkbar
  foreach var string link_key ($e.link_keyseq) {
    var Link  link            = $e->get_link($link_key);
    $link_url{$link_key}      = $link.url;
    $link_caption{$link_key}  = $link_caption{$link_key} != "" ? $link_caption{$link_key} : $link.caption;
    $link_image{$link_key}    = $link_image{$link_key}   != "" ? $link_image{$link_key}   : $link.icon.url;
    $link_keyseq[$keyseq_index++] = $link_key; # add this to new link_keyseq array
  }
  if($show_interentry) {
    # if show interentry, put next entry link last
    $link_keyseq[$keyseq_index++] = "nav_next";
  }

  #################################################################################################################
  # by now, the above hashes should look something like:                                                          #
  #                                                                                                               #
  # If interentry:                                                                                                #
  #   Previous Entry:                                                                                             # 
  #    $link_url{"nav_prev"}     = http://www.livejournal.com/go.bml?journal=exampleusername&itemid=256&dir=prev  #
  #    $link_caption{"nav_prev"} = Previous Entry                                                                 #
  #    $link_image{"nav_prev"}   = http://stat.livejournal.com/img/btn_prev.gif                                   #
  #                                                                                                               #
  # Edit Entry:                                                                                                   # 
  #  $link_url{"edit_entry"}     = http://www.livejourna.com/editjournal.bml?journal=exampleusername&itemid=256   #
  #  $link_caption{"edit_entry"} = Edit Entry                                                                     #
  #  $link_image{"edit_entry"}   = http://stat.livejournal.com/img/btn_edit.gif                                   #
  #                                                                                                               #
  # Edit Tags:                                                                                                    # 
  #  $link_url{"edit_tags"}      = http://www.livejournal.com/edittags.bml?journal=exampleusername&itemid=256     #
  #  $link_caption{"edit_tags"}  = Edit Tags                                                                      #
  #  $link_image{"edit_tags"}    = http://stat.livejournal.com/img/btn_edittags.gif                               #
  #                                                                                                               #
  # Add to Memories:                                                                                              # 
  #  $link_url{"mem_add"}        = http://www.livejournal.com/tools/memadd.bml?journal=exampleusername&itemid=256 #
  #  $link_caption{"mem_add"}    = Add to Memories                                                                #
  #  $link_image{"mem_add"}      = http://stat.livejournal.com/img/btn_memories.gif                               #
  #                                                                                                               #
  # If interentry:                                                                                                #
  #   Next Entry:                                                                                                 #
  #    $link_url{"nav_next"}     = http://www.livejournal.com/go.bml?journal=exampleusername&itemid=256&dir=next  #
  #    $link_caption{"nav_next"} = Next Entry                                                                     #
  #    $link_image{"nav_next"}   = http://stat.livejournal.com/img/btn_next.gif                                   #
  #################################################################################################################

  # 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} != "") {
      $linkbar = $linkbar + """<a href="$link_url{$link_key}">""";
      # if image url available, use it
      if($link_image{$link_key} != "") {
        $linkbar = $linkbar + """<img src="$link_image{$link_key}" alt="$link_caption{$link_key}" title="$link_caption{$link_key}" border="0" />""";
      } else {
        # else, just use text
        $linkbar = $linkbar + """$link_caption{$link_key}""";
      }
      # add a seperator
      $linkbar = $linkbar + """</a>$linkbar_seperator""";
    }
  }

  # hack off last seperator
  $linkbar = $linkbar->substr(0, $linkbar->length() - $linkbar_seperator->length());

  print $linkbar;
}

### Override the printing of entries. This affects the Recent/Friends/Day/Entry pages.
function print_entry(Page p, Entry e, Color bgcolor, Color fgcolor, bool hide_text) {
  # USER VARS
  var string   icon_pos             = "left";                   # position for userpic in entries
  var bool     show_recent_userpic  = $*show_entry_userpic;     # show userpic on recent  page?
  var bool     show_friends_userpic = true;                     # show userpic on friends page?
  var bool     show_day_userpic     = false;                    # show userpic on day     page?
  var bool     show_entry_userpic   = $*show_entrypage_userpic; # show userpic on entry   page?
  var bool     show_reply_userpic   = $*show_entrypage_userpic; # show userpic on reply   page?

  var bool     scroll_recent_entry  = true;  # scrolling entry on recent page?
  var bool     scroll_friends_entry = true;  # scrolling entry on friends page?
  var bool     scroll_day_entry     = true;  # scrolling entry on day page?
  var bool     scroll_entry_entry   = false; # scrolling entry on entry page?
  var bool     scroll_reply_entry   = true;  # scrolling entry on reply page?

  var string{} sec_urls             = {       # security images
                                       "public"    => "http://pics.livejournal.com/kunzite1/pic/000f5p4c",
                                       "protected" => "$*IMGDIR/icon_protected.gif",
                                       "private"   => "$*IMGDIR/icon_private.gif",
                                      };

  var string{} sec_alts             = {       # security captions
                                       "public"    => "[public post]",
                                       "protected" => "$*text_icon_alt_protected",
                                       "private"   => "$*text_icon_alt_private",
                                      };
  #/USER VARS

  # build id
  var string id = ($p.view == "friends" ? $e.journal.username : "item") + $e.itemid;
  $id = """<a name="$id" id="$id"></a>""";
  #/build id

  # build entry header and security
  var string entry_header = "";
  var string security     = $e.security != "" ? $e.security : "public";

  # normal entry header
  if($sec_urls{$security} != "") {
    $entry_header = $entry_header + """<img src="$sec_urls{$security}" alt="$sec_alts{$security}" title="$sec_alts{$security}" /> """;
  }
  $entry_header = $entry_header + $e.time->time_format();
  $entry_header = $entry_header + " ";
  $entry_header = $entry_header + ($e.new_day ? "<b>" : "");
  $entry_header = $entry_header + $e.time->date_format("long");
  $entry_header = $entry_header + ($e.new_day ? "</b>" : "");

  #/build entry header and security

  # use $id                  to print anchor string for entry
  # use $entry_header        to print_entry_header($entry_header);
  # use $e->print_metadata() to print metadata (mood/music/tags)
  # use $e.comments->print() to print comments (comment links)
  # use $e->print_linkbar()  to print linkbar  (edit entry/mem add/edit tags/tell friend/etc)
  # use $show_poster         to see if we're going to show poster/journal info
  # use $show_userpic        to see if we're going to show the userpic

  # build userpic and posterinfo
  # don't edit these
  var bool   show_poster  = ($p.view == "friends" or $p.journal.journal_type == "C"); # figure out if we're going to show poster info
  var bool   show_userpic = false;                                                    # figure out if we're going to show userpic
  var bool   scroll_entry = false;                                                    # figure out if we're going to make a scrolling entry
  var string padding_pos  = "";                                                       # set padding based upon icon pos
  var string icon_data    = "";                                                       # var for icon data
  $padding_pos            = (($icon_pos == "left") or ($icon_pos == "right")) ? (($icon_pos == "left") ? "right" : "left") : "";
  $icon_data              = "";
  $show_userpic           = (
                             defined $e.userpic and
                             (
                              (($p.view == "recent")  and $show_recent_userpic ) or
                              (($p.view == "friends") and $show_friends_userpic) or
                              (($p.view == "day")     and $show_day_userpic    ) or
                              (($p.view == "entry")   and $show_entry_userpic  ) or
                              (($p.view == "reply")   and $show_reply_userpic  )
                             )
                            );

  $scroll_entry           = (
                             (($p.view == "recent")  and $scroll_recent_entry ) or
                             (($p.view == "friends") and $scroll_friends_entry) or
                             (($p.view == "day")     and $scroll_day_entry    ) or
                             (($p.view == "entry")   and $scroll_entry_entry  ) or
                             (($p.view == "reply")   and $scroll_reply_entry  )
                            );
  var string scrolling = $scroll_entry ? " class=\"fixed\"" : "";

  # Print the anchor to be used in the page summary.
  print $id;
  
  # Print the header for the entry.
  print_entry_header($entry_header);

  """
  <table cellspacing="0" cellpadding="0" border="0" width="100%"$scrolling>
    <tr>
      <td width="1" class="dkLine"><img src="$*PALIMGROOT/component/clear.gif" width="1" height="1" alt="" border="0" /></td>
      <td class="entryHolderBg" width="100%">
        <table cellspacing="0" cellpadding="0" border="0" width="100%">
          <tr>""";

  # Check to see if we need to display a usericon and/or journal names, and if so, then print them
  # Cases - 1. We are viewing a friends page, so we need to display icons if they exist and journal/poster names
  #         2. We are viewing a recent/day/entry page, so we display only the icon if it exists and 
  #            the user has set recent userpics on.
  if ($show_poster or $show_userpic) { 
     # Start the table that will hold the icon and/or names
     $icon_data = $icon_data + """
            <td valign="top" style="padding-$padding_pos: 8px;">
              <table cellspacing="0" cellpadding="0" border="0" align="center">
                <tr>
                  <td><img src="$*PALIMGROOT/component/clear.gif" width="1" height="1" alt="" border="0" /></td>
                </tr>
     """;
     # Display the icon if it exists
     if ($show_userpic) { $icon_data = $icon_data + """
                <tr>
                  <td><img src="$*PALIMGROOT/component/clear.gif" width="1" height="2" alt="" border="0" /></td>
         """;
         if ($show_poster and $show_userpic) { 
            $icon_data = $icon_data + """<td><div style="padding-top: 3px; padding-left: 3px; padding-right: 3px; padding-bottom: 3px; background-color: $bgcolor;" align="center"><a href="$*SITEROOT/allpics.bml?user=$e.poster.username"><img border="0" src="$e.userpic.url" width="$e.userpic.width" height="$e.userpic.height" alt="$e.poster.name" title="$e.poster.name" style="border-color: $fgcolor;" /></a></div></td>""";
         } else {
            $icon_data = $icon_data + """<td align="center" class="userpic"><img border="1" src="$e.userpic.url" width="$e.userpic.width" height="$e.userpic.height" alt="" /></td>""";
         }
       $icon_data = $icon_data + """
                </tr>
     """; }
     # Display the journal and possibly poster name if we are viewing the friends page or any page on a community
     # This code will print the journal the entry was made on, and if the poster is different, will print the poster under it.
     # I made the names centered under the image, but if you want to keep them left aligned as in the original, then
     # remove the blue segments
     if ($show_poster) { $icon_data = $icon_data + """
                <tr>
                  <td><img src="$*PALIMGROOT/component/clear.gif" width="1" height="2" alt="" border="0" /></td>
                  <td align="center" class="ljuser">$e.journal""";
         if ($e.journal.username!=$e.poster.username) { $icon_data = $icon_data + """
           <div align="center" class="ljuser">$e.poster</div>""";
         } $icon_data = $icon_data + """</td>
                </tr>""";
     }
     $icon_data = $icon_data + """
              </table>
            </td>
  """; }
  #/build userpic and posterinfo

# if icon position is left, stick it here
if($icon_pos == "left") {
  print $icon_data;
}

  # Start the main entry text area
  """
            <td width="100%" valign="top">""";
  print_content_top();

  # If the subject is not empty, then print it followed by the line to seperate it from the entry text
  # You can modify the lines in maroon if you want to adjust the way your subject prints, but the other lines must remain as is.
  if ($e.subject!="") { """
              <div class="entryHeader">$e.subject</div>
              <div class="entryDash"><img src="$*PALIMGROOT/component/clear.gif" width="1" height="1" alt="" border="0" /></div>
            </td>
            <td width="1" class="medLine"><img src="$*PALIMGROOT/component/clear.gif" width="1" height="1" alt="" border="0" /></td>
          </tr>
          <tr>
            <td width="1" class="medLine"><img src="$*PALIMGROOT/component/clear.gif" width="1" height="1" alt="" border="0" /></td>
            <td class="entry">
  """; }

  # Place a <div> around entry text and metadata, compliant with scrolling entries tutorial.
  """<div class="scrollentry">""";

  # Print the entry text.
  $e->print_text();

  # print metadata
  print "<br /><br />";
  $e->print_metadata();

  # Close <div> around entry text and metadata.
  """</div>""";
  
  # Close off the entry text area
  print_content_bottom();

  # This is where the fun stuff is!
  # Now we begin the area underneath the entry that holds the comments, link, and entry related buttons.

  # First we print the comment links if the entry allows comments
  """
              <table width="100%">
                <tr>
                  <td width="50%" align="left" valign="center">
                    <div class="entryComments">"""; $e.comments->print(); """</div>
                  </td>
                  <td align="center" valign="center">""";
        # Then print a permanent link to the entry.
        # I have this because I have my journal set to display comment links with "?nc=XX" tacked onto the end,
        # and when I'm copying and pasting links, it's annoying to have there. Also, if you want a link to
        # an entry that has no comments yet, the only link that's shown by default is the reply to link, and that
        # that includes "?mode=reply" which is also annoying to have to remove.
        # Essentially this is here for convenience. If you don't want it, remove the blue segment.
        """
                    <div class="entryComments"><span style="white-space:nowrap;"><b>(&nbsp;<a href="$e.permalink_url" class="commentLinks">$*text_permalink</a>&nbsp;)<b></span></div>
                  </td>
                  <td width="50%" align="right" valign="center">""";
        # Then the entry related buttons
        """
                    <div class="entryComments">"""; $e->print_linkbar(); """</div>
                  </td>
                </tr>
              </table>
  """;

# if icon position is right, stick it here
if($icon_pos == "right") {
  print $icon_data;
  """
            </td>""";
}

# End the entry component and put a spacer after it so that entry components are seperated.
  """
          </tr>
        </table>""";
  print_system_box_bottom();
  """ <div><img src="$*PALIMGROOT/component/clear.gif" width="3" height="3" alt="" border="0"></div> """;

} # end of Function print_entry
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

  • 60 comments