<?php

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

require_once 'models/thread.inc';

function threadsummary($lang, $thread) {
	$thread_id = thread_id($thread);
	if (!$thread_id) {
		return run('error/notfound', $lang);
	}

	$r = thread_get($lang, $thread_id);
	if (!$r) {
		return run('error/notfound', $lang);
	}
	extract($r); /* thread_name thread_title thread_abstract thread_cloud */

	head('title', $thread_title);
	head('description', $thread_abstract);
	head('keywords', $thread_cloud);

	$validate=url('thread', $lang) . '/'. $thread_name;
	$banner = build('banner', $lang, compact('validate'));

	$r = thread_get_contents($lang, $thread_id);

	$thread_contents = array();

	if ($r) {
		$node_uri = url('node', $lang);
		foreach ($r as $c) {
			extract($c);	/* node_id node_name node_title node_number */
			$node_url = $node_uri . '/' . $node_id;
			$thread_contents[] = compact('node_title' , 'node_url');
		}
	}

	$content = view('threadsummary', $lang, compact('thread_title', 'thread_abstract', 'thread_cloud', 'thread_contents'));

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

	return $output;
}

