layerinfo "type" = "layout";
layerinfo "name" = "Revolting Chicks";
layerinfo "author_name" = "Mārtiņš Pilsētnieks";
layerinfo "author_email" = "pilsetnieks@gmail.com";
layerinfo "redist_uniq" = "revoltchicks/layout";

propgroup setup = "Page setup";
propgroup setup
{
	property use page_friends_items;
	property use page_recent_items;
	property use font_base;

	property string title_font
	{
		des = "Title font";
		size = 4;
	}
	property string text_fontsize
	{
		des = "Font size";
		size = 4;
	}
	property string side_fontsize
	{
		des = "Sidebar font size";
		size = 4;
	}
	property string title_fontsize
	{
		des = "Title font size (subjects, etc.)";
		size = 4;
	}
	property string small_fontsize
	{
		des = "Small texts (talkback links, dates) font size";
		size = 4;
	}
	property bool show_title
	{
		des = "Show page title";
	}
	set show_user_link = true;
	set show_title = true;
	set title_font = "Georgia";
	set font_base = "Georgia";
	set page_friends_items = 30;
	set page_recent_items = 15;
	set text_fontsize = "11pt";
	set side_fontsize = "9pt";
	set title_fontsize = "12pt";
	set small_fontsize = "8pt";
}

propgroup text = "Page text";
propgroup text
{
	property use text_post_comment;
	property use text_read_comments;
	property use text_reply_nocomments;
	property use text_nosubject;
	property use text_comment_reply;
	property use text_comment_ipaddr;
	property use text_view_archive;
	property use text_view_friends;
	property use text_view_recent;
	property use text_view_userinfo;
	property use text_skiplinks_forward;
	property use text_skiplinks_back;
	property use text_meta_mood;
	property use text_meta_music;

	property string text_next_post
	{
		des = "Text for the next post link";
	}
	property string text_prev_post
	{
		des = "Text for the previous post link";
	}
	property string text_comment_anonymous
	{
		des = "Anonymous";
	}
	set text_skiplinks_back = "Vecākus pukstus";
	set text_skiplinks_forward = "Jaunākus pukstus";
	set text_next_post = "Nākamais puksts";
	set text_prev_post = "Iepriekšējais puksts";
	set text_comment_anonymous = "Anonīms";
	set text_comment_screened = "Paslēpta nopūta";
}

propgroup colors = "Page colors";
propgroup colors
{
	property Color bgcolor
	{
		des = "Background";
	}
	property Color text_color
	{
		des = "Text color";
	}
	property Color link_color
	{
		des = "Link color";
	}
	property Color title_color
	{
		des = "Title color";
	}
	property Color title_bgcolor
	{
		des = "Title background";
	}
	property Color date_color
	{
		des = "Date and time color";
	}
	property Color img_border_color
	{
		des = "Image border color";
	}
	set bgcolor = "#FFFFFF";
	set text_color = "#000000";
	set link_color = "#D99F21";
	set title_color = "#E6AE35";
	set title_bgcolor = "#ECECEC";
	set date_color = "#A6A6A6";
	set img_border_color = "#D99F21";
	set entry_bottom_color = "#D5D5D5";
}

function print_stylesheet()
{
	var string content_top = "220px";
	if (not $*show_title)
	{
		$content_top = "100px";
	}

	"""body{
		padding: 0;
		margin: 0;
		background-color: $*bgcolor;
		color: $*text_color;
	}""";
	if ($*show_title)
	{
		"""h1{
			font-family: $*title_font;
			padding: 0;
			margin: 0;
		}
		h1#top{
			position: absolute;
			top: 60px;
			left: 150px;
			color: $*title_color;
			font: normal 80px $*title_font;
			font-weight: normal;
			z-index: 1;
		}
		h1#bottom{
			position: absolute;
			top: 30px;
			left: 120px;
			color: $*title_bgcolor;
			font: italic 130px $*title_font;
			font-weight: normal;
			z-index: 0;
		}""";
	}
	"""#sidebar{
		position: absolute;
		top: $content_top;
		left: 120px;
		z-index: 3;
		width: 150px;
		font: normal $*side_fontsize $*font_base;
		font-weight: bold;
	}
	#sidebar a{
		display: block;
		font-weight: normal;
	}
	.userpic, img.special{
		border: 1px solid $*img_border_color;
		margin: 0 10px 0 10px;
		padding: 10px;
		text-align: center;
	}
	.userpic img{
		padding: 0;
		margin: 0;
		border-width: 0;
	}
	.userpic a{
		padding: 0;
		margin: 0;
		font-weight: bold;
	}
	.userpic a.infoLink{
		padding-top: 10px;
		padding-right: 10px;
	}
	.subject a img{
		border-width: 0;
	}
	#sidebar img.special{
		margin: 0 0 20px 0;
	}
	#content{
		position: absolute;
		top: $content_top;
		padding: 0 200px 0 270px;
		font-family: $*font_base;
	}
	.post{
		padding: 0 0 10px 0;
		margin: 0 0 30px 0;
		list-style-type: none;
		font: normal $*small_fontsize $*font_base;
		border-bottom: 1px solid $*entry_bottom_color;
	}
	.post .subject{
		font-size: $*title_fontsize;
	}
	.post a, form a{
		padding: 0;
	}
	.post .datetime{
		color: $*date_color;
	}
	.post .event{
		padding: 10px 0 10px 0;
		font-size: $*text_fontsize;
		color: $*text_color important;
	}
	.post .event .userpic{
		float: left;
	}
	.post .talkback{
		color: $*date_color;
	}
	.post .talkback a{
		padding-right: 20px;
	}
	#itemrange{
		height: 30px;
		border-bottom: 1px solid $*entry_bottom_color;
	}
	form{
		font-size: $*side_fontsize;
	}
	input, textarea, select{
		font-family: Verdana;
		font-size: $*small_fontsize;
	}
	a{
		color: $*link_color;
		padding-right: 20px;
	}
	#footer{
		text-align: center;
		margin: 10px auto 10px auto;
		font-size: $*small_fontsize;
	}\n""";
}

function print_sidebar(User u, string{} view_url, string[] views_order)
{
	var string url;
	var string view;
	var string a;
	var string hr;
	var string{} viewTitles;
	var Page p;
	var string jUrl;

	$jUrl = $u -> base_url();
	$viewTitles = {
		"recent" => $*text_view_recent,
		"friends" => $*text_view_friends,
		"archive" => $*text_view_archive,
		"userinfo" => $*text_view_userinfo
	};
	"""<div id="sidebar">\n""";
	if ($u.default_pic.url -> length() > 0)
	{
		"""<a href="$jUrl"><img src="$u.default_pic.url" alt="$u.name" title="$u.name" id="userpic" class="special"/></a>\n""";
	}
	else
	{
		"""<strong>$u.name</strong><br/>\n""";
	}
	foreach $view ($views_order)
	{
		$hr = $view_url{$view};
		$a = $viewTitles{$view};
		"""<a href="$hr">$a</a>\n""";
	}
	if ($u.website_url -> length() > 0)
	{
		"""<a href="$u.website_url">$u.website_name</a>\n""";
	}
}

function print_plain_footer()
{
	"""</div>
	</body>
	</html>""";
}

function print_footer(RecentNav nav)
{
	"""<div id="itemrange">\n""";
	if ($nav.backward_count > 0)
	{
		"""<a href="$nav.backward_url">$*text_skiplinks_back</a>\n""";
	}
	if ($nav.forward_count > 0)
	{
		"""<a href="$nav.forward_url">$*text_skiplinks_forward</a>\n""";
	}
	"</div>\n";
	print_plain_footer();
}

function print_entryLite(EntryLite e)
{
	var string dt;
	var string music;
	var string mood;
	var string posterHref;
	var string name;
	var bool isAnonymous;

	$isAnonymous = isnull $e.poster;
	$music = $e.metadata{"music"};
	$mood = $e.metadata{"mood"};
	$dt = $e.time -> date_format() + " " + $e.time -> time_format();
	$posterHref = ($isAnonymous ? "" : $e.poster -> base_url());
	$name = ($isAnonymous ? $*text_comment_anonymous : $e.poster.name);
	"""<ul class="post">\n""";
	if ($e.subject -> length() > 0)
	{
		"""<li class="subject"><a href="$e.permalink_url">$e.subject</a></li>\n""";
	}
	"""<li class="datetime">$dt</li>
	<li class="event">\n""";
	"""$e.text</li>\n""";
	if ($music -> length() > 0 or $mood -> length() > 0)
	{
		"""<li class="currents">""";
		if ($music -> length() > 0)
		{
			"$*text_meta_music: $music";
		}
		if ($music -> length() > 0 and $mood -> length() > 0)
		{
			"<br/>\n";
		}
		if ($mood -> length() > 0)
		{
			"$*text_meta_mood: $mood";
		}
		"</li>\n";
	}
	"</ul>\n";
}

function Page::print_custom_head()
{
	var string title;
	var string un;

	$un = $.journal.username;
	if ($.global_title -> length() > 0)
	{
		$title = $.global_title;
	}
	else
	{
		if ($.journal.name -> length() > 0)
		{
			$title = $.journal.name;
		}
		else
		{
			$title = "";
		}
	}

	"""<!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>$title</title>

	<style type="text/css">\n""";
	print_stylesheet();
	"""</style>
	<link rel="home" href="$.base_url"/>
	<link rel="copyright" href="$.base_url"/>
	<link rel="first" href="$.base_url"/>
	<link rel="start" href="$.base_url"/>""";
#	if (not isnull $.nav){
#		if ($.nav.backward_url -> length() > 0){ """<link rel="prev" href="$.nav.backward_url"/>"""; }
#		if ($.nav.forward_url -> length() > 0){ """<link rel="next" href="$.nav.forward_url"/>"""; }
#	}
	"</head>
	<body>";
	
	if ($*show_title)
	{
		"""<h1 id="top">$title</h1>
		<h1 id="bottom">$title</h1>\n""";
	}
}

function Page::print_linklist()
{
	if ($*linklist_support and size $.linklist > 0)
	{
		var UserLink l;
		"<br/>\n";
		foreach $l ($.linklist)
		{
			if ($l.is_heading)
			{
				"""$l.title<br/>\n""";
			}
			else
			{
				if ($l.title -> length() > 0)
				{
					"""<a href="$l.url" title="$l.title">$l.title</a>\n""";
				}
				else
				{
					"<br/>\n";
				}
			}
		}
	}
}

function Page::print_entry(Entry e)
{
	var string dt;
	var string music;
	var string mood;
	var string posterHref;
	var string posterName;
	var string security;
	var string temp;
	var string img;
	var Image uInfoIcon;

	$music = $e.metadata{"music"};
	$mood = $e.metadata{"mood"};
	$dt = $e.time -> date_format() + " " + $e.time -> time_format();
	$posterHref = $e.journal -> base_url();
	$posterName = $e.journal.name;
	if ($e.journal.journal_type == "C")
	{
		$posterName = "$e.poster.name on behalf of $e.journal.name";
	}
	$security = ($e.security_icon.url -> length() > 0 ?
		"""<img src="$e.security_icon.url" alt="security" title="security"/>\n""" : "");
	"""<ul class="post">""";
	if ($e.subject -> length() > 0)
	{
		"""<li class="subject"><a href="$e.permalink_url">$e.subject</a></li>\n""";
	}
	"""<li class="datetime">$dt $security</li>
	<li class="event">""";
	if ($.view == "friends" or $.journal_type == "C")
	{
		"""<div class="userpic"><a href="$posterHref" title="$posterName">""";
		if ($e.userpic.url -> length() > 0)
		{
			"""<img class="pic" src="$e.userpic.url" alt="$posterName"/>""";
		}
		else
		{
			if (not $*show_user_link)
			{
				"$posterName";
			}
		}
		"</a>";
		if ($*show_user_link)
		{
			$uInfoIcon = userinfoicon($e.journal);
			if ($e.userpic.url -> length() > 0)
			{
				"<br />";
			}
			"""<a href="$posterHref/info/">""";
			"""<img src="$uInfoIcon.url" alt="$e.journal.name" /></a>""";
			"""<a href="$posterHref">$e.journal.username</a>""";
		}
		"</div>";
	}

	"""$e.text<br style="clear: both;" /></li>\n""";
	if ($music -> length() > 0 or $mood -> length() > 0)
	{
		"""<li class="currents">\n""";
		if ($music -> length() > 0)
		{
			"$*text_meta_music: $music";
		}
		if ($music -> length() > 0 and $mood -> length() > 0)
		{
			"<br/>";
		}
		if ($mood -> length() > 0)
		{
			"$*text_meta_mood: $mood";
		}
		"</li>\n";
	}
	"""<li class="talkback">\n""";
	if ($e.comments.enabled)
	{
		$e.comments -> print_readlink();
		$e.comments -> print_postlink();
	}
	else
	{
		print $*text_reply_nocomments;
	}
	"</li></ul>\n";
}

function RecentPage::print()
{
	var Entry en;
	$this -> print_custom_head();
	print_sidebar($.journal, $.view_url, $.views_order);
	$this -> print_linklist();
	"""</div>
	<div id="content">\n""";
	foreach $en ($.entries)
	{
		$this -> print_entry($en);
	}
	print_footer($.nav);
}

function EntryPage::print_comment(Comment c)
{
	var string left;
	var string posterHref;
	var Comment cN;
	var bool isAnonymous;
	var string dt;
	var Image uInfoIcon;

	$left = string(($c.depth - 1) * 20) + "px";
	$isAnonymous = (isnull $c.poster);
	$posterHref = ($isAnonymous ? "a" : $c.poster -> base_url());
	$dt = $c.time -> date_format() + " " + $c.time -> time_format();
	if ($c.full)
	{
		var string ip;
		$ip = ($c.metadata{"poster_ip"} -> length() > 0 ? $*text_comment_ipaddr + " " + $c.metadata{"poster_ip"} : "");
		"""<ul class="post" style="margin-left: $left">\n""";
		if ($c.subject -> length() > 0)
		{
			"""<li class="subject"><a href="$c.permalink_url">$c.subject</a></li>\n""";
		}
		"""<li class="datetime">\n""";
		if ($c.screened)
		{
			$dt = $dt + " " + $*text_comment_screened;
		}
		if ($.multiform_on)
		{
			$c -> print_multiform_check();
		}
		"""$dt</li>
		<li class="event">\n""";
		"""<div class="userpic">""";
		if ($isAnonymous)
		{
			"$*text_comment_anonymous";
		}
		else
		{
			if ($c.userpic.url -> length() == 0 and not $*show_user_link)
			{
				"""<a href="$posterHref">$c.poster.name</a>""";
			}
			else
			{
				if ($c.userpic.url -> length() > 0)
				{
					"""<a href="$posterHref"><img class="pic" src="$c.userpic.url" alt="$c.poster.name" /></a>""";
				}
			}
			if ($*show_user_link)
			{
				$uInfoIcon = userinfoicon($c.poster);
				if ($c.userpic.url -> length() > 0)
				{
					"<br />";
				}
				"""<a href="$posterHref/info/">""";
				"""<img src="$uInfoIcon.url" alt="$c.poster.name" /></a>""";
				"""<a href="$posterHref">$c.poster.username</a>""";
			}
		}
		"""</div>""";
		"""<p><a id="$c.talkid">$ip</a></p><p>$c.text</p><br style="clear: both;" /></li>
		<li class="talkback">
			<a href="$c.reply_url" title="reply">$*text_comment_reply</a>
		</li>
		</ul>\n""";
	}
	else
	{
		var string subj;
		var string poster;
		var Image uicon;
		var string posterHref;

		$subj = ($c.subject -> length() > 0 ? $c.subject : $*text_nosubject);
		if ($c.screened)
		{
			$subj = $subj + $*text_comment_screened;
		}

		$uicon = userinfoicon($c.poster);
		$posterHref = $c.poster -> base_url();
		$poster = ($isAnonymous ? $*text_comment_anonymous : """<a href="$posterHref/info/"><img src="$uicon.url" /></a><a href="$posterHref">$c.poster.username</a>\n""");
		"""<ul class="post" style="margin-left: $left">
			<li class="datetime">\n""";
		if ($.multiform_on)
		{
			$c -> print_multiform_check();
		}
		"""$dt</li>
			<li class="subject">$poster<a href="$c.permalink_url" style="position: relative; left: 20px;">$subj</a></li>
		</ul>\n""";
	}

	foreach $cN ($c.replies)
	{
		$this -> print_comment($cN);
	}
}

function EntryPage::print()
{
	var Comment c;

	$this -> print_custom_head();
	print_sidebar($.journal, $.view_url, $.views_order);
	$this -> print_linklist();
	"""</div>
	<div id="content">""";
	$this -> print_entry($.entry);
	$this -> print_multiform_start();
	foreach $c ($.comments)
	{
		$this -> print_comment($c);
	}
	$this -> print_multiform_actionline();
	$this -> print_multiform_end();
	print_plain_footer();
}

function ReplyPage::print()
{
	$this -> print_custom_head();
	print_sidebar($.journal, $.view_url, $.views_order);
	$this -> print_linklist();
	"""</div>
	<div id="content">\n""";
	print_entryLite($.replyto);
	$.form -> print();
	print_plain_footer();
}

function YearPage::print()
{
	$this -> print_custom_head();
	print_sidebar($.journal, $.view_url, $.views_order);
	$this -> print_linklist();
	"""</div>
	<div id="content">\n""";
	$this -> print_body();
	print_plain_footer();
}

function MonthPage::print()
{
	$this -> print_custom_head();
	print_sidebar($.journal, $.view_url, $.views_order);
	$this -> print_linklist();
	"""</div>
	<div id="content">\n""";
	$this -> print_body();
	print_plain_footer();
}

function DayPage::print()
{
	$this -> print_custom_head();
	print_sidebar($.journal, $.view_url, $.views_order);
	$this -> print_linklist();
	"""</div>
	<div id="content">\n""";
	$this -> print_body();
	print_plain_footer();
}