in response to
ravenshrinkery's
s2styles post.
# add colons to labels because it's silly to hard-code it in the function
set text_meta_location = "Current Location:";
set text_meta_mood = "Current Mood:";
set text_meta_music = "Current Music:";
class MyUtils {
function entrylite_make_comment_count(EntryLite el) : string;
function entrylite_make_icon (EntryLite el) : string;
function entrylite_make_id (EntryLite el) : string;
function lang_user_wrote_summary (EntryLite e ) : string;
function num_comments_in_thread (Comment[] comments) : int;
}
# make icon string for comments/entries
function MyUtils::entrylite_make_icon(EntryLite el) : string {
# if this is a Comment
if($el isa Comment) {
# return subject icon string, if it exists
var Comment c = $el as Comment;
return (defined $c.subject_icon) ? $c.subject_icon->as_string() : "";
}
# if this is an Entry
if($el isa Entry) {
# return security icon string, if it exits
var Entry e = $el as Entry;
return (defined $e.security_icon) ? $e.security_icon->as_string() : "";
}
return "";
}
# make id string for comments/entries
function MyUtils::entrylite_make_id(EntryLite el) : string {
# if this is a Comment
if($el isa Comment) {
# "t" [talkid]
var Comment c = $el as Comment;
return "t" + $c.talkid;
}
# if this is an Entry
if($el isa Entry) {
# [journal username][itemid number]
var Entry e = $el as Entry;
return "$e.journal.username$e.itemid";
}
return "";
}
# make comment count string for comments/entries
function MyUtils::entrylite_make_comment_count(EntryLite el) : string {
var string return = "";
# if this is a Comment
if($el isa Comment) {
var Comment c = $el as Comment;
# if the comment has replies, get the number of comments in this thread
if(size $c.replies) {
$return = "[+" + $this->num_comments_in_thread($c.replies) + "]";
}
}
# if this is an Entry
if($el isa Entry) {
var Entry e = $el as Entry;
# if there are comments present or screened comments, get number of comments on entry
if(($e.comments.count > 0) or $e.comments.screened) {
$return = "[+$e.comments.count]";
}
}
return $return;
}
function MyUtils::num_comments_in_thread (Comment[] comments) : int {
var int total = 0;
foreach var Comment c ($comments) {
$total = $total + 1;
if (size $c.replies > 0) {
$total = $total + $this->num_comments_in_thread($c.replies);
}
}
return $total;
}
# Returns text describing that the user wrote something, for use in summary navbar box. i18nc layers should override this.
function MyUtils::lang_user_wrote_summary(EntryLite e) : string "Returns text describing that the user wrote something, for use in summary navbar box. i18nc layers should override this." {
# get poster, journal, icon, subject, id, comment count
var UserLite poster = $e.poster;
var UserLite journal = $e.journal;
var string icon = $this->entrylite_make_icon($e);
var string subject = $e.subject != "" ? $e->get_plain_subject() : """$*text_nosubject""";
var string id = $this->entrylite_make_id($e);
var string comments = $this->entrylite_make_comment_count($e);
# get page handle
var Page p = get_page();
var bool showjournal = (not $e.poster->equals($e.journal) and (not $e isa Comment));
var bool showposter = (not $p.journal->equals($e.journal) and ($p.view != "day"));
var string return = "";
# add icon
$return = $return + $icon;
# if we're showing the journal name, add journal name and " - "
if($showjournal) {
$return = $return + $journal->as_string() + " - ";
}
# if we're showing the poster name or this is a Comment
if ($showposter or ($e isa Comment)) {
# if we have a poster, add the poster's name
# else, add """$*text_poster_anonymous"""
if (defined $poster) {
$return = $return + $poster->as_string();
} else {
$return = $return + """$*text_poster_anonymous""";
}
$return = $return + " - ";
}
if($p.view == "day") {
$return = $return + $e.time->time_format() + " - ";
}
# put it all together
$return = $return + """
$subject $comments""";
return $return;
}
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 = ""; # 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
# if you need data specific to the meta to be in these strings you'll have to set those individually down further
# one example is provided with meta_label_open
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
# in this layout, each piece of meta gets its own class
$meta_label_open = """
""";
# 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);
}
# in this layout, each piece of meta gets its own class
$meta_label_open = """
""";
# 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"
# in this layout, each piece of meta gets its own class
$meta_label_open = """
""";
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 print_entry_short (Page p, Entry e, Color bgcolor, Color fgcolor) {
var string subject = $e.subject ? $e.subject : """$*text_nosubject""";
var string datetime = $e.time->date_format("med") + " @ " + $e.time->time_format();
"""
» $subject """;
$e->print_text();
"""
$datetime""";
$e.comments->print();
"""
""";
}
function print_entry_full (Page p, Entry e, Color bgcolor, Color fgcolor, bool hide_text) {
"""
""";
var string time = $p.view != "day" ? $e.time->date_format("med") + " @ " : "";
$time = $time + $e.time->time_format();
var string subject = $e.subject ? $e.subject : """$*text_nosubject""";
if ($e.security) {
$subject = "$e.security_icon $subject";
}
if ($subject) {
$subject = """$subject""";
}
var Link prev; var Link next;
if ($p.view == "entry") {
$prev = $e->get_link("nav_prev");
$next = $e->get_link("nav_next");
}
print_heading_bar("$prev $subject", "$time $next");
"""
""";
var bool showjournal = (not $e.poster->equals($e.journal)) or ($p.view == "friends");
var bool showposter = (not $e.poster->equals($e.journal)) and ($p.view == "friends");
var bool showuserpic = ($*show_entry_userpic and defined $e.userpic);
if (($showjournal or $showuserpic) and $p.view != "entry") {
"""
""";
if ($p.view == "friends") {
if ($showposter) {
print $e.poster->as_string() + ", posting in ";
}
print $e.journal->as_string() + "
";
if ($showuserpic) {
"""
""";
}
} elseif ($showposter) {
print $e.poster->as_string() + "
";
if (defined $e.userpic) {
"""
""";
}
} elseif (defined $e.userpic and $p.view != "entry") {
"""
""";
}
"""
""";
}
"""
""";
if (not $hide_text) {
$e->print_text();
$e->print_metadata();
}
$e.comments->print();
"""
""";
}
function Page::lay_sidebar_view_summary() : string {
var MyUtils mu = new MyUtils;
var Page p = $this;
var string[] links = [];
var string return = "";
# If the Page is a RecentPage
# Get the Page as a RecentPage
# Cycle through the entries while tossing them into an array
if ($p isa RecentPage) {
var RecentPage rp = $p as RecentPage;
foreach var Entry e ($rp.entries) {
$links[size $links] = $mu->lang_user_wrote_summary($e);
}
}
# If the Page is a YearPage
# Get the Page as a YearPage
# Cycle through the entries while tossing them into an array
if ($p isa YearPage) {
var YearPage yp = $p as YearPage;
if($*page_year_sortorder == "reverse") { $yp.months = reverse $yp.months; }
foreach var YearMonth ym ($yp.months) {
if($ym.has_entries) {
$links[size $links] = """
""" + $ym->month_format("long") + """""";
}
}
}
# If the Page is a MonthPage
# Get the Page as a MonthPage
# Cycle through the entries while tossing them into an array
if ($p isa MonthPage) {
var MonthPage mp = $p as MonthPage;
foreach var MonthDay md ($mp.days) {
if($md.has_entries) {
$links[size $links] = """
""" + $md.date->date_format("long") + """""";
}
}
}
# If the Page is a DayPage
# Get the Page as a DayPage
# Cycle through the entries while tossing them into an array
if ($p isa DayPage) {
var DayPage dp = $p as DayPage;
if($*page_day_sortorder == "reverse") { $dp.entries = reverse $dp.entries; }
foreach var Entry e ($dp.entries) {
$links[size $links] = $mu->lang_user_wrote_summary($e);
}
}
# If the Page is a EntryPage
# Get the Page as a EntryPage
# Cycle through the entries while tossing them into an array
if ($p isa EntryPage) {
var EntryPage ep = $p as EntryPage;
foreach var Comment c ($ep.comments) {
$links[size $links] = $mu->lang_user_wrote_summary($c);
}
}
if (size($links) > 0) {
foreach var string link ($links) {
$return = $return + "" + $link + "";
}
}
return $return;
}
function MonthPage::print_body {
"\n";
foreach var MonthDay d ($.days) {
if ($d.has_entries) {
var string id = $d.day + "";
$id = " id=\"$id\" name=\"$id\"";
"
";
print lang_ordinal($d.day);
"\n";
$d->print_subjectlist();
"\n";
}
}
"\n";
}