?

Log in

No account? Create an account
[theme] - [boxer] - [k1ified print_entry] - S2 Layers [entries|archive|friends|userinfo]
S2 Layers

[ website | advanced customization ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Links
[Links:| how to post tags page ]
[affiliated communities| fblayers ]

[theme] - [boxer] - [k1ified print_entry] [Oct. 9th, 2005|12:00 am]
S2 Layers

s2layers

[kunzite1]
[Tags|, , , , , , ]

# add tags, alter mood/music cuz i removed printing of the : in Entry::print_metadata();
set tags_aware         = true;
set text_meta_location = "Current Location:";
set text_meta_mood     = "Current Mood:";
set text_meta_music    = "Current Music:";

function Entry::print_metadata() {
  var string tags_header         = "Current Tags"; # text for tags header,    "Current Tags"
  var string tags_joiner         = ":";            # text for tags joiner,    ":"
  var string tags_sep            = ", ";           # text for tags separator, ", "
  var bool   show_edit_tags_link = false;          # set to true if you want edit tags link as tags header

  var string currents_open       = """<div class="metadata">"""; # html for opening of currents container
  var string currents_close      = """</div>"""; # html for closing of currents container

  var bool   loc_after_mood      = false;               # set to true to print location after mood
  var bool   vanilla_loc         = false;               # set to true to delinkify location

  var string meta_label_open     = """<strong>""";   # html for opening of metadata label
  var string meta_label_close    = """</strong> """; # html for closing of metadata label
  var string meta_val_open       = "";               # html for opening of metadata value
  var string meta_val_close      = """<br />""";     # html for closing of metadata value

  var Link   edit_tags           = $this->get_link("edit_tags"); # helper var to see if remote user can edit tags

  if ((size $.metadata > 0) or ((size $.tags > 0) and ($*tags_aware))){
    if($.metadata{"mood"} == "" and $loc_after_mood) {
      # if we're printing loc after mood but we have no mood, set loc_after_mood to false
      $loc_after_mood = false;
    }
    var string currents = "";             # make var for printing
    $currents           = $currents_open; # add opening of currents container

    foreach var string k ($.metadata){  # step thru metadata
      var string text = $k;             # set text to key
      var string val  = $.metadata{$k}; # get val
      if ($k == "mood"){                # if mood, set text to mood property
        $text = $*text_meta_mood;
        if (defined $.mood_icon){       # if we have a mood icon, add it
          var Image i = $.mood_icon;
          $val        = """<img src="$i.url" width="$i.width" height="$i.height" align="middle" alt="$val" title="$val" /> $val""";
        }
      } 
      elseif ($k == "music") {          # if music, set text to music property
        $text = $*text_meta_music;
      } elseif ($k == "location") {     # if location, set text to loc variable
        $text = $*text_meta_location;
        if($vanilla_loc) {              # if vanilla loc, striphtml() it
          $val = striphtml($val);
        }
      }
      if(not ($k == "location" and $loc_after_mood)) {
        # if we're doing loc right now and printing loc after mood, skip it
        # if we're doing loc right now and we're not printing loc after mood, print it now
        # if we're not doing loc right now, print this piece of meta

        # add the meta
        $currents = $currents + """$meta_label_open$text$meta_label_close$meta_val_open$val$meta_val_close""";
      }

      if($k == "mood" and $loc_after_mood) {
        # if we just now did the mood and we're printing loc after mood, print the loc
        $k    = "location";           # set meta key to "location"
        $text = $*text_meta_location; # set text to loc variable
        $val  = $.metadata{$k};       # get val

        # if we have a loc, do stuff
        if($val != "") {

          # if vanilla loc, striphtml() it
          if($vanilla_loc) {
            $val = striphtml($val);
          }

          # add the meta
          $currents         = $currents + """$meta_label_open$text$meta_label_close$meta_val_open$val$meta_val_close""";
        }
      }
    }
    if ((size $.tags > 0) and $*tags_aware) {
      var string k      = "tags"; # set key to "tags"

      var int tcount = 0; # set counter for tags
      if($edit_tags.url != "" and $show_edit_tags_link) { # if remote user can edit tags, let's give them a link
        $tags_header = """<a href="$edit_tags.url">$tags_header</a>""";
      }

      # add text, open val container
      $currents = $currents + """$meta_label_open$tags_header$tags_joiner$meta_label_close$meta_val_open""";

      # build tag list
      foreach var Tag t ($.tags) {
        $currents = $currents + """<a rel="tag" href="$t.url">$t.name</a>""";
        $tcount++;

        # if we haven't hit the last tag, add a separator
        if ($tcount != size $.tags) { $currents = $currents + $tags_sep; }
      }

      # close val container
      $currents = $currents + $meta_val_close;
    }

    # close currents container
    $currents = $currents + $currents_close;

    # print currents
    println "$currents";
  }
}

function CommentInfo::print_readlink() {
  var string img_url    = $*comment;
  var int    img_width  = 20;
  var int    img_height = 21;
  var bool   img_count  = true;

  if($.show_readlink) {
    var Page p      = get_page();
    var string url  = $.read_url;
    var string text = get_plural_phrase($.count, "text_read_comments" + ($p.view == "friends" ? "_friends" : ""));
    if($.screened) {
      $text = $text + " " + $*text_month_screened_comments;
    }

    """<span class="icon">""";

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

function CommentInfo::print_postlink() {
  var string img_url    = $*leave_comment;
  var int    img_width  = 20;
  var int    img_height = 21;

  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;
    }

    """<span class="icon">""";

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

function CommentInfo::print() {
  var string text_comment_divider = "";

  if($.show_readlink) {
    $this->print_readlink();
    if($.show_postlink) {
      print $text_comment_divider;
    }
  }
  if($.show_postlink) {
    $this->print_postlink();
  }
}

function Entry::print_linkbar() {
  var string   link_seperator = ""; # seperator for links

  # 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 Page   p               = get_page();                                 # page handle to determine interentry
  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             = $this->get_link("nav_prev");
    $link_url{"nav_prev"}     = $prev.url;
    $link_caption{"nav_prev"} = $prev.caption;
    $link_image{"nav_prev"}   = $prev.icon.url;

    # get next entry link information
    var Link next             = $this->get_link("nav_next");
    $link_url{"nav_next"}     = $next.url;
    $link_caption{"nav_next"} = $next.caption;
    $link_image{"nav_next"}   = $next.icon.url;
  }

  # 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
  }
  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.livejournal.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                                   #
  #################################################################################################################

  $link_image{"mem_add"}     = $*memories;
  $link_image{"edit_entry"}  = $*edit;
  $link_image{"edit_tags"}   = $*edit;
  $link_image{"tell_friend"} = $*mail;

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

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

  # we're done! let's print it!
  print $print;
}

function print_entry (Page p, Entry e, Color bgcolor, Color fgcolor, bool hide_text) {
  var int entry_page_width = $*page_width;
  var int entry_half_width = $entry_page_width / 2;
  var bool userpic_view = false;

  if($p.view == "friends" or $p.journal_type == "C" or $e.poster.username != $e.journal.username or $*show_entry_userpic) {
    $userpic_view = true;
  } 

  if($p.view != "friends" and $*show_entry_userpic) {
    $bgcolor = $*entry_bg;
    $fgcolor = $*entry_font;
  }
                  

  if($userpic_view) {
    var string url    = $e.journal->base_url();
    var string url2   = $e.poster->base_url();
    $entry_page_width = $*page_width - 122;
    $entry_half_width = $entry_page_width / 2;
    """
    <table cellspacing="0" cellpadding="0" border="0" width="$*page_width" class="new">
      <tr>
        <td valign="top" width="120" style="background-color: $bgcolor; color: $fgcolor; text-weight: bold;" align="center">
    """;
    if($e.journal.username != $e.poster.username) {
      """
          <a href="$url2/" style="color: $fgcolor; text-decoration: none;">$e.poster.username</a>:<br />""";
    }
    """
          <a href="$url/" style="color: $fgcolor; text-decoration: none;">$e.journal.username</a>""";
    if($e.userpic) {
      """<br />
          <img src="$e.userpic.url" width="$e.userpic.width" height="$e.userpic.height" border="0" alt="$e.journal.username" title="$e.journal.username">""";
    }
    """<br />
          <a href="$*SITEROOT/userinfo.bml?user=$e.journal.username" style="color: $fgcolor; text-decoration: none;">$e.journal.name</a>
        </td>
        <td>
          <img src="$*PALIMGROOT/boxer/clear.gif" width="2" height="1" alt="" border="0">
        </td>
        <td valign="top" class="entry">
    """;
  }

  """
          <!-- BEGIN ENTRY -->
          <table cellspacing="0" cellpadding="0" border="0" width="$entry_page_width" """;
  if($userpic_view == false) {
    print """ class="new" """;
  }
  """>
            <tr>
              <td class="entry">""";
  if ($e.security) {
    """
                <div style='padding-left: 5px;'>$e.security_icon</div>""";
  }
  """
              </td>
              <td class="entry" align="right">
                <table cellspacing="0" cellpadding="0" border="0" width="$entry_half_width">
                  <tr>
                    <td class="bgcolor" width="1"><img src="$*PALIMGROOT/boxer/clear.gif" alt="" width="1" height="1" border="0"></td>
                    <td align="right" class="date" width="$entry_half_width">""";
  print $e.time->date_format($*my_date);
  print " " + $e.time->time_format();
  """
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2" class="bgcolor" width="1"></td>
                  </tr>
                </table>
              </td>
            </tr>
            <tr>
              <td class="entry" colspan="2" align="left">
                <div class="entrycontent">""";
  if($e.subject) {
    """
                  <div><b>$e.subject</b></div><br />""";
  }
  if (not $hide_text) { print "<div>"; $e->print_text(); "</div><br />"; $e->print_metadata(); }
  """
                </div>
                <p class="entrycontent">""";
  $e.comments->print();
  """<span class="icon">"""; $p->print_reply_link({"target" => "topcomments", "reply_url" => $e.comments.post_url, "img_url" => $*leave_comment, "img_width" => "20", "img_height" => "21", "img_align" => "middle", "alt" => "Reply", "title" => "Reply"}); "</span>";

  $e->print_linkbar();
                                             
  $p->print_reply_container({"target"=>"topcomments"});
  """
                </p>
              </td>
            </tr>
          </table>
          <!-- END ENTRY -->
  """;
  if($userpic_view) {
    """
        </td>
      </tr>
    </table>
    """;
  }
}
linkReply

Comments:
[User Picture]From: xevinx
2005-10-09 10:09 am (UTC)
why was that dude's code so bad to begin with?!
(Reply) (Thread)
[User Picture]From: kunzite1
2005-10-09 03:45 pm (UTC)

not a clue! XD

and the additions that the guys are making? they don't know what they're doing either. >.<
(Reply) (Parent) (Thread)
[User Picture]From: oryssein
2006-07-19 05:59 am (UTC)

Doubled/Outdated Icons?

Um, I know that the stupid end-user questions are universally reviled and everything, but when I copy and paste this into my Boxer layer, I end up with a messed-up linkbar, which features two identical Reply icons and the old Edit Tags icon, which has since been replaced with a better version by whomever is in charge of layout icons at LiveJournal.

I've tried to fix this myself, but as I don't know what I'm doing, I mess it up and either break the function or call up those odd-looking old standard LJ icons with grey backgrounds. I don't think even I am capable of messing up a copy & paste, so I'm wondering if maybe this isn't a problem with the function? Or maybe a stupidly obvious end-user mistake?

At any rate, thank you for providing the function to begin with (I'm using it in order to use the 'metadata to the left' code, which does not appear to work with the default Boxer layout).
(Reply) (Thread)
[User Picture]From: kunzite1
2006-07-24 10:41 pm (UTC)

Re: Doubled/Outdated Icons?

change the 2nd $*edit to $*tags

not sure about the double reply icon issue.
(Reply) (Parent) (Thread)
[User Picture]From: oryssein
2006-07-25 06:24 am (UTC)

Re: Doubled/Outdated Icons?

Thanks so much! I had no idea it was such a simple change.

I got rid of the extra reply icon by randomly copying out pieces and then trying the function. So I don't really know how I did it. Maybe it was just a singular problem on my Journal, anyway.

Thanks again for the help.
(Reply) (Parent) (Thread)