in response to
nice_cup_of_tea's
s2styles post.
layerinfo "type" = "user";
class MyUtils {
function lay_make_icon (EntryLite el) : string;
function lay_make_id (EntryLite el) : string;
function num_comments_in_thread (Comment[] comments) : int;
function lay_make_comment_count (EntryLite el) : string;
function lang_user_wrote_summary(EntryLite el) : string;
}
function MyUtils::lay_make_icon(EntryLite el) : string {
if($el isa Comment) {
var Comment c = $el as Comment;
return (defined $c.subject_icon) ? $c.subject_icon->as_string() : "";
}
if($el isa Entry) {
var Entry e = $el as Entry;
return (defined $e.security_icon) ? $e.security_icon->as_string() : "";
}
return "";
}
function MyUtils::lay_make_id(EntryLite el) : string {
if($el isa Comment) {
var Comment c = $el as Comment;
return "t" + $c.talkid;
}
if($el isa Entry) {
var Entry e = $el as Entry;
return "$e.journal.username$e.itemid";
}
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;
}
function MyUtils::lay_make_comment_count(EntryLite el) : string {
var string return = "";
if($el isa Comment) {
var Comment c = $el as Comment;
if(size $c.replies) {
$return = "[+" + $this->num_comments_in_thread($c.replies) + "]";
}
}
if($el isa Entry) {
var Entry e = $el as Entry;
if(($e.comments.count > 0) or $e.comments.screened) {
$return = "[+$e.comments.count]";
}
}
return $return;
}
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." {
var UserLite poster = $e.poster;
var UserLite journal = $e.journal;
var string icon = $this->lay_make_icon($e);
var string subject = $e.subject != "" ? $e->get_plain_subject() : """$*text_nosubject""";
var string id = $this->lay_make_id($e);
var string comments = $this->lay_make_comment_count($e);
var Page p = get_page();
var bool iscomment = $e.depth > 0;
var bool showposter = ($p.view == "friends") or (not $e.poster->equals($e.journal));
var bool showjournal = ($p.view == "friends" and (not $e.poster->equals($e.journal)));
var string return = "-";
$return = $return + $icon;
if($showjournal) {
$return = $return + $journal->as_string() + " :: ";
}
if ($showposter or $iscomment) {
if (defined $poster) {
$return = $return + $poster->as_string();
} else {
$return = $return + """$*text_poster_anonymous""";
}
$return = $return + " : ";
}
$return = $return + """
$subject $comments\n""";
return $return;
}
function MonthPage::lay_sidebar_navigation() {
var string prev_text = $.prev_date->date_format("%%month%% %%yyyy%%");
var string prev_url = $.prev_url;
var string next_text = $.next_date->date_format("%%month%% %%yyyy%%");
var string next_url = $.next_url;
""">
$prev_text>
$next_text""";
}
function DayPage::lay_sidebar_navigation() {
var string prev_text = $.prev_date->date_format("long");
var string prev_url = $.prev_url;
var string next_text = $.next_date->date_format("long");
var string next_url = $.next_url;
""">
$prev_text>
$next_text""";
}
function EntryPage::lay_sidebar_navigation() {
var Entry e = $.entry;
var Link prev = $e->get_link("nav_prev");
var Link next = $e->get_link("nav_next");
""">
$prev.caption>
$next.caption""";
}
function Page::print_entry (Entry e) {
var MyUtils mu = new MyUtils;
var string id = $mu->lay_make_id($e);
"""""";
print_entry($this, $e, null Color, null Color, false);
}
function FriendsPage::print_entry (Entry e) {
var MyUtils mu = new MyUtils;
var string id = $mu->lay_make_id($e);
"""""";
var Friend f = $.friends{$e.journal.username};
print_entry($this, $e, $f.bgcolor, $f.fgcolor, false);
}
function MonthPage::print_body {
"\n";
foreach var MonthDay d ($.days) {
if ($d.has_entries) {
var string id = "day$d.day";
"
";
print lang_ordinal($d.day);
"\n";
$d->print_subjectlist();
"\n";
}
}
"\n";
}
function YearPage::print_body {
"
$.year
\n";
foreach var YearMonth m ($.months) {
if($m.has_entries) {
var string id = "month$m.month";
"""""";
$this->print_month($m);
}
}
}
function print_sidebar(Page p) {
var string title = $p->title();
var string userpic;
var Image up_img = $p.journal.default_pic;
if (defined $up_img) {
$userpic = """
""";
}
var string website_name = $p.journal.website_name ? $p.journal.website_name : $*text_website_default_name;
var string website;
if ($p.journal.website_url != "") {
$website = """>
$website_name""";
}
var string links;
foreach var string v ($p.views_order) {
$links = "$links> " + ($p.view == $v ?
lang_viewname($v) :
"
"+lang_viewname($v)+""
) + "
\n";
}
# create vars to help with creating sidebar "boxes"
var string header = "";
var string header_one = "
";
var string header_two = "
";
var string content = "";
var string content_one = "
";
var string content_two = "
";
# Table Wrapper
"""
""";
# Title
var string subtitle = $p.global_subtitle != "" and $p.view != "friends" ? """
$p.global_subtitle""" : "";
"""
$title
$subtitle
""";
# Links
"""
$links
$website
""";
$p->lay_sidebar_navigation();
"""
""";
# Userpic
if($userpic != "") {
"""
$userpic
""";
}
# Link List
if (size $p.linklist > 0 and $*linklist_support) {
if (not $p.linklist[0].is_heading) {
"""
Links
""";
}
$p->print_linklist();
}
var MyUtils mu = new MyUtils;
# set header
$header = "";
# set content
$content = "";
if($p isa RecentPage) {
var RecentPage rp = $p as RecentPage;
$header = $rp.view == "recent" ? "Recent" : "Friends";
foreach var Entry e ($rp.entries) {
$content = $content + $mu->lang_user_wrote_summary($e);
}
}
if($p isa YearPage) {
var YearPage yp = $p as YearPage;
$header = $yp.year + "";
foreach var YearMonth m ($yp.months) {
if($m.has_entries) {
$content = $content + """-
""" + $*lang_monthname_long[$m.month] + "\n";
}
}
}
if($p isa MonthPage) {
var MonthPage mp = $p as MonthPage;
$header = $mp.date->date_format("%%month%% %%yyyy%%");
foreach var MonthDay d ($mp.days) {
var int size = size($d.entries);
if($size) {
$content = $content + """-
""" + lang_ordinal($d.day) + """ [$size]\n""";
}
}
}
if($p isa DayPage) {
var DayPage dp = $p as DayPage;
$header = $dp.date->date_format("long");
foreach var Entry e ($dp.entries) {
$content = $content + $mu->lang_user_wrote_summary($e);
}
}
if($p isa EntryPage) {
var EntryPage ep = $p as EntryPage;
$header = $ep.entry.subject != "" ? $ep.entry.subject : """$*text_nosubject""";
foreach var Comment e ($ep.comments) {
$content = $content + $mu->lang_user_wrote_summary($e);
}
}
# print sidebar "box"
print "$header_one$header$header_two$content_one$content$content_two";
# End Table
"""
""";
}