/** * Return AJAX for the requested layout. * * @return string String in JSON or RAW. * * @throws RuntimeException * @throws KunenaExceptionAuthorise */ public function execute() { $format = $this->input->getWord('format', 'html'); $function = 'display' . ucfirst($format); if (!method_exists($this, $function)) { // Invalid page request. throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 404); } // Run before executing action. $result = $this->before(); if ($result === false) { $content = new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 404); } elseif (!JSession::checkToken()) { // Invalid access token. $content = new KunenaExceptionAuthorise(JText::_('COM_KUNENA_ERROR_TOKEN'), 403); } elseif ($this->config->board_offline && !$this->me->isAdmin()) { // Forum is offline. $content = new KunenaExceptionAuthorise(JText::_('COM_KUNENA_FORUM_IS_OFFLINE'), 503); } elseif ($this->config->regonly && !$this->me->exists()) { // Forum is for registered users only. $content = new KunenaExceptionAuthorise(JText::_('COM_KUNENA_LOGIN_NOTIFICATION'), 401); } else { $display = $this->input->getCmd('display', 'Undefined') . '/Display'; try { $content = KunenaRequest::factory($display, $this->input, $this->options)->setPrimary()->execute()->render(); } catch (Exception $e) { $content = $e; } } return $this->{$function}($content); }
/** * Plugin processor. * * @param string $content * @return bool */ protected function process(&$content) { // Quick search to optimize pages which do not contain the tag. if (stripos($content, 'Kunena.Display') === false) { return false; } $regex = '/{{\\s*Kunena.Display\\(([^\\)]+)\\)\\s*}}/i'; preg_match_all($regex, $content, $matches, PREG_SET_ORDER); if (!$matches) { return false; } foreach ($matches as $match) { $paramslist = (array) explode(',', $match[1]); $layout = trim(trim(array_shift($paramslist)), '\'"') . '/Display'; try { // TODO: de we need to load the language files? $input = new JInput($this->getParams($paramslist)); $output = KunenaRequest::factory($layout, $input); } catch (Exception $e) { $output = '<div class="alert">' . $e->getMessage() . '</div>'; } $pos = strpos($content, $match[0]); if ($pos !== false) { $content = substr_replace($content, (string) $output, $pos, strlen($match[0])); } } return true; }
/** * Get main MVC triad from current layout. * * @param $path * @param $input * @param $options * * @return KunenaControllerDisplay */ public function request($path, Jinput $input = null, $options = null) { return KunenaRequest::factory($path . '/Display', $input, $options ? $options : $this->getOptions())->setPrimary()->set('layout', $this->getLayout()); }
/** * Display arbitrary MVC triad from current layout. * * By using $this->subRequest() instead of KunenaRequest::factory() you can make your template files both * easier to read and gain some context awareness. * * @param $path * @param $input * @param $options * * @return KunenaControllerDisplay */ public function subRequest($path, Jinput $input = null, $options = null) { return KunenaRequest::factory($path . '/Display', $input, $options)->setLayout($this->getLayout()); }