altered version of masterslacker's "customizing the entries" tutorial.
pulled mood/music/tags and linkbar out of
print_entry()
and replaced them with print_metadata()
and print_linkbar()
then overrode those functions too.
# 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";
var string tags_joiner = ":";
var string tags_seperator = ", ";
var Link edit_tags = $this->get_link("edit_tags");
if ((size $.metadata > 0) or ((size $.tags > 0) and ($*tags_aware))){
var string currents = "";
foreach var string k ($.metadata){
var string text = $k;
var string val = $.metadata{$k};
if ($k == "mood"){
$text = $*text_meta_mood;
}
elseif ($k == "music") {
$text = $*text_meta_music;
}
if ($k == "mood" and defined $.mood_icon){
var Image i = $.mood_icon;
$val = "<img src='$i.url' width='$i.width' height='$i.height' align='middle' alt='' /> $val";
}
$currents = $currents + """<strong>$text</strong> $val<br />""";
}
if ((size $.tags > 0) and $*tags_aware) {
var int tcount = 0;
if($edit_tags.url != "") {
$tags_header = """<a href="$edit_tags.url">$tags_header</a>""";
}
$currents = $currents + """<strong>$tags_header$tags_joiner</strong> """;
foreach var Tag t ($.tags) {
$currents = $currents + """<a rel="tag" href="$t.url">$t.name</a>""";
$tcount++;
if ($tcount != size $.tags) { $currents = $currents + $tags_seperator; }
}
}
println "$currents";
}
}
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 #
#################################################################################################################
# replace images with pretty component ones
# unfortunately, there aren't any for the prev/next links
$link_image{"edit_entry"} = $*edit_img;
$link_image{"edit_tags"} = $*tags_img;
$link_image{"mem_add"} = $*mem_img;
$link_image{"tell_friend"} = $*tellfriend_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} != "") {
$print = $print + """<img 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 seperator
$print = $print + "</a>$link_seperator";
}
}
# hack off last seperator
$print = $print->substr(0, $print->length() - $link_seperator->length());
# we're done! let's print it!
print $print;
}
### Override the printing of entries. This affects the Recent/Day pages, Friends pages, and Entry pages.
function print_entry(Page p, Entry e, Color bgcolor, Color fgcolor, bool hide_text) {
# Print the anchor to be used in the page summary.
if ($p.view=="friends") {
"""<a name="$e.journal.username$e.itemid"></a>""";
} else { # for recent, day, entry pages.
"""<a name="item$e.itemid"></a>""";
}
# Print the header for the entry. It prints in the default form "[<icon> ]<time> <date>" where:
# <icon> is the security icon (ie. lock if protected, eye if private, or none if public)
# <time> is in the default time format (eg: 03:46 am)
# <date> is bold and in the "long" format (eg: November 25th, 2003)
# The ordering can be adjusted however needed, and you can also modify the formats that date and time print in.
# For specifications of available formats or how to construct
# your own formats, you can see: http://www.livejournal.com/doc/s2/siteapi.core1.html#siteapi.core1.dateformats
var string entry_header = "";
if(defined $e.security_icon) {
$entry_header = $entry_header + $e.security_icon + " ";
}
$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>" : "");
print_entry_header($entry_header);
"""
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td width="1" class="dkLine"><img src="http://stat.livejournal.com/palimg/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.
# The code in maroon is the logic to decide whether or not to show the userpics. You can modify it as you see fit.
if ($p.view=="friends" or ($*show_entry_userpic and defined $e.userpic) or $e.journal.journal_type=="C") {
# Start the table that will hold the icon and/or names
"""
<td valign="top" style="padding-right: 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 (defined $e.userpic) { """
<tr>
<td><img src="$*PALIMGROOT/component/clear.gif" width="1" height="2" alt="" border="0" /></td>
""";
# If we are on the friends view, then we want to print the extra border around the image that have the colors
# which are custom defined. If you don't like the colors or the border on the friends view, then you can just
# remove the blue segments. By default the recent/day/entry pages have a border around the usericons. If a user
# has a non-rectangular image, this may look strange, so you can replace the 1 with a 0 to remove the border.
#
if ($p.view=="friends") {
""" <div style="padding-top: 3px; padding-left: 3px; padding-right: 3px; padding-bottom: 3px; background-color: """; print $bgcolor.as_string; """ ;" 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: """; print $fgcolor.as_string; """ ;" /></a>
</div> """;
} else {
""" <td align="center" class="userpic"><img border="1" src="$e.userpic.url" width="$e.userpic.width" height="$e.userpic.height" alt="" /></td> """;
}
"""
</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 ($p.view=="friends" or $e.journal.journal_type=="C") { """
<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) {"""
<div align="center" class="ljuser">$e.poster</div>""";
} """
</td>
</tr>""";
}
"""
</table>
</td>
"""; }
# 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">
"""; }
# Print the entry text.
""" $e.text """;
if ((size $e.metadata > 0) or ((size $e.tags > 0) and ($*tags_aware))){
"<br /><br />";
$e->print_metadata();
}
# 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.
"""
<table width="100%">
<tr>
<td width="50%" align="left" valign="center">
<div class="entryComments">
""";
# First we print the comment links if the entry allows comments
if ($e.comments.enabled) {
$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>( <a href="$e.permalink_url" class="commentLinks">$*text_permalink</a> )<b></span></div>
</td>
<td width="50%" align="right" valign="center">""";
# Then the entry related buttons
"""<div class="entryComments">
""";
# The easiest way to do this, which will work for all account types, is as follows, and will display actual buttons.
# If you'd like text instead of buttons, then remove the following line in blue, decomment the lines in pink,
# and edit as you see fit. Note that using the print_linkbar function will also add next and previous buttons to the
# Entry page (with comments), and I've reflected that in the pink lines below.
$e->print_linkbar();
# var Link prevlink = $e->get_link("nav_prev");
# if ($p.view=="entry" and defined $prevlink and $prevlink.url!="") { """<a href="$prevlink.url"><img border='0' width="$prevlink.icon.width" height="$prevlink.icon.height" alt="" src="$prevlink.icon.url" /></a>"""; }
# var Link editlink = $e->get_link("edit_entry");
# if (defined $editlink and $editlink.url!="") { """<a href="$editlink.url"><img border='0' width="$editlink.icon.width" height="$editlink.icon.height" alt="" src="$editlink.icon.url" /></a>"""; }
# var Link edittagslink = $e->get_link("edit_tags");
# if (defined $edittagslink and $edittagslink.url!="") { """<a href="$edittagslink.url"><img border='0' width="$edittagslink.icon.width" height="$edittagslink.icon.height" alt="" src="$edittagslink.icon.url" /></a>"""; }
# var Link memlink = $e->get_link("mem_add");
# if (defined $memlink and $memlink.url!="") { """<a href="$memlink.url"><img border='0' width="$memlink.icon.width" height="$memlink.icon.height" alt="" src="$memlink.icon.url" /></a>"""; }
# var Link nextlink = $e->get_link("nav_next");
# if ($p.view=="entry" and defined $nextlink and $nextlink.url!="") { """<a href="$nextlink.url"><img border='0' width="$nextlink.icon.width" height="$nextlink.icon.height" alt="" src="$nextlink.icon.url" /></a>"""; }
"""
</div>
</td>
</tr>
</table>
""";
# End the entry component and put a spacer after it so that entry components are seperated.
"""
</td>
</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