Thread
Site Infrastructure / Thread

[show modes: view mark_as_read]
[begin mode mark_as_read]
[clean_title = _title;
if(strpos(_title, "<!>") >= 0) {[
	clean_title = substr(_title, 0, strpos(_title, "<!>"));
	override_title(clean_title, _subtitle);
]}]
[_mark_read();
refresh_to({/?id=[_parent]}, 1);]
Marked! <b><a href="/?id=[_parent]">Back to [get_title(_parent)].</a></b>
[end mode mark_as_read]
[begin mode mark_read][
children("mark_read", _id);
][end mode mark_read]
[begin mode preview][
	clean_title = _title;
	if(strpos(_title, "<!>") >= 0) clean_title = substr(_title, 0, strpos(_title, "<!>"));

	override_title("Preview Post", clean_title);
	_postform(_params.title, _params.body);
][end mode preview]
[begin mode postindex][
	// Returns the order in which the post (specified by ID number) appears in the thread.
	qs = children("id", _id);
	qs = split(qs, chr(10));
	max = count(qs);

	for(n = 0, n < max, n++)
		if(qs[n] == _args[0])
			return max - n;

	return -1;
][end mode postindex]
[begin mode first_unread_post]
[
	nposts = retrieve({select entries.id from `entries` right join `data` on entries.id = data.id where `parent` = [_id] and `name` = [_viewer.id] and `value` <> "" order by entries.id asc limit 1});
	return nposts.0.id;
][end mode first_unread_post]
[begin mode postquery][
	// number of unread posts
	__lf;
	if(_viewer.id == 0) return;
	nposts = retrieve({select entries.id from `entries` right join `data` on entries.id = data.id where `parent` = [_id] and `name` = [_viewer.id] and `value` <> ""});
	count(nposts);
][end mode postquery]
[begin mode pnl][
lqc = _args[0];
qc = _args[1];

if(lqc > (qc - 20)) {[
	pnl = (qc - 20);
]} else if(lqc > 20) {[
	if(lqc == qc)
		pnl = (lqc - 20)
	else
		pnl = lqc - 1;
]} else
	pnl = 0;

if(pnl < 0) pnl = 0;

return pnl;
][end mode pnl]
[begin mode abbr]
[
clean_title = _title;
if(strpos(_title, "<!>") >= 0) clean_title = substr(_title, 0, strpos(_title, "<!>"));

q = query("posts", 1, "id desc, author", "parent", _id);
//qc = query_count(q);
qlast = int(query_run("id", q));

q = query("posts", 1, "id asc, author", "parent", _id);
qc = query_count(q);
qfirst = int(query_run("id", q));

_params.posts_pagenum = -30;
q = query("posts", 20, "id desc, author", "parent", _id);
if(qc > 1) la = get_author(qlast);

fp_edit = retrieve({select `value` from data where data.id = "[qfirst]" and data.name = "edits"});
fp_edit = int(fp_edit.0.value);

lqc = qc;
lqlast = qlast;

nposts = retrieve({select entries.id from `entries` right join `data` on entries.id = data.id where `parent` = [_id] and `name` = [_viewer.id] and `value` <> "" order by entries.id asc});
npc = count(nposts);

if(_viewer.id == 0) npc = 0;

if(npc > 0) {[
	lqlast = nposts.0.id;
	lqc = _postindex(lqlast);
]};

bg = {position: relative; margin-top: 6px; padding: 6px; padding-left: 11px};

fdate = get_date(qfirst);

if(npc == 0)
	msg_start(bg)
else
	msg_start({border-color: #0086b6; [bg]}, "new_post");

sstd = {position: absolute; left: 0px; top: 0px; bottom: 0px; width: 5px;};

if(_priority > 0)
	{<div style="[sstd]; background: rgb(0, 132, 172)" title="This thread is pinned."></div>}
else
	{<div style="[sstd]; background: rgba(128, 128, 128, 0.6)"></div>};

pnl = _pnl(lqc, qc);
]
<table style="width: 100%; border-collapse: collapse;"  ondblclick="window.location.href = '[bare_url()]?id=[_id]&posts_pagenum=[pnl]#[lqlast]'">
<tr>
[if(qc > 1) {
<td style="width: 20px; text-align: right; font-weight: bold; padding-right: 10px;">
<span style="min-width: 18px; display: block; border: 1px solid rgba(128, 128, 128, 0.2); color: rgba(128, 128, 128, 0.6); background: rgba(128, 128, 128, 0.2); padding: 3px; text-align: center; font-size: 70%">[qc - 1]</span>
}]
<td>
<b><a href="/?id=[_id]&posts_pagenum=[pnl]#[lqlast]">[info_display(clean_title)]</a></b>
<span style="font-size: 70%; display: block;">[
	if(qc > 20) {pages: <b>[replace(page_list(q), {?id=[_parent]}, {?id=[_id]})]</b> };

	if(npc > 1) { ([npc] new posts)}
	else if(npc == 1) { (1 new post)};
]</span>
<td style="text-align: right; font-size: 70%;">
[if(fp_edit == 0) {started} else {first post updated}] <span title="[fdate]">[soft_age(fdate)] ago</span> by [if(_owner.profile_id > 0) page("link", _owner.profile_id) else _owner.name]
[if(qc > 1) {
	<br>last post <span title="[lad = get_date(qlast); lad]">[soft_age(lad)] ago</span> by [rp = get_profile_id(la); if(rp > 0) page("link", rp) else uid2name(la)]
}]
</table>
[msg_end()]
[end mode abbr]
[begin mode view]
[
clean_title = _title;
if(strpos(_title, "<!>") >= 0) {[
	clean_title = substr(_title, 0, strpos(_title, "<!>"));
	override_title(clean_title, _subtitle);
]};

page("view", 63);

q = query("posts", 20, "id", "parent", _id);

pl = page_list(q, 0);

qc = query_count(q);

calc = query_run("view", q);

if(_params.posts_pagenum < 1)
	pp = -1
else if(_params.posts_pagenum < 20)
	pp = 0
else if((_params.posts_pagenum % 20) == 0)
	pp = _params.posts_pagenum - 20
else
	pp = _params.posts_pagenum - (_params.posts_pagenum % 20);

if(pp != "-1") pp = {/?id=[_id]&posts_pagenum=[pp]};

// lastpage = qc - (qc % 20);

if(_params.posts_pagenum == "") _params.posts_pagenum = 0;

if(_params.posts_pagenum >= (qc - 20))
	np = -1
else
	np = (_params.posts_pagenum - (_params.posts_pagenum % 20)) + 20;

if(np != "-1") np = {/?id=[_id]&posts_pagenum=[np]};

gadget = {[
	if((pp == "-1") && (np == "-1")) {[
		if(qc > 20)
			{<a href="/?id=[_id]">start</a> [pl]};
	]} else if(pp == "-1")
		{previous [pl] <a href="[np]">next</a>}
	else if(np == "-1")
		{<a href="[pp]">previous</a> [pl] next}
	else
		{<a href="[pp]">previous</a> [pl] <a href="[np]">next</a>};

	 if(qc <= 20)
		{}
	else if(_params.posts_pagenum == qc - 20)
		{ end}
	else
		{ <a href="/?id=[_id]&posts_pagenum=[qc - 20]" title="show last 20 posts">end</a>};

	lq = query("posts", 1, "id asc, author", "parent", _id);
	lqc = query_count(lq);

	nposts = retrieve({select entries.id from `entries` right join `data` on entries.id = data.id where `parent` = [_id] and `name` = [_viewer.id] and `value` <> "" order by entries.id asc});
	npc = count(nposts);

	if(_viewer.id == 0) npc = 0;

	lqlast = 0;
	if(npc > 0) {[
		lqlast = nposts.0.id;
		lqc = _postindex(lqlast);
	]};

	pnl = _pnl(lqc, qc);

	if(lqlast > 0)
		{ <a href="/?id=[_id]&posts_pagenum=[pnl]#[lqlast]" title="jump to first unread post">continue</a>};
]};

if(gadget != "") gadget = msg(gadget);

t = 0;

if(get_template(_parent) == _template) t = 1;

if(t == 1) {<div style="padding-left: 10px;">};

gadget;
calc;
gadget;

if(can_comment()) {[
	if( (np == "-1") )
		_postform("")
	else
		{<center><b><a href="/?id=[_id]&mode=reply">reply</a></b></center>}
]};

if(t == 1) {</div>};

]

[end mode view]
[begin mode reply]
[
clean_title = _title;
if(strpos(_title, "<!>") >= 0) {[
	clean_title = substr(_title, 0, strpos(_title, "<!>"));
	override_title(clean_title, _subtitle);
]};

page("view", 63);

if(can_comment()) {[
	b = "";
	if(_params.quote != "") {[
		qb = get_body(_params.quote);
		qa = get_author(_params.quote);
		qp = (import _params.quote);
		qu = list();
		qu.id = qa;
		ge = get_extended(qa);
		qu.profile_id = get_profile_id(qa);
		pcount = getva("posts", ge);
		// force post count consistency—slow and undesirable
		pcount2 = query_count(query("posts", 0, "id", "author", _author, "template", _template));
		if(pcount2 > pcount) pcount = pcount2;

		qrank = _postrank(pcount, qu);
		qloc = qp.location;
		
		qn = uid2name(qa) & ", ";
		if(strpos(qloc, "(rank)") >= 0) {[
			qp.rankloc = replace(qp.location, "(rank)", qrank);
			qn = qn & qp.rankloc;
		]} else {[
			qn = qn & qrank;
			if(qloc != "") {[
				if(substr(qloc, 0, 1) != " ") if(substr(qloc, 0, 1) != ",") qloc = ", " & qloc;
				qn = qn & qloc;
			]};
		]};
		b = "[quote " & qn & "]" & qb & "[/quote]" & chr(10) & chr(10);
	]};
	_postform("", b);
]} else
	{<p>Not for you! <a href="##" onClick="history.go(-1); return false;">Go back.</a></b></p>};
]
[end mode reply]
[begin mode post]
[
if(_viewer.profile_id < 1) return "Please create a user profile before posting on the forums.";

clean_title = _title;
if(strpos(_title, "<!>") >= 0) {[
	clean_title = substr(_title, 0, strpos(_title, "<!>"));
	override_title(clean_title, _subtitle);
]};

if(can_comment()) {[
	title = _params.title;
	if(title == "") title = {<!>[clean_title] ([now()])};
	if(search("id", "parent", _id, "title", title) != "") title &= "<!>#" & rand();
	post = _generate(_id, title, title2id("Linear Post"), _params.body);
	if(post > 0) {
			[
			q = query("posts", 20, "id", "parent", _id);
			qc = query_count(q);
			pagenum = int((qc - 1) / 20) * 20;
			set_date(_id, now());
			putu("posts", (int(getu("posts")) + 1) + "");

			@the_post = (import entry post);
			locstyle = getu("locstyle");
			if(locstyle == "country") {[
				locinfo = ip2location(_viewer.ip);
				@the_post.location = locinfo.geoplugin_countryName;
			]} else if(locstyle == "city") {[
				locinfo = ip2location(_viewer.ip);
				@the_post.location = {[locinfo.geoplugin_city], [locinfo.geoplugin_countryName]};
			]} else if(locstyle == "custom") {[
				@the_post.location = getu("locfantasy");
			]} else {[
				@the_post.location = "";
			]};

			if(@the_post.location != "") {[
				locstring = getu("locstring");
				if(len(locstring) > 0) {[
					if(strpos(locstring, "(loc)") >= 0) {[
						customlocation = replace(locstring, "(loc)", @the_post.location);
					]} else {[
						customlocation = locstring & ", " & @the_post.location;
					]};
				]};
				
				if(len(customlocation) > 0) {[
					@the_post.location = customlocation;
				]} else {[
					@the_post.location = ", " & @the_post.location;
				]};
			]};

			refresh_to({/?mode=view&id=[_id]&posts_pagenum=[pagenum]#[post]}, 1);
			]

			<p>Success! <b><a href="/?mode=view&id=[_id]&posts_pagenum=[pagenum]#[post]">Click here to go view it.</a></b></p>
	} else {
			<p>Post failed! Another post with that title already exists.</p>
			<p>... that shouldn't have happened.</p>
			<p><b><a href="##" onClick="history.go(-1); return false;">Go back.</a></b></p>
	};
]} else {
	<p>Not for you! <b><a href="##" onClick="history.go(-1); return false;">Go back.</a></b></p>
};
]
[end mode post]

[begin mode delete_submit]
[
clean_title = _title;
if(strpos(_title, "<!>") >= 0) {[
	clean_title = substr(_title, 0, strpos(_title, "<!>"));
	override_title(clean_title, _subtitle);
]};

if(is_user_in_group(_viewer.id, 1) || (_author == _viewer.id)) {[
	$n = delete_page($_id);
	$children = children("id", $_id);
	mute foreach($children) delete_page(_data);
	if($n == "1") {
		<p><b>[clean_title]</b> has been removed from <b>[get_title($_parent)]</b>.</p>
	} else {
		<p><b>[clean_title]</b> could not be removed from <b>[get_title($_parent)]</b>
		by you ([$_viewer.name]). If you feel that should be able to do so, now
		might be a good time to
		<a href="mailto:[$_globals.ADMIN_EMAIL]"> write a letter to the administrator</a>.</p>
	}
]} else {No soup for you!};
]
<p><a href="/?id=[$_parent]">Return to [get_title($_parent)]</a></p>
[end mode delete_submit]