# -*-s2-*-

layerinfo type = "layout";
layerinfo name = "Magazine";
layerinfo redist_uniq = "magazine/layout";
layerinfo previews = "magazine/magazine.jpg";

propgroup colors {
  property Color main_bgcolor { 
      des = "Main Background color";
      s1color = "page_back";
  }
  property Color main_fgcolor {
      des = "Main text color";
      s1color = "page_text";
  }
  property Color sidebar_color {
      des = "Sidebar color"; 
      s1color = "stronger_back";
  }
  property Color headerbar_bgcolor { 
      des = "Headerbar background color";
      s1color = "strong_back";
  }
  property Color headerbar_fgcolor { 
      des = "Text color on headerbar"; 
      s1color = "strong_text";
  }
  property Color headerbar_bevel_color { 
      des = "Accent line color for headerbar"; 
      s1color = "stronger_back";
  }
  property Color highlight_bgcolor { 
      des = "Highlighting color for accented text";
      s1color = "weak_back";
  }
  property Color highlight_fgcolor { 
      des = "Highlighted text color"; 
      s1color = "weak_text";
  }
  property Color border_color { 
      des = "Color of borders"; 
      s1color = "weak_text";
  }
  property Color title_color  { 
      des = "Text color of top title"; 
      s1color = "page_text_title";
  }
  property Color meta_color { 
      des = "Text color of meta descriptions"; 
      s1color = "page_text_em";
  }
  property Color link_color { 
      des = "Text color of links"; 
      s1color = "page_link";
  }
  property Color vlink_color { 
      des = "Text color of visited links"; 
      s1color = "page_vlink";
  }
  property Color alink_color { 
      des = "Text color of active links"; 
      s1color = "page_alink";
  }
  property Color comment_bar_one_bgcolor {
      des = "Alternating background color for comment bars (one)";
  }
  property Color comment_bar_two_fgcolor {
      des = "Text color on alternating comment bars (one)";
  }
  property Color comment_bar_two_bgcolor {
      des = "Alternating background color for comment bars (two)";
  }
  property Color comment_bar_one_fgcolor {
      des = "Text color on alternating comment bars (two)";
  }
  property Color comment_bar_screened_bgcolor {
      des = "Background bar color for screened comments";
  }
  property Color comment_bar_screened_fgcolor {
      des = "Text color on background bar for screened comments";
  }
}
set main_bgcolor = "#ffffff";
set main_fgcolor = "#000000";
set sidebar_color = "#6666cc";
set headerbar_bgcolor = "#c0c0ff";
set headerbar_fgcolor = "#000000";
set headerbar_bevel_color = "#6666cc";
set highlight_bgcolor = "#eeeeff";
set highlight_fgcolor = "#000000";
set border_color = "#000000";
set title_color = "#8b1a1";
set meta_color = "#c00000";
set link_color = "#000050";
set vlink_color = "#500050";
set alink_color = "#ff00c0";
set comment_bar_one_bgcolor = "#c0c0ff";
set comment_bar_one_fgcolor = "#000000";
set comment_bar_two_bgcolor = "#eeeeff";
set comment_bar_two_fgcolor = "#000000";
set comment_bar_screened_bgcolor = "#dddddd";
set comment_bar_screened_fgcolor = "#000000";

propgroup presentation {
  property bool show_entry_userpic { 
      des = "Show the userpic on the journal entries? [Excludes friends page]"; 
  }
  property use page_recent_items;
  property use page_friends_items;
  property use use_shared_pic;
  property use view_entry_disabled;
  property bool show_entrynav_icons {
    des = "Toggle to show the next, memory, edit, etc icons on the entry view page";
  }
  property string page_background_image {
    des = "URL to an image to be used for the page background";
  }
  property use external_stylesheet;
}
set show_entry_userpic = false;
set view_entry_disabled = false;
set show_entrynav_icons = true;
set page_background_image = "";

propgroup text {
  property use text_post_comment;
  property use text_read_comments;
  property use text_post_comment_friends;
  property use text_read_comments_friends;
}

set tags_aware = true;

function Page::lay_skip_navigation() {}

function Page::lay_bottom_navigation() {}

function print_stylesheet ()
{
    print clean_url($*page_background_image) != "" ? "body { background-image: url($*page_background_image); }" : "";
    """HTML {
    border-left: 1cm solid $*sidebar_color; 
    padding: 1cm;
}
BODY {
    line-height: 1.3;
    margin: 0;
    background-color: $*main_bgcolor;
    color: $*main_fgcolor;
}
P {
    margin-top: 0;
    text-align: justify;
}
H1 {
    font: x-large Verdana, sans-serif; text-align: center;
    letter-spacing: -0.09em;
    color: $*title_color;
}
H2 {
    background-color: $*headerbar_bgcolor;
    color: $*headerbar_fgcolor;
    border-bottom: thin solid $*headerbar_bevel_color;
    font: normal 1.3em Georgia, serif;
}
H3 {
    color: $*highlight_fgcolor;
    font: medium sans-serif;
}
H3 SPAN {
    background-color: $*highlight_bgcolor;
    border-right: thin solid $*border_color;
    border-bottom: thin solid $*border_color;
    padding-right: 0.5ex; 
}
H3 EM {
    color: $*meta_color;
    font-style: normal;
}
.H3Holder {
    clear: both; 
    padding-left: 2ex;
    border-left: thin solid $*border_color;
    border-bottom: thin solid $*border_color;
    margin-bottom: 1em;
}
A:link {
    color: $*link_color;
}
A:visited {
    color: $*vlink_color;
}
A:active { 
    color: $*alink_color;
}
.Navigation {
    text-align: center;
    font-family: sans-serif;
}
.Comment {
    font-size: 0.7em;
    margin-top: -1em;
    text-align: right;
}
.Comment, .Current {
    margin-bottom: 1em; 
    clear: right;
}
.Picture {
    border-left: thin solid $*border_color;
    border-top: thin solid $*border_color;
    float: right;
    margin: 0 0 0.5em 0.5em;
    padding: 0.2em;
}
.Picture DIV { 
    text-align: center;
}
.Active {
    background-color: $*highlight_bgcolor;
}
ACRONYM {
    border-bottom: thin dashed $*border_color;
    cursor: help;
}
.Bottom {
    border-top: thin solid $*border_color;
    text-align: center;
}
.Empty {
    background-color: $*highlight_bgcolor;
}
.Month {
    margin-top: 1em;
}
.MonthHeader {
    color: $*headerbar_fgcolor;
    background-color: $*headerbar_bgcolor ! important;
    line-height: 1.5;
}
.Month TD {
    color: $*highlight_fgcolor;
    width: 14%;
    border: thin outset;
}
.Month TH {
    background-color: $*highlight_bgcolor;
    font-family: Verdana, sans-serif;
    border: thin outset;
}""";
}

function Page::print () {
    var string title = $this->title();

    """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n<html>\n<head>\n""";

    if ($*external_stylesheet) {
        println """<link rel="stylesheet" href="$.stylesheet_url" type="text/css" />""";
    } else {
        println """<style type="text/css">"""; print_stylesheet(); "</style>";
    }
    $this->print_head();

    """<title>$title</title>
  </head>
  <body>
    <h1>$title</h1>""";

    var string website_name = $.journal.website_name ? $.journal.website_name : $*text_website_default_name;
    var string website = ($.journal.website_url != "" ? "(<a href='$.journal.website_url'>$website_name</a>)" : "");

    var string links;
    foreach var string v ($.views_order) {
        $links = "$links(<span style='white-space: nowrap;'>" + ($.view == $v ?
                           "<span class='Active'>"+lang_viewname($v)+"</span>" :
                           "<a href='$.view_url{$v}'>"+lang_viewname($v)+"</a>") + ")</span>\n";
    }

    """<p class="Navigation">$links $website<br />""";
    $this->lay_skip_navigation();
    "</p>";

    $this->print_body();

    $this->lay_bottom_navigation();

    "</body></html>";
}

function print_entry (Page p, Entry e, Color bgcolor, Color fgcolor, bool hide_text)
{
    var string time = $e.time->time_format();
    var string userpic = (defined $e.userpic ? "<img src='$e.userpic.url' />" : "");
    if (($p.view != "entry" and $e.new_day) or $p.view == "entry")
    {
        "<h2>" + $e.time->date_format("med") + "</h2>";
    }
    "<div class='H3Holder'>";

    # Altposter / friends / lastn userpic
    if ($p.view == "friends" or
        $p.view == "entry" or 
        $*show_entry_userpic == true or
        $e.journal.username != $e.poster.username) 
    {
        "<div class='Picture' style='background-color: $bgcolor;'>";
        if ($p.view == "friends")
        {
            "<div><a href='";
            print $e.journal->base_url() + "/";
            "' style='color: $fgcolor;'><small>$e.journal.username</small></a></div>";
        }
        if ($*show_entry_userpic == true or $p.view == "friends" or $p.view == "entry") 
        {
            if (defined $e.userpic) { "<div><img src='$e.userpic.url' /></div>"; }
        }
        if ($e.journal.username != $e.poster.username) 
        {
            "<div><a href='";
            print $e.poster->base_url() + "/";
            "'>$e.poster.username</a></div>";
        }
        "</div>";
    }
    # Time / Subject / Security
    var string subject = ($e.subject != "" ? " - <em>$e.subject</em>" : "");
    "<h3><span>$time$subject</span> $e.security_icon</h3>";

    if ($p.view == "entry" and $*show_entrynav_icons)
    {
        print "<div style='text-align: center'>";
        $e->print_linkbar();
        print "</div>";
    }

    if (not $hide_text)
    {
        # Entry
        "<p>$e.text</p>";

        # Tags
        if ($e.tags) {
            var int tcount = 0;
            "<div class='ljtags'><strong>Tags:</strong> ";
            foreach var Tag t ($e.tags) {
                """<a rel="tag" href="$t.url">$t.name</a>""";
                $tcount++;
                if ($tcount != size $e.tags) { ", "; }
            }
            "</div>";
        }

        # Metadata
        if (size $e.metadata) {
            foreach var string k ($e.metadata) {
                "<div class='Currents'>";
                var string key = $k;
                var string val = $e.metadata{$k};
                if ($k == "mood") {
                    $key = $*text_meta_mood;
                } elseif ( $k == "music" ) {
                    $key = $*text_meta_music;
                }
                if ($k == "mood" and defined $e.mood_icon) {
                    var Image i = $e.mood_icon;
                    $val = "<img src='$i.url' width='$i.width' height='$i.height' align='absmiddle' alt='[mood icon]' /> $val";
                }
                "<div><strong>$key:</strong> $val</div>";
                "</div>";
            }
        }
    }

    # Comments
    $e.comments->print();
    "</div>";
}

function CommentInfo::print()
{
    if (not $.enabled) { return; }
    "<div class='Comment'>(";
    if ($.count > 0 or $.screened) {
        $this->print_readlink(); "&nbsp;|&nbsp;";
    }
    $this->print_postlink();
    ")</div>";
}

function Page::print_entry (Entry e) 
{
    print_entry($this, $e, null Color, null Color, false);
}

function RecentPage::lay_skip_navigation() 
{
    var int total = size $.entries;
    var string nav = "";
    if ($.nav.backward_url != "") {
        $nav = """<a href="$.nav.backward_url">Previous $total Entries</a>""";
    }
    if ($.nav.forward_url != "" and $.nav.backward_url != "") {
        $nav = "$nav&nbsp;|&nbsp;";
    }
    if ($.nav.forward_url != "") {
        $nav = """$nav<a href="$.nav.forward_url">Next $total Entries</a>""";
    }
    if ($nav != "") { print "Navigate: ($nav)"; }
}

function RecentPage::lay_bottom_navigation()
{
    "<p class='Bottom'>"; $this->lay_skip_navigation(); "</p>";
}

function RecentPage::print_body 
{
    foreach var Entry e ($.entries) {
        $this->print_entry($e);
    }
}

function FriendsPage::lay_skip_navigation() 
{
    var int total = size $.entries;
    var string nav = "";
    if ($.nav.backward_url != "") {
        $nav = """<a href="$.nav.backward_url">Previous $total Friends</a>""";
    }
    if ($.nav.forward_url != "" and $.nav.backward_url != "") {
        $nav = "$nav&nbsp;|&nbsp;";
    }
    if ($.nav.forward_url != "") {
        $nav = """$nav<a href="$.nav.forward_url">Next $total Friends</a>""";
    }
    if ($nav != "") { print "Navigate: ($nav)"; }
}

function FriendsPage::print_entry (Entry e) 
{
    var Friend f = $.friends{$e.journal.username};
    print_entry($this, $e, $f.bgcolor, $f.fgcolor, false);
}

function FriendsPage::print_body 
{
    foreach var Entry e ($.entries) {
        $this->print_entry($e);
    }
}

function YearPage::lay_skip_navigation ()
{
    $this->print_year_links();
}

function YearPage::lay_bottom_navigation() { }

function YearPage::print_body() {
    "<h2>$.year</h2>";
    foreach var YearMonth m ($.months) {
        $this->print_month($m);
    }
}

function YearPage::print_year_links ()
{
    "Navigate: ";
    foreach var YearYear y ($.years) {
        if ($y.displayed) {
            " (<span class='Active'>$y.year</span>) ";
        } else {
            " (<a href='$y.url'>$y.year</a>) ";
        }
    }
}

function YearPage::print_month(YearMonth m)
{
    if (not $m.has_entries) { return; }
    "<table class='Month'>";
    "<tr><th class='MonthHeader' colspan='7'>";
    "<a href='$m.url'>"; print $m->month_format(); "</a></th></tr>\n";
    "<tr>";
    foreach var int d (weekdays())
    {
        "<th>"+$*lang_dayname_short[$d]+ "</th>\n";
    }
    "</tr>";
    foreach var YearWeek w ($m.weeks)
    {
        $w->print();
    }
    "</table>\n";
}

function YearWeek::print() {
    "<tr valign='top'>";
    if ($.pre_empty) { "<td class='empty' colspan='$.pre_empty'></td></td>"; }
    foreach var YearDay d ($.days)
    {
        "<td>$d.day";
        if ($d.num_entries)
        {
            "<div align='center'><a href='$d.url'><strong>$d.num_entries</strong></a></div>";
        } else {
            "<br /><br />";
        }
        "</td>";
    }
    if ($.post_empty) { "<td class='empty' colspan='$.post_empty'></td></td>"; }
    "</tr>";
}

function DayPage::lay_skip_navigation()
{
    "Navigate: (<a href='$.prev_url'>Previous Day</a>&nbsp;|&nbsp;<a href='$.next_url'>Next Day</a>)";
}

function DayPage::lay_bottom_navigation() 
{
    """
<table style="border-top: thin solid $*headerbar_bevel_color;" width="100%">
  <tr>
    <td width="33%">&larr; <a href="$.prev_url">Previous day</a></td>
    <td width="34%" align="center">(<a href="$.base_url/calendar">Calendar</a>)</td>
    <td width="33%" align="right"><a href="$.next_url">Next day</a> &rarr;</td>
  </tr>
</table>
    """;
}

function DayPage::print_body ()
{
    if (not $.has_entries) {
        "<h2>"; print $.date->date_format("med"); "</h2>";
        print "<p>(No journal entries for this day.)</p>";
    } else {
        foreach var Entry e ($.entries) {
            $this->print_entry($e);
        }
    }
}

function EntryPage::print_body ()
{
        set_handler("unscreen_comment_#", [
                                           [ "style_bgcolor", "cmtbar#", "$*comment_bar_one_bgcolor", ],
                                           [ "style_color", "cmtbar#", "$*comment_bar_one_fgcolor", ],
                                           ]);
        set_handler("screen_comment_#", [
                                         [ "style_bgcolor", "cmtbar#", "$*comment_bar_screened_bgcolor", ],
                                         [ "style_color", "cmtbar#", "$*comment_bar_screened_fgcolor", ],
                                         ]);


    print_entry($this, $.entry, null Color, null Color, $.viewing_thread);
    if ($.entry.comments.enabled and $.comment_pages.total_subitems > 0)
    {
        $this->print_multiform_start();
        print "<h2>Comments:</h2><div style='margin-left: 30px;'>";
        if ($.comment_pages.total_subitems > 0) {
            $.comment_pages->print();
            $this->print_comments($.comments);
        }
        "</div>";
        if ($this.multiform_on) {
            "<h2>Mass Action</h2><div style='margin-left: 30px;'>";
            $this->print_multiform_actionline();
            $this->print_multiform_end();
            "</div>";
        }
    }
}

function EntryPage::print_comment (Comment c) {
    var Color background; var Color color;
    if ($c.screened) {
        $background = $*comment_bar_screened_bgcolor;
        $color = $*comment_bar_screened_fgcolor;
    } elseif ($c.depth % 2) {
        $background = $*comment_bar_one_bgcolor;
        $color = $*comment_bar_one_fgcolor;
    } else {
        $background = $*comment_bar_two_bgcolor;
        $color = $*comment_bar_two_fgcolor;
    }
    var string poster = defined $c.poster ? $c.poster->as_string() : "<i>(Anonymous)</i>";
    var string sub_icon;
    if (defined $c.subject_icon) {
        $sub_icon = $c.subject_icon->as_string();
    }
    "<a name='$c.anchor'></a><div id='cmtbar$c.talkid' style='background-color: $background; color: $color; margin-top: 10px; width: 100%'>";
    "<table cellpadding='2' cellspacing='0' summary='0' style='width: 100%'><tr valign='top'>";
    if (defined $c.userpic and $*comment_userpic_style != "off") { 
        var int w = $c.userpic.width;
        var int h = $c.userpic.height;
        # WARNING: this will later be done by the system (it'll be a
        # constructional property), so don't copy this hack into your
        # layout layers or you'll be messed up later.
        if ($*comment_userpic_style == "small") {
            $w = $w / 2;
            $h = $h / 2;
        }
        print "<td style='width: 102px'><img src='$c.userpic.url' width='$w' height='$h' alt='[User Picture]' /></td>";
    }

    "<td style='width: 100%'><table style='width: 100%'><tr>";

    ### From, date, etc
    "<td align='left' style='width: 50%'>";
      print "<table>";
      print "<tr><th align='right'>From:</th><td>$poster</td></tr>\n";
      print "<tr><th align='right'>Date:</th><td style='white-space: nowrap'>";
        print $c.time->date_format("long") + " - " + $c.time->time_format() + "</td></tr>";
      if ($c.metadata{"poster_ip"}) { print "<tr><th align='right'>IP Address:</th><td>(" + $c.metadata{"poster_ip"} + ")</td></tr>"; }
    "</table></td>";

    ### Gadgets
    "<td align='right' style='width: 50%'>";
    if ($this.multiform_on) {
        " <label for='ljcomsel_$c.talkid'>$*text_multiform_check</label>";
        $c->print_multiform_check();
    }
    $c->print_linkbar();
    "</td></tr>";

    ### Subject / icon
    print "<tr valign='top'><td style='width: 50%'>";
    print (defined $c.subject_icon or $c.subject != "") ? "<h3>$c.subject_icon $c.subject</h3>" : "";
    print "</td>";

    ### Permalink
    print "<td style='width: 50%' align='right'><strong>(<a href='$c.permalink_url'>Link</a>)</strong></td></tr>";

    print "</table></td></tr></table></div>";
    print "<div style='margin-left: 5px'>$c.text</div>";
    print "<div style='margin-top: 3px; font-size: smaller'>";
    if ($c.frozen) {
        print """(Replies frozen) """;
    } else {
        print """(<a href='$c.reply_url'>Reply to this</a>) """;
    }
    if ($c.parent_url != "") { "(<a href='$c.parent_url'>Parent</a>) "; }
    if ($c.thread_url != "") { "(<a href='$c.thread_url'>Thread</a>) "; }
    "</div>";
}

function ReplyPage::print_body () 
{
    var string time = $.replyto.time->time_format();

    if (not $.entry.comments.enabled)
    {
        print "<h2>$*text_reply_nocomments_header</h2><p>$*text_reply_nocomments</p>";
        return;
    }

    "<h2>" + $.replyto.time->date_format("med") + "</h2>";

    "<div class='H3Holder'>";

    "<div class='Picture'>";
    print defined $.replyto.poster ? $.replyto.poster->as_string() : "<i>(Anonymous)</i>";
    if (defined $.replyto.userpic) { "<div><img src='$.replyto.userpic.url' /></div>"; }
    "</div>";
 
    # Time / Subject / Security
    var string subject = ($.replyto.subject ? " - <em>$.replyto.subject</em>" : "");
    "<h3><span>$time$subject</span></h3>";

    "<p>$.replyto.text</p>";

    "<div class='Comment'><a href='$.entry.comments.read_url'>Read Comments</a></div>";
    "</div>";
    print "<h2>Reply:</h2>";
    $.form->print();
}


function print_theme_preview ()
{
  """<table width='100%' bgcolor='$*main_bgcolor' cellpadding='3' border='0'><tr valign='top'>
<td width='30' bgcolor='$*sidebar_color'>&nbsp;</td>
<td width='30'>&nbsp;</td>
<td>
<h2 style='background-color: $*headerbar_bgcolor; color: $*headerbar_fgcolor; border-bottom: thin solid $*headerbar_bevel_color; font: normal 1.3em Georgia, serif; line-height: 1.3;'>Dec. 22nd, 2002</h2>
<div style='clear: both; padding-left: 2ex; border-left: thin solid $*border_color; border-bottom: thin solid $*border_color; margin-bottom: 1em; '>
<h3 style='color: $*highlight_fgcolor; font: medium sans-serif'><span style='background-color: $*highlight_bgcolor; border-right: thin solid $*border_color; border-bottom: thin solid $*border_color; padding-right: 0.5ex;'>08:46 pm - <em style='color: $*meta_color; font-style: normal;'>subject</em></span></h3>
<p style='margin-top: 0; text-align: justify; font-family: serif; font-size: 12pt; color: $*main_fgcolor;'>Words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words</p>

<div style='font-size: 0.7em; margin-top: -1em; text-align: right; font-size: 8pt; color: $*main_fgcolor;'>(<a style='color: $*link_color;' href='#'>1 comment</a>&nbsp;|&nbsp;<a style='color: $*link_color;' href='#'>Leave a comment</a>)</div>
</div>

</td></tr>
</table>""";
}
