All pastes #770695 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-11-12 14:37 UTC
rendered paste body
<?php
/**
* Display thread page
* @package viewthread
* @since 0.0.1
* @version 0.0.1
*/
define('THIS_SCRIPT','THREADS');
try
{
	include('config.php');
	include('./includes/const.php');
	include('./includes/functions.php');
	include('./includes/class_core.php');
	include('./includes/functions_xml.php');
	include('./includes/class_bbparser.php');

	$db = $kraster->getInstance('database');
	$template = $kraster->getInstance('template');
	
	process_user_settings($kraster,$template);
	
	$priviliges = parser_user_priviliges($kraster,'threads');
	if($priviliges !== true)
	{
		throw new exception(constant($priviliges));
	}

	// ID definition of certain things 
	$groupID = $kraster->getInstance('session')->read('group');
	$groupID = $groupID === false ? 0 : $groupID;
	$uid = $kraster->getInstance('session')->read('uid');
	$uid = $uid === false ? 0 : $uid;
	$page = $kraster->getInstance('httpData')->read('page');
	$page = empty($page) ? 0 : $page;
	$id = $kraster->getInstance('httpData')->read('id');
	$id = empty($id) ? 0 : $id;

	$group = $kraster->getInstance('groups');
	$group->setGroupData($db->query('SELECT * FROM `groups` WHERE `id` = '.$groupID)->fetch());
	$thread = $db->query('SELECT * FROM `threads` WHERE `id` = '.(int) $id)->fetch();
	
	if(empty($thread) || !is_numeric($id))
	{
		throw new exception(THREAD_DOSE_NOT_EXIST);
	}

	// This is abit of a waste of resources.
	// What it dose is that it checks the category then board group access requirements for the current thread.
	// Disabled by settings system.security level smaller then 2
	if($kraster->getConfig('system.security') >= 2)
	{
		// Here we can use fetch because if a thread exists a board must exist for it.
		$board = $db->query('SELECT `groups`,`upperid` FROM `boards` WHERE `id` = '.(int) $thread[0]['boardid'])->fetch();

		// Access denied for the board
		if(!(in_array($groupID, unserialize($board['groups'])) && strpos($board['groups'],'*') === false && $group->canView('all')))
		{
			throw new exception(PERMISSION_DENIED);
		}
		
		$category = $db->query('SELECT `groups` FROM `categories` WHERE `position` = '.$board['upperid'])->fetch();
		
		if(!(in_array($groupID, unserialize($category['groups'])) && strpos($category['groups'],'*') === false && $group->canView('all')))
		{
			throw new exception(PERMISSION_DENIED);
		}
	}
	
	$canViewDeleted = $group->canView('deleted') == 1 && in_array($groupID,$board[0]['groups'])  ? '' : ' AND `deleted` = \'n\'';
	$posts = $db->query('SELECT * FROM `posts` WHERE `threadid` = '.$id.$canViewDeleted.' ORDER BY `id` DESC')->fetchAll();


	
	foreach($posts as $post)
	{
		$root = $template->xml->createElement('table');
		setAttributes(array('width' => '440px','height' => 165,'border' => '1px solid #000','cellpadding' => 0,'cellspacing' => 0),$root);


		/*
			First row
		*/
		$tr = $template->xml->createElement('tr');
		
		$td = $template->xml->createElement('td',array('width' => 74,'align' => 'left','valign' => 'top','bgcolor' => '#FFFF00'));
		
		$td->nodeValue = '#'.$post['id'];
		$tr->appendChild($td);

		$td = $template->xml->createElement('td',array('width' => 260,'height' => 21,'valign' => 'top','bgcolor' => '#FFFF00'));

		$td->nodeValue = $post['title'];
		$tr->appendChild($td);

		$td = $template->xml->createElement('td',array('width' => 98,'align' => 'right','valign' => 'top','bgcolor' => '#FFFF00'));

		$td->nodeValue = date('d-m-y H:i',$post['date']);
		$tr->appendChild($td);
		$root->appendChild($tr);


		/*
			Second row
		*/

		$user = $db->query('SELECT `id`,`name`,`avatar` FROM `users` WHERE `id` = '.(int) $post['uid'])->fetch();
		$avatar = $user['avatar'] != NULL ? $user['name'].'.'.$user['avatar'] : 'bildsaknas.jpg';
		$tr = $template->xml->createElement('tr');
		
		$td = $template->xml->createElement('td',array('width' => 74,'align' => 'left','valign' => 'top'));
		
		$td->appendChild($template->html->img('./img/users/'.$avatar,$user['avatar'],false,'width:70px;'));
		$td->appendChild($template->xml->createElement('br'));
		$td->appendChild($template->html->createLink($user['name'],array('href' => 'profile.php?id='.$user['id'])));
		$tr->appendChild($td);

		$td = $template->xml->createElement('td',array('width' => 121,'colspan' => 2,'align' => 'left','valign' => 'top'));

		$td->appendChild($template->xml->inparse(BBParser::parse($post['message'])));
		$tr->appendChild($td);
		$root->appendChild($tr);
		$template->appendTree($root);
		$template->appendTree($template->xml->createElement('br'));
	}
}
catch(exception $e)
{
	
	$error = $db->query('SELECT * FROM `errors` WHERE `id` = '.(int) $e->getMessage().' AND `language` = \''.$kraster->getInstance('session')->read('language').'\' LIMIT 1')->fetch();
	message($error['message'],$template,$error['redirect'] != NULL ? $error['redirect'] : '');
}
$template->display();
?>