/** * @param \Difra\Param\AnyInt $id */ public function pageAction(Param\AnyInt $id) { /** @var $pageNode \DOMElement */ $pageNode = $this->root->appendChild($this->xml->createElement('page')); $page = Page::get($id->val()); $page->getXML($pageNode); $this->root->setAttribute('pageTitle', $page->getTitle()); }
/** * Delete page * @param \Difra\Param\AnyInt $id * @param \Difra\Param\AjaxCheckbox $confirm */ public function deleteAjaxAction(\Difra\Param\AnyInt $id, \Difra\Param\AjaxCheckbox $confirm = null) { if ($confirm and $confirm->val()) { \Difra\Plugins\CMS\Page::get($id->val())->delete(); Ajaxer::close(); Ajaxer::redirect('/adm/content/pages'); return; } $page = \Difra\Plugins\CMS\Page::get($id->val()); Ajaxer::display('<span>' . \Difra\Locales::get('cms/adm/delete-page-confirm-1') . $page->getTitle() . \Difra\Locales::get('cms/adm/delete-page-confirm-2') . '</span>' . '<form action="/adm/content/pages/delete/' . $id . '" method="post" class="ajaxer">' . '<input type="hidden" name="confirm" value="1"/>' . '<input type="submit" value="Да"/>' . '<a href="#" onclick="ajaxer.close(this)" class="button">Нет</a>' . '</form>'); }
/** * Get menu element data as XML node * @param \DOMElement $node * @return bool */ public function getXML($node) { if (!$this->load()) { return false; } $node->setAttribute('id', $this->id); $node->setAttribute('id', $this->id); $node->setAttribute('menu', $this->menu); $node->setAttribute('parent', $this->parent); $controllerUri = Action::getControllerUri(); $uri = Envi::getUri(); $href = ''; if ($this->page) { // page if (empty($this->pageData)) { $page = Page::get($this->page); $this->pageData = ['id' => $page->getId(), 'tag' => $page->getUri(), 'hidden' => $page->getHidden(), 'title' => $page->getTitle()]; } $hidden = (!$this->visible or $this->pageData['hidden']) ? '1' : '0'; $node->setAttribute('type', 'page'); $node->setAttribute('label', $this->pageData['title']); $node->setAttribute('link', $href = $this->pageData['tag']); $node->setAttribute('hidden', $hidden); $node->setAttribute('page', $this->pageData['id']); } elseif ($this->link) { // link $node->setAttribute('type', 'link'); $node->setAttribute('label', $this->linkLabel); $node->setAttribute('link', $href = $this->link); $node->setAttribute('hidden', !$this->visible ? '1' : '0'); } else { // empty $node->setAttribute('type', 'empty'); $node->setAttribute('label', $this->linkLabel); $node->setAttribute('hidden', !$this->visible ? '1' : '0'); } if ($href) { if ($href == $uri) { $node->setAttribute('match', 'exact'); } elseif ($href == $controllerUri) { $node->setAttribute('match', 'partial'); } elseif (strpos($uri, $href) !== false) { $node->setAttribute('match', 'partial'); } } return true; }
/** * Get pages list * @param \DOMElement $node * @param int $menuId * @param MenuItem $currentItem */ public function getAvailablePagesXML($node, $menuId, $currentItem = null) { $current = MenuItem::getList($menuId); $currentIds = []; if (!empty($current)) { foreach ($current as $item) { $currentIds[] = $item->getPage(); } } $all = CMS\Page::getList(true); if (!empty($all)) { foreach ($all as $item) { if (!$currentItem or $item->getId() != $currentItem->getPage()) { if (in_array($item->getId(), $currentIds)) { continue; } } /** @var $pageNode \DOMElement */ $pageNode = $node->appendChild($node->ownerDocument->createElement('page')); $item->getXML($pageNode); } } }
/** * Get pages list * @param \DOMElement|\DOMNode $node * @param bool|int $visible * @return bool */ public function getListXML($node, $visible = null) { $data = Page::getList($visible); if (empty($data)) { return false; } foreach ($data as $page) { $pageNode = $node->appendChild($node->ownerDocument->createElement('page')); $page->getXML($pageNode); } return true; }