/** * Defined by IfwPsn_Vendor_Zend_Application_Resource_Resource * * @return IfwPsn_Vendor_Zend_Navigation */ public function init() { if (!$this->_container) { $options = $this->getOptions(); if (isset($options['defaultPageType'])) { IfwPsn_Vendor_Zend_Navigation_Page::setDefaultPageType($options['defaultPageType']); } $pages = isset($options['pages']) ? $options['pages'] : array(); $this->_container = new IfwPsn_Vendor_Zend_Navigation($pages); } $this->store(); return $this->_container; }
/** * Returns an array representation of the page * * @return array associative array containing all page properties */ public function toArray() { return array_merge(parent::toArray(), array('action' => $this->getAction(), 'controller' => $this->getController(), 'module' => $this->getModule(), 'params' => $this->getParams(), 'route' => $this->getRoute(), 'reset_params' => $this->getResetParams(), 'encodeUrl' => $this->getEncodeUrl(), 'scheme' => $this->getScheme())); }
/** * Renders the given $page as a link element, with $attrib = $relation * * @param IfwPsn_Vendor_Zend_Navigation_Page $page the page to render the link for * @param string $attrib the attribute to use for $type, * either 'rel' or 'rev' * @param string $relation relation type, muse be one of; * alternate, appendix, bookmark, * chapter, contents, copyright, * glossary, help, home, index, next, * prev, section, start, stylesheet, * subsection * @return string rendered link element * @throws IfwPsn_Vendor_Zend_View_Exception if $attrib is invalid */ public function renderLink(IfwPsn_Vendor_Zend_Navigation_Page $page, $attrib, $relation) { if (!in_array($attrib, array('rel', 'rev'))) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/View/Exception.php'; $e = new IfwPsn_Vendor_Zend_View_Exception(sprintf('Invalid relation attribute "%s", must be "rel" or "rev"', $attrib)); $e->setView($this->view); throw $e; } if (!($href = $page->getHref())) { return ''; } // TODO: add more attribs // http://www.w3.org/TR/html401/struct/links.html#h-12.2 $attribs = array($attrib => $relation, 'href' => $href, 'title' => $page->getLabel()); return '<link' . $this->_htmlAttribs($attribs) . $this->getClosingBracket(); }
/** * Returns an array representation of the page * * @return array */ public function toArray() { return array_merge(parent::toArray(), array('uri' => $this->getUri())); }
public static function setDefaultPageType($type = null) { if ($type !== null && !is_string($type)) { throw new IfwPsn_Vendor_Zend_Navigation_Exception('Cannot set default page type: type is no string but should be'); } self::$_defaultPageType = $type; }
/** * Returns an escaped absolute URL for the given page * * @param IfwPsn_Vendor_Zend_Navigation_Page $page page to get URL from * @return string */ public function url(IfwPsn_Vendor_Zend_Navigation_Page $page) { $href = $page->getHref(); if (!isset($href[0])) { // no href return ''; } elseif ($href[0] == '/') { // href is relative to root; use serverUrl helper $url = $this->getServerUrl() . $href; } elseif (preg_match('/^[a-z]+:/im', (string) $href)) { // scheme is given in href; assume absolute URL already $url = (string) $href; } else { // href is relative to current document; use url helpers $url = $this->getServerUrl() . rtrim($this->view->url(), '/') . '/' . $href; } return $this->_xmlEscape($url); }
/** * Returns an HTML string containing an 'a' element for the given page if * the page's href is not empty, and a 'span' element if it is empty * * Overrides {@link IfwPsn_Vendor_Zend_View_Helper_Navigation_Abstract::htmlify()}. * * @param IfwPsn_Vendor_Zend_Navigation_Page $page page to generate HTML for * @return string HTML string for the given page */ public function htmlify(IfwPsn_Vendor_Zend_Navigation_Page $page) { // get label and title for translating $label = $page->getLabel(); $title = $page->getTitle(); // translate label and title? if ($this->getUseTranslator() && ($t = $this->getTranslator())) { if (is_string($label) && !empty($label)) { $label = $t->translate($label); } if (is_string($title) && !empty($title)) { $title = $t->translate($title); } } // get attribs for element $attribs = array('id' => $page->getId(), 'title' => $title); if (false === $this->getAddPageClassToLi()) { $attribs['class'] = $page->getClass(); } // does page have a href? if ($href = $page->getHref()) { $element = 'a'; $attribs['href'] = $href; $attribs['target'] = $page->getTarget(); $attribs['accesskey'] = $page->getAccessKey(); } else { $element = 'span'; } // Add custom HTML attributes $attribs = array_merge($attribs, $page->getCustomHtmlAttribs()); return '<' . $element . $this->_htmlAttribs($attribs) . '>' . $this->view->escape($label) . '</' . $element . '>'; }
/** * Determines whether a page should be accepted by ACL when iterating * * Rules: * - If helper has no ACL, page is accepted * - If page has a resource or privilege defined, page is accepted * if the ACL allows access to it using the helper's role * - If page has no resource or privilege, page is accepted * * @param IfwPsn_Vendor_Zend_Navigation_Page $page page to check * @return bool whether page is accepted by ACL */ protected function _acceptAcl(IfwPsn_Vendor_Zend_Navigation_Page $page) { if (!($acl = $this->getAcl())) { // no acl registered means don't use acl return true; } $role = $this->getRole(); $resource = $page->getResource(); $privilege = $page->getPrivilege(); if ($resource || $privilege) { // determine using helper role and page resource/privilege return $acl->isAllowed($role, $resource, $privilege); } return true; }
/** * Checks if the container has the given page * * @param IfwPsn_Vendor_Zend_Navigation_Page $page page to look for * @param bool $recursive [optional] whether to search * recursively. Default is false. * @return bool whether page is in container */ public function hasPage(IfwPsn_Vendor_Zend_Navigation_Page $page, $recursive = false) { if (array_key_exists($page->hashCode(), $this->_index)) { return true; } elseif ($recursive) { foreach ($this->_pages as $childPage) { if ($childPage->hasPage($page, true)) { return true; } } } return false; }