in response to
thepixieinside's
s2tranquility2 post.
# tell the system to not auto-magically add tags to entry text
set tags_aware = true;
# add colons to mood/music
set text_meta_location = "location:";
set text_meta_mood = "mood:";
set text_meta_music = "music:";
function Entry::print_metadata() {
var string tags_header = "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 = ""; # html for opening of currents container
var string currents_close = ""; # 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 = """"""; # html for opening of metadata label
var string meta_label_close = """ """; # html for closing of metadata label
var string meta_val_open = ""; # html for opening of metadata value
var string meta_val_close = """
"""; # 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 = """
$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 = """
$tags_header""";
}
# 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 + """
$t.name""";
$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 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 #
#################################################################################################################
# disable pictures
$link_image{"edit_entry"} = "";
$link_image{"edit_tags"} = "";
$link_image{"mem_add"} = "";
$link_image{"nav_prev"} = "";
$link_image{"nav_next"} = "";
# 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 + """
""";
# 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;
}
# -------------------------------
# display an entry (all views )
# -------------------------------
function print_entry ( Page p, Entry e ) {
# ideally, this would be the same as the seperator in Entry::print_linkbar()
var string link_sep = " | ";
var string interentry = "";
# get date/time
var string datetime;
$datetime = $e.time->date_format($*date_format) + " | " + $e.time->time_format($*time_format);
# get subject
var string subject = $e.subject != "" ? $e.subject : """$*text_nosubject""";
# get any extra user info (if posting to community, etc)
var string poster = "";
var string userpic = "";
var bool show_recent_userpic = true;
var bool show_friends_userpic = true;
var bool show_day_userpic = true;
var bool show_entry_userpic = true;
var bool show_reply_userpic = true;
var bool 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))
)
);
if ( $p.view == "friends" or $p.journal_type == "C" or $e.poster.username != $e.journal.username ) {
if ( $e.poster.username != $e.journal.username ) {
$poster = "$e.poster in $e.journal";
} else {
$poster = $e.poster->as_string();
}
$poster = "posted by: $poster";
}
if ($show_userpic) {
$userpic = """
""";
}
# print the entry now:
"""
""";
# print icon (if needed)
if ( $userpic != "" ) {
"""
$userpic""";
}
"""
""";
if ( $e.security != "" ) {
$e.security_icon->print();
" ";
}
"$subject
";
var bool show_interentry = ($p.view == "entry" or $p.view == "reply");
if($show_interentry) {
var Link nav_prev = $e->get_link("nav_prev");
var Link nav_next = $e->get_link("nav_next");
var string text = "";
if($nav_prev.url != "") {
$text = "« previous entry";
$interentry = $interentry + """
$text""";
}
if($nav_next.url != "") {
$text = "next entry »";
if($interentry != "") {
$interentry = $interentry + $link_sep;
}
$interentry = $interentry + """
$text""";
}
if($interentry != "") {
$interentry = $interentry + "
";
}
}
"""
$interentry
$datetime
""";
$e->print_metadata();
if ( $poster != "" ) {
"""
$poster""";
}
"""
""";
"""
"""; $e->print_text(); """""";
"""
""";
"""
$*text_permalink""";
print $link_sep;
$e.comments->print();
if($e.comments.enabled) {
print $link_sep;
}
$e->print_linkbar();
"""
""";
}