<?php

/**
 *
 * @copyright  2010 frasq.org
 * @version    1
 * @link       http://www.frasq.org
 */

require_once 'models/thread.inc';

function page($lang, $arglist=false) {
	$page=false;

	if (is_array($arglist)) {
		if (isset($arglist[0])) {
			$page=$arglist[0];
		}
	}

	if (!$page) {
		return run('error/notfound', $lang);
	}

	$thread_id = 1;

	$page_id = thread_node_id($thread_id, $page);
	if (!$page_id) {
		return run('error/notfound', $lang);
	}

	$r = thread_get_node($lang, $thread_id, $page_id);
	if (!$r) {
		return run('error/notfound', $lang);
	}
	extract($r); /* node_name node_title node_abstract node_cloud node_nocomment */

	$page_name=$node_name;
	$page_title=$node_title;
	$page_abstract=$node_abstract;
	$page_cloud=$node_cloud;

	$page_contents = build('nodecontent', $lang, $page_id);

	head('title', $page_title);
	head('description', $page_abstract);
	head('keywords', $page_cloud);

	$validate='/' . $lang . '/'. $page_name;
	$banner = build('banner', $lang, compact('validate'));

	$content = view('page', false, compact('page_name', 'page_title', 'page_contents'));

	$output = layout('standard', compact('banner', 'content'));

	return $output;
}

