[theme] - [customizable linkbar]

Aug 06, 2005 09:16


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 #
#################################################################################################################

# alter data here
# $link_keyseq = ["mem_add", "edit_entry", "edit_tags"]; # change link order ["nav_prev", "edit_entry", "edit_tags", "mem_add", "nav_next"]
# $link_caption{"edit_entry"} = "edit entry"; # change caption
# $link_image{"edit_entry"} = ""; # set to "" to disable image, set to different url to print different image

# $link_keyseq[size($link_keyseq)] = "permalink"; # add a permalink to end of linkbar
# $link_url{"permalink"} = $.permalink_url;
# $link_caption{"permalink"} = $*text_permalink;
# $link_image{"permalink"} = "";

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

class entry, function print_linkbar, !all

Previous post Next post
Up