<?php


namespace IPS\chatbox\modules\front\chatbox;

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

/**
 * msg
 */
class _msg extends \IPS\Content\Controller
{
	/**
	 * [Content\Controller]	Class
	 */
	protected static $contentModel = 'IPS\chatbox\Rooms\Chat';
	
	/**
	 * Execute
	 *
	 * @return	void
	 */
	public function execute()
	{
		# Load room
		try
		{
			$this->msg = \IPS\chatbox\Rooms\Chat::load( \IPS\Request::i()->id );
		}
		catch ( \OutOfRangeException $e )
		{
			\IPS\Output::i()->error( 'node_error', '2CHATBOX103/1', 404 );
		}
		
		parent::execute();
	}

	/**
	 * ...
	 *
	 * @return	void
	 */
	protected function manage()
	{
		$opts = $this->msg->container()->options();
		
		$chats[] = $this->msg;
		
		$files = \IPS\Application::load('chatbox')->showFiles( $chats, 'room' );
		$content = \IPS\Application::load('chatbox')->parseContent( $opts, $this->msg->content ) . $files[ $this->msg->id ];
		
		# Output
		$title = \IPS\Member::loggedIn()->language()->addToStack( 'chatbox_view_msg' );
		
		\IPS\Output::i()->breadcrumb[] = array( $this->msg->container()->url(), $this->msg->container()->_title );
		\IPS\Output::i()->breadcrumb[] = array( NULL, $title );
		
		\IPS\Output::i()->title = $title;
		\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'room', 'chatbox', 'front' )->viewMsg( $this->msg, $content );
	}
	
	
}