Esempio n. 1
0
 /**
  * Display attachment.
  *
  * @return void
  *
  * @throws RuntimeException
  * @throws KunenaExceptionAuthorise
  */
 public function execute()
 {
     try {
         $this->display();
     } catch (Exception $e) {
         // In case of an error we want to set HTTP error code.
         // We want to wrap the exception to be able to display correct HTTP status code.
         $error = new KunenaExceptionAuthorise($e->getMessage(), $e->getCode(), $e);
         header('HTTP/1.1 ' . $error->getResponseStatus(), true);
         echo $error->getResponseStatus();
         if (JDEBUG) {
             echo "<pre>{$e->getTraceAsString()}</pre>";
         }
     }
     flush();
     $this->app->close();
 }
Esempio n. 2
0
 /**
  * Calls a task and creates HTML or JSON response from it.
  *
  * If response is in HTML, we just redirect and enqueue message if there's an exception.
  * NOTE: legacy display task is a special case and reverts to original Joomla behavior.
  *
  * If response is in JSON, we return JSON response, which follows JResponseJson with some extra data:
  *
  * Default:   {code, location=null, success, message, messages, data={step, location, html}}
  * Redirect:  {code, location=[string], success, message, messages=null, data}
  * Exception: {code, location=[null|string], success=false, message, messages, data={exceptions=[{code, message}...]}}
  *
  * code = [int]: Usually HTTP status code, but can also error code from the exception (informal only).
  * location = [null|string]: If set, JavaScript should always redirect to another page.
  * success = [bool]: Determines whether the request (or action) was successful. Can be false without being an error.
  * message = [string|null]: The main response message.
  * messages = [array|null]: Array of enqueue'd messages.
  * data = [mixed]: The response data.
  *
  * @param  string  $task  Task to be run.
  *
  * @return void
  * @throws Exception
  */
 public function execute($task)
 {
     if (!$task) {
         $task = 'display';
     }
     $app = JFactory::getApplication();
     $this->format = $this->input->getWord('format', 'html');
     try {
         // TODO: This would be great, but we would need to store POST before doing it in here...
         /*
         			if ($task != 'display')
         			{
         				// Make sure that Kunena is online before running any tasks (doesn't affect admins).
         				if (!KunenaForum::enabled(true))
         				{
         					throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_FORUM_IS_OFFLINE'), 503);
         				}
         
         				// If forum is for registered users only, prevent guests from accessing tasks.
         				if ($this->config->regonly && !$this->me->exists())
         				{
         					throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_LOGIN_NOTIFICATION'), 403);
         				}
         			}
         */
         // Execute the task.
         $content = static::executeTask($task);
     } catch (Exception $e) {
         $content = $e;
     }
     // Legacy view support.
     if ($task == 'display') {
         if ($content instanceof Exception) {
             throw $content;
         }
         return;
     }
     // Create HTML redirect.
     if ($this->format == 'html') {
         if ($content instanceof Exception) {
             $app->enqueueMessage($content->getMessage(), 'error');
             if (!$this->redirect) {
                 // On exceptions always return back to the referrer page.
                 $this->setRedirect(KunenaRoute::getReferrer());
             }
         }
         // The following code gets only called for successful tasks.
         if (!$this->redirect) {
             // If controller didn't set a new redirect, try if request has return url in it.
             $return = base64_decode(JRequest::getVar('return', '', 'method', 'base64'));
             // Only allow internal urls to be used.
             if ($return && JUri::isInternal($return)) {
                 $redirect = JRoute::_($return, false);
             } else {
                 $redirect = KunenaRoute::getReferrer();
             }
             $this->setRedirect($redirect);
         }
         return;
     }
     // Otherwise tell the browser that our response is in JSON.
     header('Content-type: application/json', true);
     // Create JSON response and set the redirect.
     $response = new KunenaResponseJson($content, null, false, !empty($this->redirect));
     $response->location = $this->redirect;
     // In case of an error we want to set HTTP error code.
     if ($content instanceof Exception) {
         // We want to wrap the exception to be able to display correct HTTP status code.
         $exception = new KunenaExceptionAuthorise($content->getMessage(), $content->getCode(), $content);
         header('HTTP/1.1 ' . $exception->getResponseStatus(), true);
     }
     echo json_encode($response);
     // It's much faster and safer to exit now than let Joomla to send the response.
     JFactory::getApplication()->close();
 }
Esempio n. 3
0
 /**
  * Display output as JSON.
  *
  * @param   mixed  $content  Content to be returned.
  *
  * @return  string
  */
 public function displayJson($content)
 {
     // Tell the browser that our response is in JSON.
     header('Content-type: application/json', true);
     // Create JSON response.
     $response = new KunenaResponseJson($content);
     // In case of an error we want to set HTTP error code.
     if (!$response->success) {
         // We want to wrap the exception to be able to display correct HTTP status code.
         $error = new KunenaExceptionAuthorise($response->message, $response->code);
         header('HTTP/1.1 ' . $error->getResponseStatus(), true);
     }
     echo json_encode($response);
     // It's much faster and safer to exit now than let Joomla to send the response.
     JFactory::getApplication()->close();
 }
Esempio n. 4
0
<?php
/**
 * Kunena Component
* @package Kunena.Template.Crypsis
* @subpackage BBCode
*
* @copyright (C) 2008 - 2016 Kunena Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link https://www.kunena.org
**/
defined ( '_JEXEC' ) or die ();

/** @var KunenaAttachment $attachment */
$attachment = $this->attachment;
/** @var KunenaUser $user */
$user = isset($this->user) ? $this->user : null;

// Get authorisation message.
$exception = $attachment->tryAuthorise('read', $user, false);
if (!$exception) $exception = new KunenaExceptionAuthorise('Bad Request.', 400);
?>
<div class="kmsgattach">
	<?php echo $exception->getMessage(); ?>
</div>
Esempio n. 5
0
	public function execute()
	{
		KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.get_class($this).'::'.__FUNCTION__.'()') : null;

		// Run before executing action.
		$result = $this->before();

		if ($result === false)
		{
			KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.get_class($this).'::'.__FUNCTION__.'()') : null;
			throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 404);
		}

		// Wrapper layout.
		$this->output = KunenaLayout::factory('Page')
			->set('me', $this->me)
			->setOptions($this->getOptions());

		if ($this->config->board_offline && !$this->me->isAdmin ())
		{
			// Forum is offline.
			$this->setResponseStatus(503);
			$this->output->setLayout('offline');

			$this->content = KunenaLayout::factory('Widget/Custom')
				->set('header', JText::_('COM_KUNENA_FORUM_IS_OFFLINE'))
				->set('body', $this->config->offline_message);

		}
		elseif ($this->config->regonly && !$this->me->exists())
		{
			// Forum is for registered users only.
			$this->setResponseStatus(403);
			$this->output->setLayout('offline');

			$this->content = KunenaLayout::factory('Widget/Custom')
				->set('header', JText::_('COM_KUNENA_LOGIN_NOTIFICATION'))
				->set('body', JText::_('COM_KUNENA_LOGIN_FORUM'));

		}
		else
		{
			// Display real content.
			try
			{
				// Split into two lines for exception handling.
				$content = $this->display()->set('breadcrumb', $this->breadcrumb);
				$this->content = $content->render();

			}
			catch (KunenaExceptionAuthorise $e)
			{
				$this->setResponseStatus($e->getResponseCode());
				$this->output->setLayout('unauthorized');
				$this->document->setTitle($e->getResponseStatus());

				$this->content = KunenaLayout::factory('Widget/Custom')
					->set('header', $e->getResponseStatus())
					->set('body', $e->getMessage());

			}
			catch (Exception $e)
			{
				if (!($e instanceof KunenaExceptionAuthorise))
				{
					$header = 'Error while rendering layout';
					$content = isset($content) ? $content->renderError($e) : $this->content->renderError($e);
					$e = new KunenaExceptionAuthorise($e->getMessage(), $e->getCode(), $e);
				}
				else
				{
					$header = $e->getResponseStatus();
					$content = $e->getMessage();
				}

				$this->setResponseStatus($e->getResponseCode());
				$this->output->setLayout('unauthorized');
				$this->document->setTitle($header);

				$this->content = KunenaLayout::factory('Widget/Custom')
					->set('header', $header)
					->set('body', $content);
			}
		}

		// Display wrapper layout with given parameters.
		$this->output
			->set('content', $this->content)
			->set('breadcrumb', $this->breadcrumb);

		// Run after executing action.
		$this->after();

		KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.get_class($this).'::'.__FUNCTION__.'()') : null;

		return $this->output;
	}
Esempio n. 6
0
<?php

/**
 * Kunena Component
* @package Kunena.Template.Crypsis
* @subpackage BBCode
*
* @copyright (C) 2008 - 2015 Kunena Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link http://www.kunena.org
**/
defined('_JEXEC') or die;
/** @var KunenaAttachment $attachment */
$attachment = $this->attachment;
/** @var KunenaUser $user */
$user = isset($this->user) ? $this->user : null;
// Get authorisation message.
$exception = $attachment->tryAuthorise('read', $user, false);
if (!$exception) {
    $exception = new KunenaExceptionAuthorise('Bad Request.', 400);
}
?>
<div class="kmsgattach">
	<?php 
echo $exception->getMessage();
?>
</div>