. */ namespace SP\Controller; defined('APP_ROOT') || die(); use SP\Config\Config; use SP\Core\ActionsInterface; use SP\Core\Exceptions\SPException; use SP\Core\SessionFactory; use SP\Core\SessionUtil; use SP\Core\Template; use SP\Http\Request; use SP\Util\Checks; use SP\Util\Json; use SP\Util\Wiki\DokuWikiApi; /** * Class WikiC para la gestión de la Wiki * * @package SP\Controller */ class WikiController extends ControllerBase implements ActionsInterface { use RequestControllerTrait; /** * Constructor * * @param $template Template con instancia de plantilla */ public function __construct(Template $template = null) { parent::__construct($template); $this->init(); $this->view->assign('sk', SessionUtil::getSessionKey(true)); $this->view->assign('isDemoMode', $this->configData->isDemoEnabled() && !SessionFactory::getUserData()->isUserIsAdminApp()); $this->view->assign('isDisabled', ($this->configData->isDemoEnabled() && !SessionFactory::getUserData()->isUserIsAdminApp()) ? 'DISABLED' : ''); } /** * Realizar las acciones del controlador * * @param mixed $type Tipo de acción */ public function doAction($type = null) { try { switch ($this->actionId) { case self::ACTION_WIKI_VIEW: $this->getWikiPage(); break; default: $this->invalidAction(); } if (count($this->JsonResponse->getData()) === 0) { $this->JsonResponse->setData(['html' => $this->render()]); } } catch (\Exception $e) { $this->JsonResponse->setDescription($e->getMessage()); } $this->JsonResponse->setCsrf($this->view->sk); Json::returnJson($this->JsonResponse); } /** * Obtener los datos para la ficha de una página de la Wiki */ public function getWikiPage() { $pageName = Request::analyze('pageName'); $this->view->addTemplate('wikipage'); $pageData = ''; $pageInfo = ''; $headerData = ''; $pageSearch = ''; $wikiUrlBase = $this->configData->getDokuwikiUrlBase(); try { $DokuWikiApi = new DokuWikiApi(); $headerData = $DokuWikiApi->getTitle(); $pageData = $DokuWikiApi->getPage($pageName); if ($pageData !== false) { if (is_array($pageData) && empty($pageData[0])) { $pageSearch = $DokuWikiApi->getSearch($pageName); } else { $pageInfo = $DokuWikiApi->getPageInfo($pageName); } } } catch (SPException $e) { // $DokuWikiApi->getPageList(); } $this->view->assign('pageName', $pageName); $this->view->assign('wikiUrlBase', $wikiUrlBase); $this->view->assign('pageData', $pageData); $this->view->assign('pageSearch', $pageSearch); $this->view->assign('pageInfo', $pageInfo); $this->view->assign('header', $headerData); $this->JsonResponse->setStatus(0); } }